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/constants.h"
25 #include "lib/cross.h"
27 #include <dcp/certificate_chain.h>
28 #include <boost/algorithm/string.hpp>
31 using std::make_shared;
32 using std::shared_ptr;
36 MakeChainDialog::MakeChainDialog (
38 shared_ptr<const dcp::CertificateChain> chain
40 : TableDialog (parent, _("Make certificate chain"), 2, 1, true)
42 string subject_organization_name;
43 string subject_organizational_unit_name;
44 string root_common_name;
45 string intermediate_common_name;
46 string leaf_common_name;
48 auto all = chain->root_to_leaf ();
50 if (all.size() >= 1) {
52 subject_organization_name = chain->root().subject_organization_name ();
53 subject_organizational_unit_name = chain->root().subject_organizational_unit_name ();
54 root_common_name = chain->root().subject_common_name ();
57 if (all.size() >= 2) {
59 leaf_common_name = chain->leaf().subject_common_name ();
62 if (all.size() >= 3) {
63 /* Have an intermediate */
64 dcp::CertificateChain::List::iterator i = all.begin ();
66 intermediate_common_name = i->subject_common_name ();
69 wxTextValidator validator (wxFILTER_EXCLUDE_CHAR_LIST);
70 validator.SetCharExcludes (wxT ("/"));
72 if (boost::algorithm::starts_with (root_common_name, ".")) {
73 root_common_name = root_common_name.substr (1);
76 if (boost::algorithm::starts_with (intermediate_common_name, ".")) {
77 intermediate_common_name = intermediate_common_name.substr (1);
80 if (boost::algorithm::starts_with (leaf_common_name, "CS.")) {
81 leaf_common_name = leaf_common_name.substr (3);
84 add (_("Organisation"), true);
85 add (_organisation = new wxTextCtrl (this, wxID_ANY, std_to_wx(subject_organization_name), wxDefaultPosition, wxSize (480, -1), 0, validator));
86 add (_("Organisational unit"), true);
87 add (_organisational_unit = new wxTextCtrl (this, wxID_ANY, std_to_wx(subject_organizational_unit_name), wxDefaultPosition, wxDefaultSize, 0, validator));
89 add (_("Root common name"), true);
92 auto s = new wxBoxSizer (wxHORIZONTAL);
93 s->Add (new StaticText (this, wxT (".")), 0, wxALIGN_CENTER_VERTICAL);
94 s->Add (_root_common_name = new wxTextCtrl (
95 this, wxID_ANY, std_to_wx (root_common_name), wxDefaultPosition, wxDefaultSize, 0, validator), 1, wxALIGN_CENTER_VERTICAL
100 add (_("Intermediate common name"), true);
103 auto s = new wxBoxSizer (wxHORIZONTAL);
104 s->Add (new StaticText (this, wxT (".")), 0, wxALIGN_CENTER_VERTICAL);
105 s->Add (_intermediate_common_name = new wxTextCtrl (
106 this, wxID_ANY, std_to_wx (intermediate_common_name), wxDefaultPosition, wxDefaultSize, 0, validator), 1, wxALIGN_CENTER_VERTICAL
111 add (_("Leaf common name"), true);
114 auto s = new wxBoxSizer (wxHORIZONTAL);
115 s->Add (new StaticText (this, wxT ("CS.")), 0, wxALIGN_CENTER_VERTICAL);
116 s->Add (_leaf_common_name = new wxTextCtrl (
117 this, wxID_ANY, std_to_wx (leaf_common_name), wxDefaultPosition, wxDefaultSize, 0, validator), 1, wxALIGN_CENTER_VERTICAL
124 _organisation->SetFocus ();
128 shared_ptr<dcp::CertificateChain>
129 MakeChainDialog::get () const
131 return make_shared<dcp::CertificateChain>(
133 CERTIFICATE_VALIDITY_PERIOD,
134 wx_to_std(_organisation->GetValue()),
135 wx_to_std(_organisational_unit->GetValue()),
136 "." + wx_to_std(_root_common_name->GetValue()),
137 "." + wx_to_std(_intermediate_common_name->GetValue()),
138 "CS." + wx_to_std(_leaf_common_name->GetValue())