Key generation: do not clear private MPIs for keys without passphrase.

This commit is contained in:
Thomas Oberndörfer 2014-07-30 16:36:01 +02:00
parent 8a27866225
commit 060da64aab
3 changed files with 16 additions and 0 deletions

View File

@ -916,6 +916,10 @@ function generate(options) {
if (options.keyType !== enums.publicKey.rsa_encrypt_sign) {
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();

View File

@ -279,6 +279,9 @@ SecretKey.prototype.generate = function (bits) {
* Clear private MPIs, return to initial state
*/
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.isDecrypted = false;
};

View File

@ -636,4 +636,13 @@ describe("Signature", function() {
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;
});
});