mirror of
https://codeberg.org/keyoxide/keyoxide-web.git
synced 2025-01-10 15:19:28 -07:00
Fix support for keybase keys
This commit is contained in:
parent
d1f194128d
commit
88afb49e18
3 changed files with 57 additions and 1 deletions
|
@ -59,7 +59,11 @@ router.get('/hkp/:server/:id', async (req, res) => {
|
||||||
})
|
})
|
||||||
|
|
||||||
router.get('/keybase/:username/:fingerprint', 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) => {
|
router.get('/:id', async (req, res) => {
|
||||||
|
@ -69,6 +73,9 @@ router.get('/:id', async (req, res) => {
|
||||||
} else {
|
} else {
|
||||||
data = await kx.generateHKPProfile(req.params.id)
|
data = await kx.generateHKPProfile(req.params.id)
|
||||||
}
|
}
|
||||||
|
if (data.errors.length > 0) {
|
||||||
|
return res.render('profile-failed', { data: data })
|
||||||
|
}
|
||||||
res.render('profile', { data: data })
|
res.render('profile', { data: data })
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -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) => {
|
const processKeyData = (keyData) => {
|
||||||
keyData.users.forEach(user => {
|
keyData.users.forEach(user => {
|
||||||
// Match claims
|
// Match claims
|
||||||
|
@ -120,3 +145,4 @@ const computeExtraData = async (key, keyData) => {
|
||||||
|
|
||||||
exports.generateWKDProfile = generateWKDProfile
|
exports.generateWKDProfile = generateWKDProfile
|
||||||
exports.generateHKPProfile = generateHKPProfile
|
exports.generateHKPProfile = generateHKPProfile
|
||||||
|
exports.generateKeybaseProfile = generateKeybaseProfile
|
||||||
|
|
|
@ -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.fetchWKD = fetchWKD
|
||||||
exports.fetchHKP = fetchHKP
|
exports.fetchHKP = fetchHKP
|
||||||
|
exports.fetchKeybase = fetchKeybase
|
||||||
|
|
Loading…
Reference in a new issue