-
Notifications
You must be signed in to change notification settings - Fork 53
Use public key fingerprint as S/MIME Certificate id #3570 #3575
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 all commits
c9a4e87
39688c0
5d3e084
45d38a2
fb4ff53
757e19a
cbc6967
cd34692
a7dc997
b190f6c
0dc8919
64cade7
7323378
2e2732c
0973000
1013a6e
421e405
5823f79
57869a6
b69e65e
e3f6105
844e01a
c9df1d9
207cebf
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 |
|---|---|---|
|
|
@@ -3,7 +3,8 @@ | |
| 'use strict'; | ||
|
|
||
| import { Key, KeyInfo, KeyUtil } from '../common/core/crypto/key.js'; | ||
| import { ContactStore, ContactUpdate } from '../common/platform/store/contact-store.js'; | ||
| import { SmimeKey } from '../common/core/crypto/smime/smime-key.js'; | ||
| import { ContactStore, ContactUpdate, Email, Pubkey } from '../common/platform/store/contact-store.js'; | ||
| import { GlobalStore } from '../common/platform/store/global-store.js'; | ||
| import { KeyStore } from '../common/platform/store/key-store.js'; | ||
|
|
||
|
|
@@ -19,6 +20,12 @@ type ContactV3 = { | |
| expiresOn: number | null; | ||
| }; | ||
|
|
||
| type PubkeyMigrationData = { | ||
| emailsToUpdate: { [email: string]: Email }; | ||
| pubkeysToDelete: string[]; | ||
| pubkeysToSave: Pubkey[]; | ||
| }; | ||
|
|
||
| const addKeyInfoFingerprints = async () => { | ||
| for (const acctEmail of await GlobalStore.acctEmailsGet()) { | ||
| const originalKis = await KeyStore.get(acctEmail); | ||
|
|
@@ -40,6 +47,69 @@ export const migrateGlobal = async () => { | |
| } | ||
| }; | ||
|
|
||
| const processSmimeKey = (pubkey: Pubkey, tx: IDBTransaction, data: PubkeyMigrationData, next: () => void) => { | ||
| if (KeyUtil.getKeyType(pubkey.armoredKey) !== 'x509') { | ||
| next(); | ||
| return; | ||
| } | ||
|
Comment on lines
+51
to
+54
Collaborator
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. This is interesting - could we instead filter when pulling pubkeys from storage? Eg
Contributor
Author
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. We don't store this info yet, only in ids (fingerprints) -- postfixed with "-X509", and in |
||
| const key = SmimeKey.parse(pubkey.armoredKey); | ||
| const newPubkeyEntity = ContactStore.pubkeyObj(key, pubkey.lastCheck); | ||
| data.pubkeysToDelete.push(pubkey.fingerprint); | ||
| const req = tx.objectStore('emails').index('index_fingerprints').getAll(pubkey.fingerprint!); | ||
| ContactStore.setReqPipe(req, | ||
| (emailEntities: Email[]) => { | ||
| if (emailEntities.length) { | ||
| data.pubkeysToSave.push(newPubkeyEntity); | ||
| } | ||
| for (const emailEntity of emailEntities) { | ||
| const cachedEmail = data.emailsToUpdate[emailEntity.email]; | ||
| if (!cachedEmail) { | ||
| data.emailsToUpdate[emailEntity.email] = emailEntity; | ||
| } | ||
| const entityToUpdate = cachedEmail ?? emailEntity; | ||
| entityToUpdate.fingerprints = entityToUpdate.fingerprints.filter(fp => fp !== pubkey.fingerprint && fp !== newPubkeyEntity.fingerprint); | ||
| entityToUpdate.fingerprints.push(newPubkeyEntity.fingerprint); | ||
| } | ||
| next(); | ||
| }); | ||
| }; | ||
|
|
||
| export const updateX509FingerprintsAndLongids = async (db: IDBDatabase): Promise<void> => { | ||
| const globalStore = await GlobalStore.get(['contact_store_x509_fingerprints_and_longids_updated']); | ||
| if (globalStore.contact_store_x509_fingerprints_and_longids_updated) { | ||
| return; | ||
| } | ||
| console.info('updating ContactStorage to correct longids and fingerprints of X.509 certificates...'); | ||
| const tx = db.transaction(['emails', 'pubkeys'], 'readwrite'); | ||
| await new Promise((resolve, reject) => { | ||
| ContactStore.setTxHandlers(tx, resolve, reject); | ||
| const data: PubkeyMigrationData = { emailsToUpdate: {}, pubkeysToDelete: [], pubkeysToSave: [] }; | ||
| const search = tx.objectStore('pubkeys').openCursor(); | ||
| ContactStore.setReqPipe(search, | ||
| (cursor: IDBCursorWithValue) => { | ||
| if (!cursor) { | ||
| // do updates | ||
| for (const fp of data.pubkeysToDelete.filter(fp => !data.pubkeysToSave.some(x => x.fingerprint === fp))) { | ||
| // console.log(`Deleting pubkey ${fp}`); | ||
| tx.objectStore('pubkeys').delete(fp); | ||
| } | ||
| for (const pubkey of data.pubkeysToSave) { | ||
| // console.log(`Updating pubkey ${pubkey.fingerprint}`); | ||
| tx.objectStore('pubkeys').put(pubkey); | ||
| } | ||
| for (const email of Object.values(data.emailsToUpdate)) { | ||
| // console.log(`Updating email ${email.email}`); | ||
| tx.objectStore('emails').put(email); | ||
| } | ||
| } else { | ||
| processSmimeKey(cursor.value as Pubkey, tx, data, () => cursor.continue()); | ||
| } | ||
| }); | ||
| }); | ||
| await GlobalStore.set({ contact_store_x509_fingerprints_and_longids_updated: true }); | ||
| console.info('done updating'); | ||
| }; | ||
|
|
||
| export const moveContactsToEmailsAndPubkeys = async (db: IDBDatabase): Promise<void> => { | ||
| if (!db.objectStoreNames.contains('contacts')) { | ||
| return; | ||
|
|
||
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.
A small nitpick - maybe this migration
updateX509FingerprintsAndLongidsshould be done aftermoveContactsToEmailsAndPubkeysis already migrated? (switch line order)Uh oh!
There was an error while loading. Please reload this page.
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.
The contacts migration
moveContactsToEmailsAndPubkeyssets correct fingerprints and longids, we only need to fix contacts migrated by the previous version