示例#1
0
        public DefaultHttpHandler(IConnection connection)
        {
            if (connection != null)
            {
                _connection = connection;
            }
            else
            {
                throw new ArgumentNullException("connection");
            }

            Credentials     = _connection.Credentials;
            PreAuthenticate = true;

            if (_connection.CookieContainer != null)
            {
                CookieContainer = _connection.CookieContainer;
            }

            if (_connection.Proxy != null)
            {
                Proxy = _connection.Proxy;
            }

            foreach (X509Certificate cert in _connection.Certificates)
            {
                ClientCertificates.Add(cert);
            }
        }
示例#2
0
 public NFeAutorizacao4(string url, X509Certificate certificado, int timeOut)
 {
     SoapVersion = SoapProtocolVersion.Soap12;
     Url         = url;
     Timeout     = timeOut;
     ClientCertificates.Add(certificado);
 }
示例#3
0
    public CustomHttpClientHandler(string clientId, string clientSecret)
    {
        _clientId                = clientId;
        _clientSecret            = clientSecret;
        ClientCertificateOptions = ClientCertificateOption.Manual;
        SslProtocols             = System.Security.Authentication.SslProtocols.None;

        byte[] certFile;

        //  Reads binary certificate file from aws s3 and attaches it to the request
        var s3Client = new AmazonS3Client(RegionEndpoint.USEast1);

        GetObjectRequest certRequest = new GetObjectRequest()
        {
            BucketName = bucketName,
            Key        = certFileName
        };

        using (GetObjectResponse response = s3Client.GetObjectAsync(certRequest).Result)
        {
            using (Stream responseStream = response.ResponseStream)
            {
                using (MemoryStream ms = new MemoryStream())
                {
                    responseStream.CopyTo(ms);
                    certFile = ms.ToArray();
                }
            }
        }

        var cert = new X509Certificate2(certFile, "certPass", X509KeyStorageFlags.DefaultKeySet);

        ClientCertificates.Add(cert);
    }
 public GnreConfiguracaoUF2(string url, X509Certificate certificado, int timeOut)
 {
     SoapVersion = SoapProtocolVersion.Soap12;
     Url         = url;
     Timeout     = timeOut;
     ClientCertificates.Add(certificado);
 }
示例#5
0
 public NfeStatusServico4NFeSVAN(string url, X509Certificate certificado, int timeOut)
 {
     SoapVersion = SoapProtocolVersion.Soap12;
     Url         = url;
     Timeout     = timeOut;
     ClientCertificates.Add(certificado);
 }
示例#6
0
 public NfeConsultaProtocolo3(string url, X509Certificate certificado, int timeOut)
 {
     SoapVersion = SoapProtocolVersion.Soap12;
     Url         = url;
     Timeout     = timeOut;
     ClientCertificates.Add(certificado);
 }
 public NfeDownloadNF(string url, X509Certificate certificado, int timeOut)
 {
     SoapVersion = SoapProtocolVersion.Soap11;
     Url         = url;
     Timeout     = timeOut;
     ClientCertificates.Add(certificado);
 }
 public NfeDistDFeInteresse(string url, X509Certificate certificado, int timeOut)
 {
     SoapVersion = SoapProtocolVersion.Soap12;
     Url         = url;
     Timeout     = timeOut;
     ClientCertificates.Add(certificado);
 }
示例#9
0
 public RecepcaoEvento4AN(string url, X509Certificate certificado, int timeOut)
 {
     SoapVersion = SoapProtocolVersion.Soap12;
     Url         = url;
     Timeout     = timeOut;
     ClientCertificates.Add(certificado);
 }
示例#10
0
 /// <summary>
 /// 配置添加客户端安全证书
 /// </summary>
 /// <param name="certificatePath">客户端安全证书路径</param>
 public TRequest ConfigAddClientCertificate(string certificatePath)
 {
     if (certificatePath.IsEmpty())
     {
         return(This());
     }
     ClientCertificates.Add(new X509Certificate2(certificatePath));
     return(This());
 }
 protected override async Task <HttpResponseMessage> SendAsync(HttpRequestMessage request,
                                                               CancellationToken cancellationToken)
 {
     ClientCertificates.Add(new X509Certificate());
     //var certificate = _certificateProvider.Load(_certificate, _password);
     //var requestHandler = new WebRequestHandler();
     //requestHandler.ClientCertificates.Add(certificate);
     return(await base.SendAsync(request, cancellationToken));
 }
示例#12
0
        public CTeDistDFeInteresse(WsdlConfiguracao configuracao)
        {
            SoapVersion = SoapProtocolVersion.Soap12;
            Url         = configuracao.Url;
            Timeout     = configuracao.TimeOut;
            ClientCertificates.Add(configuracao.CertificadoDigital);

            cteCabecMsg             = new cteCabecMsg();
            cteCabecMsg.versaoDados = configuracao.Versao;
            cteCabecMsg.cUF         = configuracao.CodigoIbgeEstado;
        }
示例#13
0
        public DockerHttpClientHandler(IConfiguration configuration)
        {
            var certificateFileName = configuration.GetCertificateFileName();

            if (!string.IsNullOrEmpty(certificateFileName))
            {
                var clientCertificate = new X509Certificate2(certificateFileName, configuration.GetCertificatePassword());
                ClientCertificates.Add(clientCertificate);

                ServerCertificateCustomValidationCallback = (httpRequestMessage, cert, cetChain, policyErrors) => true;
            }
        }
        /// <summary>
        /// Custom HTTP Handler to delegate the processing of HTTP requests and extending it.
        /// </summary>
        /// <param name="context">Cake Context the request is geting </param>
        /// <param name="settings">HttpSettings to apply to the inner handler</param>
        public CakeHttpClientHandler(ICakeContext context, HttpSettings settings)
        {
            _Context  = context ?? throw new ArgumentNullException(nameof(context));
            _Settings = settings ?? throw new ArgumentException(nameof(settings));

            UseDefaultCredentials = settings.UseDefaultCredentials;
            UseCookies            = false;

            foreach (var clientCertificate in settings.ClientCertificates)
            {
                ClientCertificates.Add(clientCertificate);
            }
        }
示例#15
0
 /// <summary>
 /// 配置添加客户端安全证书
 /// </summary>
 /// <param name="certificatePath">客户端安全证书路径</param>
 /// <param name="certificatePassword">客户端安全证书密码</param>
 public TRequest ConfigAddClientCertificate(string certificatePath, string certificatePassword)
 {
     if (certificatePath.IsEmpty())
     {
         return(This());
     }
     if (certificatePassword.IsEmpty())
     {
         return(ConfigAddClientCertificate(certificatePath));
     }
     ClientCertificates.Add(new X509Certificate2(certificatePath, certificatePassword, X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.MachineKeySet));
     return(This());
 }
        /// <summary>
        /// Constructor that always uses a client certificate if one exist for TLS client authentication.
        /// </summary>
        /// <param name="client">Backpointer to OioIdwsClient</param>
        /// <param name="accessToken">An optional access token. Can be used if client already has access to a cached token.</param>
        public OioIdwsRequestHandler(OioIdwsClient client, AccessToken.AccessToken accessToken)
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            _client      = client;
            _accessToken = accessToken;

            //We can't know in advance whether it's a Bearer/Holder-of-key token we're going to work with. Either way we just add the certificate to the request, if given
            if (client.Settings.ClientCertificate != null)
            {
                ClientCertificates.Add(client.Settings.ClientCertificate);
            }
        }
        public DKApiMessageHandler()
        {
            var username = Environment.GetEnvironmentVariable(EnvironmentVariableDKApiUsername);
            var password = Environment.GetEnvironmentVariable(EnvironmentVariableDKApiPassword);

            AuthHeaderValue = new AuthenticationHeaderValue(
                "Basic",
                Convert.ToBase64String(
                    System.Text.ASCIIEncoding.ASCII.GetBytes(
                        $"{username}:{password}")));

            // Use client ssh certificate
            var certPath = Environment.GetEnvironmentVariable(EnvironmentVariableDKApiCertPath);
            var certPass = Environment.GetEnvironmentVariable(EnvironmentVariableDKApiCertPass);
            var cert     = new X509Certificate2(certPath, certPass);

            ClientCertificates.Add(cert);
        }
示例#18
0
        public DefaultHttpHandler(IConnection connection)
        {
            if (connection != null)
            {
                _connection = connection;
            }
            else
            {
                throw new ArgumentNullException("connection");
            }

            Credentials = _connection.Credentials;
#if PORTABLE
            if (this.SupportsPreAuthenticate())
            {
                PreAuthenticate = true;
            }
#elif NET45 || NETSTANDARD
            PreAuthenticate = true;
#endif

            if (_connection.CookieContainer != null)
            {
                CookieContainer = _connection.CookieContainer;
            }

#if !PORTABLE
            if (_connection.Proxy != null)
            {
                Proxy = _connection.Proxy;
            }
#endif

#if (NET4 || NET45 || NETSTANDARD)
            foreach (X509Certificate cert in _connection.Certificates)
            {
                ClientCertificates.Add(cert);
            }
#endif
        }
