Exemplo n.º 1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private org.eclipse.jetty.server.Server setUp(String response) throws Exception
        private Server setUp(string response)
        {
            Server server = new Server();

            server.Handler = new FakeKubernetesHandler(_testNamespace, _testLabelSelector, _testAuthToken, response);

            HttpConfiguration https = new HttpConfiguration();

            https.addCustomizer(new SecureRequestCustomizer());

            string      keyStorePass   = "******";
            string      privateKeyPass = "******";
            SslResource server1        = selfSignedKeyId(0).trustKeyId(1).install(TestDir.directory("k8s"));
            SslPolicy   sslPolicy      = Org.Neo4j.Ssl.SslContextFactory.MakeSslPolicy(server1);
            KeyStore    keyStore       = sslPolicy.GetKeyStore(keyStorePass.ToCharArray(), privateKeyPass.ToCharArray());

            SslContextFactory sslContextFactory = new SslContextFactory();

            sslContextFactory.KeyStore           = keyStore;
            sslContextFactory.KeyStorePassword   = keyStorePass;
            sslContextFactory.KeyManagerPassword = privateKeyPass;

            ServerConnector sslConnector = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, "http/1.1"), new HttpConnectionFactory(https)
                                                               );

            sslConnector.Port = _port;

            server.Connectors = new Connector[] { sslConnector };

            server.start();

            _httpClient.start();

            return(server);
        }
Exemplo n.º 2
0
        private SslConnectionFactory CreateSslConnectionFactory(SslPolicy sslPolicy)
        {
            SslContextFactory sslContextFactory = new SslContextFactory();

            string password = System.Guid.randomUUID().ToString();

            sslContextFactory.KeyStore           = sslPolicy.GetKeyStore(password.ToCharArray(), password.ToCharArray());
            sslContextFactory.KeyStorePassword   = password;
            sslContextFactory.KeyManagerPassword = password;

            IList <string> ciphers = sslPolicy.CipherSuites;

            if (ciphers != null)
            {
                sslContextFactory.IncludeCipherSuites = ciphers.ToArray();
                sslContextFactory.setExcludeCipherSuites();
            }

            string[] protocols = sslPolicy.TlsVersions;
            if (protocols != null)
            {
                sslContextFactory.IncludeProtocols = protocols;
                sslContextFactory.setExcludeProtocols();
            }

            switch (sslPolicy.ClientAuth)
            {
            case REQUIRE:
                sslContextFactory.NeedClientAuth = true;
                break;

            case OPTIONAL:
                sslContextFactory.WantClientAuth = true;
                break;

            case NONE:
                sslContextFactory.WantClientAuth = false;
                sslContextFactory.NeedClientAuth = false;
                break;

            default:
                throw new System.ArgumentException("Not supported: " + sslPolicy.ClientAuth);
            }

            return(new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()));
        }