You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Skip certs with gateway-unparseable subjects during sync
During Synchronize, mirror the subject parsing the AnyCA Gateway performs
when building its /v2/certificate/search response
(new X509Name(true, netCert.Subject)). That call throws on subjects
BouncyCastle cannot re-parse from .NET's string representation, which returns
a 500 for the entire search page and aborts Command's CA sync.
GatewayCanParseSubject runs the same parse on each certificate before it is
added to the sync buffer. Certificates that would throw are skipped with a
[SYNC-SKIP] warning and counted, so a single unparseable subject never lands
in the gateway database and can never break the downstream Command sync. The
gateway-side fix (try/catch or reading the subject from DER) will be handled
separately.
_logger.LogWarning($"[SYNC-SKIP] Skipping certificate {pluginCertificate.CARequestID} - its subject would fail the AnyCA Gateway X509Name parse and abort the sync. Subject='{subject}', reason: {skipReason}");
285
+
continue;
286
+
}
287
+
288
+
certificatesBuffer.Add(pluginCertificate);
274
289
numberOfCertificates++;
275
290
_logger.LogDebug($"Found Certificate with name {certificate.CertificateName.CertificateId}{this.ToString()}");
276
291
}
@@ -298,7 +313,7 @@ public async Task<int> DownloadAllIssuedCertificates(BlockingCollection<AnyCAPlu
298
313
{
299
314
certificatesBuffer.CompleteAdding();
300
315
_logger.LogDebug($"Fetched {certificatesBuffer.Count} certificates from GCP over {pageNumber} pages.");
301
-
_logger.LogInformation($"[SYNC-DIAG] Handed {numberOfCertificates} certificate(s) to the AnyCA Gateway buffer. Review the per-record [SYNC-DIAG] lines above to confirm each carries a parseable fingerprint and NotBefore - these are the values the Gateway must surface to Command on /v2/certificate/search.");
316
+
_logger.LogInformation($"[SYNC-DIAG] Handed {numberOfCertificates} certificate(s) to the AnyCA Gateway buffer; skipped {skippedCertificates} certificate(s) with subjects the gateway cannot parse. Review the per-record [SYNC-DIAG]/[SYNC-SKIP] lines above for details.");
_logger.LogWarning($"[SYNC-DIAG] CARequestID={caRequestId}: FAILED to parse PemCertificate into an X509Certificate2 - the Gateway will likely store an empty fingerprint / notBefore=0 for this record. Error: {ex.Message}");
417
432
}
418
433
}
434
+
435
+
/// <summary>
436
+
/// Mirrors the subject parsing the AnyCA Gateway performs when it builds the /v2/certificate/search
437
+
/// response: <c>new Org.BouncyCastle.Asn1.X509.X509Name(true, netCert.Subject)</c>. That call throws on
438
+
/// subjects BouncyCastle cannot re-parse from .NET's string representation, which 500s the entire gateway
439
+
/// search page and aborts Command's CA sync. Returning <see langword="false"/> lets the sync skip the
440
+
/// certificate so it never enters the gateway database and can never break the downstream Command sync.
441
+
/// </summary>
442
+
/// <param name="pem">The PEM certificate content that will be handed to the gateway.</param>
443
+
/// <param name="subject">The parsed .NET subject string, when available (for logging).</param>
444
+
/// <param name="failureReason">The exception message when parsing fails.</param>
445
+
/// <returns><see langword="true"/> if the gateway can parse the subject; otherwise <see langword="false"/>.</returns>
0 commit comments