ó
ŠwÛjc           @   s+  d  Z  d d l Z d d l Z d d l Z d d l Z d d l Td Z e j j e j j	 e
 ƒ ƒ Z e d d d d „ Z d	 Z d
 „  Z d „  Z e d k r'e j e ƒ e d ƒ \ Z Z e d d ƒ � Z e j e ƒ Wd QXe d d ƒ � Z e j e ƒ Wd QXd GHe d d d d d d d d d g	 ƒ e d d d d d d d d d g	 ƒ e d d ƒ �! Z e j e ƒ e j e ƒ Wd QXe d d ƒ � Z e j e ƒ Wd QXe ƒ  e d ƒ \ Z Z e d d ƒ �! Z e j e ƒ e j e ƒ Wd QXe d e ƒ \ Z Z e d d ƒ �! Z e j e ƒ e j e ƒ Wd QXe d e ƒ \ Z Z e d  d ƒ �! Z e j e ƒ e j e ƒ Wd QXd! d" d# d$ d% d& d' d( d) g	 Z e d* d+ d, j e ƒ ƒ\ Z Z e d- d ƒ �! Z e j e ƒ e j e ƒ Wd QXe ƒ  d. GHe d d/ d d d0 d1 d2 g ƒ n  d S(3   sO   Make the custom certificate and private key files used by test_ssl
and friends.iÿÿÿÿN(   t   *s�  
    [req]
    distinguished_name     = req_distinguished_name
    x509_extensions        = req_x509_extensions
    prompt                 = no

    [req_distinguished_name]
    C                      = XY
    L                      = Castle Anthrax
    O                      = Python Software Foundation
    CN                     = {hostname}

    [req_x509_extensions]
    subjectAltName         = @san

    [san]
    DNS.1 = {hostname}
    {extra_san}

    [dir_sect]
    C                      = XY
    L                      = Castle Anthrax
    O                      = Python Software Foundation
    CN                     = dirname example

    [princ_name]
    realm = EXP:0, GeneralString:KERBEROS.REALM
    principal_name = EXP:1, SEQUENCE:principal_seq

    [principal_seq]
    name_type = EXP:0, INTEGER:1
    name_string = EXP:1, SEQUENCE:principals

    [principals]
    princ1 = GeneralString:username

    [ ca ]
    default_ca      = CA_default

    [ CA_default ]
    dir = cadir
    database  = $dir/index.txt
    crlnumber = $dir/crl.txt
    default_md = sha256
    default_days = 3600
    default_crl_days = 3600
    certificate = pycacert.pem
    private_key = pycakey.pem
    serial    = $dir/serial
    RANDFILE  = $dir/.rand

    policy          = policy_match

    [ policy_match ]
    countryName             = match
    stateOrProvinceName     = optional
    organizationName        = match
    organizationalUnitName  = optional
    commonName              = supplied
    emailAddress            = optional

    [ policy_anything ]
    countryName   = optional
    stateOrProvinceName = optional
    localityName    = optional
    organizationName  = optional
    organizationalUnitName  = optional
    commonName    = supplied
    emailAddress    = optional


    [ v3_ca ]

    subjectKeyIdentifier=hash
    authorityKeyIdentifier=keyid:always,issuer
    basicConstraints = CA:true

    t    t   req_x509_extensions_fulls   rsa:3072c         C   sõ  d |  GHg  } x? t  d ƒ D]1 } t j d t ƒ � } | j | j ƒ Wd  QXq W| \ } }	 }
 zot j d |  d | ƒ } t | d ƒ � } | j	 | ƒ Wd  QXd d d	 d
 d d d d |
 d | g } | rt j d t ƒ �  } | j | j ƒ | j } Wd  QX| d | g 7} n | d d |	 g 7} t
 d g | ƒ | r|d d | d |	 d d d d d d | g } t
 d g | ƒ n  t |	 d ƒ � } | j ƒ  } Wd  QXt |
 d ƒ � } | j ƒ  } Wd  QX| | f SWd  x | D] } t j | ƒ qÙWXd  S(   Ns   creating cert for i   t   deletet   hostnamet	   extra_sant   wt   reqs   -news   -dayst   3650s   -nodess   -newkeys   rsa:1024s   -keyouts   -configs   -outs   -x509t   opensslt   cas   -outdirt   cadirs   -policyt   policy_anythings   -batchs   -infilest   r(   t   ranget   tempfilet   NamedTemporaryFilet   Falset   appendt   namet   req_templatet   formatt   opent   writet
   check_callt   readt   ost   remove(   R   t   signR   t   extt   keyt	   tempnamest   it   ft   req_filet	   cert_filet   key_fileR   t   argst   reqfilet   certR   (    (    s‰   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/make_ssl_certs.pyt   make_cert_key\   s>    	R   c           C   s   t  j t ƒ d  S(   N(   t   shutilt   rmtreet	   TMP_CADIR(    (    (    s‰   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/make_ssl_certs.pyt	   unmake_ca†   s    c          C   s¼  t  j t ƒ t t  j j d d ƒ d ƒ � }  Wd  QXt t  j j d d ƒ d ƒ � }  |  j d ƒ Wd  QXt t  j j d d ƒ d ƒ � }  |  j d ƒ Wd  QXt j d	 ƒ �} | j t	 j
 d
 d d d ƒ ƒ | j ƒ  t j ƒ  �Í }  d d d d d d d d d d d d |  j d d g } t d g | ƒ d d | j d d d  d! d" t d# d d d d$ d d d% |  j g } t d g | ƒ d d | j d& d d' g } t d g | ƒ Wd  QXWd  QXd  S((   NR   s	   index.txts   a+s   crl.txtt   00s   index.txt.attrs   w+s   unique_subject = noR   R   s   our-ca-serverR   R   R   s   -news   -daysR   s   -extensionst   v3_cas   -nodess   -newkeys   rsa:3072s   -keyouts   pycakey.pems   -outs   -subjsG   /C=XY/L=Castle Anthrax/O=Python Software Foundation CA/CN=our-ca-serverR	   R
   s   -configs   -create_serials   pycacert.pems   -batchs   -outdirs   -keyfiles	   -selfsigns   -infiless   -gencrls   revocation.crl(   R   t   mkdirR+   R   t   patht   joinR   R   R   R   R   t   flushR   R   (   R!   t   tR%   (    (    s‰   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/make_ssl_certs.pyt   make_ca‰   s.    !!!
	t   __main__t	   localhosts   ssl_cert.pemR   s   ssl_key.pems5   password protecting ssl_key.pem in ssl_key.passwd.pemR	   t   rsas   -ins   -outs   ssl_key.passwd.pems   -des3s   -passouts   pass:somepasss   keycert.passwd.pems   keycert.pems   a+t   fakehostnames   keycert2.pems   keycert3.pems   keycert4.pems0   otherName.1 = 1.2.3.4;UTF8:some other identifiers/   otherName.2 = 1.3.6.1.5.2.2;SEQUENCE:princ_names   email.1 = user@example.orgs   DNS.2 = www.example.orgs   dirName.1 = dir_sects   URI.1 = https://www.python.org/s   IP.1 = 127.0.0.1s
   IP.2 = ::1s   RID.1 = 1.2.3.4.5t   allsansR   s   
s   allsans.pemsr   

Please change the values in test_ssl.py, test_parse_cert function related to notAfter,notBefore and serialNumbert   x509s   -datess   -serials   -noout(   t   __doc__R   R)   t   sysR   t
   subprocessR   R0   t   abspatht   dirnamet   __file__t   hereR   R(   R+   R,   R4   t   __name__t   chdirR'   R   R   R!   R   R   t   TrueR   R1   (    (    (    s‰   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/make_ssl_certs.pyt   <module>   sp   
O'		%%	!