Way to load PEM certificates from String into a SSL Context

Hello folks,

I was looking for ways to load PEM certificates from String into a OpenSSL::SSL::Context (specifically Client one) for certificate pinning, but I couldn’t find a clear mechanism for this.

While I know there is #ca_certificates= and #ca_certificates_path=, they all treat with files in the filesystem, but none about loading them from a string from memory.

I found OpenSSL::X509::Certificate.from_der?, but the only test is from Windows and this is expecting the cert to be in DER format, which means the PEM must be converted to DER (binary), making it a bit more complicated to bundle (via macro) into your application source.

Not to mention, no mechanism to add that certificate into that context :sweat_smile:

Any ideas?

Thank you in advance!

:heart: :heart: :heart: