Skip to content

Commit 9f5e3f6

Browse files
committed
Add support for search with wkd hash
1 parent 1d7b0b0 commit 9f5e3f6

2 files changed

Lines changed: 19 additions & 7 deletions

File tree

src/modules/public-key.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ class PublicKey {
244244
* @param {String} keyId (optional) The public key ID
245245
* @return {Promise<Object>} The verified key document
246246
*/
247-
async getVerified({userIds, fingerprint, keyId}) {
247+
async getVerified({userIds, fingerprint, keyId, wkd}) {
248248
let queries = [];
249249
// query by fingerprint
250250
if (fingerprint) {
@@ -260,8 +260,19 @@ class PublicKey {
260260
'userIds.verified': true
261261
});
262262
}
263-
// query by user ID
264-
if (userIds) {
263+
// query by wkd hash
264+
if (userIds && wkd) {
265+
queries = queries.concat(userIds.map(uid => ({
266+
userIds: {
267+
$elemMatch: {
268+
'wkdhash': uid.email,
269+
'verified': true
270+
}
271+
}
272+
})));
273+
}
274+
// query by user id
275+
if (userIds && !wkd) {
265276
queries = queries.concat(userIds.map(uid => ({
266277
userIds: {
267278
$elemMatch: {
@@ -283,10 +294,10 @@ class PublicKey {
283294
* @param {Object} i18n i18n object
284295
* @return {Promise<Object>} The public key document
285296
*/
286-
async get({fingerprint, keyId, email, i18n}) {
297+
async get({fingerprint, keyId, email, wkd, i18n}) {
287298
// look for verified key
288299
const userIds = email ? [{email}] : undefined;
289-
const key = await this.getVerified({keyId, fingerprint, userIds});
300+
const key = await this.getVerified({keyId, fingerprint, userIds, wkd});
290301
if (!key) {
291302
throw Boom.notFound(i18n.__('key_not_found'));
292303
}

src/route/hkp.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class HKP {
4646
const params = this.parseQueryString(request);
4747
const key = await this._publicKey.get({...params, i18n: request.i18n});
4848
if (params.op === 'get') {
49-
if (params.mr) {
49+
if (params.mr || params.wkd) {
5050
return h.response(key.publicKeyArmored)
5151
.header('Content-Type', 'application/pgp-keys; charset=utf-8')
5252
.header('Content-Disposition', 'attachment; filename=openpgp-key.asc');
@@ -84,7 +84,8 @@ class HKP {
8484
parseQueryString({query}) {
8585
const params = {
8686
op: query.op, // operation ... only 'get' is supported
87-
mr: query.options === 'mr' // machine readable
87+
mr: query.options === 'mr', // machine readable
88+
wkd: query.options === 'wkd' // wkd hash
8889
};
8990
if (!['get', 'index', 'vindex'].includes(params.op)) {
9091
throw Boom.notImplemented('Method not implemented');

0 commit comments

Comments
 (0)