Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 53
auto include pubkey based on rules discussed in #3445#3487
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
edad96e097808cf615cbe84496039367019fd614d1File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -7,7 +7,7 @@ import { Contact } from '../../../js/common/core/crypto/key.js'; | ||
| import { PUBKEY_LOOKUP_RESULT_FAIL, PUBKEY_LOOKUP_RESULT_WRONG } from './compose-err-module.js'; | ||
| import { ProviderContactsQuery, Recipients } from '../../../js/common/api/email-provider/email-provider-api.js'; | ||
| import { RecipientElement, RecipientStatus } from './compose-types.js'; | ||
| import { Str, Value } from '../../../js/common/core/common.js'; | ||
| import { Str } from '../../../js/common/core/common.js'; | ||
| import { ApiErr } from '../../../js/common/api/shared/api-error.js'; | ||
| import { Bm, BrowserMsg } from '../../../js/common/browser/browser-msg.js'; | ||
| import { Catch } from '../../../js/common/platform/catch.js'; | ||
| @@ -38,8 +38,6 @@ export class ComposeRecipientsModule extends ViewModule<ComposeView> { | ||
| private contactSearchInProgress = false; | ||
| private addedPubkeyDbLookupInterval?: number; | ||
| private recipientsMissingMyKey: string[] = []; | ||
| private onRecipientAddedCallbacks: ((rec: RecipientElement[]) => void)[] = []; | ||
| private dragged: Element | undefined = undefined; | ||
| @@ -300,6 +298,7 @@ export class ComposeRecipientsModule extends ViewModule<ComposeView> { | ||
| this.onRecipientAddedCallbacks.push(callback); | ||
| } | ||
| // todo: shouldn't we check longid? | ||
rrrooommmaaa marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| public doesRecipientHaveMyPubkey = async (theirEmailUnchecked: string): Promise<boolean | undefined> => { | ||
| const theirEmail = Str.parseEmail(theirEmailUnchecked).email; | ||
| if (!theirEmail) { | ||
| @@ -316,7 +315,7 @@ export class ComposeRecipientsModule extends ViewModule<ComposeView> { | ||
| const qReceivedMsg = `from:${theirEmail} "BEGIN PGP MESSAGE" "END PGP MESSAGE"`; | ||
| try { | ||
| const response = await this.view.emailProvider.msgList(`(${qSentPubkey}) OR (${qReceivedMsg})`, true); | ||
| if (response.messages) { | ||
| if (response.messages && response.messages.length > 0) { | ||
| await AcctStore.set(this.view.acctEmail, { pubkey_sent_to: (storage.pubkey_sent_to || []).concat(theirEmail) }); | ||
| return true; | ||
| } else { | ||
| @@ -857,7 +856,6 @@ export class ComposeRecipientsModule extends ViewModule<ComposeView> { | ||
| } | ||
| private removeRecipient = (element: HTMLElement) => { | ||
| this.recipientsMissingMyKey = Value.arr.withoutVal(this.recipientsMissingMyKey, $(element).parent().text()); | ||
| const index = this.addedRecipients.findIndex(r => r.element.isEqualNode(element)); | ||
| this.addedRecipients[index].element.remove(); | ||
| const container = element.parentElement?.parentElement; // Get Container, e.g. '.input-container-cc' | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -7,7 +7,8 @@ import { ApiErr } from '../shared/api-error.js'; | ||
| import { opgp } from '../../core/crypto/pgp/openpgpjs-custom.js'; | ||
| import { Buf } from '../../core/buf.js'; | ||
| import { PubkeySearchResult } from './../pub-lookup.js'; | ||
| import { KeyUtil } from '../../core/crypto/key.js'; | ||
| import { Key, KeyUtil } from '../../core/crypto/key.js'; | ||
| import { Str } from '../../core/common.js'; | ||
| // tslint:disable:no-null-keyword | ||
| // tslint:disable:no-direct-ajax | ||
| @@ -24,21 +25,23 @@ export class Wkd extends Api { | ||
| super(); | ||
| } | ||
| public lookupEmail = async (email: string): Promise<PubkeySearchResult> => { | ||
| // returns all the received keys | ||
| public rawLookupEmail = async (email: string): Promise<{ keys: Key[], errs: Error[] }> => { | ||
| // todo: should we return errs on network failures etc.? | ||
| const parts = email.split('@'); | ||
| if (parts.length !== 2) { | ||
| return { pubkey: null, pgpClient: null }; | ||
| return { keys: [], errs: [] }; | ||
| } | ||
| const [user, recipientDomain] = parts; | ||
| if (!user || !recipientDomain) { | ||
| return { pubkey: null, pgpClient: null }; | ||
| return { keys: [], errs: [] }; | ||
| } | ||
| if (!opgp) { | ||
| // pgp_block.htm does not have openpgp loaded | ||
| // the particular usecase (auto-loading pubkeys to verify signatures) is not that important, | ||
| // the user typically gets the key loaded from composing anyway | ||
| // the proper fix would be to run encodeZBase32 through background scripts | ||
| return { pubkey: null, pgpClient: null }; | ||
| return { keys: [], errs: [] }; | ||
| } | ||
| const directDomain = recipientDomain.toLowerCase(); | ||
| const advancedDomainPrefix = (directDomain === 'localhost') ? '' : 'openpgpkey.'; | ||
| @@ -50,15 +53,19 @@ export class Wkd extends Api { | ||
| const directUrl = `https://${directHost}/.well-known/openpgpkey`; | ||
| let response = await this.urlLookup(advancedUrl, userPart); | ||
| if (!response.buf && response.hasPolicy) { | ||
| return { pubkey: null, pgpClient: null }; // do not retry direct if advanced had a policy file | ||
| return { keys: [], errs: [] }; // do not retry direct if advanced had a policy file | ||
| } | ||
| if (!response.buf) { | ||
| response = await this.urlLookup(directUrl, userPart); | ||
| } | ||
| if (!response.buf) { | ||
| return { pubkey: null, pgpClient: null }; // do not retry direct if advanced had a policy file | ||
| return { keys: [], errs: [] }; // do not retry direct if advanced had a policy file | ||
| } | ||
| const { keys, errs } = await KeyUtil.readMany(response.buf); | ||
| return await KeyUtil.readMany(response.buf); | ||
| } | ||
| public lookupEmail = async (email: string): Promise<PubkeySearchResult> => { | ||
| const { keys, errs } = await this.rawLookupEmail(email); | ||
| if (errs.length) { | ||
| return { pubkey: null, pgpClient: null }; | ||
| } | ||
| @@ -67,7 +74,7 @@ export class Wkd extends Api { | ||
| return { pubkey: null, pgpClient: null }; | ||
| } | ||
| // if recipient uses same domain, we assume they use flowcrypt | ||
| const pgpClient = this.myOwnDomain === recipientDomain ? 'flowcrypt' : 'pgp-other'; | ||
| const pgpClient = this.myOwnDomain === Str.getDomainFromEmailAddress(email) ? 'flowcrypt' : 'pgp-other'; | ||
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. I suppose we'll be dropping pgpClient from everywhere. If you want to chunk up the upcoming PR, this could also be done in a separate PR. ContributorAuthor 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. Let's drop it in the PR #3445 that actually "deletes" the | ||
| try { | ||
| const pubkey = KeyUtil.armor(key); | ||
| return { pubkey, pgpClient }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -33,6 +33,11 @@ export class Str { | ||
| return { email, name, full }; | ||
| } | ||
| public static getDomainFromEmailAddress = (emailAddr: string) => { | ||
| // todo: parseEmail()? | ||
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. I think parseEmail would be sensible here, and throw if it returns "undefined" | ||
| return emailAddr.toLowerCase().split('@')[1]; | ||
| } | ||
| public static rmSpecialCharsKeepUtf = (str: string, mode: 'ALLOW-SOME' | 'ALLOW-NONE'): string => { | ||
| // not a whitelist because we still want utf chars | ||
| str = str.replace(/[@&#`();:'",<>\{\}\[\]\\\/\n\t\r]/gi, ''); | ||
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.
doesRecipientHaveMyPubkeyseems like it would be better to place it in this file and not in recipients module, but hard to say for sure without opening the IDE, and not overly important