Fix signing using keys without preferred hash algorithms (#1820)

This commit is contained in:
Daniel Huigens 2025-01-29 16:45:32 +01:00 committed by GitHub
parent b2bd8a0fdd
commit 432856ff0e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -127,7 +127,7 @@ export async function getPreferredHashAlgo(targetKeys, signingKeyPacket, date =
const supportedAlgosPerTarget = await Promise.all(targetKeys.map(async (key, i) => { const supportedAlgosPerTarget = await Promise.all(targetKeys.map(async (key, i) => {
const selfCertification = await key.getPrimarySelfSignature(date, targetUserIDs[i], config); const selfCertification = await key.getPrimarySelfSignature(date, targetUserIDs[i], config);
const targetPrefs = selfCertification.preferredHashAlgorithms; const targetPrefs = selfCertification.preferredHashAlgorithms;
return targetPrefs; return targetPrefs || [];
})); }));
const supportedAlgosMap = new Map(); // use Map over object to preserve numeric keys const supportedAlgosMap = new Map(); // use Map over object to preserve numeric keys
for (const supportedAlgos of supportedAlgosPerTarget) { for (const supportedAlgos of supportedAlgosPerTarget) {
@ -151,7 +151,7 @@ export async function getPreferredHashAlgo(targetKeys, signingKeyPacket, date =
.filter(hashAlgo => isSupportedHashAlgo(hashAlgo)) .filter(hashAlgo => isSupportedHashAlgo(hashAlgo))
.sort((algoA, algoB) => getHashByteLength(algoA) - getHashByteLength(algoB)); .sort((algoA, algoB) => getHashByteLength(algoA) - getHashByteLength(algoB));
const strongestHashAlgo = sortedHashAlgos[0]; const strongestHashAlgo = sortedHashAlgos[0];
// defaultAlgo is always implicilty supported, and might be stronger than the rest // defaultAlgo is always implicitly supported, and might be stronger than the rest
return getHashByteLength(strongestHashAlgo) >= getHashByteLength(defaultAlgo) ? strongestHashAlgo : defaultAlgo; return getHashByteLength(strongestHashAlgo) >= getHashByteLength(defaultAlgo) ? strongestHashAlgo : defaultAlgo;
}; };