2 Copyright (C) 2014-2022 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
6 DCP-o-matic is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 DCP-o-matic is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
22 #include "make_chain_dialog.h"
23 #include "static_text.h"
24 #include "lib/cross.h"
26 #include <dcp/certificate_chain.h>
27 #include <boost/algorithm/string.hpp>
30 using std::make_shared;
31 using std::shared_ptr;
35 MakeChainDialog::MakeChainDialog (
37 shared_ptr<const dcp::CertificateChain> chain
39 : TableDialog (parent, _("Make certificate chain"), 2, 1, true)
41 string subject_organization_name;
42 string subject_organizational_unit_name;
43 string root_common_name;
44 string intermediate_common_name;
45 string leaf_common_name;
47 auto all = chain->root_to_leaf ();
49 if (all.size() >= 1) {
51 subject_organization_name = chain->root().subject_organization_name ();
52 subject_organizational_unit_name = chain->root().subject_organizational_unit_name ();
53 root_common_name = chain->root().subject_common_name ();
56 if (all.size() >= 2) {
58 leaf_common_name = chain->leaf().subject_common_name ();
61 if (all.size() >= 3) {
62 /* Have an intermediate */
63 dcp::CertificateChain::List::iterator i = all.begin ();
65 intermediate_common_name = i->subject_common_name ();
68 wxTextValidator validator (wxFILTER_EXCLUDE_CHAR_LIST);
69 validator.SetCharExcludes (wxT ("/"));
71 if (boost::algorithm::starts_with (root_common_name, ".")) {
72 root_common_name = root_common_name.substr (1);
75 if (boost::algorithm::starts_with (intermediate_common_name, ".")) {
76 intermediate_common_name = intermediate_common_name.substr (1);
79 if (boost::algorithm::starts_with (leaf_common_name, "CS.")) {
80 leaf_common_name = leaf_common_name.substr (3);
83 add (_("Organisation"), true);
84 add (_organisation = new wxTextCtrl (this, wxID_ANY, std_to_wx(subject_organization_name), wxDefaultPosition, wxSize (480, -1), 0, validator));
85 add (_("Organisational unit"), true);
86 add (_organisational_unit = new wxTextCtrl (this, wxID_ANY, std_to_wx(subject_organizational_unit_name), wxDefaultPosition, wxDefaultSize, 0, validator));
88 add (_("Root common name"), true);
91 auto s = new wxBoxSizer (wxHORIZONTAL);
92 s->Add (new StaticText (this, wxT (".")), 0, wxALIGN_CENTER_VERTICAL);
93 s->Add (_root_common_name = new wxTextCtrl (
94 this, wxID_ANY, std_to_wx (root_common_name), wxDefaultPosition, wxDefaultSize, 0, validator), 1, wxALIGN_CENTER_VERTICAL
99 add (_("Intermediate common name"), true);
102 auto s = new wxBoxSizer (wxHORIZONTAL);
103 s->Add (new StaticText (this, wxT (".")), 0, wxALIGN_CENTER_VERTICAL);
104 s->Add (_intermediate_common_name = new wxTextCtrl (
105 this, wxID_ANY, std_to_wx (intermediate_common_name), wxDefaultPosition, wxDefaultSize, 0, validator), 1, wxALIGN_CENTER_VERTICAL
110 add (_("Leaf common name"), true);
113 auto s = new wxBoxSizer (wxHORIZONTAL);
114 s->Add (new StaticText (this, wxT ("CS.")), 0, wxALIGN_CENTER_VERTICAL);
115 s->Add (_leaf_common_name = new wxTextCtrl (
116 this, wxID_ANY, std_to_wx (leaf_common_name), wxDefaultPosition, wxDefaultSize, 0, validator), 1, wxALIGN_CENTER_VERTICAL
123 _organisation->SetFocus ();
127 shared_ptr<dcp::CertificateChain>
128 MakeChainDialog::get () const
130 return make_shared<dcp::CertificateChain>(
132 CERTIFICATE_VALIDITY_PERIOD,
133 wx_to_std(_organisation->GetValue()),
134 wx_to_std(_organisational_unit->GetValue()),
135 "." + wx_to_std(_root_common_name->GetValue()),
136 "." + wx_to_std(_intermediate_common_name->GetValue()),
137 "CS." + wx_to_std(_leaf_common_name->GetValue())