how to retrieve SSL certificate informations?

Roger Lipscombe roger@REDACTED
Mon Mar 9 09:23:12 CET 2020


This is probably not complete (because we generate our own
certificates), but here's what we use:

-include_lib("public_key/include/public_key.hrl").

get_certificate_subject_cn(#'OTPCertificate'{tbsCertificate = OTPTBS}) ->
    get_certificate_subject_cn(OTPTBS);
get_certificate_subject_cn(#'OTPTBSCertificate'{subject = Subject}) ->
    get_cn(Subject).

get_cn({rdnSequence, Seq}) ->
    get_cn(Seq);
get_cn([]) ->
    undefined;
get_cn([[#'AttributeTypeAndValue'{type = ?'id-at-commonName',
                                  value = {utf8String, Value}}] | _]) ->
    Value;
get_cn([_|Rest]) ->
    get_cn(Rest).

get_serial_number(#'OTPCertificate'{tbsCertificate = OTPTBS}) ->
    get_serial_number(OTPTBS);
get_serial_number(#'OTPTBSCertificate'{serialNumber = SerialNumber}) ->
    SerialNumber.

On Sun, 8 Mar 2020 at 23:34, Benoit Chesneau <bchesneau@REDACTED> wrote:
>
> How can I get informations about an SSL certificate ? Specifically I am looking for a way to retrieve the issuer, subject, and the  serial number of the certificate.
>
> The record I get from decoding using public_key functions is hard to parse so any help is welcome. Maybe there is already an api/app somewhere for it?
>
> Benoît
>
>


More information about the erlang-questions mailing list