Ejemplo n.º 1
0
 /// <summary>
 /// 开始处理新的请求
 /// </summary>
 /// <param name="server">HTTP 服务</param>
 /// <param name="socket">套接字</param>
 internal void Start(SslServer server, ref System.Net.Sockets.Socket socket)
 {
     Socket      = socket;
     this.Server = server;
     socket      = null;
     try
     {
         SslCertificate certificate = server.Certificate;
         if (certificate != null)
         {
             SslStream = certificate.CreateSslStream(this);
         }
         else
         {
             NetworkStream = new NetworkStream(Socket, true);
             if (HelloStream == null)
             {
                 HelloStream = new ServerNameIndication.HelloStream(this);
             }
             HelloStream.ReadHello();
         }
         return;
     }
     catch (Exception error)
     {
         server.RegisterServer.TcpServer.Log.Exception(error, null, LogLevel.Exception | LogLevel.AutoCSer);
     }
     HeaderError();
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a SslCertificate resource in the specified project using the data included in the request.
        /// Documentation https://developers.google.com/compute/v1/reference/sslCertificates/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 v1 body.</param>
        /// <param name="optional">Optional paramaters.</param>
        /// <returns>OperationResponse</returns>
        public static Operation Insert(ComputeService service, string project, SslCertificate body, SslCertificatesInsertOptionalParms 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.SslCertificates.Insert(body, project);

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

                // Requesting data.
                return(request.Execute());
            }
            catch (Exception ex)
            {
                throw new Exception("Request SslCertificates.Insert failed.", ex);
            }
        }
 /// <summary>
 /// Creates a SslCertificate resource in the specified project and region using the data included in the request
 /// </summary>
 /// <param name="project">
 /// Project ID for this request.
 /// </param>
 /// <param name="region">
 /// Name of the region scoping this request.
 /// </param>
 /// <param name="sslCertificateResource">
 /// The body resource for this request
 /// </param>
 /// <param name="callSettings">If not null, applies overrides to this RPC call.</param>
 /// <returns>The RPC response.</returns>
 public virtual Operation Insert(string project, string region, SslCertificate sslCertificateResource, gaxgrpc::CallSettings callSettings = null) =>
 Insert(new InsertRegionSslCertificateRequest
 {
     Project = gax::GaxPreconditions.CheckNotNullOrEmpty(project, nameof(project)),
     Region  = gax::GaxPreconditions.CheckNotNullOrEmpty(region, nameof(region)),
     SslCertificateResource = gax::GaxPreconditions.CheckNotNull(sslCertificateResource, nameof(sslCertificateResource)),
 }, callSettings);
Ejemplo n.º 4
0
 /// <summary>
 /// 开始处理新的请求
 /// </summary>
 /// <param name="server">HTTP 服务</param>
 /// <param name="socket">套接字</param>
 internal void Start(SslServer server, ref System.Net.Sockets.Socket socket)
 {
     Socket      = socket;
     this.Server = server;
     socket      = null;
     try
     {
         SslCertificate certificate = server.Certificate;
         if (certificate != null)
         {
             SslStream = certificate.CreateSslStream(this);
         }
         else
         {
             NetworkStream = new NetworkStream(Socket, true);
             if (HelloStream == null)
             {
                 HelloStream = new ServerNameIndication.HelloStream(this);
             }
             HelloStream.ReadHello();
         }
         return;
     }
     catch (Exception error)
     {
         Console.WriteLine(error.ToString());
         server.RegisterServer.TcpServer.Log.Add(Log.LogType.Debug, error);
     }
     HeaderError();
 }
        /// <summary>Snippet for InsertAsync</summary>
        public async Task InsertAsync()
        {
            // Snippet: InsertAsync(string, string, SslCertificate, CallSettings)
            // Additional: InsertAsync(string, string, SslCertificate, CancellationToken)
            // Create client
            RegionSslCertificatesClient regionSslCertificatesClient = await RegionSslCertificatesClient.CreateAsync();

            // Initialize request argument(s)
            string         project = "";
            string         region  = "";
            SslCertificate sslCertificateResource = new SslCertificate();
            // Make the request
            lro::Operation <Operation, Operation> response = await regionSslCertificatesClient.InsertAsync(project, region, sslCertificateResource);

            // 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 regionSslCertificatesClient.PollOnceInsertAsync(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
        }
Ejemplo n.º 6
0
        /// <summary>Snippet for Insert</summary>
        public void Insert()
        {
            // Snippet: Insert(string, SslCertificate, CallSettings)
            // Create client
            SslCertificatesClient sslCertificatesClient = SslCertificatesClient.Create();
            // Initialize request argument(s)
            string         project = "";
            SslCertificate sslCertificateResource = new SslCertificate();
            // Make the request
            lro::Operation <Operation, Operation> response = sslCertificatesClient.Insert(project, sslCertificateResource);

            // 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 = sslCertificatesClient.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
        }
