예제 #1
0
파일: geniutil.py 프로젝트: motine/Ohouse
def decode_urn(urn):
    """Returns authority, type and name associated with the URN as string.
    example call:
      authority, typ, name = decode_urn("urn:publicid:IDN+eict.de+user+motine")
    """
    urn = URN(urn=str(urn))
    return urn.getAuthority(), urn.getType(), urn.getName()
예제 #2
0
파일: cert_util.py 프로젝트: wvdemeer/C-BAS
def create_cert(urn,
                issuer_key=None,
                issuer_cert=None,
                ca=False,
                public_key=None,
                lifeDays=1825,
                email=None,
                uuidarg=None):
    '''Create a new certificate and return it and the associated keys.
    If issuer cert and key are given, they sign the certificate. Otherwise
    it is a self-signed certificate. 
    
    If ca then mark this as a CA certificate (can sign other certs).
    
    lifeDays is the lifetime of the supplied cert - default is 1825 (5 years).

    Certificate URN must be supplied.
    CN of the cert will be dotted notation authority.type.name from the URN.
    '''
    # Note the below throws a ValueError if it wasnt a valid URN
    c_urn = URN(urn=urn)
    dotted = '%s.%s.%s' % (c_urn.getAuthority(), c_urn.getType(),
                           c_urn.getName())

    subject = dict()
    subject['CN'] = dotted[:64]
    if email:
        subject['emailAddress'] = email

    uuidI = None
    if uuidarg:
        uuidO = None
        if isinstance(uuidarg, uuid.UUID):
            uuidO = uuidarg
        else:
            try:
                uuidO = uuid.UUID(uuidarg)
            except:
                try:
                    uuidO = uuid.UUID(int=uuidarg)
                except Exception, e:
                    try:
                        uuidO = uuid.UUID(int=int(uuidarg))
                    except Exception, e:
                        try:
                            uuidO = uuid.UUID(fields=uuidarg)
                        except:
                            try:
                                uuidO = uuid.UUID(bytes=uuidarg)
                            except:
                                try:
                                    uuidO = uuid.UUID(bytes_le=uuidarg)
                                except:
                                    pass
예제 #3
0
파일: cert_util.py 프로젝트: EICT/C-BAS
def create_cert(urn, issuer_key=None, issuer_cert=None, ca=False,
                public_key=None, lifeDays=1825, email=None, uuidarg=None, serial_number=0):
    '''Create a new certificate and return it and the associated keys.
    If issuer cert and key are given, they sign the certificate. Otherwise
    it is a self-signed certificate. 
    
    If ca then mark this as a CA certificate (can sign other certs).
    
    lifeDays is the lifetime of the supplied cert - default is 1825 (5 years).

    Certificate URN must be supplied.
    CN of the cert will be dotted notation authority.type.name from the URN.
    '''
    # Note the below throws a ValueError if it wasnt a valid URN
    c_urn = URN(urn=urn)
    dotted = '%s.%s.%s' % (c_urn.getAuthority(), c_urn.getType(), c_urn.getName())

    subject = dict()
    subject['CN'] = dotted[:64]
    if email:
        subject['emailAddress'] = email

    uuidI = None
    if uuidarg:
        uuidO = None
        if isinstance(uuidarg, uuid.UUID):
            uuidO = uuidarg
        else:
            try:
                uuidO = uuid.UUID(uuidarg)
            except:
                try:
                    uuidO = uuid.UUID(int=uuidarg)
                except Exception, e:
                    try:
                        uuidO = uuid.UUID(int=int(uuidarg))
                    except Exception, e:
                        try:
                            uuidO = uuid.UUID(fields=uuidarg)
                        except:
                            try:
                                uuidO = uuid.UUID(bytes=uuidarg)
                            except:
                                try:
                                    uuidO = uuid.UUID(bytes_le=uuidarg)
                                except:
                                    pass
예제 #4
0
파일: geniutil.py 프로젝트: motine/Ohouse
def encode_urn(authority, typ, name):
    """
    Returns a URN string with the given {authority}, {typ}e and {name}.
    {typ} shall be either of the following: authority, slice, user, sliver, (project or meybe others: http://groups.geni.net/geni/wiki/GeniApiIdentifiers#Type)
    example call:
      urn_str = encode_urn("eict.de", "user", "motine")
    """
    return URN(authority=authority, type=typ, name=name).urn_string()