This is a very good question. In some cases, like for HttpListener
, .NET requires tools or .config files (using System.Configuration
) to tweak the configuration of an application. In many cases there are API do achieve the same purpose, but not always (and not in this case).
The solution is to look at Mono's source code to see what it expects the HttpCfg.exe
tool to setup for the application. From github:
string dirname = Environment.GetFolderPath (Environment.SpecialFolder.ApplicationData);
string path = Path.Combine (dirname, ".mono");
path = Path.Combine (path, "httplistener");
string cert_file = Path.Combine (path, String.Format ("{0}.cer", port));
if (!File.Exists (cert_file))
return;
string pvk_file = Path.Combine (path, String.Format ("{0}.pvk", port));
if (!File.Exists (pvk_file))
return;
cert = new X509Certificate2 (cert_file);
key = PrivateKey.CreateFromFile (pvk_file).RSA;
So the solution is to create the same directory structure (it's possible since it will point under the Documents
directory) and copy the .cer
file (binary DER-encoded certificate) and the .pvk
file (which is the private key in the format that makecert
creates) with the port number as the file name.
With those files in place you should be able to start the HttpListener
and have it load the required certificate and private key required to handle SSL requests.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…