mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-09-22 13:39:35 +00:00
Try to make challenge works
This commit is contained in:
@@ -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
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -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: {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { z } from "zod";
|
||||
|
||||
import { TPkiAcmeChallenges } from "@app/db/schemas";
|
||||
import { JWSHeaderParameters } from "jose";
|
||||
import {
|
||||
AcmeOrderResourceSchema,
|
||||
|
||||
Reference in New Issue
Block a user