private async void ButtonGenerate_Click(object sender, EventArgs e) { try { ComboBoxKeyTypeItem selectedKeyTypeItem = GetSelectedComboBoxItem(); if (selectedKeyTypeItem.Kind == ComboBoxKeyTypeItem.Kinds.Asymmetric) { List <ObjectAttribute> privateKeyObjectAttributes = GetObjectAttributesFromListView(ListViewPrivateKeyAttributes); List <ObjectAttribute> publicKeyObjectAttributes = GetObjectAttributesFromListView(ListViewPublicKeyAttributes); await WaitDialog.Execute( this, () => _pkcs11Slot.GenerateAsymmetricKeyPair(selectedKeyTypeItem.KeyType, privateKeyObjectAttributes, publicKeyObjectAttributes) ); } else { List <ObjectAttribute> secretKeyObjectAttributes = GetObjectAttributesFromListView(ListViewSecretKeyAttributes); await WaitDialog.Execute( this, () => _pkcs11Slot.GenerateSymmetricKey(selectedKeyTypeItem.KeyType, secretKeyObjectAttributes) ); } DialogResult = DialogResult.OK; } catch (Exception ex) { WinFormsUtils.ShowError(this, ex); } }
private void GenerateKeysDialog_Shown(object sender, EventArgs e) { if (ComboBoxKeyType.Items.Count <= 0) { WinFormsUtils.ShowError(this, "PKCS#11 library does not support generation of the known key types"); DialogResult = DialogResult.Cancel; } else { ComboBoxKeyType.SelectedIndex = 0; } }
private void ButtonOk_Click(object sender, EventArgs e) { try { _slot.Login(_userType, TextBoxPin.Text); DialogResult = DialogResult.OK; } catch (Exception ex) { WinFormsUtils.ShowError(this, ex); } }
private async void ButtonOk_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(TextBoxPkcs11Library.Text)) { WinFormsUtils.ShowError(this, "PKCS#11 library is not specified"); return; } if (CheckBoxEnableLogging.Checked) { if (string.IsNullOrEmpty(TextBoxPkcs11Logger.Text)) { WinFormsUtils.ShowError(this, "PKCS#11 logging library is not specified"); return; } if (string.IsNullOrEmpty(TextBoxLogFile.Text)) { WinFormsUtils.ShowError(this, "Log file is not specified"); return; } if (!Path.IsPathRooted(TextBoxLogFile.Text)) { WinFormsUtils.ShowError(this, "Path to log file is not absolute path"); return; } } try { await WaitDialog.Execute( this, () => Pkcs11Admin.Instance.LoadLibrary( TextBoxPkcs11Library.Text, TextBoxPkcs11Logger.Text, TextBoxLogFile.Text, CheckBoxEnableLogging.Checked, CheckBoxOverwriteLogFile.Checked ) ); DialogResult = DialogResult.OK; Properties.Settings d = Properties.Settings.Default; d.UserPkcs11Library = TextBoxPkcs11Library.Text; d.Save(); } catch (Exception ex) { WinFormsUtils.ShowError(this, ex); } }
private async void ButtonOk_Click(object sender, EventArgs e) { try { await WaitDialog.Execute(this, () => _slot.InitToken(null, TextBoxTokenLabel.Text)); DialogResult = DialogResult.OK; } catch (Exception ex) { WinFormsUtils.ShowError(this, ex); } }
private async void ButtonGenerate_Click(object sender, EventArgs e) { try { if (ListViewSubject.Items.Count < 1) { WinFormsUtils.ShowInfo(null, "Please specify subject first"); return; } DnEntry[] dnEntries = new DnEntry[ListViewSubject.Items.Count]; for (int i = 0; i < ListViewSubject.Items.Count; i++) { dnEntries[i] = (DnEntry)ListViewSubject.Items[i].Tag; } string fileName = null; byte[] fileContent = null; // TODO - Parametrize HashAlgorithm // TODO - Specify SAN await WaitDialog.Execute( this, () => _pkcs11Slot.GenerateCsr(_privKeyInfo, _pubKeyInfo, dnEntries, HashAlgorithm.SHA256, out fileName, out fileContent) ); using (SaveFileDialog saveFileDialog = new SaveFileDialog()) { saveFileDialog.FileName = fileName; saveFileDialog.Filter = "All files (*.*)|*.*|DER encoded certificate signing request (*.csr)|*.csr"; saveFileDialog.FilterIndex = 2; saveFileDialog.AddExtension = true; saveFileDialog.CreatePrompt = false; saveFileDialog.OverwritePrompt = true; if (saveFileDialog.ShowDialog(this) == DialogResult.OK) { File.WriteAllBytes(saveFileDialog.FileName, fileContent); WinFormsUtils.ShowInfo(this, "CSR successfully saved"); DialogResult = DialogResult.OK; } } } catch (Exception ex) { WinFormsUtils.ShowError(this, ex); } }
private async void ButtonOk_Click(object sender, EventArgs e) { if (TextBoxPin.Text != TextBoxConfirmPin.Text) { WinFormsUtils.ShowInfo(this, "New PIN entries do not match"); return; } try { await WaitDialog.Execute(this, () => _slot.InitToken(TextBoxPin.Text, TextBoxTokenLabel.Text)); DialogResult = DialogResult.OK; } catch (Exception ex) { WinFormsUtils.ShowError(this, ex); } }
private void ButtonCreate_Click(object sender, EventArgs e) { try { List <ObjectAttribute> objectAttributes = new List <ObjectAttribute>(); foreach (ListViewItem listViewItem in ListViewAttributes.CheckedItems) { objectAttributes.Add((ObjectAttribute)listViewItem.Tag); } _pkcs11Slot.CreateObject(objectAttributes); DialogResult = DialogResult.OK; } catch (Exception ex) { WinFormsUtils.ShowError(this, ex); } }
private void ButtonOk_Click(object sender, EventArgs e) { if (TextBoxNewPin.Text != TextBoxConfirmNewPin.Text) { WinFormsUtils.ShowInfo(this, "New PIN entries do not match"); return; } try { _slot.InitPin(TextBoxNewPin.Text); WinFormsUtils.ShowInfo(this, "User PIN successfuly initialized"); DialogResult = DialogResult.OK; } catch (Exception ex) { WinFormsUtils.ShowError(this, ex); } }
private void ButtonOk_Click(object sender, EventArgs e) { if (TextBoxNewPin.Text != TextBoxConfirmNewPin.Text) { WinFormsUtils.ShowInfo(this, "New PIN entries do not match"); return; } try { _slot.ChangePin(TextBoxCurrentPin.Text, TextBoxNewPin.Text); WinFormsUtils.ShowInfo(this, (_userType == CKU.CKU_SO) ? "SO PIN successfuly changed" : "PIN successfuly changed"); DialogResult = DialogResult.OK; } catch (Exception ex) { WinFormsUtils.ShowError(this, ex); } }
private void ButtonOk_Click(object sender, EventArgs e) { try { byte[] pin = null; if (CheckBoxHexString.Checked) { try { pin = ConvertUtils.HexStringToBytes(TextBoxPin.Text); } catch (Exception) { WinFormsUtils.ShowError(this, "Unable to decode HEX string"); return; } } else { try { pin = ConvertUtils.Utf8StringToBytes(TextBoxPin.Text); } catch (Exception) { WinFormsUtils.ShowError(this, "Unable to decode UTF-8 string"); return; } } _slot.Login(_userType, pin); DialogResult = DialogResult.OK; } catch (Exception ex) { WinFormsUtils.ShowError(this, ex); } }