Hi Sunny,
Here are some Cert-related utility code (in Javascript) using XPCOM API for Mozilla PSM/NSS:

Note: Look into the IDL files for details about the attributes, methods, and related comments.

// IDL file for nsIX509CertDB : http://mxr.mozilla.org/mozilla-central/source/security/manager/ssl/public/nsIX509CertDB.idl#59
var /* nsIX509CertDB */ certDB = null;
certDB = Components.classes["@mozilla.org/security/x509certdb;1"]
                  .getService(Components.interfaces.nsIX509CertDB);



// IDL file for nsIX509Cert : http://mxr.mozilla.org/mozilla-central/source/security/manager/ssl/public/nsIX509Cert.idl#52
/* Find Cert using nick-name */
var x509CertNickName = "mycert";
var /* nsIX509Cert */ x509Cert =  certDB.findCertByNickname(
                                     null, x509CertNickName
                                     );
/* View Cert sing the browser's built-in certificate viewer */
var cd = Components.classes["@mozilla.org/nsCertificateDialogs;1"]
               .getService(Components.interfaces.nsICertificateDialogs);
cd.viewCert(window, x509Cert); // window is the global variable

// Access the various attributes of the X.509 certificate
var certNickName = x509cert.nickname;
var certCommonName = x509cert.commonName;
var certIssuedToSubjectDN = x509cert.subjectName;
var certIssuerSubjectDN = x509cert.issuerName; // or
certIssuerSubjectDN = x509cert.issuer.subjectName;

/* Just follow the above syntax for accessing the value for any other attribute that you need. All the attributes are defined in the IDL file for nsIX509Cert. */


Hope this helps.
--
Subrata




On 01/15/2010 06:45 AM, Sunny wrote:
Hi,
     How can i access the "Issuer" and "Issued to" of the selected
digital certificate in JavaScript in firefox?

For Internet Explorer, CAPICOM provides API to do this but for firefox
i'm not able to. I've tried using window.crypto.

Example Java Script code:
try {
        result = window.crypto.signText("Something to sign","ask");
        if(result == 'error:userCancel' || result ==
'error:internalError' || result == 'error:noMatchingCert'){
                // alert(" Result="+result+". Staying back. ");
                return null ;
        }
     }
catch(ex) { }

There's one way. if siging is successfull, result is a BASE64-encoded
string. It has a structure shown at
http://docs.sun.com/source/816-6152-10/sgntxt.htm. But, when i tried
to decode this base64 string to get "CN value of Subject" i'm not
getting proper strings. Is there a better way?

Is there a way i can access the "issued to" field in the digital
certificate selected thro window.crypto object or any other object.
(or)
Is there a plug-in for firefox similar to CAPICOM for Internet
Explorer.

--
dev-tech-crypto mailing list
dev-tech-crypto@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-tech-crypto

Reply via email to