Ejemplo n.º 7
0
        public static HealthCheckResult BuildResult(SslCertificate sslCertificate)
        {
            // The order matters

            // Certificate already expired
            if (SslCertificateExpression.CertificateMissing().Compile().Invoke(sslCertificate))
            {
                return(HealthCheckResult.Unhealthy($"SSL certificate is missing on {sslCertificate.Url}"));
            }

            // Certificate already expired
            if (SslCertificateExpression.CertificateAlreadyExpired().Compile().Invoke(sslCertificate))
            {
                var daysExpired = (DateTime.UtcNow.Date - sslCertificate.NotAfter.Date).Days;
                return(HealthCheckResult.Unhealthy($"SSL certificate expired {daysExpired} days ago"));
            }

            // Certificate has not become valid yet
            if (SslCertificateExpression.CertificateIsNotValidYet().Compile().Invoke(sslCertificate))
            {
                var daysToBecomeValid = (sslCertificate.NotBefore.Date - DateTime.UtcNow.Date).Days;
                return(HealthCheckResult.Unhealthy($"SSL certificate will become valid in {daysToBecomeValid} days"));
            }

            // Certificate about to expire in less than 60 days
            if (SslCertificateExpression.CertificateAboutToExpire(60).Compile().Invoke(sslCertificate))
            {
                var daysToExpire = (sslCertificate.NotAfter.Date - DateTime.UtcNow.Date).Days;
                return(HealthCheckResult.Degraded($"SSL certificate is about to expire in {daysToExpire} days"));
            }

            // Certificate has no issuer
            if (SslCertificateExpression.CertificateHasNoIssuer().Compile().Invoke(sslCertificate))
            {
                return(HealthCheckResult.Degraded("SSL certificate has no issuer"));
            }

            // Certificate has no subject
            if (SslCertificateExpression.CertificateHasNoSubject().Compile().Invoke(sslCertificate))
            {
                return(HealthCheckResult.Degraded("SSL certificate has no subject"));
            }

            // Certificate is no greater than v2
            if (SslCertificateExpression.CertificateDoesNotHaveVersionGreaterThan2().Compile().Invoke(sslCertificate))
            {
                return(HealthCheckResult.Degraded("SSL certificate is lower than version 2"));
            }

            // Return
            return(HealthCheckResult.Healthy(sslCertificate.Url));
        }
Ejemplo n.º 8
0
        public async Task <HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = new CancellationToken())
        {
            // Instantiate certificate
            var sslCertificationCheck = new SslCertificate();

            // Get url (e.g. "https://dev.pinnacle.com")
            var url = _configuration["Health:SslCertificateHealthCheck"];

            // Get info
            await sslCertificationCheck.GetServerCertificationInfo(url);

            // Return result
            return(sslCertificationCheck.HealthCheckResult);
        }
Ejemplo n.º 9
0
 /// <summary>Snippet for Get</summary>
 public void GetRequestObject()
 {
     // Snippet: Get(GetSslCertificateRequest, CallSettings)
     // Create client
     SslCertificatesClient sslCertificatesClient = SslCertificatesClient.Create();
     // Initialize request argument(s)
     GetSslCertificateRequest request = new GetSslCertificateRequest
     {
         SslCertificate = "",
         Project        = "",
     };
     // Make the request
     SslCertificate response = sslCertificatesClient.Get(request);
     // End snippet
 }
Ejemplo n.º 10
0
            void UpdateInProgressHandlers(SslCertificate certificate, Action <SslErrorHandler> update)
            {
                List <SslErrorHandler> inProgressHandlers;

                if (!this.inProgress.TryGetValue(certificate, out inProgressHandlers))
                {
                    return;
                }

                foreach (SslErrorHandler sslErrorHandler in inProgressHandlers)
                {
                    update(sslErrorHandler);
                }

                inProgressHandlers.Clear();
            }
Ejemplo n.º 11
0
        /// <summary>Snippet for GetAsync</summary>
        public async Task GetRequestObjectAsync()
        {
            // Snippet: GetAsync(GetSslCertificateRequest, CallSettings)
            // Additional: GetAsync(GetSslCertificateRequest, CancellationToken)
            // Create client
            SslCertificatesClient sslCertificatesClient = await SslCertificatesClient.CreateAsync();

            // Initialize request argument(s)
            GetSslCertificateRequest request = new GetSslCertificateRequest
            {
                SslCertificate = "",
                Project        = "",
            };
            // Make the request
            SslCertificate response = await sslCertificatesClient.GetAsync(request);

            // End snippet
        }
