Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

Try to make challenge works

Fang-Pen Lin737bbd3e08ca
diff --git a/backend/src/ee/services/pki-acme/pki-acme-challenge-dal.ts b/backend/src/ee/services/pki-acme/pki-acme-challenge-dal.ts
index 6cc465d99a..48bc1dfac6 100644
--- a/backend/src/ee/services/pki-acme/pki-acme-challenge-dal.ts
+++ b/backend/src/ee/services/pki-acme/pki-acme-challenge-dal.ts
@@ -56,6 +56,19 @@ export const pkiAcmeChallengeDALFactory = (db: TDbClient) => {
}
};
+ const markAsInvalidCascadeById = async (id: string, tx?: Knex): Promise<TPkiAcmeChallenges> => {
+ try {
+ const [challenge] = (await (tx || db)(TableName.PkiAcmeChallenge)
+ .where({ id })
+ .update({ status: AcmeChallengeStatus.Valid, validatedAt: new Date() })
+ .returning("*")) as [TPkiAcmeChallenges];
+ // TODO:
+ return challenge;
+ } catch (error) {
+ throw new DatabaseError({ error, name: "Update certificate profile" });
+ }
+ };
+
const findByAccountAuthAndChallengeId = async (accountId: string, authId: string, challengeId: string, tx?: Knex) => {
try {
const challenge = await (tx || db)(TableName.PkiAcmeChallenge)
@@ -126,6 +139,7 @@ export const pkiAcmeChallengeDALFactory = (db: TDbClient) => {
return {
...pkiAcmeChallengeOrm,
markAsValidCascadeById,
+ markAsInvalidCascadeById,
findByAccountAuthAndChallengeId,
findByIdForChallengeValidation
};
diff --git a/backend/src/ee/services/pki-acme/pki-acme-challenge-service.ts b/backend/src/ee/services/pki-acme/pki-acme-challenge-service.ts
index 6cb04f2d5e..af0ea0ebe9 100644
--- a/backend/src/ee/services/pki-acme/pki-acme-challenge-service.ts
+++ b/backend/src/ee/services/pki-acme/pki-acme-challenge-service.ts
@@ -8,6 +8,7 @@ import { TPkiAcmeChallengeDALFactory } from "./pki-acme-challenge-dal";
import { AcmeIncorrectResponseError } from "./pki-acme-errors";
import { AcmeAuthStatus, AcmeChallengeStatus, AcmeChallengeType } from "./pki-acme-schemas";
import { TPkiAcmeChallengeServiceFactory } from "./pki-acme-types";
+import { TPkiAcmeChallenges } from "@app/db/schemas";
type TPkiAcmeChallengeServiceFactoryDep = {
acmeAuthDAL: Pick<TPkiAcmeAuthDALFactory, "updateById">;
@@ -23,8 +24,8 @@ export const pkiAcmeChallengeServiceFactory = ({
}: TPkiAcmeChallengeServiceFactoryDep): TPkiAcmeChallengeServiceFactory => {
const appCfg = getConfig();
- const validateChallengeResponse = async (challengeId: string, tx?: Knex): Promise<void> => {
- return await acmeChallengeDAL.transaction(async (tx: Knex) => {
+ const validateChallengeResponse = async (challengeId: string): Promise<void> => {
+ return await acmeChallengeDAL.transaction(async (tx) => {
logger.info({ challengeId }, "Validating ACME challenge response");
const challenge = await acmeChallengeDAL.findByIdForChallengeValidation(challengeId, tx);
if (!challenge) {
@@ -72,9 +73,7 @@ export const pkiAcmeChallengeServiceFactory = ({
} catch (error) {
logger.error(error, "Error validating ACME challenge response");
// TODO: we should retry the challenge validation a few times, but let's keep it simple for now
- await acmeChallengeDAL.updateById(challengeId, { status: AcmeChallengeStatus.Invalid }, tx);
- await acmeAuthDAL.updateById(challenge.auth.account.id, { status: AcmeAuthStatus.Invalid }, tx);
- // TODO: trigger a check for order status as well
+ await acmeChallengeDAL.markAsValidCascadeById(challengeId, tx);
throw error;
}
});
diff --git a/backend/src/ee/services/pki-acme/pki-acme-service.ts b/backend/src/ee/services/pki-acme/pki-acme-service.ts
index a4916c5555..6dad459c20 100644
--- a/backend/src/ee/services/pki-acme/pki-acme-service.ts
+++ b/backend/src/ee/services/pki-acme/pki-acme-service.ts
@@ -611,14 +611,8 @@ export const pkiAcmeServiceFactory = ({
if (!result) {
throw new NotFoundError({ message: "ACME challenge not found" });
}
- const challenge = await acmeChallengeDAL.transaction(async (tx) => {
- await acmeChallengeService.validateChallengeResponse(challengeId, tx);
- return {
- ...challenge,
- ...updatedChallenge
- };
- });
- // TODO: Implement ACME challenge response
+ await acmeChallengeService.validateChallengeResponse(challengeId);
+ const challenge = (await acmeChallengeDAL.findByIdForChallengeValidation(challengeId))!;
return {
status: 200,
body: {
diff --git a/backend/src/ee/services/pki-acme/pki-acme-types.ts b/backend/src/ee/services/pki-acme/pki-acme-types.ts
index c993acf647..e9154fb5da 100644
--- a/backend/src/ee/services/pki-acme/pki-acme-types.ts
+++ b/backend/src/ee/services/pki-acme/pki-acme-types.ts
@@ -1,5 +1,6 @@
import { z } from "zod";
+import { TPkiAcmeChallenges } from "@app/db/schemas";
import { JWSHeaderParameters } from "jose";
import {
AcmeOrderResourceSchema,