Skip to content

Commit

Permalink
Use V5 keys by default (#1063)
Browse files Browse the repository at this point in the history
  • Loading branch information
larabr committed Jan 13, 2021
1 parent cd2f7e1 commit 56cb1b3
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 34 deletions.
5 changes: 2 additions & 3 deletions src/config/config.js
Expand Up @@ -69,12 +69,11 @@ export default {
aead_chunk_size_byte: 12,
/**
* Use V5 keys.
* **NOT INTEROPERABLE WITH OTHER OPENPGP IMPLEMENTATIONS**
* **FUTURE OPENPGP.JS VERSIONS MAY BREAK COMPATIBILITY WHEN USING THIS OPTION**
* Note: not all OpenPGP implementations are compatible with this option
* @memberof module:config
* @property {Boolean} v5_keys
*/
v5_keys: false,
v5_keys: true,
/**
* {@link https://tools.ietf.org/html/rfc4880#section-3.7.1.3|RFC4880 3.7.1.3}:
* Iteration Count Byte for S2K (String to Key)
Expand Down
2 changes: 0 additions & 2 deletions src/packet/signature.js
Expand Up @@ -99,8 +99,6 @@ function Signature(date = new Date()) {
/**
* parsing function for a signature packet (tag 2).
* @param {String} bytes payload of a tag 2 packet
* @param {Integer} position position to start reading from the bytes string
* @param {Integer} len length of the packet or the remaining length of bytes at position
* @returns {module:packet.Signature} object representation
*/
Signature.prototype.read = function (bytes) {
Expand Down
20 changes: 17 additions & 3 deletions test/general/key.js
Expand Up @@ -2545,6 +2545,8 @@ function versionSpecificTests() {

describe('Key', function() {
let rsaGenStub;
let v5_keysVal;
let aead_protectVal;
let rsaGenValue = openpgp.crypto.publicKey.rsa.generate(openpgp.util.getWebCryptoAll() ? 2048 : 512, "10001");

beforeEach(function() {
Expand All @@ -2557,11 +2559,25 @@ describe('Key', function() {
});

tryTests('V4', versionSpecificTests, {
if: !openpgp.config.ci
if: !openpgp.config.ci,
beforeEach: function() {
v5_keysVal = openpgp.config.v5_keys;
openpgp.config.v5_keys = false;
},
afterEach: function() {
openpgp.config.v5_keys = v5_keysVal;
}
});

tryTests('V4 - With Worker', versionSpecificTests, {
if: typeof window !== 'undefined' && window.Worker,
beforeEach: function() {
v5_keysVal = openpgp.config.v5_keys;
openpgp.config.v5_keys = false;
},
afterEach: function() {
openpgp.config.v5_keys = v5_keysVal;
},
before: async function() {
try {
await openpgp.initWorker({ path: '../dist/openpgp.worker.js' });
Expand All @@ -2574,8 +2590,6 @@ describe('Key', function() {
}
});

let v5_keysVal;
let aead_protectVal;
tryTests('V5', versionSpecificTests, {
if: !openpgp.config.ci,
beforeEach: function() {
Expand Down
52 changes: 26 additions & 26 deletions test/general/packet.js
Expand Up @@ -910,41 +910,41 @@ V+HOQJQxXJkVRYa3QrFUehiMzTeqqMdgC6ZqJy7+
const keySize = openpgp.util.getWebCryptoAll() ? 2048 : 512; // webkit webcrypto accepts minimum 2048 bit keys

return rsa.generate(keySize, "10001").then(function(mpiGen) {
let mpi = [mpiGen.n, mpiGen.e, mpiGen.d, mpiGen.p, mpiGen.q, mpiGen.u];
mpi = mpi.map(function(k) {
return new openpgp.MPI(k);
});
const testText = input.createSomeMessage();
let mpi = [mpiGen.n, mpiGen.e, mpiGen.d, mpiGen.p, mpiGen.q, mpiGen.u];
mpi = mpi.map(function(k) {
return new openpgp.MPI(k);
});
const testText = input.createSomeMessage();

key.params = mpi;
key.algorithm = "rsa_sign";
key.params = mpi;
key.algorithm = "rsa_sign";

const signed = new openpgp.packet.List();
const literal = new openpgp.packet.Literal();
const signature = new openpgp.packet.Signature();
const signed = new openpgp.packet.List();
const literal = new openpgp.packet.Literal();
const signature = new openpgp.packet.Signature();

literal.setText(testText);
literal.setText(testText);

signature.hashAlgorithm = 'sha256';
signature.publicKeyAlgorithm = 'rsa_sign';
signature.signatureType = 'text';
signature.hashAlgorithm = openpgp.enums.hash.sha256;
signature.publicKeyAlgorithm = openpgp.enums.publicKey.rsa_sign;
signature.signatureType = openpgp.enums.signature.text;

return signature.sign(key, literal).then(async () => {
return signature.sign(key, literal).then(async () => {

signed.push(literal);
signed.push(signature);
signed.push(literal);
signed.push(signature);

const raw = signed.write();
const raw = signed.write();

const signed2 = new openpgp.packet.List();
await signed2.read(raw);
signed2.concat(await openpgp.stream.readToEnd(signed2.stream, arr => arr));
const signed2 = new openpgp.packet.List();
await signed2.read(raw);
signed2.concat(await openpgp.stream.readToEnd(signed2.stream, arr => arr));

await Promise.all([
expect(signed2[1].verify(key, openpgp.enums.signature.text, signed2[0])).to.eventually.be.true,
openpgp.stream.pipe(signed2[0].getBytes(), new openpgp.stream.WritableStream())
]);
});
await Promise.all([
expect(signed2[1].verify(key, openpgp.enums.signature.text, signed2[0])).to.eventually.be.true,
openpgp.stream.pipe(signed2[0].getBytes(), new openpgp.stream.WritableStream())
]);
});
});
});
});

0 comments on commit 56cb1b3

Please sign in to comment.