-
Notifications
You must be signed in to change notification settings - Fork 53
issue 2590 key manager integration #2597
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
Merged
Merged
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
e1a5cad
issue 2590 km integration
b0e639c
prepare test email
19bb85f
prepare for tests
5461558
fix code style
2eb60ab
code style
47b701b
added test for get.key@key-manager-autogen (will fail)
02611db
basic implementation / not done
6ad601d
expect pubkey be submitted to km
af8ed0b
hide pass phrase settings
50dc4a4
throw if idToken missing only on initial setup
29326c4
add idToken to url params
d48fc80
fix tests
75ba5cf
fix conflicting html attributes
1806b92
fix checking security frame + fix test
274f930
create SetupPageRecipe.autoKeygen
e2341a4
added test for put.key
602d761
honor getEnforcedKeygenAlgo
a256636
fix code style
24e1cef
hide idToken in err msgs
3e8177b
don't show mobile prompt
4492762
fix code style
d592714
hide add_key
a2f11cd
ajaxErrorDetails
275f5a2
test get.error and put.error
c31239e
test friendly err when KM down
7bb573c
code style
d673a2a
only submit main email to attester
b5fce9a
dry
cdd7b07
throw on key parse err
fb7d159
throw if cannot decrypt generated key
3bcdde0
safe retry for storing key
7de3bb1
fixed test
77bc0d6
throw on unsupported functionality
fccd33c
change km api
33c766d
fix test after km api change
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
extension/chrome/settings/setup/setup-key-manager-autogen.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| /* ©️ 2016 - present FlowCrypt a.s. Limitations apply. Contact human@flowcrypt.com */ | ||
|
|
||
| 'use strict'; | ||
|
|
||
| import { SetupOptions, SetupView } from '../setup.js'; | ||
|
|
||
| import { PgpKey } from '../../../js/common/core/pgp-key.js'; | ||
| import { Ui } from '../../../js/common/browser/ui.js'; | ||
| import { Url } from '../../../js/common/core/common.js'; | ||
| import { AcctStore } from '../../../js/common/platform/store/acct-store.js'; | ||
| import { Buf } from '../../../js/common/core/buf.js'; | ||
| import { PgpPwd } from '../../../js/common/core/pgp-password.js'; | ||
| import { ApiErr } from '../../../js/common/api/error/api-error.js'; | ||
| import { Api } from '../../../js/common/api/api.js'; | ||
| import { Settings } from '../../../js/common/settings.js'; | ||
|
|
||
| export class SetupKeyManagerAutogenModule { | ||
|
|
||
| constructor(private view: SetupView) { | ||
| } | ||
|
|
||
| public getKeyFromKeyManagerOrAutogenAndStoreItThenRenderSetupDone = async () => { | ||
| if (!this.view.rules.mustAutogenPassPhraseQuietly()) { | ||
| const notSupportedErr = 'Combination of org rules not yet supported: PRV_AUTOIMPORT_OR_AUTOGEN cannot yet be used without PASS_PHRASE_QUIET_AUTOGEN.'; | ||
| await Ui.modal.error(`${notSupportedErr}\n\nPlease write human@flowcrypt.com to add support.`); | ||
| window.location.href = Url.create('index.htm', { acctEmail: this.view.acctEmail }); | ||
| return; | ||
| } | ||
| const keygenAlgo = this.view.rules.getEnforcedKeygenAlgo(); | ||
| if (!keygenAlgo) { | ||
| const notSupportedErr = 'Combination of org rules not yet supported: PRV_AUTOIMPORT_OR_AUTOGEN cannot yet be used without enforce_keygen_algo.'; | ||
| await Ui.modal.error(`${notSupportedErr}\n\nPlease write human@flowcrypt.com to add support.`); | ||
| window.location.href = Url.create('index.htm', { acctEmail: this.view.acctEmail }); | ||
| return; | ||
| } | ||
| const passphrase = PgpPwd.random(); // mustAutogenPassPhraseQuietly | ||
| const opts: SetupOptions = { passphrase_save: true, submit_main: true, submit_all: false, passphrase }; | ||
| try { | ||
| const { privateKeys } = await this.view.keyManager!.getPrivateKeys(); | ||
| if (privateKeys.length) { // keys already exist on keyserver, auto-import | ||
| const { keys } = await PgpKey.readMany(Buf.fromUtfStr(privateKeys.map(pk => pk.decryptedPrivateKey).join('\n'))); | ||
| if (!keys.length) { | ||
| throw new Error(`Could not parse any valid keys from Key Manager response for user ${this.view.acctEmail}`); | ||
| } | ||
| for (const prv of keys) { | ||
| if (!prv.isPrivate()) { | ||
| throw new Error(`Key ${await PgpKey.longid(prv)} for user ${this.view.acctEmail} is not a private key`); | ||
| } | ||
| if (!prv.isFullyDecrypted()) { | ||
| throw new Error(`Key ${await PgpKey.longid(prv)} for user ${this.view.acctEmail} from FlowCrypt Email Key Manager is not fully decrypted`); | ||
| } | ||
| await PgpKey.encrypt(prv, passphrase); | ||
| } | ||
| await this.view.saveKeys(keys, opts); | ||
| } else { // generate keys and store them on key manager | ||
| const { full_name } = await AcctStore.get(this.view.acctEmail, ['full_name']); | ||
| const generated = await PgpKey.create([{ name: full_name || '', email: this.view.acctEmail }], keygenAlgo, passphrase); | ||
| const decryptablePrv = await PgpKey.read(generated.private); | ||
| const generatedKeyLongid = await PgpKey.longid(decryptablePrv); | ||
| if (! await PgpKey.decrypt(decryptablePrv, passphrase)) { | ||
| throw new Error('Unexpectedly cannot decrypt newly generated key'); | ||
| } | ||
| const storePrvOnKm = () => this.view.keyManager!.storePrivateKey(decryptablePrv.armor(), decryptablePrv.toPublic().armor(), generatedKeyLongid!); | ||
| await Settings.retryUntilSuccessful(storePrvOnKm, 'Failed to store newly generated key on FlowCrypt Email Key Manager'); | ||
| await this.view.saveKeys([await PgpKey.read(generated.private)], opts); // store encrypted key + pass phrase locally | ||
| } | ||
| await this.view.finalizeSetup(opts); | ||
| await this.view.setupRender.renderSetupDone(); | ||
| } catch (e) { | ||
| if (ApiErr.isNetErr(e) && await Api.isInternetAccessible()) { // frendly message when key manager is down, helpful during initial infrastructure setup | ||
| e.message = `FlowCrypt Email Key Manager at ${this.view.rules.getPrivateKeyManagerUrl()} is down, please inform your network admin.`; | ||
| } | ||
| throw e; | ||
| } | ||
| } | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.