~corey.bryant/charms/trusty/keystone/python-six

« back to all changes in this revision

Viewing changes to hooks/keystone_ssl.py

  • Committer: James Page
  • Date: 2014-03-27 10:54:38 UTC
  • mfrom: (55.1.22 keystone)
  • mto: (52.4.7 keystone)
  • mto: This revision was merged to the branch mainline in revision 60.
  • Revision ID: james.page@canonical.com-20140327105438-oid8czi9ud51iut1
Merge ssl-everywhere branch (may break stuff)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/python
2
2
 
 
3
import base64
3
4
import os
4
5
import shutil
5
6
import subprocess
6
7
import tarfile
7
8
import tempfile
 
9
import zipfile
8
10
 
9
11
CA_EXPIRY = '365'
10
12
ORG_NAME = 'Ubuntu'
113
115
        if not os.path.exists(d):
114
116
            print 'Creating %s.' % d
115
117
            os.mkdir(d)
116
 
    os.chmod(os.path.join(ca_dir, 'private'), 0710)
 
118
    os.chmod(os.path.join(ca_dir, 'private'), 0o710)
117
119
 
118
120
    if not os.path.isfile(os.path.join(ca_dir, 'serial')):
119
121
        with open(os.path.join(ca_dir, 'serial'), 'wb') as out:
161
163
def sign_int_csr(ca_dir, csr, common_name):
162
164
    print 'Signing certificate request %s.' % csr
163
165
    crt = os.path.join(ca_dir, 'certs',
164
 
                        '%s.crt' % os.path.basename(csr).split('.')[0])
 
166
                       '%s.crt' % os.path.basename(csr).split('.')[0])
165
167
    subj = '/O=%s/OU=%s/CN=%s' % (ORG_NAME, ORG_UNIT, common_name)
166
168
    cmd = ['openssl', 'ca', '-batch', '-config',
167
169
           os.path.join(ca_dir, 'ca.cnf'),
238
240
 
239
241
 
240
242
class JujuCA(object):
 
243
 
241
244
    def __init__(self, name, ca_dir, root_ca_dir, user, group):
242
245
        root_crt, root_key = init_root_ca(root_ca_dir,
243
246
                                          '%s Certificate Authority' % name)
288
291
                key = open(key, 'r').read()
289
292
            except:
290
293
                print 'Could not load ssl private key for %s from %s' %\
291
 
                     (common_name, key)
 
294
                    (common_name, key)
292
295
                exit(1)
293
296
            return crt, key
294
297
        crt, key = self._create_certificate(common_name, common_name)