-
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
Changes from all commits
edad96e
097808c
f615cbe
8449603
9367019
fd614d1
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 |
|---|---|---|
|
|
@@ -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.
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. 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, ''); | ||
|
|
||
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