Implement Issuer Fingerprint subpacket

This commit is contained in:
Daniel Huigens 2018-04-20 20:26:24 +02:00
parent 310d8dd9b9
commit e8adeef278
2 changed files with 28 additions and 1 deletions

View File

@ -373,6 +373,7 @@ export default {
features: 30,
signature_target: 31,
embedded_signature: 32,
issuer_fingerprint: 33,
preferred_aead_algorithms: 34
},

View File

@ -84,6 +84,8 @@ function Signature(date=new Date()) {
this.signatureTargetHashAlgorithm = null;
this.signatureTargetHash = null;
this.embeddedSignature = null;
this.issuerKeyVersion = null;
this.issuerFingerprint = null;
this.preferredAeadAlgorithms = null;
this.verified = null;
@ -223,6 +225,13 @@ Signature.prototype.sign = async function (key, data) {
const arr = [new Uint8Array([4, signatureType, publicKeyAlgorithm, hashAlgorithm])];
if (key.version === 5) {
// We could also generate this subpacket for version 4 keys, but for
// now we don't.
this.issuerKeyVersion = key.version;
this.issuerFingerprint = key.getFingerprintBytes();
}
this.issuerKeyId = key.getKeyId();
// Add hashed subpackets
@ -293,7 +302,9 @@ Signature.prototype.write_all_sub_packets = function () {
bytes = util.concatUint8Array([bytes, this.revocationKeyFingerprint]);
arr.push(write_sub_packet(sub.revocation_key, bytes));
}
if (!this.issuerKeyId.isNull()) {
if (!this.issuerKeyId.isNull() && this.issuerKeyVersion !== 5) {
// If the version of [the] key is greater than 4, this subpacket
// MUST NOT be included in the signature.
arr.push(write_sub_packet(sub.issuer, this.issuerKeyId.write()));
}
if (this.notation !== null) {
@ -356,6 +367,11 @@ Signature.prototype.write_all_sub_packets = function () {
if (this.embeddedSignature !== null) {
arr.push(write_sub_packet(sub.embedded_signature, this.embeddedSignature.write()));
}
if (this.issuerFingerprint !== null) {
bytes = [new Uint8Array([this.issuerKeyVersion]), this.issuerFingerprint];
bytes = util.concatUint8Array(bytes);
arr.push(write_sub_packet(sub.issuer_fingerprint, bytes));
}
if (this.preferredAeadAlgorithms !== null) {
bytes = util.str_to_Uint8Array(util.Uint8Array_to_str(this.preferredAeadAlgorithms));
arr.push(write_sub_packet(sub.preferred_aead_algorithms, bytes));
@ -536,6 +552,16 @@ Signature.prototype.read_sub_packet = function (bytes) {
this.embeddedSignature = new Signature();
this.embeddedSignature.read(bytes.subarray(mypos, bytes.length));
break;
case 33:
// Issuer Fingerprint
this.issuerKeyVersion = bytes[mypos++];
this.issuerFingerprint = bytes.subarray(mypos, bytes.length);
if (this.issuerKeyVersion === 5) {
this.issuerKeyId.read(this.issuerFingerprint);
} else {
this.issuerKeyId.read(this.issuerFingerprint.subarray(-8));
}
break;
case 34:
// Preferred AEAD Algorithms
read_array.call(this, 'preferredAeadAlgorithms', bytes.subarray(mypos, bytes.length));