Key generation: do not clear private MPIs for keys without passphrase.
This commit is contained in:
parent
8a27866225
commit
060da64aab
|
@ -916,6 +916,10 @@ function generate(options) {
|
||||||
if (options.keyType !== enums.publicKey.rsa_encrypt_sign) {
|
if (options.keyType !== enums.publicKey.rsa_encrypt_sign) {
|
||||||
throw new Error('Only RSA Encrypt or Sign supported');
|
throw new Error('Only RSA Encrypt or Sign supported');
|
||||||
}
|
}
|
||||||
|
// Key without passphrase is unlocked by definition
|
||||||
|
if (!options.passphrase) {
|
||||||
|
options.unlocked = true;
|
||||||
|
}
|
||||||
|
|
||||||
var packetlist = new packet.List();
|
var packetlist = new packet.List();
|
||||||
|
|
||||||
|
|
|
@ -279,6 +279,9 @@ SecretKey.prototype.generate = function (bits) {
|
||||||
* Clear private MPIs, return to initial state
|
* Clear private MPIs, return to initial state
|
||||||
*/
|
*/
|
||||||
SecretKey.prototype.clearPrivateMPIs = function () {
|
SecretKey.prototype.clearPrivateMPIs = function () {
|
||||||
|
if (!this.encrypted) {
|
||||||
|
throw new Error('If secret key is not encrypted, clearing private MPIs is irreversible.');
|
||||||
|
}
|
||||||
this.mpi = this.mpi.slice(0, crypto.getPublicMpiCount(this.algorithm));
|
this.mpi = this.mpi.slice(0, crypto.getPublicMpiCount(this.algorithm));
|
||||||
this.isDecrypted = false;
|
this.isDecrypted = false;
|
||||||
};
|
};
|
||||||
|
|
|
@ -636,4 +636,13 @@ describe("Signature", function() {
|
||||||
expect(result[0].valid).to.be.true;
|
expect(result[0].valid).to.be.true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Sign message with key without password', function() {
|
||||||
|
var key = openpgp.generateKeyPair({numBits: 512, userId: 'ABC', passphrase: null}).key;
|
||||||
|
|
||||||
|
var message = openpgp.message.fromText('hello world');
|
||||||
|
message = message.sign([key]);
|
||||||
|
|
||||||
|
expect(message).to.exist;
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user