Skip to content

Conversation

@wiktor-k
Copy link
Contributor

@wiktor-k wiktor-k commented Mar 30, 2020

// tom edit: close #2124

  • minor code updates (will make a separate review for myself)
  • add a test - send to single s/mime
  • add a test - send to mixed recipients (should err)
  • add a test - send to two s/mime (sould err?)
  • add a test - attachment (is this supposed to not work yet?)
  • add a test - send with broken S/MIME cert - err
  • add a test - send with non-S/MIME cert - err
  • delete earlier dev files
  • manual testing
  • evaluate why shows as bytes, not attachment, on recipient end

This is a PR adding sending S/MIME to Secure Compose.

This is not yet ready for review.

What works:

  • adding S/MIME key if it's missing,
  • correctly encrypting content if only S/MIME keys are present

What doesn't work:

  • MIME encoding of the encrypted message... it's probably something minor I missed,
  • correctly removing own key from encrypted set if only S/MIME recipients are present,
  • correctly removing calls to PGP specific methods (that are commented out currently),
  • code style issues.

Copy link
Collaborator

@tomholub tomholub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know you said not ready for review :)

Later you can make a file like core/smime.ts with class / methods specific to smime, whose methods could (for now, before we abstract one level up) be called from the core/*-pgp.ts files.

It's shaping up really well.

@wiktor-k wiktor-k force-pushed the issue-2124-add-smime-to-compose branch from 88fafa5 to 0ff8f3e Compare April 2, 2020 13:44
@wiktor-k
Copy link
Contributor Author

wiktor-k commented Apr 2, 2020

Okay, changes from previous iteration:

  • it correctly sends S/MIME encrypted e-mails if only S/MIME recipients are selected,
  • for others the old logic is used (OpenPGP),
  • cleaned up the bit about detecting keys (missing: Serial ID detection, I used random for now),
  • minimized amount of places touched by this code, still there are too many (e.g. extension/chrome/elements/compose-modules/compose-draft-module.ts).

The goal was to seamlessly support adding S/MIME keys and sending S/MIME e-mails while leaving the rest of features un-touched. I think it's mostly done but would like to get your opinion.

Later you can make a file like core/smime.ts with class / methods specific to smime, whose methods could (for now, before we abstract one level up) be called from the core/*-pgp.ts files.

Yes, definitely. Abstracting S/MIME vs OpenPGP would definitely make working with the code more pleasant but my casual look indicated that PGP is interleaved in too many places to do it all at once :( Are there code coverage reports for test somewhere? Usually refactorings (even with static types) can introduce silent bugs and I'd like to avoid that.

@wiktor-k wiktor-k force-pushed the issue-2124-add-smime-to-compose branch from c7c3b91 to c4842e1 Compare April 2, 2020 14:05
@tomholub
Copy link
Collaborator

tomholub commented Apr 2, 2020

Are there code coverage reports for test somewhere?

Nope, I don't have any such metric. If you are familiar with a way to get such metric, I'd be happy to start tracking it.

To give you an idea, most tests are integration tests, driven through the UI (puppeteer) - testing user scenarios. What that means is that most important functionality will get hit one way or another through these tests, and "hot paths" like storage get hit a lot.

As far as code line coverage.. eh.. 60%? But it's the 60% we really care about.

Copy link
Collaborator

@tomholub tomholub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding comments. These are basically what I'd need in order to feel comfortable merging.

Plus also assuming that the new PgpMsg.Encrypt code gets moved into some sort of Smime class and just called from there.

Otherwise I don't think we need to refactor further in this PR. I could merge it and then the next few PRs would target refactoring and abstracting.

@wiktor-k
Copy link
Contributor Author

wiktor-k commented Apr 2, 2020

Yep, excellent feedback, that's what I was looking for, thanks! I'll get back with the changes and then we can think of next steps.

@wiktor-k wiktor-k force-pushed the issue-2124-add-smime-to-compose branch from 1d99df7 to e621b60 Compare April 7, 2020 11:32
@wiktor-k
Copy link
Contributor Author

wiktor-k commented Apr 7, 2020

Nope, I don't have any such metric. If you are familiar with a way to get such metric, I'd be happy to start tracking it.

It seems the tests cover quite a few critical functions (like sending stuff with/without attachments) so maybe refactoring this part is not as risky as I initially thought... 🤔

@tomholub
Copy link
Collaborator

tomholub commented Apr 7, 2020

Nope, I don't have any such metric. If you are familiar with a way to get such metric, I'd be happy to start tracking it.

It seems the tests cover quite a few critical functions (like sending stuff with/without attachments) so maybe refactoring this part is not as risky as I initially thought... thinking

I indeed test the compose button quite heavily functionality wise, but only some tests actually look at what was sent - eg if it's sending something unique. Eventually we'll need to dedicate the time to carefully evaluate the messages the tests compose.

I think, after my review, it should be reasonably safe to merge.

@wiktor-k wiktor-k marked this pull request as ready for review April 7, 2020 19:37
@tomholub
Copy link
Collaborator

@wiktor-k sorry I managed to miss this becoming ready for review! I'll take a look. Thanks!

@wiktor-k
Copy link
Contributor Author

No problem, it's still Easter here so I didn't want to push you (yet ;) ).

@tomholub
Copy link
Collaborator

Easter here too :) I don't observe holidays much, so normally a nudge doesn't hurt.

@tomholub
Copy link
Collaborator

tomholub commented Apr 13, 2020

..

@wiktor-k
Copy link
Contributor Author

add a test - send to mixed recipients (should err)

Yes.

add a test - send to two s/mime (sould err?)

No, it should work. But I never tested this :)

add a test - attachment (is this supposed to not work yet?)

Yes, it won't work but should work in general. I think S/MIME is very similary to PGP/MIME so maybe if we unified this code we would have attachment support "for free".

By the way, why isn't PGP/MIME the default? I thought inline is considered bad. Is this for some kind of backwards-compatibility reasons?

@tomholub
Copy link
Collaborator

By the way, why isn't PGP/MIME the default? I thought inline is considered bad. Is this for some kind of backwards-compatibility reasons?

Gmail API screws up the messages, so they don't really come out as PGP/MIME.

I'll try to talk to them to fix it, haven't had the time yet.

@tomholub
Copy link
Collaborator

Still want to do this.. sorry for the delay!

@wiktor-k
Copy link
Contributor Author

Don't worry Tom, when this is blocked I'm doing other stuff and will resume when you're ready 👍

Copy link
Collaborator

@tomholub tomholub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The notes are all for myself except one where you are mentioned

@tomholub
Copy link
Collaborator

I tried to give it a HTTPS cert instead, and it happily encrypts for it 🤔 is this expected behavior? The lib doesn't care? In that case, sounds like this is something we should be checking ourselves? (eg in next PR)

    // todo - unexpectedly works
    // ava.default.only('send non-S/MIME cert - err', testWithBrowser('compose', async (t, browser) => {
    //   const inboxPage = await browser.newPage(t, TestUrls.extensionInbox('test.ci.compose@org.flowcrypt.com'));
    //   let composeFrame = await InboxPageRecipe.openAndGetComposeFrame(inboxPage);
    //   await ComposePageRecipe.fillMsg(composeFrame, { to: 'smime@recipient.com' }, t.title);
    //   const httpsCert = '-----BEGIN CERTIFICATE-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nA1UdIARFMEMwCAYGZ4EMAQIBMDcGCysGAQQBgt8TAQEBMCgwJgYIKwYBBQUHAgEW\nGmh0dHA6Ly9jcHMubGV0c2VuY3J5cHQub3JnMIIBBgYKKwYBBAHWeQIEAgSB9wSB\n9ADyAHcAb1N2rDHwMRnYmQCkURX/dxUcEdkCwQApBo2yCJo32RMAAAFw2e8sLwAA\nBAMASDBGAiEA7Omcf4+uFphcbEq19r4GoWi7E1qvsJTykvgH342x1d4CIQDSCJZK\n3zsVSw8I1GVfnIr/drVhgn4TJgacXx6+gBzfXQB3ALIeBcyLos2KIE6HZvkruYol\nIGdr2vpw57JJUy3vi5BeAAABcNnvK/kAAAQDAEgwRgIhAP7BbIkG/mNclZAVqgA0\nomAB/6xMwbu1ZUsHNBMkZG+QAiEAmZWCVdUfmFs3b+zDEaAF7eFDnz7qbDa5q6M0\n98r8In0wDQYJKoZIhvcNAQELBQADggEBAFaUhUkxGkHc3lxozCbozM7ffAOcK5De\nJGoTtsXw/XmMACBIIqn2Aan+zvQdK/cWV9+dYu5tA/PHZwVbfKAU2x+Fizs7uDgs\nslg16un1/DP7bmi4Ih3KDVyznzgTwWPq9CmPMIeCXBSGvGN4xdfyIf7mKPSmsEB3\ngkM8HyE27e2u8B4f/R4W+sbqx0h5Y/Kv6NFqgQlatEY2HdAQDYYL21xO1ZjaUozP\nyfHQSJwGHp3/1Xdq5mIkV7w9xxhOn64FXp4S0spVCxT3er1EEUurq+lXjyeX4Dog\n1gy3r417NPqQWuBJcA/InSaS/GUyGghp+kuGfIDqVYfQqU1297nThEA=\n-----END CERTIFICATE-----\n';
    //   await pastePublicKeyManually(composeFrame, inboxPage, 'smime@recipient.com', httpsCert);
    //   await composeFrame.waitAndClick('@action-send', { delay: 2 });
    //   await PageRecipe.waitForModalAndRespond(composeFrame, 'error', { contentToCheck: 'dunno', timeout: 40 });
    // }));

@wiktor-k
Copy link
Contributor Author

I tried to give it a HTTPS cert instead, and it happily encrypts for it thinking is this expected behavior? The lib doesn't care? In that case, sounds like this is something we should be checking ourselves? (eg in next PR)

The library probably doesn't care but we could check it in general because S/MIME certs have "key usage flags" (simiar to E/S/C/A flags for PGP certs). I mean I didn't check if the lib exposes key flags but I hope it does... then we can reject certs that don't have correct flags. Btw interesting test case :)

@tomholub
Copy link
Collaborator

Btw interesting test case :)

Users!! :)

@tomholub
Copy link
Collaborator

When opening an s/mime message on a client without s/mime (tried Gmail), it just shows the bytes.

I would have expected it to show as an attachment (I vaguely recall trying to open such message before). Can you have a look?

image

Also, have you tried to open such message in an s/mime client, after integrating it?

We're getting there.

@wiktor-k
Copy link
Contributor Author

Also, have you tried to open such message in an s/mime client, after integrating it?

Yes, I always tested it with Thunderbird that had my certificate and it just worked:

2020-04-16T11:51:35,901000280+02:00

When opening an s/mime message on a client without s/mime (tried Gmail), it just shows the bytes.
I would have expected it to show as an attachment (I vaguely recall trying to open such message before). Can you have a look?

Maybe we can wrap it in an attachment. It worked in Thunderbird so I didn't bother to try out other options.

We're getting there.

Yes :)

Copy link
Collaborator

@tomholub tomholub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve, we can do sending as attachment in another PR.

@tomholub tomholub merged commit c27a823 into master Apr 16, 2020
@wiktor-k wiktor-k deleted the issue-2124-add-smime-to-compose branch April 16, 2020 10:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

add limited s/mime compatibility when sending email - PoC

4 participants