PageRenderTime 161ms CodeModel.GetById 26ms RepoModel.GetById 19ms app.codeStats 1ms

/security/nss/lib/certdb/cert.h

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