diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2016-07-12 17:25:28 +0300 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2016-07-14 17:56:54 +0300 |
commit | 7ea82c5013ab3c3d44b4b85cf767559e7019854f (patch) | |
tree | 24369f953efa5b3aa6b8b44937150f195f8f23e0 /bpkg/rep-info.cxx | |
parent | db5ac510d317fc3d9c2c881257e8c6a25851ea1c (diff) |
Add --cert-* rep-info command options
Diffstat (limited to 'bpkg/rep-info.cxx')
-rw-r--r-- | bpkg/rep-info.cxx | 81 |
1 files changed, 80 insertions, 1 deletions
diff --git a/bpkg/rep-info.cxx b/bpkg/rep-info.cxx index 9cad4fd..765bc70 100644 --- a/bpkg/rep-info.cxx +++ b/bpkg/rep-info.cxx @@ -6,6 +6,8 @@ #include <iostream> // cout +#include <butl/sha256> // sha256_to_fingerprint() + #include <bpkg/manifest> #include <bpkg/manifest-serializer> @@ -94,7 +96,15 @@ namespace bpkg // Now print. // - bool all (!o.name () && !o.repositories () && !o.packages ()); + bool cert_info (o.cert_fingerprint () || + o.cert_name () || + o.cert_organization () || + o.cert_email ()); + + bool all (!o.name () && + !o.repositories () && + !o.packages () && + !cert_info); try { @@ -103,6 +113,75 @@ namespace bpkg if (all || o.name ()) cout << rl.canonical_name () << " " << rl << endl; + // Certificate. + // + if (all || cert_info) + { + if (cert_pem) + { + // Repository is signed. If we got the repository certificate as the + // result of authentication then use it for printing as well. + // Otherwise parse it's PEM representation. + // + if (cert == nullptr) + cert = parse_certificate (o, *cert_pem, rl); + else + assert (!cert->dummy ()); + } + else if (cert != nullptr) + { + // Reset the dummy certificate pointer that we got as a result of + // the unsigned repository authentication. + // + assert (cert->dummy ()); + cert = nullptr; + } + + if (all) + { + // Print in the human-friendly format (nothing for an unsigned + // repository). + // + if (cert != nullptr) + cout << "CN=" << cert->name << "/O=" << cert->organization << + "/" << cert->email << endl + << sha256_to_fingerprint (cert->fingerprint) << endl; + } + else + { + // Print in the structured format if any of --cert-* options are + // specified. Print empty lines for an unsigned repository. + // + if (o.cert_fingerprint ()) + { + if (cert != nullptr) + cout << sha256_to_fingerprint (cert->fingerprint); + cout << endl; + } + + if (o.cert_name ()) + { + if (cert != nullptr) + cout << "name:" << cert->name; + cout << endl; + } + + if (o.cert_organization ()) + { + if (cert != nullptr) + cout << cert->organization; + cout << endl; + } + + if (o.cert_email ()) + { + if (cert != nullptr) + cout << cert->email; + cout << endl; + } + } + } + // Repositories. // if (all || o.repositories ()) |