mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-02 21:25:45 +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) => {
|
const findByAccountAuthAndChallengeId = async (accountId: string, authId: string, challengeId: string, tx?: Knex) => {
|
||||||
try {
|
try {
|
||||||
const challenge = await (tx || db)(TableName.PkiAcmeChallenge)
|
const challenge = await (tx || db)(TableName.PkiAcmeChallenge)
|
||||||
@@ -126,6 +139,7 @@ export const pkiAcmeChallengeDALFactory = (db: TDbClient) => {
|
|||||||
return {
|
return {
|
||||||
...pkiAcmeChallengeOrm,
|
...pkiAcmeChallengeOrm,
|
||||||
markAsValidCascadeById,
|
markAsValidCascadeById,
|
||||||
|
markAsInvalidCascadeById,
|
||||||
findByAccountAuthAndChallengeId,
|
findByAccountAuthAndChallengeId,
|
||||||
findByIdForChallengeValidation
|
findByIdForChallengeValidation
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import { TPkiAcmeChallengeDALFactory } from "./pki-acme-challenge-dal";
|
|||||||
import { AcmeIncorrectResponseError } from "./pki-acme-errors";
|
import { AcmeIncorrectResponseError } from "./pki-acme-errors";
|
||||||
import { AcmeAuthStatus, AcmeChallengeStatus, AcmeChallengeType } from "./pki-acme-schemas";
|
import { AcmeAuthStatus, AcmeChallengeStatus, AcmeChallengeType } from "./pki-acme-schemas";
|
||||||
import { TPkiAcmeChallengeServiceFactory } from "./pki-acme-types";
|
import { TPkiAcmeChallengeServiceFactory } from "./pki-acme-types";
|
||||||
|
import { TPkiAcmeChallenges } from "@app/db/schemas";
|
||||||
|
|
||||||
type TPkiAcmeChallengeServiceFactoryDep = {
|
type TPkiAcmeChallengeServiceFactoryDep = {
|
||||||
acmeAuthDAL: Pick<TPkiAcmeAuthDALFactory, "updateById">;
|
acmeAuthDAL: Pick<TPkiAcmeAuthDALFactory, "updateById">;
|
||||||
@@ -23,8 +24,8 @@ export const pkiAcmeChallengeServiceFactory = ({
|
|||||||
}: TPkiAcmeChallengeServiceFactoryDep): TPkiAcmeChallengeServiceFactory => {
|
}: TPkiAcmeChallengeServiceFactoryDep): TPkiAcmeChallengeServiceFactory => {
|
||||||
const appCfg = getConfig();
|
const appCfg = getConfig();
|
||||||
|
|
||||||
const validateChallengeResponse = async (challengeId: string, tx?: Knex): Promise<void> => {
|
const validateChallengeResponse = async (challengeId: string): Promise<void> => {
|
||||||
return await acmeChallengeDAL.transaction(async (tx: Knex) => {
|
return await acmeChallengeDAL.transaction(async (tx) => {
|
||||||
logger.info({ challengeId }, "Validating ACME challenge response");
|
logger.info({ challengeId }, "Validating ACME challenge response");
|
||||||
const challenge = await acmeChallengeDAL.findByIdForChallengeValidation(challengeId, tx);
|
const challenge = await acmeChallengeDAL.findByIdForChallengeValidation(challengeId, tx);
|
||||||
if (!challenge) {
|
if (!challenge) {
|
||||||
@@ -72,9 +73,7 @@ export const pkiAcmeChallengeServiceFactory = ({
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(error, "Error validating ACME challenge response");
|
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
|
// 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 acmeChallengeDAL.markAsValidCascadeById(challengeId, tx);
|
||||||
await acmeAuthDAL.updateById(challenge.auth.account.id, { status: AcmeAuthStatus.Invalid }, tx);
|
|
||||||
// TODO: trigger a check for order status as well
|
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -611,14 +611,8 @@ export const pkiAcmeServiceFactory = ({
|
|||||||
if (!result) {
|
if (!result) {
|
||||||
throw new NotFoundError({ message: "ACME challenge not found" });
|
throw new NotFoundError({ message: "ACME challenge not found" });
|
||||||
}
|
}
|
||||||
const challenge = await acmeChallengeDAL.transaction(async (tx) => {
|
await acmeChallengeService.validateChallengeResponse(challengeId);
|
||||||
await acmeChallengeService.validateChallengeResponse(challengeId, tx);
|
const challenge = (await acmeChallengeDAL.findByIdForChallengeValidation(challengeId))!;
|
||||||
return {
|
|
||||||
...challenge,
|
|
||||||
...updatedChallenge
|
|
||||||
};
|
|
||||||
});
|
|
||||||
// TODO: Implement ACME challenge response
|
|
||||||
return {
|
return {
|
||||||
status: 200,
|
status: 200,
|
||||||
body: {
|
body: {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
|
import { TPkiAcmeChallenges } from "@app/db/schemas";
|
||||||
import { JWSHeaderParameters } from "jose";
|
import { JWSHeaderParameters } from "jose";
|
||||||
import {
|
import {
|
||||||
AcmeOrderResourceSchema,
|
AcmeOrderResourceSchema,
|
||||||
|
|||||||
Reference in New Issue
Block a user