Skip to content

Commit 534dfab

Browse files
authored
Minor fixes and enhancements (#78)
* Extend documentation * Rename Yubikey integration test * Rename variable in Yubikey validator * Extend logging of detection of san request attribute * Fix installer handling of ETW manifest
1 parent 29a4e0b commit 534dfab

File tree

14 files changed

+158
-107
lines changed

14 files changed

+158
-107
lines changed

TameMyCerts.IntegrationTests/Tests/User_Online_YubiKey.ps1 renamed to TameMyCerts.IntegrationTests/Tests/User_Online_YubiKey.Tests.ps1

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ Describe 'User_Online_Yubikey.Tests' {
99

1010
It 'Given YubiKey Policy is enabled and a request contains a valid attestation, a certificate is issued' {
1111

12-
#$Csr = Get-Content -Path "User_Online_Yubikey.pem" -Raw
13-
1412
$Csr = "MIIIxDCCB6wCAQAwHDEaMBgGA1UEAwwRVGFtZU15Q2VydHNfNS43LjIwggEiMA0G" +
1513
"CSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC8PsNNUt67rgq4+EGGnBU46XiiXv4g" +
1614
"ADdAhOB8IQp1eZ+7Dq8JOQ9XDjjBObPj7TnEzxS+PSpXTmwV46FA4gykcVj+tRhT" +

TameMyCerts.Tests/RequestAttributeValidatorTests.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;
2+
using Newtonsoft.Json.Linq;
23
using System;
34
using System.Collections.Generic;
45
using System.ComponentModel;
@@ -187,12 +188,15 @@ public void Allow_StartDate()
187188
}
188189

189190
[Fact]
190-
public void Deny_invalid_flags()
191+
public void Deny_SAN_request_attribute_when_insecure_flag_is_set()
191192
{
193+
const string attrName = "saN"; // note that we also test case sensitivity
194+
const string attrValue = "doesnt-matter";
195+
192196
var caConfig = new CertificateAuthorityConfiguration(EditFlag.EDITF_ATTRIBUTESUBJECTALTNAME2);
193197

194198
var dbRow = new CertificateDatabaseRow(_defaultCsr, CertCli.CR_IN_PKCS10,
195-
new Dictionary<string, string> { { "saN", "doesnt-matter" } });
199+
new Dictionary<string, string> { { attrName, attrValue } });
196200

197201
var result = new CertificateRequestValidationResult(dbRow);
198202

@@ -202,15 +206,19 @@ public void Deny_invalid_flags()
202206

203207
Assert.True(result.DeniedForIssuance);
204208
Assert.True(result.StatusCode == WinError.NTE_FAIL);
209+
Assert.Contains($"{attrName}:{attrValue}", string.Join("\n", result.Warnings));
205210
}
206211

207212
[Fact]
208-
public void Allow_valid_flags()
213+
public void Allow_SAN_request_attribute_when_insecure_flag_is_not_set()
209214
{
215+
const string attrName = "saN"; // note that we also test case sensitivity
216+
const string attrValue = "doesnt-matter";
217+
210218
var caConfig = new CertificateAuthorityConfiguration(0);
211219

212220
var dbRow = new CertificateDatabaseRow(_defaultCsr, CertCli.CR_IN_PKCS10,
213-
new Dictionary<string, string> { { "saN", "doesnt-matter" } });
221+
new Dictionary<string, string> { { attrName, attrValue } });
214222

215223
var result = new CertificateRequestValidationResult(dbRow);
216224

@@ -220,6 +228,7 @@ public void Allow_valid_flags()
220228

221229
Assert.False(result.DeniedForIssuance);
222230
Assert.True(result.StatusCode == WinError.ERROR_SUCCESS);
231+
Assert.Contains($"{attrName}:{attrValue}", string.Join("\n", result.Warnings));
223232
}
224233

225234
[Fact]

TameMyCerts/LocalizedStrings.Designer.cs

Lines changed: 15 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

TameMyCerts/LocalizedStrings.resx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@
142142
{2}</value>
143143
</data>
144144
<data name="Events_REQUEST_CONTAINS_WARNINGS" xml:space="preserve">
145-
<value>The following warnings have been logged during the processing of request {0} for {1}:
145+
<value>The following warning has been logged during the processing of request {0} for {1}:
146146
{2}</value>
147147
</data>
148148
<data name="Events_REQUEST_DENIED_AUDIT" xml:space="preserve">
@@ -213,11 +213,21 @@
213213
<data name="ReqVal_Crypto_Provider_Unknown" xml:space="preserve">
214214
<value>Unable to determine the cryptographic provider that was used to create the certificate request, but policy requires this information. Probably the certificate request does not contain such information.</value>
215215
</data>
216-
<data name="AttribVal_Insecure_Flags" xml:space="preserve">
217-
<value>The certificate request metadata contains the "san" request attribute, and the certification authority is configured with the EDITF_ATTRIBUTESUBJECTALTNAME2 flag. This is a highly dangerous configuration. The request was therefore denied.</value>
216+
<data name="AttribVal_Insecure_Flags_denied" xml:space="preserve">
217+
<value>The certificate request metadata contains the "san" request attribute, and the certification authority is configured with the EDITF_ATTRIBUTESUBJECTALTNAME2 flag. This is a highly dangerous configuration. The request was therefore denied.
218+
219+
The request contains the following request attributes:
220+
221+
{0}</value>
218222
</data>
219223
<data name="AttribVal_Insecure_Flags_detected" xml:space="preserve">
220-
<value>The certificate request metadata contains the "san" request attribute. If the certification authority is configured with the EDITF_ATTRIBUTESUBJECTALTNAME2 flag, this is a highly dangerous configuration.</value>
224+
<value>The certificate request metadata contains the "san" request attribute. If the certification authority is configured with the EDITF_ATTRIBUTESUBJECTALTNAME2 flag, this is a highly dangerous configuration.
225+
226+
The request contains the following request attributes:
227+
228+
{0}
229+
230+
Requester name is {1}</value>
221231
</data>
222232
<data name="ReqVal_Err_NotAfter_Invalid" xml:space="preserve">
223233
<value>Unable to parse the configured expiration date specified in certificate request policy.</value>

TameMyCerts/Models/CertificateDatabaseRow.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public CertificateDatabaseRow(CCertServerPolicy serverPolicy)
3535
PublicKey = serverPolicy.GetBinaryCertificatePropertyOrDefault("RawPublicKey");
3636
RawRequest = serverPolicy.GetBinaryRequestPropertyOrDefault("RawRequest");
3737
RequestID = serverPolicy.GetLongRequestPropertyOrDefault("RequestID");
38+
RequesterName = serverPolicy.GetStringRequestPropertyOrDefault("RequesterName");
3839
RequestType = serverPolicy.GetLongRequestPropertyOrDefault("RequestType") ^ CertCli.CR_IN_FULLRESPONSE;
3940
Upn = serverPolicy.GetStringCertificatePropertyOrDefault("UPN") ?? string.Empty;
4041
DistinguishedName = serverPolicy.GetStringRequestPropertyOrDefault("Request.DistinguishedName") ??
@@ -136,6 +137,11 @@ public CertificateDatabaseRow(string request, int requestType,
136137
/// </summary>
137138
public int RequestID { get; }
138139

140+
/// <summary>
141+
/// The requester name.
142+
/// </summary>
143+
public string RequesterName { get; }
144+
139145
/// <summary>
140146
/// The request type as defined in certcli.h (PKCS#10, PKCS#7 or CMS).
141147
/// </summary>

TameMyCerts/Policy.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,9 @@ public int VerifyRequest(string strConfig, int context, int isNewRequest, int fl
216216

217217
#region Log warnings, if any
218218

219-
if (result.Warnings.Count > 0)
219+
foreach (var warning in result.Warnings.Distinct().ToList())
220220
{
221-
_logger.Log(Events.REQUEST_CONTAINS_WARNINGS, requestId, template.Name,
222-
string.Join("\n", result.Warnings.Distinct().ToList()));
221+
_logger.Log(Events.REQUEST_CONTAINS_WARNINGS, requestId, template.Name, warning);
223222
}
224223

225224
#endregion

TameMyCerts/Validators/RequestAttributeValidator.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
using System;
1616
using System.Globalization;
17+
using System.Linq;
1718
using TameMyCerts.Enums;
1819
using TameMyCerts.Models;
1920

@@ -39,12 +40,16 @@ public CertificateRequestValidationResult VerifyRequest(CertificateRequestValida
3940

4041
if (dbRow.RequestAttributes.ContainsKey("san"))
4142
{
42-
result.AddWarning(LocalizedStrings.AttribVal_Insecure_Flags_detected);
43+
var requestAttributes = string.Join("\n",
44+
dbRow.RequestAttributes.Select(x => $"{x.Key}:{x.Value}").ToList());
45+
46+
result.AddWarning(string.Format(LocalizedStrings.AttribVal_Insecure_Flags_detected, requestAttributes, dbRow.RequesterName));
4347

4448
if (caConfig.EditFlags.HasFlag(EditFlag.EDITF_ATTRIBUTESUBJECTALTNAME2) &&
4549
!caConfig.TmcFlags.HasFlag(TmcFlag.TMC_WARN_ONLY_ON_INSECURE_FLAGS))
4650
{
47-
result.SetFailureStatus(WinError.NTE_FAIL, LocalizedStrings.AttribVal_Insecure_Flags);
51+
result.SetFailureStatus(WinError.NTE_FAIL,
52+
string.Format(LocalizedStrings.AttribVal_Insecure_Flags_denied, requestAttributes, dbRow.RequesterName));
4853
}
4954
}
5055

TameMyCerts/Validators/YubikeyValidator.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -253,10 +253,10 @@ private bool ObjectMatchesPolicy(YubikeyPolicy policy, YubikeyObject yubikey)
253253
/// <returns></returns>
254254
private static X509Certificate2Collection GetCertificatesFromMachineStore(string storeName)
255255
{
256-
var rootCaStore = new X509Store(storeName, StoreLocation.LocalMachine);
257-
rootCaStore.Open(OpenFlags.ReadOnly);
258-
var certificates = rootCaStore.Certificates;
259-
rootCaStore.Close();
256+
var store = new X509Store(storeName, StoreLocation.LocalMachine);
257+
store.Open(OpenFlags.ReadOnly);
258+
var certificates = store.Certificates;
259+
store.Close();
260260

261261
return certificates;
262262
}

0 commit comments

Comments
 (0)