Skip to content

Commit

Permalink
Initial Yubikey support (#35)
Browse files Browse the repository at this point in the history
* Initial Yubikey support

* Rebuilt the Yubikey Policy to allow multiple policies
Added more testcases 5.7.1 is now available.

* Allow same version for Min and Max firmware

* Revert b36a062
Fixed Firmware checks

Added FIPS yubikey check

* Update to xUnit
To be able to use KeyAlgorithms in XML they need to be public

* Fix nunit output change from 1=>2
Update .any() to Assert.Contains
Regresion in CCV, error for missing substition should have what module it came from

* Add EWT logging
Add Program to generate Manifest
Add some fixes and logging and more EWT tests for Yubikeys

* Copy the EWT dll/man to the output
Add checks for XML

* Basic MSI

* Rename support projects to support.
Add another XML Policy test

* fix after changing to support.

* Update GenerateEWTManifest to net8.0-windows7.0

* Update install.ps1 to install the Manifest for EWT Logging

* Remove MSI installer as that was.. to big for this stage

* Also checks if the provider is registered with Get-WinEvent before unregistering

* Make Tasks static
  • Loading branch information
virot authored Nov 30, 2024
1 parent 5758891 commit 89b7a5f
Show file tree
Hide file tree
Showing 22 changed files with 2,025 additions and 15 deletions.
15 changes: 15 additions & 0 deletions Support.GenerateEWTManifest/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System.Diagnostics.Tracing;
using TameMyCerts;

// Generate the manifest
string? manifest = EventSource.GenerateManifest(typeof(EWTLogger), "TameMyCerts.Events.dll");
// Save the manifest to a file
if (manifest is not null)
{
File.WriteAllText("TameMyCerts.Events.man", manifest);
Console.WriteLine("Manifest generated and saved to TameMyCerts.Events.man");
}
else
{
Console.WriteLine("Failed to generate manifest. The manifest content is null.");
}
44 changes: 44 additions & 0 deletions Support.GenerateEWTManifest/Support.GenerateEWTManifest.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.26100.1742" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\TameMyCerts\TameMyCerts.csproj" />
</ItemGroup>

<Target Name="GenerateManifest" AfterTargets="Build">
<Exec Command="$(TargetDir)\$(TargetName).exe" WorkingDirectory="$(TargetDir)" />
</Target>

<Target Name="MessageCompiler" AfterTargets="Build" DependsOnTargets="GenerateManifest">
<Exec Command="&quot;$(NuGetPackageRoot)microsoft.windows.sdk.buildtools\10.0.26100.1742\bin\10.0.26100.0\x64\mc.exe&quot; &quot;TameMyCerts.Events.man&quot; -r ." WorkingDirectory="$(TargetDir)" />
</Target>

<Target Name="ResourceCompiler" AfterTargets="Build" DependsOnTargets="MessageCompiler">
<Exec Command="&quot;$(NuGetPackageRoot)microsoft.windows.sdk.buildtools\10.0.26100.1742\bin\10.0.26100.0\x64\rc.exe&quot; &quot;TameMyCerts.Events.rc&quot;" WorkingDirectory="$(TargetDir)" />
</Target>

<Target Name="BuildDll" AfterTargets="Build" DependsOnTargets="MessageCompiler">
<Exec Command="&quot;$(MSBuildSDKsPath)\..\Current\Bin\Roslyn\csc.exe&quot; /out:TameMyCerts.Events.dll /target:library /win32res:TameMyCerts.Events.res" WorkingDirectory="$(TargetDir)" />
</Target>

<Target Name="CopyOutputFiles" AfterTargets="Build">
<ItemGroup>
<!-- Include DLLs, XMLs, and JSON files from the output path -->
<FilesToCopy Include="$(OutputPath)**\TameMyCerts.Events.dll" />
<FilesToCopy Include="$(OutputPath)**\TameMyCerts.Events.man" />
</ItemGroup>

<Copy SourceFiles="@(FilesToCopy)" DestinationFolder="..\TameMyCerts\bin\$(Configuration)\$(TargetFramework)\" SkipUnchangedFiles="true" />

</Target>
</Project>
22 changes: 22 additions & 0 deletions TameMyCerts.Tests/EWTLoggerListener.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System.Collections.Generic;
using System.Diagnostics.Tracing;
using TameMyCerts;

namespace TameMyCerts.Tests
{
public class EWTLoggerListener : EventListener
{
private readonly List<EventWrittenEventArgs> events = new List<EventWrittenEventArgs>();
protected override void OnEventWritten(EventWrittenEventArgs eventData) { events.Add(eventData); }
public List<EventWrittenEventArgs> Events => events;
public void ClearEvents() { events.Clear(); }

protected override void OnEventSourceCreated(EventSource eventSource)
{
if (eventSource.Name == "TameMyCerts")
{
EnableEvents(eventSource, EventLevel.LogAlways, (EventKeywords)(-1));
}
}
}
}
2 changes: 1 addition & 1 deletion TameMyCerts.Tests/TameMyCerts.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<NoWarn>1701;1702;CA1416</NoWarn>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\TameMyCerts\TameMyCerts.csproj" />
<ProjectReference Include="..\TameMyCerts\TameMyCerts.csproj" />
</ItemGroup>
<ItemGroup>
<COMReference Include="CERTENROLLLib">
Expand Down
99 changes: 99 additions & 0 deletions TameMyCerts.Tests/XMLPolicyTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
using FluentAssertions;
using Microsoft.VisualStudio.TestPlatform.Utilities;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.IO;
using System.Linq;
using TameMyCerts.Enums;
using TameMyCerts.Models;
using TameMyCerts.Validators;
using Xunit;
using Xunit.Abstractions;
using static System.Net.Mime.MediaTypeNames;

namespace TameMyCerts.Tests;

public class XMLPolicyTests
{
private EWTLoggerListener _listener;
private readonly ITestOutputHelper output;

public XMLPolicyTests(ITestOutputHelper output)
{
this.output = output;
this._listener = new EWTLoggerListener();
}

internal void PrintResult(CertificateRequestValidationResult result)
{
output.WriteLine("0x{0:X} ({0}) {1}.", result.StatusCode,
new Win32Exception(result.StatusCode).Message);
output.WriteLine(string.Join("\n", result.Description));
}

[Fact]
public void Test_reading_compliant_XML()
{
var filename = Path.GetTempFileName();

string sampleXML = @"<CertificateRequestPolicy xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance""
xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">
<AuditOnly>false</AuditOnly>
</CertificateRequestPolicy>";
File.WriteAllText(filename, sampleXML);

CertificateRequestPolicyCacheEntry cacheEntry = new CertificateRequestPolicyCacheEntry(filename);

Assert.False(cacheEntry.CertificateRequestPolicy.AuditOnly);
Assert.Empty(cacheEntry.ErrorMessage);

File.Delete(filename);
}

[Fact]
public void Test_Unknown_XML_Element()
{
var filename = Path.GetTempFileName();

string sampleXML = @"<CertificateRequestPolicy xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance""
xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">
<ThisDoewNotExist>false</ThisDoewNotExist>
</CertificateRequestPolicy>
";
File.WriteAllText(filename, sampleXML);
_listener.ClearEvents();

CertificateRequestPolicyCacheEntry cacheEntry = new CertificateRequestPolicyCacheEntry(filename);

Assert.Empty(cacheEntry.ErrorMessage);
Assert.Equal(2, _listener.Events.Count);
Assert.Equal(92, _listener.Events[0].EventId);

File.Delete(filename);
}

[Fact]
public void Test_Unknown_XML_Element2()
{
var filename = Path.GetTempFileName();

string sampleXML = @"<CertificateRequestPolicy xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance""
xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">
<DirectoryServicesMapping><AllowedOrganizationalUnits><Test>This should fault</Test></AllowedOrganizationalUnits></DirectoryServicesMapping>
</CertificateRequestPolicy>
";
File.WriteAllText(filename, sampleXML);
_listener.ClearEvents();

CertificateRequestPolicyCacheEntry cacheEntry = new CertificateRequestPolicyCacheEntry(filename);

Assert.Empty(cacheEntry.ErrorMessage);
Assert.Equal(2, _listener.Events.Count);
Assert.Equal(92, _listener.Events[0].EventId);

File.Delete(filename);
}

}
Loading

0 comments on commit 89b7a5f

Please sign in to comment.