1 #!/usr/bin/env python 2 # 3 # This file is part of pyasn1-modules software. 4 # 5 # Copyright (c) 2005-2017, Ilya Etingof <etingof (at] gmail.com> 6 # License: http://pyasn1.sf.net/license.html 7 # 8 # Read ASN.1/PEM CMP message on stdin, parse into 9 # plain text, then build substrate from it 10 # 11 import sys 12 13 from pyasn1 import debug 14 from pyasn1.codec.der import decoder 15 from pyasn1.codec.der import encoder 16 17 from pyasn1_modules import pem 18 from pyasn1_modules import rfc4210 19 20 if len(sys.argv) == 2 and sys.argv[1] == '-d': 21 debug.setLogger(debug.Debug('all')) 22 elif len(sys.argv) != 1: 23 print("""Usage: 24 $ cat cmp.pem | %s [-d]""" % sys.argv[0]) 25 sys.exit(-1) 26 27 pkiMessage = rfc4210.PKIMessage() 28 29 substrate = pem.readBase64FromFile(sys.stdin) 30 if not substrate: 31 sys.exit(0) 32 33 pkiMsg, rest = decoder.decode(substrate, asn1Spec=pkiMessage) 34 35 print(pkiMsg.prettyPrint()) 36 37 assert encoder.encode(pkiMsg) == substrate, 'CMP message recode fails' 38