Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
feature(kms): ed25519 sign/verify keys
bernie-g180a815317c3
diff --git a/backend/src/lib/crypto/sign/index.ts b/backend/src/lib/crypto/sign/index.tsindex 25d631dbf4..394f9fd33d 100644--- a/backend/src/lib/crypto/sign/index.ts+++ b/backend/src/lib/crypto/sign/index.ts@@ -1,2 +1,2 @@-export { isPqcKeyAlgorithm, KMS_TO_OPENSSL_NAME, signingService } from "./signing";+export { isEd25519KeyAlgorithm, isPqcKeyAlgorithm, KMS_TO_OPENSSL_NAME, signingService } from "./signing";export { AsymmetricKeyAlgorithm, SigningAlgorithm } from "./types";diff --git a/backend/src/lib/crypto/sign/signing.test.ts b/backend/src/lib/crypto/sign/signing.test.tsnew file mode 100644index 0000000000..2064e36e29--- /dev/null+++ b/backend/src/lib/crypto/sign/signing.test.ts@@ -0,0 +1,112 @@+import { describe, expect, it } from "vitest";++import { crypto } from "@app/lib/crypto/cryptography";+import { BadRequestError } from "@app/lib/errors";++import { signingService } from "./signing";+import { AsymmetricKeyAlgorithm, SigningAlgorithm } from "./types";++const data = Buffer.from("payload to sign");++describe("signingService ED25519", () => {+ const service = signingService(AsymmetricKeyAlgorithm.ED25519);++ it("generates a PKCS8 PEM Ed25519 private key", async () => {+ const privateKey = await service.generateAsymmetricPrivateKey();+ const keyObject = crypto.nativeCrypto.createPrivateKey({ key: privateKey, format: "pem", type: "pkcs8" });+ expect(keyObject.asymmetricKeyType).toBe("ed25519");+ });++ it("derives a SPKI DER public key", async () => {+ const privateKey = await service.generateAsymmetricPrivateKey();+ const publicKey = await service.getPublicKeyFromPrivateKey(privateKey);+ const keyObject = crypto.nativeCrypto.createPublicKey({ key: publicKey, format: "der", type: "spki" });+ expect(keyObject.asymmetricKeyType).toBe("ed25519");+ expect(publicKey.length).toBe(44);+ });++ it("signs and verifies, deterministically", async () => {+ const privateKey = await service.generateAsymmetricPrivateKey();+ const publicKey = await service.getPublicKeyFromPrivateKey(privateKey);++ const signature = await service.sign(data, privateKey, SigningAlgorithm.ED25519, false);+ const signatureAgain = await service.sign(data, privateKey, SigningAlgorithm.ED25519, false);++ expect(signature.length).toBe(64);+ expect(signature.equals(signatureAgain)).toBe(true);+ await expect(service.verify(data, signature, publicKey, SigningAlgorithm.ED25519, false)).resolves.toBe(true);+ });++ it("rejects a tampered message and a tampered signature", async () => {+ const privateKey = await service.generateAsymmetricPrivateKey();+ const publicKey = await service.getPublicKeyFromPrivateKey(privateKey);+ const signature = await service.sign(data, privateKey, SigningAlgorithm.ED25519, false);++ const tamperedSignature = Buffer.from(signature);+ tamperedSignature[0] = tamperedSignature[0] === 0 ? 1 : 0;++ await expect(+ service.verify(Buffer.from("other payload"), signature, publicKey, SigningAlgorithm.ED25519, false)+ ).resolves.toBe(false);+ await expect(service.verify(data, tamperedSignature, publicKey, SigningAlgorithm.ED25519, false)).resolves.toBe(+ false+ );+ });++ it("rejects a signature from a different key", async () => {+ const privateKey = await service.generateAsymmetricPrivateKey();+ const otherPublicKey = await service.getPublicKeyFromPrivateKey(await service.generateAsymmetricPrivateKey());+ const signature = await service.sign(data, privateKey, SigningAlgorithm.ED25519, false);++ await expect(service.verify(data, signature, otherPublicKey, SigningAlgorithm.ED25519, false)).resolves.toBe(false);+ });++ it("rejects digest input", async () => {+ const privateKey = await service.generateAsymmetricPrivateKey();+ const publicKey = await service.getPublicKeyFromPrivateKey(privateKey);+ const digest = crypto.nativeCrypto.createHash("sha256").update(data).digest();++ await expect(service.sign(digest, privateKey, SigningAlgorithm.ED25519, true)).rejects.toBeInstanceOf(+ BadRequestError+ );+ await expect(+ service.verify(digest, Buffer.alloc(64), publicKey, SigningAlgorithm.ED25519, true)+ ).rejects.toBeInstanceOf(BadRequestError);+ });++ it("rejects non-Ed25519 signing algorithms", async () => {+ const privateKey = await service.generateAsymmetricPrivateKey();+ const publicKey = await service.getPublicKeyFromPrivateKey(privateKey);++ await expect(service.sign(data, privateKey, SigningAlgorithm.ECDSA_SHA_256, false)).rejects.toBeInstanceOf(+ BadRequestError+ );+ await expect(+ service.verify(data, Buffer.alloc(64), publicKey, SigningAlgorithm.RSASSA_PSS_SHA_256, false)+ ).rejects.toBeInstanceOf(BadRequestError);+ });++ it("verifies a signature produced by node crypto directly", async () => {+ const privateKey = await service.generateAsymmetricPrivateKey();+ const publicKey = await service.getPublicKeyFromPrivateKey(privateKey);+ const keyObject = crypto.nativeCrypto.createPrivateKey({ key: privateKey, format: "pem", type: "pkcs8" });+ const externalSignature = crypto.nativeCrypto.sign(null, data, keyObject);++ await expect(service.verify(data, externalSignature, publicKey, SigningAlgorithm.ED25519, false)).resolves.toBe(+ true+ );+ });+});++describe("signingService rejects ED25519 on other key types", () => {+ it.each([AsymmetricKeyAlgorithm.RSA_4096, AsymmetricKeyAlgorithm.ECC_NIST_P256])(+ "%s key cannot sign with ED25519",+ async (keyAlgorithm) => {+ const service = signingService(keyAlgorithm);+ const privateKey = await service.generateAsymmetricPrivateKey();+ await expect(service.sign(data, privateKey, SigningAlgorithm.ED25519, false)).rejects.toBeInstanceOf(+ BadRequestError+ );+ }+ );+});diff --git a/backend/src/lib/crypto/sign/signing.ts b/backend/src/lib/crypto/sign/signing.tsindex 7a47e5ddd8..e0cdbdfd2c 100644--- a/backend/src/lib/crypto/sign/signing.ts+++ b/backend/src/lib/crypto/sign/signing.ts@@ -12,6 +12,7 @@ import { logger } from "@app/lib/logger";import { AsymmetricKeyAlgorithm, SigningAlgorithm, TAsymmetricSignVerifyFns } from "./types";export const isPqcKeyAlgorithm = (algo: string): boolean => algo.startsWith("ML_DSA");+export const isEd25519KeyAlgorithm = (algo: string): boolean => algo === AsymmetricKeyAlgorithm.ED25519;const execFileAsync = promisify(execFile);@@ -115,6 +116,7 @@ export const signingService = (algorithm: AsymmetricKeyAlgorithm): TAsymmetricSiconst $validateAlgorithmWithKeyType = (signingAlgorithm: SigningAlgorithm) => {const isRsaKey = algorithm.startsWith("RSA");const isEccKey = algorithm.startsWith("ECC");+ const isEd25519Key = isEd25519KeyAlgorithm(algorithm);const isPqcKey = isPqcKeyAlgorithm(algorithm);const isRsaAlgorithm = signingAlgorithm.startsWith("RSASSA");@@ -129,6 +131,12 @@ export const signingService = (algorithm: AsymmetricKeyAlgorithm): TAsymmetricSithrow new BadRequestError({ message: `KMS ECC key cannot be used with ${signingAlgorithm}` });}+ if (isEd25519Key && signingAlgorithm !== SigningAlgorithm.ED25519) {+ throw new BadRequestError({+ message: `KMS ED25519 key can only be used with ${SigningAlgorithm.ED25519} signing algorithm`+ });+ }+if (isPqcKey) {if (!isPqcAlgorithm || (signingAlgorithm as string) !== (algorithm as string)) {throw new BadRequestError({@@ -407,6 +415,18 @@ export const signingService = (algorithm: AsymmetricKeyAlgorithm): TAsymmetricSireturn sig;}+ if (isEd25519KeyAlgorithm(algorithm)) {+ if (isDigest) {+ throw new BadRequestError({ message: "ED25519 does not support digested input" });+ }+ const ed25519PrivateKey = crypto.nativeCrypto.createPrivateKey({+ key: privateKey,+ format: "pem",+ type: "pkcs8"+ });+ return crypto.nativeCrypto.sign(null, data, ed25519PrivateKey);+ }+const { hashAlgorithm, padding, saltLength } = $getSigningParams(signingAlgorithm);if (isDigest) {@@ -474,6 +494,19 @@ export const signingService = (algorithm: AsymmetricKeyAlgorithm): TAsymmetricSireturn opensslVerify(publicKey, signature, data);}+ if (isEd25519KeyAlgorithm(algorithm)) {+ $validateAlgorithmWithKeyType(signingAlgorithm);+ if (isDigest) {+ throw new BadRequestError({ message: "ED25519 does not support digested input" });+ }+ const ed25519PublicKey = crypto.nativeCrypto.createPublicKey({+ key: publicKey,+ format: "der",+ type: "spki"+ });+ return crypto.nativeCrypto.verify(null, data, ed25519PublicKey, signature);+ }+try {$validateAlgorithmWithKeyType(signingAlgorithm);@@ -553,7 +586,22 @@ export const signingService = (algorithm: AsymmetricKeyAlgorithm): TAsymmetricSi}const { privateKey } = await new Promise<{ privateKey: string }>((resolve, reject) => {- if (algorithm.startsWith("RSA")) {+ if (isEd25519KeyAlgorithm(algorithm)) {+ crypto.nativeCrypto.generateKeyPair(+ "ed25519",+ {+ publicKeyEncoding: { type: "spki", format: "pem" },+ privateKeyEncoding: { type: "pkcs8", format: "pem" }+ },+ (err, _, pk) => {+ if (err) {+ reject(err);+ } else {+ resolve({ privateKey: pk });+ }+ }+ );+ } else if (algorithm.startsWith("RSA")) {crypto.nativeCrypto.generateKeyPair("rsa",{diff --git a/backend/src/lib/crypto/sign/types.ts b/backend/src/lib/crypto/sign/types.tsindex cae6501c56..4d72045dfb 100644--- a/backend/src/lib/crypto/sign/types.ts+++ b/backend/src/lib/crypto/sign/types.ts@@ -19,6 +19,7 @@ export enum AsymmetricKeyAlgorithm {ECC_NIST_P256 = "ECC_NIST_P256",ECC_NIST_P384 = "ECC_NIST_P384",ECC_NIST_P521 = "ECC_NIST_P521",+ ED25519 = "ED25519",ML_DSA_44 = "ML_DSA_44",ML_DSA_65 = "ML_DSA_65",ML_DSA_87 = "ML_DSA_87"@@ -48,6 +49,9 @@ export enum SigningAlgorithm {ECDSA_SHA_384 = "ECDSA_SHA_384",ECDSA_SHA_256 = "ECDSA_SHA_256",+ // Ed25519 (PureEdDSA): deterministic, hashing is built in, so no hash variant and no digest input+ ED25519 = "ED25519",+// ML-DSA (post-quantum) — signing algorithm equals key algorithm, no hash variantML_DSA_44 = "ML_DSA_44",ML_DSA_65 = "ML_DSA_65",diff --git a/backend/src/services/cmek/cmek-service.ts b/backend/src/services/cmek/cmek-service.tsindex a4f9e57b04..31fb0074f3 100644--- a/backend/src/services/cmek/cmek-service.ts+++ b/backend/src/services/cmek/cmek-service.ts@@ -4,7 +4,13 @@ import { ActionProjectType } from "@app/db/schemas";import { TLicenseServiceFactory } from "@app/ee/services/license/license-service";import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service-types";import { ProjectPermissionCmekActions, ProjectPermissionSub } from "@app/ee/services/permission/project-permission";-import { AsymmetricKeyAlgorithm, isPqcKeyAlgorithm, SigningAlgorithm, signingService } from "@app/lib/crypto/sign";+import {+ AsymmetricKeyAlgorithm,+ isEd25519KeyAlgorithm,+ isPqcKeyAlgorithm,+ SigningAlgorithm,+ signingService+} from "@app/lib/crypto/sign";import { DatabaseErrorCode } from "@app/lib/error-codes";import { BadRequestError, DatabaseError, NotFoundError } from "@app/lib/errors";import { OrgServiceActor } from "@app/lib/types";@@ -298,7 +304,7 @@ export const cmekServiceFactory = ({const encryptionAlgorithm = key.encryptionAlgorithm as TCmekKeyEncryptionAlgorithm;- if (isPqcKeyAlgorithm(encryptionAlgorithm as string)) {+ if (isPqcKeyAlgorithm(encryptionAlgorithm as string) || isEd25519KeyAlgorithm(encryptionAlgorithm as string)) {return { signingAlgorithms: [encryptionAlgorithm as unknown as SigningAlgorithm], projectId: key.projectId };}diff --git a/backend/src/services/kms/kms-service.ts b/backend/src/services/kms/kms-service.tsindex 4afc1827c0..7d4ab099d2 100644--- a/backend/src/services/kms/kms-service.ts+++ b/backend/src/services/kms/kms-service.ts@@ -692,6 +692,12 @@ export const kmsServiceFactory = ({message: `Key material does not match the declared algorithm. Expected an EC P-256 key.`});}+ } else if (algorithm === AsymmetricKeyAlgorithm.ED25519) {+ if (keyType !== "ed25519") {+ throw new BadRequestError({+ message: `Key material does not match the declared algorithm. Expected an Ed25519 key.`+ });+ }}}}diff --git a/docs/documentation/platform/kms/overview.mdx b/docs/documentation/platform/kms/overview.mdxindex a4ff97b6a9..45b7895ffd 100644--- a/docs/documentation/platform/kms/overview.mdx+++ b/docs/documentation/platform/kms/overview.mdx@@ -245,6 +245,11 @@ In the following steps, we explore how to generate a key and use it to sign data- `ECDSA SHA 384`: Not deterministic, and includes randomness.- `ECDSA SHA 256`: Not deterministic, and includes randomness.+ **For Ed25519 keys:**+ - `ED25519`: Deterministic. The signing algorithm is the same as the key algorithm.++ Ed25519 hashes the message as part of the signature scheme, so there is no separate hash algorithm to choose and digest input is not supported.+**For ML-DSA keys (post-quantum):**- `ML_DSA_44`: The signing algorithm is the same as the key algorithm.- `ML_DSA_65`: The signing algorithm is the same as the key algorithm.@@ -603,6 +608,7 @@ The exported file is a JSON array where each entry is one of the following shape**Signing and verification:**- `RSA_4096`- `ECC_NIST_P256`+ - `ED25519`- `ML_DSA_44` (post-quantum)- `ML_DSA_65` (post-quantum)- `ML_DSA_87` (post-quantum)@@ -681,7 +687,7 @@ The exported file is a JSON array where each entry is one of the following shape```<Note>- Please note that `RSA PSS` signing algorithms are not supported for digest signing and verification. Please use `RSA PKCS1 V1.5` signing algorithms for digest signing and verification, or `ECDSA` if you're using an ECC key. ML-DSA keys also do not support digest signing and verification, as ML-DSA handles hashing internally.+ Please note that `RSA PSS` signing algorithms are not supported for digest signing and verification. Please use `RSA PKCS1 V1.5` signing algorithms for digest signing and verification, or `ECDSA` if you're using an ECC key. Ed25519 and ML-DSA keys also do not support digest signing and verification, as both handle hashing internally.</Note></Accordion></AccordionGroup>diff --git a/frontend/src/helpers/kms.ts b/frontend/src/helpers/kms.tsindex 1c20bf7a2e..ed954d12f4 100644--- a/frontend/src/helpers/kms.ts+++ b/frontend/src/helpers/kms.ts@@ -43,7 +43,7 @@ export const formatKmsKeyAlgorithm = (algorithm: string): string =>algorithm.replaceAll("_", "-").toUpperCase();export const getDefaultSigningAlgorithm = (cmek: TCmek): SigningAlgorithm => {- if (cmek?.algorithm?.startsWith("ML_DSA")) {+ if (cmek?.algorithm?.startsWith("ML_DSA") || cmek?.algorithm === AsymmetricKeyAlgorithm.ED25519) {return cmek.algorithm as unknown as SigningAlgorithm;}if (cmek?.algorithm?.startsWith("RSA")) {diff --git a/frontend/src/hooks/api/cmeks/types.ts b/frontend/src/hooks/api/cmeks/types.tsindex e9c8392742..9e112fa186 100644--- a/frontend/src/hooks/api/cmeks/types.ts+++ b/frontend/src/hooks/api/cmeks/types.ts@@ -155,6 +155,7 @@ export enum CmekOrderBy {export enum AsymmetricKeyAlgorithm {RSA_4096 = "RSA_4096",ECC_NIST_P256 = "ECC_NIST_P256",+ ED25519 = "ED25519",ML_DSA_44 = "ML_DSA_44",ML_DSA_65 = "ML_DSA_65",ML_DSA_87 = "ML_DSA_87"@@ -196,6 +197,9 @@ export enum SigningAlgorithm {ECDSA_SHA_384 = "ECDSA_SHA_384",ECDSA_SHA_512 = "ECDSA_SHA_512",+ // Ed25519 (PureEdDSA): signing algorithm equals key algorithm+ ED25519 = "ED25519",+// ML-DSA (post-quantum) — signing algorithm equals key algorithmML_DSA_44 = "ML_DSA_44",ML_DSA_65 = "ML_DSA_65",diff --git a/frontend/src/pages/kms/OverviewPage/components/CmekSignModal.tsx b/frontend/src/pages/kms/OverviewPage/components/CmekSignModal.tsxindex eb5f8eb1b1..6221dee65f 100644--- a/frontend/src/pages/kms/OverviewPage/components/CmekSignModal.tsx+++ b/frontend/src/pages/kms/OverviewPage/components/CmekSignModal.tsx@@ -19,7 +19,7 @@ import {} from "@app/components/v2";import { getDefaultSigningAlgorithm } from "@app/helpers/kms";import { useTimedReset } from "@app/hooks";-import { SigningAlgorithm, TCmek, useCmekSign } from "@app/hooks/api/cmeks";+import { AsymmetricKeyAlgorithm, SigningAlgorithm, TCmek, useCmekSign } from "@app/hooks/api/cmeks";const formSchema = z.object({data: z.string(),@@ -74,7 +74,8 @@ const SignForm = ({ cmek }: FormProps) => {};const allowedSigningAlgorithms = Object.values(SigningAlgorithm).filter((a) => {- if (cmek?.algorithm?.startsWith("ML_DSA")) return (a as string) === (cmek.algorithm as string);+ if (cmek?.algorithm?.startsWith("ML_DSA") || cmek?.algorithm === AsymmetricKeyAlgorithm.ED25519)+ return (a as string) === (cmek.algorithm as string);if (cmek?.algorithm?.startsWith("RSA")) return a.toLowerCase().startsWith("rsa");return a.toLowerCase().startsWith("ecdsa");});diff --git a/frontend/src/pages/kms/OverviewPage/components/CmekVerifyModal.tsx b/frontend/src/pages/kms/OverviewPage/components/CmekVerifyModal.tsxindex 5c5ac7ecfe..e0a2f0acaa 100644--- a/frontend/src/pages/kms/OverviewPage/components/CmekVerifyModal.tsx+++ b/frontend/src/pages/kms/OverviewPage/components/CmekVerifyModal.tsx@@ -20,7 +20,12 @@ import {} from "@app/components/v2";import { Badge } from "@app/components/v3";import { getDefaultSigningAlgorithm } from "@app/helpers/kms";-import { SigningAlgorithm, TCmek, useCmekVerify } from "@app/hooks/api/cmeks";+import {+ AsymmetricKeyAlgorithm,+ SigningAlgorithm,+ TCmek,+ useCmekVerify+} from "@app/hooks/api/cmeks";import { isBase64 } from "@app/lib/fn/base64";const formSchema = z.object({@@ -92,7 +97,8 @@ const VerifyForm = ({ cmek }: FormProps) => {const signingAlgorithm = cmekVerify.data?.signingAlgorithm;const allowedSigningAlgorithms = Object.values(SigningAlgorithm).filter((a) => {- if (cmek?.algorithm?.startsWith("ML_DSA")) return (a as string) === (cmek.algorithm as string);+ if (cmek?.algorithm?.startsWith("ML_DSA") || cmek?.algorithm === AsymmetricKeyAlgorithm.ED25519)+ return (a as string) === (cmek.algorithm as string);if (cmek?.algorithm?.startsWith("RSA")) return a.toLowerCase().startsWith("rsa");return a.toLowerCase().startsWith("ecdsa");});