mirror of
https://github.com/openpgpjs/openpgpjs.git
synced 2025-06-07 14:46:42 +00:00
Replace config.v5Keys with config.v6Keys flag
Also, don't generate v5 keys flag, which has been removed from the draft specification.
This commit is contained in:
parent
31c2a2575d
commit
8816bd7541
2
openpgp.d.ts
vendored
2
openpgp.d.ts
vendored
@ -329,7 +329,7 @@ interface Config {
|
|||||||
allowInsecureVerificationWithReformattedKeys: boolean;
|
allowInsecureVerificationWithReformattedKeys: boolean;
|
||||||
constantTimePKCS1Decryption: boolean;
|
constantTimePKCS1Decryption: boolean;
|
||||||
constantTimePKCS1DecryptionSupportedSymmetricAlgorithms: Set<enums.symmetric>;
|
constantTimePKCS1DecryptionSupportedSymmetricAlgorithms: Set<enums.symmetric>;
|
||||||
v5Keys: boolean;
|
v6Keys: boolean;
|
||||||
preferredAEADAlgorithm: enums.aead;
|
preferredAEADAlgorithm: enums.aead;
|
||||||
aeadChunkSizeByte: number;
|
aeadChunkSizeByte: number;
|
||||||
s2kType: enums.s2k.iterated | enums.s2k.argon2;
|
s2kType: enums.s2k.iterated | enums.s2k.argon2;
|
||||||
|
@ -68,13 +68,13 @@ export default {
|
|||||||
*/
|
*/
|
||||||
aeadChunkSizeByte: 12,
|
aeadChunkSizeByte: 12,
|
||||||
/**
|
/**
|
||||||
* Use V5 keys.
|
* Use v6 keys.
|
||||||
* Note: not all OpenPGP implementations are compatible with this option.
|
* Note: not all OpenPGP implementations are compatible with this option.
|
||||||
* **FUTURE OPENPGP.JS VERSIONS MAY BREAK COMPATIBILITY WHEN USING THIS OPTION**
|
* **FUTURE OPENPGP.JS VERSIONS MAY BREAK COMPATIBILITY WHEN USING THIS OPTION**
|
||||||
* @memberof module:config
|
* @memberof module:config
|
||||||
* @property {Boolean} v5Keys
|
* @property {Boolean} v6Keys
|
||||||
*/
|
*/
|
||||||
v5Keys: false,
|
v6Keys: false,
|
||||||
/**
|
/**
|
||||||
* S2K (String to Key) type, used for key derivation in the context of secret key encryption
|
* S2K (String to Key) type, used for key derivation in the context of secret key encryption
|
||||||
* and password-encrypted data. Weaker s2k options are not allowed.
|
* and password-encrypted data. Weaker s2k options are not allowed.
|
||||||
|
@ -232,9 +232,6 @@ async function wrapKeyObject(secretKeyPacket, secretSubkeyPackets, options, conf
|
|||||||
if (config.aeadProtect) {
|
if (config.aeadProtect) {
|
||||||
signatureProperties.features[0] |= enums.features.aead;
|
signatureProperties.features[0] |= enums.features.aead;
|
||||||
}
|
}
|
||||||
if (config.v5Keys) {
|
|
||||||
signatureProperties.features[0] |= enums.features.v5Keys;
|
|
||||||
}
|
|
||||||
if (options.keyExpirationTime > 0) {
|
if (options.keyExpirationTime > 0) {
|
||||||
signatureProperties.keyExpirationTime = options.keyExpirationTime;
|
signatureProperties.keyExpirationTime = options.keyExpirationTime;
|
||||||
signatureProperties.keyNeverExpires = false;
|
signatureProperties.keyNeverExpires = false;
|
||||||
|
@ -47,7 +47,7 @@ class PublicKeyPacket {
|
|||||||
* Packet version
|
* Packet version
|
||||||
* @type {Integer}
|
* @type {Integer}
|
||||||
*/
|
*/
|
||||||
this.version = config.v5Keys ? 5 : 4;
|
this.version = config.v6Keys ? 6 : 4;
|
||||||
/**
|
/**
|
||||||
* Key creation date.
|
* Key creation date.
|
||||||
* @type {Date}
|
* @type {Date}
|
||||||
|
@ -116,10 +116,10 @@ n9/quqtmyOtYOA6gXNCw0Fal3iANKBmsPmYI
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('openpgp.generateKey', async function() {
|
it('openpgp.generateKey', async function() {
|
||||||
const v5KeysVal = openpgp.config.v5Keys;
|
const v6KeysVal = openpgp.config.v6Keys;
|
||||||
const preferredHashAlgorithmVal = openpgp.config.preferredHashAlgorithm;
|
const preferredHashAlgorithmVal = openpgp.config.preferredHashAlgorithm;
|
||||||
const showCommentVal = openpgp.config.showComment;
|
const showCommentVal = openpgp.config.showComment;
|
||||||
openpgp.config.v5Keys = false;
|
openpgp.config.v6Keys = false;
|
||||||
openpgp.config.preferredHashAlgorithm = openpgp.enums.hash.sha256;
|
openpgp.config.preferredHashAlgorithm = openpgp.enums.hash.sha256;
|
||||||
openpgp.config.showComment = false;
|
openpgp.config.showComment = false;
|
||||||
|
|
||||||
@ -134,7 +134,7 @@ n9/quqtmyOtYOA6gXNCw0Fal3iANKBmsPmYI
|
|||||||
expect(key.users[0].selfCertifications[0].preferredHashAlgorithms[0]).to.equal(openpgp.config.preferredHashAlgorithm);
|
expect(key.users[0].selfCertifications[0].preferredHashAlgorithms[0]).to.equal(openpgp.config.preferredHashAlgorithm);
|
||||||
|
|
||||||
const config = {
|
const config = {
|
||||||
v5Keys: true,
|
v6Keys: true,
|
||||||
showComment: true,
|
showComment: true,
|
||||||
preferredHashAlgorithm: openpgp.enums.hash.sha512
|
preferredHashAlgorithm: openpgp.enums.hash.sha512
|
||||||
};
|
};
|
||||||
@ -144,11 +144,11 @@ n9/quqtmyOtYOA6gXNCw0Fal3iANKBmsPmYI
|
|||||||
};
|
};
|
||||||
const { privateKey: privateKeyArmored2 } = await openpgp.generateKey(opt2);
|
const { privateKey: privateKeyArmored2 } = await openpgp.generateKey(opt2);
|
||||||
const key2 = await openpgp.readKey({ armoredKey: privateKeyArmored2 });
|
const key2 = await openpgp.readKey({ armoredKey: privateKeyArmored2 });
|
||||||
expect(key2.keyPacket.version).to.equal(5);
|
expect(key2.keyPacket.version).to.equal(6);
|
||||||
expect(privateKeyArmored2.indexOf(openpgp.config.commentString) > 0).to.be.true;
|
expect(privateKeyArmored2.indexOf(openpgp.config.commentString) > 0).to.be.true;
|
||||||
expect(key2.users[0].selfCertifications[0].preferredHashAlgorithms[0]).to.equal(config.preferredHashAlgorithm);
|
expect(key2.users[0].selfCertifications[0].preferredHashAlgorithms[0]).to.equal(config.preferredHashAlgorithm);
|
||||||
} finally {
|
} finally {
|
||||||
openpgp.config.v5Keys = v5KeysVal;
|
openpgp.config.v6Keys = v6KeysVal;
|
||||||
openpgp.config.preferredHashAlgorithm = preferredHashAlgorithmVal;
|
openpgp.config.preferredHashAlgorithm = preferredHashAlgorithmVal;
|
||||||
openpgp.config.showComment = showCommentVal;
|
openpgp.config.showComment = showCommentVal;
|
||||||
}
|
}
|
||||||
|
@ -2258,7 +2258,7 @@ function versionSpecificTests() {
|
|||||||
expect(key.users[0].selfCertifications[0].preferredCompressionAlgorithms).to.eql([compr.uncompressed, compr.zlib, compr.zip]);
|
expect(key.users[0].selfCertifications[0].preferredCompressionAlgorithms).to.eql([compr.uncompressed, compr.zlib, compr.zip]);
|
||||||
|
|
||||||
let expectedFeatures;
|
let expectedFeatures;
|
||||||
if (openpgp.config.v5Keys) {
|
if (openpgp.config.v6Keys) {
|
||||||
expectedFeatures = [7]; // v5 + aead + mdc
|
expectedFeatures = [7]; // v5 + aead + mdc
|
||||||
} else if (openpgp.config.aeadProtect) {
|
} else if (openpgp.config.aeadProtect) {
|
||||||
expectedFeatures = [3]; // aead + mdc
|
expectedFeatures = [3]; // aead + mdc
|
||||||
@ -2303,7 +2303,7 @@ function versionSpecificTests() {
|
|||||||
expect(key.users[0].selfCertifications[0].preferredCompressionAlgorithms).to.eql([compr.zip, compr.zlib, compr.uncompressed]);
|
expect(key.users[0].selfCertifications[0].preferredCompressionAlgorithms).to.eql([compr.zip, compr.zlib, compr.uncompressed]);
|
||||||
|
|
||||||
let expectedFeatures;
|
let expectedFeatures;
|
||||||
if (openpgp.config.v5Keys) {
|
if (openpgp.config.v6Keys) {
|
||||||
expectedFeatures = [7]; // v5 + aead + mdc
|
expectedFeatures = [7]; // v5 + aead + mdc
|
||||||
} else if (openpgp.config.aeadProtect) {
|
} else if (openpgp.config.aeadProtect) {
|
||||||
expectedFeatures = [3]; // aead + mdc
|
expectedFeatures = [3]; // aead + mdc
|
||||||
@ -2894,30 +2894,30 @@ function versionSpecificTests() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default () => describe('Key', function() {
|
export default () => describe('Key', function() {
|
||||||
let v5KeysVal;
|
let v6KeysVal;
|
||||||
let aeadProtectVal;
|
let aeadProtectVal;
|
||||||
|
|
||||||
tryTests('V4', versionSpecificTests, {
|
tryTests('V4', versionSpecificTests, {
|
||||||
if: !openpgp.config.ci,
|
if: !openpgp.config.ci,
|
||||||
beforeEach: function() {
|
beforeEach: function() {
|
||||||
v5KeysVal = openpgp.config.v5Keys;
|
v6KeysVal = openpgp.config.v6Keys;
|
||||||
openpgp.config.v5Keys = false;
|
openpgp.config.v6Keys = false;
|
||||||
},
|
},
|
||||||
afterEach: function() {
|
afterEach: function() {
|
||||||
openpgp.config.v5Keys = v5KeysVal;
|
openpgp.config.v6Keys = v6KeysVal;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
tryTests('V5', versionSpecificTests, {
|
tryTests('V6', versionSpecificTests, {
|
||||||
if: !openpgp.config.ci,
|
if: !openpgp.config.ci,
|
||||||
beforeEach: function() {
|
beforeEach: function() {
|
||||||
v5KeysVal = openpgp.config.v5Keys;
|
v6KeysVal = openpgp.config.v6Keys;
|
||||||
aeadProtectVal = openpgp.config.aeadProtect;
|
aeadProtectVal = openpgp.config.aeadProtect;
|
||||||
openpgp.config.v5Keys = true;
|
openpgp.config.v6Keys = true;
|
||||||
openpgp.config.aeadProtect = true;
|
openpgp.config.aeadProtect = true;
|
||||||
},
|
},
|
||||||
afterEach: function() {
|
afterEach: function() {
|
||||||
openpgp.config.v5Keys = v5KeysVal;
|
openpgp.config.v6Keys = v6KeysVal;
|
||||||
openpgp.config.aeadProtect = aeadProtectVal;
|
openpgp.config.aeadProtect = aeadProtectVal;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -2231,7 +2231,7 @@ XfA3pqV4mTzF
|
|||||||
let aeadProtectVal;
|
let aeadProtectVal;
|
||||||
let preferredAEADAlgorithmVal;
|
let preferredAEADAlgorithmVal;
|
||||||
let aeadChunkSizeByteVal;
|
let aeadChunkSizeByteVal;
|
||||||
let v5KeysVal;
|
let v6KeysVal;
|
||||||
let minRSABitsVal;
|
let minRSABitsVal;
|
||||||
|
|
||||||
beforeEach(async function() {
|
beforeEach(async function() {
|
||||||
@ -2248,7 +2248,7 @@ XfA3pqV4mTzF
|
|||||||
aeadProtectVal = openpgp.config.aeadProtect;
|
aeadProtectVal = openpgp.config.aeadProtect;
|
||||||
preferredAEADAlgorithmVal = openpgp.config.preferredAEADAlgorithm;
|
preferredAEADAlgorithmVal = openpgp.config.preferredAEADAlgorithm;
|
||||||
aeadChunkSizeByteVal = openpgp.config.aeadChunkSizeByte;
|
aeadChunkSizeByteVal = openpgp.config.aeadChunkSizeByte;
|
||||||
v5KeysVal = openpgp.config.v5Keys;
|
v6KeysVal = openpgp.config.v6Keys;
|
||||||
minRSABitsVal = openpgp.config.minRSABits;
|
minRSABitsVal = openpgp.config.minRSABits;
|
||||||
|
|
||||||
openpgp.config.minRSABits = 512;
|
openpgp.config.minRSABits = 512;
|
||||||
@ -2258,7 +2258,7 @@ XfA3pqV4mTzF
|
|||||||
openpgp.config.aeadProtect = aeadProtectVal;
|
openpgp.config.aeadProtect = aeadProtectVal;
|
||||||
openpgp.config.preferredAEADAlgorithm = preferredAEADAlgorithmVal;
|
openpgp.config.preferredAEADAlgorithm = preferredAEADAlgorithmVal;
|
||||||
openpgp.config.aeadChunkSizeByte = aeadChunkSizeByteVal;
|
openpgp.config.aeadChunkSizeByte = aeadChunkSizeByteVal;
|
||||||
openpgp.config.v5Keys = v5KeysVal;
|
openpgp.config.v6Keys = v6KeysVal;
|
||||||
openpgp.config.minRSABits = minRSABitsVal;
|
openpgp.config.minRSABits = minRSABitsVal;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -2293,12 +2293,12 @@ XfA3pqV4mTzF
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
tryTests('GCM mode (V5 keys)', tests, {
|
tryTests('GCM mode (V6 keys)', tests, {
|
||||||
if: true,
|
if: true,
|
||||||
beforeEach: function() {
|
beforeEach: function() {
|
||||||
openpgp.config.aeadProtect = true;
|
openpgp.config.aeadProtect = true;
|
||||||
openpgp.config.preferredAEADAlgorithm = openpgp.enums.aead.experimentalGCM;
|
openpgp.config.preferredAEADAlgorithm = openpgp.enums.aead.experimentalGCM;
|
||||||
openpgp.config.v5Keys = true;
|
openpgp.config.v6Keys = true;
|
||||||
|
|
||||||
// Monkey-patch AEAD feature flag
|
// Monkey-patch AEAD feature flag
|
||||||
publicKey.users[0].selfCertifications[0].features = [7];
|
publicKey.users[0].selfCertifications[0].features = [7];
|
||||||
|
@ -854,12 +854,8 @@ V+HOQJQxXJkVRYa3QrFUehiMzTeqqMdgC6ZqJy7+
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('Writing of unencrypted v5 secret key packet', async function() {
|
it('Writing of unencrypted v5 secret key packet', async function() {
|
||||||
const originalV5KeysSetting = openpgp.config.v5Keys;
|
|
||||||
openpgp.config.v5Keys = true;
|
|
||||||
|
|
||||||
try {
|
|
||||||
const packet = new openpgp.SecretKeyPacket();
|
const packet = new openpgp.SecretKeyPacket();
|
||||||
|
packet.version = 5;
|
||||||
packet.privateParams = { key: new Uint8Array([1, 2, 3]) };
|
packet.privateParams = { key: new Uint8Array([1, 2, 3]) };
|
||||||
packet.publicParams = { pubKey: new Uint8Array([4, 5, 6]) };
|
packet.publicParams = { pubKey: new Uint8Array([4, 5, 6]) };
|
||||||
packet.algorithm = openpgp.enums.publicKey.rsaSign;
|
packet.algorithm = openpgp.enums.publicKey.rsaSign;
|
||||||
@ -883,8 +879,34 @@ V+HOQJQxXJkVRYa3QrFUehiMzTeqqMdgC6ZqJy7+
|
|||||||
expect(written[23]).to.equal(1);
|
expect(written[23]).to.equal(1);
|
||||||
expect(written[24]).to.equal(2);
|
expect(written[24]).to.equal(2);
|
||||||
expect(written[25]).to.equal(3);
|
expect(written[25]).to.equal(3);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Writing of unencrypted v6 secret key packet', async function() {
|
||||||
|
const originalv6KeysSetting = openpgp.config.v6Keys;
|
||||||
|
openpgp.config.v6Keys = true;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const packet = new openpgp.SecretKeyPacket();
|
||||||
|
|
||||||
|
packet.privateParams = { key: new Uint8Array([1, 2, 3]) };
|
||||||
|
packet.publicParams = { pubKey: new Uint8Array([4, 5, 6]) };
|
||||||
|
packet.algorithm = openpgp.enums.publicKey.rsaSign;
|
||||||
|
packet.isEncrypted = false;
|
||||||
|
packet.s2kUsage = 0;
|
||||||
|
|
||||||
|
const written = packet.write();
|
||||||
|
expect(written.length).to.equal(21);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The private data
|
||||||
|
*
|
||||||
|
* The 2 bytes missing here are the length prefix of the MPI
|
||||||
|
*/
|
||||||
|
expect(written[18]).to.equal(1);
|
||||||
|
expect(written[19]).to.equal(2);
|
||||||
|
expect(written[20]).to.equal(3);
|
||||||
} finally {
|
} finally {
|
||||||
openpgp.config.v5Keys = originalV5KeysSetting;
|
openpgp.config.v6Keys = originalv6KeysSetting;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ import {
|
|||||||
(async () => {
|
(async () => {
|
||||||
|
|
||||||
// Generate keys
|
// Generate keys
|
||||||
const keyOptions = { userIDs: [{ email: 'user@corp.co' }], config: { v5Keys: true } };
|
const keyOptions = { userIDs: [{ email: 'user@corp.co' }], config: { v6Keys: true } };
|
||||||
const { privateKey: privateKeyArmored, publicKey: publicKeyArmored } = await generateKey(keyOptions);
|
const { privateKey: privateKeyArmored, publicKey: publicKeyArmored } = await generateKey(keyOptions);
|
||||||
const { privateKey: privateKeyBinary } = await generateKey({ ...keyOptions, format: 'binary' });
|
const { privateKey: privateKeyBinary } = await generateKey({ ...keyOptions, format: 'binary' });
|
||||||
const { privateKey, publicKey, revocationCertificate } = await generateKey({ ...keyOptions, format: 'object' });
|
const { privateKey, publicKey, revocationCertificate } = await generateKey({ ...keyOptions, format: 'object' });
|
||||||
|
Loading…
x
Reference in New Issue
Block a user