certvfypkix.c 70 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. /*
  5. * nss_pkix_proxy.h
  6. *
  7. * PKIX - NSS proxy functions
  8. *
  9. * NOTE: All structures, functions, data types are parts of library private
  10. * api and are subjects to change in any following releases.
  11. *
  12. */
  13. #include "prerror.h"
  14. #include "prprf.h"
  15. #include "nspr.h"
  16. #include "pk11func.h"
  17. #include "certdb.h"
  18. #include "cert.h"
  19. #include "secerr.h"
  20. #include "nssb64.h"
  21. #include "secasn1.h"
  22. #include "secder.h"
  23. #include "pkit.h"
  24. #ifndef NSS_DISABLE_LIBPKIX
  25. #include "pkix_pl_common.h"
  26. extern PRLogModuleInfo *pkixLog;
  27. #ifdef PKIX_OBJECT_LEAK_TEST
  28. extern PKIX_UInt32
  29. pkix_pl_lifecycle_ObjectLeakCheck(int *);
  30. extern SECStatus
  31. pkix_pl_lifecycle_ObjectTableUpdate(int *objCountTable);
  32. PRInt32 parallelFnInvocationCount;
  33. #endif /* PKIX_OBJECT_LEAK_TEST */
  34. static PRBool usePKIXValidationEngine = PR_FALSE;
  35. #endif /* NSS_DISABLE_LIBPKIX */
  36. /*
  37. * FUNCTION: CERT_SetUsePKIXForValidation
  38. * DESCRIPTION:
  39. *
  40. * Enables or disables use of libpkix for certificate validation
  41. *
  42. * PARAMETERS:
  43. * "enable"
  44. * PR_TRUE: enables use of libpkix for cert validation.
  45. * PR_FALSE: disables.
  46. * THREAD SAFETY:
  47. * NOT Thread Safe.
  48. * RETURNS:
  49. * Returns SECSuccess if successfully enabled
  50. */
  51. SECStatus
  52. CERT_SetUsePKIXForValidation(PRBool enable)
  53. {
  54. #ifdef NSS_DISABLE_LIBPKIX
  55. PORT_SetError(PR_NOT_IMPLEMENTED_ERROR);
  56. return SECFailure;
  57. #else
  58. usePKIXValidationEngine = (enable > 0) ? PR_TRUE : PR_FALSE;
  59. return SECSuccess;
  60. #endif /* NSS_DISABLE_LIBPKIX */
  61. }
  62. /*
  63. * FUNCTION: CERT_GetUsePKIXForValidation
  64. * DESCRIPTION:
  65. *
  66. * Checks if libpkix building function should be use for certificate
  67. * chain building.
  68. *
  69. * PARAMETERS:
  70. * NONE
  71. * THREAD SAFETY:
  72. * NOT Thread Safe
  73. * RETURNS:
  74. * Returns PR_TRUE if libpkix should be used. PR_FALSE otherwise.
  75. */
  76. PRBool
  77. CERT_GetUsePKIXForValidation()
  78. {
  79. #ifdef NSS_DISABLE_LIBPKIX
  80. return PR_FALSE;
  81. #else
  82. return usePKIXValidationEngine;
  83. #endif /* NSS_DISABLE_LIBPKIX */
  84. }
  85. #ifndef NSS_DISABLE_LIBPKIX
  86. #ifdef NOTDEF
  87. /*
  88. * FUNCTION: cert_NssKeyUsagesToPkix
  89. * DESCRIPTION:
  90. *
  91. * Converts nss key usage bit field(PRUint32) to pkix key usage
  92. * bit field.
  93. *
  94. * PARAMETERS:
  95. * "nssKeyUsage"
  96. * Nss key usage bit field.
  97. * "pkixKeyUsage"
  98. * Pkix key usage big field.
  99. * "plContext"
  100. * Platform-specific context pointer.
  101. * THREAD SAFETY:
  102. * Thread Safe (see Thread Safety Definitions in Programmer's Guide)
  103. * RETURNS:
  104. * Returns NULL if the function succeeds.
  105. * Returns a Fatal Error if the function fails in an unrecoverable way.
  106. */
  107. static PKIX_Error *
  108. cert_NssKeyUsagesToPkix(
  109. PRUint32 nssKeyUsage,
  110. PKIX_UInt32 *pPkixKeyUsage,
  111. void *plContext)
  112. {
  113. PKIX_UInt32 pkixKeyUsage = 0;
  114. PKIX_ENTER(CERTVFYPKIX, "cert_NssKeyUsagesToPkix");
  115. PKIX_NULLCHECK_ONE(pPkixKeyUsage);
  116. *pPkixKeyUsage = 0;
  117. if (nssKeyUsage & KU_DIGITAL_SIGNATURE) {
  118. pkixKeyUsage |= PKIX_DIGITAL_SIGNATURE;
  119. }
  120. if (nssKeyUsage & KU_NON_REPUDIATION) {
  121. pkixKeyUsage |= PKIX_NON_REPUDIATION;
  122. }
  123. if (nssKeyUsage & KU_KEY_ENCIPHERMENT) {
  124. pkixKeyUsage |= PKIX_KEY_ENCIPHERMENT;
  125. }
  126. if (nssKeyUsage & KU_DATA_ENCIPHERMENT) {
  127. pkixKeyUsage |= PKIX_DATA_ENCIPHERMENT;
  128. }
  129. if (nssKeyUsage & KU_KEY_AGREEMENT) {
  130. pkixKeyUsage |= PKIX_KEY_AGREEMENT;
  131. }
  132. if (nssKeyUsage & KU_KEY_CERT_SIGN) {
  133. pkixKeyUsage |= PKIX_KEY_CERT_SIGN;
  134. }
  135. if (nssKeyUsage & KU_CRL_SIGN) {
  136. pkixKeyUsage |= PKIX_CRL_SIGN;
  137. }
  138. if (nssKeyUsage & KU_ENCIPHER_ONLY) {
  139. pkixKeyUsage |= PKIX_ENCIPHER_ONLY;
  140. }
  141. /* Not supported. XXX we should support this once it is
  142. * fixed in NSS */
  143. /* pkixKeyUsage |= PKIX_DECIPHER_ONLY; */
  144. *pPkixKeyUsage = pkixKeyUsage;
  145. PKIX_RETURN(CERTVFYPKIX);
  146. }
  147. extern SECOidTag ekuOidStrings[];
  148. enum {
  149. ekuIndexSSLServer = 0,
  150. ekuIndexSSLClient,
  151. ekuIndexCodeSigner,
  152. ekuIndexEmail,
  153. ekuIndexTimeStamp,
  154. ekuIndexStatusResponder,
  155. ekuIndexUnknown
  156. } ekuIndex;
  157. typedef struct {
  158. SECCertUsage certUsage;
  159. PRUint32 ekuStringIndex;
  160. } SECCertUsageToEku;
  161. const SECCertUsageToEku certUsageEkuStringMap[] = {
  162. { certUsageSSLClient, ekuIndexSSLClient },
  163. { certUsageSSLServer, ekuIndexSSLServer },
  164. { certUsageSSLCA, ekuIndexSSLServer },
  165. { certUsageEmailSigner, ekuIndexEmail },
  166. { certUsageEmailRecipient, ekuIndexEmail },
  167. { certUsageObjectSigner, ekuIndexCodeSigner },
  168. { certUsageUserCertImport, ekuIndexUnknown },
  169. { certUsageVerifyCA, ekuIndexUnknown },
  170. { certUsageProtectedObjectSigner, ekuIndexUnknown },
  171. { certUsageStatusResponder, ekuIndexStatusResponder },
  172. { certUsageAnyCA, ekuIndexUnknown },
  173. };
  174. /*
  175. * FUNCTION: cert_NssCertificateUsageToPkixKUAndEKU
  176. * DESCRIPTION:
  177. *
  178. * Converts nss CERTCertificateUsage bit field to pkix key and
  179. * extended key usages.
  180. *
  181. * PARAMETERS:
  182. * "cert"
  183. * Pointer to CERTCertificate structure of validating cert.
  184. * "requiredCertUsages"
  185. * Required usage that will be converted to pkix eku and ku.
  186. * "requiredKeyUsage",
  187. * Additional key usages impose to cert.
  188. * "isCA",
  189. * it true, convert usages for cert that is a CA cert.
  190. * "ppkixEKUList"
  191. * Returned address of a list of pkix extended key usages.
  192. * "ppkixKU"
  193. * Returned address of pkix required key usages bit field.
  194. * "plContext"
  195. * Platform-specific context pointer.
  196. * THREAD SAFETY:
  197. * Thread Safe (see Thread Safety Definitions in Programmer's Guide)
  198. * RETURNS:
  199. * Returns NULL if the function succeeds.
  200. * Returns a Cert Verify Error if the function fails in an unrecoverable way.
  201. * Returns a Fatal Error if the function fails in an unrecoverable way.
  202. */
  203. static PKIX_Error *
  204. cert_NssCertificateUsageToPkixKUAndEKU(
  205. CERTCertificate *cert,
  206. SECCertUsage requiredCertUsage,
  207. PRUint32 requiredKeyUsages,
  208. PRBool isCA,
  209. PKIX_List **ppkixEKUList,
  210. PKIX_UInt32 *ppkixKU,
  211. void *plContext)
  212. {
  213. PKIX_List *ekuOidsList = NULL;
  214. PKIX_PL_OID *ekuOid = NULL;
  215. int i = 0;
  216. int ekuIndex = ekuIndexUnknown;
  217. PKIX_ENTER(CERTVFYPKIX, "cert_NssCertificateUsageToPkixEku");
  218. PKIX_NULLCHECK_TWO(ppkixEKUList, ppkixKU);
  219. PKIX_CHECK(
  220. PKIX_List_Create(&ekuOidsList, plContext),
  221. PKIX_LISTCREATEFAILED);
  222. for (; i < PR_ARRAY_SIZE(certUsageEkuStringMap); i++) {
  223. const SECCertUsageToEku *usageToEkuElem =
  224. &certUsageEkuStringMap[i];
  225. if (usageToEkuElem->certUsage == requiredCertUsage) {
  226. ekuIndex = usageToEkuElem->ekuStringIndex;
  227. break;
  228. }
  229. }
  230. if (ekuIndex != ekuIndexUnknown) {
  231. PRUint32 reqKeyUsage = 0;
  232. PRUint32 reqCertType = 0;
  233. CERT_KeyUsageAndTypeForCertUsage(requiredCertUsage, isCA,
  234. &reqKeyUsage,
  235. &reqCertType);
  236. requiredKeyUsages |= reqKeyUsage;
  237. PKIX_CHECK(
  238. PKIX_PL_OID_Create(ekuOidStrings[ekuIndex], &ekuOid,
  239. plContext),
  240. PKIX_OIDCREATEFAILED);
  241. PKIX_CHECK(
  242. PKIX_List_AppendItem(ekuOidsList, (PKIX_PL_Object *)ekuOid,
  243. plContext),
  244. PKIX_LISTAPPENDITEMFAILED);
  245. PKIX_DECREF(ekuOid);
  246. }
  247. PKIX_CHECK(
  248. cert_NssKeyUsagesToPkix(requiredKeyUsages, ppkixKU, plContext),
  249. PKIX_NSSCERTIFICATEUSAGETOPKIXKUANDEKUFAILED);
  250. *ppkixEKUList = ekuOidsList;
  251. ekuOidsList = NULL;
  252. cleanup:
  253. PKIX_DECREF(ekuOid);
  254. PKIX_DECREF(ekuOidsList);
  255. PKIX_RETURN(CERTVFYPKIX);
  256. }
  257. #endif
  258. /*
  259. * FUNCTION: cert_ProcessingParamsSetKeyAndCertUsage
  260. * DESCRIPTION:
  261. *
  262. * Converts cert usage to pkix KU type and sets
  263. * converted data into PKIX_ProcessingParams object. It also sets
  264. * proper cert usage into nsscontext object.
  265. *
  266. * PARAMETERS:
  267. * "procParams"
  268. * Pointer to PKIX_ProcessingParams used during validation.
  269. * "requiredCertUsage"
  270. * Required certificate usages the certificate and chain is built and
  271. * validated for.
  272. * "requiredKeyUsage"
  273. * Request additional key usages the certificate should be validated for.
  274. * "plContext"
  275. * Platform-specific context pointer.
  276. * THREAD SAFETY:
  277. * Thread Safe (see Thread Safety Definitions in Programmer's Guide)
  278. * RETURNS:
  279. * Returns NULL if the function succeeds.
  280. * Returns a Cert Verify Error if the function fails in an unrecoverable way.
  281. * Returns a Fatal Error if the function fails in an unrecoverable way.
  282. */
  283. static PKIX_Error *
  284. cert_ProcessingParamsSetKeyAndCertUsage(
  285. PKIX_ProcessingParams *procParams,
  286. SECCertUsage requiredCertUsage,
  287. PRUint32 requiredKeyUsages,
  288. void *plContext)
  289. {
  290. PKIX_CertSelector *certSelector = NULL;
  291. PKIX_ComCertSelParams *certSelParams = NULL;
  292. PKIX_PL_NssContext *nssContext = (PKIX_PL_NssContext *)plContext;
  293. PKIX_ENTER(CERTVFYPKIX, "cert_ProcessingParamsSetKeyAndCertUsage");
  294. PKIX_NULLCHECK_TWO(procParams, nssContext);
  295. PKIX_CHECK(
  296. pkix_pl_NssContext_SetCertUsage(
  297. ((SECCertificateUsage)1) << requiredCertUsage, nssContext),
  298. PKIX_NSSCONTEXTSETCERTUSAGEFAILED);
  299. if (requiredKeyUsages) {
  300. PKIX_CHECK(
  301. PKIX_ProcessingParams_GetTargetCertConstraints(procParams,
  302. &certSelector, plContext),
  303. PKIX_PROCESSINGPARAMSGETTARGETCERTCONSTRAINTSFAILED);
  304. PKIX_CHECK(
  305. PKIX_CertSelector_GetCommonCertSelectorParams(certSelector,
  306. &certSelParams, plContext),
  307. PKIX_CERTSELECTORGETCOMMONCERTSELECTORPARAMSFAILED);
  308. PKIX_CHECK(
  309. PKIX_ComCertSelParams_SetKeyUsage(certSelParams, requiredKeyUsages,
  310. plContext),
  311. PKIX_COMCERTSELPARAMSSETKEYUSAGEFAILED);
  312. }
  313. cleanup:
  314. PKIX_DECREF(certSelector);
  315. PKIX_DECREF(certSelParams);
  316. PKIX_RETURN(CERTVFYPKIX);
  317. }
  318. /*
  319. * Unused parameters:
  320. *
  321. * CERTCertList *initialChain,
  322. * CERTCertStores certStores,
  323. * CERTCertRevCheckers certRevCheckers,
  324. * CERTCertChainCheckers certChainCheckers,
  325. * SECItem *initPolicies,
  326. * PRBool policyQualifierRejected,
  327. * PRBool anyPolicyInhibited,
  328. * PRBool reqExplicitPolicy,
  329. * PRBool policyMappingInhibited,
  330. * PKIX_CertSelector certConstraints,
  331. */
  332. /*
  333. * FUNCTION: cert_CreatePkixProcessingParams
  334. * DESCRIPTION:
  335. *
  336. * Creates and fills in PKIX_ProcessingParams structure to be used
  337. * for certificate chain building.
  338. *
  339. * PARAMETERS:
  340. * "cert"
  341. * Pointer to the CERTCertificate: the leaf certificate of a chain.
  342. * "time"
  343. * Validity time.
  344. * "wincx"
  345. * Nss db password token.
  346. * "useArena"
  347. * Flags to use arena for data allocation during chain building process.
  348. * "pprocParams"
  349. * Address to return created processing parameters.
  350. * "plContext"
  351. * Platform-specific context pointer.
  352. * THREAD SAFETY:
  353. * Thread Safe (see Thread Safety Definitions in Programmer's Guide)
  354. * RETURNS:
  355. * Returns NULL if the function succeeds.
  356. * Returns a Cert Verify Error if the function fails in an unrecoverable way.
  357. * Returns a Fatal Error if the function fails in an unrecoverable way.
  358. */
  359. static PKIX_Error *
  360. cert_CreatePkixProcessingParams(
  361. CERTCertificate *cert,
  362. PRBool checkSig, /* not used yet. See bug 391476 */
  363. PRTime time,
  364. void *wincx,
  365. PRBool useArena,
  366. PRBool disableOCSPRemoteFetching,
  367. PKIX_ProcessingParams **pprocParams,
  368. void **pplContext)
  369. {
  370. PKIX_List *anchors = NULL;
  371. PKIX_PL_Cert *targetCert = NULL;
  372. PKIX_PL_Date *date = NULL;
  373. PKIX_ProcessingParams *procParams = NULL;
  374. PKIX_CertSelector *certSelector = NULL;
  375. PKIX_ComCertSelParams *certSelParams = NULL;
  376. PKIX_CertStore *certStore = NULL;
  377. PKIX_List *certStores = NULL;
  378. PKIX_RevocationChecker *revChecker = NULL;
  379. PKIX_UInt32 methodFlags = 0;
  380. void *plContext = NULL;
  381. CERTStatusConfig *statusConfig = NULL;
  382. PKIX_ENTER(CERTVFYPKIX, "cert_CreatePkixProcessingParams");
  383. PKIX_NULLCHECK_TWO(cert, pprocParams);
  384. PKIX_CHECK(
  385. PKIX_PL_NssContext_Create(0, useArena, wincx, &plContext),
  386. PKIX_NSSCONTEXTCREATEFAILED);
  387. *pplContext = plContext;
  388. #ifdef PKIX_NOTDEF
  389. /* Functions should be implemented in patch for 390532 */
  390. PKIX_CHECK(
  391. pkix_pl_NssContext_SetCertSignatureCheck(checkSig,
  392. (PKIX_PL_NssContext *)plContext),
  393. PKIX_NSSCONTEXTSETCERTSIGNCHECKFAILED);
  394. #endif /* PKIX_NOTDEF */
  395. PKIX_CHECK(
  396. PKIX_ProcessingParams_Create(&procParams, plContext),
  397. PKIX_PROCESSINGPARAMSCREATEFAILED);
  398. PKIX_CHECK(
  399. PKIX_ComCertSelParams_Create(&certSelParams, plContext),
  400. PKIX_COMCERTSELPARAMSCREATEFAILED);
  401. PKIX_CHECK(
  402. PKIX_PL_Cert_CreateFromCERTCertificate(cert, &targetCert, plContext),
  403. PKIX_CERTCREATEWITHNSSCERTFAILED);
  404. PKIX_CHECK(
  405. PKIX_ComCertSelParams_SetCertificate(certSelParams,
  406. targetCert, plContext),
  407. PKIX_COMCERTSELPARAMSSETCERTIFICATEFAILED);
  408. PKIX_CHECK(
  409. PKIX_CertSelector_Create(NULL, NULL, &certSelector, plContext),
  410. PKIX_COULDNOTCREATECERTSELECTOROBJECT);
  411. PKIX_CHECK(
  412. PKIX_CertSelector_SetCommonCertSelectorParams(certSelector,
  413. certSelParams, plContext),
  414. PKIX_CERTSELECTORSETCOMMONCERTSELECTORPARAMSFAILED);
  415. PKIX_CHECK(
  416. PKIX_ProcessingParams_SetTargetCertConstraints(procParams,
  417. certSelector, plContext),
  418. PKIX_PROCESSINGPARAMSSETTARGETCERTCONSTRAINTSFAILED);
  419. /* Turn off quialification of target cert since leaf cert is
  420. * already check for date validity, key usages and extended
  421. * key usages. */
  422. PKIX_CHECK(
  423. PKIX_ProcessingParams_SetQualifyTargetCert(procParams, PKIX_FALSE,
  424. plContext),
  425. PKIX_PROCESSINGPARAMSSETQUALIFYTARGETCERTFLAGFAILED);
  426. PKIX_CHECK(
  427. PKIX_PL_Pk11CertStore_Create(&certStore, plContext),
  428. PKIX_PK11CERTSTORECREATEFAILED);
  429. PKIX_CHECK(
  430. PKIX_List_Create(&certStores, plContext),
  431. PKIX_UNABLETOCREATELIST);
  432. PKIX_CHECK(
  433. PKIX_List_AppendItem(certStores, (PKIX_PL_Object *)certStore,
  434. plContext),
  435. PKIX_LISTAPPENDITEMFAILED);
  436. PKIX_CHECK(
  437. PKIX_ProcessingParams_SetCertStores(procParams, certStores,
  438. plContext),
  439. PKIX_PROCESSINGPARAMSADDCERTSTOREFAILED);
  440. PKIX_CHECK(
  441. PKIX_PL_Date_CreateFromPRTime(time, &date, plContext),
  442. PKIX_DATECREATEFROMPRTIMEFAILED);
  443. PKIX_CHECK(
  444. PKIX_ProcessingParams_SetDate(procParams, date, plContext),
  445. PKIX_PROCESSINGPARAMSSETDATEFAILED);
  446. PKIX_CHECK(
  447. PKIX_RevocationChecker_Create(
  448. PKIX_REV_MI_TEST_ALL_LOCAL_INFORMATION_FIRST |
  449. PKIX_REV_MI_NO_OVERALL_INFO_REQUIREMENT,
  450. PKIX_REV_MI_TEST_ALL_LOCAL_INFORMATION_FIRST |
  451. PKIX_REV_MI_NO_OVERALL_INFO_REQUIREMENT,
  452. &revChecker, plContext),
  453. PKIX_REVOCATIONCHECKERCREATEFAILED);
  454. PKIX_CHECK(
  455. PKIX_ProcessingParams_SetRevocationChecker(procParams, revChecker,
  456. plContext),
  457. PKIX_PROCESSINGPARAMSSETREVOCATIONCHECKERFAILED);
  458. /* CRL method flags */
  459. methodFlags =
  460. PKIX_REV_M_TEST_USING_THIS_METHOD |
  461. PKIX_REV_M_FORBID_NETWORK_FETCHING |
  462. PKIX_REV_M_SKIP_TEST_ON_MISSING_SOURCE | /* 0 */
  463. PKIX_REV_M_IGNORE_MISSING_FRESH_INFO | /* 0 */
  464. PKIX_REV_M_CONTINUE_TESTING_ON_FRESH_INFO;
  465. /* add CRL revocation method to check the leaf certificate */
  466. PKIX_CHECK(
  467. PKIX_RevocationChecker_CreateAndAddMethod(revChecker, procParams,
  468. PKIX_RevocationMethod_CRL, methodFlags,
  469. 0, NULL, PKIX_TRUE, plContext),
  470. PKIX_REVOCATIONCHECKERADDMETHODFAILED);
  471. /* add CRL revocation method for other certs in the chain. */
  472. PKIX_CHECK(
  473. PKIX_RevocationChecker_CreateAndAddMethod(revChecker, procParams,
  474. PKIX_RevocationMethod_CRL, methodFlags,
  475. 0, NULL, PKIX_FALSE, plContext),
  476. PKIX_REVOCATIONCHECKERADDMETHODFAILED);
  477. /* For compatibility with the old code, need to check that
  478. * statusConfig is set in the db handle and status checker
  479. * is defined befor allow ocsp status check on the leaf cert.*/
  480. statusConfig = CERT_GetStatusConfig(CERT_GetDefaultCertDB());
  481. if (statusConfig != NULL && statusConfig->statusChecker != NULL) {
  482. /* Enable OCSP revocation checking for the leaf cert. */
  483. /* OCSP method flags */
  484. methodFlags =
  485. PKIX_REV_M_TEST_USING_THIS_METHOD |
  486. PKIX_REV_M_ALLOW_NETWORK_FETCHING | /* 0 */
  487. PKIX_REV_M_ALLOW_IMPLICIT_DEFAULT_SOURCE | /* 0 */
  488. PKIX_REV_M_SKIP_TEST_ON_MISSING_SOURCE | /* 0 */
  489. PKIX_REV_M_IGNORE_MISSING_FRESH_INFO | /* 0 */
  490. PKIX_REV_M_CONTINUE_TESTING_ON_FRESH_INFO;
  491. /* Disabling ocsp fetching when checking the status
  492. * of ocsp response signer. Here and in the next if,
  493. * adjust flags for ocsp signer cert validation case. */
  494. if (disableOCSPRemoteFetching) {
  495. methodFlags |= PKIX_REV_M_FORBID_NETWORK_FETCHING;
  496. }
  497. if (ocsp_FetchingFailureIsVerificationFailure() &&
  498. !disableOCSPRemoteFetching) {
  499. methodFlags |=
  500. PKIX_REV_M_FAIL_ON_MISSING_FRESH_INFO;
  501. }
  502. /* add OCSP revocation method to check only the leaf certificate.*/
  503. PKIX_CHECK(
  504. PKIX_RevocationChecker_CreateAndAddMethod(revChecker, procParams,
  505. PKIX_RevocationMethod_OCSP, methodFlags,
  506. 1, NULL, PKIX_TRUE, plContext),
  507. PKIX_REVOCATIONCHECKERADDMETHODFAILED);
  508. }
  509. PKIX_CHECK(
  510. PKIX_ProcessingParams_SetAnyPolicyInhibited(procParams, PR_FALSE,
  511. plContext),
  512. PKIX_PROCESSINGPARAMSSETANYPOLICYINHIBITED);
  513. PKIX_CHECK(
  514. PKIX_ProcessingParams_SetExplicitPolicyRequired(procParams, PR_FALSE,
  515. plContext),
  516. PKIX_PROCESSINGPARAMSSETEXPLICITPOLICYREQUIRED);
  517. PKIX_CHECK(
  518. PKIX_ProcessingParams_SetPolicyMappingInhibited(procParams, PR_FALSE,
  519. plContext),
  520. PKIX_PROCESSINGPARAMSSETPOLICYMAPPINGINHIBITED);
  521. *pprocParams = procParams;
  522. procParams = NULL;
  523. cleanup:
  524. PKIX_DECREF(anchors);
  525. PKIX_DECREF(targetCert);
  526. PKIX_DECREF(date);
  527. PKIX_DECREF(certSelector);
  528. PKIX_DECREF(certSelParams);
  529. PKIX_DECREF(certStore);
  530. PKIX_DECREF(certStores);
  531. PKIX_DECREF(procParams);
  532. PKIX_DECREF(revChecker);
  533. PKIX_RETURN(CERTVFYPKIX);
  534. }
  535. /*
  536. * FUNCTION: cert_PkixToNssCertsChain
  537. * DESCRIPTION:
  538. *
  539. * Converts pkix cert list into nss cert list.
  540. *
  541. * PARAMETERS:
  542. * "pkixCertChain"
  543. * Pkix certificate list.
  544. * "pvalidChain"
  545. * An address of returned nss certificate list.
  546. * "plContext"
  547. * Platform-specific context pointer.
  548. * THREAD SAFETY:
  549. * Thread Safe (see Thread Safety Definitions in Programmer's Guide)
  550. * RETURNS:
  551. * Returns NULL if the function succeeds.
  552. * Returns a Cert Verify Error if the function fails in an unrecoverable way.
  553. * Returns a Fatal Error if the function fails in an unrecoverable way.
  554. */
  555. static PKIX_Error *
  556. cert_PkixToNssCertsChain(
  557. PKIX_List *pkixCertChain,
  558. CERTCertList **pvalidChain,
  559. void *plContext)
  560. {
  561. PLArenaPool *arena = NULL;
  562. CERTCertificate *nssCert = NULL;
  563. CERTCertList *validChain = NULL;
  564. PKIX_PL_Object *certItem = NULL;
  565. PKIX_UInt32 length = 0;
  566. PKIX_UInt32 i = 0;
  567. PKIX_ENTER(CERTVFYPKIX, "cert_PkixToNssCertsChain");
  568. PKIX_NULLCHECK_ONE(pvalidChain);
  569. if (pkixCertChain == NULL) {
  570. goto cleanup;
  571. }
  572. arena = PORT_NewArena(DER_DEFAULT_CHUNKSIZE);
  573. if (arena == NULL) {
  574. PKIX_ERROR(PKIX_OUTOFMEMORY);
  575. }
  576. validChain = (CERTCertList *)PORT_ArenaZAlloc(arena, sizeof(CERTCertList));
  577. if (validChain == NULL) {
  578. PKIX_ERROR(PKIX_PORTARENAALLOCFAILED);
  579. }
  580. PR_INIT_CLIST(&validChain->list);
  581. validChain->arena = arena;
  582. arena = NULL;
  583. PKIX_CHECK(
  584. PKIX_List_GetLength(pkixCertChain, &length, plContext),
  585. PKIX_LISTGETLENGTHFAILED);
  586. for (i = 0; i < length; i++) {
  587. CERTCertListNode *node = NULL;
  588. PKIX_CHECK(
  589. PKIX_List_GetItem(pkixCertChain, i, &certItem, plContext),
  590. PKIX_LISTGETITEMFAILED);
  591. PKIX_CHECK(
  592. PKIX_PL_Cert_GetCERTCertificate((PKIX_PL_Cert *)certItem, &nssCert,
  593. plContext),
  594. PKIX_CERTGETCERTCERTIFICATEFAILED);
  595. node =
  596. (CERTCertListNode *)PORT_ArenaZAlloc(validChain->arena,
  597. sizeof(CERTCertListNode));
  598. if (node == NULL) {
  599. PKIX_ERROR(PKIX_PORTARENAALLOCFAILED);
  600. }
  601. PR_INSERT_BEFORE(&node->links, &validChain->list);
  602. node->cert = nssCert;
  603. nssCert = NULL;
  604. PKIX_DECREF(certItem);
  605. }
  606. *pvalidChain = validChain;
  607. cleanup:
  608. if (PKIX_ERROR_RECEIVED) {
  609. if (validChain) {
  610. CERT_DestroyCertList(validChain);
  611. } else if (arena) {
  612. PORT_FreeArena(arena, PR_FALSE);
  613. }
  614. if (nssCert) {
  615. CERT_DestroyCertificate(nssCert);
  616. }
  617. }
  618. PKIX_DECREF(certItem);
  619. PKIX_RETURN(CERTVFYPKIX);
  620. }
  621. /*
  622. * FUNCTION: cert_BuildAndValidateChain
  623. * DESCRIPTION:
  624. *
  625. * The function builds and validates a cert chain based on certificate
  626. * selection criterias from procParams. This function call PKIX_BuildChain
  627. * to accomplish chain building. If PKIX_BuildChain returns with incomplete
  628. * IO, the function waits with PR_Poll until the blocking IO is finished and
  629. * return control back to PKIX_BuildChain.
  630. *
  631. * PARAMETERS:
  632. * "procParams"
  633. * Processing parameters to be used during chain building.
  634. * "pResult"
  635. * Returned build result.
  636. * "pVerifyNode"
  637. * Returned pointed to verify node structure: the tree-like structure
  638. * that reports points of chain building failures.
  639. * "plContext"
  640. * Platform-specific context pointer.
  641. * THREAD SAFETY:
  642. * Thread Safe (see Thread Safety Definitions in Programmer's Guide)
  643. * RETURNS:
  644. * Returns NULL if the function succeeds.
  645. * Returns a Cert Verify Error if the function fails in an unrecoverable way.
  646. * Returns a Fatal Error if the function fails in an unrecoverable way.
  647. */
  648. static PKIX_Error *
  649. cert_BuildAndValidateChain(
  650. PKIX_ProcessingParams *procParams,
  651. PKIX_BuildResult **pResult,
  652. PKIX_VerifyNode **pVerifyNode,
  653. void *plContext)
  654. {
  655. PKIX_BuildResult *result = NULL;
  656. PKIX_VerifyNode *verifyNode = NULL;
  657. void *nbioContext = NULL;
  658. void *state = NULL;
  659. PKIX_ENTER(CERTVFYPKIX, "cert_BuildAndVerifyChain");
  660. PKIX_NULLCHECK_TWO(procParams, pResult);
  661. do {
  662. if (nbioContext && state) {
  663. /* PKIX-XXX: need to test functionality of NBIO handling in libPkix.
  664. * See bug 391180 */
  665. PRInt32 filesReady = 0;
  666. PRPollDesc *pollDesc = (PRPollDesc *)nbioContext;
  667. filesReady = PR_Poll(pollDesc, 1, PR_INTERVAL_NO_TIMEOUT);
  668. if (filesReady <= 0) {
  669. PKIX_ERROR(PKIX_PRPOLLRETBADFILENUM);
  670. }
  671. }
  672. PKIX_CHECK(
  673. PKIX_BuildChain(procParams, &nbioContext, &state,
  674. &result, &verifyNode, plContext),
  675. PKIX_UNABLETOBUILDCHAIN);
  676. } while (nbioContext && state);
  677. *pResult = result;
  678. cleanup:
  679. if (pVerifyNode) {
  680. *pVerifyNode = verifyNode;
  681. }
  682. PKIX_RETURN(CERTVFYPKIX);
  683. }
  684. /*
  685. * FUNCTION: cert_PkixErrorToNssCode
  686. * DESCRIPTION:
  687. *
  688. * Converts pkix error(PKIX_Error) structure to PR error codes.
  689. *
  690. * PKIX-XXX to be implemented. See 391183.
  691. *
  692. * PARAMETERS:
  693. * "error"
  694. * Pkix error that will be converted.
  695. * "nssCode"
  696. * Corresponding nss error code.
  697. * "plContext"
  698. * Platform-specific context pointer.
  699. * THREAD SAFETY:
  700. * Thread Safe (see Thread Safety Definitions in Programmer's Guide)
  701. * RETURNS:
  702. * Returns NULL if the function succeeds.
  703. * Returns a Cert Verify Error if the function fails in an unrecoverable way.
  704. * Returns a Fatal Error if the function fails in an unrecoverable way.
  705. */
  706. static PKIX_Error *
  707. cert_PkixErrorToNssCode(
  708. PKIX_Error *error,
  709. SECErrorCodes *pNssErr,
  710. void *plContext)
  711. {
  712. int errLevel = 0;
  713. PKIX_Int32 nssErr = 0;
  714. PKIX_Error *errPtr = error;
  715. PKIX_ENTER(CERTVFYPKIX, "cert_PkixErrorToNssCode");
  716. PKIX_NULLCHECK_TWO(error, pNssErr);
  717. /* Loop until we find at least one error with non-null
  718. * plErr code, that is going to be nss error code. */
  719. while (errPtr) {
  720. if (errPtr->plErr && !nssErr) {
  721. nssErr = errPtr->plErr;
  722. if (!pkixLog)
  723. break;
  724. }
  725. if (pkixLog) {
  726. #ifdef PKIX_ERROR_DESCRIPTION
  727. PR_LOG(pkixLog, 2, ("Error at level %d: %s\n", errLevel,
  728. PKIX_ErrorText[errPtr->errCode]));
  729. #else
  730. PR_LOG(pkixLog, 2, ("Error at level %d: Error code %d\n", errLevel,
  731. errPtr->errCode));
  732. #endif /* PKIX_ERROR_DESCRIPTION */
  733. }
  734. errPtr = errPtr->cause;
  735. errLevel += 1;
  736. }
  737. PORT_Assert(nssErr);
  738. if (!nssErr) {
  739. *pNssErr = SEC_ERROR_LIBPKIX_INTERNAL;
  740. } else {
  741. *pNssErr = nssErr;
  742. }
  743. PKIX_RETURN(CERTVFYPKIX);
  744. }
  745. /*
  746. * FUNCTION: cert_GetLogFromVerifyNode
  747. * DESCRIPTION:
  748. *
  749. * Recursive function that converts verify node tree-like set of structures
  750. * to CERTVerifyLog.
  751. *
  752. * PARAMETERS:
  753. * "log"
  754. * Pointed to already allocated CERTVerifyLog structure.
  755. * "node"
  756. * A node of PKIX_VerifyNode tree.
  757. * "plContext"
  758. * Platform-specific context pointer.
  759. * THREAD SAFETY:
  760. * Thread Safe (see Thread Safety Definitions in Programmer's Guide)
  761. * RETURNS:
  762. * Returns NULL if the function succeeds.
  763. * Returns a Cert Verify Error if the function fails in an unrecoverable way.
  764. * Returns a Fatal Error if the function fails in an unrecoverable way.
  765. */
  766. static PKIX_Error *
  767. cert_GetLogFromVerifyNode(
  768. CERTVerifyLog *log,
  769. PKIX_VerifyNode *node,
  770. void *plContext)
  771. {
  772. PKIX_List *children = NULL;
  773. PKIX_VerifyNode *childNode = NULL;
  774. PKIX_ENTER(CERTVFYPKIX, "cert_GetLogFromVerifyNode");
  775. children = node->children;
  776. if (children == NULL) {
  777. PKIX_ERRORCODE errCode = PKIX_ANCHORDIDNOTCHAINTOCERT;
  778. if (node->error && node->error->errCode != errCode) {
  779. if (log != NULL) {
  780. SECErrorCodes nssErrorCode = 0;
  781. CERTCertificate *cert = NULL;
  782. cert = node->verifyCert->nssCert;
  783. PKIX_CHECK(
  784. cert_PkixErrorToNssCode(node->error, &nssErrorCode,
  785. plContext),
  786. PKIX_GETPKIXERRORCODEFAILED);
  787. cert_AddToVerifyLog(log, cert, nssErrorCode, node->depth, NULL);
  788. }
  789. }
  790. PKIX_RETURN(CERTVFYPKIX);
  791. } else {
  792. PRUint32 i = 0;
  793. PKIX_UInt32 length = 0;
  794. PKIX_CHECK(
  795. PKIX_List_GetLength(children, &length, plContext),
  796. PKIX_LISTGETLENGTHFAILED);
  797. for (i = 0; i < length; i++) {
  798. PKIX_CHECK(
  799. PKIX_List_GetItem(children, i, (PKIX_PL_Object **)&childNode,
  800. plContext),
  801. PKIX_LISTGETITEMFAILED);
  802. PKIX_CHECK(
  803. cert_GetLogFromVerifyNode(log, childNode, plContext),
  804. PKIX_ERRORINRECURSIVEEQUALSCALL);
  805. PKIX_DECREF(childNode);
  806. }
  807. }
  808. cleanup:
  809. PKIX_DECREF(childNode);
  810. PKIX_RETURN(CERTVFYPKIX);
  811. }
  812. /*
  813. * FUNCTION: cert_GetBuildResults
  814. * DESCRIPTION:
  815. *
  816. * Converts pkix build results to nss results. This function is called
  817. * regardless of build result.
  818. *
  819. * If it called after chain was successfully constructed, then it will
  820. * convert:
  821. * * pkix cert list that represent the chain to nss cert list
  822. * * trusted root the chain was anchored to nss certificate.
  823. *
  824. * In case of failure it will convert:
  825. * * pkix error to PR error code(will set it with PORT_SetError)
  826. * * pkix validation log to nss CERTVerifyLog
  827. *
  828. * PARAMETERS:
  829. * "buildResult"
  830. * Build results returned by PKIX_BuildChain.
  831. * "verifyNode"
  832. * Tree-like structure of chain building/validation failures
  833. * returned by PKIX_BuildChain. Ignored in case of success.
  834. * "error"
  835. * Final error returned by PKIX_BuildChain. Should be NULL in
  836. * case of success.
  837. * "log"
  838. * Address of pre-allocated(if not NULL) CERTVerifyLog structure.
  839. * "ptrustedRoot"
  840. * Address of returned trusted root the chain was anchored to.
  841. * "pvalidChain"
  842. * Address of returned valid chain.
  843. * "plContext"
  844. * Platform-specific context pointer.
  845. * THREAD SAFETY:
  846. * Thread Safe (see Thread Safety Definitions in Programmer's Guide)
  847. * RETURNS:
  848. * Returns NULL if the function succeeds.
  849. * Returns a Cert Verify Error if the function fails in an unrecoverable way.
  850. * Returns a Fatal Error if the function fails in an unrecoverable way.
  851. */
  852. static PKIX_Error *
  853. cert_GetBuildResults(
  854. PKIX_BuildResult *buildResult,
  855. PKIX_VerifyNode *verifyNode,
  856. PKIX_Error *error,
  857. CERTVerifyLog *log,
  858. CERTCertificate **ptrustedRoot,
  859. CERTCertList **pvalidChain,
  860. void *plContext)
  861. {
  862. PKIX_ValidateResult *validResult = NULL;
  863. CERTCertList *validChain = NULL;
  864. CERTCertificate *trustedRoot = NULL;
  865. PKIX_TrustAnchor *trustAnchor = NULL;
  866. PKIX_PL_Cert *trustedCert = NULL;
  867. PKIX_List *pkixCertChain = NULL;
  868. PKIX_ENTER(CERTVFYPKIX, "cert_GetBuildResults");
  869. if (buildResult == NULL && error == NULL) {
  870. PKIX_ERROR(PKIX_NULLARGUMENT);
  871. }
  872. if (error) {
  873. SECErrorCodes nssErrorCode = 0;
  874. if (verifyNode) {
  875. PKIX_Error *tmpError =
  876. cert_GetLogFromVerifyNode(log, verifyNode, plContext);
  877. if (tmpError) {
  878. PKIX_PL_Object_DecRef((PKIX_PL_Object *)tmpError, plContext);
  879. }
  880. }
  881. cert_PkixErrorToNssCode(error, &nssErrorCode, plContext);
  882. PORT_SetError(nssErrorCode);
  883. goto cleanup;
  884. }
  885. if (pvalidChain) {
  886. PKIX_CHECK(
  887. PKIX_BuildResult_GetCertChain(buildResult, &pkixCertChain,
  888. plContext),
  889. PKIX_BUILDRESULTGETCERTCHAINFAILED);
  890. PKIX_CHECK(
  891. cert_PkixToNssCertsChain(pkixCertChain, &validChain, plContext),
  892. PKIX_CERTCHAINTONSSCHAINFAILED);
  893. }
  894. if (ptrustedRoot) {
  895. PKIX_CHECK(
  896. PKIX_BuildResult_GetValidateResult(buildResult, &validResult,
  897. plContext),
  898. PKIX_BUILDRESULTGETVALIDATERESULTFAILED);
  899. PKIX_CHECK(
  900. PKIX_ValidateResult_GetTrustAnchor(validResult, &trustAnchor,
  901. plContext),
  902. PKIX_VALIDATERESULTGETTRUSTANCHORFAILED);
  903. PKIX_CHECK(
  904. PKIX_TrustAnchor_GetTrustedCert(trustAnchor, &trustedCert,
  905. plContext),
  906. PKIX_TRUSTANCHORGETTRUSTEDCERTFAILED);
  907. PKIX_CHECK(
  908. PKIX_PL_Cert_GetCERTCertificate(trustedCert, &trustedRoot,
  909. plContext),
  910. PKIX_CERTGETCERTCERTIFICATEFAILED);
  911. }
  912. PORT_Assert(!PKIX_ERROR_RECEIVED);
  913. if (trustedRoot) {
  914. *ptrustedRoot = trustedRoot;
  915. }
  916. if (validChain) {
  917. *pvalidChain = validChain;
  918. }
  919. cleanup:
  920. if (PKIX_ERROR_RECEIVED) {
  921. if (trustedRoot) {
  922. CERT_DestroyCertificate(trustedRoot);
  923. }
  924. if (validChain) {
  925. CERT_DestroyCertList(validChain);
  926. }
  927. }
  928. PKIX_DECREF(trustAnchor);
  929. PKIX_DECREF(trustedCert);
  930. PKIX_DECREF(pkixCertChain);
  931. PKIX_DECREF(validResult);
  932. PKIX_DECREF(error);
  933. PKIX_DECREF(verifyNode);
  934. PKIX_DECREF(buildResult);
  935. PKIX_RETURN(CERTVFYPKIX);
  936. }
  937. #endif /* NSS_DISABLE_LIBPKIX */
  938. /*
  939. * FUNCTION: cert_VerifyCertChainPkix
  940. * DESCRIPTION:
  941. *
  942. * The main wrapper function that is called from CERT_VerifyCert and
  943. * CERT_VerifyCACertForUsage functions to validate cert with libpkix.
  944. *
  945. * PARAMETERS:
  946. * "cert"
  947. * Leaf certificate of a chain we want to build.
  948. * "checkSig"
  949. * Certificate signatures will not be verified if this
  950. * flag is set to PR_FALSE.
  951. * "requiredUsage"
  952. * Required usage for certificate and chain.
  953. * "time"
  954. * Validity time.
  955. * "wincx"
  956. * Nss database password token.
  957. * "log"
  958. * Address of already allocated CERTVerifyLog structure. Not
  959. * used if NULL;
  960. * "pSigerror"
  961. * Address of PRBool. If not NULL, returns true is cert chain
  962. * was invalidated because of bad certificate signature.
  963. * "pRevoked"
  964. * Address of PRBool. If not NULL, returns true is cert chain
  965. * was invalidated because a revoked certificate was found in
  966. * the chain.
  967. * THREAD SAFETY:
  968. * Thread Safe (see Thread Safety Definitions in Programmer's Guide)
  969. * RETURNS:
  970. * SECFailure is chain building process has failed. SECSuccess otherwise.
  971. */
  972. SECStatus
  973. cert_VerifyCertChainPkix(
  974. CERTCertificate *cert,
  975. PRBool checkSig,
  976. SECCertUsage requiredUsage,
  977. PRTime time,
  978. void *wincx,
  979. CERTVerifyLog *log,
  980. PRBool *pSigerror,
  981. PRBool *pRevoked)
  982. {
  983. #ifdef NSS_DISABLE_LIBPKIX
  984. PORT_SetError(PR_NOT_IMPLEMENTED_ERROR);
  985. return SECFailure;
  986. #else
  987. PKIX_ProcessingParams *procParams = NULL;
  988. PKIX_BuildResult *result = NULL;
  989. PKIX_VerifyNode *verifyNode = NULL;
  990. PKIX_Error *error = NULL;
  991. SECStatus rv = SECFailure;
  992. void *plContext = NULL;
  993. #ifdef PKIX_OBJECT_LEAK_TEST
  994. int leakedObjNum = 0;
  995. int memLeakLoopCount = 0;
  996. int objCountTable[PKIX_NUMTYPES];
  997. int fnInvLocalCount = 0;
  998. PKIX_Boolean savedUsePkixEngFlag = usePKIXValidationEngine;
  999. if (usePKIXValidationEngine) {
  1000. /* current memory leak testing implementation does not allow
  1001. * to run simultaneous tests one the same or a different threads.
  1002. * Setting the variable to false, to make additional chain
  1003. * validations be handled by old nss. */
  1004. usePKIXValidationEngine = PR_FALSE;
  1005. }
  1006. testStartFnStackPosition = 2;
  1007. fnStackNameArr[0] = "cert_VerifyCertChainPkix";
  1008. fnStackInvCountArr[0] = 0;
  1009. PKIX_Boolean abortOnLeak =
  1010. (PR_GetEnvSecure("PKIX_OBJECT_LEAK_TEST_ABORT_ON_LEAK") == NULL) ? PKIX_FALSE
  1011. : PKIX_TRUE;
  1012. runningLeakTest = PKIX_TRUE;
  1013. /* Prevent multi-threaded run of object leak test */
  1014. fnInvLocalCount = PR_ATOMIC_INCREMENT(&parallelFnInvocationCount);
  1015. PORT_Assert(fnInvLocalCount == 1);
  1016. do {
  1017. rv = SECFailure;
  1018. plContext = NULL;
  1019. procParams = NULL;
  1020. result = NULL;
  1021. verifyNode = NULL;
  1022. error = NULL;
  1023. errorGenerated = PKIX_FALSE;
  1024. stackPosition = 0;
  1025. if (leakedObjNum) {
  1026. pkix_pl_lifecycle_ObjectTableUpdate(objCountTable);
  1027. }
  1028. memLeakLoopCount += 1;
  1029. #endif /* PKIX_OBJECT_LEAK_TEST */
  1030. error =
  1031. cert_CreatePkixProcessingParams(cert, checkSig, time, wincx,
  1032. PR_FALSE /*use arena*/,
  1033. requiredUsage == certUsageStatusResponder,
  1034. &procParams, &plContext);
  1035. if (error) {
  1036. goto cleanup;
  1037. }
  1038. error =
  1039. cert_ProcessingParamsSetKeyAndCertUsage(procParams, requiredUsage, 0,
  1040. plContext);
  1041. if (error) {
  1042. goto cleanup;
  1043. }
  1044. error =
  1045. cert_BuildAndValidateChain(procParams, &result, &verifyNode, plContext);
  1046. if (error) {
  1047. goto cleanup;
  1048. }
  1049. if (pRevoked) {
  1050. /* Currently always PR_FALSE. Will be fixed as a part of 394077 */
  1051. *pRevoked = PR_FALSE;
  1052. }
  1053. if (pSigerror) {
  1054. /* Currently always PR_FALSE. Will be fixed as a part of 394077 */
  1055. *pSigerror = PR_FALSE;
  1056. }
  1057. rv = SECSuccess;
  1058. cleanup:
  1059. error = cert_GetBuildResults(result, verifyNode, error, log, NULL, NULL,
  1060. plContext);
  1061. if (error) {
  1062. PKIX_PL_Object_DecRef((PKIX_PL_Object *)error, plContext);
  1063. }
  1064. if (procParams) {
  1065. PKIX_PL_Object_DecRef((PKIX_PL_Object *)procParams, plContext);
  1066. }
  1067. if (plContext) {
  1068. PKIX_PL_NssContext_Destroy(plContext);
  1069. }
  1070. #ifdef PKIX_OBJECT_LEAK_TEST
  1071. leakedObjNum =
  1072. pkix_pl_lifecycle_ObjectLeakCheck(leakedObjNum ? objCountTable : NULL);
  1073. if (pkixLog && leakedObjNum) {
  1074. PR_LOG(pkixLog, 1, ("The generated error caused an object leaks. Loop %d."
  1075. "Stack %s\n",
  1076. memLeakLoopCount, errorFnStackString));
  1077. }
  1078. PR_Free(errorFnStackString);
  1079. errorFnStackString = NULL;
  1080. if (abortOnLeak) {
  1081. PORT_Assert(leakedObjNum == 0);
  1082. }
  1083. } while (errorGenerated);
  1084. runningLeakTest = PKIX_FALSE;
  1085. PR_ATOMIC_DECREMENT(&parallelFnInvocationCount);
  1086. usePKIXValidationEngine = savedUsePkixEngFlag;
  1087. #endif /* PKIX_OBJECT_LEAK_TEST */
  1088. return rv;
  1089. #endif /* NSS_DISABLE_LIBPKIX */
  1090. }
  1091. #ifndef NSS_DISABLE_LIBPKIX
  1092. PKIX_CertSelector *
  1093. cert_GetTargetCertConstraints(CERTCertificate *target, void *plContext)
  1094. {
  1095. PKIX_ComCertSelParams *certSelParams = NULL;
  1096. PKIX_CertSelector *certSelector = NULL;
  1097. PKIX_CertSelector *r = NULL;
  1098. PKIX_PL_Cert *eeCert = NULL;
  1099. PKIX_Error *error = NULL;
  1100. error = PKIX_PL_Cert_CreateFromCERTCertificate(target, &eeCert, plContext);
  1101. if (error != NULL)
  1102. goto cleanup;
  1103. error = PKIX_CertSelector_Create(NULL, NULL, &certSelector, plContext);
  1104. if (error != NULL)
  1105. goto cleanup;
  1106. error = PKIX_ComCertSelParams_Create(&certSelParams, plContext);
  1107. if (error != NULL)
  1108. goto cleanup;
  1109. error = PKIX_ComCertSelParams_SetCertificate(
  1110. certSelParams, eeCert, plContext);
  1111. if (error != NULL)
  1112. goto cleanup;
  1113. error = PKIX_CertSelector_SetCommonCertSelectorParams(certSelector, certSelParams, plContext);
  1114. if (error != NULL)
  1115. goto cleanup;
  1116. error = PKIX_PL_Object_IncRef((PKIX_PL_Object *)certSelector, plContext);
  1117. if (error == NULL)
  1118. r = certSelector;
  1119. cleanup:
  1120. if (certSelParams != NULL)
  1121. PKIX_PL_Object_DecRef((PKIX_PL_Object *)certSelParams, plContext);
  1122. if (eeCert != NULL)
  1123. PKIX_PL_Object_DecRef((PKIX_PL_Object *)eeCert, plContext);
  1124. if (certSelector != NULL)
  1125. PKIX_PL_Object_DecRef((PKIX_PL_Object *)certSelector, plContext);
  1126. if (error != NULL) {
  1127. SECErrorCodes nssErr;
  1128. cert_PkixErrorToNssCode(error, &nssErr, plContext);
  1129. PKIX_PL_Object_DecRef((PKIX_PL_Object *)error, plContext);
  1130. PORT_SetError(nssErr);
  1131. }
  1132. return r;
  1133. }
  1134. static PKIX_List *
  1135. cert_GetCertStores(void *plContext)
  1136. {
  1137. PKIX_CertStore *certStore = NULL;
  1138. PKIX_List *certStores = NULL;
  1139. PKIX_List *r = NULL;
  1140. PKIX_Error *error = NULL;
  1141. error = PKIX_PL_Pk11CertStore_Create(&certStore, plContext);
  1142. if (error != NULL)
  1143. goto cleanup;
  1144. error = PKIX_List_Create(&certStores, plContext);
  1145. if (error != NULL)
  1146. goto cleanup;
  1147. error = PKIX_List_AppendItem(certStores,
  1148. (PKIX_PL_Object *)certStore, plContext);
  1149. if (error != NULL)
  1150. goto cleanup;
  1151. error = PKIX_PL_Object_IncRef((PKIX_PL_Object *)certStores, plContext);
  1152. if (error == NULL)
  1153. r = certStores;
  1154. cleanup:
  1155. if (certStores != NULL)
  1156. PKIX_PL_Object_DecRef((PKIX_PL_Object *)certStores, plContext);
  1157. if (certStore != NULL)
  1158. PKIX_PL_Object_DecRef((PKIX_PL_Object *)certStore, plContext);
  1159. if (error != NULL) {
  1160. SECErrorCodes nssErr;
  1161. cert_PkixErrorToNssCode(error, &nssErr, plContext);
  1162. PKIX_PL_Object_DecRef((PKIX_PL_Object *)error, plContext);
  1163. PORT_SetError(nssErr);
  1164. }
  1165. return r;
  1166. }
  1167. struct fake_PKIX_PL_CertStruct {
  1168. CERTCertificate *nssCert;
  1169. };
  1170. /* This needs to be part of the PKIX_PL_* */
  1171. /* This definitely needs to go away, and be replaced with
  1172. a real accessor function in PKIX */
  1173. static CERTCertificate *
  1174. cert_NSSCertFromPKIXCert(const PKIX_PL_Cert *pkix_cert)
  1175. {
  1176. struct fake_PKIX_PL_CertStruct *fcert = NULL;
  1177. fcert = (struct fake_PKIX_PL_CertStruct *)pkix_cert;
  1178. return CERT_DupCertificate(fcert->nssCert);
  1179. }
  1180. PKIX_List *
  1181. cert_PKIXMakeOIDList(const SECOidTag *oids, int oidCount, void *plContext)
  1182. {
  1183. PKIX_List *r = NULL;
  1184. PKIX_List *policyList = NULL;
  1185. PKIX_PL_OID *policyOID = NULL;
  1186. PKIX_Error *error = NULL;
  1187. int i;
  1188. error = PKIX_List_Create(&policyList, plContext);
  1189. if (error != NULL) {
  1190. goto cleanup;
  1191. }
  1192. for (i = 0; i < oidCount; i++) {
  1193. error = PKIX_PL_OID_Create(oids[i], &policyOID, plContext);
  1194. if (error) {
  1195. goto cleanup;
  1196. }
  1197. error = PKIX_List_AppendItem(policyList,
  1198. (PKIX_PL_Object *)policyOID, plContext);
  1199. if (error != NULL) {
  1200. goto cleanup;
  1201. }
  1202. PKIX_PL_Object_DecRef((PKIX_PL_Object *)policyOID, plContext);
  1203. policyOID = NULL;
  1204. }
  1205. error = PKIX_List_SetImmutable(policyList, plContext);
  1206. if (error != NULL)
  1207. goto cleanup;
  1208. error = PKIX_PL_Object_IncRef((PKIX_PL_Object *)policyList, plContext);
  1209. if (error == NULL)
  1210. r = policyList;
  1211. cleanup:
  1212. if (policyOID != NULL) {
  1213. PKIX_PL_Object_DecRef((PKIX_PL_Object *)policyOID, plContext);
  1214. }
  1215. if (policyList != NULL) {
  1216. PKIX_PL_Object_DecRef((PKIX_PL_Object *)policyList, plContext);
  1217. }
  1218. if (error != NULL) {
  1219. PKIX_PL_Object_DecRef((PKIX_PL_Object *)error, plContext);
  1220. }
  1221. return r;
  1222. }
  1223. CERTValOutParam *
  1224. cert_pkix_FindOutputParam(CERTValOutParam *params, const CERTValParamOutType t)
  1225. {
  1226. CERTValOutParam *i;
  1227. if (params == NULL) {
  1228. return NULL;
  1229. }
  1230. for (i = params; i->type != cert_po_end; i++) {
  1231. if (i->type == t) {
  1232. return i;
  1233. }
  1234. }
  1235. return NULL;
  1236. }
  1237. static PKIX_Error *
  1238. setRevocationMethod(PKIX_RevocationChecker *revChecker,
  1239. PKIX_ProcessingParams *procParams,
  1240. const CERTRevocationTests *revTest,
  1241. CERTRevocationMethodIndex certRevMethod,
  1242. PKIX_RevocationMethodType pkixRevMethod,
  1243. PKIX_Boolean verifyResponderUsages,
  1244. PKIX_Boolean isLeafTest,
  1245. void *plContext)
  1246. {
  1247. PKIX_UInt32 methodFlags = 0;
  1248. PKIX_Error *error = NULL;
  1249. PKIX_UInt32 priority = 0;
  1250. if (revTest->number_of_defined_methods <= (PRUint32)certRevMethod) {
  1251. return NULL;
  1252. }
  1253. if (revTest->preferred_methods) {
  1254. unsigned int i = 0;
  1255. for (; i < revTest->number_of_preferred_methods; i++) {
  1256. if (revTest->preferred_methods[i] == certRevMethod)
  1257. break;
  1258. }
  1259. priority = i;
  1260. }
  1261. methodFlags = revTest->cert_rev_flags_per_method[certRevMethod];
  1262. if (verifyResponderUsages &&
  1263. pkixRevMethod == PKIX_RevocationMethod_OCSP) {
  1264. methodFlags |= PKIX_REV_M_FORBID_NETWORK_FETCHING;
  1265. }
  1266. error =
  1267. PKIX_RevocationChecker_CreateAndAddMethod(revChecker, procParams,
  1268. pkixRevMethod, methodFlags,
  1269. priority, NULL,
  1270. isLeafTest, plContext);
  1271. return error;
  1272. }
  1273. SECStatus
  1274. cert_pkixSetParam(PKIX_ProcessingParams *procParams,
  1275. const CERTValInParam *param, void *plContext)
  1276. {
  1277. PKIX_Error *error = NULL;
  1278. SECStatus r = SECSuccess;
  1279. PKIX_PL_Date *date = NULL;
  1280. PKIX_List *policyOIDList = NULL;
  1281. PKIX_List *certListPkix = NULL;
  1282. const CERTRevocationFlags *flags;
  1283. SECErrorCodes errCode = SEC_ERROR_INVALID_ARGS;
  1284. const CERTCertList *certList = NULL;
  1285. CERTCertListNode *node;
  1286. PKIX_PL_Cert *certPkix = NULL;
  1287. PKIX_TrustAnchor *trustAnchor = NULL;
  1288. PKIX_RevocationChecker *revChecker = NULL;
  1289. PKIX_PL_NssContext *nssContext = (PKIX_PL_NssContext *)plContext;
  1290. /* XXX we need a way to map generic PKIX error to generic NSS errors */
  1291. switch (param->type) {
  1292. case cert_pi_policyOID:
  1293. /* needed? */
  1294. error = PKIX_ProcessingParams_SetExplicitPolicyRequired(
  1295. procParams, PKIX_TRUE, plContext);
  1296. if (error != NULL) {
  1297. break;
  1298. }
  1299. policyOIDList = cert_PKIXMakeOIDList(param->value.array.oids,
  1300. param->value.arraySize, plContext);
  1301. if (policyOIDList == NULL) {
  1302. r = SECFailure;
  1303. PORT_SetError(SEC_ERROR_INVALID_ARGS);
  1304. break;
  1305. }
  1306. error = PKIX_ProcessingParams_SetInitialPolicies(
  1307. procParams, policyOIDList, plContext);
  1308. break;
  1309. case cert_pi_date:
  1310. if (param->value.scalar.time == 0) {
  1311. error = PKIX_PL_Date_Create_UTCTime(NULL, &date, plContext);
  1312. if (error != NULL) {
  1313. errCode = SEC_ERROR_INVALID_TIME;
  1314. break;
  1315. }
  1316. } else {
  1317. error = pkix_pl_Date_CreateFromPRTime(param->value.scalar.time,
  1318. &date, plContext);
  1319. if (error != NULL) {
  1320. errCode = SEC_ERROR_INVALID_TIME;
  1321. break;
  1322. }
  1323. }
  1324. error = PKIX_ProcessingParams_SetDate(procParams, date, plContext);
  1325. if (error != NULL) {
  1326. errCode = SEC_ERROR_INVALID_TIME;
  1327. }
  1328. break;
  1329. case cert_pi_revocationFlags: {
  1330. PKIX_UInt32 leafIMFlags = 0;
  1331. PKIX_UInt32 chainIMFlags = 0;
  1332. PKIX_Boolean validatingResponderCert = PKIX_FALSE;
  1333. flags = param->value.pointer.revocation;
  1334. if (!flags) {
  1335. PORT_SetError(errCode);
  1336. r = SECFailure;
  1337. break;
  1338. }
  1339. leafIMFlags =
  1340. flags->leafTests.cert_rev_method_independent_flags;
  1341. chainIMFlags =
  1342. flags->chainTests.cert_rev_method_independent_flags;
  1343. error =
  1344. PKIX_RevocationChecker_Create(leafIMFlags, chainIMFlags,
  1345. &revChecker, plContext);
  1346. if (error) {
  1347. break;
  1348. }
  1349. error =
  1350. PKIX_ProcessingParams_SetRevocationChecker(procParams,
  1351. revChecker, plContext);
  1352. if (error) {
  1353. break;
  1354. }
  1355. if (((PKIX_PL_NssContext *)plContext)->certificateUsage &
  1356. certificateUsageStatusResponder) {
  1357. validatingResponderCert = PKIX_TRUE;
  1358. }
  1359. error = setRevocationMethod(revChecker,
  1360. procParams, &flags->leafTests,
  1361. cert_revocation_method_crl,
  1362. PKIX_RevocationMethod_CRL,
  1363. validatingResponderCert,
  1364. PKIX_TRUE, plContext);
  1365. if (error) {
  1366. break;
  1367. }
  1368. error = setRevocationMethod(revChecker,
  1369. procParams, &flags->leafTests,
  1370. cert_revocation_method_ocsp,
  1371. PKIX_RevocationMethod_OCSP,
  1372. validatingResponderCert,
  1373. PKIX_TRUE, plContext);
  1374. if (error) {
  1375. break;
  1376. }
  1377. error = setRevocationMethod(revChecker,
  1378. procParams, &flags->chainTests,
  1379. cert_revocation_method_crl,
  1380. PKIX_RevocationMethod_CRL,
  1381. validatingResponderCert,
  1382. PKIX_FALSE, plContext);
  1383. if (error) {
  1384. break;
  1385. }
  1386. error = setRevocationMethod(revChecker,
  1387. procParams, &flags->chainTests,
  1388. cert_revocation_method_ocsp,
  1389. PKIX_RevocationMethod_OCSP,
  1390. validatingResponderCert,
  1391. PKIX_FALSE, plContext);
  1392. if (error) {
  1393. break;
  1394. }
  1395. } break;
  1396. case cert_pi_trustAnchors:
  1397. certList = param->value.pointer.chain;
  1398. if (!certList) {
  1399. PORT_SetError(errCode);
  1400. r = SECFailure;
  1401. break;
  1402. }
  1403. error = PKIX_List_Create(&certListPkix, plContext);
  1404. if (error != NULL) {
  1405. break;
  1406. }
  1407. for (node = CERT_LIST_HEAD(certList); !CERT_LIST_END(node, certList);
  1408. node = CERT_LIST_NEXT(node)) {
  1409. error = PKIX_PL_Cert_CreateFromCERTCertificate(node->cert,
  1410. &certPkix, plContext);
  1411. if (error) {
  1412. break;
  1413. }
  1414. error = PKIX_TrustAnchor_CreateWithCert(certPkix, &trustAnchor,
  1415. plContext);
  1416. if (error) {
  1417. break;
  1418. }
  1419. error = PKIX_List_AppendItem(certListPkix,
  1420. (PKIX_PL_Object *)trustAnchor, plContext);
  1421. if (error) {
  1422. break;
  1423. }
  1424. PKIX_PL_Object_DecRef((PKIX_PL_Object *)trustAnchor, plContext);
  1425. trustAnchor = NULL;
  1426. PKIX_PL_Object_DecRef((PKIX_PL_Object *)certPkix, plContext);
  1427. certPkix = NULL;
  1428. }
  1429. error =
  1430. PKIX_ProcessingParams_SetTrustAnchors(procParams, certListPkix,
  1431. plContext);
  1432. break;
  1433. case cert_pi_useAIACertFetch:
  1434. error =
  1435. PKIX_ProcessingParams_SetUseAIAForCertFetching(procParams,
  1436. (PRBool)(param->value.scalar.b !=
  1437. 0),
  1438. plContext);
  1439. break;
  1440. case cert_pi_chainVerifyCallback: {
  1441. const CERTChainVerifyCallback *chainVerifyCallback =
  1442. param->value.pointer.chainVerifyCallback;
  1443. if (!chainVerifyCallback || !chainVerifyCallback->isChainValid) {
  1444. PORT_SetError(errCode);
  1445. r = SECFailure;
  1446. break;
  1447. }
  1448. nssContext->chainVerifyCallback = *chainVerifyCallback;
  1449. } break;
  1450. case cert_pi_useOnlyTrustAnchors:
  1451. error =
  1452. PKIX_ProcessingParams_SetUseOnlyTrustAnchors(procParams,
  1453. (PRBool)(param->value.scalar.b !=
  1454. 0),
  1455. plContext);
  1456. break;
  1457. default:
  1458. PORT_SetError(errCode);
  1459. r = SECFailure;
  1460. break;
  1461. }
  1462. if (policyOIDList != NULL)
  1463. PKIX_PL_Object_DecRef((PKIX_PL_Object *)policyOIDList, plContext);
  1464. if (date != NULL)
  1465. PKIX_PL_Object_DecRef((PKIX_PL_Object *)date, plContext);
  1466. if (revChecker != NULL)
  1467. PKIX_PL_Object_DecRef((PKIX_PL_Object *)revChecker, plContext);
  1468. if (certListPkix)
  1469. PKIX_PL_Object_DecRef((PKIX_PL_Object *)certListPkix, plContext);
  1470. if (trustAnchor)
  1471. PKIX_PL_Object_DecRef((PKIX_PL_Object *)trustAnchor, plContext);
  1472. if (certPkix)
  1473. PKIX_PL_Object_DecRef((PKIX_PL_Object *)certPkix, plContext);
  1474. if (error != NULL) {
  1475. PKIX_PL_Object_DecRef((PKIX_PL_Object *)error, plContext);
  1476. PORT_SetError(errCode);
  1477. r = SECFailure;
  1478. }
  1479. return r;
  1480. }
  1481. void
  1482. cert_pkixDestroyValOutParam(CERTValOutParam *params)
  1483. {
  1484. CERTValOutParam *i;
  1485. if (params == NULL) {
  1486. return;
  1487. }
  1488. for (i = params; i->type != cert_po_end; i++) {
  1489. switch (i->type) {
  1490. case cert_po_trustAnchor:
  1491. if (i->value.pointer.cert) {
  1492. CERT_DestroyCertificate(i->value.pointer.cert);
  1493. i->value.pointer.cert = NULL;
  1494. }
  1495. break;
  1496. case cert_po_certList:
  1497. if (i->value.pointer.chain) {
  1498. CERT_DestroyCertList(i->value.pointer.chain);
  1499. i->value.pointer.chain = NULL;
  1500. }
  1501. break;
  1502. default:
  1503. break;
  1504. }
  1505. }
  1506. }
  1507. static PRUint64 certRev_NSS_3_11_Ocsp_Enabled_Soft_Policy_LeafFlags[2] = {
  1508. /* crl */
  1509. CERT_REV_M_TEST_USING_THIS_METHOD |
  1510. CERT_REV_M_FORBID_NETWORK_FETCHING |
  1511. CERT_REV_M_CONTINUE_TESTING_ON_FRESH_INFO,
  1512. /* ocsp */
  1513. CERT_REV_M_TEST_USING_THIS_METHOD
  1514. };
  1515. static PRUint64 certRev_NSS_3_11_Ocsp_Enabled_Soft_Policy_ChainFlags[2] = {
  1516. /* crl */
  1517. CERT_REV_M_TEST_USING_THIS_METHOD |
  1518. CERT_REV_M_FORBID_NETWORK_FETCHING |
  1519. CERT_REV_M_CONTINUE_TESTING_ON_FRESH_INFO,
  1520. /* ocsp */
  1521. 0
  1522. };
  1523. static CERTRevocationMethodIndex
  1524. certRev_NSS_3_11_Ocsp_Enabled_Soft_Policy_Method_Preference = {
  1525. cert_revocation_method_crl
  1526. };
  1527. static const CERTRevocationFlags certRev_NSS_3_11_Ocsp_Enabled_Soft_Policy = {
  1528. { /* leafTests */
  1529. 2,
  1530. certRev_NSS_3_11_Ocsp_Enabled_Soft_Policy_LeafFlags,
  1531. 1,
  1532. &certRev_NSS_3_11_Ocsp_Enabled_Soft_Policy_Method_Preference,
  1533. 0 },
  1534. { /* chainTests */
  1535. 2,
  1536. certRev_NSS_3_11_Ocsp_Enabled_Soft_Policy_ChainFlags,
  1537. 0,
  1538. 0,
  1539. 0 }
  1540. };
  1541. #endif /* NSS_DISABLE_LIBPKIX */
  1542. extern const CERTRevocationFlags *
  1543. CERT_GetClassicOCSPEnabledSoftFailurePolicy()
  1544. {
  1545. #ifdef NSS_DISABLE_LIBPKIX
  1546. PORT_SetError(PR_NOT_IMPLEMENTED_ERROR);
  1547. return NULL;
  1548. #else
  1549. return &certRev_NSS_3_11_Ocsp_Enabled_Soft_Policy;
  1550. #endif /* NSS_DISABLE_LIBPKIX */
  1551. }
  1552. #ifndef NSS_DISABLE_LIBPKIX
  1553. static PRUint64 certRev_NSS_3_11_Ocsp_Enabled_Hard_Policy_LeafFlags[2] = {
  1554. /* crl */
  1555. CERT_REV_M_TEST_USING_THIS_METHOD |
  1556. CERT_REV_M_FORBID_NETWORK_FETCHING |
  1557. CERT_REV_M_CONTINUE_TESTING_ON_FRESH_INFO,
  1558. /* ocsp */
  1559. CERT_REV_M_TEST_USING_THIS_METHOD |
  1560. CERT_REV_M_FAIL_ON_MISSING_FRESH_INFO
  1561. };
  1562. static PRUint64 certRev_NSS_3_11_Ocsp_Enabled_Hard_Policy_ChainFlags[2] = {
  1563. /* crl */
  1564. CERT_REV_M_TEST_USING_THIS_METHOD |
  1565. CERT_REV_M_FORBID_NETWORK_FETCHING |
  1566. CERT_REV_M_CONTINUE_TESTING_ON_FRESH_INFO,
  1567. /* ocsp */
  1568. 0
  1569. };
  1570. static CERTRevocationMethodIndex
  1571. certRev_NSS_3_11_Ocsp_Enabled_Hard_Policy_Method_Preference = {
  1572. cert_revocation_method_crl
  1573. };
  1574. static const CERTRevocationFlags certRev_NSS_3_11_Ocsp_Enabled_Hard_Policy = {
  1575. { /* leafTests */
  1576. 2,
  1577. certRev_NSS_3_11_Ocsp_Enabled_Hard_Policy_LeafFlags,
  1578. 1,
  1579. &certRev_NSS_3_11_Ocsp_Enabled_Hard_Policy_Method_Preference,
  1580. 0 },
  1581. { /* chainTests */
  1582. 2,
  1583. certRev_NSS_3_11_Ocsp_Enabled_Hard_Policy_ChainFlags,
  1584. 0,
  1585. 0,
  1586. 0 }
  1587. };
  1588. #endif /* NSS_DISABLE_LIBPKIX */
  1589. extern const CERTRevocationFlags *
  1590. CERT_GetClassicOCSPEnabledHardFailurePolicy()
  1591. {
  1592. #ifdef NSS_DISABLE_LIBPKIX
  1593. PORT_SetError(PR_NOT_IMPLEMENTED_ERROR);
  1594. return NULL;
  1595. #else
  1596. return &certRev_NSS_3_11_Ocsp_Enabled_Hard_Policy;
  1597. #endif /* NSS_DISABLE_LIBPKIX */
  1598. }
  1599. #ifndef NSS_DISABLE_LIBPKIX
  1600. static PRUint64 certRev_NSS_3_11_Ocsp_Disabled_Policy_LeafFlags[2] = {
  1601. /* crl */
  1602. CERT_REV_M_TEST_USING_THIS_METHOD |
  1603. CERT_REV_M_FORBID_NETWORK_FETCHING |
  1604. CERT_REV_M_CONTINUE_TESTING_ON_FRESH_INFO,
  1605. /* ocsp */
  1606. 0
  1607. };
  1608. static PRUint64 certRev_NSS_3_11_Ocsp_Disabled_Policy_ChainFlags[2] = {
  1609. /* crl */
  1610. CERT_REV_M_TEST_USING_THIS_METHOD |
  1611. CERT_REV_M_FORBID_NETWORK_FETCHING |
  1612. CERT_REV_M_CONTINUE_TESTING_ON_FRESH_INFO,
  1613. /* ocsp */
  1614. 0
  1615. };
  1616. static const CERTRevocationFlags certRev_NSS_3_11_Ocsp_Disabled_Policy = {
  1617. { /* leafTests */
  1618. 2,
  1619. certRev_NSS_3_11_Ocsp_Disabled_Policy_LeafFlags,
  1620. 0,
  1621. 0,
  1622. 0 },
  1623. { /* chainTests */
  1624. 2,
  1625. certRev_NSS_3_11_Ocsp_Disabled_Policy_ChainFlags,
  1626. 0,
  1627. 0,
  1628. 0 }
  1629. };
  1630. #endif /* NSS_DISABLE_LIBPKIX */
  1631. extern const CERTRevocationFlags *
  1632. CERT_GetClassicOCSPDisabledPolicy()
  1633. {
  1634. #ifdef NSS_DISABLE_LIBPKIX
  1635. PORT_SetError(PR_NOT_IMPLEMENTED_ERROR);
  1636. return NULL;
  1637. #else
  1638. return &certRev_NSS_3_11_Ocsp_Disabled_Policy;
  1639. #endif /* NSS_DISABLE_LIBPKIX */
  1640. }
  1641. #ifndef NSS_DISABLE_LIBPKIX
  1642. static PRUint64 certRev_PKIX_Verify_Nist_Policy_LeafFlags[2] = {
  1643. /* crl */
  1644. CERT_REV_M_TEST_USING_THIS_METHOD |
  1645. CERT_REV_M_FAIL_ON_MISSING_FRESH_INFO |
  1646. CERT_REV_M_REQUIRE_INFO_ON_MISSING_SOURCE,
  1647. /* ocsp */
  1648. 0
  1649. };
  1650. static PRUint64 certRev_PKIX_Verify_Nist_Policy_ChainFlags[2] = {
  1651. /* crl */
  1652. CERT_REV_M_TEST_USING_THIS_METHOD |
  1653. CERT_REV_M_FAIL_ON_MISSING_FRESH_INFO |
  1654. CERT_REV_M_REQUIRE_INFO_ON_MISSING_SOURCE,
  1655. /* ocsp */
  1656. 0
  1657. };
  1658. static const CERTRevocationFlags certRev_PKIX_Verify_Nist_Policy = {
  1659. { /* leafTests */
  1660. 2,
  1661. certRev_PKIX_Verify_Nist_Policy_LeafFlags,
  1662. 0,
  1663. 0,
  1664. 0 },
  1665. { /* chainTests */
  1666. 2,
  1667. certRev_PKIX_Verify_Nist_Policy_ChainFlags,
  1668. 0,
  1669. 0,
  1670. 0 }
  1671. };
  1672. #endif /* NSS_DISABLE_LIBPKIX */
  1673. extern const CERTRevocationFlags *
  1674. CERT_GetPKIXVerifyNistRevocationPolicy()
  1675. {
  1676. #ifdef NSS_DISABLE_LIBPKIX
  1677. PORT_SetError(PR_NOT_IMPLEMENTED_ERROR);
  1678. return NULL;
  1679. #else
  1680. return &certRev_PKIX_Verify_Nist_Policy;
  1681. #endif /* NSS_DISABLE_LIBPKIX */
  1682. }
  1683. CERTRevocationFlags *
  1684. CERT_AllocCERTRevocationFlags(
  1685. PRUint32 number_leaf_methods, PRUint32 number_leaf_pref_methods,
  1686. PRUint32 number_chain_methods, PRUint32 number_chain_pref_methods)
  1687. {
  1688. #ifdef NSS_DISABLE_LIBPKIX
  1689. PORT_SetError(PR_NOT_IMPLEMENTED_ERROR);
  1690. return NULL;
  1691. #else
  1692. CERTRevocationFlags *flags;
  1693. flags = PORT_New(CERTRevocationFlags);
  1694. if (!flags)
  1695. return (NULL);
  1696. flags->leafTests.number_of_defined_methods = number_leaf_methods;
  1697. flags->leafTests.cert_rev_flags_per_method =
  1698. PORT_NewArray(PRUint64, number_leaf_methods);
  1699. flags->leafTests.number_of_preferred_methods = number_leaf_pref_methods;
  1700. flags->leafTests.preferred_methods =
  1701. PORT_NewArray(CERTRevocationMethodIndex, number_leaf_pref_methods);
  1702. flags->chainTests.number_of_defined_methods = number_chain_methods;
  1703. flags->chainTests.cert_rev_flags_per_method =
  1704. PORT_NewArray(PRUint64, number_chain_methods);
  1705. flags->chainTests.number_of_preferred_methods = number_chain_pref_methods;
  1706. flags->chainTests.preferred_methods =
  1707. PORT_NewArray(CERTRevocationMethodIndex, number_chain_pref_methods);
  1708. if (!flags->leafTests.cert_rev_flags_per_method ||
  1709. !flags->leafTests.preferred_methods ||
  1710. !flags->chainTests.cert_rev_flags_per_method ||
  1711. !flags->chainTests.preferred_methods) {
  1712. CERT_DestroyCERTRevocationFlags(flags);
  1713. return (NULL);
  1714. }
  1715. return flags;
  1716. #endif /* NSS_DISABLE_LIBPKIX */
  1717. }
  1718. void
  1719. CERT_DestroyCERTRevocationFlags(CERTRevocationFlags *flags)
  1720. {
  1721. #ifdef NSS_DISABLE_LIBPKIX
  1722. PORT_SetError(PR_NOT_IMPLEMENTED_ERROR);
  1723. return;
  1724. #else
  1725. if (!flags)
  1726. return;
  1727. if (flags->leafTests.cert_rev_flags_per_method)
  1728. PORT_Free(flags->leafTests.cert_rev_flags_per_method);
  1729. if (flags->leafTests.preferred_methods)
  1730. PORT_Free(flags->leafTests.preferred_methods);
  1731. if (flags->chainTests.cert_rev_flags_per_method)
  1732. PORT_Free(flags->chainTests.cert_rev_flags_per_method);
  1733. if (flags->chainTests.preferred_methods)
  1734. PORT_Free(flags->chainTests.preferred_methods);
  1735. PORT_Free(flags);
  1736. #endif /* NSS_DISABLE_LIBPKIX */
  1737. }
  1738. /*
  1739. * CERT_PKIXVerifyCert
  1740. *
  1741. * Verify a Certificate using the PKIX library.
  1742. *
  1743. * Parameters:
  1744. * cert - the target certificate to verify. Must be non-null
  1745. * params - an array of type/value parameters which can be
  1746. * used to modify the behavior of the validation
  1747. * algorithm, or supply additional constraints.
  1748. *
  1749. * outputTrustAnchor - the trust anchor which the certificate
  1750. * chains to. The caller is responsible
  1751. * for freeing this.
  1752. *
  1753. * Example Usage:
  1754. * CERTValParam args[3];
  1755. * args[0].type = cvpt_policyOID;
  1756. * args[0].value.si = oid;
  1757. * args[1].type = revCheckRequired;
  1758. * args[1].value.b = PR_TRUE;
  1759. * args[2].type = cvpt_end;
  1760. *
  1761. * CERT_PKIXVerifyCert(cert, &output, args
  1762. */
  1763. SECStatus
  1764. CERT_PKIXVerifyCert(
  1765. CERTCertificate *cert,
  1766. SECCertificateUsage usages,
  1767. CERTValInParam *paramsIn,
  1768. CERTValOutParam *paramsOut,
  1769. void *wincx)
  1770. {
  1771. #ifdef NSS_DISABLE_LIBPKIX
  1772. PORT_SetError(PR_NOT_IMPLEMENTED_ERROR);
  1773. return SECFailure;
  1774. #else
  1775. SECStatus r = SECFailure;
  1776. PKIX_Error *error = NULL;
  1777. PKIX_ProcessingParams *procParams = NULL;
  1778. PKIX_BuildResult *buildResult = NULL;
  1779. void *nbioContext = NULL; /* for non-blocking IO */
  1780. void *buildState = NULL; /* for non-blocking IO */
  1781. PKIX_CertSelector *certSelector = NULL;
  1782. PKIX_List *certStores = NULL;
  1783. PKIX_ValidateResult *valResult = NULL;
  1784. PKIX_VerifyNode *verifyNode = NULL;
  1785. PKIX_TrustAnchor *trustAnchor = NULL;
  1786. PKIX_PL_Cert *trustAnchorCert = NULL;
  1787. PKIX_List *builtCertList = NULL;
  1788. CERTValOutParam *oparam = NULL;
  1789. int i = 0;
  1790. void *plContext = NULL;
  1791. #ifdef PKIX_OBJECT_LEAK_TEST
  1792. int leakedObjNum = 0;
  1793. int memLeakLoopCount = 0;
  1794. int objCountTable[PKIX_NUMTYPES];
  1795. int fnInvLocalCount = 0;
  1796. PKIX_Boolean savedUsePkixEngFlag = usePKIXValidationEngine;
  1797. if (usePKIXValidationEngine) {
  1798. /* current memory leak testing implementation does not allow
  1799. * to run simultaneous tests one the same or a different threads.
  1800. * Setting the variable to false, to make additional chain
  1801. * validations be handled by old nss. */
  1802. usePKIXValidationEngine = PR_FALSE;
  1803. }
  1804. testStartFnStackPosition = 1;
  1805. fnStackNameArr[0] = "CERT_PKIXVerifyCert";
  1806. fnStackInvCountArr[0] = 0;
  1807. PKIX_Boolean abortOnLeak =
  1808. (PR_GetEnvSecure("PKIX_OBJECT_LEAK_TEST_ABORT_ON_LEAK") == NULL) ? PKIX_FALSE
  1809. : PKIX_TRUE;
  1810. runningLeakTest = PKIX_TRUE;
  1811. /* Prevent multi-threaded run of object leak test */
  1812. fnInvLocalCount = PR_ATOMIC_INCREMENT(&parallelFnInvocationCount);
  1813. PORT_Assert(fnInvLocalCount == 1);
  1814. do {
  1815. r = SECFailure;
  1816. error = NULL;
  1817. procParams = NULL;
  1818. buildResult = NULL;
  1819. nbioContext = NULL; /* for non-blocking IO */
  1820. buildState = NULL; /* for non-blocking IO */
  1821. certSelector = NULL;
  1822. certStores = NULL;
  1823. valResult = NULL;
  1824. verifyNode = NULL;
  1825. trustAnchor = NULL;
  1826. trustAnchorCert = NULL;
  1827. builtCertList = NULL;
  1828. oparam = NULL;
  1829. i = 0;
  1830. errorGenerated = PKIX_FALSE;
  1831. stackPosition = 0;
  1832. if (leakedObjNum) {
  1833. pkix_pl_lifecycle_ObjectTableUpdate(objCountTable);
  1834. }
  1835. memLeakLoopCount += 1;
  1836. #endif /* PKIX_OBJECT_LEAK_TEST */
  1837. error = PKIX_PL_NssContext_Create(
  1838. 0, PR_FALSE /*use arena*/, wincx, &plContext);
  1839. if (error != NULL) { /* need pkix->nss error map */
  1840. PORT_SetError(SEC_ERROR_CERT_NOT_VALID);
  1841. goto cleanup;
  1842. }
  1843. error = pkix_pl_NssContext_SetCertUsage(usages, plContext);
  1844. if (error != NULL) {
  1845. PORT_SetError(SEC_ERROR_INVALID_ARGS);
  1846. goto cleanup;
  1847. }
  1848. error = PKIX_ProcessingParams_Create(&procParams, plContext);
  1849. if (error != NULL) { /* need pkix->nss error map */
  1850. PORT_SetError(SEC_ERROR_CERT_NOT_VALID);
  1851. goto cleanup;
  1852. }
  1853. /* local cert store should be set into procParams before
  1854. * filling in revocation settings. */
  1855. certStores = cert_GetCertStores(plContext);
  1856. if (certStores == NULL) {
  1857. goto cleanup;
  1858. }
  1859. error = PKIX_ProcessingParams_SetCertStores(procParams, certStores, plContext);
  1860. if (error != NULL) {
  1861. goto cleanup;
  1862. }
  1863. /* now process the extensible input parameters structure */
  1864. if (paramsIn != NULL) {
  1865. i = 0;
  1866. while (paramsIn[i].type != cert_pi_end) {
  1867. if (paramsIn[i].type >= cert_pi_max) {
  1868. PORT_SetError(SEC_ERROR_INVALID_ARGS);
  1869. goto cleanup;
  1870. }
  1871. if (cert_pkixSetParam(procParams,
  1872. &paramsIn[i], plContext) !=
  1873. SECSuccess) {
  1874. PORT_SetError(SEC_ERROR_INVALID_ARGS);
  1875. goto cleanup;
  1876. }
  1877. i++;
  1878. }
  1879. }
  1880. certSelector = cert_GetTargetCertConstraints(cert, plContext);
  1881. if (certSelector == NULL) {
  1882. goto cleanup;
  1883. }
  1884. error = PKIX_ProcessingParams_SetTargetCertConstraints(procParams, certSelector, plContext);
  1885. if (error != NULL) {
  1886. goto cleanup;
  1887. }
  1888. error = PKIX_BuildChain(procParams, &nbioContext,
  1889. &buildState, &buildResult, &verifyNode,
  1890. plContext);
  1891. if (error != NULL) {
  1892. goto cleanup;
  1893. }
  1894. error = PKIX_BuildResult_GetValidateResult(buildResult, &valResult,
  1895. plContext);
  1896. if (error != NULL) {
  1897. goto cleanup;
  1898. }
  1899. error = PKIX_ValidateResult_GetTrustAnchor(valResult, &trustAnchor,
  1900. plContext);
  1901. if (error != NULL) {
  1902. goto cleanup;
  1903. }
  1904. if (trustAnchor != NULL) {
  1905. error = PKIX_TrustAnchor_GetTrustedCert(trustAnchor, &trustAnchorCert,
  1906. plContext);
  1907. if (error != NULL) {
  1908. goto cleanup;
  1909. }
  1910. }
  1911. #ifdef PKIX_OBJECT_LEAK_TEST
  1912. /* Can not continue if error was generated but not returned.
  1913. * Jumping to cleanup. */
  1914. if (errorGenerated)
  1915. goto cleanup;
  1916. #endif /* PKIX_OBJECT_LEAK_TEST */
  1917. oparam = cert_pkix_FindOutputParam(paramsOut, cert_po_trustAnchor);
  1918. if (oparam != NULL) {
  1919. if (trustAnchorCert != NULL) {
  1920. oparam->value.pointer.cert =
  1921. cert_NSSCertFromPKIXCert(trustAnchorCert);
  1922. } else {
  1923. oparam->value.pointer.cert = NULL;
  1924. }
  1925. }
  1926. error = PKIX_BuildResult_GetCertChain(buildResult, &builtCertList,
  1927. plContext);
  1928. if (error != NULL) {
  1929. goto cleanup;
  1930. }
  1931. oparam = cert_pkix_FindOutputParam(paramsOut, cert_po_certList);
  1932. if (oparam != NULL) {
  1933. error = cert_PkixToNssCertsChain(builtCertList,
  1934. &oparam->value.pointer.chain,
  1935. plContext);
  1936. if (error)
  1937. goto cleanup;
  1938. }
  1939. r = SECSuccess;
  1940. cleanup:
  1941. if (verifyNode) {
  1942. /* Return validation log only upon error. */
  1943. oparam = cert_pkix_FindOutputParam(paramsOut, cert_po_errorLog);
  1944. #ifdef PKIX_OBJECT_LEAK_TEST
  1945. if (!errorGenerated)
  1946. #endif /* PKIX_OBJECT_LEAK_TEST */
  1947. if (r && oparam != NULL) {
  1948. PKIX_Error *tmpError =
  1949. cert_GetLogFromVerifyNode(oparam->value.pointer.log,
  1950. verifyNode, plContext);
  1951. if (tmpError) {
  1952. PKIX_PL_Object_DecRef((PKIX_PL_Object *)tmpError, plContext);
  1953. }
  1954. }
  1955. PKIX_PL_Object_DecRef((PKIX_PL_Object *)verifyNode, plContext);
  1956. }
  1957. if (procParams != NULL)
  1958. PKIX_PL_Object_DecRef((PKIX_PL_Object *)procParams, plContext);
  1959. if (trustAnchorCert != NULL)
  1960. PKIX_PL_Object_DecRef((PKIX_PL_Object *)trustAnchorCert, plContext);
  1961. if (trustAnchor != NULL)
  1962. PKIX_PL_Object_DecRef((PKIX_PL_Object *)trustAnchor, plContext);
  1963. if (valResult != NULL)
  1964. PKIX_PL_Object_DecRef((PKIX_PL_Object *)valResult, plContext);
  1965. if (buildResult != NULL)
  1966. PKIX_PL_Object_DecRef((PKIX_PL_Object *)buildResult, plContext);
  1967. if (certStores != NULL)
  1968. PKIX_PL_Object_DecRef((PKIX_PL_Object *)certStores, plContext);
  1969. if (certSelector != NULL)
  1970. PKIX_PL_Object_DecRef((PKIX_PL_Object *)certSelector, plContext);
  1971. if (builtCertList != NULL)
  1972. PKIX_PL_Object_DecRef((PKIX_PL_Object *)builtCertList, plContext);
  1973. if (error != NULL) {
  1974. SECErrorCodes nssErrorCode = 0;
  1975. cert_PkixErrorToNssCode(error, &nssErrorCode, plContext);
  1976. cert_pkixDestroyValOutParam(paramsOut);
  1977. PORT_SetError(nssErrorCode);
  1978. PKIX_PL_Object_DecRef((PKIX_PL_Object *)error, plContext);
  1979. }
  1980. PKIX_PL_NssContext_Destroy(plContext);
  1981. #ifdef PKIX_OBJECT_LEAK_TEST
  1982. leakedObjNum =
  1983. pkix_pl_lifecycle_ObjectLeakCheck(leakedObjNum ? objCountTable : NULL);
  1984. if (pkixLog && leakedObjNum) {
  1985. PR_LOG(pkixLog, 1, ("The generated error caused an object leaks. Loop %d."
  1986. "Stack %s\n",
  1987. memLeakLoopCount, errorFnStackString));
  1988. }
  1989. PR_Free(errorFnStackString);
  1990. errorFnStackString = NULL;
  1991. if (abortOnLeak) {
  1992. PORT_Assert(leakedObjNum == 0);
  1993. }
  1994. } while (errorGenerated);
  1995. runningLeakTest = PKIX_FALSE;
  1996. PR_ATOMIC_DECREMENT(&parallelFnInvocationCount);
  1997. usePKIXValidationEngine = savedUsePkixEngFlag;
  1998. #endif /* PKIX_OBJECT_LEAK_TEST */
  1999. return r;
  2000. #endif /* NSS_DISABLE_LIBPKIX */
  2001. }