public CouchbaseLiteTcpListener(Manager manager, ushort port, CouchbaseLiteTcpOptions options, string realm, X509Certificate2 sslCert) { _manager = manager; _listener = new HttpListener(); _usesTLS = options.HasFlag(CouchbaseLiteTcpOptions.UseTLS); string prefix = _usesTLS ? String.Format("https://*:{0}/", port) : String.Format("http://*:{0}/", port); _listener.Prefixes.Add(prefix); _listener.AuthenticationSchemeSelector = SelectAuthScheme; HttpListener.DefaultServerString = "Couchbase Lite " + Manager.VersionString; _listener.Realm = realm; _allowsBasicAuth = options.HasFlag(CouchbaseLiteTcpOptions.AllowBasicAuth); _listener.UserCredentialsFinder = GetCredential; if (options.HasFlag(CouchbaseLiteTcpOptions.UseTLS)) { _listener.SslConfiguration.EnabledSslProtocols = SslProtocols.Tls12; _listener.SslConfiguration.ClientCertificateRequired = false; if (sslCert == null) { Log.To.Listener.I(TAG, "Generating X509 certificate for listener..."); sslCert = X509Manager.GenerateTransientCertificate("Couchbase-P2P"); } Log.To.Listener.I(TAG, "Using X509 certificate {0} (issued by {1})", sslCert.Subject, sslCert.Issuer); _listener.SslConfiguration.ServerCertificate = sslCert; } }
/// <summary> /// Constructor /// </summary> /// <param name="manager">The manager to use for opening DBs, etc</param> /// <param name="port">The port to listen on</param> /// <param name="options">The options to use when configuring the listener</param> /// <param name="realm">The realm to use when sending challenges</param> /// <param name="sslCert">The certificate to use when serving the listener over https</param> public CouchbaseLiteTcpListener(Manager manager, ushort port, CouchbaseLiteTcpOptions options, string realm, X509Certificate2 sslCert) { _manager = manager; _listener = new HttpListener(); _usesTLS = options.HasFlag(CouchbaseLiteTcpOptions.UseTLS); string prefix = _usesTLS ? String.Format("https://*:{0}/", port) : String.Format("http://*:{0}/", port); _listener.Prefixes.Add(prefix); _listener.AuthenticationSchemeSelector = SelectAuthScheme; HttpListener.DefaultServerString = "Couchbase Lite " + Manager.VersionString; _listener.Realm = realm; _allowsBasicAuth = options.HasFlag(CouchbaseLiteTcpOptions.AllowBasicAuth); _listener.UserCredentialsFinder = GetCredential; if (options.HasFlag(CouchbaseLiteTcpOptions.UseTLS)) { #if NET_3_5 throw new InvalidOperationException("TLS Listener not supported on .NET 3.5"); #else _listener.SslConfiguration.EnabledSslProtocols = SslProtocols.Tls | SslProtocols.Tls11 | SslProtocols.Tls12; _listener.SslConfiguration.ClientCertificateRequired = false; if (sslCert == null) { Log.To.Listener.I(TAG, "Generating X509 certificate for listener..."); sslCert = X509Manager.GenerateTransientCertificate("Couchbase-P2P"); } Log.To.Listener.I(TAG, "Using X509 certificate {0} (issued by {1})", sslCert.Subject, sslCert.Issuer); _listener.SslConfiguration.ServerCertificate = sslCert; #endif } _listener.Log.Level = WebSocketSharp.LogLevel.Trace; _listener.Log.Output = (data, msg) => { switch (data.Level) { case WebSocketSharp.LogLevel.Fatal: Log.To.Listener.E("HttpServer", data.Message); break; case WebSocketSharp.LogLevel.Error: case WebSocketSharp.LogLevel.Warn: Log.To.Listener.W("HttpServer", data.Message); break; case WebSocketSharp.LogLevel.Info: Log.To.Listener.I("HttpServer", data.Message); break; case WebSocketSharp.LogLevel.Trace: case WebSocketSharp.LogLevel.Debug: Log.To.Listener.V("HttpServer", data.Message); break; } }; }
public CouchbaseLiteTcpListener(Manager manager, ushort port, CouchbaseLiteTcpOptions options, string realm = "Couchbase") { _manager = manager; _realm = realm; _listener = new HttpListener(); string prefix = String.Format("http://*:{0}/", port); _listener.Prefixes.Add(prefix); _allowBasicAuth = options.HasFlag(CouchbaseLiteTcpOptions.AllowBasicAuth); }
static void Main() { Manager manager = Manager.SharedInstance; var database = manager.GetDatabase("kis-database"); var cert = X509Manager.GetPersistentCertificate("127.0.0.1", "123abc", System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "unit_test.pfx")); Uri uri = new Uri(String.Format("http://localhost:{0}/{1}/", 3689, "database")); CouchbaseLiteTcpOptions options = new CouchbaseLiteTcpOptions(); CouchbaseLiteTcpListener listener = new CouchbaseLiteTcpListener(manager, 3689, CouchbaseLiteTcpOptions.UseTLS, cert); listener.SetPasswords(new Dictionary<string, string>() { { "user", "pass" } }); listener.Start(); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); }
/// <summary> /// Constructor /// </summary> /// <param name="manager">The manager to use for opening DBs, etc</param> /// <param name="port">The port to listen on</param> /// <param name="options">The options to use when configuring the listener</param> /// <param name="realm">The realm to use when sending challenges</param> public CouchbaseLiteTcpListener(Manager manager, ushort port, CouchbaseLiteTcpOptions options, string realm = "Couchbase") : this(manager, port, options, realm, null) { }
/// <summary> /// Constructor /// </summary> /// <param name="manager">The manager to use for opening DBs, etc</param> /// <param name="port">The port to listen on</param> /// <param name="options">The options to use when configuring the listener</param> /// <param name="sslCert">The certificate to use when serving the listener over https</param> public CouchbaseLiteTcpListener(Manager manager, ushort port, CouchbaseLiteTcpOptions options, X509Certificate2 sslCert) : this(manager, port, options, "Couchbase", sslCert) { }
/// <summary> /// Constructor /// </summary> /// <param name="manager">The manager to use for opening DBs, etc</param> /// <param name="port">The port to listen on</param> /// <param name="options">The options to use when configuring the listener</param> /// <param name="realm">The realm to use when sending challenges</param> /// <param name="sslCert">The certificate to use when serving the listener over https</param> public CouchbaseLiteTcpListener(Manager manager, ushort port, CouchbaseLiteTcpOptions options, string realm, X509Certificate2 sslCert) { _manager = manager; _listener = new HttpListener(); _usesTLS = options.HasFlag(CouchbaseLiteTcpOptions.UseTLS); string prefix = _usesTLS ? String.Format("https://*:{0}/", port) : String.Format("http://*:{0}/", port); _listener.Prefixes.Add(prefix); _listener.AuthenticationSchemeSelector = SelectAuthScheme; HttpListener.DefaultServerString = "Couchbase Lite " + Manager.VersionString; _listener.Realm = realm; _allowsBasicAuth = options.HasFlag(CouchbaseLiteTcpOptions.AllowBasicAuth); _listener.UserCredentialsFinder = GetCredential; if (options.HasFlag(CouchbaseLiteTcpOptions.UseTLS)) { #if NET_3_5 throw new InvalidOperationException("TLS Listener not supported on .NET 3.5"); #else _listener.SslConfiguration.EnabledSslProtocols = SslProtocols.Tls | SslProtocols.Tls11 | SslProtocols.Tls12; _listener.SslConfiguration.ClientCertificateRequired = false; if (sslCert == null) { Log.To.Listener.I(TAG, "Generating X509 certificate for listener..."); sslCert = X509Manager.GenerateTransientCertificate("Couchbase-P2P"); } Log.To.Listener.I(TAG, "Using X509 certificate {0} (issued by {1})", sslCert.Subject, sslCert.Issuer); _listener.SslConfiguration.ServerCertificate = sslCert; #endif } _listener.Log.Level = WebSocketSharp.LogLevel.Trace; _listener.Log.Output = (data, msg) => { switch(data.Level) { case WebSocketSharp.LogLevel.Fatal: Log.To.Listener.E("HttpServer", data.Message); break; case WebSocketSharp.LogLevel.Error: case WebSocketSharp.LogLevel.Warn: Log.To.Listener.W("HttpServer", data.Message); break; case WebSocketSharp.LogLevel.Info: Log.To.Listener.I("HttpServer", data.Message); break; case WebSocketSharp.LogLevel.Trace: case WebSocketSharp.LogLevel.Debug: Log.To.Listener.V("HttpServer", data.Message); break; } }; }