Merge pull request #1 from LukeEmmet/main
Allow users of cuipod to initialise with an X509Certificate
This commit is contained in:
commit
a3a6a34e57
2
.gitignore
vendored
2
.gitignore
vendored
@ -352,3 +352,5 @@ MigrationBackup/
|
|||||||
CuipodExample/Properties/launchSettings.json
|
CuipodExample/Properties/launchSettings.json
|
||||||
|
|
||||||
.vscode/
|
.vscode/
|
||||||
|
.hg/
|
||||||
|
.hgignore
|
||||||
|
|||||||
@ -21,6 +21,7 @@ namespace Cuipod
|
|||||||
|
|
||||||
private RequestCallback _onBadRequestCallback;
|
private RequestCallback _onBadRequestCallback;
|
||||||
|
|
||||||
|
//somewhat flaky implementation - probably deprecate it
|
||||||
public App(string directoryToServe, string certificateFile, string privateRSAKeyFilePath)
|
public App(string directoryToServe, string certificateFile, string privateRSAKeyFilePath)
|
||||||
{
|
{
|
||||||
_directoryToServe = directoryToServe;
|
_directoryToServe = directoryToServe;
|
||||||
@ -29,6 +30,15 @@ namespace Cuipod
|
|||||||
_serverCertificate = CertificateUtils.LoadCertificate(certificateFile, privateRSAKeyFilePath);
|
_serverCertificate = CertificateUtils.LoadCertificate(certificateFile, privateRSAKeyFilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public App(string directoryToServe, X509Certificate2 certificate)
|
||||||
|
{
|
||||||
|
|
||||||
|
_directoryToServe = directoryToServe;
|
||||||
|
_listener = new TcpListener(IPAddress.Any, 1965);
|
||||||
|
_requestCallbacks = new Dictionary<string, RequestCallback>();
|
||||||
|
_serverCertificate = certificate;
|
||||||
|
}
|
||||||
|
|
||||||
public void OnRequest(string route, RequestCallback callback)
|
public void OnRequest(string route, RequestCallback callback)
|
||||||
{
|
{
|
||||||
_requestCallbacks.Add(route, callback);
|
_requestCallbacks.Add(route, callback);
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
using Cuipod;
|
using Cuipod;
|
||||||
using Microsoft.Extensions.CommandLineUtils;
|
using Microsoft.Extensions.CommandLineUtils;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Security.Cryptography.X509Certificates;
|
||||||
|
|
||||||
namespace CuipodExample
|
namespace CuipodExample
|
||||||
{
|
{
|
||||||
@ -15,21 +16,25 @@ namespace CuipodExample
|
|||||||
"Directory to server (required)"
|
"Directory to server (required)"
|
||||||
);
|
);
|
||||||
CommandArgument certificateFile = commandLineApplication.Argument(
|
CommandArgument certificateFile = commandLineApplication.Argument(
|
||||||
"certificate",
|
"pfx certificate file",
|
||||||
"Path to certificate (required)"
|
"Path to certificate (required)"
|
||||||
);
|
);
|
||||||
CommandArgument privateRSAKeyFilePath = commandLineApplication.Argument(
|
CommandArgument pfxPassword = commandLineApplication.Argument(
|
||||||
"key",
|
"pfx password",
|
||||||
"Path to private Pkcs8 RSA key (required)"
|
"pfx password"
|
||||||
);
|
);
|
||||||
commandLineApplication.OnExecute(() =>
|
commandLineApplication.OnExecute(() =>
|
||||||
{
|
{
|
||||||
if (directoryToServe.Value == null || certificateFile.Value == null || privateRSAKeyFilePath.Value == null)
|
if (directoryToServe.Value == null || certificateFile.Value == null )
|
||||||
{
|
{
|
||||||
commandLineApplication.ShowHelp();
|
commandLineApplication.ShowHelp();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return AppMain(directoryToServe.Value, certificateFile.Value, privateRSAKeyFilePath.Value);
|
|
||||||
|
var pass = (pfxPassword != null) ? pfxPassword.Value.ToString() : "";
|
||||||
|
var cert = new X509Certificate2(certificateFile.Value.ToString(), pass);
|
||||||
|
|
||||||
|
return AppMain(directoryToServe.Value, cert);
|
||||||
});
|
});
|
||||||
|
|
||||||
try
|
try
|
||||||
@ -42,12 +47,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(
|
App app = new App(
|
||||||
directoryToServe,
|
directoryToServe,
|
||||||
certificateFile,
|
certificate
|
||||||
privateRSAKeyFilePath
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// Serve files
|
// Serve files
|
||||||
|
|||||||
Reference in New Issue
Block a user