Fix HKP index, accept fingerprint for lookup

This commit is contained in:
Tankred Hase
2016-06-02 22:55:32 +02:00
parent 20145d3a11
commit 41cbd55d9e
3 changed files with 41 additions and 11 deletions

View File

@@ -154,8 +154,8 @@ class PublicKey {
*get(options) {
let keyid = options.keyid, email = options.email;
let verified = yield this._userId.getVerfied({
keyid: keyid ? keyid.toUpperCase() : undefined,
userIds: email ? [{ email:email.toLowerCase() }] : undefined
keyid: this._formatKeyId(keyid),
userIds: this._formatUserIds(email)
});
if (!verified) {
util.throw(404, 'Key not found');
@@ -166,6 +166,29 @@ class PublicKey {
return params;
}
/**
* Convert key id to the format used in the database.
* @param {string} keyid the public key id
* @return {string} the formatted key id
*/
_formatKeyId(keyid) {
if (!util.isString(keyid)) {
return;
}
keyid = keyid.toUpperCase(); // use uppercase key ids
let len = keyid.length;
return (len > 16) ? keyid.substr(len - 16, len) : keyid; // shorten to 16 bytes
}
/**
* Format the email address to the format used in the database.
* @param {[type]} email [description]
* @return {[type]} [description]
*/
_formatUserIds(email) {
return email ? [{ email:email.toLowerCase() }] : undefined;
}
/**
* Request removal of the public key by flagging all user ids and sending
* a verification email to the primary email address. Only one email