PageRenderTime 44ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/gecko_api/include/cmmf.h

http://firefox-mac-pdf.googlecode.com/
C Header | 1122 lines | 143 code | 60 blank | 919 comment | 0 complexity | c0b0155fcdc29bb432e6ae5b73954bcb MD5 | raw file
  1. /* -*- Mode: C; tab-width: 8 -*-*/
  2. /* ***** BEGIN LICENSE BLOCK *****
  3. * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  4. *
  5. * The contents of this file are subject to the Mozilla Public License Version
  6. * 1.1 (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. * http://www.mozilla.org/MPL/
  9. *
  10. * Software distributed under the License is distributed on an "AS IS" basis,
  11. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12. * for the specific language governing rights and limitations under the
  13. * License.
  14. *
  15. * The Original Code is the Netscape security libraries.
  16. *
  17. * The Initial Developer of the Original Code is
  18. * Netscape Communications Corporation.
  19. * Portions created by the Initial Developer are Copyright (C) 1994-2000
  20. * the Initial Developer. All Rights Reserved.
  21. *
  22. * Contributor(s):
  23. *
  24. * Alternatively, the contents of this file may be used under the terms of
  25. * either the GNU General Public License Version 2 or later (the "GPL"), or
  26. * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  27. * in which case the provisions of the GPL or the LGPL are applicable instead
  28. * of those above. If you wish to allow use of your version of this file only
  29. * under the terms of either the GPL or the LGPL, and not to allow others to
  30. * use your version of this file under the terms of the MPL, indicate your
  31. * decision by deleting the provisions above and replace them with the notice
  32. * and other provisions required by the GPL or the LGPL. If you do not delete
  33. * the provisions above, a recipient may use your version of this file under
  34. * the terms of any one of the MPL, the GPL or the LGPL.
  35. *
  36. * ***** END LICENSE BLOCK ***** */
  37. #ifndef _CMMF_H_
  38. #define _CMMF_H_
  39. /*
  40. * These are the functions exported by the security library for
  41. * implementing Certificate Management Message Formats (CMMF).
  42. *
  43. * This API is designed against July 1998 CMMF draft. Please read this
  44. * draft before trying to use this API in an application that use CMMF.
  45. */
  46. #include "seccomon.h"
  47. #include "cmmft.h"
  48. #include "crmf.h"
  49. SEC_BEGIN_PROTOS
  50. /******************* Creation Functions *************************/
  51. /*
  52. * FUNCTION: CMMF_CreateCertRepContent
  53. * INPUTS:
  54. * NONE
  55. * NOTES:
  56. * This function will create an empty CMMFCertRepContent Structure.
  57. * The client of the library must set the CMMFCertResponses.
  58. * Call CMMF_CertRepContentSetCertResponse to accomplish this task.
  59. * If the client of the library also wants to include the chain of
  60. * CA certs required to make the certificates in CMMFCertResponse valid,
  61. * then the user must also set the caPubs field of CMMFCertRepContent.
  62. * Call CMMF_CertRepContentSetCAPubs to accomplish this. After setting
  63. * the desired fields, the user can then call CMMF_EncodeCertRepContent
  64. * to DER-encode the CertRepContent.
  65. * RETURN:
  66. * A pointer to the CMMFCertRepContent. A NULL return value indicates
  67. * an error in allocating memory or failure to initialize the structure.
  68. */
  69. extern CMMFCertRepContent* CMMF_CreateCertRepContent(void);
  70. /*
  71. * FUNCTION: CMMF_CreateCertRepContentFromDER
  72. * INPUTS
  73. * db
  74. * The certificate database where the certificates will be placed.
  75. * The certificates will be placed in the temporary database associated
  76. * with the handle.
  77. * buf
  78. * A buffer to the DER-encoded CMMFCertRepContent
  79. * len
  80. * The length in bytes of the buffer 'buf'
  81. * NOTES:
  82. * This function passes the buffer to the ASN1 decoder and creates a
  83. * CMMFCertRepContent structure. The user must call
  84. * CMMF_DestroyCertRepContent after the return value is no longer needed.
  85. *
  86. * RETURN:
  87. * A pointer to the CMMFCertRepContent structure. A NULL return
  88. * value indicates the library was unable to parse the DER.
  89. */
  90. extern CMMFCertRepContent*
  91. CMMF_CreateCertRepContentFromDER(CERTCertDBHandle *db,
  92. const char *buf,
  93. long len);
  94. /*
  95. * FUNCTION: CMMF_CreateCertResponse
  96. * INPUTS:
  97. * inCertReqId
  98. * The Certificate Request Id this response is for.
  99. * NOTES:
  100. * This creates a CMMFCertResponse. This response should correspond
  101. * to a request that was received via CRMF. From the CRMF message you
  102. * can get the Request Id to pass in as inCertReqId, in essence binding
  103. * a CMRFCertRequest message to the CMMFCertResponse created by this
  104. * function. If no requuest id is associated with the response to create
  105. * then the user should pass in -1 for 'inCertReqId'.
  106. *
  107. * RETURN:
  108. * A pointer to the new CMMFCertResponse corresponding to the request id
  109. * passed in. A NULL return value indicates an error while trying to
  110. * create the CMMFCertResponse.
  111. */
  112. extern CMMFCertResponse* CMMF_CreateCertResponse(long inCertReqId);
  113. /*
  114. * FUNCTION: CMMF_CreateKeyRecRepContent
  115. * INPUTS:
  116. * NONE
  117. * NOTES:
  118. * This function creates a new empty CMMFKeyRecRepContent structure.
  119. * At the very minimum, the user must call
  120. * CMMF_KeyRecRepContentSetPKIStatusInfoStatus field to have an
  121. * encodable structure. Depending on what the response is, the user may
  122. * have to set other fields as well to properly build up the structure so
  123. * that it can be encoded. Refer to the CMMF draft for how to properly
  124. * set up a CMMFKeyRecRepContent. This is the structure that an RA returns
  125. * to an end entity when doing key recovery.
  126. * The user must call CMMF_DestroyKeyRecRepContent when the return value
  127. * is no longer needed.
  128. * RETURN:
  129. * A pointer to the empty CMMFKeyRecRepContent. A return value of NULL
  130. * indicates an error in allocating memory or initializing the structure.
  131. */
  132. extern CMMFKeyRecRepContent *CMMF_CreateKeyRecRepContent(void);
  133. /*
  134. * FUNCTION: CMMF_CreateKeyRecRepContentFromDER
  135. * INPUTS:
  136. * db
  137. * The handle for the certificate database where the decoded
  138. * certificates will be placed. The decoded certificates will
  139. * be placed in the temporary database associated with the
  140. * handle.
  141. * buf
  142. * A buffer contatining the DER-encoded CMMFKeyRecRepContent
  143. * len
  144. * The length in bytes of the buffer 'buf'
  145. * NOTES
  146. * This function passes the buffer to the ASN1 decoder and creates a
  147. * CMMFKeyRecRepContent structure.
  148. *
  149. * RETURN:
  150. * A pointer to the CMMFKeyRecRepContent structure. A NULL return
  151. * value indicates the library was unable to parse the DER.
  152. */
  153. extern CMMFKeyRecRepContent*
  154. CMMF_CreateKeyRecRepContentFromDER(CERTCertDBHandle *db,
  155. const char *buf,
  156. long len);
  157. /*
  158. * FUNCTION: CMMF_CreatePOPODecKeyChallContent
  159. * INPUTS:
  160. * NONE
  161. * NOTES:
  162. * This function creates an empty CMMFPOPODecKeyChallContent. The user
  163. * must add the challenges individually specifying the random number to
  164. * be used and the public key to be used when creating each individual
  165. * challenge. User can accomplish this by calling the function
  166. * CMMF_POPODecKeyChallContentSetNextChallenge.
  167. * RETURN:
  168. * A pointer to a CMMFPOPODecKeyChallContent structure. Ther user can
  169. * then call CMMF_EncodePOPODecKeyChallContent passing in the return
  170. * value from this function after setting all of the challenges. A
  171. * return value of NULL indicates an error while creating the
  172. * CMMFPOPODecKeyChallContent structure.
  173. */
  174. extern CMMFPOPODecKeyChallContent*
  175. CMMF_CreatePOPODecKeyChallContent(void);
  176. /*
  177. * FUNCTION: CMMF_CreatePOPODecKeyChallContentFromDER
  178. * INPUTS
  179. * buf
  180. * A buffer containing the DER-encoded CMMFPOPODecKeyChallContent
  181. * len
  182. * The length in bytes of the buffer 'buf'
  183. * NOTES:
  184. * This function passes the buffer to the ASN1 decoder and creates a
  185. * CMMFPOPODecKeyChallContent structure.
  186. *
  187. * RETURN:
  188. * A pointer to the CMMFPOPODecKeyChallContent structure. A NULL return
  189. * value indicates the library was unable to parse the DER.
  190. */
  191. extern CMMFPOPODecKeyChallContent*
  192. CMMF_CreatePOPODecKeyChallContentFromDER(const char *buf, long len);
  193. /*
  194. * FUNCTION: CMMF_CreatePOPODecKeyRespContentFromDER
  195. * INPUTS:
  196. * buf
  197. * A buffer contatining the DER-encoded CMMFPOPODecKeyRespContent
  198. * len
  199. * The length in bytes of the buffer 'buf'
  200. * NOTES
  201. * This function passes the buffer to the ASN1 decoder and creates a
  202. * CMMFPOPODecKeyRespContent structure.
  203. *
  204. * RETURN:
  205. * A pointer to the CMMFPOPODecKeyRespContent structure. A NULL return
  206. * value indicates the library was unable to parse the DER.
  207. */
  208. extern CMMFPOPODecKeyRespContent*
  209. CMMF_CreatePOPODecKeyRespContentFromDER(const char *buf, long len);
  210. /************************** Set Functions *************************/
  211. /*
  212. * FUNCTION: CMMF_CertRepContentSetCertResponses
  213. * INPUTS:
  214. * inCertRepContent
  215. * The CMMFCertRepContent to operate on.
  216. * inCertResponses
  217. * An array of pointers to CMMFCertResponse structures to
  218. * add to the CMMFCertRepContent structure.
  219. * inNumResponses
  220. * The length of the array 'inCertResponses'
  221. * NOTES:
  222. * This function will add the CMMFCertResponse structure to the
  223. * CMMFCertRepContent passed in. The CMMFCertResponse field of
  224. * CMMFCertRepContent is required, so the client must call this function
  225. * before calling CMMF_EncodeCertRepContent. If the user calls
  226. * CMMF_EncodeCertRepContent before calling this function,
  227. * CMMF_EncodeCertRepContent will fail.
  228. *
  229. * RETURN:
  230. * SECSuccess if adding the CMMFCertResponses to the CMMFCertRepContent
  231. * structure was successful. Any other return value indicates an error
  232. * while trying to add the CMMFCertResponses.
  233. */
  234. extern SECStatus
  235. CMMF_CertRepContentSetCertResponses(CMMFCertRepContent *inCertRepContent,
  236. CMMFCertResponse **inCertResponses,
  237. int inNumResponses);
  238. /*
  239. * FUNCTION: CMMF_CertRepContentSetCAPubs
  240. * INPUTS:
  241. * inCertRepContent
  242. * The CMMFCertRepContent to operate on.
  243. * inCAPubs
  244. * The certificate list which makes up the chain of CA certificates
  245. * required to make the issued cert valid.
  246. * NOTES:
  247. * This function will set the the certificates in the CA chain as part
  248. * of the CMMFCertRepContent. This field is an optional member of the
  249. * CMMFCertRepContent structure, so the client is not required to call
  250. * this function before calling CMMF_EncodeCertRepContent.
  251. *
  252. * RETURN:
  253. * SECSuccess if adding the 'inCAPubs' to the CERTRepContent was successful.
  254. * Any other return value indicates an error while adding 'inCAPubs' to the
  255. * CMMFCertRepContent structure.
  256. *
  257. */
  258. extern SECStatus
  259. CMMF_CertRepContentSetCAPubs (CMMFCertRepContent *inCertRepContent,
  260. CERTCertList *inCAPubs);
  261. /*
  262. * FUNCTION: CMMF_CertResponseSetPKIStatusInfoStatus
  263. * INPUTS:
  264. * inCertResp
  265. * The CMMFCertResponse to operate on.
  266. * inPKIStatus
  267. * The value to set for the PKIStatusInfo.status field.
  268. * NOTES:
  269. * This function will set the CertResponse.status.status field of
  270. * the CMMFCertResponse structure. (View the definition of CertResponse
  271. * in the CMMF draft to see exactly which value this talks about.) This
  272. * field is a required member of the structure, so the user must call this
  273. * function in order to have a CMMFCertResponse that can be encoded.
  274. *
  275. * RETURN:
  276. * SECSuccess if setting the field with the passed in value was successful.
  277. * Any other return value indicates an error while trying to set the field.
  278. */
  279. extern SECStatus
  280. CMMF_CertResponseSetPKIStatusInfoStatus (CMMFCertResponse *inCertResp,
  281. CMMFPKIStatus inPKIStatus);
  282. /*
  283. * FUNCTION: CMMF_CertResponseSetCertificate
  284. * INPUTS:
  285. * inCertResp
  286. * The CMMFCertResponse to operate on.
  287. * inCertificate
  288. * The certificate to add to the
  289. * CertResponse.CertifiedKeyPair.certOrEncCert.certificate field.
  290. * NOTES:
  291. * This function will take the certificate and make it a member of the
  292. * CMMFCertResponse. The certificate should be the actual certificate
  293. * being issued via the response.
  294. *
  295. * RETURN:
  296. * SECSuccess if adding the certificate to the response was successful.
  297. * Any other return value indicates an error in adding the certificate to
  298. * the CertResponse.
  299. */
  300. extern SECStatus
  301. CMMF_CertResponseSetCertificate (CMMFCertResponse *inCertResp,
  302. CERTCertificate *inCertificate);
  303. /*
  304. * FUNCTION: CMMF_KeyRecRepContentSetPKIStatusInfoStatus
  305. * INPUTS:
  306. * inKeyRecRep
  307. * The CMMFKeyRecRepContent to operate on.
  308. * inPKIStatus
  309. * The value to set the PKIStatusInfo.status field to.
  310. * NOTES:
  311. * This function sets the only required field for the KeyRecRepContent.
  312. * In most cases, the user will set this field and other fields of the
  313. * structure to properly create the CMMFKeyRecRepContent structure.
  314. * Refer to the CMMF draft to see which fields need to be set in order
  315. * to create the desired CMMFKeyRecRepContent.
  316. *
  317. * RETURN:
  318. * SECSuccess if setting the PKIStatusInfo.status field was successful.
  319. * Any other return value indicates an error in setting the field.
  320. */
  321. extern SECStatus
  322. CMMF_KeyRecRepContentSetPKIStatusInfoStatus(CMMFKeyRecRepContent *inKeyRecRep,
  323. CMMFPKIStatus inPKIStatus);
  324. /*
  325. * FUNCTION: CMMF_KeyRecRepContentSetNewSignCert
  326. * INPUTS:
  327. * inKeyRecRep
  328. * The CMMFKeyRecRepContent to operate on.
  329. * inNewSignCert
  330. * The new signing cert to add to the CMMFKeyRecRepContent structure.
  331. * NOTES:
  332. * This function sets the new signeing cert in the CMMFKeyRecRepContent
  333. * structure.
  334. *
  335. * RETURN:
  336. * SECSuccess if setting the new signing cert was successful. Any other
  337. * return value indicates an error occurred while trying to add the
  338. * new signing certificate.
  339. */
  340. extern SECStatus
  341. CMMF_KeyRecRepContentSetNewSignCert(CMMFKeyRecRepContent *inKeyRecRep,
  342. CERTCertificate *inNewSignCert);
  343. /*
  344. * FUNCTION: CMMF_KeyRecRepContentSetCACerts
  345. * INPUTS:
  346. * inKeyRecRep
  347. * The CMMFKeyRecRepContent to operate on.
  348. * inCACerts
  349. * The list of CA certificates required to construct a valid
  350. * certificate chain with the certificates that will be returned
  351. * to the end user via this KeyRecRepContent.
  352. * NOTES:
  353. * This function sets the caCerts that are required to form a chain with the
  354. * end entity certificates that are being re-issued in this
  355. * CMMFKeyRecRepContent structure.
  356. *
  357. * RETURN:
  358. * SECSuccess if adding the caCerts was successful. Any other return value
  359. * indicates an error while tring to add the caCerts.
  360. */
  361. extern SECStatus
  362. CMMF_KeyRecRepContentSetCACerts(CMMFKeyRecRepContent *inKeyRecRep,
  363. CERTCertList *inCACerts);
  364. /*
  365. * FUNCTION: CMMF_KeyRecRepContentSetCertifiedKeyPair
  366. * INPUTS:
  367. * inKeyRecRep
  368. * The CMMFKeyRecRepContent to operate on.
  369. * inCert
  370. * The certificate to add to the CMMFKeyRecRepContent structure.
  371. * inPrivKey
  372. * The private key associated with the certificate above passed in.
  373. * inPubKey
  374. * The public key to use for wrapping the private key.
  375. * NOTES:
  376. * This function adds another certificate-key pair to the
  377. * CMMFKeyRecRepcontent structure. There may be more than one
  378. * certificate-key pair in the structure, so the user must call this
  379. * function multiple times to add more than one cert-key pair.
  380. *
  381. * RETURN:
  382. * SECSuccess if adding the certified key pair was successful. Any other
  383. * return value indicates an error in adding certified key pair to
  384. * CMMFKeyRecRepContent structure.
  385. */
  386. extern SECStatus
  387. CMMF_KeyRecRepContentSetCertifiedKeyPair(CMMFKeyRecRepContent *inKeyRecRep,
  388. CERTCertificate *inCert,
  389. SECKEYPrivateKey *inPrivKey,
  390. SECKEYPublicKey *inPubKey);
  391. /*
  392. * FUNCTION: CMMF_POPODecKeyChallContentSetNextChallenge
  393. * INPUTS:
  394. * inDecKeyChall
  395. * The CMMFPOPODecKeyChallContent to operate on.
  396. * inRandom
  397. * The random number to use when generating the challenge,
  398. * inSender
  399. * The GeneralName representation of the sender of the challenge.
  400. * inPubKey
  401. * The public key to use when encrypting the challenge.
  402. * passwdArg
  403. * This value will be passed to the function used for getting a
  404. * password. The password for getting a password should be registered
  405. * by calling PK11_SetPasswordFunc before this function is called.
  406. * If no password callback is registered and the library needs to
  407. * authenticate to the slot for any reason, this function will fail.
  408. * NOTES:
  409. * This function adds a challenge to the end of the list of challenges
  410. * contained by 'inDecKeyChall'. Refer to the CMMF draft on how the
  411. * the random number passed in and the sender's GeneralName are used
  412. * to generate the challenge and witness fields of the challenge. This
  413. * library will use SHA1 as the one-way function for generating the
  414. * witess field of the challenge.
  415. *
  416. * RETURN:
  417. * SECSuccess if generating the challenge and adding to the end of list
  418. * of challenges was successful. Any other return value indicates an error
  419. * while trying to generate the challenge.
  420. */
  421. extern SECStatus
  422. CMMF_POPODecKeyChallContentSetNextChallenge
  423. (CMMFPOPODecKeyChallContent *inDecKeyChall,
  424. long inRandom,
  425. CERTGeneralName *inSender,
  426. SECKEYPublicKey *inPubKey,
  427. void *passwdArg);
  428. /************************** Encoding Functions *************************/
  429. /*
  430. * FUNCTION: CMMF_EncodeCertRepContent
  431. * INPUTS:
  432. * inCertRepContent
  433. * The CMMFCertRepContent to DER-encode.
  434. * inCallback
  435. * A callback function that the ASN1 encoder will call whenever it
  436. * wants to write out DER-encoded bytes. Look at the defintion of
  437. * CRMFEncoderOutputCallback in crmft.h for a description of the
  438. * parameters to the function.
  439. * inArg
  440. * An opaque pointer to a user-supplied argument that will be passed
  441. * to the callback funtion whenever the function is called.
  442. * NOTES:
  443. * The CMMF library will use the same DER-encoding scheme as the CRMF
  444. * library. In other words, when reading CRMF comments that pertain to
  445. * encoding, those comments apply to the CMMF libray as well.
  446. * The callback function will be called multiple times, each time supplying
  447. * the next chunk of DER-encoded bytes. The user must concatenate the
  448. * output of each successive call to the callback in order to get the
  449. * entire DER-encoded CMMFCertRepContent structure.
  450. *
  451. * RETURN:
  452. * SECSuccess if encoding the CMMFCertRepContent was successful. Any
  453. * other return value indicates an error while decoding the structure.
  454. */
  455. extern SECStatus
  456. CMMF_EncodeCertRepContent (CMMFCertRepContent *inCertRepContent,
  457. CRMFEncoderOutputCallback inCallback,
  458. void *inArg);
  459. /*
  460. * FUNCTION: CMMF_EncodeKeyRecRepContent
  461. * INPUTS:
  462. * inKeyRecRep
  463. * The CMMFKeyRepContent to DER-encode.
  464. * inCallback
  465. * A callback function that the ASN1 encoder will call whenever it
  466. * wants to write out DER-encoded bytes. Look at the defintion of
  467. * CRMFEncoderOutputCallback in crmft.h for a description of the
  468. * parameters to the function.
  469. * inArg
  470. * An opaque pointer to a user-supplied argument that will be passed
  471. * to the callback funtion whenever the function is called.
  472. * NOTES:
  473. * The CMMF library will use the same DER-encoding scheme as the CRMF
  474. * library. In other words, when reading CRMF comments that pertain to
  475. * encoding, those comments apply to the CMMF libray as well.
  476. * The callback function will be called multiple times, each time supplying
  477. * the next chunk of DER-encoded bytes. The user must concatenate the
  478. * output of each successive call to the callback in order to get the
  479. * entire DER-encoded CMMFCertRepContent structure.
  480. *
  481. * RETURN:
  482. * SECSuccess if encoding the CMMFKeyRecRepContent was successful. Any
  483. * other return value indicates an error while decoding the structure.
  484. */
  485. extern SECStatus
  486. CMMF_EncodeKeyRecRepContent(CMMFKeyRecRepContent *inKeyRecRep,
  487. CRMFEncoderOutputCallback inCallback,
  488. void *inArg);
  489. /*
  490. * FUNCTION: CMMF_EncodePOPODecKeyChallContent
  491. * INPUTS:
  492. * inDecKeyChall
  493. * The CMMFDecKeyChallContent to operate on.
  494. * inCallback
  495. * A callback function that the ASN1 encoder will call whenever it
  496. * wants to write out DER-encoded bytes. Look at the defintion of
  497. * CRMFEncoderOutputCallback in crmft.h for a description of the
  498. * parameters to the function.
  499. * inArg
  500. * An opaque pointer to a user-supplied argument that will be passed
  501. * to the callback function whenever the function is called.
  502. * NOTES:
  503. * The CMMF library will use the same DER-encoding scheme as the CRMF
  504. * library. In other words, when reading CRMF comments that pertain to
  505. * encoding, those comments apply to the CMMF libray as well.
  506. * The callback function will be called multiple times, each time supplying
  507. * the next chunk of DER-encoded bytes. The user must concatenate the
  508. * output of each successive call to the callback in order to get the
  509. * entire DER-encoded CMMFCertRepContent structure.
  510. * The DER will be an encoding of the type POPODecKeyChallContents, which
  511. * is just a sequence of challenges.
  512. *
  513. * RETURN:
  514. * SECSuccess if encoding was successful. Any other return value indicates
  515. * an error in trying to encode the Challenges.
  516. */
  517. extern SECStatus
  518. CMMF_EncodePOPODecKeyChallContent(CMMFPOPODecKeyChallContent *inDecKeyChall,
  519. CRMFEncoderOutputCallback inCallback,
  520. void *inArg);
  521. /*
  522. * FUNCTION: CMMF_EncodePOPODecKeyRespContent
  523. * INPUTS:
  524. * inDecodedRand
  525. * An array of integers to encode as the responses to
  526. * CMMFPOPODecKeyChallContent. The integers must be in the same order
  527. * as the challenges extracted from CMMFPOPODecKeyChallContent.
  528. * inNumRand
  529. * The number of random integers contained in the array 'inDecodedRand'
  530. * inCallback
  531. * A callback function that the ASN1 encoder will call whenever it
  532. * wants to write out DER-encoded bytes. Look at the defintion of
  533. * CRMFEncoderOutputCallback in crmft.h for a description of the
  534. * parameters to the function.
  535. * inArg
  536. * An opaque pointer to a user-supplied argument that will be passed
  537. * to the callback funtion whenever the function is called.
  538. * NOTES:
  539. * The CMMF library will use the same DER-encoding scheme as the CRMF
  540. * library. In other words, when reading CRMF comments that pertain to
  541. * encoding, those comments apply to the CMMF libray as well.
  542. * The callback function will be called multiple times, each time supplying
  543. * the next chunk of DER-encoded bytes. The user must concatenate the
  544. * output of each successive call to the callback in order to get the
  545. * entire DER-encoded POPODecKeyRespContent.
  546. *
  547. * RETURN:
  548. * SECSuccess if encoding was successful. Any other return value indicates
  549. * an error in trying to encode the Challenges.
  550. */
  551. extern SECStatus
  552. CMMF_EncodePOPODecKeyRespContent(long *inDecodedRand,
  553. int inNumRand,
  554. CRMFEncoderOutputCallback inCallback,
  555. void *inArg);
  556. /*************** Accessor function ***********************************/
  557. /*
  558. * FUNCTION: CMMF_CertRepContentGetCAPubs
  559. * INPUTS:
  560. * inCertRepContent
  561. * The CMMFCertRepContent to extract the caPubs from.
  562. * NOTES:
  563. * This function will return a copy of the list of certificates that
  564. * make up the chain of CA's required to make the cert issued valid.
  565. * The user must call CERT_DestroyCertList on the return value when
  566. * done using the return value.
  567. *
  568. * Only call this function on a CertRepContent that has been decoded.
  569. * The client must call CERT_DestroyCertList when the certificate list
  570. * is no longer needed.
  571. *
  572. * The certs in the list will not be in the temporary database. In order
  573. * to make these certificates a part of the permanent CA internal database,
  574. * the user must collect the der for all of these certs and call
  575. * CERT_ImportCAChain. Afterwards the certs will be part of the permanent
  576. * database.
  577. *
  578. * RETURN:
  579. * A pointer to the CERTCertList representing the CA chain associated
  580. * with the issued cert. A NULL return value indicates that no CA Pubs
  581. * were available in the CMMFCertRepContent structure.
  582. */
  583. extern CERTCertList*
  584. CMMF_CertRepContentGetCAPubs (CMMFCertRepContent *inCertRepContent);
  585. /*
  586. * FUNCTION: CMMF_CertRepContentGetNumResponses
  587. * INPUTS:
  588. * inCertRepContent
  589. * The CMMFCertRepContent to operate on.
  590. * NOTES:
  591. * This function will return the number of CertResponses that are contained
  592. * by the CMMFCertRepContent passed in.
  593. *
  594. * RETURN:
  595. * The number of CMMFCertResponses contained in the structure passed in.
  596. */
  597. extern int
  598. CMMF_CertRepContentGetNumResponses (CMMFCertRepContent *inCertRepContent);
  599. /*
  600. * FUNCTION: CMMF_CertRepContentGetResponseAtIndex
  601. * INPUTS:
  602. * inCertRepContent
  603. * The CMMFCertRepContent to operate on.
  604. * inIndex
  605. * The index of the CMMFCertResponse the user wants a copy of.
  606. * NOTES:
  607. * This funciton creates a copy of the CMMFCertResponse at the index
  608. * corresponding to the parameter 'inIndex'. Indexing is done like a
  609. * traditional C array, ie the valid indexes are (0...numResponses-1).
  610. * The user must call CMMF_DestroyCertResponse after the return value is
  611. * no longer needed.
  612. *
  613. * RETURN:
  614. * A pointer to the CMMFCertResponse at the index corresponding to
  615. * 'inIndex'. A return value of NULL indicates an error in copying
  616. * the CMMFCertResponse.
  617. */
  618. extern CMMFCertResponse*
  619. CMMF_CertRepContentGetResponseAtIndex (CMMFCertRepContent *inCertRepContent,
  620. int inIndex);
  621. /*
  622. * FUNCTION: CMMF_CertResponseGetCertReqId
  623. * INPUTS:
  624. * inCertResp
  625. * The CMMFCertResponse to operate on.
  626. * NOTES:
  627. * This function returns the CertResponse.certReqId from the
  628. * CMMFCertResponse structure passed in. If the return value is -1, that
  629. * means there is no associated certificate request with the CertResponse.
  630. * RETURN:
  631. * A long representing the id of the certificate request this
  632. * CMMFCertResponse corresponds to. A return value of -1 indicates an
  633. * error in extracting the value of the integer.
  634. */
  635. extern long CMMF_CertResponseGetCertReqId(CMMFCertResponse *inCertResp);
  636. /*
  637. * FUNCTION: CMMF_CertResponseGetPKIStatusInfoStatus
  638. * INPUTS:
  639. * inCertResp
  640. * The CMMFCertResponse to operate on.
  641. * NOTES:
  642. * This function returns the CertResponse.status.status field of the
  643. * CMMFCertResponse structure.
  644. *
  645. * RETURN:
  646. * The enumerated value corresponding to the PKIStatus defined in the CMMF
  647. * draft. See the CMMF draft for the definition of PKIStatus. See crmft.h
  648. * for the definition of CMMFPKIStatus.
  649. */
  650. extern CMMFPKIStatus
  651. CMMF_CertResponseGetPKIStatusInfoStatus(CMMFCertResponse *inCertResp);
  652. /*
  653. * FUNCTION: CMMF_CertResponseGetCertificate
  654. * INPUTS:
  655. * inCertResp
  656. * The Certificate Response to operate on.
  657. * inCertdb
  658. * This is the certificate database where the function will place the
  659. * newly issued certificate.
  660. * NOTES:
  661. * This function retrieves the CertResponse.certifiedKeyPair.certificate
  662. * from the CMMFCertResponse. The user will get a copy of that certificate
  663. * so the user must call CERT_DestroyCertificate when the return value is
  664. * no longer needed. The certificate returned will be in the temporary
  665. * certificate database.
  666. *
  667. * RETURN:
  668. * A pointer to a copy of the certificate contained within the
  669. * CMMFCertResponse. A return value of NULL indicates an error while trying
  670. * to make a copy of the certificate.
  671. */
  672. extern CERTCertificate*
  673. CMMF_CertResponseGetCertificate(CMMFCertResponse *inCertResp,
  674. CERTCertDBHandle *inCertdb);
  675. /*
  676. * FUNCTION: CMMF_KeyRecRepContentGetPKIStatusInfoStatus
  677. * INPUTS:
  678. * inKeyRecRep
  679. * The CMMFKeyRecRepContent structure to operate on.
  680. * NOTES:
  681. * This function retrieves the KeyRecRepContent.status.status field of
  682. * the CMMFKeyRecRepContent structure.
  683. * RETURN:
  684. * The CMMFPKIStatus corresponding to the value held in the
  685. * CMMFKeyRecRepContent structure.
  686. */
  687. extern CMMFPKIStatus
  688. CMMF_KeyRecRepContentGetPKIStatusInfoStatus(CMMFKeyRecRepContent *inKeyRecRep);
  689. /*
  690. * FUNCTION: CMMF_KeyRecRepContentGetNewSignCert
  691. * INPUTS:
  692. * inKeyRecRep
  693. * The CMMFKeyRecRepContent to operate on.
  694. * NOTES:
  695. * This function retrieves the KeyRecRepContent.newSignCert field of the
  696. * CMMFKeyRecRepContent structure. The user must call
  697. * CERT_DestroyCertificate when the return value is no longer needed. The
  698. * returned certificate will be in the temporary database. The user
  699. * must then place the certificate permanently in whatever token the
  700. * user determines is the proper destination. A return value of NULL
  701. * indicates the newSigCert field was not present.
  702. */
  703. extern CERTCertificate*
  704. CMMF_KeyRecRepContentGetNewSignCert(CMMFKeyRecRepContent *inKeyRecRep);
  705. /*
  706. * FUNCTION: CMMF_KeyRecRepContentGetCACerts
  707. * INPUTS:
  708. * inKeyRecRep
  709. * The CMMFKeyRecRepContent to operate on.
  710. * NOTES:
  711. * This function returns a CERTCertList which contains all of the
  712. * certficates that are in the sequence KeyRecRepContent.caCerts
  713. * User must call CERT_DestroyCertList when the return value is no longer
  714. * needed. All of these certificates will be placed in the tempoaray
  715. * database.
  716. *
  717. * RETURN:
  718. * A pointer to the list of caCerts contained in the CMMFKeyRecRepContent
  719. * structure. A return value of NULL indicates the library was not able to
  720. * make a copy of the certifcates. This may be because there are no caCerts
  721. * included in the CMMFKeyRecRepContent strucure or an internal error. Call
  722. * CMMF_KeyRecRepContentHasCACerts to find out if there are any caCerts
  723. * included in 'inKeyRecRep'.
  724. */
  725. extern CERTCertList*
  726. CMMF_KeyRecRepContentGetCACerts(CMMFKeyRecRepContent *inKeyRecRep);
  727. /*
  728. * FUNCTION: CMMF_KeyRecRepContentGetNumKeyPairs
  729. * INPUTS:
  730. * inKeyRecRep
  731. * The CMMFKeyRecRepContent to operate on.
  732. * RETURN:
  733. * This function returns the number of CMMFCertifiedKeyPair structures that
  734. * that are stored in the KeyRecRepContent structure.
  735. */
  736. extern int
  737. CMMF_KeyRecRepContentGetNumKeyPairs(CMMFKeyRecRepContent *inKeyRecRep);
  738. /*
  739. * FUNCTION: CMMF_KeyRecRepContentGetCertKeyAtIndex
  740. * INPUTS:
  741. * inKeyRecRepContent
  742. * The CMMFKeyRecRepContent to operate on.
  743. * inIndex
  744. * The index of the desired CMMFCertifiedKeyPair
  745. * NOTES:
  746. * This function retrieves the CMMFCertifiedKeyPair structure at the index
  747. * 'inIndex'. Valid indexes are 0...(numKeyPairs-1) The user must call
  748. * CMMF_DestroyCertifiedKeyPair when the return value is no longer needed.
  749. *
  750. * RETURN:
  751. * A pointer to the Certified Key Pair at the desired index. A return value
  752. * of NULL indicates an error in extracting the Certified Key Pair at the
  753. * desired index.
  754. */
  755. extern CMMFCertifiedKeyPair*
  756. CMMF_KeyRecRepContentGetCertKeyAtIndex(CMMFKeyRecRepContent *inKeyRecRep,
  757. int inIndex);
  758. /*
  759. * FUNCTION: CMMF_CertifiedKeyPairGetCertificate
  760. * INPUTS:
  761. * inCertKeyPair
  762. * The CMMFCertifiedKeyPair to operate on.
  763. * inCertdb
  764. * The database handle for the database you want this certificate
  765. * to wind up in.
  766. * NOTES:
  767. * This function retrieves the certificate at
  768. * CertifiedKeyPair.certOrEncCert.certificate
  769. * The user must call CERT_DestroyCertificate when the return value is no
  770. * longer needed. The user must import this certificate as a token object
  771. * onto PKCS#11 slot in order to make it a permanent object. The returned
  772. * certificate will be in the temporary database.
  773. *
  774. * RETURN:
  775. * A pointer to the certificate contained within the certified key pair.
  776. * A return value of NULL indicates an error in creating the copy of the
  777. * certificate.
  778. */
  779. extern CERTCertificate*
  780. CMMF_CertifiedKeyPairGetCertificate(CMMFCertifiedKeyPair *inCertKeyPair,
  781. CERTCertDBHandle *inCertdb);
  782. /*
  783. * FUNCTION: CMMF_POPODecKeyChallContentGetNumChallenges
  784. * INPUTS:
  785. * inKeyChallCont
  786. * The CMMFPOPODecKeyChallContent to operate on.
  787. * RETURN:
  788. * This function returns the number of CMMFChallenges are contained in
  789. * the CMMFPOPODecKeyChallContent structure.
  790. */
  791. extern int CMMF_POPODecKeyChallContentGetNumChallenges
  792. (CMMFPOPODecKeyChallContent *inKeyChallCont);
  793. /*
  794. * FUNCTION: CMMF_POPODecKeyChallContentGetPublicValue
  795. * ---------------------------------------------------
  796. * INPUTS:
  797. * inKeyChallCont
  798. * The CMMFPOPODecKeyChallContent to operate on.
  799. * inIndex
  800. * The index of the Challenge within inKeyChallCont to operate on.
  801. * Indexes start from 0, ie the Nth Challenge corresponds to index
  802. * N-1.
  803. * NOTES:
  804. * This function retrieves the public value stored away in the Challenge at
  805. * index inIndex of inKeyChallCont.
  806. * RETURN:
  807. * A pointer to a SECItem containing the public value. User must call
  808. * SECITEM_FreeItem on the return value when the value is no longer necessary.
  809. * A return value of NULL indicates an error while retrieving the public value.
  810. */
  811. extern SECItem* CMMF_POPODecKeyChallContentGetPublicValue
  812. (CMMFPOPODecKeyChallContent *inKeyChallCont,
  813. int inIndex);
  814. /*
  815. * FUNCTION: CMMF_POPODecKeyChallContentGetRandomNumber
  816. * INPUTS:
  817. * inChallContent
  818. * The CMMFPOPODecKeyChallContent to operate on.
  819. * inIndex
  820. * The index of the challenge to look at. Valid indexes are 0 through
  821. * (CMMF_POPODecKeyChallContentGetNumChallenges(inChallContent) - 1).
  822. * inDest
  823. * A pointer to a user supplied buffer where the library
  824. * can place a copy of the random integer contatained in the
  825. * challenge.
  826. * NOTES:
  827. * This function returns the value held in the decrypted Rand structure
  828. * corresponding to the random integer. The user must call
  829. * CMMF_POPODecKeyChallContentDecryptChallenge before calling this function. Call
  830. * CMMF_ChallengeIsDecrypted to find out if the challenge has been
  831. * decrypted.
  832. *
  833. * RETURN:
  834. * SECSuccess indicates the witness field has been previously decrypted
  835. * and the value for the random integer was successfully placed at *inDest.
  836. * Any other return value indicates an error and that the value at *inDest
  837. * is not a valid value.
  838. */
  839. extern SECStatus CMMF_POPODecKeyChallContentGetRandomNumber
  840. (CMMFPOPODecKeyChallContent *inKeyChallCont,
  841. int inIndex,
  842. long *inDest);
  843. /*
  844. * FUNCTION: CMMF_POPODecKeyRespContentGetNumResponses
  845. * INPUTS:
  846. * inRespCont
  847. * The POPODecKeyRespContent to operate on.
  848. * RETURN:
  849. * This function returns the number of responses contained in inRespContent.
  850. */
  851. extern int
  852. CMMF_POPODecKeyRespContentGetNumResponses(CMMFPOPODecKeyRespContent *inRespCont);
  853. /*
  854. * FUNCTION: CMMF_POPODecKeyRespContentGetResponse
  855. * INPUTS:
  856. * inRespCont
  857. * The POPODecKeyRespContent to operate on.
  858. * inIndex
  859. * The index of the response to retrieve.
  860. * The Nth response is at index N-1, ie the 1st response is at index 0,
  861. * the 2nd response is at index 1, and so on.
  862. * inDest
  863. * A pointer to a pre-allocated buffer where the library can put the
  864. * value of the response located at inIndex.
  865. * NOTES:
  866. * The function returns the response contained at index inIndex.
  867. * CMMFPOPODecKeyRespContent is a structure that the server will generally
  868. * get in response to a CMMFPOPODecKeyChallContent. The server will expect
  869. * to see the responses in the same order as it constructed them in
  870. * the CMMFPOPODecKeyChallContent structure.
  871. * RETURN:
  872. * SECSuccess if getting the response at the desired index was successful. Any
  873. * other return value indicates an errror.
  874. */
  875. extern SECStatus
  876. CMMF_POPODecKeyRespContentGetResponse (CMMFPOPODecKeyRespContent *inRespCont,
  877. int inIndex,
  878. long *inDest);
  879. /************************* Destructor Functions ******************************/
  880. /*
  881. * FUNCTION: CMMF_DestroyCertResponse
  882. * INPUTS:
  883. * inCertResp
  884. * The CMMFCertResponse to destroy.
  885. * NOTES:
  886. * This function frees all the memory associated with the CMMFCertResponse
  887. * passed in.
  888. * RETURN:
  889. * SECSuccess if freeing the memory was successful. Any other return value
  890. * indicates an error while freeing the memory.
  891. */
  892. extern SECStatus CMMF_DestroyCertResponse(CMMFCertResponse *inCertResp);
  893. /*
  894. * FUNCTION: CMMF_DestroyCertRepContent
  895. * INPUTS:
  896. * inCertRepContent
  897. * The CMMFCertRepContent to destroy
  898. * NOTES:
  899. * This function frees the memory associated with the CMMFCertRepContent
  900. * passed in.
  901. * RETURN:
  902. * SECSuccess if freeing all the memory associated with the
  903. * CMMFCertRepContent passed in is successful. Any other return value
  904. * indicates an error while freeing the memory.
  905. */
  906. extern SECStatus
  907. CMMF_DestroyCertRepContent (CMMFCertRepContent *inCertRepContent);
  908. /*
  909. * FUNCTION: CMMF_DestroyKeyRecRepContent
  910. * INPUTS:
  911. * inKeyRecRep
  912. * The CMMFKeyRecRepContent to destroy.
  913. * NOTES:
  914. * This function destroys all the memory associated with the
  915. * CMMFKeyRecRepContent passed in.
  916. *
  917. * RETURN:
  918. * SECSuccess if freeing all the memory is successful. Any other return
  919. * value indicates an error in freeing the memory.
  920. */
  921. extern SECStatus
  922. CMMF_DestroyKeyRecRepContent(CMMFKeyRecRepContent *inKeyRecRep);
  923. /*
  924. * FUNCTION: CMMF_DestroyCertifiedKeyPair
  925. * INPUTS:
  926. * inCertKeyPair
  927. * The CMMFCertifiedKeyPair to operate on.
  928. * NOTES:
  929. * This function frees up all the memory associated with 'inCertKeyPair'
  930. *
  931. * RETURN:
  932. * SECSuccess if freeing all the memory associated with 'inCertKeyPair'
  933. * is successful. Any other return value indicates an error while trying
  934. * to free the memory.
  935. */
  936. extern SECStatus
  937. CMMF_DestroyCertifiedKeyPair(CMMFCertifiedKeyPair *inCertKeyPair);
  938. /*
  939. * FUNCTION: CMMF_DestroyPOPODecKeyRespContent
  940. * INPUTS:
  941. * inDecKeyResp
  942. * The CMMFPOPODecKeyRespContent structure to free.
  943. * NOTES:
  944. * This function frees up all the memory associate with the
  945. * CMMFPOPODecKeyRespContent.
  946. *
  947. * RETURN:
  948. * SECSuccess if freeing up all the memory associated with the
  949. * CMMFPOPODecKeyRespContent structure is successful. Any other
  950. * return value indicates an error while freeing the memory.
  951. */
  952. extern SECStatus
  953. CMMF_DestroyPOPODecKeyRespContent(CMMFPOPODecKeyRespContent *inDecKeyResp);
  954. /************************** Miscellaneous Functions *************************/
  955. /*
  956. * FUNCTION: CMMF_CertifiedKeyPairUnwrapPrivKey
  957. * INPUTS:
  958. * inCertKeyPair
  959. * The CMMFCertifiedKeyPair to operate on.
  960. * inPrivKey
  961. * The private key to use to un-wrap the private key
  962. * inNickName
  963. * This is the nickname that will be associated with the private key
  964. * to be unwrapped.
  965. * inSlot
  966. * The PKCS11 slot where the unwrapped private key should end up.
  967. * inCertdb
  968. * The Certificate database with which the new key will be associated.
  969. * destPrivKey
  970. * A pointer to memory where the library can place a pointer to the
  971. * private key after importing the key onto the specified slot.
  972. * wincx
  973. * An opaque pointer that the library will use in a callback function
  974. * to get the password if necessary.
  975. *
  976. * NOTES:
  977. * This function uses the private key passed in to unwrap the private key
  978. * contained within the CMMFCertifiedKeyPair structure. After this
  979. * function successfully returns, the private key has been unwrapped and
  980. * placed in the specified slot.
  981. *
  982. * RETURN:
  983. * SECSuccess if unwrapping the private key was successful. Any other
  984. * return value indicates an error while trying to un-wrap the private key.
  985. */
  986. extern SECStatus
  987. CMMF_CertifiedKeyPairUnwrapPrivKey(CMMFCertifiedKeyPair *inKeyPair,
  988. SECKEYPrivateKey *inPrivKey,
  989. SECItem *inNickName,
  990. PK11SlotInfo *inSlot,
  991. CERTCertDBHandle *inCertdb,
  992. SECKEYPrivateKey **destPrivKey,
  993. void *wincx);
  994. /*
  995. * FUNCTION: CMMF_KeyRecRepContentHasCACerts
  996. * INPUTS:
  997. * inKeyRecRecp
  998. * The CMMFKeyRecRepContent to operate on.
  999. * RETURN:
  1000. * This function returns PR_TRUE if there are one or more certificates in
  1001. * the sequence KeyRecRepContent.caCerts within the CMMFKeyRecRepContent
  1002. * structure. The function will return PR_FALSE if there are 0 certificate
  1003. * in the above mentioned sequence.
  1004. */
  1005. extern PRBool
  1006. CMMF_KeyRecRepContentHasCACerts(CMMFKeyRecRepContent *inKeyRecRep);
  1007. /*
  1008. * FUNCTION: CMMF_POPODecKeyChallContDecryptChallenge
  1009. * INPUTS:
  1010. * inChalCont
  1011. * The CMMFPOPODecKeyChallContent to operate on.
  1012. * inIndex
  1013. * The index of the Challenge to operate on. The 1st Challenge is
  1014. * at index 0, the second at index 1 and so forth.
  1015. * inPrivKey
  1016. * The private key to use to decrypt the witness field.
  1017. * NOTES:
  1018. * This function uses the private key to decrypt the challenge field
  1019. * contained in the appropriate challenge. Make sure the private key matches
  1020. * the public key that was used to encrypt the witness. Use
  1021. * CMMF_POPODecKeyChallContentGetPublicValue to get the public value of
  1022. * the key used to encrypt the witness and then use that to determine the
  1023. * appropriate private key. This can be done by calling PK11_MakeIDFromPubKey
  1024. * and then passing that return value to PK11_FindKeyByKeyID. The creator of
  1025. * the challenge will most likely be an RA that has the public key
  1026. * from a Cert request. So the private key should be the private key
  1027. * associated with public key in that request. This function will also
  1028. * verify the witness field of the challenge. This function also verifies
  1029. * that the sender and witness hashes match within the challenge.
  1030. *
  1031. * RETURN:
  1032. * SECSuccess if decrypting the witness field was successful. This does
  1033. * not indicate that the decrypted data is valid, since the private key
  1034. * passed in may not be the actual key needed to properly decrypt the
  1035. * witness field. Meaning that there is a decrypted structure now, but
  1036. * may be garbage because the private key was incorrect.
  1037. * Any other return value indicates the function could not complete the
  1038. * decryption process.
  1039. */
  1040. extern SECStatus
  1041. CMMF_POPODecKeyChallContDecryptChallenge(CMMFPOPODecKeyChallContent *inChalCont,
  1042. int inIndex,
  1043. SECKEYPrivateKey *inPrivKey);
  1044. /*
  1045. * FUNCTION: CMMF_DestroyPOPODecKeyChallContent
  1046. * INPUTS:
  1047. * inDecKeyCont
  1048. * The CMMFPOPODecKeyChallContent to free
  1049. * NOTES:
  1050. * This function frees up all the memory associated with the
  1051. * CMMFPOPODecKeyChallContent
  1052. * RETURN:
  1053. * SECSuccess if freeing up all the memory associatd with the
  1054. * CMMFPOPODecKeyChallContent is successful. Any other return value
  1055. * indicates an error while freeing the memory.
  1056. *
  1057. */
  1058. extern SECStatus
  1059. CMMF_DestroyPOPODecKeyChallContent (CMMFPOPODecKeyChallContent *inDecKeyCont);
  1060. SEC_END_PROTOS
  1061. #endif /* _CMMF_H_ */