• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 X.509 CRMF request on stdin, parse into
9# plain text, then build substrate from it
10#
11import sys
12
13from pyasn1.codec.der import decoder
14from pyasn1.codec.der import encoder
15
16from pyasn1_modules import pem
17from pyasn1_modules import rfc2511
18
19if len(sys.argv) != 1:
20    print("""Usage:
21$ cat crmf.pem | %s""" % sys.argv[0])
22    sys.exit(-1)
23
24certReq = rfc2511.CertReqMessages()
25
26substrate = pem.readBase64FromFile(sys.stdin)
27if not substrate:
28    sys.exit(0)
29
30cr, rest = decoder.decode(substrate, asn1Spec=certReq)
31
32print(cr.prettyPrint())
33
34assert encoder.encode(cr) == substrate, 'crmf recode fails'
35