misc: addressed review comments

This commit is contained in:
Sheen Capadngan
2024-08-26 21:10:29 +08:00
parent f560534493
commit 00f86cfd00
7 changed files with 93 additions and 54 deletions
@@ -24,3 +24,24 @@ export const revocationReasonToCrlCode = (crlReason: CrlReason) => {
return x509.X509CrlReason.unspecified;
}
};
export const isCertChainValid = async (certificates: x509.X509Certificate[]) => {
if (certificates.length === 1) {
return true;
}
// check for self-signed
if (certificates.length === 2 && certificates[0].equal(certificates[1])) {
return true;
}
const leafCert = certificates[0];
const chain = new x509.X509ChainBuilder({
certificates: certificates.slice(1)
});
const chainItems = await chain.build(leafCert);
// chain.build() implicitly verifies the chain
return chainItems.length === certificates.length;
};