Created
June 6, 2018 18:37
-
-
Save cocowalla/568c64db465e6018b2f6e354f494b845 to your computer and use it in GitHub Desktop.
Simple console app for testing how mod_nss handles client certificates
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.IO; | |
using System.Net.Http; | |
using System.Security.Cryptography.X509Certificates; | |
using System.Threading; | |
using System.Threading.Tasks; | |
namespace NssTest | |
{ | |
class Program | |
{ | |
static async Task Main(string[] args) | |
{ | |
// Load the client cert, ensuring we can access the private key | |
var clientCertFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ClientCert.p12"); | |
var clientCert = new X509Certificate2(clientCertFile, String.Empty, X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.PersistKeySet); | |
using (var handler = new HttpClientHandler()) | |
{ | |
// Just accept all server certs | |
handler.ServerCertificateCustomValidationCallback += (message, serverCert, chain, errors) | |
=> true; | |
handler.ClientCertificateOptions = ClientCertificateOption.Manual; | |
handler.ClientCertificates.Add(clientCert); | |
using (var httpClient = new HttpClient(handler)) | |
{ | |
var result = await httpClient.GetStringAsync(@"https://172.17.147.210:443"); | |
Console.WriteLine(result); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment