[WO-510] fix toBigInteger bug

* Add tests to reconstruct the issue
* Upgrade to OpenPGP.js v0.7.2
This commit is contained in:
Tankred Hase 2014-07-30 17:31:56 +02:00
parent 1e7255f8ce
commit e072f118ca
2 changed files with 52 additions and 5 deletions

View File

@ -1510,7 +1510,7 @@ module.exports = {
show_version: true,
show_comment: true,
versionstring: "OpenPGP.js v0.7.1",
versionstring: "OpenPGP.js v0.7.2",
commentstring: "Whiteout Mail - https://whiteout.io",
keyserver: "keyserver.linux.it", // "pgp.mit.edu:11371"
@ -11767,6 +11767,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();
@ -14657,6 +14661,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

@ -14,7 +14,7 @@ define(function(require) {
keySize = 512,
keyId = 'F6F60E9B42CDFF4C',
pubkey = '-----BEGIN PGP PUBLIC KEY BLOCK-----\r\n' +
'Version: OpenPGP.js v0.7.1\r\n' +
'Version: OpenPGP.js v0.7.2\r\n' +
'Comment: Whiteout Mail - https://whiteout.io\r\n' +
'\r\n' +
'xk0EUlhMvAEB/2MZtCUOAYvyLFjDp3OBMGn3Ev8FwjzyPbIF0JUw+L7y2XR5\r\n' +
@ -25,7 +25,7 @@ define(function(require) {
'=6XMW\r\n' +
'-----END PGP PUBLIC KEY BLOCK-----\r\n\r\n',
privkey = '-----BEGIN PGP PRIVATE KEY BLOCK-----\r\n' +
'Version: OpenPGP.js v0.7.1\r\n' +
'Version: OpenPGP.js v0.7.2\r\n' +
'Comment: Whiteout Mail - https://whiteout.io\r\n' +
'\r\n' +
'xcBeBFJYTLwBAf9jGbQlDgGL8ixYw6dzgTBp9xL/BcI88j2yBdCVMPi+8tl0\r\n' +
@ -80,7 +80,27 @@ define(function(require) {
expect(keys.keyId).to.exist;
expect(keys.privateKeyArmored).to.exist;
expect(keys.publicKeyArmored).to.exist;
done();
// test encrypt/decrypt
pgp.importKeys({
passphrase: passphrase,
privateKeyArmored: keys.privateKeyArmored,
publicKeyArmored: keys.publicKeyArmored
}, function(err) {
expect(err).to.not.exist;
pgp.encrypt('secret', [keys.publicKeyArmored], function(err, ct) {
expect(err).to.not.exist;
expect(ct).to.exist;
pgp.decrypt(ct, keys.publicKeyArmored, function(err, pt, signValid) {
expect(err).to.not.exist;
expect(pt).to.equal('secret');
expect(signValid).to.be.true;
done();
});
});
});
});
});
it('should work without passphrase', function(done) {
@ -93,7 +113,27 @@ define(function(require) {
expect(keys.keyId).to.exist;
expect(keys.privateKeyArmored).to.exist;
expect(keys.publicKeyArmored).to.exist;
done();
// test encrypt/decrypt
pgp.importKeys({
passphrase: undefined,
privateKeyArmored: keys.privateKeyArmored,
publicKeyArmored: keys.publicKeyArmored
}, function(err) {
expect(err).to.not.exist;
pgp.encrypt('secret', [keys.publicKeyArmored], function(err, ct) {
expect(err).to.not.exist;
expect(ct).to.exist;
pgp.decrypt(ct, keys.publicKeyArmored, function(err, pt, signValid) {
expect(err).to.not.exist;
expect(pt).to.equal('secret');
expect(signValid).to.be.true;
done();
});
});
});
});
});
});