~citrix-openstack/nova/xenapi

« back to all changes in this revision

Viewing changes to nova/crypto.py

  • Committer: rlane at wikimedia
  • Date: 2011-03-03 23:04:11 UTC
  • mfrom: (408.9.363 nova)
  • mto: (408.9.366 nova)
  • mto: This revision was merged to the branch mainline in revision 449.
  • Revision ID: rlane@wikimedia.org-20110303230411-qx4qndimfyr1w1fx
MergeĀ fromĀ trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
105
105
 
106
106
    tmpdir = tempfile.mkdtemp()
107
107
    keyfile = os.path.join(tmpdir, 'temp')
108
 
    utils.execute('ssh-keygen -q -b %d -N "" -f %s' % (bits, keyfile))
109
 
    (out, err) = utils.execute('ssh-keygen -q -l -f %s.pub' % (keyfile))
 
108
    utils.execute('ssh-keygen', '-q', '-b', bits, '-N', '',
 
109
                  '-f', keyfile)
 
110
    (out, err) = utils.execute('ssh-keygen', '-q', '-l', '-f',
 
111
                               '%s.pub' % (keyfile))
110
112
    fingerprint = out.split(' ')[1]
111
113
    private_key = open(keyfile).read()
112
114
    public_key = open(keyfile + '.pub').read()
118
120
    # bio = M2Crypto.BIO.MemoryBuffer()
119
121
    # key.save_pub_key_bio(bio)
120
122
    # public_key = bio.read()
121
 
    # public_key, err = execute('ssh-keygen -y -f /dev/stdin', private_key)
 
123
    # public_key, err = execute('ssh-keygen', '-y', '-f',
 
124
    #                           '/dev/stdin', private_key)
122
125
 
123
126
    return (private_key, public_key, fingerprint)
124
127
 
143
146
    start = os.getcwd()
144
147
    os.chdir(ca_folder(project_id))
145
148
    # NOTE(vish): potential race condition here
146
 
    utils.execute("openssl ca -config ./openssl.cnf -revoke '%s'" % file_name)
147
 
    utils.execute("openssl ca -gencrl -config ./openssl.cnf -out '%s'" %
148
 
                  FLAGS.crl_file)
 
149
    utils.execute('openssl', 'ca', '-config', './openssl.cnf', '-revoke',
 
150
                  file_name)
 
151
    utils.execute('openssl', 'ca', '-gencrl', '-config', './openssl.cnf',
 
152
                  '-out', FLAGS.crl_file)
149
153
    os.chdir(start)
150
154
 
151
155
 
193
197
    tmpdir = tempfile.mkdtemp()
194
198
    keyfile = os.path.abspath(os.path.join(tmpdir, 'temp.key'))
195
199
    csrfile = os.path.join(tmpdir, 'temp.csr')
196
 
    utils.execute("openssl genrsa -out %s %s" % (keyfile, bits))
197
 
    utils.execute("openssl req -new -key %s -out %s -batch -subj %s" %
198
 
                  (keyfile, csrfile, subject))
 
200
    utils.execute('openssl', 'genrsa', '-out', keyfile, str(bits))
 
201
    utils.execute('openssl', 'req', '-new', '-key', keyfile, '-out', csrfile,
 
202
                  '-batch', '-subj', subject)
199
203
    private_key = open(keyfile).read()
200
204
    csr = open(csrfile).read()
201
205
    shutil.rmtree(tmpdir)
212
216
    if not os.path.exists(ca_path(project_id)):
213
217
        start = os.getcwd()
214
218
        os.chdir(ca_folder())
215
 
        utils.execute("sh geninter.sh %s %s" %
216
 
                      (project_id, _project_cert_subject(project_id)))
 
219
        utils.execute('sh', 'geninter.sh', project_id,
 
220
                      _project_cert_subject(project_id))
217
221
        os.chdir(start)
218
222
 
219
223
 
228
232
    start = os.getcwd()
229
233
    os.chdir(ca_folder())
230
234
    # TODO(vish): the shell scripts could all be done in python
231
 
    utils.execute("sh genvpn.sh %s %s" %
232
 
                  (project_id, _vpn_cert_subject(project_id)))
 
235
    utils.execute('sh', 'genvpn.sh',
 
236
                  project_id, _vpn_cert_subject(project_id))
233
237
    with open(csr_fn, "r") as csrfile:
234
238
        csr_text = csrfile.read()
235
239
    (serial, signed_csr) = sign_csr(csr_text, project_id)
259
263
    start = os.getcwd()
260
264
    # Change working dir to CA
261
265
    os.chdir(ca_folder)
262
 
    utils.execute("openssl ca -batch -out %s -config "
263
 
                  "./openssl.cnf -infiles %s" % (outbound, inbound))
264
 
    out, _err = utils.execute("openssl x509 -in %s -serial -noout" % outbound)
 
266
    utils.execute('openssl', 'ca', '-batch', '-out', outbound, '-config',
 
267
                  './openssl.cnf', '-infiles', inbound)
 
268
    out, _err = utils.execute('openssl', 'x509', '-in', outbound,
 
269
                              '-serial', '-noout')
265
270
    serial = out.rpartition("=")[2]
266
271
    os.chdir(start)
267
272
    with open(outbound, "r") as crtfile: