コード例 #1
0
        /// <summary>Snippet for Insert</summary>
        public void Insert()
        {
            // Snippet: Insert(string, SslPolicy, CallSettings)
            // Create client
            SslPoliciesClient sslPoliciesClient = SslPoliciesClient.Create();
            // Initialize request argument(s)
            string    project           = "";
            SslPolicy sslPolicyResource = new SslPolicy();
            // Make the request
            lro::Operation <Operation, Operation> response = sslPoliciesClient.Insert(project, sslPolicyResource);

            // Poll until the returned long-running operation is complete
            lro::Operation <Operation, Operation> completedResponse = response.PollUntilCompleted();
            // Retrieve the operation result
            Operation result = completedResponse.Result;

            // Or get the name of the operation
            string operationName = response.Name;
            // This name can be stored, then the long-running operation retrieved later by name
            lro::Operation <Operation, Operation> retrievedResponse = sslPoliciesClient.PollOnceInsert(operationName);

            // Check if the retrieved long-running operation has completed
            if (retrievedResponse.IsCompleted)
            {
                // If it has completed, then access the result
                Operation retrievedResult = retrievedResponse.Result;
            }
            // End snippet
        }
コード例 #2
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);
        }
コード例 #3
0
        /// <summary>Snippet for PatchAsync</summary>
        public async Task PatchAsync()
        {
            // Snippet: PatchAsync(string, string, SslPolicy, CallSettings)
            // Additional: PatchAsync(string, string, SslPolicy, CancellationToken)
            // Create client
            SslPoliciesClient sslPoliciesClient = await SslPoliciesClient.CreateAsync();

            // Initialize request argument(s)
            string    project           = "";
            string    sslPolicy         = "";
            SslPolicy sslPolicyResource = new SslPolicy();
            // Make the request
            lro::Operation <Operation, Operation> response = await sslPoliciesClient.PatchAsync(project, sslPolicy, sslPolicyResource);

            // Poll until the returned long-running operation is complete
            lro::Operation <Operation, Operation> completedResponse = await response.PollUntilCompletedAsync();

            // Retrieve the operation result
            Operation result = completedResponse.Result;

            // Or get the name of the operation
            string operationName = response.Name;
            // This name can be stored, then the long-running operation retrieved later by name
            lro::Operation <Operation, Operation> retrievedResponse = await sslPoliciesClient.PollOncePatchAsync(operationName);

            // Check if the retrieved long-running operation has completed
            if (retrievedResponse.IsCompleted)
            {
                // If it has completed, then access the result
                Operation retrievedResult = retrievedResponse.Result;
            }
            // End snippet
        }
コード例 #4
0
        /// <summary>
        /// Returns the specified SSL policy resource. Get a list of available SSL policies by making a list() request.
        /// Documentation https://developers.google.com/compute/alpha/reference/sslPolicies/insert
        /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
        /// </summary>
        /// <param name="service">Authenticated Compute service.</param>
        /// <param name="project">Project ID for this request.</param>
        /// <param name="body">A valid Compute alpha body.</param>
        /// <param name="optional">Optional paramaters.</param>
        /// <returns>OperationResponse</returns>
        public static Operation Insert(ComputeService service, string project, SslPolicy body, SslPoliciesInsertOptionalParms optional = null)
        {
            try
            {
                // Initial validation.
                if (service == null)
                {
                    throw new ArgumentNullException("service");
                }
                if (body == null)
                {
                    throw new ArgumentNullException("body");
                }
                if (project == null)
                {
                    throw new ArgumentNullException(project);
                }

                // Building the initial request.
                var request = service.SslPolicies.Insert(body, project);

                // Applying optional parameters to the request.
                request = (SslPoliciesResource.InsertRequest)SampleHelpers.ApplyOptionalParms(request, optional);

                // Requesting data.
                return(request.Execute());
            }
            catch (Exception ex)
            {
                throw new Exception("Request SslPolicies.Insert failed.", ex);
            }
        }
