I need to parse .PEM files.
I know that the standard for “Privacy-enhanced Electronic Mail” is defined in RFCs 1421-24. But they don’t seem to mention some text I find inside OpenSSL .pem files (eg. “Key Attributes”, “BEGIN CERTIFICATE”, etc…)
Is this an OpenSSL-specific format?
I need to parse .PEM files. I know that the standard for Privacy-enhanced Electronic
Share
For quite a long time, there was no formal specification of the PEM format with regards to cryptographic exchange of information. PEM is the textual encoding, but what is actually being encoded depends on the context. In April 2015, the IETF approved RFC 7468, which finally documents how various implementations exchange data using PEM textual encoding. The following list, taken directly from the RFC, describes the PEM format used for the following scenarios:
Public Key Info structures in the Internet X.509 Public Key
Infrastructure Certificate and Certificate Revocation List (CRL)
Profile [RFC5280].
Asymmetric Key in Asymmetric Key Package [RFC5958], and Encrypted
Private-Key Information Syntax in the same documents.
Profile for Authorization [RFC5755].
According to this RFC, for the above scenarios you can expect the following labels to be within the BEGIN header and END footer. Figure 4 of the RFC has more detail, including corresponding ASN.1 types.
That’s not the full story, though. The RFC was written by looking at existing implementations and documenting what they did. The RFC wasn’t written first, nor was it written based on some existing authoritative documentation. So if you end up in a situation where you want to inter-operate with some implementation, you may have to look into the implementation’s source code to figure out what they support.
For example, OpenSSL defines these BEGIN and END markers in crypto/pem/pem.h. Here is an excerpt from the header file with all the BEGIN and END labels that they support.
These labels are a start, but you still have to look into how the implementation encodes the data between the labels. There’s not one correct answer for everything.