title: PyOpenSSL reading certificate/pkey file
body: <p>That's how i create certificate</p>
  
  <pre><code>  from OpenSSL import crypto
  
    cert = crypto.X509()
    cert.get_subject().C            = countryName
    cert.get_subject().ST           = stateOrProvinceName
    ...
  </code></pre>
  
  <p><br><a href="http://www.themacaque.com/?p=1057" rel="noreferrer">Here</a> what generation looks like.<br>
  Now, how do I extract those values fomr certificate using PyOpenSSL backwards from plain files?</p>
  
  <p>So here's what I cameup with</p>
  
  <pre><code>def certext(certstr):
    p1 = Popen(['printf', certstr], stdout=PIPE)
    p2 = Popen(['openssl', 'x509', '-text'], stdin=p1.stdout, stdout=PIPE)
    p1.stdout.close()
    output = p2.communicate()[0]
    return output
  </code></pre>