gracefully handle reformatting keys with no subkey packets
This commit is contained in:
parent
0a4e9461ca
commit
18e46ed6cf
|
@ -1272,6 +1272,9 @@ export function reformat(options) {
|
||||||
options.subkeyType = secretSubkeyPacket.algorithm;
|
options.subkeyType = secretSubkeyPacket.algorithm;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!secretKeyPacket) {
|
||||||
|
throw new Error('Key does not contain a secret key packet');
|
||||||
|
}
|
||||||
return wrapKeyObject(secretKeyPacket, secretSubkeyPacket, options);
|
return wrapKeyObject(secretKeyPacket, secretSubkeyPacket, options);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1280,8 +1283,10 @@ async function wrapKeyObject(secretKeyPacket, secretSubkeyPacket, options) {
|
||||||
// set passphrase protection
|
// set passphrase protection
|
||||||
if (options.passphrase) {
|
if (options.passphrase) {
|
||||||
secretKeyPacket.encrypt(options.passphrase);
|
secretKeyPacket.encrypt(options.passphrase);
|
||||||
|
if (secretSubkeyPacket) {
|
||||||
secretSubkeyPacket.encrypt(options.passphrase);
|
secretSubkeyPacket.encrypt(options.passphrase);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var packetlist = new packet.List();
|
var packetlist = new packet.List();
|
||||||
|
|
||||||
|
@ -1336,6 +1341,7 @@ async function wrapKeyObject(secretKeyPacket, secretSubkeyPacket, options) {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (secretSubkeyPacket) {
|
||||||
var dataToSign = {};
|
var dataToSign = {};
|
||||||
dataToSign.key = secretKeyPacket;
|
dataToSign.key = secretKeyPacket;
|
||||||
dataToSign.bind = secretSubkeyPacket;
|
dataToSign.bind = secretSubkeyPacket;
|
||||||
|
@ -1352,11 +1358,14 @@ async function wrapKeyObject(secretKeyPacket, secretSubkeyPacket, options) {
|
||||||
|
|
||||||
packetlist.push(secretSubkeyPacket);
|
packetlist.push(secretSubkeyPacket);
|
||||||
packetlist.push(subkeySignaturePacket);
|
packetlist.push(subkeySignaturePacket);
|
||||||
|
}
|
||||||
|
|
||||||
if (!options.unlocked) {
|
if (!options.unlocked) {
|
||||||
secretKeyPacket.clearPrivateParams();
|
secretKeyPacket.clearPrivateParams();
|
||||||
|
if (secretSubkeyPacket) {
|
||||||
secretSubkeyPacket.clearPrivateParams();
|
secretSubkeyPacket.clearPrivateParams();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return new Key(packetlist);
|
return new Key(packetlist);
|
||||||
}
|
}
|
||||||
|
|
|
@ -126,6 +126,7 @@ export function generateKey({ userIds=[], passphrase, numBits=2048, unlocked=fal
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reformats signature packets for a key and rewraps key object.
|
* Reformats signature packets for a key and rewraps key object.
|
||||||
|
* @param {Key} privateKey private key to reformat
|
||||||
* @param {Array<Object>} userIds array of user IDs e.g. [{ name:'Phil Zimmermann', email:'phil@openpgp.org' }]
|
* @param {Array<Object>} userIds array of user IDs e.g. [{ name:'Phil Zimmermann', email:'phil@openpgp.org' }]
|
||||||
* @param {String} passphrase (optional) The passphrase used to encrypt the resulting private key
|
* @param {String} passphrase (optional) The passphrase used to encrypt the resulting private key
|
||||||
* @param {Boolean} unlocked (optional) If the returned secret part of the generated key is unlocked
|
* @param {Boolean} unlocked (optional) If the returned secret part of the generated key is unlocked
|
||||||
|
|
Loading…
Reference in New Issue
Block a user