//
#if SECURITY_DEP
+#if MONO_SECURITY_ALIAS
+extern alias MonoSecurity;
+using MonoSecurity::Mono.Security.Authenticode;
+using MSI = MonoSecurity::Mono.Security.Interface;
+#else
+using Mono.Security.Authenticode;
+using MSI = Mono.Security.Interface;
+#endif
+using System.IO;
using System.Collections;
using System.Threading;
using System.Threading.Tasks;
+using System.Security.Cryptography;
+using System.Security.Cryptography.X509Certificates;
+
+using Mono.Net.Security;
+
//TODO: logging
namespace System.Net {
bool listening;
bool disposed;
+ IMonoTlsProvider tlsProvider;
+ MSI.MonoTlsSettings tlsSettings;
+ X509Certificate certificate;
+
Hashtable registry; // Dictionary<HttpListenerContext,HttpListenerContext>
ArrayList ctx_queue; // List<HttpListenerContext> ctx_queue;
ArrayList wait_queue; // List<ListenerAsyncResult> wait_queue;
auth_schemes = AuthenticationSchemes.Anonymous;
}
+ internal HttpListener (X509Certificate certificate, IMonoTlsProvider tlsProvider, MSI.MonoTlsSettings tlsSettings)
+ : this ()
+ {
+ this.certificate = certificate;
+ this.tlsProvider = tlsProvider;
+ this.tlsSettings = tlsSettings;
+ }
+
+ internal X509Certificate LoadCertificateAndKey (IPAddress addr, int port)
+ {
+ lock (registry) {
+ if (certificate != null)
+ return certificate;
+
+ // Actually load the certificate
+ try {
+ 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 null;
+ string pvk_file = Path.Combine (path, String.Format ("{0}.pvk", port));
+ if (!File.Exists (pvk_file))
+ return null;
+ var cert = new X509Certificate2 (cert_file);
+ cert.PrivateKey = PrivateKey.CreateFromFile (pvk_file).RSA;
+ certificate = cert;
+ return certificate;
+ } catch {
+ // ignore errors
+ certificate = null;
+ return null;
+ }
+ }
+ }
+
+ internal IMonoSslStream CreateSslStream (Stream innerStream, bool ownsStream, MSI.MonoRemoteCertificateValidationCallback callback)
+ {
+ lock (registry) {
+ if (tlsProvider == null)
+ tlsProvider = MonoTlsProviderFactory.GetProviderInternal ();
+ if (tlsSettings == null)
+ tlsSettings = MSI.MonoTlsSettings.CopyDefaultSettings ();
+ if (tlsSettings.RemoteCertificateValidationCallback == null)
+ tlsSettings.RemoteCertificateValidationCallback = callback;
+ return tlsProvider.CreateSslStream (innerStream, ownsStream, tlsSettings);
+ }
+ }
+
// TODO: Digest, NTLM and Negotiate require ControlPrincipal
public AuthenticationSchemes AuthenticationSchemes {
get { return auth_schemes; }
}
}
}
+#else // SECURITY_DEP
+namespace System.Net
+{
+ public sealed class HttpListener
+ {
+ }
+}
#endif
-