private void client_CertificateRequired(object sender, ComponentPro.Security.CertificateRequiredEventArgs e) { string cert = _loginSettings.Get <string>(FtpLoginInfo.Certificate); // If the client cert file is specified. if (!string.IsNullOrEmpty(cert)) { // Load Certificate. PasswordPrompt passdlg = new PasswordPrompt("Please provide password for certificate"); // Ask for cert's passpharse if (passdlg.ShowDialog() == System.Windows.Forms.DialogResult.OK) { X509Certificate2 clientCert = new X509Certificate2(cert, passdlg.Password); e.Certificates = new X509Certificate2Collection(clientCert); return; } // Password has not been provided. } CertProvider dlg = new CertProvider(); dlg.ShowDialog(); // Get the selected certificate. e.Certificates = new X509Certificate2Collection(dlg.SelectedCertificate); }
static void HandleDeleteAll(this CommandBindingCollection commandBindings) { commandBindings.Add(new CommandBinding(DeleteAll, (s, e) => { if (CertProvider.RemoveAll()) { NotifyCertificateChanged.Execute(null, e?.Source as IInputElement); } })); }
protected override Stream GetStream() { if (!AuthenticateAsClient && !AuthenticateAsServer) { throw new Exception("Authenticate as client or server."); } stream = new SslStreamExt(NetworkStream, true, RemoteCertificateValidationCallback) { ServerCertificateCallback = GetServerCertificate, InvalidHandshake = InvalidHandshake, }; try { if (AuthenticateAsClient) { stream.AuthenticateAsClient( SNI, ClientCertificate == null ? null : new X509CertificateCollection() { ClientCertificate }, SslProtocols, checkCertificateRevocation: false); } if (AuthenticateAsServer) { if (AutoGenerateServerCertificate) { certProvider = new CertProvider() { IssuerCertificate = CertificateAuthority, SubjectPrefix = GeneratedServerCertificatePrefix, SubjectPostfix = null, }; } stream.AuthenticateAsServer(ServerCertificate, RequireClientCertificate, SslProtocols, checkCertificateRevocation: false); } } finally { if (stream.ClientHello != null || stream.ServerHello != null) { WriteChunk(new MessageData(new SslHandshake(stream, chain))); } } return(stream); }
private void Create_Click(object sender, RoutedEventArgs e) { try { model.Validate(); Mouse.OverrideCursor = Cursors.Wait; var crt = X509.CreateCertificate(model); using (var certProvider = new CertProvider() { AppendOnly = true }) { certProvider.IsRoot = !model.SignByCertificateAuthority; if (model.SignByCertificateAuthority) { certProvider.IssuerThumbprint = model.CertificateAuthority; } certProvider.Append(crt); } model.Value = crt; Result = model; Close(); } catch (Exception ex) { if (ex is ValueException vex) { MessageBox.Show(vex.Message, "Invalid Value", MessageBoxButton.OK, MessageBoxImage.Warning); this.Focus(vex.PropertyName); } else { MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } finally { Mouse.OverrideCursor = null; } }