コード例 #5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldReturnNullPolicyIfNullRequested()
        public virtual void ShouldReturnNullPolicyIfNullRequested()
        {
            // given
            SslPolicyLoader sslPolicyLoader = SslPolicyLoader.Create(Config.defaults(), NullLogProvider.Instance);

            // when
            SslPolicy sslPolicy = sslPolicyLoader.GetPolicy(null);

            // then
            assertNull(sslPolicy);
        }
コード例 #6
0
 /// <summary>Snippet for Insert</summary>
 public void Insert()
 {
     // Snippet: Insert(string, SslPolicy, CallSettings)
     // Create client
     SslPoliciesClient sslPoliciesClient = SslPoliciesClient.Create();
     // Initialize request argument(s)
     string    project           = "";
     SslPolicy sslPolicyResource = new SslPolicy();
     // Make the request
     Operation response = sslPoliciesClient.Insert(project, sslPolicyResource);
     // End snippet
 }
コード例 #7
0
 /// <summary>Snippet for Get</summary>
 public void Get()
 {
     // Snippet: Get(string, string, CallSettings)
     // Create client
     SslPoliciesClient sslPoliciesClient = SslPoliciesClient.Create();
     // Initialize request argument(s)
     string project   = "";
     string sslPolicy = "";
     // Make the request
     SslPolicy response = sslPoliciesClient.Get(project, sslPolicy);
     // End snippet
 }
コード例 #8
0
 /// <summary>Snippet for Get</summary>
 public void GetRequestObject()
 {
     // Snippet: Get(GetSslPolicyRequest, CallSettings)
     // Create client
     SslPoliciesClient sslPoliciesClient = SslPoliciesClient.Create();
     // Initialize request argument(s)
     GetSslPolicyRequest request = new GetSslPolicyRequest
     {
         Project   = "",
         SslPolicy = "",
     };
     // Make the request
     SslPolicy response = sslPoliciesClient.Get(request);
     // End snippet
 }
コード例 #9
0
        /// <summary>Snippet for InsertAsync</summary>
        public async Task InsertAsync()
        {
            // Snippet: InsertAsync(string, SslPolicy, CallSettings)
            // Additional: InsertAsync(string, SslPolicy, CancellationToken)
            // Create client
            SslPoliciesClient sslPoliciesClient = await SslPoliciesClient.CreateAsync();

            // Initialize request argument(s)
            string    project           = "";
            SslPolicy sslPolicyResource = new SslPolicy();
            // Make the request
            Operation response = await sslPoliciesClient.InsertAsync(project, sslPolicyResource);

            // End snippet
        }
コード例 #10
0
        /// <summary>Snippet for GetAsync</summary>
        public async Task GetAsync()
        {
            // Snippet: GetAsync(string, string, CallSettings)
            // Additional: GetAsync(string, string, CancellationToken)
            // Create client
            SslPoliciesClient sslPoliciesClient = await SslPoliciesClient.CreateAsync();

            // Initialize request argument(s)
            string project   = "";
            string sslPolicy = "";
            // Make the request
            SslPolicy response = await sslPoliciesClient.GetAsync(project, sslPolicy);

            // End snippet
        }
コード例 #11
0
        protected internal virtual void ConfigureWebServer()
        {
            WebServerConflict.HttpAddress        = _httpListenAddress;
            WebServerConflict.HttpsAddress       = _httpsListenAddress;
            WebServerConflict.MaxThreads         = _config.get(ServerSettings.webserver_max_threads);
            WebServerConflict.WadlEnabled        = _config.get(ServerSettings.wadl_enabled);
            WebServerConflict.DefaultInjectables = CreateDefaultInjectables();

            string sslPolicyName = _config.get(ServerSettings.ssl_policy);

            if (!string.ReferenceEquals(sslPolicyName, null))
            {
                SslPolicy sslPolicy = SslPolicyFactorySupplier.get().getPolicy(sslPolicyName);
                WebServerConflict.SslPolicy = sslPolicy;
            }
        }
コード例 #12
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()));
        }
コード例 #13
0
        /// <summary>Snippet for GetAsync</summary>
        public async Task GetRequestObjectAsync()
        {
            // Snippet: GetAsync(GetSslPolicyRequest, CallSettings)
            // Additional: GetAsync(GetSslPolicyRequest, CancellationToken)
            // Create client
            SslPoliciesClient sslPoliciesClient = await SslPoliciesClient.CreateAsync();

            // Initialize request argument(s)
            GetSslPolicyRequest request = new GetSslPolicyRequest
            {
                Project   = "",
                SslPolicy = "",
            };
            // Make the request
            SslPolicy response = await sslPoliciesClient.GetAsync(request);

            // End snippet
        }
