As above, you can use the OpenSSL X509 parser for this.