Skip to content
This repository was archived by the owner on Jul 10, 2019. It is now read-only.

Commit e072f11

Browse files
author
Tankred Hase
committed
[WO-510] fix toBigInteger bug
* Add tests to reconstruct the issue * Upgrade to OpenPGP.js v0.7.2
1 parent 1e7255f commit e072f11

File tree

2 files changed

+52
-5
lines changed

2 files changed

+52
-5
lines changed

src/lib/openpgp/openpgp.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -1510,7 +1510,7 @@ module.exports = {
15101510

15111511
show_version: true,
15121512
show_comment: true,
1513-
versionstring: "OpenPGP.js v0.7.1",
1513+
versionstring: "OpenPGP.js v0.7.2",
15141514
commentstring: "Whiteout Mail - https://whiteout.io",
15151515

15161516
keyserver: "keyserver.linux.it", // "pgp.mit.edu:11371"
@@ -11767,6 +11767,10 @@ function generate(options) {
1176711767
if (options.keyType !== enums.publicKey.rsa_encrypt_sign) {
1176811768
throw new Error('Only RSA Encrypt or Sign supported');
1176911769
}
11770+
// Key without passphrase is unlocked by definition
11771+
if (!options.passphrase) {
11772+
options.unlocked = true;
11773+
}
1177011774

1177111775
var packetlist = new packet.List();
1177211776

@@ -14657,6 +14661,9 @@ SecretKey.prototype.generate = function (bits) {
1465714661
* Clear private MPIs, return to initial state
1465814662
*/
1465914663
SecretKey.prototype.clearPrivateMPIs = function () {
14664+
if (!this.encrypted) {
14665+
throw new Error('If secret key is not encrypted, clearing private MPIs is irreversible.');
14666+
}
1466014667
this.mpi = this.mpi.slice(0, crypto.getPublicMpiCount(this.algorithm));
1466114668
this.isDecrypted = false;
1466214669
};

test/unit/pgp-test.js

+44-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ define(function(require) {
1414
keySize = 512,
1515
keyId = 'F6F60E9B42CDFF4C',
1616
pubkey = '-----BEGIN PGP PUBLIC KEY BLOCK-----\r\n' +
17-
'Version: OpenPGP.js v0.7.1\r\n' +
17+
'Version: OpenPGP.js v0.7.2\r\n' +
1818
'Comment: Whiteout Mail - https://whiteout.io\r\n' +
1919
'\r\n' +
2020
'xk0EUlhMvAEB/2MZtCUOAYvyLFjDp3OBMGn3Ev8FwjzyPbIF0JUw+L7y2XR5\r\n' +
@@ -25,7 +25,7 @@ define(function(require) {
2525
'=6XMW\r\n' +
2626
'-----END PGP PUBLIC KEY BLOCK-----\r\n\r\n',
2727
privkey = '-----BEGIN PGP PRIVATE KEY BLOCK-----\r\n' +
28-
'Version: OpenPGP.js v0.7.1\r\n' +
28+
'Version: OpenPGP.js v0.7.2\r\n' +
2929
'Comment: Whiteout Mail - https://whiteout.io\r\n' +
3030
'\r\n' +
3131
'xcBeBFJYTLwBAf9jGbQlDgGL8ixYw6dzgTBp9xL/BcI88j2yBdCVMPi+8tl0\r\n' +
@@ -80,7 +80,27 @@ define(function(require) {
8080
expect(keys.keyId).to.exist;
8181
expect(keys.privateKeyArmored).to.exist;
8282
expect(keys.publicKeyArmored).to.exist;
83-
done();
83+
84+
// test encrypt/decrypt
85+
pgp.importKeys({
86+
passphrase: passphrase,
87+
privateKeyArmored: keys.privateKeyArmored,
88+
publicKeyArmored: keys.publicKeyArmored
89+
}, function(err) {
90+
expect(err).to.not.exist;
91+
92+
pgp.encrypt('secret', [keys.publicKeyArmored], function(err, ct) {
93+
expect(err).to.not.exist;
94+
expect(ct).to.exist;
95+
96+
pgp.decrypt(ct, keys.publicKeyArmored, function(err, pt, signValid) {
97+
expect(err).to.not.exist;
98+
expect(pt).to.equal('secret');
99+
expect(signValid).to.be.true;
100+
done();
101+
});
102+
});
103+
});
84104
});
85105
});
86106
it('should work without passphrase', function(done) {
@@ -93,7 +113,27 @@ define(function(require) {
93113
expect(keys.keyId).to.exist;
94114
expect(keys.privateKeyArmored).to.exist;
95115
expect(keys.publicKeyArmored).to.exist;
96-
done();
116+
117+
// test encrypt/decrypt
118+
pgp.importKeys({
119+
passphrase: undefined,
120+
privateKeyArmored: keys.privateKeyArmored,
121+
publicKeyArmored: keys.publicKeyArmored
122+
}, function(err) {
123+
expect(err).to.not.exist;
124+
125+
pgp.encrypt('secret', [keys.publicKeyArmored], function(err, ct) {
126+
expect(err).to.not.exist;
127+
expect(ct).to.exist;
128+
129+
pgp.decrypt(ct, keys.publicKeyArmored, function(err, pt, signValid) {
130+
expect(err).to.not.exist;
131+
expect(pt).to.equal('secret');
132+
expect(signValid).to.be.true;
133+
done();
134+
});
135+
});
136+
});
97137
});
98138
});
99139
});

0 commit comments

Comments
 (0)