Skip to content

Conversation

rrrooommmaaa
Copy link
Contributor

@rrrooommmaaa rrrooommmaaa commented Apr 5, 2023

This PR is WIP

close #5022
close #3944
close #4164
close #4810

Tests (delete all except exactly one):

  • Tests added or updated

To be filled by reviewers

I have reviewed that this PR... (tick whichever items you personally focused on during this review):

  • addresses the issue it closes (if any)
  • code is readable and understandable
  • is accompanied with tests, or tests are not needed
  • is free of vulnerabilities
  • is documented clearly and usefully, or doesn't need documentation

@rrrooommmaaa rrrooommmaaa requested a review from sosnovsky June 19, 2023 08:50
@sosnovsky
Copy link
Collaborator

sosnovsky commented Jun 19, 2023

@rrrooommmaaa I built extension and now can't open any encrypted message, got such errors:

Error: BrowserMsg(db) sendRawResponse::TypeError: Cannot read properties of undefined (reading 'readKeys')`
Could not open this message with FlowCrypt.
other: TypeCannot read properties of undefined (reading 'readMessage')
Error: BrowserMsg(db) sendRawResponse::TypeError: undefined has no properties
Could not open this message with FlowCrypt.
other: Typeopgp is undefined

@sosnovsky
Copy link
Collaborator

BrowserMsg(db) sendRawResponse::TypeError: undefined has no properties
BrowserMsg.jsonToErr@moz-extension://cc209f92-c631-4136-896d-fd5c240338aa/js/content_scripts/webmail_bundle.js:8805:15
processRawMsgResponse@moz-extension://cc209f92-c631-4136-896d-fd5c240338aa/js/content_scripts/webmail_bundle.js:8720:35


[callerStack]
BrowserMsg.sendAwait@moz-extension://cc209f92-c631-4136-896d-fd5c240338aa/js/content_scripts/webmail_bundle.js:8681:18
db@moz-extension://cc209f92-c631-4136-896d-fd5c240338aa/js/content_scripts/webmail_bundle.js:8435:36
ContactStore.getOneWithAllPubkeys@moz-extension://cc209f92-c631-4136-896d-fd5c240338aa/js/content_scripts/webmail_bundle.js:1478:47
MessageRenderer.getVerificationPubs@moz-extension://cc209f92-c631-4136-896d-fd5c240338aa/js/content_scripts/webmail_bundle.js:11067:44
MessageRenderer/this.renderCryptoMessage@moz-extension://cc209f92-c631-4136-896d-fd5c240338aa/js/content_scripts/webmail_bundle.js:10809:74


url: https://mail.google.com/mail/u/0/#inbox/FMfcgzGsmrCDZttTrQKbnKckXSXKZLzn

[/callerStack]

[responderStack]
Catch.rewrapErr@moz-extension://cc209f92-c631-4136-896d-fd5c240338aa/js/common/platform/catch.js:35:20
BrowserMsg.errToJson@moz-extension://cc209f92-c631-4136-896d-fd5c240338aa/js/common/browser/browser-msg.js:397:38
BrowserMsg.sendRawResponse/<@moz-extension://cc209f92-c631-4136-896d-fd5c240338aa/js/common/browser/browser-msg.js:418:67


[typeof:Error:TypeError] undefined has no properties

OpenPGPKey.parseMany@moz-extension://cc209f92-c631-4136-896d-fd5c240338aa/js/common/core/crypto/pgp/openpgp-key.js:23:24
KeyUtil.parseMany@moz-extension://cc209f92-c631-4136-896d-fd5c240338aa/js/common/core/crypto/key.js:99:33
KeyUtil.parse@moz-extension://cc209f92-c631-4136-896d-fd5c240338aa/js/common/core/crypto/key.js:89:32
ContactStore.sortKeys/pubkeyInfos<@moz-extension://cc209f92-c631-4136-896d-fd5c240338aa/js/common/platform/store/contact-store.js:716:34
ContactStore.sortKeys@moz-extension://cc209f92-c631-4136-896d-fd5c240338aa/js/common/platform/store/contact-store.js:715:51
ContactStore.getOneWithAllPubkeys@moz-extension://cc209f92-c631-4136-896d-fd5c240338aa/js/common/platform/store/contact-store.js:563:46

[/responderStack]

@sosnovsky
Copy link
Collaborator

webmail_bundle.js:68 Error: BrowserMsg(db) sendRawResponse::TypeError: Cannot read properties of undefined (reading 'readKeys')
    at BrowserMsg.jsonToErr (chrome-extension://pjohdcpiapjhagmakkjpgjmodmgfmkkd/js/content_scripts/webmail_bundle.js:10002:15)
    at processRawMsgResponse (chrome-extension://pjohdcpiapjhagmakkjpgjmodmgfmkkd/js/content_scripts/webmail_bundle.js:9908:39)

[callerStack]
    at chrome-extension://pjohdcpiapjhagmakkjpgjmodmgfmkkd/js/content_scripts/webmail_bundle.js:9877:30
    at new Promise (<anonymous>)
    at BrowserMsg.sendAwait (chrome-extension://pjohdcpiapjhagmakkjpgjmodmgfmkkd/js/content_scripts/webmail_bundle.js:9869:22)
    at Object.db (chrome-extension://pjohdcpiapjhagmakkjpgjmodmgfmkkd/js/content_scripts/webmail_bundle.js:9612:36)
    at ContactStore.getOneWithAllPubkeys (chrome-extension://pjohdcpiapjhagmakkjpgjmodmgfmkkd/js/content_scripts/webmail_bundle.js:1549:51)
    at MessageRenderer.getVerificationPubs (chrome-extension://pjohdcpiapjhagmakkjpgjmodmgfmkkd/js/content_scripts/webmail_bundle.js:12567:48)
    at MessageRenderer.renderCryptoMessage (chrome-extension://pjohdcpiapjhagmakkjpgjmodmgfmkkd/js/content_scripts/webmail_bundle.js:12269:78)
    at async MessageRenderer.renderMsgBlock (chrome-extension://pjohdcpiapjhagmakkjpgjmodmgfmkkd/js/content_scripts/webmail_bundle.js:12197:24)

url: https://mail.google.com/mail/u/0/#inbox/FMfcgzGsmDrQHdnkVcnWSFlhJnhfzJnD

[/callerStack]

[responderStack]
Error: sendRawResponse::TypeError: Cannot read properties of undefined (reading 'readKeys')
    at Catch.rewrapErr (chrome-extension://pjohdcpiapjhagmakkjpgjmodmgfmkkd/js/common/platform/catch.js:35:20)
    at BrowserMsg.errToJson (chrome-extension://pjohdcpiapjhagmakkjpgjmodmgfmkkd/js/common/browser/browser-msg.js:417:38)
    at chrome-extension://pjohdcpiapjhagmakkjpgjmodmgfmkkd/js/common/browser/browser-msg.js:438:67

[typeof:Error:TypeError] Cannot read properties of undefined (reading 'readKeys')

TypeError: Cannot read properties of undefined (reading 'readKeys')
    at OpenPGPKey.parseMany (chrome-extension://pjohdcpiapjhagmakkjpgjmodmgfmkkd/js/common/core/crypto/pgp/openpgp-key.js:29:39)
    at KeyUtil.parseMany (chrome-extension://pjohdcpiapjhagmakkjpgjmodmgfmkkd/js/common/core/crypto/key.js:120:37)
    at KeyUtil.parse (chrome-extension://pjohdcpiapjhagmakkjpgjmodmgfmkkd/js/common/core/crypto/key.js:105:36)
    at chrome-extension://pjohdcpiapjhagmakkjpgjmodmgfmkkd/js/common/platform/store/contact-store.js:780:42
    at Array.map (<anonymous>)
    at ContactStore.sortKeys (chrome-extension://pjohdcpiapjhagmakkjpgjmodmgfmkkd/js/common/platform/store/contact-store.js:778:55)
    at ContactStore.getOneWithAllPubkeys (chrome-extension://pjohdcpiapjhagmakkjpgjmodmgfmkkd/js/common/platform/store/contact-store.js:594:50)
    at async BgHandlers.dbOperationHandler (chrome-extension://pjohdcpiapjhagmakkjpgjmodmgfmkkd/js/background_page/bg-handlers.js:34:16)
    at <async> parseMany (/extension/js/common/core/crypto/pgp/openpgp-key.ts:38:28)
    at <async> parseMany (/extension/js/common/core/crypto/key.ts:191:28)
    at <async> parse (/extension/js/common/core/crypto/key.ts:182:24)
    at <async> <anonymous> (/extension/js/common/platform/store/contact-store.ts:768:19)
    at <async> sortKeys (/extension/js/common/platform/store/contact-store.ts:765:28)
    at <async> getOneWithAllPubkeys (/extension/js/common/platform/store/contact-store.ts:549:39)
    at <async> dbOperationHandler (/extension/js/background_page/bg-handlers.ts:17:37)
[/responderStack]

    at <async> sendAwait (/extension/js/common/browser/browser-msg.ts:456:29)
    at <async> getOneWithAllPubkeys (/extension/js/common/platform/store/contact-store.ts:549:39)
    at <async> getVerificationPubs (/extension/js/common/message-renderer.ts:215:39)
    at <async> renderCryptoMessage (/extension/js/common/message-renderer.ts:686:32)
    at <async> renderMsgBlock (/extension/js/common/message-renderer.ts:613:27)

### Catch.reportErr calling stack ###
#     at Catch.formatExceptionForReport (chrome-extension://pjohdcpiapjhagmakkjpgjmodmgfmkkd/js/content_scripts/webmail_bundle.js:277:90)
#     at Catch.onErrorInternalHandler (chrome-extension://pjohdcpiapjhagmakkjpgjmodmgfmkkd/js/content_scripts/webmail_bundle.js:85:29)
#     at Catch.reportErr (chrome-extension://pjohdcpiapjhagmakkjpgjmodmgfmkkd/js/content_scripts/webmail_bundle.js:101:18)
#     at chrome-extension://pjohdcpiapjhagmakkjpgjmodmgfmkkd/js/content_scripts/webmail_bundle.js:12185:27
# 
# url: https://mail.google.com/mail/u/0/#inbox/FMfcgzGsmDrQHdnkVcnWSFlhJnhfzJnD
# 
######################

@rrrooommmaaa
Copy link
Contributor Author

Could not open this message with FlowCrypt.
other: Typeopgp is undefined

What browser is it?
Have you re-built in full? (with npm install)?

@sosnovsky
Copy link
Collaborator

Could not open this message with FlowCrypt.
other: Typeopgp is undefined

This error happened in Firefox.
I tried in both - Chrome and Firefox, there were different errors for different messages.
You can check attached logs from console - #5069 (comment) from Firefox, #5069 (comment) from Chrome

What browser is it? Have you re-built in full? (with npm install)?

Yes, I ran npm install and then also tried to re-build with npm run build

@sosnovsky
Copy link
Collaborator

I checked console and there is error even without opening any email, just after loading gmail page:

SyntaxError: expected expression, got keyword 'return' [openpgp.js:4378:7](moz-extension://cc209f92-c631-4136-896d-fd5c240338aa/lib/openpgp.js)
Loading FlowCrypt 8.4.8 [webmail_bundle.js:13150:29](moz-extension://cc209f92-c631-4136-896d-fd5c240338aa/js/content_scripts/webmail_bundle.js)
Error: Some keys could not be parsed
    parseAndCheckPrivateKeys moz-extension://cc209f92-c631-4136-896d-fd5c240338aa/js/content_scripts/webmail_bundle.js:10025
    # Catch.onErrorInternalHandler moz-extension://cc209f92-c631-4136-896d-fd5c240338aa/js/content_scripts/webmail_bundle.js:85
    # Catch.reportErr moz-extension://cc209f92-c631-4136-896d-fd5c240338aa/js/content_scripts/webmail_bundle.js:101
    # processKeysFromEkm moz-extension://cc209f92-c631-4136-896d-fd5c240338aa/js/content_scripts/webmail_bundle.js:13364
[webmail_bundle.js:68:13](moz-extension://cc209f92-c631-4136-896d-fd5c240338aa/js/content_scripts/webmail_bundle.js)
Some keys could not be parsed
parseAndCheckPrivateKeys@moz-extension://cc209f92-c631-4136-896d-fd5c240338aa/js/content_scripts/webmail_bundle.js:10025:19
[webmail_bundle.js:72:13](moz-extension://cc209f92-c631-4136-896d-fd5c240338aa/js/content_scripts/webmail_bundle.js)
TypeError: opgp is undefined
    parseMany moz-extension://cc209f92-c631-4136-896d-fd5c240338aa/js/content_scripts/webmail_bundle.js:4561
    parseMany moz-extension://cc209f92-c631-4136-896d-fd5c240338aa/js/content_scripts/webmail_bundle.js:3903
    parse moz-extension://cc209f92-c631-4136-896d-fd5c240338aa/js/content_scripts/webmail_bundle.js:3893
    expirations moz-extension://cc209f92-c631-4136-896d-fd5c240338aa/js/content_scripts/webmail_bundle.js:10126
    getLocalKeyExpiration moz-extension://cc209f92-c631-4136-896d-fd5c240338aa/js/content_scripts/webmail_bundle.js:10126
    # Catch.onErrorInternalHandler moz-extension://cc209f92-c631-4136-896d-fd5c240338aa/js/content_scripts/webmail_bundle.js:85
    # Catch.reportErr moz-extension://cc209f92-c631-4136-896d-fd5c240338aa/js/content_scripts/webmail_bundle.js:101
[webmail_bundle.js:68:13](moz-extension://cc209f92-c631-4136-896d-fd5c240338aa/js/content_scripts/webmail_bundle.js)
opgp is undefined
OpenPGPKey.parseMany@moz-extension://cc209f92-c631-4136-896d-fd5c240338aa/js/content_scripts/webmail_bundle.js:4561:24
KeyUtil.parseMany@moz-extension://cc209f92-c631-4136-896d-fd5c240338aa/js/content_scripts/webmail_bundle.js:3903:33
KeyUtil.parse@moz-extension://cc209f92-c631-4136-896d-fd5c240338aa/js/content_scripts/webmail_bundle.js:3893:32
getLocalKeyExpiration/expirations<@moz-extension://cc209f92-c631-4136-896d-fd5c240338aa/js/content_scripts/webmail_bundle.js:10126:80
getLocalKeyExpiration@moz-extension://cc209f92-c631-4136-896d-fd5c240338aa/js/content_scripts/webmail_bundle.js:10126:47

@sosnovsky
Copy link
Collaborator

Line with error in openpgp.js

4377  function is_bytes(a) {
4378 (     return a instanceof Uint8Array ||      return a instanceof globalThis.Uint8Array);
4379  }

@rrrooommmaaa
Copy link
Contributor Author

I tried in both - Chrome and Firefox, there were different errors for different messages.

So these are both on Mac?

function is_bytes(a)

I see something wrong with regexes again...

@sosnovsky
Copy link
Collaborator

So these are both on Mac?

Yes, that's on Mac, but there wasn't any errors during build. I can re-check later today which regexes from build script may fail on Mac

@rrrooommmaaa
Copy link
Contributor Author

That's because of greediness.

Should be return (a instanceof Uint8Array || a instanceof globalThis.Uint8Array); instead of ( return a instanceof Uint8Array || return a instanceof globalThis.Uint8Array);

@rrrooommmaaa
Copy link
Contributor Author

rrrooommmaaa commented Jun 19, 2023

That's because of greediness.

I pushed the lazy-matching fix. Can you build it again on Mac?

@sosnovsky
Copy link
Collaborator

That's because of greediness.

I pushed the lazy-matching fix. Can you build it again on Mac?

No, currently I get error:

+ backup_ext=''\'''\'''
+ for file in "$@"
+ sed '-i'\'''\''' -E 's/\(([^\(\)\x20]+?)\x20instanceof\x20Uint8Array\)/\(\1\x20instanceof\x20Uint8Array\x20\|\|\x20\1\x20instanceof\x20globalThis\.Uint8Array\)/g' ./build/generic-extension-wip/lib/openpgp.js
sed: 1: "s/\(([^\(\)\x20]+?)\x20 ...": RE error: repetition-operator operand invalid

@rrrooommmaaa
Copy link
Contributor Author

rrrooommmaaa commented Jun 20, 2023

This means the lazy modificator isn't supported. I guess, /U isn't supported either.
I'm a bit confused by this behavior as I specified the space character to be excluded with [^\(\)\x20].
How could return a have been captured?
We can try to replace \x20 with \s if it helps.
But wouldn't be better to use a package with the same behavior on all platforms,
some package installable with npm? e.g. https://www.npmjs.com/package/replace

@sosnovsky
Copy link
Collaborator

I updated ISUINT8ARRAY_REGEX3 to be

ISUINT8ARRAY_REGEX3="s/return\x20([^\(\)\x20]+)\x20instanceof\x20Uint8Array;/return\x20\(\1\x20instanceof\x20Uint8Array\x20\|\|\x20\1\x20instanceof\x20globalThis\.Uint8Array\);/g"

and it worked well, all occurrences in openpgp.js were replaced. Maybe let's just use this regex?

@rrrooommmaaa
Copy link
Contributor Author

Maybe let's just use this regex?

Yes, we can make do with this regex.

Copy link
Collaborator

@sosnovsky sosnovsky left a comment

Choose a reason for hiding this comment

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

Great job, I haven't found any issues - everything works well. Maybe I missed something, as list of changes is very big, but if anything will be found - it can be fixed in another PR, this one can be merged so there won't be merge conflicts with other PRs.

@sosnovsky sosnovsky enabled auto-merge (squash) June 20, 2023 20:29
@sosnovsky sosnovsky merged commit a5f53bc into master Jun 20, 2023
@sosnovsky sosnovsky deleted the issue-5022-gmail-element-replacer-refactor-live-test branch June 20, 2023 20:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants