private static SSLConfig ConfigSslConfig(SSLConfig sslConfig, bool isSslEnabled, bool?validateCertificateChain,
                                          bool?validateCertificateName, bool?checkCertificateRevocation, string certSubjectName, byte[] clientCertificate,
                                          string certPassword)
 {
     sslConfig.Enabled = isSslEnabled;
     if (clientCertificate != null)
     {
         var certFilePath = CreateTmpFile(clientCertificate);
         sslConfig.CertificateFilePath = certFilePath;
         if (certPassword != null)
         {
             sslConfig.CertificatePassword = certPassword;
         }
     }
     if (validateCertificateChain != null)
     {
         sslConfig.ValidateCertificateChain = validateCertificateChain.Value;
     }
     if (validateCertificateName != null)
     {
         sslConfig.ValidateCertificateName = validateCertificateName.Value;
     }
     if (certSubjectName != null)
     {
         sslConfig.CertificateName = certSubjectName;
     }
     if (checkCertificateRevocation != null)
     {
         sslConfig.CheckCertificateRevocation = checkCertificateRevocation.Value;
     }
     return(sslConfig);
 }
예제 #2
0
        private static SSLConfig CreateSslConfig(bool isSslEnabled, bool?validateCertificateChain, bool?validateCertificateName,
                                                 bool?checkCertificateRevocation, string certSubjectName, byte[] clientCertificate, string certPassword)
        {
            var sslConfig = new SSLConfig();

            sslConfig.SetEnabled(isSslEnabled);
            if (clientCertificate != null)
            {
                var certFilePath = CreateTmpFile(clientCertificate);
                sslConfig.SetProperty(SSLConfig.CertificateFilePath, certFilePath);
                if (certPassword != null)
                {
                    sslConfig.SetProperty(SSLConfig.CertificatePassword, certPassword);
                }
            }
            if (validateCertificateChain != null)
            {
                sslConfig.SetProperty(SSLConfig.ValidateCertificateChain, validateCertificateChain.ToString());
            }
            if (validateCertificateName != null)
            {
                sslConfig.SetProperty(SSLConfig.ValidateCertificateName, validateCertificateName.ToString());
            }
            if (certSubjectName != null)
            {
                sslConfig.SetProperty(SSLConfig.CertificateName, certSubjectName);
            }
            if (checkCertificateRevocation != null)
            {
                sslConfig.SetProperty(SSLConfig.CheckCertificateRevocation, checkCertificateRevocation.ToString());
            }
            return(sslConfig);
        }
예제 #3
0
        static X509Certificate2Collection GetClientCertificatesOrDefault(string cerPath, SSLConfig sslConfig)
        {
            if (cerPath == null)
            {
                return(null);
            }

            var clientCertificates = new X509Certificate2Collection();

            try
            {
                clientCertificates.Import(cerPath, sslConfig.CertificatePassword, X509KeyStorageFlags.DefaultKeySet);
            }
            catch (Exception)
            {
                Logger.Finest($"Cannot load client certificate:{cerPath}.");
                throw;
            }

            return(clientCertificates);
        }