Fix generating keys with a date in the future
This was broken in 8c3bcd1
.
(Before then, the revocation certificate was already broken when
generating a key with a date in the future.)
This commit is contained in:
parent
f6507c30e1
commit
60822d87d9
|
@ -664,12 +664,13 @@ Key.prototype.revoke = async function({
|
||||||
/**
|
/**
|
||||||
* Get revocation certificate from a revoked key.
|
* Get revocation certificate from a revoked key.
|
||||||
* (To get a revocation certificate for an unrevoked key, call revoke() first.)
|
* (To get a revocation certificate for an unrevoked key, call revoke() first.)
|
||||||
|
* @param {Date} date Use the given date instead of the current time
|
||||||
* @returns {Promise<String>} armored revocation certificate
|
* @returns {Promise<String>} armored revocation certificate
|
||||||
* @async
|
* @async
|
||||||
*/
|
*/
|
||||||
Key.prototype.getRevocationCertificate = async function() {
|
Key.prototype.getRevocationCertificate = async function(date = new Date()) {
|
||||||
const dataToVerify = { key: this.keyPacket };
|
const dataToVerify = { key: this.keyPacket };
|
||||||
const revocationSignature = await helper.getLatestValidSignature(this.revocationSignatures, this.keyPacket, enums.signature.key_revocation, dataToVerify);
|
const revocationSignature = await helper.getLatestValidSignature(this.revocationSignatures, this.keyPacket, enums.signature.key_revocation, dataToVerify, date);
|
||||||
const packetlist = new packet.List();
|
const packetlist = new packet.List();
|
||||||
packetlist.push(revocationSignature);
|
packetlist.push(revocationSignature);
|
||||||
return armor.encode(enums.armor.public_key, packetlist.write(), null, null, 'This is a revocation certificate');
|
return armor.encode(enums.armor.public_key, packetlist.write(), null, null, 'This is a revocation certificate');
|
||||||
|
|
|
@ -136,7 +136,7 @@ export function generateKey({ userIds = [], passphrase = "", numBits = 2048, rsa
|
||||||
}
|
}
|
||||||
|
|
||||||
return generate(options).then(async key => {
|
return generate(options).then(async key => {
|
||||||
const revocationCertificate = await key.getRevocationCertificate();
|
const revocationCertificate = await key.getRevocationCertificate(date);
|
||||||
key.revocationSignatures = [];
|
key.revocationSignatures = [];
|
||||||
|
|
||||||
return convertStreams({
|
return convertStreams({
|
||||||
|
@ -172,7 +172,7 @@ export function reformatKey({ privateKey, userIds = [], passphrase = "", keyExpi
|
||||||
options.revoked = options.revocationCertificate;
|
options.revoked = options.revocationCertificate;
|
||||||
|
|
||||||
return reformat(options).then(async key => {
|
return reformat(options).then(async key => {
|
||||||
const revocationCertificate = await key.getRevocationCertificate();
|
const revocationCertificate = await key.getRevocationCertificate(date);
|
||||||
key.revocationSignatures = [];
|
key.revocationSignatures = [];
|
||||||
|
|
||||||
return convertStreams({
|
return convertStreams({
|
||||||
|
|
|
@ -1972,7 +1972,25 @@ function versionSpecificTests() {
|
||||||
expect(+newKey.key.subKeys[0].getCreationTime()).to.equal(+past);
|
expect(+newKey.key.subKeys[0].getCreationTime()).to.equal(+past);
|
||||||
expect(+newKey.key.subKeys[0].bindingSignatures[0].created).to.equal(+past);
|
expect(+newKey.key.subKeys[0].bindingSignatures[0].created).to.equal(+past);
|
||||||
});
|
});
|
||||||
})
|
});
|
||||||
|
|
||||||
|
it('Generate key - setting date to the future', function() {
|
||||||
|
const future = new Date(Math.ceil(Date.now() / 1000) * 1000 + 1000);
|
||||||
|
const opt = {
|
||||||
|
numBits: 512,
|
||||||
|
userIds: { name: 'Test User', email: 'text@example.com' },
|
||||||
|
passphrase: 'secret',
|
||||||
|
date: future
|
||||||
|
};
|
||||||
|
if (openpgp.util.getWebCryptoAll()) { opt.numBits = 2048; } // webkit webcrypto accepts minimum 2048 bit keys
|
||||||
|
|
||||||
|
return openpgp.generateKey(opt).then(function(newKey) {
|
||||||
|
expect(newKey.key).to.exist;
|
||||||
|
expect(+newKey.key.getCreationTime()).to.equal(+future);
|
||||||
|
expect(+newKey.key.subKeys[0].getCreationTime()).to.equal(+future);
|
||||||
|
expect(+newKey.key.subKeys[0].bindingSignatures[0].created).to.equal(+future);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('Generate key - multi userid', function() {
|
it('Generate key - multi userid', function() {
|
||||||
const userId1 = 'test <a@b.com>';
|
const userId1 = 'test <a@b.com>';
|
||||||
|
|
Loading…
Reference in New Issue
Block a user