Ejemplo n.º 12
0
        /// <summary>
        /// 设置证书信息
        /// </summary>
        /// <param name="domain">域名信息</param>
        /// <returns></returns>
        internal bool SetCertificate(Domain domain)
        {
            string         domainString   = domain.DomainData.toStringNotNull();
            SslCertificate sslCertificate = HttpRegister.Server.Config.GetCertificate(domain, domainString, RegisterServer.TcpServer.Log);

            if (sslCertificate == null)
            {
                RegisterServer.TcpServer.Log.Add(AutoCSer.Log.LogType.Error, "安全证书获取失败 " + domainString);
                return(false);
            }
            HashBytes domainKey;
            int       portIndex = domainString.IndexOf(':');

            if (portIndex != -1)
            {
                domainString = domainString.Substring(0, portIndex);
                domainKey    = domainString.getBytes();
            }
            else
            {
                domainKey = domain.DomainData;
            }
            Monitor.Enter(certificateLock);
            try
            {
                if (certificate == null)
                {
                    certificate       = sslCertificate;
                    certificateDomain = domainKey;
                }
                else
                {
                    certificates = DictionaryCreator.CreateHashBytes <SslCertificate>();
                    certificates.Add(certificateDomain, certificate);
                    certificates[domainKey] = sslCertificate;
                }
            }
            finally { Monitor.Exit(certificateLock); }
            return(true);
        }
Ejemplo n.º 13
0
        public void GetRequestObject()
        {
            moq::Mock <RegionSslCertificates.RegionSslCertificatesClient> mockGrpcClient = new moq::Mock <RegionSslCertificates.RegionSslCertificatesClient>(moq::MockBehavior.Strict);

            mockGrpcClient.Setup(x => x.CreateOperationsClientForRegionOperations()).Returns(new moq::Mock <lro::Operations.OperationsClient>().Object);
            GetRegionSslCertificateRequest request = new GetRegionSslCertificateRequest
            {
                SslCertificate = "ssl_certificate25650c52",
                Region         = "regionedb20d96",
                Project        = "projectaa6ff846",
            };
            SslCertificate expectedResponse = new SslCertificate
            {
                Id   = 11672635353343658936UL,
                Kind = "kindf7aa39d9",
                Name = "name1c9368b0",
                Type = SslCertificate.Types.Type.Unspecified,
                CreationTimestamp       = "creation_timestamp235e59a1",
                Region                  = "regionedb20d96",
                Managed                 = new SslCertificateManagedSslCertificate(),
                SelfManaged             = new SslCertificateSelfManagedSslCertificate(),
                Certificate             = "certificateef0cd3e0",
                PrivateKey              = "private_key33176a15",
                Description             = "description2cf9da67",
                ExpireTime              = "expire_timece1cc25c",
                SelfLink                = "self_link7e87f12d",
                SubjectAlternativeNames =
                {
                    "subject_alternative_names2036b37b",
                },
            };

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

            xunit::Assert.Same(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
 /// <summary>
 /// Creates a SslCertificate resource in the specified project and region using the data included in the request
 /// </summary>
 /// <param name="project">
 /// Project ID for this request.
 /// </param>
 /// <param name="region">
 /// Name of the region scoping this request.
 /// </param>
 /// <param name="sslCertificateResource">
 /// The body resource for this request
 /// </param>
 /// <param name="cancellationToken">A <see cref="st::CancellationToken"/> to use for this RPC.</param>
 /// <returns>A Task containing the RPC response.</returns>
 public virtual stt::Task <Operation> InsertAsync(string project, string region, SslCertificate sslCertificateResource, st::CancellationToken cancellationToken) =>
 InsertAsync(project, region, sslCertificateResource, gaxgrpc::CallSettings.FromCancellationToken(cancellationToken));
Ejemplo n.º 15
0
 /// <summary>
 /// Creates a SslCertificate resource in the specified project using the data included in the request.
 /// </summary>
 /// <param name="project">
 /// Project ID for this request.
 /// </param>
 /// <param name="sslCertificateResource">
 /// The body resource for this request
 /// </param>
 /// <param name="callSettings">If not null, applies overrides to this RPC call.</param>
 /// <returns>A Task containing the RPC response.</returns>
 public virtual stt::Task <Operation> InsertAsync(string project, SslCertificate sslCertificateResource, gaxgrpc::CallSettings callSettings = null) =>
 InsertAsync(new InsertSslCertificateRequest
 {
     Project = gax::GaxPreconditions.CheckNotNullOrEmpty(project, nameof(project)),
     SslCertificateResource = gax::GaxPreconditions.CheckNotNull(sslCertificateResource, nameof(sslCertificateResource)),
 }, callSettings);