Skip to content

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

Addressed greptile comments

Carlos Monastyrski3c9a15e8853d
diff --git a/backend/src/ee/services/pki-scep/pki-scep-message-parser.test.ts b/backend/src/ee/services/pki-scep/pki-scep-message-parser.test.ts
index f5b2431244..c6c911f2f0 100644
--- a/backend/src/ee/services/pki-scep/pki-scep-message-parser.test.ts
+++ b/backend/src/ee/services/pki-scep/pki-scep-message-parser.test.ts
@@ -226,6 +226,10 @@ describe("parseScepMessage key transport", () => {
test.each([
["RSA PKCS#1 v1.5", PKCS1_V15],
+ [
+ "RSA PKCS#1 v1.5 labelled with a non-standard algorithm",
+ { ...PKCS1_V15, algorithm: new AlgorithmIdentifier({ algorithmId: SHA256_OID }) }
+ ],
["RSAES-OAEP with default SHA-1 parameters", OAEP_DEFAULT_PARAMS],
["RSAES-OAEP with SHA-256 parameters", OAEP_SHA256],
["RSAES-OAEP with an explicit label", OAEP_SHA256_WITH_LABEL]
@@ -283,11 +287,17 @@ describe("parseScepMessage key transport", () => {
);
});
- test("rejects a PKCSReq encrypted for a different key", async () => {
+ test("never returns the request when it was encrypted for a different key", async () => {
const otherRa = await createIdentity("Other RA");
+ const message = buildPkcsReq(csr, client, otherRa, OAEP_DEFAULT_PARAMS);
- expect(() => parseScepMessage(buildPkcsReq(csr, client, otherRa, OAEP_DEFAULT_PARAMS), exportPkcs8(ra))).toThrow(
- "Failed to decrypt SCEP enveloped data"
- );
+ let decryptedCsr: Buffer | undefined;
+ try {
+ decryptedCsr = parseScepMessage(message, exportPkcs8(ra)).csr;
+ } catch (err) {
+ expect((err as Error).message).toBe("Failed to decrypt SCEP enveloped data");
+ }
+
+ expect(decryptedCsr?.equals(csr) ?? false).toBe(false);
});
});
diff --git a/backend/src/ee/services/pki-scep/pki-scep-message-parser.ts b/backend/src/ee/services/pki-scep/pki-scep-message-parser.ts
index 46ef188d97..23a080d9bf 100644
--- a/backend/src/ee/services/pki-scep/pki-scep-message-parser.ts
+++ b/backend/src/ee/services/pki-scep/pki-scep-message-parser.ts
@@ -298,19 +298,11 @@ const parseKeyTransportAlgorithm = (keyEncryptionAlgorithm: asn1js.BaseBlock): T
try {
algorithm = new AlgorithmIdentifier({ schema: keyEncryptionAlgorithm });
} catch {
- throw new BadRequestError({
- message: "The SCEP client sent a malformed key encryption algorithm, so its request could not be decrypted."
- });
- }
-
- if (algorithm.algorithmId === KEY_TRANSPORT_OIDS.rsaEncryption) {
return { scheme: KeyTransportScheme.RsaPkcs1 };
}
if (algorithm.algorithmId !== KEY_TRANSPORT_OIDS.rsaesOaep) {
- throw new BadRequestError({
- message: `The SCEP client encrypted its request with an unsupported key encryption algorithm (OID ${algorithm.algorithmId}). Supported algorithms are RSA PKCS#1 v1.5 and RSA-OAEP.`
- });
+ return { scheme: KeyTransportScheme.RsaPkcs1 };
}
const { algorithmParams } = algorithm as { algorithmParams: unknown };