diff options
author | Rob Crittenden <rcritten@redhat.com> | 2011-02-11 18:12:02 -0500 |
---|---|---|
committer | Rob Crittenden <rcritten@redhat.com> | 2011-02-14 16:43:48 -0500 |
commit | dab452442d1425332369d00d95be4cd1b460407f (patch) | |
tree | 3740676d970c6877f0956f77381f595fe607fa11 /ipalib | |
parent | 0e4f0528cfbf771ad9b52d329c2ad26720ee4e66 (diff) | |
download | freeipa-dab452442d1425332369d00d95be4cd1b460407f.tar.gz freeipa-dab452442d1425332369d00d95be4cd1b460407f.tar.xz freeipa-dab452442d1425332369d00d95be4cd1b460407f.zip |
The --out option wasn't working at all with cert-show.
Also fix some related problems in write_certificate(), handle
either a DER or base64-formatted incoming certificate and don't
explode if the filename is None.
ticket 954
Diffstat (limited to 'ipalib')
-rw-r--r-- | ipalib/plugins/cert.py | 9 | ||||
-rw-r--r-- | ipalib/plugins/service.py | 8 |
2 files changed, 13 insertions, 4 deletions
diff --git a/ipalib/plugins/cert.py b/ipalib/plugins/cert.py index ec77fea6..f5ffd158 100644 --- a/ipalib/plugins/cert.py +++ b/ipalib/plugins/cert.py @@ -418,13 +418,15 @@ class cert_show(VirtualCommand): takes_options = ( Str('out?', + label=_('Output filename'), doc=_('file to store certificate in'), + exclude='webui', ), ) operation="retrieve certificate" - def execute(self, serial_number): + def execute(self, serial_number, **options): hostname = None try: self.check_access() @@ -455,9 +457,8 @@ class cert_show(VirtualCommand): if 'out' in options: check_writable_file(options['out']) result = super(cert_show, self).forward(*keys, **options) - if 'usercertificate' in result['result']: - write_certificate(result['result']['usercertificate'][0], options['out']) - result['summary'] = _('Certificate stored in file \'%(file)s\'') % dict(file=options['out']) + if 'certificate' in result['result']: + write_certificate(result['result']['certificate'], options['out']) return result else: raise errors.NoCertificateError(entry=keys[-1]) diff --git a/ipalib/plugins/service.py b/ipalib/plugins/service.py index cab1f7b2..970ed043 100644 --- a/ipalib/plugins/service.py +++ b/ipalib/plugins/service.py @@ -231,6 +231,8 @@ def check_writable_file(filename): Determine if the file is writable. If the file doesn't exist then open the file to test writability. """ + if filename is None: + raise errors.FileError(reason='Filename is empty') try: if file_exists(filename): if not os.access(filename, os.W_OK): @@ -255,6 +257,12 @@ def write_certificate(cert, filename): """ Check to see if the certificate should be written to a file and do so. """ + if cert and util.isvalid_base64(cert): + try: + cert = base64.b64decode(cert) + except Exception, e: + raise errors.Base64DecodeError(reason=str(e)) + try: fp = open(filename, 'w') fp.write(make_pem(base64.b64encode(cert))) |