2 Copyright (C) 2017-2019 Carl Hetherington <cth@carlh.net>
4 This file is part of libdcp.
6 libdcp 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 libdcp 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 libdcp. If not, see <http://www.gnu.org/licenses/>.
19 In addition, as a special exception, the copyright holders give
20 permission to link the code of portions of this program with the
21 OpenSSL library under certain conditions as described in each
22 individual source file, and distribute linked combinations
25 You must obey the GNU General Public License in all respects
26 for all of the code used other than OpenSSL. If you modify
27 file(s) with this exception, you may extend this exception to your
28 version of the file(s), but you are not obligated to do so. If you
29 do not wish to do so, delete this exception statement from your
30 version. If you delete this exception statement from all source
31 files in the program, then also delete it here.
34 #include "encrypted_kdm.h"
35 #include "decrypted_kdm.h"
37 #include "exceptions.h"
38 #include "certificate_chain.h"
39 #include <boost/foreach.hpp>
45 using boost::optional;
50 cerr << "Syntax: " << n << " [OPTION] <KDM>\n"
51 << " -h, --help show this help\n"
52 << " -p, --private-key private key file\n";
56 tm_to_string (struct tm t)
59 snprintf (buffer, 64, "%02d/%02d/%02d %02d:%02d:%02d", t.tm_mday, t.tm_mon + 1, t.tm_year + 1900, t.tm_hour, t.tm_min, t.tm_sec);
64 main (int argc, char* argv[])
69 optional<boost::filesystem::path> private_key_file;
73 struct option long_options[] = {
74 { "help", no_argument, 0, 'h' },
75 { "private-key", required_argument, 0, 'p'},
79 int c = getopt_long (argc, argv, "hp:", long_options, &option_index);
90 private_key_file = optarg;
100 boost::filesystem::path kdm_file = argv[optind];
102 dcp::EncryptedKDM enc_kdm (dcp::file_to_string (kdm_file));
104 if (enc_kdm.annotation_text()) {
105 cout << "Annotation: " << enc_kdm.annotation_text().get() << "\n";
107 cout << "Content title: " << enc_kdm.content_title_text() << "\n";
108 cout << "CPL id: " << enc_kdm.cpl_id() << "\n";
109 cout << "Recipient: " << enc_kdm.recipient_x509_subject_name() << "\n";
110 cout << "Not valid before: " << enc_kdm.not_valid_before().as_string() << "\n";
111 cout << "Not valid after: " << enc_kdm.not_valid_after().as_string() << "\n";
113 cout << "Signer chain:\n";
114 dcp::CertificateChain signer = enc_kdm.signer_certificate_chain ();
115 BOOST_FOREACH (dcp::Certificate const & i, signer.root_to_leaf()) {
116 cout << "\tCertificate:\n";
117 cout << "\t\tSubject: " << i.subject() << "\n";
118 cout << "\t\tSubject common name: " << i.subject_common_name() << "\n";
119 cout << "\t\tSubject organization name: " << i.subject_organization_name() << "\n";
120 cout << "\t\tSubject organizational unit name: " << i.subject_organizational_unit_name() << "\n";
121 cout << "\t\tNot before: " << tm_to_string(i.not_before()) << "\n";
122 cout << "\t\tNot after: " << tm_to_string(i.not_after()) << "\n";
123 if (i.has_utf8_strings()) {
124 cout << "\t\tUSES INCORRECT (UTF8) STRING ENCODING\n";
128 if (private_key_file) {
130 dcp::DecryptedKDM dec_kdm (enc_kdm, dcp::file_to_string (private_key_file.get()));
132 BOOST_FOREACH (dcp::DecryptedKDMKey i, dec_kdm.keys ()) {
134 cout << "\tID: " << i.id() << "\n";
135 cout << "\tStandard: " << (i.standard() == dcp::SMPTE ? "SMPTE" : "Interop") << "\n";
136 cout << "\tCPL ID: " << i.cpl_id() << "\n";
138 cout << "\tType: " << i.type().get() << "\n";
140 cout << "\tKey: " << i.key().hex() << "\n";
142 } catch (dcp::KDMDecryptionError& e) {
143 cerr << e.what() << "\n";
150 catch (std::exception& e)
152 cerr << "Error: " << e.what() << "\n";