Created
          September 16, 2014 01:45 
        
      - 
      
- 
        Save exarkun/2d0fa72bec36447dd28d to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | # coding: utf-8 | |
| from inspect import getsource | |
| from datetime import datetime | |
| from OpenSSL.crypto import FILETYPE_PEM, TYPE_RSA, X509, PKey, dump_privatekey, dump_certificate | |
| key = PKey() | |
| key.generate_key(TYPE_RSA, 2048) | |
| cert = X509() | |
| issuer = cert.get_issuer() | |
| subject = cert.get_subject() | |
| for dn in [issuer, subject]: | |
| dn.C = b"TR" | |
| dn.ST = b"Çorum" | |
| dn.L = b"Başmakçı" | |
| dn.CN = b"localhost" | |
| dn.O = b"Twisted Matrix Labs" | |
| dn.OU = b"Automated Testing Authority" | |
| dn.emailAddress = b"[email protected]" | |
| cert.set_serial_number(datetime.now().toordinal()) | |
| cert.gmtime_adj_notBefore(0) | |
| cert.gmtime_adj_notAfter(60 * 60 * 24 * 365 * 100) | |
| cert.set_pubkey(key) | |
| cert.sign(key, b"sha1") | |
| import __main__ | |
| source = getsource(__main__) | |
| source = source.split(b"\n" + b"-" * 5)[0].rsplit(b"\n", 1)[0] | |
| with open(b"server.pem", "wb") as fObj: | |
| fObj.write(source) | |
| fObj.write(b"\n") | |
| fObj.write(b"'''\n") | |
| fObj.write(dump_privatekey(FILETYPE_PEM, key)) | |
| fObj.write(dump_certificate(FILETYPE_PEM, cert)) | |
| fObj.write(b"'''\n") | |
| ''' | |
| ----- | |
| ''' | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment