简体   繁体   中英

OpenSSL crypto error: [('PEM routines', 'PEM_read_bio', 'no start line')]

I am getting the following error when trying to read a certificate:

OpenSSL.crypto.Error: [('PEM routines', 'PEM_read_bio', 'no start line')]

when running OpenSSL.crypto.load_certificate(FILETYPE_PEM, filename) . I have made some research but was not able to find an answer specific to my case.

I tried checking if the file existed with os.path.isfile(filename) which returns True , but loading the certificate ONLY raises the error above.

Also, when executing on the terminal openssl X509 -in file.pem , it works like a charm.

The file.pem looks like this:

-----BEGIN CERTIFICATE-----
<<sensitive data>>
-----END CERTIFICATE-----

It seems to be valid since I able to perform basic openssl operations on the terminal. I am running CentOS 7, if that helps.

Any ideas?

Thanks!

According to http://www.pyopenssl.org/en/stable/api/crypto.html#OpenSSL.crypto.load_certificate , load_certificate() takes a buffer (string will do) containing the certificate, not a filename.

Your need to do:

with open(filename, "r") as my_cert_file:
    my_cert_text = my_cert_file.read()
    cert = load_certificate(FILETYPE_PEM, my_cert_text)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM