From 63c6c12d69a4326e9cc76dd02625ee15252856d5 Mon Sep 17 00:00:00 2001 From: Pavel Zuna Date: Fri, 6 Nov 2009 11:04:00 +0100 Subject: Use File parameter for CSR in cert_request command plugin. --- ipalib/plugins/cert.py | 41 ++++++++++++----------------------------- 1 file changed, 12 insertions(+), 29 deletions(-) (limited to 'ipalib') diff --git a/ipalib/plugins/cert.py b/ipalib/plugins/cert.py index 0416730f8..48ceaa6d7 100644 --- a/ipalib/plugins/cert.py +++ b/ipalib/plugins/cert.py @@ -26,7 +26,7 @@ from ipalib import api, SkipPluginModule if api.env.enable_ra is not True: # In this case, abort loading this plugin module... raise SkipPluginModule(reason='env.enable_ra is not True') -from ipalib import Command, Str, Int, Bytes, Flag +from ipalib import Command, Str, Int, Bytes, Flag, File from ipalib import errors from ipalib.plugins.virtual import * from ipalib.plugins.service import split_principal @@ -83,7 +83,11 @@ class cert_request(VirtualCommand): Submit a certificate signing request. """ - takes_args = (Str('csr', validate_csr),) + takes_args = ( + File('csr', validate_csr, + cli_name='csr_file', + ), + ) operation="request certificate" takes_options = ( @@ -110,6 +114,12 @@ class cert_request(VirtualCommand): del kw['add'] service = None + # We just want the CSR bits, make sure there is nothing else + s = csr.find("-----BEGIN NEW CERTIFICATE REQUEST-----") + e = csr.find("-----END NEW CERTIFICATE REQUEST-----") + if s >= 0: + csr = csr[s+40:e] + # Can this user request certs? self.check_access() @@ -157,33 +167,6 @@ class cert_request(VirtualCommand): else: textui.print_plain('Failed to submit a certificate request.') - def run(self, *args, **options): - """ - Dispatch to forward() and execute() to do work locally and on the - server. - """ - if self.env.in_server: - return self.execute(*args, **options) - - # Client-side code - csr = args[0] - if csr[:7] == "file://": - file = csr[7:] - try: - f = open(file, "r") - csr = f.readlines() - f.close() - except IOError, err: - raise errors.ValidationError(name='csr', error=err[1]) - csr = "".join(csr) - # We just want the CSR bits, make sure there is nothing else - s = csr.find("-----BEGIN NEW CERTIFICATE REQUEST-----") - e = csr.find("-----END NEW CERTIFICATE REQUEST-----") - if s >= 0: - csr = csr[s+40:e] - csr = csr.decode('UTF-8') - return self.forward(csr, **options) - api.register(cert_request) -- cgit