1 #!/usr/bin/python 2 # 3 # Read ASN.1/PEM X.509 CRMF request on stdin, parse into 4 # plain text, then build substrate from it 5 # 6 from pyasn1.codec.der import decoder, encoder 7 from pyasn1_modules import rfc2560, pem 8 import sys 9 10 if len(sys.argv) != 1: 11 print("""Usage: 12 $ cat ocsp-request.pem | %s""" % sys.argv[0]) 13 sys.exit(-1) 14 15 ocspReq = rfc2560.OCSPRequest() 16 17 substrate = pem.readBase64FromFile(sys.stdin) 18 if not substrate: 19 sys.exit(0) 20 21 cr, rest = decoder.decode(substrate, asn1Spec=ocspReq) 22 23 print(cr.prettyPrint()) 24 25 assert encoder.encode(cr, defMode=False) == substrate or \ 26 encoder.encode(cr, defMode=True) == substrate, \ 27 'OCSP request recode fails' 28