Formatting fix.
[libdcp.git] / tools / dcpkdm.cc
index 1e35803f4edabe0bd375362c09e5c15dc914d6f0..9fb35d128507b8c1e3a43c7e39c92597d5ee312d 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2017 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2017-2019 Carl Hetherington <cth@carlh.net>
 
     This file is part of libdcp.
 
@@ -35,6 +35,7 @@
 #include "decrypted_kdm.h"
 #include "util.h"
 #include "exceptions.h"
+#include "certificate_chain.h"
 #include <boost/foreach.hpp>
 #include <getopt.h>
 
@@ -46,11 +47,19 @@ using boost::optional;
 static void
 help (string n)
 {
-       cerr << "Syntax: " << n << " [OPTION] <KDM>]\n"
+       cerr << "Syntax: " << n << " [OPTION] <KDM>\n"
             << "  -h, --help         show this help\n"
             << "  -p, --private-key  private key file\n";
 }
 
+static string
+tm_to_string (struct tm t)
+{
+       char buffer[64];
+       snprintf (buffer, 64, "%02d/%02d/%02d %02d:%02d:%02d", t.tm_mday, t.tm_mon, (t.tm_year + 1900), t.tm_hour, t.tm_min, t.tm_sec);
+       return buffer;
+}
+
 int
 main (int argc, char* argv[])
 {
@@ -90,11 +99,28 @@ main (int argc, char* argv[])
        dcp::EncryptedKDM enc_kdm (dcp::file_to_string (kdm_file));
 
        if (enc_kdm.annotation_text()) {
-               cout << "Annotation:    " << enc_kdm.annotation_text().get() << "\n";
+               cout << "Annotation:       " << enc_kdm.annotation_text().get() << "\n";
+       }
+       cout << "Content title:    " << enc_kdm.content_title_text() << "\n";
+       cout << "CPL id:           " << enc_kdm.cpl_id() << "\n";
+       cout << "Recipient:        " << enc_kdm.recipient_x509_subject_name() << "\n";
+       cout << "Not valid before: " << enc_kdm.not_valid_before().as_string() << "\n";
+       cout << "Not valid after:  " << enc_kdm.not_valid_after().as_string() << "\n";
+
+       cout << "Signer chain:\n";
+       dcp::CertificateChain signer = enc_kdm.signer_certificate_chain ();
+       BOOST_FOREACH (dcp::Certificate const & i, signer.root_to_leaf()) {
+               cout << "\tCertificate:\n";
+               cout << "\t\tSubject: " << i.subject() << "\n";
+               cout << "\t\tSubject common name: " << i.subject_common_name() << "\n";
+               cout << "\t\tSubject organization name: " << i.subject_organization_name() << "\n";
+               cout << "\t\tSubject organizational unit name: " << i.subject_organizational_unit_name() << "\n";
+               cout << "\t\tNot before: " << tm_to_string(i.not_before()) << "\n";
+               cout << "\t\tNot after:  " << tm_to_string(i.not_after()) << "\n";
+               if (i.has_utf8_strings()) {
+                       cout << "\t\tUSES INCORRECT (UTF8) STRING ENCODING\n";
+               }
        }
-       cout << "Content title: " << enc_kdm.content_title_text() << "\n";
-       cout << "CPL id:        " << enc_kdm.cpl_id() << "\n";
-       cout << "Recipient:     " << enc_kdm.recipient_x509_subject_name() << "\n";
 
        if (private_key_file) {
                try {
@@ -104,6 +130,7 @@ main (int argc, char* argv[])
                                cout << "\n";
                                cout << "\tID:       " << i.id() << "\n";
                                cout << "\tStandard: " << (i.standard() == dcp::SMPTE ? "SMPTE" : "Interop") << "\n";
+                               cout << "\tCPL ID:   " << i.cpl_id() << "\n";
                                if (i.type()) {
                                        cout << "\tType:     " << i.type().get() << "\n";
                                }