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()
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
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