Compare commits

...

1 Commits

Author SHA1 Message Date
dad65cc278 fix: rename isDigest to preDigested 2025-04-15 03:47:32 +04:00
8 changed files with 27 additions and 27 deletions

View File

@ -1719,7 +1719,7 @@ export const KMS = {
SIGN: { SIGN: {
keyId: "The ID of the key to sign the data with.", keyId: "The ID of the key to sign the data with.",
data: "The data in string format to be signed (base64 encoded).", data: "The data in string format to be signed (base64 encoded).",
isDigest: preDigested:
"Whether the data is already digested or not. Please be aware that if you are passing a digest the algorithm used to create the digest must match the signing algorithm used to sign the digest.", "Whether the data is already digested or not. Please be aware that if you are passing a digest the algorithm used to create the digest must match the signing algorithm used to sign the digest.",
signingAlgorithm: "The algorithm to use when performing cryptographic operations with the key." signingAlgorithm: "The algorithm to use when performing cryptographic operations with the key."
}, },
@ -1727,7 +1727,7 @@ export const KMS = {
keyId: "The ID of the key to verify the data with.", keyId: "The ID of the key to verify the data with.",
data: "The data in string format to be verified (base64 encoded). For data larger than 4096 bytes you must first create a digest of the data and then pass the digest in the data parameter.", data: "The data in string format to be verified (base64 encoded). For data larger than 4096 bytes you must first create a digest of the data and then pass the digest in the data parameter.",
signature: "The signature to be verified (base64 encoded).", signature: "The signature to be verified (base64 encoded).",
isDigest: "Whether the data is already digested or not." preDigested: "Whether the data is already digested or not."
} }
}; };

View File

