Fix KID match

This commit is contained in:
Fang-Pen Lin
2025-11-07 09:20:15 -08:00
parent 4d9833acd6
commit 5256b11402
@@ -339,10 +339,15 @@ export const pkiAcmeServiceFactory = ({
externalAccountBinding, externalAccountBinding,
eabSecret eabSecret
); );
const eabAlg = eabProtectedHeader!.alg!; const { alg: eabAlg, kid: eabKid } = eabProtectedHeader!;
if (!["HS256", "HS384", "HS512"].includes(eabAlg)) { if (!["HS256", "HS384", "HS512"].includes(eabAlg!)) {
throw new AcmeMalformedError({ detail: "Invalid algorithm for external account binding JWS payload" }); throw new AcmeMalformedError({ detail: "Invalid algorithm for external account binding JWS payload" });
} }
// Make sure the KID in the EAB payload matches the profile ID
if (eabKid !== profile.id) {
throw new UnauthorizedError({ message: "External account binding KID mismatch" });
}
// Make sure the URL matches the expected URL // Make sure the URL matches the expected URL
const url = eabProtectedHeader!.url!; const url = eabProtectedHeader!.url!;
if (url !== buildUrl(profile.id, "/new-account")) { if (url !== buildUrl(profile.id, "/new-account")) {
@@ -359,10 +364,6 @@ export const pkiAcmeServiceFactory = ({
message: "External account binding public key thumbprint or algorithm mismatch" message: "External account binding public key thumbprint or algorithm mismatch"
}); });
} }
// Make sure the KID in the EAB payload matches the profile ID
if ((eabPayload as unknown as { kid: string }).kid !== profile.id) {
throw new UnauthorizedError({ message: "External account binding KID mismatch" });
}
} catch (error) { } catch (error) {
if (error instanceof errors.JWSInvalid) { if (error instanceof errors.JWSInvalid) {
throw new AcmeMalformedError({ detail: "Invalid external account binding JWS payload" }); throw new AcmeMalformedError({ detail: "Invalid external account binding JWS payload" });