mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-19 02:25:07 +00:00
fix: requested changes
This commit is contained in:
@@ -1,2 +1,2 @@
|
||||
export { signingService } from "./signing";
|
||||
export { AsymmetricKeySignVerify, SigningAlgorithm } from "./types";
|
||||
export { AsymmetricKeyAlgorithm, SigningAlgorithm } from "./types";
|
||||
|
||||
@@ -3,7 +3,7 @@ import crypto from "crypto";
|
||||
import { BadRequestError } from "@app/lib/errors";
|
||||
import { logger } from "@app/lib/logger";
|
||||
|
||||
import { AsymmetricKeySignVerify, SigningAlgorithm, TAsymmetricSignVerifyFns } from "./types";
|
||||
import { AsymmetricKeyAlgorithm, SigningAlgorithm, TAsymmetricSignVerifyFns } from "./types";
|
||||
|
||||
// Map of signing algorithms to their parameters
|
||||
interface SigningParams {
|
||||
@@ -22,7 +22,7 @@ const SHA512_DIGEST_LENGTH = 64;
|
||||
* @param algorithm The signing algorithm to use
|
||||
* @returns Object with sign and verify functions
|
||||
*/
|
||||
export const signingService = (algorithm: AsymmetricKeySignVerify): TAsymmetricSignVerifyFns => {
|
||||
export const signingService = (algorithm: AsymmetricKeyAlgorithm): TAsymmetricSignVerifyFns => {
|
||||
const $getSigningParams = (signingAlgorithm: SigningAlgorithm): SigningParams => {
|
||||
switch (signingAlgorithm) {
|
||||
// RSA PSS
|
||||
@@ -76,10 +76,10 @@ export const signingService = (algorithm: AsymmetricKeySignVerify): TAsymmetricS
|
||||
};
|
||||
|
||||
// For ECC key generation, nodejs has some strange and hardly documented curve naming conventions
|
||||
const $getEcCurveName = (keyAlgorithm: AsymmetricKeySignVerify): string => {
|
||||
const $getEcCurveName = (keyAlgorithm: AsymmetricKeyAlgorithm): string => {
|
||||
// We will support more in the future
|
||||
switch (keyAlgorithm) {
|
||||
case AsymmetricKeySignVerify.ECC_NIST_P256:
|
||||
case AsymmetricKeyAlgorithm.ECC_NIST_P256:
|
||||
return "prime256v1";
|
||||
default:
|
||||
throw new Error(`Unsupported EC curve: ${keyAlgorithm}`);
|
||||
@@ -172,7 +172,6 @@ export const signingService = (algorithm: AsymmetricKeySignVerify): TAsymmetricS
|
||||
type: "pkcs8"
|
||||
});
|
||||
|
||||
// Return public key in PEM format for both RSA and EC
|
||||
const publicKey = crypto.createPublicKey(privateKeyObj).export({
|
||||
type: "spki",
|
||||
format: "pem"
|
||||
@@ -210,7 +209,8 @@ export const signingService = (algorithm: AsymmetricKeySignVerify): TAsymmetricS
|
||||
}
|
||||
// For PKCS1 v1.5 padding
|
||||
return signer.sign({
|
||||
key: privateKeyObject
|
||||
key: privateKeyObject,
|
||||
padding
|
||||
});
|
||||
}
|
||||
if (signingAlgorithm.startsWith("ECDSA")) {
|
||||
@@ -252,7 +252,8 @@ export const signingService = (algorithm: AsymmetricKeySignVerify): TAsymmetricS
|
||||
// For PKCS1 v1.5 padding
|
||||
return verifier.verify(
|
||||
{
|
||||
key: publicKey.toString()
|
||||
key: publicKey.toString(),
|
||||
padding
|
||||
},
|
||||
signature
|
||||
);
|
||||
|
||||
@@ -8,13 +8,13 @@ export type TAsymmetricSignVerifyFns = {
|
||||
};
|
||||
|
||||
// Supported asymmetric key types
|
||||
export enum AsymmetricKeySignVerify {
|
||||
export enum AsymmetricKeyAlgorithm {
|
||||
RSA_4096 = "rsa-4096",
|
||||
ECC_NIST_P256 = "ecc-nist-p256"
|
||||
}
|
||||
|
||||
export const AsymmetricKeySignVerifyEnum = z.enum(
|
||||
Object.values(AsymmetricKeySignVerify) as [string, ...string[]]
|
||||
export const AsymmetricKeyAlgorithmEnum = z.enum(
|
||||
Object.values(AsymmetricKeyAlgorithm) as [string, ...string[]]
|
||||
).options;
|
||||
|
||||
export enum SigningAlgorithm {
|
||||
|
||||
Reference in New Issue
Block a user