mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-08 08:27:53 +00:00
Add signature type enum
This commit is contained in:
+6
-9
@@ -33,6 +33,7 @@ import {
|
|||||||
CertKeyAlgorithm,
|
CertKeyAlgorithm,
|
||||||
CertKeyUsage,
|
CertKeyUsage,
|
||||||
CertSignatureAlgorithm,
|
CertSignatureAlgorithm,
|
||||||
|
CertSignatureType,
|
||||||
CertStatus,
|
CertStatus,
|
||||||
TAltNameMapping
|
TAltNameMapping
|
||||||
} from "../../certificate/certificate-types";
|
} from "../../certificate/certificate-types";
|
||||||
@@ -1663,19 +1664,15 @@ export const internalCertificateAuthorityServiceFactory = ({
|
|||||||
const caKeyAlgorithm = ca.internalCa.keyAlgorithm;
|
const caKeyAlgorithm = ca.internalCa.keyAlgorithm;
|
||||||
const requestedKeyType = signatureAlgorithm.split("-")[0]; // Get the first part (RSA, ECDSA)
|
const requestedKeyType = signatureAlgorithm.split("-")[0]; // Get the first part (RSA, ECDSA)
|
||||||
|
|
||||||
const isRsaCa = caKeyAlgorithm.startsWith(CertKeyAlgorithm.RSA_2048.split("_")[0]);
|
const isRsaCa = caKeyAlgorithm.startsWith(CertSignatureType.RSA);
|
||||||
const isEcdsaCa = caKeyAlgorithm.startsWith(CertKeyAlgorithm.ECDSA_P256.split("_")[0]);
|
const isEcdsaCa = caKeyAlgorithm.startsWith(CertSignatureType.ECDSA);
|
||||||
|
|
||||||
if (
|
if (
|
||||||
(requestedKeyType === CertSignatureAlgorithm.RSA_SHA256.split("-")[0] && !isRsaCa) ||
|
(requestedKeyType === CertSignatureType.RSA && !isRsaCa) ||
|
||||||
(requestedKeyType === CertSignatureAlgorithm.ECDSA_SHA256.split("-")[0] && !isEcdsaCa)
|
(requestedKeyType === CertSignatureType.ECDSA && !isEcdsaCa)
|
||||||
) {
|
) {
|
||||||
// eslint-disable-next-line no-nested-ternary
|
// eslint-disable-next-line no-nested-ternary
|
||||||
const supportedType = isRsaCa
|
const supportedType = isRsaCa ? CertSignatureType.RSA : isEcdsaCa ? CertSignatureType.ECDSA : "unknown";
|
||||||
? CertSignatureAlgorithm.RSA_SHA256.split("-")[0]
|
|
||||||
: isEcdsaCa
|
|
||||||
? CertSignatureAlgorithm.ECDSA_SHA256.split("-")[0]
|
|
||||||
: "unknown";
|
|
||||||
throw new BadRequestError({
|
throw new BadRequestError({
|
||||||
message: `Requested signature algorithm ${signatureAlgorithm} is not compatible with CA key algorithm ${caKeyAlgorithm}. CA can only sign with ${supportedType}-based signature algorithms.`
|
message: `Requested signature algorithm ${signatureAlgorithm} is not compatible with CA key algorithm ${caKeyAlgorithm}. CA can only sign with ${supportedType}-based signature algorithms.`
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -51,6 +51,11 @@ export enum CertExtendedKeyUsage {
|
|||||||
OCSP_SIGNING = "ocspSigning"
|
OCSP_SIGNING = "ocspSigning"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export enum CertSignatureType {
|
||||||
|
RSA = "RSA",
|
||||||
|
ECDSA = "ECDSA"
|
||||||
|
}
|
||||||
|
|
||||||
export const CertExtendedKeyUsageOIDToName: Record<string, CertExtendedKeyUsage> = {
|
export const CertExtendedKeyUsageOIDToName: Record<string, CertExtendedKeyUsage> = {
|
||||||
[x509.ExtendedKeyUsage.clientAuth]: CertExtendedKeyUsage.CLIENT_AUTH,
|
[x509.ExtendedKeyUsage.clientAuth]: CertExtendedKeyUsage.CLIENT_AUTH,
|
||||||
[x509.ExtendedKeyUsage.serverAuth]: CertExtendedKeyUsage.SERVER_AUTH,
|
[x509.ExtendedKeyUsage.serverAuth]: CertExtendedKeyUsage.SERVER_AUTH,
|
||||||
|
|||||||
Reference in New Issue
Block a user