Skip to content

Commit 3325bb6

Browse files
committed
chore: add comment about policy chosen for SecTrustEvaluateWithError
1 parent 3ae29ba commit 3325bb6

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/crypto/crypto_context.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,16 @@ bool IsCertificateTrustValid(SecCertificateRef ref) {
456456
CFArrayCreateMutable(nullptr, 1, &kCFTypeArrayCallBacks);
457457
CFArraySetValueAtIndex(subj_certs, 0, ref);
458458

459+
// SecTrustEvaluateWithError is used to check whether an individual
460+
// certificate is trusted by the system — not to validate it for a
461+
// specific role (server, intermediate, etc.). We just need a minimal
462+
// policy that guarantees the certificate can be chained to a known
463+
// trust anchor while filtering out irrelevant certificates.
464+
//
465+
// Refs https://github.com/apple-oss-distributions/Security/blob/db15acbe6a7f257a859ad9a3bb86097bfe0679d9/OSX/sec/Security/SecPolicy.c#L1855-L1890
466+
// SecPolicyCreateSSL (both mark EKU optional):
467+
// server=true -> BasicX509 + serverAuth + anyExtendedKeyUsage + SGC
468+
// server=false -> BasicX509 + clientAuth + anyExtendedKeyUsage
459469
SecPolicyRef policy = SecPolicyCreateSSL(false, nullptr);
460470
OSStatus ortn =
461471
SecTrustCreateWithCertificates(subj_certs, policy, &sec_trust);

0 commit comments

Comments
 (0)