<s> """<STR_LIT>""" <EOL> from __future__ import absolute_import <EOL> from __future__ import print_function <EOL> from __future__ import division <EOL> import re <EOL> import pytz <EOL> from datetime import datetime <EOL> from OpenSSL import crypto <EOL> _FILETYPES = { <EOL> "<STR_LIT>" : crypto . FILETYPE_PEM , <EOL> "<STR_LIT>" : crypto . FILETYPE_PEM , <EOL> "<STR_LIT>" : crypto . FILETYPE_ASN1 , <EOL> "<STR_LIT>" : crypto . FILETYPE_ASN1 , <EOL> } <EOL> VERSION_1 = <NUM_LIT:1> <EOL> VERSION_2 = <NUM_LIT:2> <EOL> VERSION_3 = <NUM_LIT:3> <EOL> class CertError ( Exception ) : <EOL> pass <EOL> class ExtensionEncodingError ( CertError ) : <EOL> pass <EOL> class CertificateRequest ( object ) : <EOL> def __init__ ( self , country = None , state = None , locality = None , <EOL> organization = None , organization_unit = None , <EOL> name = None , email = None , digest = "<STR_LIT>" , filename = None ) : <EOL> if filename is None : <EOL> req = crypto . X509Req ( ) <EOL> subject = req . get_subject ( ) <EOL> if country : <EOL> subject . C = country <EOL> if state : <EOL> subject . ST = state <EOL> if locality : <EOL> subject . L = locality <EOL> if organization : <EOL> subject . O = organization <EOL> if organization_unit : <EOL> subject . OU = organization_unit <EOL> if name : <EOL> subject . CN = name <EOL> if email : <EOL> subject . emailAddress = email <EOL> else : <EOL> ftype , text = get_type_and_text ( filename ) <EOL> req = crypto . load_certificate_request ( ftype , text ) <EOL> self . _req = req <EOL> def __str__ ( self ) : <EOL> return "<STR_LIT>" . format ( self . _get_subject ( ) ) <EOL> def _get_version ( self ) : <EOL> return self . _req . get_version ( ) <EOL> def _set_version ( self , ver ) : <EOL> self . _req . set_version ( ver ) <EOL> version = property ( _get_version , _set_version ) <EOL> def _get_subject ( self ) : <EOL> return DistinguishedName ( _dn = self . _req . get_subject ( ) ) <EOL> subject = property ( _get_subject ) <EOL> def _get_pubkey ( self ) : <EOL> return PrivateKey ( _key = self . _req . get_pubkey ( ) ) <EOL> def _set_pubkey ( self , pkey ) : <EOL> if isinstance ( pkey , PrivateKey ) : <EOL> pkey = pkey . _key <EOL> self . _req . set_pubkey ( pkey ) <EOL> pubkey = property ( _get_pubkey , _set_pubkey ) <EOL> def _set_extensions ( self , extlist ) : <EOL> nx = [ ] <EOL> for ext in extlist : <EOL> if isinstance ( ext , Extension ) : <EOL> nx . append ( ext . _ext ) <EOL> elif isinstance ( ext , crypto . X509ExtensionType ) : <EOL> nx . append ( ext ) <EOL> self . _req . add_extensions ( nx ) <EOL> self . _req . set_version ( VERSION_3 ) <EOL> extensions = property ( None , _set_extensions ) <EOL> def sign ( self , pkey , digest = "<STR_LIT>" ) : <EOL> return self . _req . sign ( pkey . _key , digest ) <EOL> def verify ( self , pubkey ) : <EOL> return self . _req . verify ( pubkey . _key ) <EOL> def emit ( self , fo , filetype = "<STR_LIT>" ) : <EOL> fo . write ( crypto . dump_certificate_request ( _FILETYPES [ filetype ] , <EOL> self . _req ) ) <EOL> def get_pem ( self ) : <EOL> return crypto . dump_certificate_request ( crypto . FILETYPE_PEM , self . _req ) <EOL> class PrivateKey ( object ) : <EOL> def __init__ ( self , filename = None , text = None , passphrase = None , <EOL> filetype = "<STR_LIT>" , bits = <NUM_LIT> , _key = None ) : <EOL> self . __passphrase = passphrase <EOL> if _key is not None : <EOL> key = _key <EOL> else : <EOL> ftype = _FILETYPES [ filetype ] <EOL> if filename is not None : <EOL> ftype , text = get_type_and_text ( filename ) <EOL> if text is not None : <EOL> if passphrase is not None : <EOL> key = crypto . load_privatekey ( ftype , text , passphrase ) <EOL> else : <EOL> key = crypto . load_privatekey ( ftype , text ) <EOL> else : <EOL> key = crypto . PKey ( ) <EOL> key . generate_key ( crypto . TYPE_RSA , bits ) <EOL> key . check ( ) <EOL> self . _key = key <EOL> bits = property ( lambda self : self . _key . bits ( ) ) <EOL> type = property ( lambda self : { <NUM_LIT:6> : "<STR_LIT>" , <NUM_LIT> : "<STR_LIT>" } [ self . _key . type ( ) ] ) <EOL> def check ( self ) : <EOL> self . _key . check ( ) <EOL> def _set_pw ( self , pw ) : <EOL> self . __passphrase = str ( pw ) <EOL> def _del_pw ( self ) : <EOL> self . __passphrase = None <EOL> passphrase = property ( None , _set_pw , _del_pw , <EOL> doc = "<STR_LIT>" ) <EOL> def encrypt ( self , passphrase ) : <EOL> self . _key . check ( ) <EOL> text = crypto . dump_privatekey ( crypto . FILETYPE_PEM , self . _key , <EOL> '<STR_LIT>' , passphrase ) <EOL> return text <EOL> def emit ( self , fo , filetype = "<STR_LIT>" ) : <EOL> if self . __passphrase is not None : <EOL> text = self . encrypt ( self . __passphrase ) <EOL> else : <EOL> text = crypto . dump_privatekey ( crypto . FILETYPE_PEM , self . _key ) <EOL> fo . write ( text ) <EOL> def get_pem ( self ) : <EOL> return crypto . dump_privatekey ( crypto . FILETYPE_PEM , self . _key ) <EOL> class Certificate ( object ) : <EOL> def __init__ ( self , filename = None , _cert = None ) : <EOL> if _cert is not None : <EOL> cert = _cert <EOL> elif filename is not None : <EOL> ftype , text = get_type_and_text ( filename ) <EOL> cert = crypto . load_certificate ( ftype , text ) <EOL> else : <EOL> cert = crypto . X509 ( ) <EOL> self . _cert = cert <EOL> def _get_subject ( self ) : <EOL> return DistinguishedName ( _dn = self . _cert . get_subject ( ) ) <EOL> def _set_subject ( self , subj ) : <EOL> self . _cert . set_subject ( subj ) <EOL> subject = property ( _get_subject , _set_subject ) <EOL> def _get_issuer ( self ) : <EOL> return DistinguishedName ( _dn = self . _cert . get_issuer ( ) ) <EOL> def _set_issuer ( self , issuer ) : <EOL> self . _cert . set_issuer ( issuer ) <EOL> issuer = property ( _get_issuer , _set_issuer ) <EOL> def _get_serial ( self ) : <EOL> return self . _cert . get_serial_number ( ) <EOL> def _set_serial ( self , num ) : <EOL> return self . _cert . set_serial_number ( num ) <EOL> serial = property ( _get_serial , _set_serial ) <EOL> def _get_not_before ( self ) : <EOL> return get_datetime ( self . _cert . get_notBefore ( ) ) <EOL> def _set_not_before ( self , when ) : <EOL> self . _cert . set_notBefore ( get_asn1time ( when ) ) <EOL> notbefore = property ( _get_not_before , _set_not_before ) <EOL> def _get_not_after ( self ) : <EOL> return get_datetime ( self . _cert . get_notAfter ( ) ) <EOL> def _set_not_after ( self , when ) : <EOL> self . _cert . set_notAfter ( get_asn1time ( when ) ) <EOL> notafter = property ( _get_not_after , _set_not_after ) <EOL> def _get_extensions ( self ) : <EOL> count = self . _cert . get_extension_count ( ) <EOL> i = <NUM_LIT:0> <EOL> while i < count : <EOL> yield Extension ( _ext = self . _cert . get_extension ( i ) ) <EOL> i += <NUM_LIT:1> <EOL> def _set_extensions ( self , extlist ) : <EOL> nx = [ ] <EOL> for ext in extlist : <EOL> if isinstance ( ext , Extension ) : <EOL> nx . append ( ext . _ext ) <EOL> elif isinstance ( ext , crypto . X509ExtensionType ) : <EOL> nx . append ( ext ) <EOL> self . _req . set_version ( VERSION_3 ) <EOL> self . _cert . add_extensions ( nx ) <EOL> extensions = property ( _get_extensions , _set_extensions ) <EOL> def _get_version ( self ) : <EOL> return self . _cert . get_version ( ) <EOL> def _set_version ( self , ver ) : <EOL> return self . _cert . set_version ( ver ) <EOL> version = property ( _get_version , _set_version ) <EOL> def _get_pubkey ( self ) : <EOL> return PrivateKey ( _key = self . _cert . get_pubkey ( ) ) <EOL> def _set_pubkey ( self , pubkey ) : <EOL> if isinstance ( pubkey , PrivateKey ) : <EOL> pubkey = pubkey . _key <EOL> self . _cert . set_pubkey ( pubkey ) <EOL> pubkey = property ( _get_pubkey , _set_pubkey ) <EOL> expired = property ( lambda self : bool ( self . _cert . has_expired ( ) ) ) <EOL> signature_algorithm = property ( <EOL> lambda self : self . _cert . get_signature_algorithm ( ) ) <EOL> subject_name_hash = property ( lambda self : self . _cert . subject_name_hash ( ) ) <EOL> def digest ( self , digest_name ) : <EOL> return self . _cert . digest ( digest_name ) <EOL> def sign ( self , pkey , digest_name ) : <EOL> if isinstance ( pkey , PrivateKey ) : <EOL> pkey = pkey . _key <EOL> return self . _cert . sign ( pkey , digest_name ) <EOL> def emit ( self , fo , filetype = "<STR_LIT>" ) : <EOL> fo . write ( crypto . dump_certificate ( _FILETYPES [ filetype ] , self . _cert ) ) <EOL> def get_pem ( self ) : <EOL> return crypto . dump_certificate ( crypto . FILETYPE_PEM , self . _cert ) <EOL> class DistinguishedName ( object ) : <EOL> def __init__ ( self , country = None , state = None , locality = None , <EOL> organization = None , organization_unit = None , <EOL> name = None , email = None , _dn = None ) : <EOL> if _dn is None : <EOL> dn = crypto . X509Req ( ) . get_subject ( ) <EOL> if country : <EOL> dn . C = country <EOL> if state : <EOL> dn . ST = state <EOL> if locality : <EOL> dn . L = locality <EOL> if organization : <EOL> dn . O = organization <EOL> if organization_unit : <EOL> dn . OU = organization_unit <EOL> if name : <EOL> dn . CN = name <EOL> if email : <EOL> dn . emailAddress = email <EOL> else : <EOL> dn = _dn <EOL> self . __dict__ [ "<STR_LIT>" ] = dn <EOL> der = property ( lambda self : self . _dn . der ( ) ) <EOL> hash = property ( lambda self : self . _dn . hash ( ) ) <EOL> componenents = property ( lambda self : self . _dn . get_components ( ) ) <EOL> def __getattr__ ( self , name ) : <EOL> return getattr ( self . __dict__ [ "<STR_LIT>" ] , name ) <EOL> def __setattr__ ( self , name , value ) : <EOL> return setattr ( self . _dn , name , value ) <EOL> def __str__ ( self ) : <EOL> s = [ "<STR_LIT>" ] <EOL> for pn in ( "<STR_LIT:C>" , "<STR_LIT>" , "<STR_LIT:L>" , "<STR_LIT:O>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) : <EOL> val = getattr ( self . _dn , pn , None ) <EOL> if val : <EOL> s . append ( "<STR_LIT>" . format ( pn , val ) ) <EOL> return "<STR_LIT:/>" . join ( s ) <EOL> class Extension ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , typename = None , critical = None , value = None , <EOL> subject = None , issuer = None , _ext = None ) : <EOL> if _ext is not None : <EOL> ext = _ext <EOL> elif subject is None and issuer is None : <EOL> ext = crypto . X509Extension ( typename , critical , value ) <EOL> elif subject is not None and issuer is None : <EOL> subject = subject . _cert <EOL> ext = crypto . X509Extension ( typename , critical , value , <EOL> subject = subject ) <EOL> elif subject is None and issuer is not None : <EOL> issuer = issuer . _cert <EOL> ext = crypto . X509Extension ( typename , critical , value , <EOL> issuer = issuer ) <EOL> elif subject is not None and issuer is not None : <EOL> issuer = issuer . _cert <EOL> ext = crypto . X509Extension ( typename , critical , value , <EOL> subject = subject , issuer = issuer ) <EOL> self . _ext = ext <EOL> critical = property ( lambda self : self . _ext . get_critical ( ) ) <EOL> short_name = property ( lambda self : self . _ext . get_short_name ( ) ) <EOL> der = property ( lambda self : self . _ext . get_data ( ) ) <EOL> value = property ( lambda self : str ( self . _ext ) ) <EOL> def __str__ ( self ) : <EOL> ext = self . _ext <EOL> return "<STR_LIT>" . format ( <EOL> ext . get_short_name ( ) , <EOL> "<STR_LIT>" if self . _ext . get_critical ( ) else "<STR_LIT>" , <EOL> str ( ext ) . strip ( ) ) <EOL> def _der_ ( self ) : <EOL> return self . _ext . get_data ( ) <EOL> class BasicConstraints ( Extension ) : <EOL> def __init__ ( self , is_ca = False , critical = False , pathlen = None ) : <EOL> if is_ca : <EOL> value = "<STR_LIT>" <EOL> else : <EOL> value = "<STR_LIT>" <EOL> if pathlen is not None : <EOL> value += "<STR_LIT>" . format ( pathlen ) <EOL> super ( BasicConstraints , self ) . __init__ ( "<STR_LIT>" , critical , <EOL> value ) <EOL> class KeyUsage ( Extension ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , values , critical = False ) : <EOL> assert len ( values ) > <NUM_LIT:0> , "<STR_LIT>" <EOL> super ( KeyUsage , self ) . __init__ ( "<STR_LIT>" , critical , "<STR_LIT:U+002CU+0020>" . join ( values ) ) <EOL> class ExtendedKeyUsage ( Extension ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , values , critical = False ) : <EOL> assert len ( values ) > <NUM_LIT:0> , "<STR_LIT>" <EOL> super ( ExtendedKeyUsage , self ) . __init__ ( "<STR_LIT>" , critical , <EOL> "<STR_LIT:U+002CU+0020>" . join ( values ) ) <EOL> class AuthorityKeyIdentifier ( Extension ) : <EOL> def __init__ ( self , issuer , critical = False ) : <EOL> super ( AuthorityKeyIdentifier , self ) . __init__ ( <EOL> "<STR_LIT>" , critical , "<STR_LIT>" , <EOL> issuer = issuer ) <EOL> class SubjectKeyIdentifier ( Extension ) : <EOL> def __init__ ( self , subject , critical = False ) : <EOL> super ( SubjectKeyIdentifier , self ) . __init__ ( <EOL> "<STR_LIT>" , critical , "<STR_LIT>" , subject = subject ) <EOL> class SubjectAltName ( Extension ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , values , critical = False ) : <EOL> assert len ( values ) > <NUM_LIT:0> , "<STR_LIT>" <EOL> new = [ ] <EOL> for value in values : <EOL> pre = guess_altname_prefix ( value ) <EOL> new . append ( "<STR_LIT>" . format ( pre , value ) ) <EOL> super ( SubjectAltName , self ) . __init__ ( "<STR_LIT>" , critical , <EOL> "<STR_LIT:U+002C>" . join ( new ) ) <EOL> class IssuerAltName ( Extension ) : <EOL> def __init__ ( self , values , critical = False ) : <EOL> assert len ( values ) > <NUM_LIT:0> , "<STR_LIT>" <EOL> new = [ ] <EOL> for value in values : <EOL> if isinstance ( value , Certificate ) : <EOL> super ( IssuerAltName , self ) . __init__ ( <EOL> "<STR_LIT>" , critical , "<STR_LIT>" , issuer = value ) <EOL> break <EOL> elif isinstance ( value , crypto . X509 ) : <EOL> super ( IssuerAltName , self ) . __init__ ( <EOL> "<STR_LIT>" , critical , "<STR_LIT>" , <EOL> issuer = Certificate ( _cert = value ) ) <EOL> break <EOL> pre = guess_altname_prefix ( value ) <EOL> new . append ( "<STR_LIT>" . format ( pre , value ) ) <EOL> else : <EOL> super ( IssuerAltName , self ) . __init__ ( "<STR_LIT>" , critical , <EOL> "<STR_LIT:U+002C>" . join ( new ) ) <EOL> class AuthorityInfoAccess ( Extension ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , ocsp = None , caissuers = None , critical = False ) : <EOL> new = [ ] <EOL> if ocsp is not None : <EOL> pre = guess_altname_prefix ( ocsp ) <EOL> new . append ( "<STR_LIT>" . format ( pre , ocsp ) ) <EOL> if caissuers is not None : <EOL> pre = guess_altname_prefix ( caissuers ) <EOL> new . append ( "<STR_LIT>" . format ( pre , caissuers ) ) <EOL> if not new : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> super ( AuthorityInfoAccess , self ) . __init__ ( <EOL> "<STR_LIT>" , critical , "<STR_LIT:U+002C>" . join ( new ) ) <EOL> class CrlDistributionPoints ( Extension ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , values , critical = False ) : <EOL> assert len ( values ) > <NUM_LIT:0> , "<STR_LIT>" <EOL> new = [ ] <EOL> for value in values : <EOL> pre = guess_altname_prefix ( value ) <EOL> new . append ( "<STR_LIT>" . format ( pre , value ) ) <EOL> super ( CrlDistributionPoints , self ) . __init__ ( "<STR_LIT>" , <EOL> critical , "<STR_LIT:U+002C>" . join ( new ) ) <EOL> class PolicyConstraints ( Extension ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , requireexplicitpolicy = None , inhibitpolicymapping = None , <EOL> critical = False ) : <EOL> new = [ ] <EOL> if requireexplicitpolicy is not None : <EOL> new . append ( "<STR_LIT>" . format ( <EOL> requireexplicitpolicy ) ) <EOL> if inhibitpolicymapping is not None : <EOL> new . append ( "<STR_LIT>" . format ( <EOL> inhibitpolicymapping ) ) <EOL> if not new : <EOL> raise ValueError ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> super ( PolicyConstraints , self ) . __init__ ( "<STR_LIT>" , critical , <EOL> "<STR_LIT:U+002C>" . join ( new ) ) <EOL> class InhibitAnyPolicy ( Extension ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , value , critical = False ) : <EOL> super ( InhibitAnyPolicy , self ) . __init__ ( "<STR_LIT>" , critical , <EOL> str ( value ) ) <EOL> class NameConstraints ( Extension ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , permitted = None , excluded = None , critical = False ) : <EOL> new = [ ] <EOL> if permitted is not None : <EOL> pre = guess_altname_prefix ( permitted ) <EOL> new . append ( "<STR_LIT>" . format ( pre , permitted ) ) <EOL> if excluded is not None : <EOL> pre = guess_altname_prefix ( excluded ) <EOL> new . append ( "<STR_LIT>" . format ( pre , excluded ) ) <EOL> super ( NameConstraints , self ) . __init__ ( "<STR_LIT>" , critical , <EOL> "<STR_LIT:U+002C>" . join ( new ) ) <EOL> class OCSPNoCheck ( Extension ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , critical = False ) : <EOL> super ( OCSPNoCheck , self ) . __init__ ( "<STR_LIT>" , critical , "<STR_LIT>" ) <EOL> def guess_altname_prefix ( string ) : <EOL> if "<STR_LIT:@>" in string : <EOL> return "<STR_LIT:email>" <EOL> elif "<STR_LIT>" in string : <EOL> return "<STR_LIT>" <EOL> elif "<STR_LIT>" in string : <EOL> return "<STR_LIT>" <EOL> elif re . search ( br"<STR_LIT>" , string , re . I ) : <EOL> return "<STR_LIT>" <EOL> elif re . search ( br"<STR_LIT>" , string ) : <EOL> return "<STR_LIT>" <EOL> else : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> def create_rsa_keypair ( bits = <NUM_LIT> ) : <EOL> pkey = crypto . PKey ( ) <EOL> pkey . generate_key ( crypto . TYPE_RSA , bits ) <EOL> return PrivateKey ( _key = pkey ) <EOL> def create_dsa_keypair ( bits = <NUM_LIT> ) : <EOL> pkey = crypto . PKey ( ) <EOL> pkey . generate_key ( crypto . TYPE_DSA , bits ) <EOL> return PrivateKey ( _key = pkey ) <EOL> def now_utc ( ) : <EOL> return datetime . now ( pytz . utc ) <EOL> def get_asn1time ( when ) : <EOL> """<STR_LIT>""" <EOL> if when is None : <EOL> when = now_utc ( ) <EOL> if isinstance ( when , str ) : <EOL> import iso8601 <EOL> when = iso8601 . parse_date ( when ) <EOL> assert type ( when ) is datetime <EOL> return when . strftime ( "<STR_LIT>" ) <EOL> def get_datetime ( when ) : <EOL> """<STR_LIT>""" <EOL> dt = datetime . strptime ( when , "<STR_LIT>" ) <EOL> return dt . replace ( tzinfo = pytz . utc ) <EOL> def get_type_and_text ( filename ) : <EOL> ftype = _FILETYPES [ filename [ - <NUM_LIT:3> : ] ] <EOL> text = open ( filename ) . read ( ) <EOL> return ftype , text <EOL> def der ( obj ) : <EOL> try : <EOL> return obj . _der_ ( ) <EOL> except AttributeError : <EOL> raise ExtensionEncodingError ( <EOL> "<STR_LIT>" . format ( obj ) ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> import sys <EOL> from pycopia import autodebug <EOL> req = CertificateRequest ( country = "<STR_LIT>" , <EOL> state = "<STR_LIT>" , <EOL> locality = "<STR_LIT>" , <EOL> organization = "<STR_LIT>" , <EOL> name = "<STR_LIT>" ) <EOL> req . emit ( sys . stdout ) <EOL> pw = PrivateKey ( ) <EOL> ektext = pw . encrypt ( "<STR_LIT>" ) <EOL> print ( repr ( ektext ) ) <EOL> npw = PrivateKey ( text = ektext , passphrase = "<STR_LIT>" ) <EOL> cert = Certificate ( ) <EOL> dt = now_utc ( ) <EOL> print ( get_asn1time ( now_utc ( ) . isoformat ( ) ) ) <EOL> cert = Certificate ( filename = "<STR_LIT>" ) <EOL> print ( cert . subject ) <EOL> print ( cert . notafter ) <EOL> for gext in cert . extensions : <EOL> print ( gext ) <EOL> print ( '<STR_LIT>' ) <EOL> cert = Certificate ( filename = "<STR_LIT>" ) <EOL> print ( cert . subject ) <EOL> print ( cert . issuer ) <EOL> print ( cert . notafter ) <EOL> print ( "<STR_LIT>" ) <EOL> rawext = crypto . X509Extension ( "<STR_LIT>" , False , <EOL> "<STR_LIT>" ) <EOL> ext = Extension ( _ext = rawext ) <EOL> print ( ext ) <EOL> print ( KeyUsage ( [ "<STR_LIT>" , "<STR_LIT>" ] ) ) <EOL> print ( BasicConstraints ( is_ca = True ) ) <EOL> print ( BasicConstraints ( is_ca = True , critical = True ) ) <EOL> print ( BasicConstraints ( is_ca = True , critical = True , pathlen = <NUM_LIT:0> ) ) <EOL> print ( BasicConstraints ( is_ca = False ) ) <EOL> print ( ExtendedKeyUsage ( [ "<STR_LIT>" , "<STR_LIT>" ] ) ) <EOL> print ( SubjectKeyIdentifier ( cert ) ) <EOL> print ( SubjectAltName ( [ "<STR_LIT>" , "<STR_LIT>" ] ) ) <EOL> print ( SubjectAltName ( [ "<STR_LIT>" ] ) ) <EOL> print ( SubjectAltName ( [ "<STR_LIT>" ] ) ) <EOL> print ( SubjectAltName ( [ "<STR_LIT>" , "<STR_LIT>" ] ) ) <EOL> print ( IssuerAltName ( [ cert ] ) ) <EOL> print ( IssuerAltName ( [ "<STR_LIT>" ] ) ) <EOL> print ( AuthorityInfoAccess ( ocsp = "<STR_LIT>" ) ) <EOL> print ( AuthorityInfoAccess ( caissuers = "<STR_LIT>" ) ) <EOL> print ( AuthorityInfoAccess ( ocsp = "<STR_LIT>" , <EOL> caissuers = "<STR_LIT>" ) ) <EOL> print ( CrlDistributionPoints ( [ "<STR_LIT>" ] ) ) <EOL> print ( PolicyConstraints ( requireexplicitpolicy = <NUM_LIT:3> ) ) <EOL> print ( PolicyConstraints ( inhibitpolicymapping = <NUM_LIT:3> ) ) <EOL> print ( InhibitAnyPolicy ( <NUM_LIT:3> ) ) <EOL> print ( NameConstraints ( permitted = "<STR_LIT>" ) ) <EOL> print ( NameConstraints ( excluded = "<STR_LIT>" ) ) <EOL> print ( OCSPNoCheck ( ) ) <EOL> print ( OCSPNoCheck ( critical = True ) ) <EOL> dn = DistinguishedName ( country = "<STR_LIT>" , state = "<STR_LIT>" , <EOL> organization = "<STR_LIT>" ) <EOL> print ( dn ) <EOL> req = CertificateRequest ( <EOL> country = "<STR_LIT>" , <EOL> state = "<STR_LIT>" , <EOL> locality = "<STR_LIT>" , <EOL> organization = "<STR_LIT>" , <EOL> organization_unit = "<STR_LIT>" , <EOL> name = "<STR_LIT>" , <EOL> ) <EOL> req . extensions = [ <EOL> BasicConstraints ( is_ca = False ) , <EOL> KeyUsage ( [ "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" ] ) , <EOL> SubjectAltName ( [ "<STR_LIT>" , "<STR_LIT>" ] ) , <EOL> ] <EOL> req . pubkey = npw <EOL> req . sign ( npw ) <EOL> with open ( "<STR_LIT>" , "<STR_LIT>" ) as fo : <EOL> req . emit ( fo ) <EOL> with open ( "<STR_LIT>" , "<STR_LIT>" ) as fo : <EOL> npw . emit ( fo ) </s>
