Reload existing certificate chain's details when creating a new one.
authorCarl Hetherington <cth@carlh.net>
Sun, 12 Jul 2015 19:48:04 +0000 (20:48 +0100)
committerCarl Hetherington <cth@carlh.net>
Sun, 12 Jul 2015 19:48:04 +0000 (20:48 +0100)
src/wx/config_dialog.cc
src/wx/make_signer_chain_dialog.cc
src/wx/make_signer_chain_dialog.h

index f744ca83faa4a33b8ff682d9fc5d4bbf1ea2215f..86ad2dbe17c5d8d53b87d8c0aab0281030192ccb 100644 (file)
@@ -731,7 +731,25 @@ private:
 
        void remake_certificates ()
        {
-               MakeSignerChainDialog* d = new MakeSignerChainDialog (_panel);
+               dcp::CertificateChain chain = Config::instance()->signer()->certificates ();
+
+               string intermediate_common_name;
+               if (chain.root_to_leaf().size() >= 3) {
+                       dcp::CertificateChain::List all = chain.root_to_leaf ();
+                       dcp::CertificateChain::List::iterator i = all.begin ();
+                       ++i;
+                       intermediate_common_name = i->subject_common_name ();
+               }
+
+               MakeSignerChainDialog* d = new MakeSignerChainDialog (
+                       _panel,
+                       chain.root().subject_organization_name (),
+                       chain.root().subject_organizational_unit_name (),
+                       chain.root().subject_common_name (),
+                       intermediate_common_name,
+                       chain.leaf().subject_common_name ()
+                       );
+
                if (d->ShowModal () == wxID_OK) {
                        _signer.reset (
                                new dcp::Signer (
index 8df208934372512b9a7f20adf6dcc676b5b3c49b..df8b198e3f53d3092685cdc2f1c322838f95b7eb 100644 (file)
 */
 
 #include "make_signer_chain_dialog.h"
+#include <boost/algorithm/string.hpp>
 
-MakeSignerChainDialog::MakeSignerChainDialog (wxWindow* parent)
+using std::string;
+
+MakeSignerChainDialog::MakeSignerChainDialog (
+       wxWindow* parent,
+       string organisation,
+       string organisational_unit_name,
+       string root_common_name,
+       string intermediate_common_name,
+       string leaf_common_name
+       )
        : TableDialog (parent, _("Make certificate chain"), 2, true)
 {
        wxTextValidator validator (wxFILTER_EXCLUDE_CHAR_LIST);
        validator.SetCharExcludes (wxT ("/"));
 
+       if (boost::algorithm::starts_with (root_common_name, ".")) {
+               root_common_name = root_common_name.substr (1);
+       }
+
+       if (boost::algorithm::starts_with (intermediate_common_name, ".")) {
+               intermediate_common_name = intermediate_common_name.substr (1);
+       }
+
+       if (boost::algorithm::starts_with (leaf_common_name, "CS.")) {
+               leaf_common_name = leaf_common_name.substr (3);
+       }
+
        add (_("Organisation"), true);
-       add (_organisation = new wxTextCtrl (this, wxID_ANY, wxT (""), wxDefaultPosition, wxDefaultSize, 0, validator));
+       add (_organisation = new wxTextCtrl (this, wxID_ANY, std_to_wx (organisation), wxDefaultPosition, wxDefaultSize, 0, validator));
        add (_("Organisational unit"), true);
-       add (_organisational_unit = new wxTextCtrl (this, wxID_ANY, wxT (""), wxDefaultPosition, wxDefaultSize, 0, validator));
+       add (_organisational_unit = new wxTextCtrl (this, wxID_ANY, std_to_wx (organisational_unit_name), wxDefaultPosition, wxDefaultSize, 0, validator));
 
        add (_("Root common name"), true);
 
@@ -36,7 +58,7 @@ MakeSignerChainDialog::MakeSignerChainDialog (wxWindow* parent)
                wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
                s->Add (new wxStaticText (this, wxID_ANY, wxT (".")), 0, wxALIGN_CENTER_VERTICAL);
                s->Add (_root_common_name = new wxTextCtrl (
-                               this, wxID_ANY, wxT (""), wxDefaultPosition, wxDefaultSize, 0, validator), 1, wxALIGN_CENTER_VERTICAL
+                               this, wxID_ANY, std_to_wx (root_common_name), wxDefaultPosition, wxDefaultSize, 0, validator), 1, wxALIGN_CENTER_VERTICAL
                        );
                add (s);
        }
@@ -47,7 +69,7 @@ MakeSignerChainDialog::MakeSignerChainDialog (wxWindow* parent)
                wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
                s->Add (new wxStaticText (this, wxID_ANY, wxT (".")), 0, wxALIGN_CENTER_VERTICAL);
                s->Add (_intermediate_common_name = new wxTextCtrl (
-                               this, wxID_ANY, wxT (""), wxDefaultPosition, wxDefaultSize, 0, validator), 1, wxALIGN_CENTER_VERTICAL
+                               this, wxID_ANY, std_to_wx (intermediate_common_name), wxDefaultPosition, wxDefaultSize, 0, validator), 1, wxALIGN_CENTER_VERTICAL
                        );
                add (s);
        }
@@ -58,7 +80,7 @@ MakeSignerChainDialog::MakeSignerChainDialog (wxWindow* parent)
                wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
                s->Add (new wxStaticText (this, wxID_ANY, wxT ("CS.")), 0, wxALIGN_CENTER_VERTICAL);
                s->Add (_leaf_common_name = new wxTextCtrl (
-                               this, wxID_ANY, wxT (""), wxDefaultPosition, wxDefaultSize, 0, validator), 1, wxALIGN_CENTER_VERTICAL
+                               this, wxID_ANY, std_to_wx (leaf_common_name), wxDefaultPosition, wxDefaultSize, 0, validator), 1, wxALIGN_CENTER_VERTICAL
                        );
                add (s);
        }
index d05b4381f831b627ba726612c5362535c1c43c6c..0ebffeb26f4c44d1124222044b3bddc0f7601830 100644 (file)
 class MakeSignerChainDialog : public TableDialog
 {
 public:
-       MakeSignerChainDialog (wxWindow* parent);
+       MakeSignerChainDialog (
+               wxWindow* parent,
+               std::string organisation,
+               std::string organisational_unit_name,
+               std::string root_common_name,
+               std::string intermediate_common_name,
+               std::string leaf_common_name
+               );
 
        std::string organisation () const {
                return wx_to_std (_organisation->GetValue ());