0

Let's say that I have a python string:

string_full = """
              -----BEGIN CERTIFICATE----- 
              GIBBERISH................
              ......................
              ........................
              -----END CERTIFICATE-----
              """

After removing the first line, newlines, and last line I got something like this:

 string = """ GIBBERISH .................................. """

What I'm trying to do is to get the Public Key from that certificate.

I was having a look at this post, but it seems that the string must be formated as string_full but the real problem is that I'm reading that line from a user uploaded file (django), but since this file is structured by the Mexican Goverment, it would be really easy for me to calculate the public key from the string as shown in string. a Got any ideas? I was having a look at M2Cryptolib which implements a get_pukeybut it will only work on requests and I have no way to get this request from an external server.

Any help would be appreciated.

Community
  • 1
  • 1
Jose_Sunstrider
  • 323
  • 1
  • 3
  • 17

1 Answers1

1

I'm not sure why you are trying to get that string since to my knowledge most ssl functions will take the whole cert to verify.

Have you seen this post? It looks like what you want.

Hope that helps.

EDIT:

I think this example will help you understand what's every argument and in what format should it be.

Community
  • 1
  • 1
JasonPap
  • 98
  • 6
  • When using the first option of that answer (openssl) it works perfectly, tomorrow morning I will try with OpenSSL python library. I was just wondering, what does the `signature`argument stands for in `OpenSSL.crypto.verify(cert, signature, data, 'sha256')` Is it refering to the public key obtained before? The [documentation](http://pythonhosted.org/pyOpenSSL/api/crypto.html) wasn't that helpfull :( Also thanks a lot @JasonPap, this post was really useful! – Jose_Sunstrider Jan 21 '15 at 04:03
  • 1
    @Jose_Sunstrider I updated my answer, check if it's now more helpful. – JasonPap Jan 21 '15 at 12:15
  • Thanks for the update. I also read again the documentation and I found some information on the signature: `signature is a str instance giving the signature itself.`. I missed that one last night. Just for future reference, the string MUST be a byte encoded string. – Jose_Sunstrider Jan 21 '15 at 14:58