crmffut.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. /*
  5. * These functions to be implemented in the future if the features
  6. * which these functions would implement wind up being needed.
  7. */
  8. /*
  9. * Use this function to create the CRMFSinglePubInfo* variables that will
  10. * populate the inPubInfoArray parameter for the function
  11. * CRMF_CreatePKIPublicationInfo.
  12. *
  13. * "inPubMethod" specifies which publication method will be used
  14. * "pubLocation" is a representation of the location where
  15. */
  16. extern CRMFSinglePubInfo *
  17. CRMF_CreateSinglePubInfo(CRMFPublicationMethod inPubMethod,
  18. CRMFGeneralName *pubLocation);
  19. /*
  20. * Create a PKIPublicationInfo that can later be passed to the function
  21. * CRMFAddPubInfoControl.
  22. */
  23. extern CRMFPKIPublicationInfo *
  24. CRMF_CreatePKIPublicationInfo(CRMFPublicationAction inAction,
  25. CRMFSinglePubInfo **inPubInfoArray,
  26. int numPubInfo);
  27. /*
  28. * Only call this function on a CRMFPublicationInfo that was created by
  29. * CRMF_CreatePKIPublicationInfo that was passed in NULL for arena.
  30. */
  31. extern SECStatus
  32. CRMF_DestroyPKIPublicationInfo(CRMFPKIPublicationInfo *inPubInfo);
  33. extern SECStatus CRMF_AddPubInfoControl(CRMFCertRequest *inCertReq,
  34. CRMFPKIPublicationInfo *inPubInfo);
  35. /*
  36. * This is to create a Cert ID Control which can later be added to
  37. * a certificate request.
  38. */
  39. extern CRMFCertID *CRMF_CreateCertID(CRMFGeneralName *issuer,
  40. long serialNumber);
  41. extern SECStatus CRMF_DestroyCertID(CRMFCertID *certID);
  42. extern SECStatus CRMF_AddCertIDControl(CRMFCertRequest *inCertReq,
  43. CRMFCertID *certID);
  44. extern SECStatus
  45. CRMF_AddProtocolEncryptioKeyControl(CRMFCertRequest *inCertReq,
  46. CERTSubjectPublicKeyInfo *spki);
  47. /*
  48. * Add the ASCII Pairs Registration Info to the Certificate Request.
  49. * The SECItem must be an OCTET string representation.
  50. */
  51. extern SECStatus
  52. CRMF_AddUTF8PairsRegInfo(CRMFCertRequest *inCertReq,
  53. SECItem *asciiPairs);
  54. /*
  55. * This takes a CertRequest and adds it to another CertRequest.
  56. */
  57. extern SECStatus
  58. CRMF_AddCertReqToRegInfo(CRMFCertRequest *certReqToAddTo,
  59. CRMFCertRequest *certReqBeingAdded);
  60. /*
  61. * Returns which option was used for the authInfo field of POPOSigningKeyInput
  62. */
  63. extern CRMFPOPOSkiInputAuthChoice
  64. CRMF_GetSignKeyInputAuthChoice(CRMFPOPOSigningKeyInput *inKeyInput);
  65. /*
  66. * Gets the PKMACValue associated with the POPOSigningKeyInput.
  67. * If the POPOSigningKeyInput did not use authInfo.publicKeyMAC
  68. * the function returns SECFailure and the value at *destValue is unchanged.
  69. *
  70. * If the POPOSigningKeyInput did use authInfo.publicKeyMAC, the function
  71. * returns SECSuccess and places the PKMACValue at *destValue.
  72. */
  73. extern SECStatus
  74. CRMF_GetSignKeyInputPKMACValue(CRMFPOPOSigningKeyInput *inKeyInput,
  75. CRMFPKMACValue **destValue);
  76. /*
  77. * Gets the SubjectPublicKeyInfo from the POPOSigningKeyInput
  78. */
  79. extern CERTSubjectPublicKeyInfo *
  80. CRMF_GetSignKeyInputPublicKey(CRMFPOPOSigningKeyInput *inKeyInput);
  81. /*
  82. * Return the value for the PKIPublicationInfo Control.
  83. * A return value of NULL indicates that the Control was
  84. * not a PKIPublicationInfo Control. Call
  85. * CRMF_DestroyPKIPublicationInfo on the return value when done
  86. * using the pointer.
  87. */
  88. extern CRMFPKIPublicationInfo *CRMF_GetPKIPubInfo(CRMFControl *inControl);
  89. /*
  90. * Free up a CRMFPKIPublicationInfo structure.
  91. */
  92. extern SECStatus
  93. CRMF_DestroyPKIPublicationInfo(CRMFPKIPublicationInfo *inPubInfo);
  94. /*
  95. * Get the choice used for action in this PKIPublicationInfo.
  96. */
  97. extern CRMFPublicationAction
  98. CRMF_GetPublicationAction(CRMFPKIPublicationInfo *inPubInfo);
  99. /*
  100. * Get the number of pubInfos are stored in the PKIPubicationInfo.
  101. */
  102. extern int CRMF_GetNumPubInfos(CRMFPKIPublicationInfo *inPubInfo);
  103. /*
  104. * Get the pubInfo at index for the given PKIPubicationInfo.
  105. * Indexing is done like a traditional C Array. (0 .. numElements-1)
  106. */
  107. extern CRMFSinglePubInfo *
  108. CRMF_GetPubInfoAtIndex(CRMFPKIPublicationInfo *inPubInfo,
  109. int index);
  110. /*
  111. * Destroy the CRMFSinglePubInfo.
  112. */
  113. extern SECStatus CRMF_DestroySinglePubInfo(CRMFSinglePubInfo *inPubInfo);
  114. /*
  115. * Get the pubMethod used by the SinglePubInfo.
  116. */
  117. extern CRMFPublicationMethod
  118. CRMF_GetPublicationMethod(CRMFSinglePubInfo *inPubInfo);
  119. /*
  120. * Get the pubLocation associated with the SinglePubInfo.
  121. * A NULL return value indicates there was no pubLocation associated
  122. * with the SinglePuInfo.
  123. */
  124. extern CRMFGeneralName *CRMF_GetPubLocation(CRMFSinglePubInfo *inPubInfo);
  125. /*
  126. * Get the authInfo.sender field out of the POPOSigningKeyInput.
  127. * If the POPOSigningKeyInput did not use the authInfo the function
  128. * returns SECFailure and the value at *destName is unchanged.
  129. *
  130. * If the POPOSigningKeyInput did use authInfo.sender, the function returns
  131. * SECSuccess and puts the authInfo.sender at *destName/
  132. */
  133. extern SECStatus CRMF_GetSignKeyInputSender(CRMFPOPOSigningKeyInput *keyInput,
  134. CRMFGeneralName **destName);
  135. /**************** CMMF Functions that need to be added. **********************/
  136. /*
  137. * FUNCTION: CMMF_POPODecKeyChallContentSetNextChallenge
  138. * INPUTS:
  139. * inDecKeyChall
  140. * The CMMFPOPODecKeyChallContent to operate on.
  141. * inRandom
  142. * The random number to use when generating the challenge,
  143. * inSender
  144. * The GeneralName representation of the sender of the challenge.
  145. * inPubKey
  146. * The public key to use when encrypting the challenge.
  147. * NOTES:
  148. * This function adds a challenge to the end of the list of challenges
  149. * contained by 'inDecKeyChall'. Refer to the CMMF draft on how the
  150. * the random number passed in and the sender's GeneralName are used
  151. * to generate the challenge and witness fields of the challenge. This
  152. * library will use SHA1 as the one-way function for generating the
  153. * witess field of the challenge.
  154. *
  155. * RETURN:
  156. * SECSuccess if generating the challenge and adding to the end of list
  157. * of challenges was successful. Any other return value indicates an error
  158. * while trying to generate the challenge.
  159. */
  160. extern SECStatus
  161. CMMF_POPODecKeyChallContentSetNextChallenge(CMMFPOPODecKeyChallContent *inDecKeyChall,
  162. long inRandom,
  163. CERTGeneralName *inSender,
  164. SECKEYPublicKey *inPubKey);
  165. /*
  166. * FUNCTION: CMMF_POPODecKeyChallContentGetNumChallenges
  167. * INPUTS:
  168. * inKeyChallCont
  169. * The CMMFPOPODecKeyChallContent to operate on.
  170. * RETURN:
  171. * This function returns the number of CMMFChallenges are contained in
  172. * the CMMFPOPODecKeyChallContent structure.
  173. */
  174. extern int CMMF_POPODecKeyChallContentGetNumChallenges(CMMFPOPODecKeyChallContent *inKeyChallCont);
  175. /*
  176. * FUNCTION: CMMF_ChallengeGetRandomNumber
  177. * INPUTS:
  178. * inChallenge
  179. * The CMMFChallenge to operate on.
  180. * inDest
  181. * A pointer to a user supplied buffer where the library
  182. * can place a copy of the random integer contatained in the
  183. * challenge.
  184. * NOTES:
  185. * This function returns the value held in the decrypted Rand structure
  186. * corresponding to the random integer. The user must call
  187. * CMMF_ChallengeDecryptWitness before calling this function. Call
  188. * CMMF_ChallengeIsDecrypted to find out if the challenge has been
  189. * decrypted.
  190. *
  191. * RETURN:
  192. * SECSuccess indicates the witness field has been previously decrypted
  193. * and the value for the random integer was successfully placed at *inDest.
  194. * Any other return value indicates an error and that the value at *inDest
  195. * is not a valid value.
  196. */
  197. extern SECStatus CMMF_ChallengeGetRandomNumber(CMMFChallenge *inChallenge,
  198. long *inDest);
  199. /*
  200. * FUNCTION: CMMF_ChallengeGetSender
  201. * INPUTS:
  202. * inChallenge
  203. * the CMMFChallenge to operate on.
  204. * NOTES:
  205. * This function returns the value held in the decrypted Rand structure
  206. * corresponding to the sender. The user must call
  207. * CMMF_ChallengeDecryptWitness before calling this function. Call
  208. * CMMF_ChallengeIsDecrypted to find out if the witness field has been
  209. * decrypted. The user must call CERT_DestroyGeneralName after the return
  210. * value is no longer needed.
  211. *
  212. * RETURN:
  213. * A pointer to a copy of the sender CERTGeneralName. A return value of
  214. * NULL indicates an error in trying to copy the information or that the
  215. * witness field has not been decrypted.
  216. */
  217. extern CERTGeneralName *CMMF_ChallengeGetSender(CMMFChallenge *inChallenge);
  218. /*
  219. * FUNCTION: CMMF_ChallengeGetAlgId
  220. * INPUTS:
  221. * inChallenge
  222. * The CMMFChallenge to operate on.
  223. * inDestAlgId
  224. * A pointer to memory where a pointer to a copy of the algorithm
  225. * id can be placed.
  226. * NOTES:
  227. * This function retrieves the one way function algorithm identifier
  228. * contained within the CMMFChallenge if the optional field is present.
  229. *
  230. * RETURN:
  231. * SECSucces indicates the function was able to place a pointer to a copy of
  232. * the alogrithm id at *inAlgId. If the value at *inDestAlgId is NULL,
  233. * that means there was no algorithm identifier present in the
  234. * CMMFChallenge. Any other return value indicates the function was not
  235. * able to make a copy of the algorithm identifier. In this case the value
  236. * at *inDestAlgId is not valid.
  237. */
  238. extern SECStatus CMMF_ChallengeGetAlgId(CMMFChallenge *inChallenge,
  239. SECAlgorithmID *inAlgId);
  240. /*
  241. * FUNCTION: CMMF_DestroyChallenge
  242. * INPUTS:
  243. * inChallenge
  244. * The CMMFChallenge to free up.
  245. * NOTES:
  246. * This function frees up all the memory associated with the CMMFChallenge
  247. * passed in.
  248. * RETURN:
  249. * SECSuccess if freeing all the memory associated with the CMMFChallenge
  250. * passed in is successful. Any other return value indicates an error
  251. * while freeing the memory.
  252. */
  253. extern SECStatus CMMF_DestroyChallenge(CMMFChallenge *inChallenge);
  254. /*
  255. * FUNCTION: CMMF_DestroyPOPODecKeyRespContent
  256. * INPUTS:
  257. * inDecKeyResp
  258. * The CMMFPOPODecKeyRespContent structure to free.
  259. * NOTES:
  260. * This function frees up all the memory associate with the
  261. * CMMFPOPODecKeyRespContent.
  262. *
  263. * RETURN:
  264. * SECSuccess if freeint up all the memory associated with the
  265. * CMMFPOPODecKeyRespContent structure is successful. Any other
  266. * return value indicates an error while freeing the memory.
  267. */
  268. extern SECStatus
  269. CMMF_DestroyPOPODecKeyRespContent(CMMFPOPODecKeyRespContent *inDecKeyResp);
  270. /*
  271. * FUNCTION: CMMF_ChallengeDecryptWitness
  272. * INPUTS:
  273. * inChallenge
  274. * The CMMFChallenge to operate on.
  275. * inPrivKey
  276. * The private key to use to decrypt the witness field.
  277. * NOTES:
  278. * This function uses the private key to decrypt the challenge field
  279. * contained in the CMMFChallenge. Make sure the private key matches the
  280. * public key that was used to encrypt the witness. The creator of
  281. * the challenge will most likely be an RA that has the public key
  282. * from a Cert request. So the private key should be the private key
  283. * associated with public key in that request. This function will also
  284. * verify the witness field of the challenge.
  285. *
  286. * RETURN:
  287. * SECSuccess if decrypting the witness field was successful. This does
  288. * not indicate that the decrypted data is valid, since the private key
  289. * passed in may not be the actual key needed to properly decrypt the
  290. * witness field. Meaning that there is a decrypted structure now, but
  291. * may be garbage because the private key was incorrect.
  292. * Any other return value indicates the function could not complete the
  293. * decryption process.
  294. */
  295. extern SECStatus CMMF_ChallengeDecryptWitness(CMMFChallenge *inChallenge,
  296. SECKEYPrivateKey *inPrivKey);
  297. /*
  298. * FUNCTION: CMMF_ChallengeIsDecrypted
  299. * INPUTS:
  300. * inChallenge
  301. * The CMMFChallenge to operate on.
  302. * RETURN:
  303. * This is a predicate function that returns PR_TRUE if the decryption
  304. * process has already been performed. The function return PR_FALSE if
  305. * the decryption process has not been performed yet.
  306. */
  307. extern PRBool CMMF_ChallengeIsDecrypted(CMMFChallenge *inChallenge);
  308. /*
  309. * FUNCTION: CMMF_DestroyPOPODecKeyChallContent
  310. * INPUTS:
  311. * inDecKeyCont
  312. * The CMMFPOPODecKeyChallContent to free
  313. * NOTES:
  314. * This function frees up all the memory associated with the
  315. * CMMFPOPODecKeyChallContent
  316. * RETURN:
  317. * SECSuccess if freeing up all the memory associatd with the
  318. * CMMFPOPODecKeyChallContent is successful. Any other return value
  319. * indicates an error while freeing the memory.
  320. *
  321. */
  322. extern SECStatus
  323. CMMF_DestroyPOPODecKeyChallContent(CMMFPOPODecKeyChallContent *inDecKeyCont);