示例#19
0
    protected override async Task <HttpResponseMessage> SendAsync(
        HttpRequestMessage request,
        CancellationToken cancellationToken)
    {
        string serverName = request.RequestUri.Host;

        if (ClientCertificates.Contains(_certMap[serverName]))
        {
            try
            {
                var response = await base.SendAsync(request, cancellationToken);

                return(response);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.ReadKey();
                throw;
            }
        }
        else
        {
            ClientCertificates.Clear();
            ClientCertificates.Add(_certMap[serverName]);
            try
            {
                var response = await base.SendAsync(request, cancellationToken);

                return(response);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.ReadKey();
                throw;
            }
        }
    }
        public IWebClientRequest UseClientCertificate(X509Certificate2 clientCertificate)
        {
            ClientCertificates.Add(clientCertificate);

            return(this);
        }
示例#21
0
 public CertMessageHandler()
 {
     ClientCertificateOptions = ClientCertificateOption.Manual;
     ClientCertificates.Add(HttpClientHelpers.GetCert());
 }
示例#22
0
            public ScopedHttpClientHandler(Uri certFile, string certPass)
            {
                AllowAutoRedirect = false;

                ClientCertificates.Add(GetCertificate(certFile, certPass));
            }
示例#23
0
 public CollegeLicenceClientHandler()
 {
     ClientCertificates.Add(new X509Certificate2(PrimeConstants.PHARMANET_SSL_CERT_FILENAME, PrimeConstants.PHARMANET_SSL_CERT_PASSWORD));
     ClientCertificateOptions = ClientCertificateOption.Manual;
 }
示例#24
0
        //public BankIDHttpClientHandler()
        //{
        //    _telemetryClient = new TelemetryClient();
        //}

        public BankIDHttpClientHandler(BankIDServiceSettings bankIdServiceSettings, TelemetryClient telemetryClient)
        {
            //TelemetryConfiguration.Active
            _telemetryClient       = telemetryClient; // new TelemetryClient();
            _bankIdServiceSettings = bankIdServiceSettings;
            //var bankIdServiceSettings = new BankIDServiceSettings(env);

            AllowAutoRedirect      = false;
            AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip;
            SslProtocols           = SslProtocols.Tls12;

            // Hosting dependent config
            var hosting = Environment.GetEnvironmentVariable("ASPNETCORE_HOSTING");

            if (!string.IsNullOrEmpty(hosting) && hosting.Equals("Azure"))
            {
                // https://docs.microsoft.com/en-us/azure/app-service/app-service-web-ssl-cert-load


                // server certificate
                X509Store certStore = new X509Store(StoreName.My, StoreLocation.CurrentUser);
                certStore.Open(OpenFlags.ReadOnly);

                X509Certificate2Collection caCertCollection = certStore.Certificates.Find(
                    X509FindType.FindByThumbprint,
                    _bankIdServiceSettings.CaCertThumbprint,
                    false);

                if (caCertCollection.Count > 0)
                {
                    X509Certificate2 caCert = caCertCollection[0];
                    var validator           = new RootCaValidator(caCert);
                    ServerCertificateCustomValidationCallback = validator.Validate;

                    _telemetryClient.TrackTrace($"Loaded CA Cert {caCert.SubjectName?.Name}, {caCert.Thumbprint}", SeverityLevel.Information);
                }
                else
                {
                    _telemetryClient.TrackTrace($"Could not load CA Cert", SeverityLevel.Critical);
                }

                X509Certificate2Collection rpCertCollection = certStore.Certificates.Find(
                    X509FindType.FindByThumbprint,
                    _bankIdServiceSettings.RpCertThumbprint,
                    false);

                if (rpCertCollection.Count > 0)
                {
                    X509Certificate2 rpCert = rpCertCollection[0];
                    ClientCertificates.Add(rpCert);
                    _telemetryClient.TrackTrace($"Loaded RP Cert {rpCert.SubjectName?.Name}, {rpCert.Thumbprint}", SeverityLevel.Information);
                }
                else
                {
                    _telemetryClient.TrackTrace($"Could not load RP Cert", SeverityLevel.Critical);
                }
                _telemetryClient.Flush();
                certStore.Close();
            }
            else
            {
                // Local
                SecureString secureString = new SecureString();
                "qwerty123".ToCharArray().ToList().ForEach(p => secureString.AppendChar(p));

                var rootCa    = new X509Certificate2(_bankIdServiceSettings.CaCert);
                var validator = new RootCaValidator(rootCa);
                ServerCertificateCustomValidationCallback = validator.Validate;

                ClientCertificates.Add(new X509Certificate2(_bankIdServiceSettings.RpCert, secureString));
            }
        }
示例#25
0
 public CollegeLicenceClientHandler()
 {
     ClientCertificates.Add(new X509Certificate2(PrimeEnvironment.PharmanetApi.SslCertFilename, PrimeEnvironment.PharmanetApi.SslCertPassword));
     ClientCertificateOptions = ClientCertificateOption.Manual;
 }