PageRenderTime 49ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/gecko_api/include/cert.h

http://firefox-mac-pdf.googlecode.com/
C Header | 1661 lines | 565 code | 291 blank | 805 comment | 0 complexity | cec6c62e3f2324f6966abbd9b7a225e7 MD5 | raw file
  1. /* ***** BEGIN LICENSE BLOCK *****
  2. * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  3. *
  4. * The contents of this file are subject to the Mozilla Public License Version
  5. * 1.1 (the "License"); you may not use this file except in compliance with
  6. * the License. You may obtain a copy of the License at
  7. * http://www.mozilla.org/MPL/
  8. *
  9. * Software distributed under the License is distributed on an "AS IS" basis,
  10. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11. * for the specific language governing rights and limitations under the
  12. * License.
  13. *
  14. * The Original Code is the Netscape security libraries.
  15. *
  16. * The Initial Developer of the Original Code is
  17. * Netscape Communications Corporation.
  18. * Portions created by the Initial Developer are Copyright (C) 1994-2000
  19. * the Initial Developer. All Rights Reserved.
  20. *
  21. * Contributor(s):
  22. *
  23. * Alternatively, the contents of this file may be used under the terms of
  24. * either the GNU General Public License Version 2 or later (the "GPL"), or
  25. * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  26. * in which case the provisions of the GPL or the LGPL are applicable instead
  27. * of those above. If you wish to allow use of your version of this file only
  28. * under the terms of either the GPL or the LGPL, and not to allow others to
  29. * use your version of this file under the terms of the MPL, indicate your
  30. * decision by deleting the provisions above and replace them with the notice
  31. * and other provisions required by the GPL or the LGPL. If you do not delete
  32. * the provisions above, a recipient may use your version of this file under
  33. * the terms of any one of the MPL, the GPL or the LGPL.
  34. *
  35. * ***** END LICENSE BLOCK ***** */
  36. /*
  37. * cert.h - public data structures and prototypes for the certificate library
  38. *
  39. * $Id: cert.h,v 1.68 2008/03/15 02:15:34 alexei.volkov.bugs%sun.com Exp $
  40. */
  41. #ifndef _CERT_H_
  42. #define _CERT_H_
  43. #include "utilrename.h"
  44. #include "plarena.h"
  45. #include "plhash.h"
  46. #include "prlong.h"
  47. #include "prlog.h"
  48. #include "seccomon.h"
  49. #include "secdert.h"
  50. #include "secoidt.h"
  51. #include "keyt.h"
  52. #include "certt.h"
  53. SEC_BEGIN_PROTOS
  54. /****************************************************************************
  55. *
  56. * RFC1485 ascii to/from X.? RelativeDistinguishedName (aka CERTName)
  57. *
  58. ****************************************************************************/
  59. /*
  60. ** Convert an ascii RFC1485 encoded name into its CERTName equivalent.
  61. */
  62. extern CERTName *CERT_AsciiToName(char *string);
  63. /*
  64. ** Convert an CERTName into its RFC1485 encoded equivalent.
  65. ** Returns a string that must be freed with PORT_Free().
  66. */
  67. extern char *CERT_NameToAscii(CERTName *name);
  68. extern CERTAVA *CERT_CopyAVA(PRArenaPool *arena, CERTAVA *src);
  69. /* convert an OID to dotted-decimal representation */
  70. /* Returns a string that must be freed with PR_smprintf_free(). */
  71. extern char * CERT_GetOidString(const SECItem *oid);
  72. /*
  73. ** Examine an AVA and return the tag that refers to it. The AVA tags are
  74. ** defined as SEC_OID_AVA*.
  75. */
  76. extern SECOidTag CERT_GetAVATag(CERTAVA *ava);
  77. /*
  78. ** Compare two AVA's, returning the difference between them.
  79. */
  80. extern SECComparison CERT_CompareAVA(const CERTAVA *a, const CERTAVA *b);
  81. /*
  82. ** Create an RDN (relative-distinguished-name). The argument list is a
  83. ** NULL terminated list of AVA's.
  84. */
  85. extern CERTRDN *CERT_CreateRDN(PRArenaPool *arena, CERTAVA *avas, ...);
  86. /*
  87. ** Make a copy of "src" storing it in "dest".
  88. */
  89. extern SECStatus CERT_CopyRDN(PRArenaPool *arena, CERTRDN *dest, CERTRDN *src);
  90. /*
  91. ** Destory an RDN object.
  92. ** "rdn" the RDN to destroy
  93. ** "freeit" if PR_TRUE then free the object as well as its sub-objects
  94. */
  95. extern void CERT_DestroyRDN(CERTRDN *rdn, PRBool freeit);
  96. /*
  97. ** Add an AVA to an RDN.
  98. ** "rdn" the RDN to add to
  99. ** "ava" the AVA to add
  100. */
  101. extern SECStatus CERT_AddAVA(PRArenaPool *arena, CERTRDN *rdn, CERTAVA *ava);
  102. /*
  103. ** Compare two RDN's, returning the difference between them.
  104. */
  105. extern SECComparison CERT_CompareRDN(CERTRDN *a, CERTRDN *b);
  106. /*
  107. ** Create an X.500 style name using a NULL terminated list of RDN's.
  108. */
  109. extern CERTName *CERT_CreateName(CERTRDN *rdn, ...);
  110. /*
  111. ** Make a copy of "src" storing it in "dest". Memory is allocated in
  112. ** "dest" for each of the appropriate sub objects. Memory is not freed in
  113. ** "dest" before allocation is done (use CERT_DestroyName(dest, PR_FALSE) to
  114. ** do that).
  115. */
  116. extern SECStatus CERT_CopyName(PRArenaPool *arena, CERTName *dest, CERTName *src);
  117. /*
  118. ** Destroy a Name object.
  119. ** "name" the CERTName to destroy
  120. ** "freeit" if PR_TRUE then free the object as well as its sub-objects
  121. */
  122. extern void CERT_DestroyName(CERTName *name);
  123. /*
  124. ** Add an RDN to a name.
  125. ** "name" the name to add the RDN to
  126. ** "rdn" the RDN to add to name
  127. */
  128. extern SECStatus CERT_AddRDN(CERTName *name, CERTRDN *rdn);
  129. /*
  130. ** Compare two names, returning the difference between them.
  131. */
  132. extern SECComparison CERT_CompareName(CERTName *a, CERTName *b);
  133. /*
  134. ** Convert a CERTName into something readable
  135. */
  136. extern char *CERT_FormatName (CERTName *name);
  137. /*
  138. ** Convert a der-encoded integer to a hex printable string form.
  139. ** Perhaps this should be a SEC function but it's only used for certs.
  140. */
  141. extern char *CERT_Hexify (SECItem *i, int do_colon);
  142. /******************************************************************************
  143. *
  144. * Certificate handling operations
  145. *
  146. *****************************************************************************/
  147. /*
  148. ** Create a new validity object given two unix time values.
  149. ** "notBefore" the time before which the validity is not valid
  150. ** "notAfter" the time after which the validity is not valid
  151. */
  152. extern CERTValidity *CERT_CreateValidity(int64 notBefore, int64 notAfter);
  153. /*
  154. ** Destroy a validity object.
  155. ** "v" the validity to destroy
  156. ** "freeit" if PR_TRUE then free the object as well as its sub-objects
  157. */
  158. extern void CERT_DestroyValidity(CERTValidity *v);
  159. /*
  160. ** Copy the "src" object to "dest". Memory is allocated in "dest" for
  161. ** each of the appropriate sub-objects. Memory in "dest" is not freed
  162. ** before memory is allocated (use CERT_DestroyValidity(v, PR_FALSE) to do
  163. ** that).
  164. */
  165. extern SECStatus CERT_CopyValidity
  166. (PRArenaPool *arena, CERTValidity *dest, CERTValidity *src);
  167. /*
  168. ** The cert lib considers a cert or CRL valid if the "notBefore" time is
  169. ** in the not-too-distant future, e.g. within the next 24 hours. This
  170. ** prevents freshly issued certificates from being considered invalid
  171. ** because the local system's time zone is incorrectly set.
  172. ** The amount of "pending slop time" is adjustable by the application.
  173. ** Units of SlopTime are seconds. Default is 86400 (24 hours).
  174. ** Negative SlopTime values are not allowed.
  175. */
  176. PRInt32 CERT_GetSlopTime(void);
  177. SECStatus CERT_SetSlopTime(PRInt32 slop);
  178. /*
  179. ** Create a new certificate object. The result must be wrapped with an
  180. ** CERTSignedData to create a signed certificate.
  181. ** "serialNumber" the serial number
  182. ** "issuer" the name of the certificate issuer
  183. ** "validity" the validity period of the certificate
  184. ** "req" the certificate request that prompted the certificate issuance
  185. */
  186. extern CERTCertificate *
  187. CERT_CreateCertificate (unsigned long serialNumber, CERTName *issuer,
  188. CERTValidity *validity, CERTCertificateRequest *req);
  189. /*
  190. ** Destroy a certificate object
  191. ** "cert" the certificate to destroy
  192. ** NOTE: certificate's are reference counted. This call decrements the
  193. ** reference count, and if the result is zero, then the object is destroyed
  194. ** and optionally freed.
  195. */
  196. extern void CERT_DestroyCertificate(CERTCertificate *cert);
  197. /*
  198. ** Make a shallow copy of a certificate "c". Just increments the
  199. ** reference count on "c".
  200. */
  201. extern CERTCertificate *CERT_DupCertificate(CERTCertificate *c);
  202. /*
  203. ** Create a new certificate request. This result must be wrapped with an
  204. ** CERTSignedData to create a signed certificate request.
  205. ** "name" the subject name (who the certificate request is from)
  206. ** "spki" describes/defines the public key the certificate is for
  207. ** "attributes" if non-zero, some optional attribute data
  208. */
  209. extern CERTCertificateRequest *
  210. CERT_CreateCertificateRequest (CERTName *name, CERTSubjectPublicKeyInfo *spki,
  211. SECItem **attributes);
  212. /*
  213. ** Destroy a certificate-request object
  214. ** "r" the certificate-request to destroy
  215. ** "freeit" if PR_TRUE then free the object as well as its sub-objects
  216. */
  217. extern void CERT_DestroyCertificateRequest(CERTCertificateRequest *r);
  218. /*
  219. ** Start adding extensions to a certificate request.
  220. */
  221. void *
  222. CERT_StartCertificateRequestAttributes(CERTCertificateRequest *req);
  223. /*
  224. ** Reformat the certificate extension list into a CertificateRequest
  225. ** attribute list.
  226. */
  227. SECStatus
  228. CERT_FinishCertificateRequestAttributes(CERTCertificateRequest *req);
  229. /*
  230. ** Extract the Extension Requests from a DER CertRequest attribute list.
  231. */
  232. SECStatus
  233. CERT_GetCertificateRequestExtensions(CERTCertificateRequest *req,
  234. CERTCertExtension ***exts);
  235. /*
  236. ** Extract a public key object from a certificate
  237. */
  238. extern SECKEYPublicKey *CERT_ExtractPublicKey(CERTCertificate *cert);
  239. /*
  240. * used to get a public key with Key Material ID. Only used for fortezza V1
  241. * certificates.
  242. */
  243. extern SECKEYPublicKey *CERT_KMIDPublicKey(CERTCertificate *cert);
  244. /*
  245. ** Retrieve the Key Type associated with the cert we're dealing with
  246. */
  247. extern KeyType CERT_GetCertKeyType (CERTSubjectPublicKeyInfo *spki);
  248. /*
  249. ** Initialize the certificate database. This is called to create
  250. ** the initial list of certificates in the database.
  251. */
  252. extern SECStatus CERT_InitCertDB(CERTCertDBHandle *handle);
  253. extern int CERT_GetDBContentVersion(CERTCertDBHandle *handle);
  254. /*
  255. ** Default certificate database routines
  256. */
  257. extern void CERT_SetDefaultCertDB(CERTCertDBHandle *handle);
  258. extern CERTCertDBHandle *CERT_GetDefaultCertDB(void);
  259. extern CERTCertList *CERT_GetCertChainFromCert(CERTCertificate *cert,
  260. int64 time,
  261. SECCertUsage usage);
  262. extern CERTCertificate *
  263. CERT_NewTempCertificate (CERTCertDBHandle *handle, SECItem *derCert,
  264. char *nickname, PRBool isperm, PRBool copyDER);
  265. /******************************************************************************
  266. *
  267. * X.500 Name handling operations
  268. *
  269. *****************************************************************************/
  270. /*
  271. ** Create an AVA (attribute-value-assertion)
  272. ** "arena" the memory arena to alloc from
  273. ** "kind" is one of SEC_OID_AVA_*
  274. ** "valueType" is one of DER_PRINTABLE_STRING, DER_IA5_STRING, or
  275. ** DER_T61_STRING
  276. ** "value" is the null terminated string containing the value
  277. */
  278. extern CERTAVA *CERT_CreateAVA
  279. (PRArenaPool *arena, SECOidTag kind, int valueType, char *value);
  280. /*
  281. ** Extract the Distinguished Name from a DER encoded certificate
  282. ** "derCert" is the DER encoded certificate
  283. ** "derName" is the SECItem that the name is returned in
  284. */
  285. extern SECStatus CERT_NameFromDERCert(SECItem *derCert, SECItem *derName);
  286. /*
  287. ** Extract the Issuers Distinguished Name from a DER encoded certificate
  288. ** "derCert" is the DER encoded certificate
  289. ** "derName" is the SECItem that the name is returned in
  290. */
  291. extern SECStatus CERT_IssuerNameFromDERCert(SECItem *derCert,
  292. SECItem *derName);
  293. extern SECItem *
  294. CERT_EncodeGeneralName(CERTGeneralName *genName, SECItem *dest,
  295. PRArenaPool *arena);
  296. extern CERTGeneralName *
  297. CERT_DecodeGeneralName(PRArenaPool *reqArena, SECItem *encodedName,
  298. CERTGeneralName *genName);
  299. /*
  300. ** Generate a database search key for a certificate, based on the
  301. ** issuer and serial number.
  302. ** "arena" the memory arena to alloc from
  303. ** "derCert" the DER encoded certificate
  304. ** "key" the returned key
  305. */
  306. extern SECStatus CERT_KeyFromDERCert(PRArenaPool *reqArena, SECItem *derCert,
  307. SECItem *key);
  308. extern SECStatus CERT_KeyFromIssuerAndSN(PRArenaPool *arena, SECItem *issuer,
  309. SECItem *sn, SECItem *key);
  310. extern SECStatus CERT_SerialNumberFromDERCert(SECItem *derCert,
  311. SECItem *derName);
  312. /*
  313. ** Generate a database search key for a crl, based on the
  314. ** issuer.
  315. ** "arena" the memory arena to alloc from
  316. ** "derCrl" the DER encoded crl
  317. ** "key" the returned key
  318. */
  319. extern SECStatus CERT_KeyFromDERCrl(PRArenaPool *arena, SECItem *derCrl, SECItem *key);
  320. /*
  321. ** Open the certificate database. Use callback to get name of database.
  322. */
  323. extern SECStatus CERT_OpenCertDB(CERTCertDBHandle *handle, PRBool readOnly,
  324. CERTDBNameFunc namecb, void *cbarg);
  325. /* Open the certificate database. Use given filename for database. */
  326. extern SECStatus CERT_OpenCertDBFilename(CERTCertDBHandle *handle,
  327. char *certdbname, PRBool readOnly);
  328. /*
  329. ** Open and initialize a cert database that is entirely in memory. This
  330. ** can be used when the permanent database can not be opened or created.
  331. */
  332. extern SECStatus CERT_OpenVolatileCertDB(CERTCertDBHandle *handle);
  333. /*
  334. ** Extract the list of host names, host name patters, IP address strings
  335. ** this cert is valid for.
  336. ** This function does NOT return nicknames.
  337. ** Type CERTCertNicknames is being used because it's a convenient
  338. ** data structure to carry a list of strings and its count.
  339. */
  340. extern CERTCertNicknames *
  341. CERT_GetValidDNSPatternsFromCert(CERTCertificate *cert);
  342. /*
  343. ** Check the hostname to make sure that it matches the shexp that
  344. ** is given in the common name of the certificate.
  345. */
  346. extern SECStatus CERT_VerifyCertName(CERTCertificate *cert, const char *hostname);
  347. /*
  348. ** Add a domain name to the list of names that the user has explicitly
  349. ** allowed (despite cert name mismatches) for use with a server cert.
  350. */
  351. extern SECStatus CERT_AddOKDomainName(CERTCertificate *cert, const char *hostname);
  352. /*
  353. ** Decode a DER encoded certificate into an CERTCertificate structure
  354. ** "derSignedCert" is the DER encoded signed certificate
  355. ** "copyDER" is true if the DER should be copied, false if the
  356. ** existing copy should be referenced
  357. ** "nickname" is the nickname to use in the database. If it is NULL
  358. ** then a temporary nickname is generated.
  359. */
  360. extern CERTCertificate *
  361. CERT_DecodeDERCertificate (SECItem *derSignedCert, PRBool copyDER, char *nickname);
  362. /*
  363. ** Decode a DER encoded CRL/KRL into an CERTSignedCrl structure
  364. ** "derSignedCrl" is the DER encoded signed crl/krl.
  365. ** "type" is this a CRL or KRL.
  366. */
  367. #define SEC_CRL_TYPE 1
  368. #define SEC_KRL_TYPE 0
  369. extern CERTSignedCrl *
  370. CERT_DecodeDERCrl (PRArenaPool *arena, SECItem *derSignedCrl,int type);
  371. /*
  372. * same as CERT_DecodeDERCrl, plus allow options to be passed in
  373. */
  374. extern CERTSignedCrl *
  375. CERT_DecodeDERCrlWithFlags(PRArenaPool *narena, SECItem *derSignedCrl,
  376. int type, PRInt32 options);
  377. /* CRL options to pass */
  378. #define CRL_DECODE_DEFAULT_OPTIONS 0x00000000
  379. /* when CRL_DECODE_DONT_COPY_DER is set, the DER is not copied . The
  380. application must then keep derSignedCrl until it destroys the
  381. CRL . Ideally, it should allocate derSignedCrl in an arena
  382. and pass that arena in as the first argument to
  383. CERT_DecodeDERCrlWithFlags */
  384. #define CRL_DECODE_DONT_COPY_DER 0x00000001
  385. #define CRL_DECODE_SKIP_ENTRIES 0x00000002
  386. #define CRL_DECODE_KEEP_BAD_CRL 0x00000004
  387. #define CRL_DECODE_ADOPT_HEAP_DER 0x00000008
  388. /* complete the decoding of a partially decoded CRL, ie. decode the
  389. entries. Note that entries is an optional field in a CRL, so the
  390. "entries" pointer in CERTCrlStr may still be NULL even after
  391. function returns SECSuccess */
  392. extern SECStatus CERT_CompleteCRLDecodeEntries(CERTSignedCrl* crl);
  393. /* Validate CRL then import it to the dbase. If there is already a CRL with the
  394. * same CA in the dbase, it will be replaced if derCRL is more up to date.
  395. * If the process successes, a CRL will be returned. Otherwise, a NULL will
  396. * be returned. The caller should call PORT_GetError() for the exactly error
  397. * code.
  398. */
  399. extern CERTSignedCrl *
  400. CERT_ImportCRL (CERTCertDBHandle *handle, SECItem *derCRL, char *url,
  401. int type, void * wincx);
  402. extern void CERT_DestroyCrl (CERTSignedCrl *crl);
  403. /* this is a hint to flush the CRL cache. crlKey is the DER subject of
  404. the issuer (CA). */
  405. void CERT_CRLCacheRefreshIssuer(CERTCertDBHandle* dbhandle, SECItem* crlKey);
  406. /* add the specified DER CRL object to the CRL cache. Doing so will allow
  407. certificate verification functions (such as CERT_VerifyCertificate)
  408. to automatically find and make use of this CRL object.
  409. Once a CRL is added to the CRL cache, the application must hold on to
  410. the object's memory, because the cache will reference it directly. The
  411. application can only free the object after it calls CERT_UncacheCRL to
  412. remove it from the CRL cache.
  413. */
  414. SECStatus CERT_CacheCRL(CERTCertDBHandle* dbhandle, SECItem* newcrl);
  415. /* remove a previously added CRL object from the CRL cache. It is OK
  416. for the application to free the memory after a successful removal
  417. */
  418. SECStatus CERT_UncacheCRL(CERTCertDBHandle* dbhandle, SECItem* oldcrl);
  419. /*
  420. ** Decode a certificate and put it into the temporary certificate database
  421. */
  422. extern CERTCertificate *
  423. CERT_DecodeCertificate (SECItem *derCert, char *nickname,PRBool copyDER);
  424. /*
  425. ** Find a certificate in the database
  426. ** "key" is the database key to look for
  427. */
  428. extern CERTCertificate *CERT_FindCertByKey(CERTCertDBHandle *handle, SECItem *key);
  429. /*
  430. ** Find a certificate in the database by name
  431. ** "name" is the distinguished name to look up
  432. */
  433. extern CERTCertificate *
  434. CERT_FindCertByName (CERTCertDBHandle *handle, SECItem *name);
  435. /*
  436. ** Find a certificate in the database by name
  437. ** "name" is the distinguished name to look up (in ascii)
  438. */
  439. extern CERTCertificate *
  440. CERT_FindCertByNameString (CERTCertDBHandle *handle, char *name);
  441. /*
  442. ** Find a certificate in the database by name and keyid
  443. ** "name" is the distinguished name to look up
  444. ** "keyID" is the value of the subjectKeyID to match
  445. */
  446. extern CERTCertificate *
  447. CERT_FindCertByKeyID (CERTCertDBHandle *handle, SECItem *name, SECItem *keyID);
  448. /*
  449. ** Generate a certificate key from the issuer and serialnumber, then look it
  450. ** up in the database. Return the cert if found.
  451. ** "issuerAndSN" is the issuer and serial number to look for
  452. */
  453. extern CERTCertificate *
  454. CERT_FindCertByIssuerAndSN (CERTCertDBHandle *handle, CERTIssuerAndSN *issuerAndSN);
  455. /*
  456. ** Find a certificate in the database by a subject key ID
  457. ** "subjKeyID" is the subject Key ID to look for
  458. */
  459. extern CERTCertificate *
  460. CERT_FindCertBySubjectKeyID (CERTCertDBHandle *handle, SECItem *subjKeyID);
  461. /*
  462. ** Find a certificate in the database by a nickname
  463. ** "nickname" is the ascii string nickname to look for
  464. */
  465. extern CERTCertificate *
  466. CERT_FindCertByNickname (CERTCertDBHandle *handle, const char *nickname);
  467. /*
  468. ** Find a certificate in the database by a DER encoded certificate
  469. ** "derCert" is the DER encoded certificate
  470. */
  471. extern CERTCertificate *
  472. CERT_FindCertByDERCert(CERTCertDBHandle *handle, SECItem *derCert);
  473. /*
  474. ** Find a certificate in the database by a email address
  475. ** "emailAddr" is the email address to look up
  476. */
  477. CERTCertificate *
  478. CERT_FindCertByEmailAddr(CERTCertDBHandle *handle, char *emailAddr);
  479. /*
  480. ** Find a certificate in the database by a email address or nickname
  481. ** "name" is the email address or nickname to look up
  482. */
  483. CERTCertificate *
  484. CERT_FindCertByNicknameOrEmailAddr(CERTCertDBHandle *handle, const char *name);
  485. /*
  486. ** Find a certificate in the database by a digest of a subject public key
  487. ** "spkDigest" is the digest to look up
  488. */
  489. extern CERTCertificate *
  490. CERT_FindCertBySPKDigest(CERTCertDBHandle *handle, SECItem *spkDigest);
  491. /*
  492. * Find the issuer of a cert
  493. */
  494. CERTCertificate *
  495. CERT_FindCertIssuer(CERTCertificate *cert, int64 validTime, SECCertUsage usage);
  496. /*
  497. ** Check the validity times of a certificate vs. time 't', allowing
  498. ** some slop for broken clocks and stuff.
  499. ** "cert" is the certificate to be checked
  500. ** "t" is the time to check against
  501. ** "allowOverride" if true then check to see if the invalidity has
  502. ** been overridden by the user.
  503. */
  504. extern SECCertTimeValidity CERT_CheckCertValidTimes(CERTCertificate *cert,
  505. PRTime t,
  506. PRBool allowOverride);
  507. /*
  508. ** WARNING - this function is depricated, and will either go away or have
  509. ** a new API in the near future.
  510. **
  511. ** Check the validity times of a certificate vs. the current time, allowing
  512. ** some slop for broken clocks and stuff.
  513. ** "cert" is the certificate to be checked
  514. */
  515. extern SECStatus CERT_CertTimesValid(CERTCertificate *cert);
  516. /*
  517. ** Extract the validity times from a certificate
  518. ** "c" is the certificate
  519. ** "notBefore" is the start of the validity period
  520. ** "notAfter" is the end of the validity period
  521. */
  522. extern SECStatus
  523. CERT_GetCertTimes (CERTCertificate *c, PRTime *notBefore, PRTime *notAfter);
  524. /*
  525. ** Extract the issuer and serial number from a certificate
  526. */
  527. extern CERTIssuerAndSN *CERT_GetCertIssuerAndSN(PRArenaPool *,
  528. CERTCertificate *);
  529. /*
  530. ** verify the signature of a signed data object with a given certificate
  531. ** "sd" the signed data object to be verified
  532. ** "cert" the certificate to use to check the signature
  533. */
  534. extern SECStatus CERT_VerifySignedData(CERTSignedData *sd,
  535. CERTCertificate *cert,
  536. int64 t,
  537. void *wincx);
  538. /*
  539. ** verify the signature of a signed data object with the given DER publickey
  540. */
  541. extern SECStatus
  542. CERT_VerifySignedDataWithPublicKeyInfo(CERTSignedData *sd,
  543. CERTSubjectPublicKeyInfo *pubKeyInfo,
  544. void *wincx);
  545. /*
  546. ** verify the signature of a signed data object with a SECKEYPublicKey.
  547. */
  548. extern SECStatus
  549. CERT_VerifySignedDataWithPublicKey(CERTSignedData *sd,
  550. SECKEYPublicKey *pubKey, void *wincx);
  551. /*
  552. ** NEW FUNCTIONS with new bit-field-FIELD SECCertificateUsage - please use
  553. ** verify a certificate by checking validity times against a certain time,
  554. ** that we trust the issuer, and that the signature on the certificate is
  555. ** valid.
  556. ** "cert" the certificate to verify
  557. ** "checkSig" only check signatures if true
  558. */
  559. extern SECStatus
  560. CERT_VerifyCertificate(CERTCertDBHandle *handle, CERTCertificate *cert,
  561. PRBool checkSig, SECCertificateUsage requiredUsages,
  562. int64 t, void *wincx, CERTVerifyLog *log,
  563. SECCertificateUsage* returnedUsages);
  564. /* same as above, but uses current time */
  565. extern SECStatus
  566. CERT_VerifyCertificateNow(CERTCertDBHandle *handle, CERTCertificate *cert,
  567. PRBool checkSig, SECCertificateUsage requiredUsages,
  568. void *wincx, SECCertificateUsage* returnedUsages);
  569. /*
  570. ** Verify that a CA cert can certify some (unspecified) leaf cert for a given
  571. ** purpose. This is used by UI code to help identify where a chain may be
  572. ** broken and why. This takes identical parameters to CERT_VerifyCert
  573. */
  574. extern SECStatus
  575. CERT_VerifyCACertForUsage(CERTCertDBHandle *handle, CERTCertificate *cert,
  576. PRBool checkSig, SECCertUsage certUsage, int64 t,
  577. void *wincx, CERTVerifyLog *log);
  578. /*
  579. ** OLD OBSOLETE FUNCTIONS with enum SECCertUsage - DO NOT USE FOR NEW CODE
  580. ** verify a certificate by checking validity times against a certain time,
  581. ** that we trust the issuer, and that the signature on the certificate is
  582. ** valid.
  583. ** "cert" the certificate to verify
  584. ** "checkSig" only check signatures if true
  585. */
  586. extern SECStatus
  587. CERT_VerifyCert(CERTCertDBHandle *handle, CERTCertificate *cert,
  588. PRBool checkSig, SECCertUsage certUsage, int64 t,
  589. void *wincx, CERTVerifyLog *log);
  590. /* same as above, but uses current time */
  591. extern SECStatus
  592. CERT_VerifyCertNow(CERTCertDBHandle *handle, CERTCertificate *cert,
  593. PRBool checkSig, SECCertUsage certUsage, void *wincx);
  594. SECStatus
  595. CERT_VerifyCertChain(CERTCertDBHandle *handle, CERTCertificate *cert,
  596. PRBool checkSig, SECCertUsage certUsage, int64 t,
  597. void *wincx, CERTVerifyLog *log);
  598. /*
  599. ** Read a base64 ascii encoded DER certificate and convert it to our
  600. ** internal format.
  601. ** "certstr" is a null-terminated string containing the certificate
  602. */
  603. extern CERTCertificate *CERT_ConvertAndDecodeCertificate(char *certstr);
  604. /*
  605. ** Read a certificate in some foreign format, and convert it to our
  606. ** internal format.
  607. ** "certbuf" is the buffer containing the certificate
  608. ** "certlen" is the length of the buffer
  609. ** NOTE - currently supports netscape base64 ascii encoded raw certs
  610. ** and netscape binary DER typed files.
  611. */
  612. extern CERTCertificate *CERT_DecodeCertFromPackage(char *certbuf, int certlen);
  613. extern SECStatus
  614. CERT_ImportCAChain (SECItem *certs, int numcerts, SECCertUsage certUsage);
  615. extern SECStatus
  616. CERT_ImportCAChainTrusted(SECItem *certs, int numcerts, SECCertUsage certUsage);
  617. /*
  618. ** Read a certificate chain in some foreign format, and pass it to a
  619. ** callback function.
  620. ** "certbuf" is the buffer containing the certificate
  621. ** "certlen" is the length of the buffer
  622. ** "f" is the callback function
  623. ** "arg" is the callback argument
  624. */
  625. typedef SECStatus (PR_CALLBACK *CERTImportCertificateFunc)
  626. (void *arg, SECItem **certs, int numcerts);
  627. extern SECStatus
  628. CERT_DecodeCertPackage(char *certbuf, int certlen, CERTImportCertificateFunc f,
  629. void *arg);
  630. /*
  631. ** Returns the value of an AVA. This was a formerly static
  632. ** function that has been exposed due to the need to decode
  633. ** and convert unicode strings to UTF8.
  634. **
  635. ** XXX This function resides in certhtml.c, should it be
  636. ** moved elsewhere?
  637. */
  638. extern SECItem *CERT_DecodeAVAValue(const SECItem *derAVAValue);
  639. /*
  640. ** extract various element strings from a distinguished name.
  641. ** "name" the distinguished name
  642. */
  643. extern char *CERT_GetCertificateEmailAddress(CERTCertificate *cert);
  644. extern char *CERT_GetCertEmailAddress(CERTName *name);
  645. extern const char * CERT_GetFirstEmailAddress(CERTCertificate * cert);
  646. extern const char * CERT_GetNextEmailAddress(CERTCertificate * cert,
  647. const char * prev);
  648. /* The return value must be freed with PORT_Free. */
  649. extern char *CERT_GetCommonName(CERTName *name);
  650. extern char *CERT_GetCountryName(CERTName *name);
  651. extern char *CERT_GetLocalityName(CERTName *name);
  652. extern char *CERT_GetStateName(CERTName *name);
  653. extern char *CERT_GetOrgName(CERTName *name);
  654. extern char *CERT_GetOrgUnitName(CERTName *name);
  655. extern char *CERT_GetDomainComponentName(CERTName *name);
  656. extern char *CERT_GetCertUid(CERTName *name);
  657. /* manipulate the trust parameters of a certificate */
  658. extern SECStatus CERT_GetCertTrust(CERTCertificate *cert, CERTCertTrust *trust);
  659. extern SECStatus
  660. CERT_ChangeCertTrust (CERTCertDBHandle *handle, CERTCertificate *cert,
  661. CERTCertTrust *trust);
  662. extern SECStatus
  663. CERT_ChangeCertTrustByUsage(CERTCertDBHandle *certdb, CERTCertificate *cert,
  664. SECCertUsage usage);
  665. /*************************************************************************
  666. *
  667. * manipulate the extensions of a certificate
  668. *
  669. ************************************************************************/
  670. /*
  671. ** Set up a cert for adding X509v3 extensions. Returns an opaque handle
  672. ** used by the next two routines.
  673. ** "cert" is the certificate we are adding extensions to
  674. */
  675. extern void *CERT_StartCertExtensions(CERTCertificate *cert);
  676. /*
  677. ** Add an extension to a certificate.
  678. ** "exthandle" is the handle returned by the previous function
  679. ** "idtag" is the integer tag for the OID that should ID this extension
  680. ** "value" is the value of the extension
  681. ** "critical" is the critical extension flag
  682. ** "copyData" is a flag indicating whether the value data should be
  683. ** copied.
  684. */
  685. extern SECStatus CERT_AddExtension (void *exthandle, int idtag,
  686. SECItem *value, PRBool critical, PRBool copyData);
  687. extern SECStatus CERT_AddExtensionByOID (void *exthandle, SECItem *oid,
  688. SECItem *value, PRBool critical, PRBool copyData);
  689. extern SECStatus CERT_EncodeAndAddExtension
  690. (void *exthandle, int idtag, void *value, PRBool critical,
  691. const SEC_ASN1Template *atemplate);
  692. extern SECStatus CERT_EncodeAndAddBitStrExtension
  693. (void *exthandle, int idtag, SECItem *value, PRBool critical);
  694. extern SECStatus
  695. CERT_EncodeAltNameExtension(PRArenaPool *arena, CERTGeneralName *value, SECItem *encodedValue);
  696. /*
  697. ** Finish adding cert extensions. Does final processing on extension
  698. ** data, putting it in the right format, and freeing any temporary
  699. ** storage.
  700. ** "exthandle" is the handle used to add extensions to a certificate
  701. */
  702. extern SECStatus CERT_FinishExtensions(void *exthandle);
  703. /*
  704. ** Merge an external list of extensions into a cert's extension list, adding one
  705. ** only when its OID matches none of the cert's existing extensions. Call this
  706. ** immediately before calling CERT_FinishExtensions().
  707. */
  708. SECStatus
  709. CERT_MergeExtensions(void *exthandle, CERTCertExtension **exts);
  710. /* If the extension is found, return its criticality and value.
  711. ** This allocate storage for the returning extension value.
  712. */
  713. extern SECStatus CERT_GetExtenCriticality
  714. (CERTCertExtension **extensions, int tag, PRBool *isCritical);
  715. extern void
  716. CERT_DestroyOidSequence(CERTOidSequence *oidSeq);
  717. /****************************************************************************
  718. *
  719. * DER encode and decode extension values
  720. *
  721. ****************************************************************************/
  722. /* Encode the value of the basicConstraint extension.
  723. ** arena - where to allocate memory for the encoded value.
  724. ** value - extension value to encode
  725. ** encodedValue - output encoded value
  726. */
  727. extern SECStatus CERT_EncodeBasicConstraintValue
  728. (PRArenaPool *arena, CERTBasicConstraints *value, SECItem *encodedValue);
  729. /*
  730. ** Encode the value of the authorityKeyIdentifier extension.
  731. */
  732. extern SECStatus CERT_EncodeAuthKeyID
  733. (PRArenaPool *arena, CERTAuthKeyID *value, SECItem *encodedValue);
  734. /*
  735. ** Encode the value of the crlDistributionPoints extension.
  736. */
  737. extern SECStatus CERT_EncodeCRLDistributionPoints
  738. (PRArenaPool *arena, CERTCrlDistributionPoints *value,SECItem *derValue);
  739. /*
  740. ** Decodes a DER encoded basicConstaint extension value into a readable format
  741. ** value - decoded value
  742. ** encodedValue - value to decoded
  743. */
  744. extern SECStatus CERT_DecodeBasicConstraintValue
  745. (CERTBasicConstraints *value, SECItem *encodedValue);
  746. /* Decodes a DER encoded authorityKeyIdentifier extension value into a
  747. ** readable format.
  748. ** arena - where to allocate memory for the decoded value
  749. ** encodedValue - value to be decoded
  750. ** Returns a CERTAuthKeyID structure which contains the decoded value
  751. */
  752. extern CERTAuthKeyID *CERT_DecodeAuthKeyID
  753. (PRArenaPool *arena, SECItem *encodedValue);
  754. /* Decodes a DER encoded crlDistributionPoints extension value into a
  755. ** readable format.
  756. ** arena - where to allocate memory for the decoded value
  757. ** der - value to be decoded
  758. ** Returns a CERTCrlDistributionPoints structure which contains the
  759. ** decoded value
  760. */
  761. extern CERTCrlDistributionPoints * CERT_DecodeCRLDistributionPoints
  762. (PRArenaPool *arena, SECItem *der);
  763. /* Extract certain name type from a generalName */
  764. extern void *CERT_GetGeneralNameByType
  765. (CERTGeneralName *genNames, CERTGeneralNameType type, PRBool derFormat);
  766. extern CERTOidSequence *
  767. CERT_DecodeOidSequence(SECItem *seqItem);
  768. /****************************************************************************
  769. *
  770. * Find extension values of a certificate
  771. *
  772. ***************************************************************************/
  773. extern SECStatus CERT_FindCertExtension
  774. (CERTCertificate *cert, int tag, SECItem *value);
  775. extern SECStatus CERT_FindNSCertTypeExtension
  776. (CERTCertificate *cert, SECItem *value);
  777. extern char * CERT_FindNSStringExtension (CERTCertificate *cert, int oidtag);
  778. extern SECStatus CERT_FindIssuerCertExtension
  779. (CERTCertificate *cert, int tag, SECItem *value);
  780. extern SECStatus CERT_FindCertExtensionByOID
  781. (CERTCertificate *cert, SECItem *oid, SECItem *value);
  782. extern char *CERT_FindCertURLExtension (CERTCertificate *cert, int tag,
  783. int catag);
  784. /* Returns the decoded value of the authKeyID extension.
  785. ** Note that this uses passed in the arena to allocate storage for the result
  786. */
  787. extern CERTAuthKeyID * CERT_FindAuthKeyIDExten (PRArenaPool *arena,CERTCertificate *cert);
  788. /* Returns the decoded value of the basicConstraint extension.
  789. */
  790. extern SECStatus CERT_FindBasicConstraintExten
  791. (CERTCertificate *cert, CERTBasicConstraints *value);
  792. /* Returns the decoded value of the crlDistributionPoints extension.
  793. ** Note that the arena in cert is used to allocate storage for the result
  794. */
  795. extern CERTCrlDistributionPoints * CERT_FindCRLDistributionPoints
  796. (CERTCertificate *cert);
  797. /* Returns value of the keyUsage extension. This uses PR_Alloc to allocate
  798. ** buffer for the decoded value. The caller should free up the storage
  799. ** allocated in value->data.
  800. */
  801. extern SECStatus CERT_FindKeyUsageExtension (CERTCertificate *cert,
  802. SECItem *value);
  803. /* Return the decoded value of the subjectKeyID extension. The caller should
  804. ** free up the storage allocated in retItem->data.
  805. */
  806. extern SECStatus CERT_FindSubjectKeyIDExtension (CERTCertificate *cert,
  807. SECItem *retItem);
  808. /*
  809. ** If cert is a v3 certificate, and a critical keyUsage extension is included,
  810. ** then check the usage against the extension value. If a non-critical
  811. ** keyUsage extension is included, this will return SECSuccess without
  812. ** checking, since the extension is an advisory field, not a restriction.
  813. ** If cert is not a v3 certificate, this will return SECSuccess.
  814. ** cert - certificate
  815. ** usage - one of the x.509 v3 the Key Usage Extension flags
  816. */
  817. extern SECStatus CERT_CheckCertUsage (CERTCertificate *cert,
  818. unsigned char usage);
  819. /****************************************************************************
  820. *
  821. * CRL v2 Extensions supported routines
  822. *
  823. ****************************************************************************/
  824. extern SECStatus CERT_FindCRLExtensionByOID
  825. (CERTCrl *crl, SECItem *oid, SECItem *value);
  826. extern SECStatus CERT_FindCRLExtension
  827. (CERTCrl *crl, int tag, SECItem *value);
  828. extern SECStatus
  829. CERT_FindInvalidDateExten (CERTCrl *crl, int64 *value);
  830. /*
  831. ** Set up a crl for adding X509v3 extensions. Returns an opaque handle
  832. ** used by routines that take an exthandle (void*) argument .
  833. ** "crl" is the CRL we are adding extensions to
  834. */
  835. extern void *CERT_StartCRLExtensions(CERTCrl *crl);
  836. /*
  837. ** Set up a crl entry for adding X509v3 extensions. Returns an opaque handle
  838. ** used by routines that take an exthandle (void*) argument .
  839. ** "crl" is the crl we are adding certs entries to
  840. ** "entry" is the crl entry we are adding extensions to
  841. */
  842. extern void *CERT_StartCRLEntryExtensions(CERTCrl *crl, CERTCrlEntry *entry);
  843. extern CERTCertNicknames *CERT_GetCertNicknames (CERTCertDBHandle *handle,
  844. int what, void *wincx);
  845. /*
  846. ** Finds the crlNumber extension and decodes its value into 'value'
  847. */
  848. extern SECStatus CERT_FindCRLNumberExten (PRArenaPool *arena, CERTCrl *crl,
  849. SECItem *value);
  850. extern SECStatus CERT_FindCRLEntryReasonExten (CERTCrlEntry *crlEntry,
  851. CERTCRLEntryReasonCode *value);
  852. extern void CERT_FreeNicknames(CERTCertNicknames *nicknames);
  853. extern PRBool CERT_CompareCerts(CERTCertificate *c1, CERTCertificate *c2);
  854. extern PRBool CERT_CompareCertsForRedirection(CERTCertificate *c1,
  855. CERTCertificate *c2);
  856. /*
  857. ** Generate an array of the Distinguished Names that the given cert database
  858. ** "trusts"
  859. */
  860. extern CERTDistNames *CERT_GetSSLCACerts(CERTCertDBHandle *handle);
  861. extern void CERT_FreeDistNames(CERTDistNames *names);
  862. /*
  863. ** Generate an array of Distinguished names from an array of nicknames
  864. */
  865. extern CERTDistNames *CERT_DistNamesFromNicknames
  866. (CERTCertDBHandle *handle, char **nicknames, int nnames);
  867. /*
  868. ** Generate a certificate chain from a certificate.
  869. */
  870. extern CERTCertificateList *
  871. CERT_CertChainFromCert(CERTCertificate *cert, SECCertUsage usage,
  872. PRBool includeRoot);
  873. extern CERTCertificateList *
  874. CERT_CertListFromCert(CERTCertificate *cert);
  875. extern CERTCertificateList *
  876. CERT_DupCertList(CERTCertificateList * oldList);
  877. extern void CERT_DestroyCertificateList(CERTCertificateList *list);
  878. /*
  879. ** is cert a user cert? i.e. does it have CERTDB_USER trust,
  880. ** i.e. a private key?
  881. */
  882. PRBool CERT_IsUserCert(CERTCertificate* cert);
  883. /* is cert a newer than cert b? */
  884. PRBool CERT_IsNewer(CERTCertificate *certa, CERTCertificate *certb);
  885. /* currently a stub for address book */
  886. PRBool
  887. CERT_IsCertRevoked(CERTCertificate *cert);
  888. void
  889. CERT_DestroyCertArray(CERTCertificate **certs, unsigned int ncerts);
  890. /* convert an email address to lower case */
  891. char *CERT_FixupEmailAddr(const char *emailAddr);
  892. /* decode string representation of trust flags into trust struct */
  893. SECStatus
  894. CERT_DecodeTrustString(CERTCertTrust *trust, char *trusts);
  895. /* encode trust struct into string representation of trust flags */
  896. char *
  897. CERT_EncodeTrustString(CERTCertTrust *trust);
  898. /* find the next or prev cert in a subject list */
  899. CERTCertificate *
  900. CERT_PrevSubjectCert(CERTCertificate *cert);
  901. CERTCertificate *
  902. CERT_NextSubjectCert(CERTCertificate *cert);
  903. /*
  904. * import a collection of certs into the temporary or permanent cert
  905. * database
  906. */
  907. SECStatus
  908. CERT_ImportCerts(CERTCertDBHandle *certdb, SECCertUsage usage,
  909. unsigned int ncerts, SECItem **derCerts,
  910. CERTCertificate ***retCerts, PRBool keepCerts,
  911. PRBool caOnly, char *nickname);
  912. char *
  913. CERT_MakeCANickname(CERTCertificate *cert);
  914. PRBool
  915. CERT_IsCACert(CERTCertificate *cert, unsigned int *rettype);
  916. PRBool
  917. CERT_IsCADERCert(SECItem *derCert, unsigned int *rettype);
  918. PRBool
  919. CERT_IsRootDERCert(SECItem *derCert);
  920. SECStatus
  921. CERT_SaveSMimeProfile(CERTCertificate *cert, SECItem *emailProfile,
  922. SECItem *profileTime);
  923. /*
  924. * find the smime symmetric capabilities profile for a given cert
  925. */
  926. SECItem *
  927. CERT_FindSMimeProfile(CERTCertificate *cert);
  928. SECStatus
  929. CERT_AddNewCerts(CERTCertDBHandle *handle);
  930. CERTPackageType
  931. CERT_CertPackageType(SECItem *package, SECItem *certitem);
  932. CERTCertificatePolicies *
  933. CERT_DecodeCertificatePoliciesExtension(SECItem *extnValue);
  934. void
  935. CERT_DestroyCertificatePoliciesExtension(CERTCertificatePolicies *policies);
  936. CERTCertificatePolicyMappings *
  937. CERT_DecodePolicyMappingsExtension(SECItem *encodedCertPolicyMaps);
  938. SECStatus
  939. CERT_DestroyPolicyMappingsExtension(CERTCertificatePolicyMappings *mappings);
  940. SECStatus
  941. CERT_DecodePolicyConstraintsExtension(
  942. CERTCertificatePolicyConstraints *decodedValue, SECItem *encodedValue);
  943. SECStatus CERT_DecodeInhibitAnyExtension
  944. (CERTCertificateInhibitAny *decodedValue, SECItem *extnValue);
  945. CERTUserNotice *
  946. CERT_DecodeUserNotice(SECItem *noticeItem);
  947. extern CERTGeneralName *
  948. CERT_DecodeAltNameExtension(PRArenaPool *reqArena, SECItem *EncodedAltName);
  949. extern CERTNameConstraints *
  950. CERT_DecodeNameConstraintsExtension(PRArenaPool *arena,
  951. SECItem *encodedConstraints);
  952. /* returns addr of a NULL termainated array of pointers to CERTAuthInfoAccess */
  953. extern CERTAuthInfoAccess **
  954. CERT_DecodeAuthInfoAccessExtension(PRArenaPool *reqArena,
  955. SECItem *encodedExtension);
  956. extern CERTPrivKeyUsagePeriod *
  957. CERT_DecodePrivKeyUsagePeriodExtension(PLArenaPool *arena, SECItem *extnValue);
  958. extern CERTGeneralName *
  959. CERT_GetNextGeneralName(CERTGeneralName *current);
  960. extern CERTGeneralName *
  961. CERT_GetPrevGeneralName(CERTGeneralName *current);
  962. CERTNameConstraint *
  963. CERT_GetNextNameConstraint(CERTNameConstraint *current);
  964. CERTNameConstraint *
  965. CERT_GetPrevNameConstraint(CERTNameConstraint *current);
  966. void
  967. CERT_DestroyUserNotice(CERTUserNotice *userNotice);
  968. typedef char * (* CERTPolicyStringCallback)(char *org,
  969. unsigned long noticeNumber,
  970. void *arg);
  971. void
  972. CERT_SetCAPolicyStringCallback(CERTPolicyStringCallback cb, void *cbarg);
  973. char *
  974. CERT_GetCertCommentString(CERTCertificate *cert);
  975. PRBool
  976. CERT_GovtApprovedBitSet(CERTCertificate *cert);
  977. SECStatus
  978. CERT_AddPermNickname(CERTCertificate *cert, char *nickname);
  979. CERTCertList *
  980. CERT_MatchUserCert(CERTCertDBHandle *handle,
  981. SECCertUsage usage,
  982. int nCANames, char **caNames,
  983. void *proto_win);
  984. CERTCertList *
  985. CERT_NewCertList(void);
  986. void
  987. CERT_DestroyCertList(CERTCertList *certs);
  988. /* remove the node and free the cert */
  989. void
  990. CERT_RemoveCertListNode(CERTCertListNode *node);
  991. SECStatus
  992. CERT_AddCertToListTail(CERTCertList *certs, CERTCertificate *cert);
  993. SECStatus
  994. CERT_AddCertToListHead(CERTCertList *certs, CERTCertificate *cert);
  995. SECStatus
  996. CERT_AddCertToListTailWithData(CERTCertList *certs, CERTCertificate *cert,
  997. void *appData);
  998. SECStatus
  999. CERT_AddCertToListHeadWithData(CERTCertList *certs, CERTCertificate *cert,
  1000. void *appData);
  1001. typedef PRBool (* CERTSortCallback)(CERTCertificate *certa,
  1002. CERTCertificate *certb,
  1003. void *arg);
  1004. SECStatus
  1005. CERT_AddCertToListSorted(CERTCertList *certs, CERTCertificate *cert,
  1006. CERTSortCallback f, void *arg);
  1007. /* callback for CERT_AddCertToListSorted that sorts based on validity
  1008. * period and a given time.
  1009. */
  1010. PRBool
  1011. CERT_SortCBValidity(CERTCertificate *certa,
  1012. CERTCertificate *certb,
  1013. void *arg);
  1014. SECStatus
  1015. CERT_CheckForEvilCert(CERTCertificate *cert);
  1016. CERTGeneralName *
  1017. CERT_GetCertificateNames(CERTCertificate *cert, PRArenaPool *arena);
  1018. char *
  1019. CERT_GetNickName(CERTCertificate *cert, CERTCertDBHandle *handle, PRArenaPool *nicknameArena);
  1020. /*
  1021. * Creates or adds to a list of all certs with a give subject name, sorted by
  1022. * validity time, newest first. Invalid certs are considered older than
  1023. * valid certs. If validOnly is set, do not include invalid certs on list.
  1024. */
  1025. CERTCertList *
  1026. CERT_CreateSubjectCertList(CERTCertList *certList, CERTCertDBHandle *handle,
  1027. SECItem *name, int64 sorttime, PRBool validOnly);
  1028. /*
  1029. * Creates or adds to a list of all certs with a give nickname, sorted by
  1030. * validity time, newest first. Invalid certs are considered older than valid
  1031. * certs. If validOnly is set, do not include invalid certs on list.
  1032. */
  1033. CERTCertList *
  1034. CERT_CreateNicknameCertList(CERTCertList *certList, CERTCertDBHandle *handle,
  1035. char *nickname, int64 sorttime, PRBool validOnly);
  1036. /*
  1037. * Creates or adds to a list of all certs with a give email addr, sorted by
  1038. * validity time, newest first. Invalid certs are considered older than valid
  1039. * certs. If validOnly is set, do not include invalid certs on list.
  1040. */
  1041. CERTCertList *
  1042. CERT_CreateEmailAddrCertList(CERTCertList *certList, CERTCertDBHandle *handle,
  1043. char *emailAddr, int64 sorttime, PRBool validOnly);
  1044. /*
  1045. * remove certs from a list that don't have keyUsage and certType
  1046. * that match the given usage.
  1047. */
  1048. SECStatus
  1049. CERT_FilterCertListByUsage(CERTCertList *certList, SECCertUsage usage,
  1050. PRBool ca);
  1051. /*
  1052. * check the key usage of a cert against a set of required values
  1053. */
  1054. SECStatus
  1055. CERT_CheckKeyUsage(CERTCertificate *cert, unsigned int requiredUsage);
  1056. /*
  1057. * return required key usage and cert type based on cert usage
  1058. */
  1059. SECStatus
  1060. CERT_KeyUsageAndTypeForCertUsage(SECCertUsage usage,
  1061. PRBool ca,
  1062. unsigned int *retKeyUsage,
  1063. unsigned int *retCertType);
  1064. /*
  1065. * return required trust flags for various cert usages for CAs
  1066. */
  1067. SECStatus
  1068. CERT_TrustFlagsForCACertUsage(SECCertUsage usage,
  1069. unsigned int *retFlags,
  1070. SECTrustType *retTrustType);
  1071. /*
  1072. * Find all user certificates that match the given criteria.
  1073. *
  1074. * "handle" - database to search
  1075. * "usage" - certificate usage to match
  1076. * "oneCertPerName" - if set then only return the "best" cert per
  1077. * name
  1078. * "validOnly" - only return certs that are curently valid
  1079. * "proto_win" - window handle passed to pkcs11
  1080. */
  1081. CERTCertList *
  1082. CERT_FindUserCertsByUsage(CERTCertDBHandle *handle,
  1083. SECCertUsage usage,
  1084. PRBool oneCertPerName,
  1085. PRBool validOnly,
  1086. void *proto_win);
  1087. /*
  1088. * Find a user certificate that matchs the given criteria.
  1089. *
  1090. * "handle" - database to search
  1091. * "nickname" - nickname to match
  1092. * "usage" - certificate usage to match
  1093. * "validOnly" - only return certs that are curently valid
  1094. * "proto_win" - window handle passed to pkcs11
  1095. */
  1096. CERTCertificate *
  1097. CERT_FindUserCertByUsage(CERTCertDBHandle *handle,
  1098. const char *nickname,
  1099. SECCertUsage usage,
  1100. PRBool validOnly,
  1101. void *proto_win);
  1102. /*
  1103. * Filter a list of certificates, removing those certs that do not have
  1104. * one of the named CA certs somewhere in their cert chain.
  1105. *
  1106. * "certList" - the list of certificates to filter
  1107. * "nCANames" - number of CA names
  1108. * "caNames" - array of CA names in string(rfc 1485) form
  1109. * "usage" - what use the certs are for, this is used when
  1110. * selecting CA certs
  1111. */
  1112. SECStatus
  1113. CERT_FilterCertListByCANames(CERTCertList *certList, int nCANames,
  1114. char **caNames, SECCertUsage usage);
  1115. /*
  1116. * Filter a list of certificates, removing those certs that aren't user certs
  1117. */
  1118. SECStatus
  1119. CERT_FilterCertListForUserCerts(CERTCertList *certList);
  1120. /*
  1121. * Collect the nicknames from all certs in a CertList. If the cert is not
  1122. * valid, append a string to that nickname.
  1123. *
  1124. * "certList" - the list of certificates
  1125. * "expiredString" - the string to append to the nickname of any expired cert
  1126. * "notYetGoodString" - the string to append to the nickname of any cert
  1127. * that is not yet valid
  1128. */
  1129. CERTCertNicknames *
  1130. CERT_NicknameStringsFromCertList(CERTCertList *certList, char *expiredString,
  1131. char *notYetGoodString);
  1132. /*
  1133. * Extract the nickname from a nickmake string that may have either
  1134. * expiredString or notYetGoodString appended.
  1135. *
  1136. * Args:
  1137. * "namestring" - the string containing the nickname, and possibly
  1138. * one of the validity label strings
  1139. * "expiredString" - the expired validity label string
  1140. * "notYetGoodString" - the not yet good validity label string
  1141. *
  1142. * Returns the raw nickname
  1143. */
  1144. char *
  1145. CERT_ExtractNicknameString(char *namestring, char *expiredString,
  1146. char *notYetGoodString);
  1147. /*
  1148. * Given a certificate, return a string containing the nickname, and possibly
  1149. * one of the validity strings, based on the current validity state of the
  1150. * certificate.
  1151. *
  1152. * "arena" - arena to allocate returned string from. If NULL, then heap
  1153. * is used.
  1154. * "cert" - the cert to get nickname from
  1155. * "expiredString" - the string to append to the nickname if the cert is
  1156. * expired.
  1157. * "notYetGoodString" - the string to append to the nickname if the cert is
  1158. * not yet good.
  1159. */
  1160. char *
  1161. CERT_GetCertNicknameWithValidity(PRArenaPool *arena, CERTCertificate *cert,
  1162. char *expiredString, char *notYetGoodString);
  1163. /*
  1164. * Return the string representation of a DER encoded distinguished name
  1165. * "dername" - The DER encoded name to convert
  1166. */
  1167. char *
  1168. CERT_DerNameToAscii(SECItem *dername);
  1169. /*
  1170. * Supported usage values and types:
  1171. * certUsageSSLClient
  1172. * certUsageSSLServer
  1173. * certUsageSSLServerWithStepUp
  1174. * certUsageEmailSigner
  1175. * certUsageEmailRecipient
  1176. * certUsageObjectSigner
  1177. */
  1178. CERTCertificate *
  1179. CERT_FindMatchingCert(CERTCertDBHandle *handle, SECItem *derName,
  1180. CERTCertOwner owner, SECCertUsage usage,
  1181. PRBool preferTrusted, int64 validTime, PRBool validOnly);
  1182. /*
  1183. * Acquire the global lock on the cert database.
  1184. * This lock is currently used for the following operations:
  1185. * adding or deleting a cert to either the temp or perm databases
  1186. * converting a temp to perm or perm to temp
  1187. * changing(maybe just adding?) the trust of a cert
  1188. * adjusting the reference count of a cert
  1189. */
  1190. void
  1191. CERT_LockDB(CERTCertDBHandle *handle);
  1192. /*
  1193. * Free the global cert database lock.
  1194. */
  1195. void
  1196. CERT_UnlockDB(CERTCertDBHandle *handle);
  1197. /*
  1198. * Get the certificate status checking configuratino data for
  1199. * the certificate database
  1200. */
  1201. CERTStatusConfig *
  1202. CERT_GetStatusConfig(CERTCertDBHandle *handle);
  1203. /*
  1204. * Set the certificate status checking information for the
  1205. * database. The input structure becomes part of the certificate
  1206. * database and will be freed by calling the 'Destroy' function in
  1207. * the configuration object.
  1208. */
  1209. void
  1210. CERT_SetStatusConfig(CERTCertDBHandle *handle, CERTStatusConfig *config);
  1211. /*
  1212. * Acquire the cert reference count lock
  1213. * There is currently one global lock for all certs, but I'm putting a cert
  1214. * arg here so that it will be easy to make it per-cert in the future if
  1215. * that turns out to be necessary.
  1216. */
  1217. void
  1218. CERT_LockCertRefCount(CERTCertificate *cert);
  1219. /*
  1220. * Free the cert reference count lock
  1221. */
  1222. void
  1223. CERT_UnlockCertRefCount(CERTCertificate *cert);
  1224. /*
  1225. * Acquire the cert trust lock
  1226. * There is currently one global lock for all certs, but I'm putting a cert
  1227. * arg here so that it will be easy to make it per-cert in the future if
  1228. * that turns out to be necessary.
  1229. */
  1230. void
  1231. CERT_LockCertTrust(CERTCertificate *cert);
  1232. /*
  1233. * Free the cert trust lock
  1234. */
  1235. void
  1236. CERT_UnlockCertTrust(CERTCertificate *cert);
  1237. /*
  1238. * Digest the cert's subject public key using the specified algorithm.
  1239. * The necessary storage for the digest data is allocated. If "fill" is
  1240. * non-null, the data is put there, otherwise a SECItem is allocated.
  1241. * Allocation from "arena" if it is non-null, heap otherwise. Any problem
  1242. * results in a NULL being returned (and an appropriate error set).
  1243. */
  1244. extern SECItem *
  1245. CERT_GetSPKIDigest(PRArenaPool *arena, const CERTCertificate *cert,
  1246. SECOidTag digestAlg, SECItem *fill);
  1247. SECStatus CERT_CheckCRL(CERTCertificate* cert, CERTCertificate* issuer,
  1248. SECItem* dp, int64 t, void* wincx);
  1249. /*
  1250. * Add a CERTNameConstraint to the CERTNameConstraint list
  1251. */
  1252. extern CERTNameConstraint *
  1253. CERT_AddNameConstraint(CERTNameConstraint *list,
  1254. CERTNameConstraint *constraint);
  1255. /*
  1256. * Allocate space and copy CERTNameConstraint from src to dest.
  1257. * Arena is used to allocate result(if dest eq NULL) and its members
  1258. * SECItem data.
  1259. */
  1260. extern CERTNameConstraint *
  1261. CERT_CopyNameConstraint(PRArenaPool *arena,
  1262. CERTNameConstraint *dest,
  1263. CERTNameConstraint *src);
  1264. /*
  1265. * Verify name against all the constraints relevant to that type of
  1266. * the name.
  1267. */
  1268. extern SECStatus
  1269. CERT_CheckNameSpace(PRArenaPool *arena,
  1270. CERTNameConstraints *constraints,
  1271. CERTGeneralName *currentName);
  1272. /*
  1273. * Extract and allocate the name constraints extension from the CA cert.
  1274. */
  1275. extern SECStatus
  1276. CERT_FindNameConstraintsExten(PRArenaPool *arena,
  1277. CERTCertificate *cert,
  1278. CERTNameConstraints **constraints);
  1279. /*
  1280. * Initialize a new GERTGeneralName fields (link)
  1281. */
  1282. extern CERTGeneralName *
  1283. CERT_NewGeneralName(PLArenaPool *arena, CERTGeneralNameType type);
  1284. /*
  1285. * PKIX extension encoding routines
  1286. */
  1287. extern SECStatus
  1288. CERT_EncodePolicyConstraintsExtension(PRArenaPool *arena,
  1289. CERTCertificatePolicyConstraints *constr,
  1290. SECItem *dest);
  1291. extern SECStatus
  1292. CERT_EncodeInhibitAnyExtension(PRArenaPool *arena,
  1293. CERTCertificateInhibitAny *inhibitAny,
  1294. SECItem *dest);
  1295. extern SECStatus
  1296. CERT_EncodePolicyMappingExtension(PRArenaPool *arena,
  1297. CERTCertificatePolicyMappings *maps,
  1298. SECItem *dest);
  1299. extern SECStatus CERT_EncodeInfoAccessExtension(PRArenaPool *arena,
  1300. CERTAuthInfoAccess **info,
  1301. SECItem *dest);
  1302. extern SECStatus
  1303. CERT_EncodeUserNotice(PRArenaPool *arena,
  1304. CERTUserNotice *notice,
  1305. SECItem *dest);
  1306. extern SECStatus
  1307. CERT_EncodeDisplayText(PRArenaPool *arena,
  1308. SECItem *text,
  1309. SECItem *dest);
  1310. extern SECStatus
  1311. CERT_EncodeCertPoliciesExtension(PRArenaPool *arena,
  1312. CERTPolicyInfo **info,
  1313. SECItem *dest);
  1314. extern SECStatus
  1315. CERT_EncodeNoticeReference(PRArenaPool *arena,
  1316. CERTNoticeReference *reference,
  1317. SECItem *dest);
  1318. /*
  1319. * Returns a pointer to a static structure.
  1320. */
  1321. extern const CERTRevocationFlags*
  1322. CERT_GetPKIXVerifyNistRevocationPolicy();
  1323. /*
  1324. * Returns a pointer to a static structure.
  1325. */
  1326. extern const CERTRevocationFlags*
  1327. CERT_GetClassicOCSPEnabledSoftFailurePolicy();
  1328. /*
  1329. * Returns a pointer to a static structure.
  1330. */
  1331. extern const CERTRevocationFlags*
  1332. CERT_GetClassicOCSPEnabledHardFailurePolicy();
  1333. /*
  1334. * Returns a pointer to a static structure.
  1335. */
  1336. extern const CERTRevocationFlags*
  1337. CERT_GetClassicOCSPDisabledPolicy();
  1338. /*
  1339. * Verify a Cert with libpkix
  1340. * paramsIn control the verification options. If a value isn't specified
  1341. * in paramsIn, it reverts to the application default.
  1342. * paramsOut specifies the parameters the caller would like to get back.
  1343. * the caller may pass NULL, in which case no parameters are returned.
  1344. */
  1345. extern SECStatus CERT_PKIXVerifyCert(
  1346. CERTCertificate *cert,
  1347. SECCertificateUsage usages,
  1348. CERTValInParam *paramsIn,
  1349. CERTValOutParam *paramsOut,
  1350. void *wincx);
  1351. /*
  1352. * This function changes the application defaults for the Verify function.
  1353. * It should be called once at app initialization time, and only changes
  1354. * if the default configuration changes.
  1355. *
  1356. * This changes the default values for the parameters specified. These
  1357. * defaults can be overridden in CERT_PKIXVerifyCert() by explicitly
  1358. * setting the value in paramsIn.
  1359. */
  1360. extern SECStatus CERT_PKIXSetDefaults(CERTValInParam *paramsIn);
  1361. /* Makes old cert validation APIs(CERT_VerifyCert, CERT_VerifyCertificate)
  1362. * to use libpkix validation engine. The function should be called ones at
  1363. * application initialization time.
  1364. * Function is not thread safe.*/
  1365. SECStatus CERT_SetUsePKIXForValidation(PRBool enable);
  1366. /* The function return PR_TRUE if cert validation should use
  1367. * libpkix cert validation engine. */
  1368. PRBool CERT_GetUsePKIXForValidation();
  1369. SEC_END_PROTOS
  1370. #endif /* _CERT_H_ */