-
Notifications
You must be signed in to change notification settings - Fork 51
use OpenPGP.js from web content script, simplify #5013
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 26 commits
11d8a76
3346597
7a7651e
48fb7f2
3dfd68b
6c8da84
a2c989f
fe9bb59
7ff645f
6a1af63
1fa81d9
7dff2be
4e33580
6d2ec20
8d4a3ab
4298b1d
9598bb0
a72e748
aa5c6ac
3fb4257
710f27d
70dc59c
d7df2bc
d971da2
4d88425
3efd2e7
e53a17d
2dd0237
18dc1ab
2a0c078
9deb31a
97396e1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
//webpack.config.js | ||
//bundle the web version of @openpgp/web-stream-tools for content script | ||
const path = require('path'); | ||
|
||
module.exports = { | ||
mode: 'production', | ||
entry: { | ||
main: '../build/generic-extension-wip/lib/streams/streams.js', | ||
}, | ||
output: { | ||
library: { | ||
name: 'Stream', | ||
type: 'var', | ||
}, | ||
path: path.resolve('../build/generic-extension-wip/lib'), | ||
filename: 'streams_web.js', // <--- Will be compiled to this single file | ||
}, | ||
resolve: { | ||
fallback: { | ||
stream: false, | ||
}, | ||
extensions: ['.js'], | ||
}, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,6 @@ import { Bm, BrowserMsg } from '../common/browser/browser-msg.js'; | |
import { emailKeyIndex } from '../common/core/common.js'; | ||
import { VERSION } from '../common/core/const.js'; | ||
import { ExpirationCache } from '../common/core/expiration-cache.js'; | ||
import { processAndStoreKeysFromEkmLocally, getLocalKeyExpiration } from '../common/helpers.js'; | ||
import { Catch } from '../common/platform/catch.js'; | ||
import { AcctStore } from '../common/platform/store/acct-store.js'; | ||
import { ContactStore } from '../common/platform/store/contact-store.js'; | ||
|
@@ -60,8 +59,6 @@ console.info('background_process.js starting'); | |
BrowserMsg.bgAddListener('storeGlobalSet', (r: Bm.StoreGlobalSet) => GlobalStore.set(r.values)); | ||
BrowserMsg.bgAddListener('storeAcctGet', (r: Bm.StoreAcctGet) => AcctStore.get(r.acctEmail, r.keys)); | ||
BrowserMsg.bgAddListener('storeAcctSet', (r: Bm.StoreAcctSet) => AcctStore.set(r.acctEmail, r.values)); | ||
BrowserMsg.bgAddListener('processAndStoreKeysFromEkmLocally', processAndStoreKeysFromEkmLocally); | ||
BrowserMsg.bgAddListener('getLocalKeyExpiration', getLocalKeyExpiration); | ||
|
||
// todo - when https://github.com/FlowCrypt/flowcrypt-browser/issues/2560 | ||
// is fixed, this can be moved to the gmail content script, and some may be removed | ||
Comment on lines
-63
to
64
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also Then pgp_block can be updated to call content script instead of background script. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should I do this in this PR? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i see. then it doesn't have to be in this pr. |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -269,6 +269,7 @@ export class OpenPGPKey { | |
throw new Error(`Key ${key.id} is not a private key`); | ||
} | ||
opgpKey = (await opgp.revokeKey({ key: opgpKey, format: 'object' })).privateKey; | ||
OpenPGPKey.patch(opgpKey); | ||
tomholub marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
} | ||
const certificate = await opgpKey.getRevocationCertificate(); | ||
if (!certificate) { | ||
|
@@ -998,4 +999,27 @@ export class OpenPGPKey { | |
} | ||
return nonDummyPrvPackets; | ||
}; | ||
|
||
private static fixUint8Arrays = (obj: object, processed: object[] = []) => { | ||
for (const k in obj) { | ||
if (obj.hasOwnProperty(k)) { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const x = (obj as any)[k]; | ||
if (x instanceof globalThis.Uint8Array || x instanceof window.Uint8Array) { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
(obj as any)[k] = new Uint8Array(x); | ||
} else if (typeof x === 'object' && x && !processed.includes(x)) { | ||
processed.push(x); | ||
OpenPGPKey.fixUint8Arrays(x, processed); | ||
} | ||
} | ||
} | ||
}; | ||
|
||
private static patch = (opgpKey: OpenPGP.Key) => { | ||
if (Catch.browser()?.name === 'firefox') { | ||
// need to re-create Uint8Array from globalThis.Uint8Array or window.Uint8Array for Firefox content script | ||
OpenPGPKey.fixUint8Arrays(opgpKey); | ||
|
||
} | ||
}; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was really a lot of work done only to be able to call web-stream-tools
readToEnd
function, with different approaches for unit test code, extension pages and content script. May it be possible to convince OpenPGP.js developers to simply re-export this helper function from their library, @tomholub ?