Implement Issuer Fingerprint subpacket
This commit is contained in:
parent
310d8dd9b9
commit
e8adeef278
|
@ -373,6 +373,7 @@ export default {
|
||||||
features: 30,
|
features: 30,
|
||||||
signature_target: 31,
|
signature_target: 31,
|
||||||
embedded_signature: 32,
|
embedded_signature: 32,
|
||||||
|
issuer_fingerprint: 33,
|
||||||
preferred_aead_algorithms: 34
|
preferred_aead_algorithms: 34
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -84,6 +84,8 @@ function Signature(date=new Date()) {
|
||||||
this.signatureTargetHashAlgorithm = null;
|
this.signatureTargetHashAlgorithm = null;
|
||||||
this.signatureTargetHash = null;
|
this.signatureTargetHash = null;
|
||||||
this.embeddedSignature = null;
|
this.embeddedSignature = null;
|
||||||
|
this.issuerKeyVersion = null;
|
||||||
|
this.issuerFingerprint = null;
|
||||||
this.preferredAeadAlgorithms = null;
|
this.preferredAeadAlgorithms = null;
|
||||||
|
|
||||||
this.verified = null;
|
this.verified = null;
|
||||||
|
@ -223,6 +225,13 @@ Signature.prototype.sign = async function (key, data) {
|
||||||
|
|
||||||
const arr = [new Uint8Array([4, signatureType, publicKeyAlgorithm, hashAlgorithm])];
|
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();
|
this.issuerKeyId = key.getKeyId();
|
||||||
|
|
||||||
// Add hashed subpackets
|
// Add hashed subpackets
|
||||||
|
@ -293,7 +302,9 @@ Signature.prototype.write_all_sub_packets = function () {
|
||||||
bytes = util.concatUint8Array([bytes, this.revocationKeyFingerprint]);
|
bytes = util.concatUint8Array([bytes, this.revocationKeyFingerprint]);
|
||||||
arr.push(write_sub_packet(sub.revocation_key, bytes));
|
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()));
|
arr.push(write_sub_packet(sub.issuer, this.issuerKeyId.write()));
|
||||||
}
|
}
|
||||||
if (this.notation !== null) {
|
if (this.notation !== null) {
|
||||||
|
@ -356,6 +367,11 @@ Signature.prototype.write_all_sub_packets = function () {
|
||||||
if (this.embeddedSignature !== null) {
|
if (this.embeddedSignature !== null) {
|
||||||
arr.push(write_sub_packet(sub.embedded_signature, this.embeddedSignature.write()));
|
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) {
|
if (this.preferredAeadAlgorithms !== null) {
|
||||||
bytes = util.str_to_Uint8Array(util.Uint8Array_to_str(this.preferredAeadAlgorithms));
|
bytes = util.str_to_Uint8Array(util.Uint8Array_to_str(this.preferredAeadAlgorithms));
|
||||||
arr.push(write_sub_packet(sub.preferred_aead_algorithms, bytes));
|
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 = new Signature();
|
||||||
this.embeddedSignature.read(bytes.subarray(mypos, bytes.length));
|
this.embeddedSignature.read(bytes.subarray(mypos, bytes.length));
|
||||||
break;
|
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:
|
case 34:
|
||||||
// Preferred AEAD Algorithms
|
// Preferred AEAD Algorithms
|
||||||
read_array.call(this, 'preferredAeadAlgorithms', bytes.subarray(mypos, bytes.length));
|
read_array.call(this, 'preferredAeadAlgorithms', bytes.subarray(mypos, bytes.length));
|
||||||
|
|
Loading…
Reference in New Issue
Block a user