From 0647df528e0f6d25e6ce08dfb228c5a5a88e62d6 Mon Sep 17 00:00:00 2001 From: Luke Emmet Date: Fri, 16 Jul 2021 20:19:29 +0100 Subject: [PATCH] update example to use pfx file which seems more reliable --- CuipodExample/Server.cs | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/CuipodExample/Server.cs b/CuipodExample/Server.cs index 2b05256..4b8a4a3 100644 --- a/CuipodExample/Server.cs +++ b/CuipodExample/Server.cs @@ -1,6 +1,7 @@ using Cuipod; using Microsoft.Extensions.CommandLineUtils; using System; +using System.Security.Cryptography.X509Certificates; namespace CuipodExample { @@ -15,21 +16,38 @@ namespace CuipodExample "Directory to server (required)" ); CommandArgument certificateFile = commandLineApplication.Argument( - "certificate", + "pfx certificate file", "Path to certificate (required)" ); - CommandArgument privateRSAKeyFilePath = commandLineApplication.Argument( - "key", - "Path to private Pkcs8 RSA key (required)" + CommandArgument pfxPassword = commandLineApplication.Argument( + "pfx password", + "pfx password" ); commandLineApplication.OnExecute(() => { - if (directoryToServe.Value == null || certificateFile.Value == null || privateRSAKeyFilePath.Value == null) + if (directoryToServe.Value == null || certificateFile.Value == null ) { commandLineApplication.ShowHelp(); return 1; } - return AppMain(directoryToServe.Value, certificateFile.Value, privateRSAKeyFilePath.Value); + + string pass; + if (pfxPassword != null) + { + pass = pfxPassword.Value.ToString(); + } + else + { + pass = ""; + } + + Console.WriteLine("pass: " + pass.ToString()); + Console.WriteLine("cert: " + certificateFile.Value.ToString()); + + var cert = new X509Certificate2(certificateFile.Value.ToString(), pass); + + + return AppMain(directoryToServe.Value, cert); }); try @@ -42,12 +60,11 @@ namespace CuipodExample } } - private static int AppMain(string directoryToServe, string certificateFile, string privateRSAKeyFilePath) + private static int AppMain(string directoryToServe, X509Certificate2 certificate) { App app = new App( directoryToServe, - certificateFile, - privateRSAKeyFilePath + certificate ); // Serve files