Re: Clarification on nsHTMLInputElement/ certificates

Boris Zbarsky <[email protected]> Thu, 19 Apr 2012 15:30:24 -0400
Newsgroups gmane.comp.mozilla.devel.dom
Message-ID <[email protected]>
On 4/19/12 3:10 PM, Anderson Walls wrote:
>> Getting it for the document the<input>  is in goes like this:
>>
>>     nsCOMPtr<nsISupports>  cert;
>>     NodePrincipal()->GetCertificate(getter_AddRefs(cert));
>>     if (cert) {
>>       // Can now QI cert to nsIX509Cert, nsIX509Cert2, nsIX509Cert3,
>>       // extract whatever you want.
>>     }
>>
>> -Boris
>
> Thanks for the helpful reply Boris.
>
> Would you be able to tell me how to take cert and literally print out
> the x509 cert to stderr, PEM, DEM, doesn't matter the format I can
> script it pem with openssl.

I can get you DER.  Would that be good enough?

Starting with the above code:

   nsCOMPtr<nsIX509Cert> c = do_QueryInterface(cert);
   PRUint32 length;
   PRUint8* data;
   c->GetRawDER(&length, &data);
   // Do whatever you want with the data; write it to files, whatever
   NS_Free(data);

-Boris