mirleft / ocaml-x509

X509 (RFC5280) handling in OCaml
BSD 2-Clause "Simplified" License
52 stars 33 forks source link

parsing pem from string #104

Closed zoggy closed 6 years ago

zoggy commented 6 years ago

Hi,

I could not find a way to parse a certificate in pem format from a string (I want to access a certificate in a HTTP header, using apache proxy). I guess this is just a matter of adding some existing functions of x509_pem to X509 interface ?

hannesm commented 6 years ago

The encoder and decoder for PEM-encoded certificates is within the X509.Encoding.Pem.Certificate https://mirleft.github.io/ocaml-x509/doc/X509.Encoding.Pem.Certificate.html .

Now, it looks to me that of_pem_cstruct1 would suit your usecase rather well, after you Cstruct.of_string pem_cert. Be aware that the decoding functions can raise an exception atm.

I guess this is just a matter of adding some existing functions of x509_pem to X509 interface ?

I don't understand what you propose exactly here.

zoggy commented 6 years ago

Thanks for your quick answer. I did not known about Cstruct and so I thought there was something more to give to parse the string. So no need to add anything.