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