use the specified digest for the CSR
[stack/cam.git] / cam / openssl_wrap.py
1 import logging
2 import os
3 import subprocess
4
5 log = logging.getLogger(__name__)
6
7
8 class CommandError(Exception):
9     pass
10
11
12 def run(*args, **env_vars):
13     cmd = ['openssl']
14     cmd.extend(args)
15     env = dict(os.environ)
16     env.update(env_vars)
17     log.debug('executing "%s"' % ' '.join(cmd))
18     pipe = subprocess.Popen(cmd, env=env, stdout=subprocess.PIPE)
19     stdout, _ = pipe.communicate()
20     if pipe.returncode != 0:
21         raise CommandError('openssl exited with status %d' % (
22                 pipe.returncode,))
23     return stdout
24
25
26 def run_with_config(caroot, config_file, *args):
27     cmd = args[0]
28     args = args[1:]
29     caroot = os.path.abspath(caroot)
30     return run(cmd, '-config', config_file, '-batch', *args, CAROOT=caroot)