private void LoadCertificateFromStore() { // Initial data cleanup, just in case String lThumbprint = this.CertificateThumbprint.Replace("\u200e", "").Replace("\u200f", "").Replace(" ", ""); X509Certificate2 lCertificate = SslConnectionFactory.LoadCertificateFromStore(lThumbprint, StoreLocation.CurrentUser) ?? SslConnectionFactory.LoadCertificateFromStore(lThumbprint, StoreLocation.LocalMachine); if (lCertificate == null) { throw new CryptographicException("Cannot find certificate with provided thumbprint: " + this.CertificateThumbprint); } this.Certificate = lCertificate; }
internal virtual ConnectionFactory CreateConnectionFactory() { ConnectionFactory factory = UseSockets ? new SocketConnectionFactory() : new MemoryConnectionFactory(); if (UseSsl) { factory = new SslConnectionFactory(factory); } if (Trickle) { factory = new TricklingConnectionFactory(factory) { ForceAsync = TrickleForceAsync } } ; return(factory); }
public async Task Connect_SelfSigned_Success() { var protocols = new List <SslApplicationProtocol> { new SslApplicationProtocol("test") }; var connectProperties = new ConnectionProperties(); connectProperties.Add(SslConnectionFactory.SslClientAuthenticationOptionsPropertyKey, new SslClientAuthenticationOptions { TargetHost = "localhost", ApplicationProtocols = protocols, RemoteCertificateValidationCallback = delegate { return(true); } }); var listenProperties = new ConnectionProperties(); listenProperties.Add(SslConnectionFactory.SslServerAuthenticationOptionsPropertyKey, new SslServerAuthenticationOptions { ApplicationProtocols = protocols, ServerCertificate = TestCertificates.GetSelfSigned13ServerCertificate() }); byte[] sendBuffer = Encoding.ASCII.GetBytes("Testing 123"); await using ConnectionFactory factory = new SslConnectionFactory(new MemoryConnectionFactory()); await using ConnectionListener listener = await factory.ListenAsync(options : listenProperties); await RunClientServer( async() => { await using Connection connection = await factory.ConnectAsync(listener.EndPoint !, connectProperties); await connection.Stream.WriteAsync(sendBuffer); }, async() => { await using Connection? connection = await listener.AcceptConnectionAsync(); Assert.NotNull(connection); Debug.Assert(connection != null); byte[] buffer = new byte[sendBuffer.Length + 1]; int readLen = await connection.Stream.ReadAsync(buffer); Assert.Equal(sendBuffer, buffer[..readLen]);
public virtual ServerConnector CreateConnector(Server server, SslPolicy sslPolicy, ListenSocketAddress address, JettyThreadCalculator jettyThreadCalculator) { SslConnectionFactory sslConnectionFactory = CreateSslConnectionFactory(sslPolicy); return(createConnector(server, address, jettyThreadCalculator, sslConnectionFactory, CreateHttpConnectionFactory())); }