I have a p7b file I need to extract the base64 server certificate from. I have an openssl command I can do this on in my terminal, but the problem is I have a whole folder full of p7b certs I need to extract the server certs from.
Here is my openSSL command:
openssl pkcs7 -inform DER -outform PEM -in p7bfile.p7b -print_certs > base64_server_cert.cer
I did some googling and found a post saying to use the call command to run this in python, but when I try that it runs with no errors but there's no output in folder, so I'm not sure if I'm running they python syntax incorrectly or this is the wrong module to use. If I try printing the assigned "decrypted" variable I just get a 1 (assuming it's 0 or 1 output only).
Example of my python code:
from subprocess import call
def main():
decrypted = call(['openssl', 'pkcs7', '-inform', 'DER', '-outform', 'PEM', '-in', 'p7bfile.p7b', '-print_certs', '>', 'base64_server_cert.cer'])
if __name__ == '__main__':
main()
Is there a better way to run an open SSL command like this to extract the server cert? I don't care about extracting the CA or intermediate certs in the file, just the server cert is all that matters to me.
Included in above post, but attempted to run code using call from subprocess module and formatting my openssl command I can successfully run from my terminal, but it doesn't appear to take any action when run in python (no cert is output like when I run the command locally).