Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add collection of CertificatePolicy property #116

Merged
merged 2 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/CommonLib/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,15 @@ public static string LdapValue(this Guid s)

public static string GetSid(this DirectoryEntry result)
{
if (!result.Properties.Contains(LDAPProperties.ObjectSID))
try
{
if (!result.Properties.Contains(LDAPProperties.ObjectSID))
return null;
}
catch
{
return null;
}

var s = result.Properties[LDAPProperties.ObjectSID][0];
return s switch
Expand Down
1 change: 1 addition & 0 deletions src/CommonLib/LDAPProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public static class LDAPProperties
public const string ApplicationPolicies = "mspki-ra-application-policies";
public const string IssuancePolicies = "mspki-ra-policies";
public const string CertificateApplicationPolicy = "mspki-certificate-application-policy";
public const string CertificatePolicy = "mspki-certificate-policy";
public const string CACertificate = "cacertificate";
public const string CertificateTemplates = "certificatetemplates";
public const string CrossCertificatePair = "crosscertificatepair";
Expand Down
2 changes: 1 addition & 1 deletion src/CommonLib/LDAPQueries/CommonProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public static class CommonProperties
LDAPProperties.CertificateTemplates, LDAPProperties.Flags, LDAPProperties.DNSHostName, LDAPProperties.CACertificate, LDAPProperties.PKINameFlag,
LDAPProperties.PKIEnrollmentFlag, LDAPProperties.DisplayName, LDAPProperties.Name, LDAPProperties.TemplateSchemaVersion, LDAPProperties.CertTemplateOID,
LDAPProperties.PKIOverlappedPeriod, LDAPProperties.PKIExpirationPeriod, LDAPProperties.ExtendedKeyUsage, LDAPProperties.NumSignaturesRequired,
LDAPProperties.CertificateApplicationPolicy, LDAPProperties.IssuancePolicies, LDAPProperties.CrossCertificatePair,
LDAPProperties.CertificateApplicationPolicy, LDAPProperties.CertificatePolicy, LDAPProperties.IssuancePolicies, LDAPProperties.CrossCertificatePair,
LDAPProperties.ApplicationPolicies, LDAPProperties.PKIPrivateKeyFlag, LDAPProperties.OIDGroupLink
};
}
Expand Down
13 changes: 8 additions & 5 deletions src/CommonLib/Processors/LDAPPropertyProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -508,8 +508,11 @@ public static Dictionary<string, object> ReadCertTemplateProperties(ISearchResul

var ekus = entry.GetArrayProperty(LDAPProperties.ExtendedKeyUsage);
props.Add("ekus", ekus);
var certificateapplicationpolicy = entry.GetArrayProperty(LDAPProperties.CertificateApplicationPolicy);
props.Add("certificateapplicationpolicy", certificateapplicationpolicy);
var certificateApplicationPolicy = entry.GetArrayProperty(LDAPProperties.CertificateApplicationPolicy);
props.Add("certificateapplicationpolicy", certificateApplicationPolicy);

var certificatePolicy = entry.GetArrayProperty(LDAPProperties.CertificatePolicy);
props.Add("certificatepolicy", certificatePolicy);

if (entry.GetIntProperty(LDAPProperties.NumSignaturesRequired, out var authorizedSignatures))
props.Add("authorizedsignatures", authorizedSignatures);
Expand All @@ -525,12 +528,12 @@ public static Dictionary<string, object> ReadCertTemplateProperties(ISearchResul
props.Add("issuancepolicies", entry.GetArrayProperty(LDAPProperties.IssuancePolicies));

// Construct effectiveekus
var effectiveekus = schemaVersion == 1 & ekus.Length > 0 ? ekus : certificateapplicationpolicy;
var effectiveekus = schemaVersion == 1 & ekus.Length > 0 ? ekus : certificateApplicationPolicy;
props.Add("effectiveekus", effectiveekus);

// Construct authenticationenabled
var authenticationenabled = effectiveekus.Intersect(Helpers.AuthenticationOIDs).Any() | effectiveekus.Length == 0;
props.Add("authenticationenabled", authenticationenabled);
var authenticationEnabled = effectiveekus.Intersect(Helpers.AuthenticationOIDs).Any() | effectiveekus.Length == 0;
props.Add("authenticationenabled", authenticationEnabled);

return props;
}
Expand Down
12 changes: 11 additions & 1 deletion test/unit/LDAPPropertyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using CommonLibTest.Facades;
using SharpHoundCommonLib;
using SharpHoundCommonLib.Enums;
using SharpHoundCommonLib.OutputTypes;
using SharpHoundCommonLib.Processors;
Expand Down Expand Up @@ -714,9 +715,12 @@ public void LDAPPropertyProcessor_ReadCertTemplateProperties()
{"ekus", new[]
{"1.3.6.1.5.5.7.3.2"}
},
{"certificateapplicationpolicy", new[]
{LDAPProperties.CertificateApplicationPolicy, new[]
{"1.3.6.1.5.5.7.3.2"}
},
{LDAPProperties.CertificatePolicy, new[]
{"1.3.6.1.5.5.7.3.2"}
},
{"authorizedsignatures", 1},
{"applicationpolicies", new[]
{ "1.3.6.1.4.1.311.20.2.1"}
Expand Down Expand Up @@ -754,6 +758,12 @@ public void LDAPPropertyProcessor_ReadCertTemplateProperties()
Assert.Contains("subjectrequireemail", keys);
Assert.Contains("ekus", keys);
Assert.Contains("certificateapplicationpolicy", keys);
var hasPolicy = test.TryGetValue("certificatepolicy", out var policies);
Assert.True(hasPolicy);
if (policies is string[] e)
{
Assert.Contains("1.3.6.1.5.5.7.3.2", e);
}
Assert.Contains("authorizedsignatures", keys);
Assert.Contains("applicationpolicies", keys);
Assert.Contains("issuancepolicies", keys);
Expand Down
Loading