-
Notifications
You must be signed in to change notification settings - Fork 578
Create Test SSL CA & Client Server Keys #973
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
base: master
Are you sure you want to change the base?
Changes from 5 commits
a736ccb
9f4292a
032b1be
ee759c7
6b0de7d
9d5a25a
58b59d4
bf3f3aa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFramework>net8.0</TargetFramework> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <Nullable>enable</Nullable> | ||
| </PropertyGroup> | ||
|
|
||
| </Project> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| $rootCert = New-SelfSignedCertificate -Subject "CN=QuickFixn-TestCA" -Type Custom -KeyUsage CertSign, CRLSign, DigitalSignature -SuppressOid "2.5.29.37" -KeyLength 2048 -NotAfter (Get-Date).AddDays(30) | ||
|
|
||
| $rootCertPath = "QuickFixn-TestCA.cer" | ||
| Export-Certificate -Cert $rootCert -FilePath $rootCertPath | ||
|
|
||
| $serverCert = New-SelfSignedCertificate -Subject "CN=QuickFixn-TestServer" -DnsName localhost, 127.0.0.1 -Signer $rootCert -KeyUsage DigitalSignature, KeyEncipherment -TextExtension "2.5.29.37={text}1.3.6.1.5.5.7.3.1" -KeyLength 2048 -NotAfter (Get-Date).AddDays(5) | ||
| $serverCertPath = "QuickFixn-TestServer.pfx" | ||
| $password = ConvertTo-SecureString -String "qfnpass123" -Force -AsPlainText | ||
| Export-Certificate -Cert $serverCert -FilePath "QuickFixn-TestServer.cer" | ||
| Export-PfxCertificate -Cert $serverCert -FilePath $serverCertPath -Password $password | ||
|
|
||
|
|
||
| $clientCert = New-SelfSignedCertificate -Subject "CN=QuickFixn-TestClient" -DnsName localhost, 127.0.0.1 -Signer $rootCert -KeyUsage DigitalSignature, KeyEncipherment -TextExtension "2.5.29.37={text}1.3.6.1.5.5.7.3.2" -KeyLength 2048 -NotAfter (Get-Date).AddDays(5) | ||
| $clientCertPath = "QuickFixn-TestClient.pfx" | ||
| $password = ConvertTo-SecureString -String "qfnpass123" -Force -AsPlainText | ||
| Export-Certificate -Cert $clientCert -FilePath "QuickFixn-TestClient.cer" | ||
| Export-PfxCertificate -Cert $clientCert -FilePath $clientCertPath -Password $password | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| using System.Net; | ||
| using System.Security.Cryptography; | ||
| using System.Security.Cryptography.X509Certificates; | ||
|
|
||
| const string CaCertificatePath = "..\\..\\..\\..\\QuickFixn-TestCA.cer"; | ||
| const string ServerPfxCertificatePath = "..\\..\\..\\..\\QuickFixn-TestServer.pfx"; | ||
| const string ClientPfxCertificatePath = "..\\..\\..\\..\\QuickFixn-TestClient.pfx"; | ||
|
|
||
| const string PfxPassword = @"qfnpass123"; | ||
|
|
||
| static X509Certificate2 CreateCACertificate() | ||
| { | ||
| using var rsa = RSA.Create(); | ||
| var request = new CertificateRequest("CN=QuickFixn-TestCA", rsa, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1); | ||
| request.CertificateExtensions.Add(new X509BasicConstraintsExtension(true, false, 0, true)); | ||
| request.CertificateExtensions.Add(new X509KeyUsageExtension(X509KeyUsageFlags.KeyCertSign | X509KeyUsageFlags.CrlSign | X509KeyUsageFlags.DigitalSignature, true)); | ||
|
|
||
| X509Certificate2 certificate = request.CreateSelfSigned(DateTimeOffset.UtcNow.AddDays(-1), DateTimeOffset.UtcNow.AddDays(30)); | ||
| return certificate; | ||
| } | ||
|
|
||
| static X509Certificate2 CreateServerCertificate(X509Certificate2 caCertificate) | ||
| { | ||
| using var rsa = RSA.Create(); | ||
| using (RSA caPrivateKey = caCertificate.GetRSAPrivateKey()) | ||
|
Check warning on line 25 in Examples/GenerateKeys/Program.cs
|
||
| { | ||
| var request = new CertificateRequest($"CN=QuickFixn-TestServer", rsa, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1); | ||
| request.CertificateExtensions.Add(new X509BasicConstraintsExtension(false, false, 0, true)); | ||
| request.CertificateExtensions.Add(new X509KeyUsageExtension(X509KeyUsageFlags.DigitalSignature | X509KeyUsageFlags.KeyEncipherment, true)); | ||
|
|
||
| var sanBuilder = new SubjectAlternativeNameBuilder(); | ||
| sanBuilder.AddDnsName("localhost"); | ||
| sanBuilder.AddIpAddress(IPAddress.Loopback); | ||
| request.CertificateExtensions.Add(sanBuilder.Build()); | ||
|
|
||
| var enhancedKeyUsages = new OidCollection | ||
| { | ||
| new Oid("1.3.6.1.5.5.7.3.1"), // OID for Server Authentication | ||
| }; | ||
| request.CertificateExtensions.Add(new X509EnhancedKeyUsageExtension(enhancedKeyUsages, true)); | ||
|
|
||
| X509Certificate2 certificate = request.Create(caCertificate, DateTimeOffset.UtcNow.AddDays(-1), DateTimeOffset.UtcNow.AddDays(5), [0, 0, 0, 0, 0, 0, 0, 1]); | ||
| return certificate.CopyWithPrivateKey(rsa); | ||
| } | ||
| } | ||
|
|
||
| static X509Certificate2 CreateClientCertificate(X509Certificate2 caCertificate) | ||
| { | ||
| using var rsa = RSA.Create(); | ||
| using (RSA caPrivateKey = caCertificate.GetRSAPrivateKey()) | ||
|
Check warning on line 50 in Examples/GenerateKeys/Program.cs
|
||
| { | ||
| var request = new CertificateRequest($"CN=QuickFixn-TestClient", rsa, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1); | ||
| request.CertificateExtensions.Add(new X509BasicConstraintsExtension(false, false, 0, true)); | ||
| request.CertificateExtensions.Add(new X509KeyUsageExtension(X509KeyUsageFlags.DigitalSignature | X509KeyUsageFlags.KeyEncipherment, true)); | ||
|
|
||
| var sanBuilder = new SubjectAlternativeNameBuilder(); | ||
| sanBuilder.AddDnsName("localhost"); | ||
| sanBuilder.AddIpAddress(IPAddress.Loopback); | ||
| request.CertificateExtensions.Add(sanBuilder.Build()); | ||
|
|
||
| var enhancedKeyUsages = new OidCollection | ||
| { | ||
| new Oid("1.3.6.1.5.5.7.3.2") // OID for Client Authentication | ||
| }; | ||
| request.CertificateExtensions.Add(new X509EnhancedKeyUsageExtension(enhancedKeyUsages, true)); | ||
|
|
||
| X509Certificate2 certificate = request.Create(caCertificate, DateTimeOffset.UtcNow.AddDays(-1), DateTimeOffset.UtcNow.AddDays(5), [0, 0, 0, 0, 0, 0, 0, 2]); | ||
| return certificate.CopyWithPrivateKey(rsa); | ||
| } | ||
| } | ||
|
|
||
| var caCertificate = CreateCACertificate(); | ||
| File.WriteAllBytes(CaCertificatePath, caCertificate.Export(X509ContentType.Cert)); | ||
|
|
||
| var serverCertificate = CreateServerCertificate(caCertificate); | ||
| File.WriteAllBytes(ServerPfxCertificatePath, serverCertificate.Export(X509ContentType.Pfx, PfxPassword)); | ||
|
|
||
| var clientCertificate = CreateClientCertificate(caCertificate); | ||
| File.WriteAllBytes(ClientPfxCertificatePath, clientCertificate.Export(X509ContentType.Pfx, PfxPassword)); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,10 +20,11 @@ ResetOnLogon=Y | |
|
|
||
| # It is recommended to install the certificate and refer to it by name instead of using filename + password | ||
| SSLCertificate=../QuickFixn-TestClient.pfx | ||
| SSLCertificatePassword=QuickFixn-TestClient | ||
| SSLCertificatePassword=qfnpass123 | ||
| # For production refer to certificate by name instead: SSLCertificate=CN=QuickFixn-TestClient | ||
| SSLServerName=QuickFixn-TestServer | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Key Resolution really cares about Subject Alternative Names |
||
| SSLCACertificate=../QuickFixn-TestCA.cer | ||
| SSLCheckCertificateRevocation=N | ||
| SSLProtocols=Default | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use SSLProtocols=Default instead of SSLProtocols=None to let the OS pick the best one. |
||
|
|
||
| [SESSION] | ||
| # inherit ConnectionType, ReconnectInterval and SenderCompID from default | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works in an elevated prompt on windows.
powershell -noexit -executionpolicy bypass -File .\GenerateKeys.ps1