mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-07 15:27:46 +00:00
Use thumbprint instead
This commit is contained in:
@@ -20,19 +20,23 @@ export const pkiAcmeAccountDALFactory = (db: TDbClient) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const findByPublicKey = async (profileId: string, alg: string, publicKey: unknown, tx?: Knex) => {
|
const findByProfileIdAndPublicKeyThumbprintAndAlg = async (
|
||||||
|
profileId: string,
|
||||||
|
alg: string,
|
||||||
|
publicKeyThumbprint: string,
|
||||||
|
tx?: Knex
|
||||||
|
) => {
|
||||||
try {
|
try {
|
||||||
const account = await (tx || db)(TableName.PkiAcmeAccount).where({ profileId, alg, publicKey }).first();
|
const account = await (tx || db)(TableName.PkiAcmeAccount).where({ profileId, alg, publicKeyThumbprint }).first();
|
||||||
|
|
||||||
return account || null;
|
return account || null;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new DatabaseError({ error, name: "Find PKI ACME account by public key and alg" });
|
throw new DatabaseError({ error, name: "Find PKI ACME account by profile id, public key thumbprint and alg" });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...pkiAcmeAccountOrm,
|
...pkiAcmeAccountOrm,
|
||||||
findByProjectIdAndAccountId,
|
findByProjectIdAndAccountId,
|
||||||
findByPublicKey
|
findByProfileIdAndPublicKeyThumbprintAndAlg
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -11,7 +11,14 @@ import {
|
|||||||
EnrollmentType,
|
EnrollmentType,
|
||||||
TCertificateProfileWithConfigs
|
TCertificateProfileWithConfigs
|
||||||
} from "@app/services/certificate-profile/certificate-profile-types";
|
} from "@app/services/certificate-profile/certificate-profile-types";
|
||||||
import { errors, flattenedVerify, FlattenedVerifyResult, importJWK, JWSHeaderParameters } from "jose";
|
import {
|
||||||
|
calculateJwkThumbprint,
|
||||||
|
errors,
|
||||||
|
flattenedVerify,
|
||||||
|
FlattenedVerifyResult,
|
||||||
|
importJWK,
|
||||||
|
JWSHeaderParameters
|
||||||
|
} from "jose";
|
||||||
import { z, ZodError } from "zod";
|
import { z, ZodError } from "zod";
|
||||||
import { TPkiAcmeAccountDALFactory } from "./pki-acme-account-dal";
|
import { TPkiAcmeAccountDALFactory } from "./pki-acme-account-dal";
|
||||||
import { TPkiAcmeAuthDALFactory } from "./pki-acme-auth-dal";
|
import { TPkiAcmeAuthDALFactory } from "./pki-acme-auth-dal";
|
||||||
@@ -57,7 +64,10 @@ import {
|
|||||||
|
|
||||||
type TPkiAcmeServiceFactoryDep = {
|
type TPkiAcmeServiceFactoryDep = {
|
||||||
certificateProfileDAL: Pick<TCertificateProfileDALFactory, "findById">;
|
certificateProfileDAL: Pick<TCertificateProfileDALFactory, "findById">;
|
||||||
acmeAccountDAL: Pick<TPkiAcmeAccountDALFactory, "findByProjectIdAndAccountId" | "findByPublicKey" | "create">;
|
acmeAccountDAL: Pick<
|
||||||
|
TPkiAcmeAccountDALFactory,
|
||||||
|
"findByProjectIdAndAccountId" | "findByProfileIdAndPublicKeyThumbprintAndAlg" | "create"
|
||||||
|
>;
|
||||||
acmeOrderDAL: Pick<TPkiAcmeOrderDALFactory, "create" | "transaction" | "findByAccountAndOrderIdWithAuthorizations">;
|
acmeOrderDAL: Pick<TPkiAcmeOrderDALFactory, "create" | "transaction" | "findByAccountAndOrderIdWithAuthorizations">;
|
||||||
acmeAuthDAL: Pick<TPkiAcmeAuthDALFactory, "create" | "findByAccountIdAndAuthIdWithChallenges">;
|
acmeAuthDAL: Pick<TPkiAcmeAuthDALFactory, "create" | "findByAccountIdAndAuthIdWithChallenges">;
|
||||||
acmeOrderAuthDAL: Pick<TPkiAcmeOrderAuthDALFactory, "insertMany">;
|
acmeOrderAuthDAL: Pick<TPkiAcmeOrderAuthDALFactory, "insertMany">;
|
||||||
@@ -286,8 +296,12 @@ export const pkiAcmeServiceFactory = ({
|
|||||||
payload: TCreateAcmeAccountPayload;
|
payload: TCreateAcmeAccountPayload;
|
||||||
}): Promise<TAcmeResponse<TCreateAcmeAccountResponse>> => {
|
}): Promise<TAcmeResponse<TCreateAcmeAccountResponse>> => {
|
||||||
const profile = await validateAcmeProfile(profileId);
|
const profile = await validateAcmeProfile(profileId);
|
||||||
// TODO: ensure unique account per public key
|
const publicKeyThumbprint = await calculateJwkThumbprint(jwk, "sha256");
|
||||||
const existingAccount: TPkiAcmeAccounts | null = await acmeAccountDAL.findByPublicKey(profileId, alg, jwk);
|
const existingAccount: TPkiAcmeAccounts | null = await acmeAccountDAL.findByProfileIdAndPublicKeyThumbprintAndAlg(
|
||||||
|
profileId,
|
||||||
|
alg,
|
||||||
|
publicKeyThumbprint
|
||||||
|
);
|
||||||
if (onlyReturnExisting && !existingAccount) {
|
if (onlyReturnExisting && !existingAccount) {
|
||||||
throw new AcmeAccountDoesNotExistError({ message: "ACME account not found" });
|
throw new AcmeAccountDoesNotExistError({ message: "ACME account not found" });
|
||||||
}
|
}
|
||||||
@@ -311,6 +325,7 @@ export const pkiAcmeServiceFactory = ({
|
|||||||
profileId: profile.id,
|
profileId: profile.id,
|
||||||
alg,
|
alg,
|
||||||
publicKey: jwk,
|
publicKey: jwk,
|
||||||
|
publicKeyThumbprint,
|
||||||
emails: contact ?? []
|
emails: contact ?? []
|
||||||
});
|
});
|
||||||
// TODO: create audit log here
|
// TODO: create audit log here
|
||||||
|
|||||||
Reference in New Issue
Block a user