コード例 #14
0
ファイル: SslPolicyLoader.cs プロジェクト: Neo4Net/Neo4Net
        /// <summary>
        /// Use this for retrieving the SSL policy configured under the specified name.
        /// </summary>
        /// <param name="policyName"> The name of the SSL policy to be returned. </param>
        /// <returns> Returns the policy defined under the requested name. If the policy name is null
        /// then the null policy will be returned which means that SSL will not be used. It is up
        /// to each respective SSL policy using component to decide exactly what that means. </returns>
        /// <exception cref="IllegalArgumentException"> If a policy with the supplied name does not exist. </exception>
        public virtual SslPolicy GetPolicy(string policyName)
        {
            if (string.ReferenceEquals(policyName, null))
            {
                return(null);
            }
            else if (policyName.Equals(LEGACY_POLICY_NAME))
            {
                return(OrCreateLegacyPolicy);
            }

            SslPolicy sslPolicy = _policies[policyName];

            if (sslPolicy == null)
            {
                throw new System.ArgumentException(format("Cannot find enabled SSL policy with name '%s' in the configuration", policyName));
            }
            return(sslPolicy);
        }
コード例 #15
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test(timeout = 120_000) public void shouldBeAbleToStartAndStoreWithoutSuccessfulJoin()
        public virtual void ShouldBeAbleToStartAndStoreWithoutSuccessfulJoin()
        {
            // given
            IDictionary <string, string> @params = stringMap();

            SslPolicyConfig policyConfig = new SslPolicyConfig("default");

            @params[neo4j_home.name()] = _home.AbsolutePath;
            @params[policyConfig.BaseDirectory.name()] = "certificates/default";

            JobScheduler          jobScheduler   = JobSchedulerFactory.createInitialisedScheduler();
            PlatformModule        platformModule = new PlatformModule(TestDirectory.storeDir(), Config.defaults(), ENTERPRISE, newDependencies());
            AbstractEditionModule editionModule  = new EnterpriseEditionModule(platformModule);
            // Random members that does not exists, discovery will never succeed
            string initialHosts = "localhost:" + PortAuthority.allocatePort() + ",localhost:" + PortAuthority.allocatePort();
            Config config       = config();

            config.augment(initial_discovery_members, initialHosts);

            // Setup SslPolicy
            config.augment(neo4j_home.name(), _home.AbsolutePath);
            config.Augment(policyConfig.BaseDirectory.name(), "certificates/default");

            SslPolicyLoader sslPolicyLoader = SslPolicyLoader.create(config, NullLogProvider.Instance);

            RemoteMembersResolver remoteMembersResolver = ResolutionResolverFactory.ChooseResolver(config, platformModule.Logging);

            // then
            SslPolicy sslPolicy = sslPolicyLoader.GetPolicy("default");
            Monitors  monitors  = new Monitors();
            SecureHazelcastCoreTopologyService service = new SecureHazelcastCoreTopologyService(config, sslPolicy, new MemberId(System.Guid.randomUUID()), jobScheduler, NullLogProvider.Instance, NullLogProvider.Instance, remoteMembersResolver, new TopologyServiceNoRetriesStrategy(), monitors);

            try
            {
                service.Init();
                service.Start();
                service.Stop();
            }
            catch (Exception)
            {
                fail("Caught an Exception");
            }
        }
