Exemplo n.º 1
0
        internal override MSI.IMonoTlsContext CreateTlsContext(
            string hostname, bool serverMode, MSI.TlsProtocols protocolFlags,
            SSCX.X509Certificate serverCertificate, PSSCX.X509CertificateCollection clientCertificates,
            bool remoteCertRequired, MSI.MonoEncryptionPolicy encryptionPolicy,
            MSI.MonoTlsSettings settings)
        {
            var config = TlsProviderFactory.CreateTlsConfiguration(
                hostname, serverMode, protocolFlags, serverCertificate,
                remoteCertRequired, settings);

            return(new TlsContextWrapper(config, serverMode));
        }
Exemplo n.º 2
0
        public TlsConfiguration(MSI.TlsProtocols protocols, MSI.MonoTlsSettings settings, string targetHost)
        {
            supportedProtocols = protocols;
            requestedProtocol  = CheckProtocol(settings, ref supportedProtocols, false);
            TlsSettings        = settings;
            TargetHost         = targetHost;

            if (settings != null)
            {
                UserSettings = (UserSettings)settings.UserSettings;
            }
            if (UserSettings == null)
            {
                UserSettings = new UserSettings(settings);
            }

            RenegotiationFlags = DefaultRenegotiationFlags;
        }
Exemplo n.º 3
0
        public TlsConfiguration(MSI.TlsProtocols protocols, MSI.MonoTlsSettings settings, MX.X509Certificate certificate, AsymmetricAlgorithm privateKey)
        {
            supportedProtocols = protocols;
            requestedProtocol  = CheckProtocol(settings, ref supportedProtocols, true);
            TlsSettings        = settings;
            Certificate        = certificate;
            PrivateKey         = privateKey;

            if (settings != null)
            {
                UserSettings = (UserSettings)settings.UserSettings;
            }
            if (UserSettings == null)
            {
                UserSettings = new UserSettings(settings);
            }

            RenegotiationFlags = DefaultRenegotiationFlags;
        }
Exemplo n.º 4
0
        internal static ITlsConfiguration CreateTlsConfiguration(
            string hostname, bool serverMode, MSI.TlsProtocols protocolFlags,
            SSCX.X509Certificate serverCertificate, bool remoteCertRequired,
            MSI.MonoTlsSettings settings)
        {
            object[]          args;
            ITlsConfiguration config;

            if (serverMode)
            {
                var cert     = (PSSCX.X509Certificate2)serverCertificate;
                var monoCert = new MX.X509Certificate(cert.RawData);
                args = new object[] {
                    (MSI.TlsProtocols)protocolFlags,
                    (MSI.MonoTlsSettings)settings,
                    monoCert,
                    cert.PrivateKey
                };
            }
            else
            {
                args = new object[] {
                    (MSI.TlsProtocols)protocolFlags,
                    (MSI.MonoTlsSettings)settings,
                    hostname
                };
            }

            config = (ITlsConfiguration)CreateInstance(tlsConfigTypeName, args);

            if (serverMode && remoteCertRequired)
            {
                config.AskForClientCertificate = true;
            }

            return(config);
        }
Exemplo n.º 5
0
        static MSI.TlsProtocolCode CheckProtocol(MSI.MonoTlsSettings settings, ref MSI.TlsProtocols protocols, bool isServer)
        {
            if (settings != null && settings.EnabledProtocols != null)
            {
                protocols = (MSI.TlsProtocols)settings.EnabledProtocols.Value;
            }

            if (isServer)
            {
                protocols &= MSI.TlsProtocols.ServerMask;
            }
            else
            {
                protocols &= MSI.TlsProtocols.ClientMask;
            }

            if (protocols == 0)
            {
                throw new MSI.TlsException(MSI.AlertDescription.ProtocolVersion);
            }

            if ((protocols & MSI.TlsProtocols.Tls12) != 0)
            {
                return(MSI.TlsProtocolCode.Tls12);
            }
            if ((protocols & MSI.TlsProtocols.Tls11) != 0)
            {
                return(MSI.TlsProtocolCode.Tls11);
            }
            if ((protocols & MSI.TlsProtocols.Tls10) != 0)
            {
                return(MSI.TlsProtocolCode.Tls10);
            }

            throw new MSI.TlsException(MSI.AlertDescription.ProtocolVersion);
        }