@ -339,13 +339,13 @@ export const signingService = (algorithm: AsymmetricKeyAlgorithm): TAsymmetricSi
data: Buffer, data: Buffer,
privateKey: Buffer, privateKey: Buffer,
signingAlgorithm: SigningAlgorithm, signingAlgorithm: SigningAlgorithm,
isDigest: boolean preDigested: boolean
): Promise<Buffer> => { ): Promise<Buffer> => {
$validateAlgorithmWithKeyType(signingAlgorithm); $validateAlgorithmWithKeyType(signingAlgorithm);
const { hashAlgorithm, padding, saltLength } = $getSigningParams(signingAlgorithm); const { hashAlgorithm, padding, saltLength } = $getSigningParams(signingAlgorithm);
if (isDigest) { if (preDigested) {
if (signingAlgorithm.startsWith("RSASSA_PSS")) { if (signingAlgorithm.startsWith("RSASSA_PSS")) {
throw new BadRequestError({ throw new BadRequestError({
message: "RSA PSS does not support digested input" message: "RSA PSS does not support digested input"
@ -400,14 +400,14 @@ export const signingService = (algorithm: AsymmetricKeyAlgorithm): TAsymmetricSi
signature: Buffer, signature: Buffer,
publicKey: Buffer, publicKey: Buffer,
signingAlgorithm: SigningAlgorithm, signingAlgorithm: SigningAlgorithm,
isDigest: boolean preDigested: boolean
): Promise<boolean> => { ): Promise<boolean> => {
try { try {
$validateAlgorithmWithKeyType(signingAlgorithm); $validateAlgorithmWithKeyType(signingAlgorithm);
const { hashAlgorithm, padding, saltLength } = $getSigningParams(signingAlgorithm); const { hashAlgorithm, padding, saltLength } = $getSigningParams(signingAlgorithm);
if (isDigest) { if (preDigested) {
if (signingAlgorithm.startsWith("RSASSA_PSS")) { if (signingAlgorithm.startsWith("RSASSA_PSS")) {
throw new BadRequestError({ throw new BadRequestError({
message: "RSA PSS does not support digested input" message: "RSA PSS does not support digested input"

View File

@ -1,13 +1,13 @@
import { z } from "zod"; import { z } from "zod";
export type TAsymmetricSignVerifyFns = { export type TAsymmetricSignVerifyFns = {
sign: (data: Buffer, key: Buffer, signingAlgorithm: SigningAlgorithm, isDigest: boolean) => Promise<Buffer>; sign: (data: Buffer, key: Buffer, signingAlgorithm: SigningAlgorithm, preDigested: boolean) => Promise<Buffer>;
verify: ( verify: (
data: Buffer, data: Buffer,
signature: Buffer, signature: Buffer,
key: Buffer, key: Buffer,
signingAlgorithm: SigningAlgorithm, signingAlgorithm: SigningAlgorithm,
isDigest: boolean preDigested: boolean
) => Promise<boolean>; ) => Promise<boolean>;
generateAsymmetricPrivateKey: () => Promise<Buffer>; generateAsymmetricPrivateKey: () => Promise<Buffer>;
getPublicKeyFromPrivateKey: (privateKey: Buffer) => Buffer; getPublicKeyFromPrivateKey: (privateKey: Buffer) => Buffer;

View File

@ -501,7 +501,7 @@ export const registerCmekRouter = async (server: FastifyZodProvider) => {
}), }),
body: z.object({ body: z.object({
signingAlgorithm: z.nativeEnum(SigningAlgorithm), signingAlgorithm: z.nativeEnum(SigningAlgorithm),
isDigest: z.boolean().optional().default(false).describe(KMS.SIGN.isDigest), preDigested: z.boolean().optional().default(false).describe(KMS.SIGN.preDigested),
data: base64Schema.describe(KMS.SIGN.data) data: base64Schema.describe(KMS.SIGN.data)
}), }),
response: { response: {
@ -516,12 +516,12 @@ export const registerCmekRouter = async (server: FastifyZodProvider) => {
handler: async (req) => { handler: async (req) => {
const { const {
params: { keyId: inputKeyId }, params: { keyId: inputKeyId },
body: { data, signingAlgorithm, isDigest }, body: { data, signingAlgorithm, preDigested },
permission permission
} = req; } = req;
const { projectId, ...result } = await server.services.cmek.cmekSign( const { projectId, ...result } = await server.services.cmek.cmekSign(
{ keyId: inputKeyId, data, signingAlgorithm, isDigest }, { keyId: inputKeyId, data, signingAlgorithm, preDigested },
permission permission
); );
@ -553,7 +553,7 @@ export const registerCmekRouter = async (server: FastifyZodProvider) => {
keyId: z.string().uuid().describe(KMS.VERIFY.keyId) keyId: z.string().uuid().describe(KMS.VERIFY.keyId)
}), }),
body: z.object({ body: z.object({
isDigest: z.boolean().optional().default(false).describe(KMS.VERIFY.isDigest), preDigested: z.boolean().optional().default(false).describe(KMS.VERIFY.preDigested),
data: base64Schema.describe(KMS.VERIFY.data), data: base64Schema.describe(KMS.VERIFY.data),
signature: base64Schema.describe(KMS.VERIFY.signature), signature: base64Schema.describe(KMS.VERIFY.signature),
signingAlgorithm: z.nativeEnum(SigningAlgorithm) signingAlgorithm: z.nativeEnum(SigningAlgorithm)
@ -570,12 +570,12 @@ export const registerCmekRouter = async (server: FastifyZodProvider) => {
handler: async (req) => { handler: async (req) => {
const { const {
params: { keyId }, params: { keyId },
body: { data, signature, signingAlgorithm, isDigest }, body: { data, signature, signingAlgorithm, preDigested },
permission permission
} = req; } = req;
const { projectId, ...result } = await server.services.cmek.cmekVerify( const { projectId, ...result } = await server.services.cmek.cmekVerify(
{ keyId, data, signature, signingAlgorithm, isDigest }, { keyId, data, signature, signingAlgorithm, preDigested },
permission permission
); );

View File

@ -304,7 +304,7 @@ export const cmekServiceFactory = ({ kmsService, kmsDAL, permissionService, proj
return { publicKey: publicKey.toString("base64"), projectId: key.projectId }; return { publicKey: publicKey.toString("base64"), projectId: key.projectId };
}; };
const cmekSign = async ({ keyId, data, signingAlgorithm, isDigest }: TCmekSignDTO, actor: OrgServiceActor) => { const cmekSign = async ({ keyId, data, signingAlgorithm, preDigested }: TCmekSignDTO, actor: OrgServiceActor) => {
const key = await kmsDAL.findCmekById(keyId); const key = await kmsDAL.findCmekById(keyId);
if (!key) throw new NotFoundError({ message: `Key with ID "${keyId}" not found` }); if (!key) throw new NotFoundError({ message: `Key with ID "${keyId}" not found` });
@ -326,7 +326,7 @@ export const cmekServiceFactory = ({ kmsService, kmsDAL, permissionService, proj
const sign = await kmsService.signWithKmsKey({ kmsId: keyId }); const sign = await kmsService.signWithKmsKey({ kmsId: keyId });
const { signature, algorithm } = await sign({ data: Buffer.from(data, "base64"), signingAlgorithm, isDigest }); const { signature, algorithm } = await sign({ data: Buffer.from(data, "base64"), signingAlgorithm, preDigested });
return { return {
signature: signature.toString("base64"), signature: signature.toString("base64"),
@ -337,7 +337,7 @@ export const cmekServiceFactory = ({ kmsService, kmsDAL, permissionService, proj
}; };
const cmekVerify = async ( const cmekVerify = async (
{ keyId, data, signature, signingAlgorithm, isDigest }: TCmekVerifyDTO, { keyId, data, signature, signingAlgorithm, preDigested }: TCmekVerifyDTO,
actor: OrgServiceActor actor: OrgServiceActor
) => { ) => {
const key = await kmsDAL.findCmekById(keyId); const key = await kmsDAL.findCmekById(keyId);
@ -362,7 +362,7 @@ export const cmekServiceFactory = ({ kmsService, kmsDAL, permissionService, proj
const verify = await kmsService.verifyWithKmsKey({ kmsId: keyId, signingAlgorithm }); const verify = await kmsService.verifyWithKmsKey({ kmsId: keyId, signingAlgorithm });
const { signatureValid, algorithm } = await verify({ const { signatureValid, algorithm } = await verify({
isDigest, preDigested,
data: Buffer.from(data, "base64"), data: Buffer.from(data, "base64"),
signature: Buffer.from(signature, "base64") signature: Buffer.from(signature, "base64")
}); });

View File

@ -57,7 +57,7 @@ export type TCmekSignDTO = {
keyId: string; keyId: string;
data: string; data: string;
signingAlgorithm: SigningAlgorithm; signingAlgorithm: SigningAlgorithm;
isDigest: boolean; preDigested: boolean;
}; };
export type TCmekVerifyDTO = { export type TCmekVerifyDTO = {
@ -65,5 +65,5 @@ export type TCmekVerifyDTO = {
data: string; data: string;
signature: string; signature: string;
signingAlgorithm: SigningAlgorithm; signingAlgorithm: SigningAlgorithm;
isDigest: boolean; preDigested: boolean;
}; };

View File

@ -469,10 +469,10 @@ export const kmsServiceFactory = ({
return async ({ return async ({
data, data,
signingAlgorithm, signingAlgorithm,
isDigest preDigested
}: Pick<TSignWithKmsDTO, "data" | "signingAlgorithm" | "isDigest">) => { }: Pick<TSignWithKmsDTO, "data" | "signingAlgorithm" | "preDigested">) => {
const kmsKey = keyCipher.decrypt(kmsDoc.internalKms?.encryptedKey as Buffer, ROOT_ENCRYPTION_KEY); const kmsKey = keyCipher.decrypt(kmsDoc.internalKms?.encryptedKey as Buffer, ROOT_ENCRYPTION_KEY);
const signature = await sign(data, kmsKey, signingAlgorithm, isDigest); const signature = await sign(data, kmsKey, signingAlgorithm, preDigested);
return Promise.resolve({ signature, algorithm: signingAlgorithm }); return Promise.resolve({ signature, algorithm: signingAlgorithm });
}; };
@ -494,11 +494,11 @@ export const kmsServiceFactory = ({
const keyCipher = symmetricCipherService(SymmetricKeyAlgorithm.AES_GCM_256); const keyCipher = symmetricCipherService(SymmetricKeyAlgorithm.AES_GCM_256);
const { verify, getPublicKeyFromPrivateKey } = signingService(encryptionAlgorithm); const { verify, getPublicKeyFromPrivateKey } = signingService(encryptionAlgorithm);
return async ({ data, signature, isDigest }: Pick<TVerifyWithKmsDTO, "data" | "signature" | "isDigest">) => { return async ({ data, signature, preDigested }: Pick<TVerifyWithKmsDTO, "data" | "signature" | "preDigested">) => {
const kmsKey = keyCipher.decrypt(kmsDoc.internalKms?.encryptedKey as Buffer, ROOT_ENCRYPTION_KEY); const kmsKey = keyCipher.decrypt(kmsDoc.internalKms?.encryptedKey as Buffer, ROOT_ENCRYPTION_KEY);
const publicKey = getPublicKeyFromPrivateKey(kmsKey); const publicKey = getPublicKeyFromPrivateKey(kmsKey);
const signatureValid = await verify(data, signature, publicKey, signingAlgorithm, isDigest); const signatureValid = await verify(data, signature, publicKey, signingAlgorithm, preDigested);
return Promise.resolve({ signatureValid, algorithm: signingAlgorithm }); return Promise.resolve({ signatureValid, algorithm: signingAlgorithm });
}; };
}; };

View File

@ -52,7 +52,7 @@ export type TSignWithKmsDTO = {
kmsId: string; kmsId: string;
data: Buffer; data: Buffer;
signingAlgorithm: SigningAlgorithm; signingAlgorithm: SigningAlgorithm;
isDigest: boolean; preDigested: boolean;
}; };
export type TVerifyWithKmsDTO = { export type TVerifyWithKmsDTO = {
@ -60,7 +60,7 @@ export type TVerifyWithKmsDTO = {
data: Buffer; data: Buffer;
signature: Buffer; signature: Buffer;
signingAlgorithm: SigningAlgorithm; signingAlgorithm: SigningAlgorithm;
isDigest: boolean; preDigested: boolean;
}; };
export type TEncryptionWithKeyDTO = { export type TEncryptionWithKeyDTO = {