コード例 #16
0
        public async stt::Task GetRequestObjectAsync()
        {
            moq::Mock <SslPolicies.SslPoliciesClient> mockGrpcClient = new moq::Mock <SslPolicies.SslPoliciesClient>(moq::MockBehavior.Strict);

            mockGrpcClient.Setup(x => x.CreateOperationsClientForGlobalOperations()).Returns(new moq::Mock <lro::Operations.OperationsClient>().Object);
            GetSslPolicyRequest request = new GetSslPolicyRequest
            {
                Project   = "projectaa6ff846",
                SslPolicy = "ssl_policybf005a65",
            };
            SslPolicy expectedResponse = new SslPolicy
            {
                Id                = 11672635353343658936UL,
                Kind              = "kindf7aa39d9",
                Name              = "name1c9368b0",
                MinTlsVersion     = "min_tls_versionf843e251",
                CreationTimestamp = "creation_timestamp235e59a1",
                CustomFeatures    =
                {
                    "custom_features19916d63",
                },
                Profile         = "profile1b48977d",
                Fingerprint     = "fingerprint009e6052",
                Description     = "description2cf9da67",
                SelfLink        = "self_link7e87f12d",
                EnabledFeatures =
                {
                    "enabled_featuresf1f398e0",
                },
                Warnings = { new Warnings(), },
            };

            mockGrpcClient.Setup(x => x.GetAsync(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(new grpccore::AsyncUnaryCall <SslPolicy>(stt::Task.FromResult(expectedResponse), null, null, null, null));
            SslPoliciesClient client = new SslPoliciesClientImpl(mockGrpcClient.Object, null);
            SslPolicy         responseCallSettings = await client.GetAsync(request, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None));

            xunit::Assert.Same(expectedResponse, responseCallSettings);
            SslPolicy responseCancellationToken = await client.GetAsync(request, st::CancellationToken.None);

            xunit::Assert.Same(expectedResponse, responseCancellationToken);
            mockGrpcClient.VerifyAll();
        }
コード例 #17
0
        public void GetRequestObject()
        {
            moq::Mock <SslPolicies.SslPoliciesClient> mockGrpcClient = new moq::Mock <SslPolicies.SslPoliciesClient>(moq::MockBehavior.Strict);

            mockGrpcClient.Setup(x => x.CreateOperationsClientForGlobalOperations()).Returns(new moq::Mock <lro::Operations.OperationsClient>().Object);
            GetSslPolicyRequest request = new GetSslPolicyRequest
            {
                Project   = "projectaa6ff846",
                SslPolicy = "ssl_policybf005a65",
            };
            SslPolicy expectedResponse = new SslPolicy
            {
                Id                = 11672635353343658936UL,
                Kind              = "kindf7aa39d9",
                Name              = "name1c9368b0",
                MinTlsVersion     = SslPolicy.Types.MinTlsVersion.Tls12,
                CreationTimestamp = "creation_timestamp235e59a1",
                CustomFeatures    =
                {
                    "custom_features19916d63",
                },
                Profile         = SslPolicy.Types.Profile.UndefinedProfile,
                Fingerprint     = "fingerprint009e6052",
                Description     = "description2cf9da67",
                SelfLink        = "self_link7e87f12d",
                EnabledFeatures =
                {
                    "enabled_featuresf1f398e0",
                },
                Warnings = { new Warnings(), },
            };

            mockGrpcClient.Setup(x => x.Get(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(expectedResponse);
            SslPoliciesClient client   = new SslPoliciesClientImpl(mockGrpcClient.Object, null);
            SslPolicy         response = client.Get(request);

            xunit::Assert.Same(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
コード例 #18
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldLoadBaseCryptographicObjects() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldLoadBaseCryptographicObjects()
        {
            // given
            IDictionary <string, string> @params = stringMap();

            SslPolicyConfig policyConfig = new SslPolicyConfig("default");

            @params[neo4j_home.name()] = _home.AbsolutePath;
            @params[policyConfig.BaseDirectory.name()] = "certificates/default";
            Config config = Config.defaults(@params);

            // when
            SslPolicyLoader sslPolicyLoader = SslPolicyLoader.Create(config, NullLogProvider.Instance);

            // then
            SslPolicy sslPolicy = sslPolicyLoader.GetPolicy("default");

            assertNotNull(sslPolicy);
            assertNotNull(sslPolicy.PrivateKey());
            assertNotNull(sslPolicy.CertificateChain());
            assertNotNull(sslPolicy.NettyClientContext());
            assertNotNull(sslPolicy.NettyServerContext());
        }
コード例 #19
0
 /// <param name="sslPolicy"> </param>
 internal SecureClientPipelineWrapper(SslPolicy sslPolicy)
 {
     this._sslPolicy = sslPolicy;
 }
コード例 #20
0
ファイル: SslPolicyLoader.cs プロジェクト: Neo4Net/Neo4Net
        private void Load(Config config, Log log)
        {
            ISet <string> policyNames = config.IdentifiersFromGroup(typeof(SslPolicyConfig));

            foreach (string policyName in policyNames)
            {
                if (policyName.Equals(LEGACY_POLICY_NAME))
                {
                    // the legacy policy name is reserved for the legacy policy which derives its configuration from legacy settings
                    throw new System.ArgumentException("Legacy policy cannot be configured. Please migrate to new SSL policy system.");
                }

                SslPolicyConfig policyConfig           = new SslPolicyConfig(policyName);
                File            baseDirectory          = config.Get(policyConfig.BaseDirectory);
                File            trustedCertificatesDir = config.Get(policyConfig.TrustedDir);
                File            revokedCertificatesDir = config.Get(policyConfig.RevokedDir);

                if (!baseDirectory.exists())
                {
                    throw new System.ArgumentException(format("Base directory '%s' for SSL policy with name '%s' does not exist.", baseDirectory, policyName));
                }

                bool allowKeyGeneration = config.Get(policyConfig.AllowKeyGeneration);

                File       privateKeyFile     = config.Get(policyConfig.PrivateKey);
                string     privateKeyPassword = config.Get(policyConfig.PrivateKeyPassword);
                PrivateKey privateKey;

                X509Certificate[] keyCertChain;
                File keyCertChainFile = config.Get(policyConfig.PublicCertificate);

                if (allowKeyGeneration && !privateKeyFile.exists() && !keyCertChainFile.exists())
                {
                    GeneratePrivateKeyAndCertificate(log, policyName, keyCertChainFile, privateKeyFile, trustedCertificatesDir, revokedCertificatesDir);
                }

                privateKey   = LoadPrivateKey(privateKeyFile, privateKeyPassword);
                keyCertChain = LoadCertificateChain(keyCertChainFile);

                ClientAuth          clientAuth     = config.Get(policyConfig.ClientAuth);
                bool                trustAll       = config.Get(policyConfig.TrustAll);
                bool                verifyHostname = config.Get(policyConfig.VerifyHostname);
                TrustManagerFactory trustManagerFactory;

                ICollection <X509CRL> crls = GetCRLs(revokedCertificatesDir);

                try
                {
                    trustManagerFactory = CreateTrustManagerFactory(trustAll, trustedCertificatesDir, crls, clientAuth);
                }
                catch (Exception e)
                {
                    throw new Exception("Failed to create trust manager based on: " + trustedCertificatesDir, e);
                }

                IList <string> tlsVersions = config.Get(policyConfig.TlsVersions);
                IList <string> ciphers     = config.Get(policyConfig.Ciphers);

                SslPolicy sslPolicy = new SslPolicy(privateKey, keyCertChain, tlsVersions, ciphers, clientAuth, trustManagerFactory, _sslProvider, verifyHostname, _logProvider);
                log.Info(format("Loaded SSL policy '%s' = %s", policyName, sslPolicy));
                _policies[policyName] = sslPolicy;
            }
        }
コード例 #21
0
 /// <param name="sslPolicy"> </param>
 internal SecureServerPipelineWrapper(SslPolicy sslPolicy)
 {
     this._sslPolicy = sslPolicy;
 }
コード例 #22
0
 /// <param name="sslPolicy"> </param>
 /// <param name="logProvider"> </param>
 internal SecureHazelcastContextFactory(SslPolicy sslPolicy, LogProvider logProvider)
 {
     this._sslPolicy = sslPolicy;
     this._log       = logProvider.getLog(this.GetType());
 }
コード例 #23
0
        public virtual ServerConnector CreateConnector(Server server, SslPolicy sslPolicy, ListenSocketAddress address, JettyThreadCalculator jettyThreadCalculator)
        {
            SslConnectionFactory sslConnectionFactory = CreateSslConnectionFactory(sslPolicy);

            return(createConnector(server, address, jettyThreadCalculator, sslConnectionFactory, CreateHttpConnectionFactory()));
        }