cert: include certificate chain in cert command output

Include the full certificate chain in the output of cert-request, cert-show
and cert-find if --chain or --all is specified.

If output file is specified in the CLI together with --chain, the full
certificate chain is written to the file.

https://pagure.io/freeipa/issue/6547

Reviewed-By: David Kupka <dkupka@redhat.com>
This commit is contained in:
Jan Cholasta authored and David Kupka committed 2017-03-14 12:58:45 +01:00
1 parent c60d9c9744
commit 8ed891cb61
4 files changed
+56 -12

No files matched your search

+4 -1
View File
@@ -57,7 +57,10 @@ class CertRetrieveOverride(MethodOverride):
result = super(CertRetrieveOverride, self).forward(*args, **options)
if certificate_out is not None:
certs = [result['result']['certificate']]
if options.get('chain', False):
certs = result['result']['certificate_chain']
else:
certs = [result['result']['certificate']]
certs = (x509.normalize_certificate(cert) for cert in certs)
certs = (x509.make_pem(base64.b64encode(cert)) for cert in certs)
with open(certificate_out, 'w') as f: