ich habe ein "stacked" PEM file. D.h eine Zertifikats-Datei die gleich mehrere Zertifikate enthält (stacked)
Nun ist bekannter-weise der openssl "Client" nicht in der Lage alle Zertifikate innerhalb der Datei zu auf Gültigkeit testen, sonder nimmt immer nur das Erste.
Daher meine Idee das File in Blöcke zu unterteilen und block-by-block durch den openssl zu schieben.
Code: Alles auswählen
#!/usr/bin/python
import sys, subprocess
from StringIO import StringIO
output = StringIO()
with open ('fullchain.pem','r') as certfile:
read_data = certfile.readlines()
for line in read_data:
if not ( "-----END CERTIFICATE-----" in line):
output.write(line)
else:
output.write("-----END CERTIFICATE-----")
cert = str(output.getvalue())
print cert
print "next: "
subprocess.call( ["openssl", "x509", "-text", "-noout" ], stdin=cert )
output = StringIO()
Das Problem ist der "Subprocess".
Nimmt man die Zeile raus, werden die Blöcke richtig angezeigt. Und "piped" man den output an den openccl Client funktioniert's auch.
Code: Alles auswählen
check.py | openssl x509 -text -noout
Auch wenn man sie abändert in:
Code: Alles auswählen
subprocess.call( ["openssl", "x509", "-text", "-noout", cert ])
Es scheint als das openssl den Input einfach ignoriert ...
(Der Aufruf mit shell=True bringt auch nichts ... da landet man nur im interaktiven Modus von Openssl )