Changeset 4fc2250 for fedd/fedd_util.py


Ignore:
Timestamp:
Sep 5, 2008 4:08:19 PM (16 years ago)
Author:
Ted Faber <faber@…>
Branches:
axis_example, compt_changes, info-ops, master, version-1.30, version-2.00, version-3.01, version-3.02
Children:
987aaa1
Parents:
bcbf543
Message:

add slice/experiment name

File:
1 edited

Legend:

Unmodified
Added
Removed
  • fedd/fedd_util.py

    rbcbf543 r4fc2250  
    11#!/usr/local/bin/python
    22
    3 import sys
     3import os, sys
     4import subprocess
     5import tempfile
    46
    57from M2Crypto import SSL, X509, EVP
     
    225227    else:
    226228        return element
     229
     230def generate_fedid(subj, bits=2048, trace=None, dir=None):
     231    """
     232    Create a new certificate and derive a fedid from it.
     233
     234    The fedid and the certificte are returned as a tuple.
     235    """
     236
     237    keypath = None
     238    certpath = None
     239    try:
     240        try:
     241            kd, keypath = tempfile.mkstemp(dir=dir, prefix="key",
     242                    suffix=".pem")
     243            cd, certpath = tempfile.mkstemp(dir=dir, prefix="cert",
     244                    suffix=".pem")
     245
     246            cmd = ["openssl", "req", "-text", "-newkey", "rsa:%d" % bits,
     247                    "-keyout", keypath,  "-nodes", "-subj", "/CN=%s" % subj,
     248                    "-x509", "-days", "30", "-out", certpath]
     249
     250            if trace:
     251                print >>trace, "calling %s" % " ".join(cmd)
     252                call_out = trace
     253            else:
     254                call_out = open("/dev/null", "w")
     255               
     256            rv = subprocess.call(cmd, stdout=call_out, stderr=call_out)
     257            if rv == 0:
     258                cert = ""
     259                for p in (certpath, keypath):
     260                    f = open(p)
     261                    for line in f:
     262                        cert += line
     263               
     264                fid = fedid(file=certpath)
     265                return (fid, cert)
     266            else:
     267                return None
     268        except IOError, e:
     269            raise e
     270    finally:
     271        if keypath: os.remove(keypath)
     272        if certpath: os.remove(certpath)
Note: See TracChangeset for help on using the changeset viewer.