300f310d300b0603550403130446616B65
The above is hex bytes of a DER-encoded X.509 certificate subject. when it is decoded, it should return string "Fake" which is certificate subject. How to do it in perl.
300f310d300b0603550403130446616B65
The above is hex bytes of a DER-encoded X.509 certificate subject. when it is decoded, it should return string "Fake" which is certificate subject. How to do it in perl.
Copyright © 2021 Jogjafile Inc.
This is easy to decode manually:
"Fake"Just to double-check, the output of
perl -e "print pack qw/H* 300f310d300b0603550403130446616b65/" | openssl asn1parse -inform DERis:Here is an ad hoc parser:
Let's try to parse it with the Perl DER parser library Convert::ASN1. For that we need type definitions for the
->prepare(...)method. Let's try to guess the types.I copy-pasted
300f310d300b0603550403130446616b65to an online ASN.1 decoder: https://lapo.it/asn1js/#MA8xDTALBgNVBAMTBEZha2U , with the following result:The keywords like tbsCertificate and CertificateSerialNumber pointed me to https://www.rfc-editor.org/rfc/rfc5280, but I noticed that the types above were autodetected incorrectly, because CertificateSerialNumber is an INTEGER there. By looking at the RFC document, I guessed these types:
The corresponding ASN.1 type definitions extracted from the RFC document https://www.rfc-editor.org/rfc/rfc5280:
Let's try to feed these types to the
->prepare(...)method of the Perl module Convert::ASN1. With a Google search forConvert::ASN1 RDNSequence, I've found this example code: https://github.com/gbarr/perl-Convert-ASN1/blob/master/examples/x509decode , based on this and the Convert::ASN1 documentation I wrote the following Perl script:Output:
Here you go.