diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /third_party/python/pyasn1-modules/tools/cmcdump.py | |
parent | Initial commit. (diff) | |
download | firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/python/pyasn1-modules/tools/cmcdump.py')
-rwxr-xr-x | third_party/python/pyasn1-modules/tools/cmcdump.py | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/third_party/python/pyasn1-modules/tools/cmcdump.py b/third_party/python/pyasn1-modules/tools/cmcdump.py new file mode 100755 index 0000000000..bce48b1990 --- /dev/null +++ b/third_party/python/pyasn1-modules/tools/cmcdump.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python +# +# Read CMC certificate request with wrappers on stdin, parse each into +# plain text, then build substrate from it +# +from pyasn1.codec.der import decoder, encoder +from pyasn1_modules import rfc5652, rfc6402, pem +import sys + +if len(sys.argv) != 1: + print("""Usage: +$ cat cmc_request.pem | %s""" % (sys.argv[0],)) + sys.exit(-1) + +reqCnt = 0 + +substrate = pem.readBase64FromFile(sys.stdin) + +_, rest = decoder.decode(substrate, asn1Spec=rfc5652.ContentInfo()) +assert not rest + +next_layer = rfc5652.id_ct_contentInfo +data = substrate +while next_layer: + if next_layer == rfc5652.id_ct_contentInfo: + layer, rest = decoder.decode(data, asn1Spec=rfc5652.ContentInfo()) + assert encoder.encode(layer) == data, 'wrapper recode fails' + assert not rest + + print(" * New layer (wrapper):") + print(layer.prettyPrint()) + + next_layer = layer['contentType'] + data = layer['content'] + + elif next_layer == rfc5652.id_signedData: + layer, rest = decoder.decode(data, asn1Spec=rfc5652.SignedData()) + assert encoder.encode(layer) == data, 'wrapper recode fails' + assert not rest + + print(" * New layer (wrapper):") + print(layer.prettyPrint()) + + next_layer = layer['encapContentInfo']['eContentType'] + data = layer['encapContentInfo']['eContent'] + + elif next_layer == rfc6402.id_cct_PKIData: + layer, rest = decoder.decode(data, asn1Spec=rfc6402.PKIData()) + assert encoder.encode(layer) == data, 'pkidata recode fails' + assert not rest + + print(" * New layer (pkidata):") + print(layer.prettyPrint()) + + next_layer = None + data = None |