Supporters update.
[dcpomatic.git] / src / wx / make_chain_dialog.cc
1 /*
2     Copyright (C) 2014-2022 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
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.
10
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.
15
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/>.
18
19 */
20
21
22 #include "make_chain_dialog.h"
23 #include "static_text.h"
24 #include "lib/cross.h"
25 #include "lib/util.h"
26 #include <dcp/certificate_chain.h>
27 #include <boost/algorithm/string.hpp>
28
29
30 using std::make_shared;
31 using std::shared_ptr;
32 using std::string;
33
34
35 MakeChainDialog::MakeChainDialog (
36         wxWindow* parent,
37         shared_ptr<const dcp::CertificateChain> chain
38         )
39         : TableDialog (parent, _("Make certificate chain"), 2, 1, true)
40 {
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;
46
47         auto all = chain->root_to_leaf ();
48
49         if (all.size() >= 1) {
50                 /* Have a root */
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 ();
54         }
55
56         if (all.size() >= 2) {
57                 /* Have a leaf */
58                 leaf_common_name = chain->leaf().subject_common_name ();
59         }
60
61         if (all.size() >= 3) {
62                 /* Have an intermediate */
63                 dcp::CertificateChain::List::iterator i = all.begin ();
64                 ++i;
65                 intermediate_common_name = i->subject_common_name ();
66         }
67
68         wxTextValidator validator (wxFILTER_EXCLUDE_CHAR_LIST);
69         validator.SetCharExcludes (wxT ("/"));
70
71         if (boost::algorithm::starts_with (root_common_name, ".")) {
72                 root_common_name = root_common_name.substr (1);
73         }
74
75         if (boost::algorithm::starts_with (intermediate_common_name, ".")) {
76                 intermediate_common_name = intermediate_common_name.substr (1);
77         }
78
79         if (boost::algorithm::starts_with (leaf_common_name, "CS.")) {
80                 leaf_common_name = leaf_common_name.substr (3);
81         }
82
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));
87
88         add (_("Root common name"), true);
89
90         {
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
95                         );
96                 add (s);
97         }
98
99         add (_("Intermediate common name"), true);
100
101         {
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
106                         );
107                 add (s);
108         }
109
110         add (_("Leaf common name"), true);
111
112         {
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
117                         );
118                 add (s);
119         }
120
121         layout ();
122
123         _organisation->SetFocus ();
124 }
125
126
127 shared_ptr<dcp::CertificateChain>
128 MakeChainDialog::get () const
129 {
130         return make_shared<dcp::CertificateChain>(
131                 openssl_path(),
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())
138                 );
139 }