<s> import os <EOL> import re <EOL> import shlex <EOL> import random <EOL> import subprocess <EOL> from burst . conf import CERT_DIR <EOL> from burst . exception import CertError <EOL> RE_DOMAIN = re . compile ( r'<STR_LIT>' ) <EOL> def extract_name ( cert ) : <EOL> if "<STR_LIT>" in cert and len ( cert [ "<STR_LIT>" ] ) >= <NUM_LIT:0> : <EOL> s = cert [ "<STR_LIT>" ] <EOL> for x in s : <EOL> if x [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] == "<STR_LIT>" : <EOL> return x [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] <EOL> def generate_serial ( ) : <EOL> return hex ( random . getrandbits ( <NUM_LIT:64> ) ) [ : - <NUM_LIT:1> ] <EOL> def get_key_file ( ) : <EOL> return os . path . join ( CERT_DIR , "<STR_LIT>" ) <EOL> def generate_ssl_cert ( domain ) : <EOL> if not RE_DOMAIN . match ( domain ) : <EOL> raise CertError ( "<STR_LIT>" ) <EOL> domain_cert = os . path . join ( CERT_DIR , "<STR_LIT>" , domain + "<STR_LIT>" ) <EOL> gen_req_cmd = "<STR_LIT>" "<STR_LIT>" . format ( CERT_DIR , domain ) <EOL> sign_req_cmd = "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" . format ( CERT_DIR , domain_cert , generate_serial ( ) , domain ) <EOL> if not os . path . exists ( domain_cert ) : <EOL> p_req = subprocess . Popen ( shlex . split ( gen_req_cmd ) , stdout = subprocess . PIPE , stderr = subprocess . PIPE ) <EOL> ss , se = p_req . communicate ( ) <EOL> if p_req . returncode : <EOL> raise CertError ( "<STR_LIT>" + se ) <EOL> p_sign = subprocess . Popen ( shlex . split ( sign_req_cmd ) , stdout = subprocess . PIPE , stderr = subprocess . PIPE ) <EOL> ss , se = p_sign . communicate ( ) <EOL> if p_sign . returncode : <EOL> raise CertError ( "<STR_LIT>" + se ) <EOL> os . remove ( os . path . join ( CERT_DIR , "<STR_LIT>" . format ( domain ) ) ) <EOL> return domain_cert <EOL> def generate_ca_cert ( ) : <EOL> gen_key_cmd = "<STR_LIT>" . format ( CERT_DIR ) <EOL> gen_ca_cert_cmd = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" . format ( CERT_DIR ) <EOL> p_key = subprocess . Popen ( shlex . split ( gen_key_cmd ) , stdout = subprocess . PIPE , stderr = subprocess . PIPE ) <EOL> ss , se = p_key . communicate ( ) <EOL> if p_key . returncode : <EOL> raise CertError ( "<STR_LIT>" + se ) <EOL> p_cert = subprocess . Popen ( shlex . split ( gen_ca_cert_cmd ) , stdout = subprocess . PIPE , stderr = subprocess . PIPE ) <EOL> ss , se = p_cert . communicate ( ) <EOL> if p_cert . returncode : <EOL> raise CertError ( "<STR_LIT>" + se ) <EOL> print "<STR_LIT>" + CERT_DIR + "<STR_LIT>" </s>
