diff options
| author | Carl Hetherington <cth@carlh.net> | 2015-09-03 14:17:00 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2015-09-14 10:21:11 +0100 |
| commit | e33376edb08202bb8eaf2e182a0dc1f2126e0525 (patch) | |
| tree | f300f12d12292fd03b0ca284427824d93d3e4716 /src | |
| parent | b0834f33e972a6e7b0d234d09e420007943a136d (diff) | |
Add export button for certificates.
Diffstat (limited to 'src')
| -rw-r--r-- | src/wx/config_dialog.cc | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/wx/config_dialog.cc b/src/wx/config_dialog.cc index 4633552a6..81fffbbbc 100644 --- a/src/wx/config_dialog.cc +++ b/src/wx/config_dialog.cc @@ -650,6 +650,8 @@ public: s->Add (_add_certificate, 0, wxTOP | wxBOTTOM, DCPOMATIC_BUTTON_STACK_GAP); _remove_certificate = new wxButton (this, wxID_ANY, _("Remove")); s->Add (_remove_certificate, 0, wxTOP | wxBOTTOM, DCPOMATIC_BUTTON_STACK_GAP); + _export_certificate = new wxButton (this, wxID_ANY, _("Export")); + s->Add (_export_certificate, 0, wxTOP | wxBOTTOM, DCPOMATIC_BUTTON_STACK_GAP); certificates_sizer->Add (s, 0, wxLEFT, DCPOMATIC_SIZER_X_GAP); } @@ -675,6 +677,7 @@ public: _add_certificate->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&CertificateChainEditor::add_certificate, this)); _remove_certificate->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&CertificateChainEditor::remove_certificate, this)); + _export_certificate->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&CertificateChainEditor::export_certificate, this)); _certificates->Bind (wxEVT_COMMAND_LIST_ITEM_SELECTED, boost::bind (&CertificateChainEditor::update_sensitivity, this)); _certificates->Bind (wxEVT_COMMAND_LIST_ITEM_DESELECTED, boost::bind (&CertificateChainEditor::update_sensitivity, this)); _remake_certificates->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&CertificateChainEditor::remake_certificates, this)); @@ -733,6 +736,37 @@ private: update_sensitivity (); } + void export_certificate () + { + int i = _certificates->GetNextItem (-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); + if (i == -1) { + return; + } + + wxFileDialog* d = new wxFileDialog ( + this, _("Select Certificate File"), wxEmptyString, wxEmptyString, wxT ("PEM files (*.pem)|*.pem"), + wxFD_SAVE | wxFD_OVERWRITE_PROMPT + ); + + dcp::CertificateChain::List all = _chain->root_to_leaf (); + dcp::CertificateChain::List::iterator j = all.begin (); + for (int k = 0; k < i; ++k) { + ++j; + } + + if (d->ShowModal () == wxID_OK) { + FILE* f = fopen_boost (wx_to_std (d->GetPath ()), "w"); + if (!f) { + throw OpenFileError (wx_to_std (d->GetPath ())); + } + + string const s = j->certificate (true); + fwrite (s.c_str(), 1, s.length(), f); + fclose (f); + } + d->Destroy (); + } + void update_certificate_list () { _certificates->DeleteAllItems (); @@ -800,6 +834,7 @@ private: void update_sensitivity () { _remove_certificate->Enable (_certificates->GetNextItem (-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED) != -1); + _export_certificate->Enable (_certificates->GetNextItem (-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED) != -1); } void update_private_key () @@ -835,6 +870,7 @@ private: wxListCtrl* _certificates; wxButton* _add_certificate; + wxButton* _export_certificate; wxButton* _remove_certificate; wxButton* _remake_certificates; wxStaticText* _private_key; |
