Fix key expiration time. Add key revocation unit test.
This commit is contained in:
parent
d22facc61c
commit
ff8d93f956
File diff suppressed because one or more lines are too long
|
@ -44,14 +44,14 @@ module.exports = function packet_signature() {
|
||||||
|
|
||||||
this.created = new Date();
|
this.created = new Date();
|
||||||
this.signatureExpirationTime = null;
|
this.signatureExpirationTime = null;
|
||||||
this.signatureNeverExpires = null;
|
this.signatureNeverExpires = true;
|
||||||
this.exportable = null;
|
this.exportable = null;
|
||||||
this.trustLevel = null;
|
this.trustLevel = null;
|
||||||
this.trustAmount = null;
|
this.trustAmount = null;
|
||||||
this.regularExpression = null;
|
this.regularExpression = null;
|
||||||
this.revocable = null;
|
this.revocable = null;
|
||||||
this.keyExpirationTime = null;
|
this.keyExpirationTime = null;
|
||||||
this.keyNeverExpires = null;
|
this.keyNeverExpires = true;
|
||||||
this.preferredSymmetricAlgorithms = null;
|
this.preferredSymmetricAlgorithms = null;
|
||||||
this.revocationKeyClass = null;
|
this.revocationKeyClass = null;
|
||||||
this.revocationKeyAlgorithm = null;
|
this.revocationKeyAlgorithm = null;
|
||||||
|
@ -225,7 +225,7 @@ module.exports = function packet_signature() {
|
||||||
result += write_sub_packet(sub.signature_creation_time, util.writeDate(this.created));
|
result += write_sub_packet(sub.signature_creation_time, util.writeDate(this.created));
|
||||||
}
|
}
|
||||||
if (this.signatureExpirationTime !== null) {
|
if (this.signatureExpirationTime !== null) {
|
||||||
result += write_sub_packet(sub.signature_expiration_time, util.writeDate(this.signatureExpirationTime));
|
result += write_sub_packet(sub.signature_expiration_time, util.writeNumber(this.signatureExpirationTime, 4));
|
||||||
}
|
}
|
||||||
if (this.exportable !== null) {
|
if (this.exportable !== null) {
|
||||||
result += write_sub_packet(sub.exportable_certification, String.fromCharCode(this.exportable ? 1 : 0));
|
result += write_sub_packet(sub.exportable_certification, String.fromCharCode(this.exportable ? 1 : 0));
|
||||||
|
@ -241,7 +241,7 @@ module.exports = function packet_signature() {
|
||||||
result += write_sub_packet(sub.revocable, String.fromCharCode(this.revocable ? 1 : 0));
|
result += write_sub_packet(sub.revocable, String.fromCharCode(this.revocable ? 1 : 0));
|
||||||
}
|
}
|
||||||
if (this.keyExpirationTime !== null) {
|
if (this.keyExpirationTime !== null) {
|
||||||
result += write_sub_packet(sub.key_expiration_time, util.writeDate(this.keyExpirationTime));
|
result += write_sub_packet(sub.key_expiration_time, util.writeNumber(this.keyExpirationTime, 4));
|
||||||
}
|
}
|
||||||
if (this.preferredSymmetricAlgorithms !== null) {
|
if (this.preferredSymmetricAlgorithms !== null) {
|
||||||
bytes = util.bin2str(this.preferredSymmetricAlgorithms);
|
bytes = util.bin2str(this.preferredSymmetricAlgorithms);
|
||||||
|
@ -361,11 +361,11 @@ module.exports = function packet_signature() {
|
||||||
this.created = util.readDate(bytes.substr(mypos));
|
this.created = util.readDate(bytes.substr(mypos));
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
// Signature Expiration Time
|
// Signature Expiration Time in seconds
|
||||||
var time = util.readDate(bytes.substr(mypos));
|
var seconds = util.readNumber(bytes.substr(mypos));
|
||||||
|
|
||||||
this.signatureNeverExpires = time.getTime() == 0;
|
this.signatureNeverExpires = seconds == 0;
|
||||||
this.signatureExpirationTime = time;
|
this.signatureExpirationTime = seconds;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
|
@ -386,11 +386,11 @@ module.exports = function packet_signature() {
|
||||||
this.revocable = bytes.charCodeAt(mypos++) == 1;
|
this.revocable = bytes.charCodeAt(mypos++) == 1;
|
||||||
break;
|
break;
|
||||||
case 9:
|
case 9:
|
||||||
// Key Expiration Time
|
// Key Expiration Time in seconds
|
||||||
var time = util.readDate(bytes.substr(mypos));
|
var seconds = util.readNumber(bytes.substr(mypos));
|
||||||
|
|
||||||
this.keyExpirationTime = time;
|
this.keyExpirationTime = seconds;
|
||||||
this.keyNeverExpires = time.getTime() == 0;
|
this.keyNeverExpires = seconds == 0;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 11:
|
case 11:
|
||||||
|
@ -593,7 +593,7 @@ module.exports = function packet_signature() {
|
||||||
|
|
||||||
var mpicount = 0;
|
var mpicount = 0;
|
||||||
// Algorithm-Specific Fields for RSA signatures:
|
// Algorithm-Specific Fields for RSA signatures:
|
||||||
// - multiprecision number (MPI) of RSA signature value m**d mod n.
|
// - multiprecision number (MPI) of RSA signature value m**d mod n.
|
||||||
if (publicKeyAlgorithm > 0 && publicKeyAlgorithm < 4)
|
if (publicKeyAlgorithm > 0 && publicKeyAlgorithm < 4)
|
||||||
mpicount = 1;
|
mpicount = 1;
|
||||||
// Algorithm-Specific Fields for DSA signatures:
|
// Algorithm-Specific Fields for DSA signatures:
|
||||||
|
@ -615,4 +615,15 @@ module.exports = function packet_signature() {
|
||||||
|
|
||||||
return this.verified;
|
return this.verified;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verifies signature expiration date
|
||||||
|
* @return {Boolean} true if expired
|
||||||
|
*/
|
||||||
|
this.isExpired = function() {
|
||||||
|
if (!this.signatureNeverExpires) {
|
||||||
|
return Date.now() > (this.created.getTime() + this.signatureExpirationTime*1000);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -169,6 +169,58 @@ var pub_key_arm3 =
|
||||||
'=ummy',
|
'=ummy',
|
||||||
'-----END PGP PUBLIC KEY BLOCK-----'].join('\n');
|
'-----END PGP PUBLIC KEY BLOCK-----'].join('\n');
|
||||||
|
|
||||||
|
var pub_revoked =
|
||||||
|
['-----BEGIN PGP PUBLIC KEY BLOCK-----',
|
||||||
|
'Version: GnuPG v2.0.19 (GNU/Linux)',
|
||||||
|
'',
|
||||||
|
'mQENBFKpincBCADhZjIihK15f3l+j87JgeLp9eUTSbn+g3gOFSR73TOMyBHMPt8O',
|
||||||
|
'KwuA+TN2sM86AooOR/2B2MjHBUZqrgeJe+sk5411yXezyYdQGZ8vlq/FeLeNF70D',
|
||||||
|
'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wx+FoSRbqRvsqLFYoU3d745zX1W7o',
|
||||||
|
'dFcDddGMv5LMPnvNR+Qm7PUlowARAQABiQE0BCgBAgAeBQJSqY5XFx0DVGVzdGlu',
|
||||||
|
'ZyBzdWJrZXkgcmV2b2tlAAoJEDvitUh9FgWzsUoH/1MrYYo7aQErScnhbIVQ5qpB',
|
||||||
|
'qnqBTiyVGa3cqSPKUkT552dRs6TwsjFKnOs68MIZQ6qfliZE/ApKPQhxaHgmfWKI',
|
||||||
|
'Q09Qv04SKHqo9njX6E3q257DnvmQiv6c9PRA3G/p2doBrj3joaOVm/ZioiCZdf2W',
|
||||||
|
'l6akAf7j5DbcVRh8BQigM4EUhsVjBvGPYxqVNIM4aWHMTG62CaREa9g1PWOobASU',
|
||||||
|
'jX47B7/FFP4zCLkeb+znDMwc8jKWeUBp5sUGhWo74wFiD5Dp2Zz50qRi1u05nJXg',
|
||||||
|
'bIib7pwmH2CeDwmPRi/HRUrKBcqFzSYG5QVggQ5KMIU9M7zmvd8mDYE8MQbTLbaJ',
|
||||||
|
'ASUEGAECAA8FAlKpincCGwwFCQlmAYAACgkQO+K1SH0WBbPbnQgAxcYAS3YplyBI',
|
||||||
|
'ddNJQNvyrWnnuGXoGGKgkE8+LUR3rX3NK/c4pF7EFgrNxKIPrWZoIu7m1XNqoK3g',
|
||||||
|
'PwRXJfPPQWalVrhhOajtYipXumQVAe+q8DyxAZ5YJGrUvR9b96GRel9G+HsRlR1M',
|
||||||
|
'NV62ZXFdXVgg9FZJHDR8fa1Zy93xC0JSKu4ZoCrH5ybw+DPCngogDl4KwgdV5y4e',
|
||||||
|
'EAZpGDSq7PrdsgZTiSuepwVw116GWJm1zecmh6FdpZL/ZrE6EfYcCGJqJiVfDiCR',
|
||||||
|
'jgvGbcTzxnvrRmDevmJUdXBSAE11OYQuDGlhgFCU0o9cdX+k+QqP5wNycXhoJ+yk',
|
||||||
|
'pMiJM+NJAQ==',
|
||||||
|
'=ok+o',
|
||||||
|
'-----END PGP PUBLIC KEY BLOCK-----'].join('\n');
|
||||||
|
|
||||||
|
|
||||||
var tests = [function() {
|
var tests = [function() {
|
||||||
var priv_key = openpgp.key.readArmored(priv_key_arm1).packets;
|
var priv_key = openpgp.key.readArmored(priv_key_arm1).packets;
|
||||||
|
@ -417,6 +469,20 @@ var pub_key_arm3 =
|
||||||
verified = verified && cleartextSig.signatures[0].valid;
|
verified = verified && cleartextSig.signatures[0].valid;
|
||||||
|
|
||||||
return new unit.result("Sign text with openpgp.signClearMessage and verify with openpgp.verifyClearSignedMessage leads to same cleartext and valid signatures", verified);
|
return new unit.result("Sign text with openpgp.signClearMessage and verify with openpgp.verifyClearSignedMessage leads to same cleartext and valid signatures", verified);
|
||||||
|
}, function() {
|
||||||
|
|
||||||
|
var pubKey = openpgp.key.readArmored(pub_revoked);
|
||||||
|
|
||||||
|
var verified = pubKey.packets[1].verify(pubKey.packets[0], {key: pubKey.packets[0]});
|
||||||
|
|
||||||
|
return new unit.result("Verify revocation signature", verified);
|
||||||
|
}, function() {
|
||||||
|
|
||||||
|
var pubKey = openpgp.key.readArmored(pub_revoked);
|
||||||
|
|
||||||
|
var verified = !pubKey.packets[4].keyNeverExpires && pubKey.packets[4].keyExpirationTime == 5*365*24*60*60;
|
||||||
|
|
||||||
|
return new unit.result("Verify key expiration date", verified);
|
||||||
}];
|
}];
|
||||||
|
|
||||||
var results = [];
|
var results = [];
|
||||||
|
|
Loading…
Reference in New Issue
Block a user