As mentioned in [_ Extracting x5cs from a JSON Web Key Set (JWKS) to PEM files with Ruby_](/posts/2020/04/30/jwks-x5c-to-pem/), it can be handy to take a JWKS, such as:
And extract the full certificate chain for each key.
The below script will create `somekey_0.pem` for the leaf cert, `somekey_1.pem` for the next cert, and so on, by running `node x5c-to-pems.js filename.jwks`:
The [JSON Web Key (JWK) specification, RFC7517](https://tools.ietf.org/html/rfc7517#appendix-B) defines the `x5c` parameter to a JWK as the X.509 certificate chain:
However, the form above isn't necessarily the most human-readable format, so how can we convert that to a more readable X.509 certificate, [for use with OpenSSL](/posts/2018/11/02/viewing-x509-pem-openssl/).
To do so, we can parse it using the [node-jose](https://www.npmjs.com/package/node-jose) library, convert it to a certificate, then dump the X509 certificate with its headers: