diff --git a/backend/src/ee/services/pki-acme/pki-acme-auth-dal.ts b/backend/src/ee/services/pki-acme/pki-acme-auth-dal.ts index d03275f9b..880d54dc9 100644 --- a/backend/src/ee/services/pki-acme/pki-acme-auth-dal.ts +++ b/backend/src/ee/services/pki-acme/pki-acme-auth-dal.ts @@ -17,7 +17,7 @@ export const pkiAcmeAuthDALFactory = (db: TDbClient) => { .select( selectAllTableCols(TableName.PkiAcmeAuth), db.ref("id").withSchema(TableName.PkiAcmeChallenge).as("challengeId"), - db.ref("token").withSchema(TableName.PkiAcmeChallenge).as("challengeToken"), + db.ref("type").withSchema(TableName.PkiAcmeChallenge).as("challengeType"), db.ref("status").withSchema(TableName.PkiAcmeChallenge).as("challengeStatus") ) .where(`${TableName.PkiAcmeAuth}.accountId`, accountId) @@ -34,9 +34,9 @@ export const pkiAcmeAuthDALFactory = (db: TDbClient) => { { key: "challengeId", label: "challenges" as const, - mapper: ({ challengeId, challengeToken, challengeStatus }) => ({ + mapper: ({ challengeId, challengeType, challengeStatus }) => ({ id: challengeId, - token: challengeToken, + type: challengeType, status: challengeStatus }) } 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 97e08d757..0658886a4 100644 --- a/backend/src/ee/services/pki-acme/pki-acme-service.ts +++ b/backend/src/ee/services/pki-acme/pki-acme-service.ts @@ -49,12 +49,13 @@ import { TRawJwsPayload, TRespondToAcmeChallengeResponse } from "./pki-acme-types"; +import { TPkiAcmeChallenges } from "@app/db/schemas"; type TPkiAcmeServiceFactoryDep = { certificateProfileDAL: Pick; acmeAccountDAL: Pick; acmeOrderDAL: Pick; - acmeAuthDAL: Pick; + acmeAuthDAL: Pick; acmeOrderAuthDAL: Pick; }; @@ -514,8 +515,8 @@ export const pkiAcmeServiceFactory = ({ accountId: string; authzId: string; }): Promise> => { - const auth = await acmeAuthDAL.findById(authzId); - if (!auth || auth.accountId !== accountId) { + const auth = await acmeAuthDAL.findByAccountIdAndAuthIdWithChallenges(accountId, authzId); + if (!auth) { throw new NotFoundError({ message: "ACME authorization not found" }); } return { @@ -527,15 +528,16 @@ export const pkiAcmeServiceFactory = ({ type: auth.identifierType, value: auth.identifierValue }, - challenges: [ - // TODO: fixme - { - type: "http-01", - url: buildUrl(`/api/v1/pki/acme/profiles/${profileId}/authorizations/${authzId}/challenges/http-01`), - status: "pending", + challenges: auth.challenges.map((challenge: TPkiAcmeChallenges) => { + return { + type: challenge.type, + url: buildUrl( + `/api/v1/pki/acme/profiles/${profileId}/authorizations/${authzId}/challenges/${challenge.id}` + ), + status: challenge.status, token: auth.token - } - ] + }; + }) }, headers: { Location: buildUrl(`/api/v1/pki/acme/profiles/${profileId}/authorizations/${authzId}`)