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); }
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); }
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)); }
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); }