Allow for whitespace in fingerprint for hkp search

When the search form is submitted, remove whitespace from the input prior to submitting to search
This commit is contained in:
Dasheroo 2022-11-22 06:58:44 -06:00 committed by Gitea
parent f9b46f1806
commit 48943216a0

View file

@ -124,15 +124,22 @@ const fetchHKP = (id, keyserverDomain) => {
keyserverDomain = keyserverDomain || 'keys.openpgp.org' keyserverDomain = keyserverDomain || 'keys.openpgp.org'
let query = '' let query = ''
let sanitizedId = '';
if (id.includes('@')) { if (id.includes('@')) {
query = id query = id
} else { } else {
query = `0x${id}` const whitespaceRegex = /\s/g;
if (whitespaceRegex.test(id)) {
sanitizedId = id.replaceAll(whitespaceRegex, '');
} else {
sanitizedId = id;
}
query = `0x${sanitizedId}`
} }
output.fetchURL = `https://${keyserverDomain}/pks/lookup?op=get&options=mr&search=${query}` output.fetchURL = `https://${keyserverDomain}/pks/lookup?op=get&options=mr&search=${query}`
const hash = createHash('md5').update(`${id}__${keyserverDomain}`).digest('hex') const hash = createHash('md5').update(`${sanitizedId}__${keyserverDomain}`).digest('hex')
if (c && await c.get(hash)) { if (c && await c.get(hash)) {
output.publicKey = await readKey({ output.publicKey = await readKey({
@ -140,7 +147,7 @@ const fetchHKP = (id, keyserverDomain) => {
}) })
} else { } else {
try { try {
output.publicKey = await doipjs.keys.fetchHKP(id, keyserverDomain) output.publicKey = await doipjs.keys.fetchHKP(sanitizedId, keyserverDomain)
} catch (error) { } catch (error) {
reject(new Error('No public keys could be fetched using HKP')) reject(new Error('No public keys could be fetched using HKP'))
} }