Hi, all: Now I want to retrieve user certificate from Mozilla which had been installed into its db, and those certificates could be checked from Mozilla menu: "Edit->Preferences->Privacy&Security->Certificate" or similar ways.
Via the following function I hope to get user certificate: (Notice: macro "DBG_VIEW" record my debug information only.) Now, my problem is "CERT_GetDefaultCertDB" return NULL. And I do not catch it with more message. Could anybody instruct me to change my settings or what to do in my program? Where could I learn about it? Where could I get more examples about these? /**--------------------------------------------------begin function*/ int GetCert(char *strCertSubjectCN, char *strSN, char *strCertContent, int *nCertLen) { DBG_VIEW("Enter:+++++++GetCert: strCertSubjectCN=%s\nstrSN=%s\n", strCertSubjectCN, strSN); CERTCertDBHandle *certdb = NULL; void *libc = NULL; int rv = S_OK; try { if(certdb == NULL) { libc = dlopen("libnss3.so",RTLD_NOW | RTLD_LOCAL); if(libc == NULL) { DBG_VIEW("dlopen libnss3.so failed!\n"); throw (rv = E_LIB_NOT_FOUND); } CERTCertDBHandle* (*CERT_GetDefaultCertDB)(void); CERT_GetDefaultCertDB = (CERTCertDBHandle *(*) ())dlsym(libc, "CERT_GetDefaultCertDB"); if(CERT_GetDefaultCertDB == NULL) { DBG_VIEW("CERT_GetDefaultCertDB == NULL\n"); throw (rv = E_EXCEPTIONAL); } certdb = (*CERT_GetDefaultCertDB)(); if(certdb == NULL) { DBG_VIEW("certdb == NULL\n"); throw (rv = E_CERT_STORE_NO_EXIST); } DBG_VIEW("certdb=0x%08X\n", certdb); char *strROOTCA = "ROOTCA"; CERTIssuerAndSN issuerAndSN; CERTCertificate *usercert; CERTCertificate *(*CERT_FindCertByNameString)(CERTCertDBHandle *handle, char *name); CERT_FindCertByNameString = (CERTCertificate *(*) (CERTCertDBHandle *, char *))dlsym(libc, "CERT_FindCertByNameString"); usercert = CERT_FindCertByNameString(certdb,strROOTCA); if (usercert == NULL) { DBG_VIEW("usercert == NULL\n"); throw( rv = E_CERT_STORE_NO_EXIST); } /*-- more done with how to return user certificate.*/. } } catch(...) { } SECStatus (*NSS_Shutdown)(void); NSS_Shutdown = (SECStatus (*)())dlsym(libc, "NSS_Shutdown"); NSS_Shutdown(); dlclose(libc); DBG_VIEW("Exit:------GetUCertfromCertDb::GetCert.\n"); return rv; } /**----------------------------------------------------end function*/ Best regards. Thankful boise _______________________________________________ mozilla-crypto mailing list mozilla-crypto@mozilla.org http://mail.mozilla.org/listinfo/mozilla-crypto