title: Create a self signed X509 certificate in Python
body: <p>I followed <a href="http://blog.richardknop.com/2012/08/create-a-self-signed-x509-certificate-in-python/" rel="noreferrer">this url</a> to create a X509 certificate. And the code is:</p>
  
  <pre><code>from OpenSSL import crypto, SSL
  from socket import gethostname
  from pprint import pprint
  from time import gmtime, mktime
  
  CERT_FILE = "selfsigned.crt"
  KEY_FILE = "private.key"
  
  def create_self_signed_cert():
  
      # create a key pair
      k = crypto.PKey()
      k.generate_key(crypto.TYPE_&lt;wbr&gt;RSA, 1024)
  
      # create a self-signed cert
      cert = crypto.X509()
      cert.get_subject().C = "UK"
      cert.get_subject().ST = "London"
      cert.get_subject().L = "London"
      cert.get_subject().O = "Dummy Company Ltd"
      cert.get_subject().OU = "Dummy Company Ltd"
      cert.get_subject().CN = gethostname()
      cert.set_serial_number(1000)
      cert.gmtime_adj_notBefore(0)
      cert.gmtime_adj_notAfter(10*&lt;wbr&gt;365*24*60*60)
      cert.set_issuer(cert.get_&lt;wbr&gt;subject())
      cert.set_pubkey(k)
      cert.sign(k, 'sha1')
  
      open(CERT_FILE, "wt").write(
          crypto.dump_certificate(&lt;wbr&gt;crypto.FILETYPE_PEM, cert))
      open(KEY_FILE, "wt").write(
          crypto.dump_privatekey(crypto.&lt;wbr&gt;FILETYPE_PEM, k))
  
  create_self_signed_cert()
  </code></pre>
  
  <p>But there is something wrong with the code when I run it. Could someone tell me what the meaning of <code>&lt;wbr&gt;</code>? There is a <code>SyntaxError</code> in <code>cert.gmtime_adj_notAfter(10*&lt;wbr&gt;365*24*60*60)</code>. Thx.</p>