fix certificate selection

This commit is contained in:
Oliver Kieselbach
2026-05-18 12:25:45 +02:00
parent bb4f663ace
commit e64b795b28
4 changed files with 26 additions and 14 deletions
@@ -52,15 +52,21 @@ namespace AutopilotMonitor.Agent.Core.Security
}
else
{
// Auto-detect MDM certificate by issuer and EKU
// Auto-detect MDM certificate by issuer and EKU.
// Match ONLY "CN=Microsoft Intune MDM Device CA" — NOT
// "CN=Microsoft Intune Device Management Device CA" (MMP-C stack),
// which is co-installed on dual-enrolled devices and chains to a
// different intermediate the backend does not pin. A broader
// substring match on "Microsoft Intune" would let the MMP-C cert
// win the NotAfter tiebreaker and produce ChainFailed at the backend.
var mdmCerts = store.Certificates
.OfType<X509Certificate2>()
.Where(c =>
{
// Check issuer (Microsoft Intune MDM Device CA or similar)
var issuerContainsMdm = c.Issuer.Contains("Microsoft Intune", StringComparison.OrdinalIgnoreCase) ||
c.Issuer.Contains("MDM Device CA", StringComparison.OrdinalIgnoreCase) ||
c.Issuer.Contains("Microsoft Device CA", StringComparison.OrdinalIgnoreCase);
var issuerIsMdm = string.Equals(
c.Issuer,
"CN=Microsoft Intune MDM Device CA",
StringComparison.OrdinalIgnoreCase);
// Check Enhanced Key Usage for Client Authentication (1.3.6.1.5.5.7.3.2)
var hasClientAuth = c.Extensions
@@ -69,7 +75,7 @@ namespace AutopilotMonitor.Agent.Core.Security
.OfType<Oid>()
.Any(oid => oid.Value == "1.3.6.1.5.5.7.3.2"));
return issuerContainsMdm && hasClientAuth;
return issuerIsMdm && hasClientAuth;
})
.OrderByDescending(c => c.NotAfter) // Prefer certs with longer validity
.ToList();
@@ -52,15 +52,21 @@ namespace AutopilotMonitor.Agent.V2.Core.Security
}
else
{
// Auto-detect MDM certificate by issuer and EKU
// Auto-detect MDM certificate by issuer and EKU.
// Match ONLY "CN=Microsoft Intune MDM Device CA" — NOT
// "CN=Microsoft Intune Device Management Device CA" (MMP-C stack),
// which is co-installed on dual-enrolled devices and chains to a
// different intermediate the backend does not pin. A broader
// substring match on "Microsoft Intune" would let the MMP-C cert
// win the NotAfter tiebreaker and produce ChainFailed at the backend.
var mdmCerts = store.Certificates
.OfType<X509Certificate2>()
.Where(c =>
{
// Check issuer (Microsoft Intune MDM Device CA or similar)
var issuerContainsMdm = c.Issuer.Contains("Microsoft Intune", StringComparison.OrdinalIgnoreCase) ||
c.Issuer.Contains("MDM Device CA", StringComparison.OrdinalIgnoreCase) ||
c.Issuer.Contains("Microsoft Device CA", StringComparison.OrdinalIgnoreCase);
var issuerIsMdm = string.Equals(
c.Issuer,
"CN=Microsoft Intune MDM Device CA",
StringComparison.OrdinalIgnoreCase);
// Check Enhanced Key Usage for Client Authentication (1.3.6.1.5.5.7.3.2)
var hasClientAuth = c.Extensions
@@ -69,7 +75,7 @@ namespace AutopilotMonitor.Agent.V2.Core.Security
.OfType<Oid>()
.Any(oid => oid.Value == "1.3.6.1.5.5.7.3.2"));
return issuerContainsMdm && hasClientAuth;
return issuerIsMdm && hasClientAuth;
})
.OrderByDescending(c => c.NotAfter) // Prefer certs with longer validity
.ToList();
@@ -1 +1 @@
768
770
@@ -1 +1 @@
1353
1354