Attempt both WKD and HKP if no protocol specified

This commit is contained in:
Yarmo Mackenbach 2022-10-11 15:14:53 +02:00
parent b0ca9e7bd0
commit b2b1a1a8d0
No known key found for this signature in database
GPG key ID: 37367F4AF4087AD1
2 changed files with 28 additions and 7 deletions

View file

@ -29,7 +29,7 @@ more information on this, and how to apply and follow the GNU AGPL, see <https:/
*/
import express from 'express'
import bodyParserImport from 'body-parser'
import { generateSignatureProfile, utils, generateWKDProfile, generateHKPProfile, generateKeybaseProfile } from '../server/index.js'
import { generateSignatureProfile, utils, generateWKDProfile, generateHKPProfile, generateAutoProfile, generateKeybaseProfile } from '../server/index.js'
const router = express.Router()
const bodyParser = bodyParserImport.urlencoded({ extended: false })
@ -74,12 +74,7 @@ router.get('/keybase/:username/:fingerprint', async (req, res) => {
})
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 })

View file

@ -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 }