Fix support for keybase keys

This commit is contained in:
Yarmo Mackenbach 2021-05-02 23:05:40 +02:00
parent d1f194128d
commit 88afb49e18
No known key found for this signature in database
GPG key ID: 37367F4AF4087AD1
3 changed files with 57 additions and 1 deletions

View file

@ -59,7 +59,11 @@ router.get('/hkp/:server/:id', async (req, res) => {
})
router.get('/keybase/:username/:fingerprint', async (req, res) => {
res.render('profile', { mode: 'keybase', uid: `${req.params.username}/${req.params.fingerprint}` })
const data = await kx.generateKeybaseProfile(req.params.username, req.params.fingerprint)
if (data.errors.length > 0) {
return res.render('profile-failed', { data: data })
}
res.render('profile', { data: data })
})
router.get('/:id', async (req, res) => {
@ -69,6 +73,9 @@ router.get('/:id', async (req, res) => {
} else {
data = await kx.generateHKPProfile(req.params.id)
}
if (data.errors.length > 0) {
return res.render('profile-failed', { data: data })
}
res.render('profile', { data: data })
})

View file

@ -81,6 +81,31 @@ const generateHKPProfile = async (id, keyserverDomain) => {
})
}
const generateKeybaseProfile = async (username, fingerprint) => {
return keys.fetchKeybase(id, keyserverDomain)
.then(async key => {
let keyData = await doip.keys.process(key.publicKey)
keyData.key.fetchMethod = 'hkp'
keyData.key.uri = key.fetchURL
keyData = processKeyData(keyData)
return {
key: key,
keyData: keyData,
extra: await computeExtraData(key, keyData),
errors: []
}
})
.catch(err => {
return {
key: null,
keyData: null,
extra: null,
errors: [err.message]
}
})
}
const processKeyData = (keyData) => {
keyData.users.forEach(user => {
// Match claims
@ -120,3 +145,4 @@ const computeExtraData = async (key, keyData) => {
exports.generateWKDProfile = generateWKDProfile
exports.generateHKPProfile = generateHKPProfile
exports.generateKeybaseProfile = generateKeybaseProfile

View file

@ -118,5 +118,28 @@ const fetchHKP = (id, keyserverDomain) => {
})
}
const fetchKeybase = (username, fingerprint) => {
return new Promise(async (resolve, reject) => {
let output = {
publicKey: null,
fetchURL: null
}
try {
output.publicKey = await doip.keys.fetchKeybase(username, fingerprint)
output.fetchURL = `https://keybase.io/${username}`
} catch(error) {
reject(new Error("No public keys could be fetched from Keybase"))
}
if (!output.publicKey) {
reject(new Error("No public keys could be fetched from Keybase"))
}
resolve(output)
})
}
exports.fetchWKD = fetchWKD
exports.fetchHKP = fetchHKP
exports.fetchKeybase = fetchKeybase