1

使用 asn1parse 解码 openssl 数据时出现问题。使用 asn1parse 命令后,out.pem 包含与预期输出不匹配。实际输出和预期输出如下所示。请在这个问题上帮助我。

openssl asn1parse -inform PEM -in base64.pem -out out.pem

猫base64。佩姆cmF0aW9uLWhhbmRsaW5nIjogIm1lcmdlIiwKICAgICAgICAiY29uZmlndXJhdGlvbiI6ICJQSFJ2Y0NCNGJXeHVjejBpYUhSMGNITTZMMlY0WVcxd2JHVXVZMjl0TDJOdmJtWnBaeUkrQ2lBZ1​​BHRnVlUzE0Yld3dFkyOXVkR1Z1ZEMxdmEyRjVMejRLUEM5MGIzQStDZz09IiwKICAgICAgICAicG9zdC1jb25maWd1cmF0aW9uLXNjcmlwdCI6ICJJeTlpYVc0dlltRnphQXBsWTJodklDSnBibk5wWkdVZ2RHaGxJSEJ2YzNRdFkyOXVabWxuZFhKaGRHbHZiaTF6WTNKcGNIUXVMaTRpQ2c9PSIKICAgIH0KfQ==

0:d=0  hl=2 l=  86 prim: appl [ 7 ]        

88:d=0 hl=2 l= 67 prim: appl [ 9 ]

cat out.pem GVudC1va2F5Lz4KPC90b3A+Cg==", "配置后脚本": "Iy9iaW4vYmFzaAplY2hvICJpbnNpZGUgdGhlIHBvc3QtY29uZmlndXJhdGlvbi1zY3JpcHQuLi4iCg==" } }

预期输出.pem b'0\x82\x03\x99\x06\x0b*\x86H\x86\xf7\r\x01\t\x10\x01+\xa0\x82\x03\x88\x04\x82\x03\x84 {\n "ietf-sztp-conveyed-info:onboarding-information": {\n "boot-image": {\n "download-uri": [\n "https://example.com/my-boot -image.img"\n ],\n "image-verification": [\n {\n "hash-algorithm": "ietf-sztp-conveyed-info:sha-256",\n "hash-value" :“d8:56:8d:d2:10:5e:dc:75:4c:c7:87:ae:f1:27:97:65:e0:65:17:6c:04:61:22:fa: 3e:82:cf:9d:0f:ae:1a:3d"\n }\n ]\n },\n "预配置脚本": "Iy9iaW4vYmFzaAplY2hvICJpbnNpZGUgdGhlIHByZS1jb25maWd1cmF0aW9uLXNjcmlwdC4uLiIK",\n "configuration-handling": "merge",\n "configuration": "PHRvcCB4bWxucz0iaHR0cHM6L2V4YW1wbGUuY29tL2NvbmZpZyI+CiAgPGFueS14bWwtY29udGVudC1va2F5Lz4KPC90b3A+Cg==",\n "post-configuration-script": "Iy9iaW4vYmFzaAplY2hvICJpbnNpZGUgdGhlIHBvc3QtY29uZmlndXJhdGlvbi1zY3JpcHQuLi4iCg=="\n }\n}'

4

1 回答 1

1

您的输入文件包含一个长的 base64 行。OpenSSL 期望 base64 格式的输入以 64 个字符换行。

如果您在 *nix 环境中,则可以使用该fold工具进行换行。您可以使用换行创建输入文件的不同版本,也可以使用Process Substitution一次性完成,如下所示:

$ openssl asn1parse -in <(fold -w 64 base64.pem)
    0:d=0  hl=4 l= 921 cons: SEQUENCE          
    4:d=1  hl=2 l=  11 prim: OBJECT            :1.2.840.113549.1.9.16.1.43
   17:d=1  hl=4 l= 904 cons: cont [ 0 ]        
   21:d=2  hl=4 l= 900 prim: OCTET STRING      :{
    "ietf-sztp-conveyed-info:onboarding-information": {
        "boot-image": {
            "download-uri": [
                "https://example.com/my-boot-image.img"
            ],
            "image-verification": [
                {
                    "hash-algorithm": "ietf-sztp-conveyed-info:sha-256",
                    "hash-value": "f0:f7:5e:34:53:c0:11:72:e3:cf:e1:d9:3a:dc:c7:bf:b5:c6:7f:17:6f:7e:30:75:0a:13:42:16:34:24:9c:2d"
                }
            ]
        },
        "pre-configuration-script": "Iy9iaW4vYmFzaAplY2hvICJpbnNpZGUgdGhlIHByZS1jb25maWd1cmF0aW9uLXNjcmlwdC4uLiIK",
        "configuration-handling": "merge",
        "configuration": "PHRvcCB4bWxucz0iaHR0cHM6L2V4YW1wbGUuY29tL2NvbmZpZyI+CiAgPGFueS14bWwtY29udGVudC1va2F5Lz4KPC90b3A+Cg==",
        "post-configuration-script": "Iy9iaW4vYmFzaAplY2hvICJpbnNpZGUgdGhlIHBvc3QtY29uZmlndXJhdGlvbi1zY3JpcHQuLi4iCg=="
    }
}
于 2020-10-17T04:39:25.510 回答