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/constants.h"
25 #include "lib/cross.h"
26 #include "lib/util.h"
27 #include <dcp/certificate_chain.h>
28 #include <boost/algorithm/string.hpp>
29
30
31 using std::make_shared;
32 using std::shared_ptr;
33 using std::string;
34
35
36 MakeChainDialog::MakeChainDialog (
37         wxWindow* parent,
38         shared_ptr<const dcp::CertificateChain> chain
39         )
40         : TableDialog (parent, _("Make certificate chain"), 2, 1, true)
41 {
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;
47
48         auto all = chain->root_to_leaf ();
49
50         if (all.size() >= 1) {
51                 /* Have a root */
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 ();
55         }
56
57         if (all.size() >= 2) {
58                 /* Have a leaf */
59                 leaf_common_name = chain->leaf().subject_common_name ();
60         }
61
62         if (all.size() >= 3) {
63                 /* Have an intermediate */
64                 dcp::CertificateChain::List::iterator i = all.begin ();
65                 ++i;
66                 intermediate_common_name = i->subject_common_name ();
67         }
68
69         wxTextValidator validator (wxFILTER_EXCLUDE_CHAR_LIST);
70         validator.SetCharExcludes (wxT ("/"));
71
72         if (boost::algorithm::starts_with (root_common_name, ".")) {
73                 root_common_name = root_common_name.substr (1);
74         }
75
76         if (boost::algorithm::starts_with (intermediate_common_name, ".")) {
77                 intermediate_common_name = intermediate_common_name.substr (1);
78         }
79
80         if (boost::algorithm::starts_with (leaf_common_name, "CS.")) {
81                 leaf_common_name = leaf_common_name.substr (3);
82         }
83
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));
88
89         add (_("Root common name"), true);
90
91         {
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
96                         );
97                 add (s);
98         }
99
100         add (_("Intermediate common name"), true);
101
102         {
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
107                         );
108                 add (s);
109         }
110
111         add (_("Leaf common name"), true);
112
113         {
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
118                         );
119                 add (s);
120         }
121
122         layout ();
123
124         _organisation->SetFocus ();
125 }
126
127
128 shared_ptr<dcp::CertificateChain>
129 MakeChainDialog::get () const
130 {
131         return make_shared<dcp::CertificateChain>(
132                 openssl_path(),
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())
139                 );
140 }