Fix KID match

This commit is contained in:
Fang-Pen Lin
2025-11-03 16:21:21 -08:00
parent 4d9833acd6
commit 5256b11402

View File

@@ -339,10 +339,15 @@ export const pkiAcmeServiceFactory = ({
externalAccountBinding,
eabSecret
);
const eabAlg = eabProtectedHeader!.alg!;
if (!["HS256", "HS384", "HS512"].includes(eabAlg)) {
const { alg: eabAlg, kid: eabKid } = eabProtectedHeader!;
if (!["HS256", "HS384", "HS512"].includes(eabAlg!)) {
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
const url = eabProtectedHeader!.url!;
if (url !== buildUrl(profile.id, "/new-account")) {
@@ -359,10 +364,6 @@ export const pkiAcmeServiceFactory = ({
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) {
if (error instanceof errors.JWSInvalid) {
throw new AcmeMalformedError({ detail: "Invalid external account binding JWS payload" });