Ejemplo n.º 1
0
        public IRestClient AddClientAuthentication(IRestClient client)
        {
            if (client.ClientCertificates == null)
            {
                client.ClientCertificates = new X509CertificateCollection();
            }

            var clientCertificate = CertificateProvider.GetCertificate(_certificate, _privateKey, _password);

            client.ClientCertificates.Add(clientCertificate);

            return(client);
        }
Ejemplo n.º 2
0
        internal static X509Certificate2Collection GetClientCertificates(ConnectionParameters parameters)
        {
            if (parameters.ClientCertificate == null)
            {
                return(null);
            }

            var clientCertificateCollection = new X509Certificate2Collection();
            var certificate = (X509Certificate2)CertificateProvider.GetCertificate(parameters.ClientCertificate);

            clientCertificateCollection.Add(certificate);

            return(clientCertificateCollection);
        }
Ejemplo n.º 3
0
        public MonoSslStream CreateServerStream(Stream stream, ConnectionParameters parameters)
        {
            var settings    = new MSI.MonoTlsSettings();
            var certificate = CertificateProvider.GetCertificate(parameters.ServerCertificate);

            var protocol = GetProtocol(parameters, true);

            CallbackHelpers.AddCertificateValidator(settings, parameters.ServerCertificateValidator);

            var askForCert = parameters.AskForClientCertificate || parameters.RequireClientCertificate;

            var sslStream = tlsProvider.CreateSslStream(stream, false, settings);

            sslStream.AuthenticateAsServer(certificate, askForCert, protocol, false);

            return(new MonoSslStream(sslStream));
        }
Ejemplo n.º 4
0
        public async Task <MonoSslStream> CreateServerStreamAsync(Stream stream, ConnectionParameters parameters, MSI.MonoTlsSettings settings, CancellationToken cancellationToken)
        {
            var certificate = CertificateProvider.GetCertificate(parameters.ServerCertificate);
            var protocol    = GetProtocol(parameters, true);

            CallbackHelpers.AddCertificateValidator(settings, parameters.ServerCertificateValidator);

            var askForCert    = parameters.AskForClientCertificate || parameters.RequireClientCertificate;
            var sslStream     = tlsProvider.CreateSslStream(stream, false, settings);
            var monoSslStream = new MonoSslStream(sslStream);

            try {
                await sslStream.AuthenticateAsServerAsync(certificate, askForCert, protocol, false).ConfigureAwait(false);
            } catch (Exception ex) {
                var lastError = monoSslStream.LastError;
                if (lastError != null)
                {
                    throw new AggregateException(ex, lastError);
                }
                throw;
            }

            return(monoSslStream);
        }