From b2b1a1a8d0b22395af64def8e3f9adf9d58a010a Mon Sep 17 00:00:00 2001 From: Yarmo Mackenbach Date: Tue, 11 Oct 2022 15:14:53 +0200 Subject: [PATCH] Attempt both WKD and HKP if no protocol specified --- routes/profile.js | 9 ++------- server/index.js | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/routes/profile.js b/routes/profile.js index efc6393..a618b33 100644 --- a/routes/profile.js +++ b/routes/profile.js @@ -29,7 +29,7 @@ more information on this, and how to apply and follow the GNU AGPL, see { }) router.get('/:id', async (req, res) => { - let data - if (req.params.id.includes('@')) { - data = await generateWKDProfile(req.params.id) - } else { - data = await generateHKPProfile(req.params.id) - } + const data = await generateAutoProfile(req.params.id) const title = utils.generatePageTitle('profile', data) res.set('ariadne-identity-proof', data.keyData.openpgp4fpr) res.render('profile', { title: title, data: data }) diff --git a/server/index.js b/server/index.js index a856f1e..67ae81b 100644 --- a/server/index.js +++ b/server/index.js @@ -99,6 +99,31 @@ const generateHKPProfile = async (id, keyserverDomain) => { }) } +const generateAutoProfile = async (id) => { + let result + + if (id.includes('@')) { + result = await generateWKDProfile(id) + + if (result && result.errors.length === 0) { + return result + } + } + + result = await generateHKPProfile(id) + if (result && result.errors.length === 0) { + return result + } + + return { + key: {}, + keyData: {}, + keyoxide: {}, + extra: {}, + errors: ["No public keys could be found"] + } +} + const generateSignatureProfile = async (signature) => { return fetchSignature(signature) .then(async key => { @@ -203,6 +228,7 @@ const computeExtraData = async (key, keyData) => { export { generateWKDProfile } export { generateHKPProfile } +export { generateAutoProfile } export { generateKeybaseProfile } export { generateSignatureProfile }