コード例 #1
0
        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);
            }
        }
コード例 #2
0
        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);
            }
        }
コード例 #3
0
        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);
            }
        }
コード例 #4
0
ファイル: CsrDialog.cs プロジェクト: sluckywhh/Pkcs11Admin
        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);
            }
        }
コード例 #5
0
ファイル: WaitDialog.cs プロジェクト: TSFO27/Pkcs11Admin
        private static void ShowInstance(Form owner)
        {
            lock (_lockObject)
            {
                if (_instance != null)
                {
                    throw new Exception("Dialog instance already exists");
                }

                _instance = new WaitDialog();
                _instance.Show(owner);
                _instance.Owner.Enabled = false;
            }
        }
コード例 #6
0
ファイル: WaitDialog.cs プロジェクト: TSFO27/Pkcs11Admin
        private static void CloseInstance()
        {
            lock (_lockObject)
            {
                if (_instance == null)
                {
                    throw new Exception("Dialog instance does not exist");
                }

                _instance.Owner.Enabled = true;
                _instance.Close();
                _instance.Dispose();
                _instance = null;
            }
        }
コード例 #7
0
ファイル: InitTokenDialog.cs プロジェクト: TSFO27/Pkcs11Admin
        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);
            }
        }