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# 6from pyasn1.codec.der import decoder, encoder 7from pyasn1_modules import rfc2560, pem 8import sys 9 10if len(sys.argv) != 1: 11 print("""Usage: 12$ cat ocsp-request.pem | %s""" % sys.argv[0]) 13 sys.exit(-1) 14 15ocspReq = rfc2560.OCSPRequest() 16 17substrate = pem.readBase64FromFile(sys.stdin) 18if not substrate: 19 sys.exit(0) 20 21cr, rest = decoder.decode(substrate, asn1Spec=ocspReq) 22 23print(cr.prettyPrint()) 24 25assert encoder.encode(cr, defMode=False) == substrate or \ 26 encoder.encode(cr, defMode=True) == substrate, \ 27 'OCSP request recode fails' 28