cms.h 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154
  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. * Interfaces of the CMS implementation.
  6. */
  7. #ifndef _CMS_H_
  8. #define _CMS_H_
  9. #include "seccomon.h"
  10. #include "secoidt.h"
  11. #include "certt.h"
  12. #include "keythi.h"
  13. #include "hasht.h"
  14. #include "cmst.h"
  15. /************************************************************************/
  16. SEC_BEGIN_PROTOS
  17. /************************************************************************
  18. * cmsdecode.c - CMS decoding
  19. ************************************************************************/
  20. /*
  21. * NSS_CMSDecoder_Start - set up decoding of a DER-encoded CMS message
  22. *
  23. * "poolp" - pointer to arena for message, or NULL if new pool should be created
  24. * "cb", "cb_arg" - callback function and argument for delivery of inner content
  25. * inner content will be stored in the message if cb is NULL.
  26. * "pwfn", pwfn_arg" - callback function for getting token password
  27. * "decrypt_key_cb", "decrypt_key_cb_arg" - callback function for getting bulk key for encryptedData
  28. */
  29. extern NSSCMSDecoderContext *
  30. NSS_CMSDecoder_Start(PLArenaPool *poolp,
  31. NSSCMSContentCallback cb, void *cb_arg,
  32. PK11PasswordFunc pwfn, void *pwfn_arg,
  33. NSSCMSGetDecryptKeyCallback decrypt_key_cb, void *decrypt_key_cb_arg);
  34. /*
  35. * NSS_CMSDecoder_Update - feed DER-encoded data to decoder
  36. */
  37. extern SECStatus
  38. NSS_CMSDecoder_Update(NSSCMSDecoderContext *p7dcx, const char *buf, unsigned long len);
  39. /*
  40. * NSS_CMSDecoder_Cancel - cancel a decoding process
  41. */
  42. extern void
  43. NSS_CMSDecoder_Cancel(NSSCMSDecoderContext *p7dcx);
  44. /*
  45. * NSS_CMSDecoder_Finish - mark the end of inner content and finish decoding
  46. */
  47. extern NSSCMSMessage *
  48. NSS_CMSDecoder_Finish(NSSCMSDecoderContext *p7dcx);
  49. /*
  50. * NSS_CMSMessage_CreateFromDER - decode a CMS message from DER encoded data
  51. */
  52. extern NSSCMSMessage *
  53. NSS_CMSMessage_CreateFromDER(SECItem *DERmessage,
  54. NSSCMSContentCallback cb, void *cb_arg,
  55. PK11PasswordFunc pwfn, void *pwfn_arg,
  56. NSSCMSGetDecryptKeyCallback decrypt_key_cb, void *decrypt_key_cb_arg);
  57. /************************************************************************
  58. * cmsencode.c - CMS encoding
  59. ************************************************************************/
  60. /*
  61. * NSS_CMSEncoder_Start - set up encoding of a CMS message
  62. *
  63. * "cmsg" - message to encode
  64. * "outputfn", "outputarg" - callback function for delivery of DER-encoded output
  65. * will not be called if NULL.
  66. * "dest" - if non-NULL, pointer to SECItem that will hold the DER-encoded output
  67. * "destpoolp" - pool to allocate DER-encoded output in
  68. * "pwfn", pwfn_arg" - callback function for getting token password
  69. * "decrypt_key_cb", "decrypt_key_cb_arg" - callback function for getting bulk key for encryptedData
  70. * "detached_digestalgs", "detached_digests" - digests from detached content
  71. */
  72. extern NSSCMSEncoderContext *
  73. NSS_CMSEncoder_Start(NSSCMSMessage *cmsg,
  74. NSSCMSContentCallback outputfn, void *outputarg,
  75. SECItem *dest, PLArenaPool *destpoolp,
  76. PK11PasswordFunc pwfn, void *pwfn_arg,
  77. NSSCMSGetDecryptKeyCallback decrypt_key_cb, void *decrypt_key_cb_arg,
  78. SECAlgorithmID **detached_digestalgs, SECItem **detached_digests);
  79. /*
  80. * NSS_CMSEncoder_Update - take content data delivery from the user
  81. *
  82. * "p7ecx" - encoder context
  83. * "data" - content data
  84. * "len" - length of content data
  85. */
  86. extern SECStatus
  87. NSS_CMSEncoder_Update(NSSCMSEncoderContext *p7ecx, const char *data, unsigned long len);
  88. /*
  89. * NSS_CMSEncoder_Cancel - stop all encoding
  90. */
  91. extern SECStatus
  92. NSS_CMSEncoder_Cancel(NSSCMSEncoderContext *p7ecx);
  93. /*
  94. * NSS_CMSEncoder_Finish - signal the end of data
  95. *
  96. * we need to walk down the chain of encoders and the finish them from the innermost out
  97. */
  98. extern SECStatus
  99. NSS_CMSEncoder_Finish(NSSCMSEncoderContext *p7ecx);
  100. /************************************************************************
  101. * cmsmessage.c - CMS message object
  102. ************************************************************************/
  103. /*
  104. * NSS_CMSMessage_Create - create a CMS message object
  105. *
  106. * "poolp" - arena to allocate memory from, or NULL if new arena should be created
  107. */
  108. extern NSSCMSMessage *
  109. NSS_CMSMessage_Create(PLArenaPool *poolp);
  110. /*
  111. * NSS_CMSMessage_SetEncodingParams - set up a CMS message object for encoding or decoding
  112. *
  113. * "cmsg" - message object
  114. * "pwfn", pwfn_arg" - callback function for getting token password
  115. * "decrypt_key_cb", "decrypt_key_cb_arg" - callback function for getting bulk key for encryptedData
  116. * "detached_digestalgs", "detached_digests" - digests from detached content
  117. *
  118. * used internally.
  119. */
  120. extern void
  121. NSS_CMSMessage_SetEncodingParams(NSSCMSMessage *cmsg,
  122. PK11PasswordFunc pwfn, void *pwfn_arg,
  123. NSSCMSGetDecryptKeyCallback decrypt_key_cb, void *decrypt_key_cb_arg,
  124. SECAlgorithmID **detached_digestalgs, SECItem **detached_digests);
  125. /*
  126. * NSS_CMSMessage_Destroy - destroy a CMS message and all of its sub-pieces.
  127. */
  128. extern void
  129. NSS_CMSMessage_Destroy(NSSCMSMessage *cmsg);
  130. /*
  131. * NSS_CMSMessage_Copy - return a copy of the given message.
  132. *
  133. * The copy may be virtual or may be real -- either way, the result needs
  134. * to be passed to NSS_CMSMessage_Destroy later (as does the original).
  135. */
  136. extern NSSCMSMessage *
  137. NSS_CMSMessage_Copy(NSSCMSMessage *cmsg);
  138. /*
  139. * NSS_CMSMessage_GetArena - return a pointer to the message's arena pool
  140. */
  141. extern PLArenaPool *
  142. NSS_CMSMessage_GetArena(NSSCMSMessage *cmsg);
  143. /*
  144. * NSS_CMSMessage_GetContentInfo - return a pointer to the top level contentInfo
  145. */
  146. extern NSSCMSContentInfo *
  147. NSS_CMSMessage_GetContentInfo(NSSCMSMessage *cmsg);
  148. /*
  149. * Return a pointer to the actual content.
  150. * In the case of those types which are encrypted, this returns the *plain* content.
  151. * In case of nested contentInfos, this descends and retrieves the innermost content.
  152. */
  153. extern SECItem *
  154. NSS_CMSMessage_GetContent(NSSCMSMessage *cmsg);
  155. /*
  156. * NSS_CMSMessage_ContentLevelCount - count number of levels of CMS content objects in this message
  157. *
  158. * CMS data content objects do not count.
  159. */
  160. extern int
  161. NSS_CMSMessage_ContentLevelCount(NSSCMSMessage *cmsg);
  162. /*
  163. * NSS_CMSMessage_ContentLevel - find content level #n
  164. *
  165. * CMS data content objects do not count.
  166. */
  167. extern NSSCMSContentInfo *
  168. NSS_CMSMessage_ContentLevel(NSSCMSMessage *cmsg, int n);
  169. /*
  170. * NSS_CMSMessage_ContainsCertsOrCrls - see if message contains certs along the way
  171. */
  172. extern PRBool
  173. NSS_CMSMessage_ContainsCertsOrCrls(NSSCMSMessage *cmsg);
  174. /*
  175. * NSS_CMSMessage_IsEncrypted - see if message contains a encrypted submessage
  176. */
  177. extern PRBool
  178. NSS_CMSMessage_IsEncrypted(NSSCMSMessage *cmsg);
  179. /*
  180. * NSS_CMSMessage_IsSigned - see if message contains a signed submessage
  181. *
  182. * If the CMS message has a SignedData with a signature (not just a SignedData)
  183. * return true; false otherwise. This can/should be called before calling
  184. * VerifySignature, which will always indicate failure if no signature is
  185. * present, but that does not mean there even was a signature!
  186. * Note that the content itself can be empty (detached content was sent
  187. * another way); it is the presence of the signature that matters.
  188. */
  189. extern PRBool
  190. NSS_CMSMessage_IsSigned(NSSCMSMessage *cmsg);
  191. /*
  192. * NSS_CMSMessage_IsContentEmpty - see if content is empty
  193. *
  194. * returns PR_TRUE is innermost content length is < minLen
  195. * XXX need the encrypted content length (why?)
  196. */
  197. extern PRBool
  198. NSS_CMSMessage_IsContentEmpty(NSSCMSMessage *cmsg, unsigned int minLen);
  199. /************************************************************************
  200. * cmscinfo.c - CMS contentInfo methods
  201. ************************************************************************/
  202. /*
  203. * NSS_CMSContentInfo_Destroy - destroy a CMS contentInfo and all of its sub-pieces.
  204. */
  205. extern void
  206. NSS_CMSContentInfo_Destroy(NSSCMSContentInfo *cinfo);
  207. /*
  208. * NSS_CMSContentInfo_GetChildContentInfo - get content's contentInfo (if it exists)
  209. */
  210. extern NSSCMSContentInfo *
  211. NSS_CMSContentInfo_GetChildContentInfo(NSSCMSContentInfo *cinfo);
  212. /*
  213. * NSS_CMSContentInfo_SetContent - set cinfo's content type & content to CMS object
  214. */
  215. extern SECStatus
  216. NSS_CMSContentInfo_SetContent(NSSCMSMessage *cmsg, NSSCMSContentInfo *cinfo, SECOidTag type, void *ptr);
  217. /*
  218. * NSS_CMSContentInfo_SetContent_XXXX - typesafe wrappers for NSS_CMSContentInfo_SetType
  219. * set cinfo's content type & content to CMS object
  220. */
  221. extern SECStatus
  222. NSS_CMSContentInfo_SetContent_Data(NSSCMSMessage *cmsg, NSSCMSContentInfo *cinfo, SECItem *data, PRBool detached);
  223. extern SECStatus
  224. NSS_CMSContentInfo_SetContent_SignedData(NSSCMSMessage *cmsg, NSSCMSContentInfo *cinfo, NSSCMSSignedData *sigd);
  225. extern SECStatus
  226. NSS_CMSContentInfo_SetContent_EnvelopedData(NSSCMSMessage *cmsg, NSSCMSContentInfo *cinfo, NSSCMSEnvelopedData *envd);
  227. extern SECStatus
  228. NSS_CMSContentInfo_SetContent_DigestedData(NSSCMSMessage *cmsg, NSSCMSContentInfo *cinfo, NSSCMSDigestedData *digd);
  229. extern SECStatus
  230. NSS_CMSContentInfo_SetContent_EncryptedData(NSSCMSMessage *cmsg, NSSCMSContentInfo *cinfo, NSSCMSEncryptedData *encd);
  231. /*
  232. * turn off streaming for this content type.
  233. * This could fail with SEC_ERROR_NO_MEMORY in memory constrained conditions.
  234. */
  235. extern SECStatus
  236. NSS_CMSContentInfo_SetDontStream(NSSCMSContentInfo *cinfo, PRBool dontStream);
  237. /*
  238. * NSS_CMSContentInfo_GetContent - get pointer to inner content
  239. *
  240. * needs to be casted...
  241. */
  242. extern void *
  243. NSS_CMSContentInfo_GetContent(NSSCMSContentInfo *cinfo);
  244. /*
  245. * NSS_CMSContentInfo_GetInnerContent - get pointer to innermost content
  246. *
  247. * this is typically only called by NSS_CMSMessage_GetContent()
  248. */
  249. extern SECItem *
  250. NSS_CMSContentInfo_GetInnerContent(NSSCMSContentInfo *cinfo);
  251. /*
  252. * NSS_CMSContentInfo_GetContentType{Tag,OID} - find out (saving pointer to lookup result
  253. * for future reference) and return the inner content type.
  254. */
  255. extern SECOidTag
  256. NSS_CMSContentInfo_GetContentTypeTag(NSSCMSContentInfo *cinfo);
  257. extern SECItem *
  258. NSS_CMSContentInfo_GetContentTypeOID(NSSCMSContentInfo *cinfo);
  259. /*
  260. * NSS_CMSContentInfo_GetContentEncAlgTag - find out (saving pointer to lookup result
  261. * for future reference) and return the content encryption algorithm tag.
  262. */
  263. extern SECOidTag
  264. NSS_CMSContentInfo_GetContentEncAlgTag(NSSCMSContentInfo *cinfo);
  265. /*
  266. * NSS_CMSContentInfo_GetContentEncAlg - find out and return the content encryption algorithm tag.
  267. */
  268. extern SECAlgorithmID *
  269. NSS_CMSContentInfo_GetContentEncAlg(NSSCMSContentInfo *cinfo);
  270. extern SECStatus
  271. NSS_CMSContentInfo_SetContentEncAlg(PLArenaPool *poolp, NSSCMSContentInfo *cinfo,
  272. SECOidTag bulkalgtag, SECItem *parameters, int keysize);
  273. extern SECStatus
  274. NSS_CMSContentInfo_SetContentEncAlgID(PLArenaPool *poolp, NSSCMSContentInfo *cinfo,
  275. SECAlgorithmID *algid, int keysize);
  276. extern void
  277. NSS_CMSContentInfo_SetBulkKey(NSSCMSContentInfo *cinfo, PK11SymKey *bulkkey);
  278. extern PK11SymKey *
  279. NSS_CMSContentInfo_GetBulkKey(NSSCMSContentInfo *cinfo);
  280. extern int
  281. NSS_CMSContentInfo_GetBulkKeySize(NSSCMSContentInfo *cinfo);
  282. /************************************************************************
  283. * cmsutil.c - CMS misc utility functions
  284. ************************************************************************/
  285. /*
  286. * NSS_CMSArray_SortByDER - sort array of objects by objects' DER encoding
  287. *
  288. * make sure that the order of the objects guarantees valid DER (which must be
  289. * in lexigraphically ascending order for a SET OF); if reordering is necessary it
  290. * will be done in place (in objs).
  291. */
  292. extern SECStatus
  293. NSS_CMSArray_SortByDER(void **objs, const SEC_ASN1Template *objtemplate, void **objs2);
  294. /*
  295. * NSS_CMSUtil_DERCompare - for use with NSS_CMSArray_Sort to
  296. * sort arrays of SECItems containing DER
  297. */
  298. extern int
  299. NSS_CMSUtil_DERCompare(void *a, void *b);
  300. /*
  301. * NSS_CMSAlgArray_GetIndexByAlgID - find a specific algorithm in an array of
  302. * algorithms.
  303. *
  304. * algorithmArray - array of algorithm IDs
  305. * algid - algorithmid of algorithm to pick
  306. *
  307. * Returns:
  308. * An integer containing the index of the algorithm in the array or -1 if
  309. * algorithm was not found.
  310. */
  311. extern int
  312. NSS_CMSAlgArray_GetIndexByAlgID(SECAlgorithmID **algorithmArray, SECAlgorithmID *algid);
  313. /*
  314. * NSS_CMSAlgArray_GetIndexByAlgID - find a specific algorithm in an array of
  315. * algorithms.
  316. *
  317. * algorithmArray - array of algorithm IDs
  318. * algiddata - id of algorithm to pick
  319. *
  320. * Returns:
  321. * An integer containing the index of the algorithm in the array or -1 if
  322. * algorithm was not found.
  323. */
  324. extern int
  325. NSS_CMSAlgArray_GetIndexByAlgTag(SECAlgorithmID **algorithmArray, SECOidTag algtag);
  326. extern const SECHashObject *
  327. NSS_CMSUtil_GetHashObjByAlgID(SECAlgorithmID *algid);
  328. extern const SEC_ASN1Template *
  329. NSS_CMSUtil_GetTemplateByTypeTag(SECOidTag type);
  330. extern size_t
  331. NSS_CMSUtil_GetSizeByTypeTag(SECOidTag type);
  332. extern NSSCMSContentInfo *
  333. NSS_CMSContent_GetContentInfo(void *msg, SECOidTag type);
  334. extern const char *
  335. NSS_CMSUtil_VerificationStatusToString(NSSCMSVerificationStatus vs);
  336. /************************************************************************
  337. * cmssigdata.c - CMS signedData methods
  338. ************************************************************************/
  339. extern NSSCMSSignedData *
  340. NSS_CMSSignedData_Create(NSSCMSMessage *cmsg);
  341. extern void
  342. NSS_CMSSignedData_Destroy(NSSCMSSignedData *sigd);
  343. /*
  344. * NSS_CMSSignedData_Encode_BeforeStart - do all the necessary things to a SignedData
  345. * before start of encoding.
  346. *
  347. * In detail:
  348. * - find out about the right value to put into sigd->version
  349. * - come up with a list of digestAlgorithms (which should be the union of the algorithms
  350. * in the signerinfos).
  351. * If we happen to have a pre-set list of algorithms (and digest values!), we
  352. * check if we have all the signerinfos' algorithms. If not, this is an error.
  353. */
  354. extern SECStatus
  355. NSS_CMSSignedData_Encode_BeforeStart(NSSCMSSignedData *sigd);
  356. extern SECStatus
  357. NSS_CMSSignedData_Encode_BeforeData(NSSCMSSignedData *sigd);
  358. /*
  359. * NSS_CMSSignedData_Encode_AfterData - do all the necessary things to a SignedData
  360. * after all the encapsulated data was passed through the encoder.
  361. *
  362. * In detail:
  363. * - create the signatures in all the SignerInfos
  364. *
  365. * Please note that nothing is done to the Certificates and CRLs in the message - this
  366. * is entirely the responsibility of our callers.
  367. */
  368. extern SECStatus
  369. NSS_CMSSignedData_Encode_AfterData(NSSCMSSignedData *sigd);
  370. extern SECStatus
  371. NSS_CMSSignedData_Decode_BeforeData(NSSCMSSignedData *sigd);
  372. /*
  373. * NSS_CMSSignedData_Decode_AfterData - do all the necessary things to a SignedData
  374. * after all the encapsulated data was passed through the decoder.
  375. */
  376. extern SECStatus
  377. NSS_CMSSignedData_Decode_AfterData(NSSCMSSignedData *sigd);
  378. /*
  379. * NSS_CMSSignedData_Decode_AfterEnd - do all the necessary things to a SignedData
  380. * after all decoding is finished.
  381. */
  382. extern SECStatus
  383. NSS_CMSSignedData_Decode_AfterEnd(NSSCMSSignedData *sigd);
  384. /*
  385. * NSS_CMSSignedData_GetSignerInfos - retrieve the SignedData's signer list
  386. */
  387. extern NSSCMSSignerInfo **
  388. NSS_CMSSignedData_GetSignerInfos(NSSCMSSignedData *sigd);
  389. extern int
  390. NSS_CMSSignedData_SignerInfoCount(NSSCMSSignedData *sigd);
  391. extern NSSCMSSignerInfo *
  392. NSS_CMSSignedData_GetSignerInfo(NSSCMSSignedData *sigd, int i);
  393. /*
  394. * NSS_CMSSignedData_GetDigestAlgs - retrieve the SignedData's digest algorithm list
  395. */
  396. extern SECAlgorithmID **
  397. NSS_CMSSignedData_GetDigestAlgs(NSSCMSSignedData *sigd);
  398. /*
  399. * NSS_CMSSignedData_GetContentInfo - return pointer to this signedData's contentinfo
  400. */
  401. extern NSSCMSContentInfo *
  402. NSS_CMSSignedData_GetContentInfo(NSSCMSSignedData *sigd);
  403. /*
  404. * NSS_CMSSignedData_GetCertificateList - retrieve the SignedData's certificate list
  405. */
  406. extern SECItem **
  407. NSS_CMSSignedData_GetCertificateList(NSSCMSSignedData *sigd);
  408. extern SECStatus
  409. NSS_CMSSignedData_ImportCerts(NSSCMSSignedData *sigd, CERTCertDBHandle *certdb,
  410. SECCertUsage certusage, PRBool keepcerts);
  411. /*
  412. * NSS_CMSSignedData_HasDigests - see if we have digests in place
  413. */
  414. extern PRBool
  415. NSS_CMSSignedData_HasDigests(NSSCMSSignedData *sigd);
  416. /*
  417. * NSS_CMSSignedData_VerifySignerInfo - check a signature.
  418. *
  419. * The digests were either calculated during decoding (and are stored in the
  420. * signedData itself) or set after decoding using NSS_CMSSignedData_SetDigests.
  421. *
  422. * The verification checks if the signing cert is valid and has a trusted chain
  423. * for the purpose specified by "certusage".
  424. */
  425. extern SECStatus
  426. NSS_CMSSignedData_VerifySignerInfo(NSSCMSSignedData *sigd, int i, CERTCertDBHandle *certdb,
  427. SECCertUsage certusage);
  428. /*
  429. * NSS_CMSSignedData_VerifyCertsOnly - verify the certs in a certs-only message
  430. */
  431. extern SECStatus
  432. NSS_CMSSignedData_VerifyCertsOnly(NSSCMSSignedData *sigd,
  433. CERTCertDBHandle *certdb,
  434. SECCertUsage usage);
  435. extern SECStatus
  436. NSS_CMSSignedData_AddCertList(NSSCMSSignedData *sigd, CERTCertificateList *certlist);
  437. /*
  438. * NSS_CMSSignedData_AddCertChain - add cert and its entire chain to the set of certs
  439. */
  440. extern SECStatus
  441. NSS_CMSSignedData_AddCertChain(NSSCMSSignedData *sigd, CERTCertificate *cert);
  442. extern SECStatus
  443. NSS_CMSSignedData_AddCertificate(NSSCMSSignedData *sigd, CERTCertificate *cert);
  444. extern PRBool
  445. NSS_CMSSignedData_ContainsCertsOrCrls(NSSCMSSignedData *sigd);
  446. extern SECStatus
  447. NSS_CMSSignedData_AddSignerInfo(NSSCMSSignedData *sigd,
  448. NSSCMSSignerInfo *signerinfo);
  449. extern SECStatus
  450. NSS_CMSSignedData_SetDigests(NSSCMSSignedData *sigd,
  451. SECAlgorithmID **digestalgs,
  452. SECItem **digests);
  453. extern SECStatus
  454. NSS_CMSSignedData_SetDigestValue(NSSCMSSignedData *sigd,
  455. SECOidTag digestalgtag,
  456. SECItem *digestdata);
  457. extern SECStatus
  458. NSS_CMSSignedData_AddDigest(PLArenaPool *poolp,
  459. NSSCMSSignedData *sigd,
  460. SECOidTag digestalgtag,
  461. SECItem *digest);
  462. extern SECItem *
  463. NSS_CMSSignedData_GetDigestValue(NSSCMSSignedData *sigd, SECOidTag digestalgtag);
  464. /*
  465. * NSS_CMSSignedData_CreateCertsOnly - create a certs-only SignedData.
  466. *
  467. * cert - base certificates that will be included
  468. * include_chain - if true, include the complete cert chain for cert
  469. *
  470. * More certs and chains can be added via AddCertificate and AddCertChain.
  471. *
  472. * An error results in a return value of NULL and an error set.
  473. */
  474. extern NSSCMSSignedData *
  475. NSS_CMSSignedData_CreateCertsOnly(NSSCMSMessage *cmsg, CERTCertificate *cert, PRBool include_chain);
  476. /************************************************************************
  477. * cmssiginfo.c - signerinfo methods
  478. ************************************************************************/
  479. extern NSSCMSSignerInfo *
  480. NSS_CMSSignerInfo_Create(NSSCMSMessage *cmsg, CERTCertificate *cert, SECOidTag digestalgtag);
  481. extern NSSCMSSignerInfo *
  482. NSS_CMSSignerInfo_CreateWithSubjKeyID(NSSCMSMessage *cmsg, SECItem *subjKeyID, SECKEYPublicKey *pubKey, SECKEYPrivateKey *signingKey, SECOidTag digestalgtag);
  483. /*
  484. * NSS_CMSSignerInfo_Destroy - destroy a SignerInfo data structure
  485. */
  486. extern void
  487. NSS_CMSSignerInfo_Destroy(NSSCMSSignerInfo *si);
  488. /*
  489. * NSS_CMSSignerInfo_Sign - sign something
  490. *
  491. */
  492. extern SECStatus
  493. NSS_CMSSignerInfo_Sign(NSSCMSSignerInfo *signerinfo, SECItem *digest, SECItem *contentType);
  494. extern SECStatus
  495. NSS_CMSSignerInfo_VerifyCertificate(NSSCMSSignerInfo *signerinfo, CERTCertDBHandle *certdb,
  496. SECCertUsage certusage);
  497. /*
  498. * NSS_CMSSignerInfo_Verify - verify the signature of a single SignerInfo
  499. *
  500. * Just verifies the signature. The assumption is that verification of the certificate
  501. * is done already.
  502. */
  503. extern SECStatus
  504. NSS_CMSSignerInfo_Verify(NSSCMSSignerInfo *signerinfo, SECItem *digest, SECItem *contentType);
  505. extern NSSCMSVerificationStatus
  506. NSS_CMSSignerInfo_GetVerificationStatus(NSSCMSSignerInfo *signerinfo);
  507. extern SECOidData *
  508. NSS_CMSSignerInfo_GetDigestAlg(NSSCMSSignerInfo *signerinfo);
  509. extern SECOidTag
  510. NSS_CMSSignerInfo_GetDigestAlgTag(NSSCMSSignerInfo *signerinfo);
  511. extern int
  512. NSS_CMSSignerInfo_GetVersion(NSSCMSSignerInfo *signerinfo);
  513. extern CERTCertificateList *
  514. NSS_CMSSignerInfo_GetCertList(NSSCMSSignerInfo *signerinfo);
  515. /*
  516. * NSS_CMSSignerInfo_GetSigningTime - return the signing time,
  517. * in UTCTime format, of a CMS signerInfo.
  518. *
  519. * sinfo - signerInfo data for this signer
  520. *
  521. * Returns a pointer to XXXX (what?)
  522. * A return value of NULL is an error.
  523. */
  524. extern SECStatus
  525. NSS_CMSSignerInfo_GetSigningTime(NSSCMSSignerInfo *sinfo, PRTime *stime);
  526. /*
  527. * Return the signing cert of a CMS signerInfo.
  528. *
  529. * the certs in the enclosing SignedData must have been imported already
  530. */
  531. extern CERTCertificate *
  532. NSS_CMSSignerInfo_GetSigningCertificate(NSSCMSSignerInfo *signerinfo, CERTCertDBHandle *certdb);
  533. /*
  534. * NSS_CMSSignerInfo_GetSignerCommonName - return the common name of the signer
  535. *
  536. * sinfo - signerInfo data for this signer
  537. *
  538. * Returns a pointer to allocated memory, which must be freed with PORT_Free.
  539. * A return value of NULL is an error.
  540. */
  541. extern char *
  542. NSS_CMSSignerInfo_GetSignerCommonName(NSSCMSSignerInfo *sinfo);
  543. /*
  544. * NSS_CMSSignerInfo_GetSignerEmailAddress - return the common name of the signer
  545. *
  546. * sinfo - signerInfo data for this signer
  547. *
  548. * Returns a pointer to allocated memory, which must be freed.
  549. * A return value of NULL is an error.
  550. */
  551. extern char *
  552. NSS_CMSSignerInfo_GetSignerEmailAddress(NSSCMSSignerInfo *sinfo);
  553. /*
  554. * NSS_CMSSignerInfo_AddAuthAttr - add an attribute to the
  555. * authenticated (i.e. signed) attributes of "signerinfo".
  556. */
  557. extern SECStatus
  558. NSS_CMSSignerInfo_AddAuthAttr(NSSCMSSignerInfo *signerinfo, NSSCMSAttribute *attr);
  559. /*
  560. * NSS_CMSSignerInfo_AddUnauthAttr - add an attribute to the
  561. * unauthenticated attributes of "signerinfo".
  562. */
  563. extern SECStatus
  564. NSS_CMSSignerInfo_AddUnauthAttr(NSSCMSSignerInfo *signerinfo, NSSCMSAttribute *attr);
  565. /*
  566. * NSS_CMSSignerInfo_AddSigningTime - add the signing time to the
  567. * authenticated (i.e. signed) attributes of "signerinfo".
  568. *
  569. * This is expected to be included in outgoing signed
  570. * messages for email (S/MIME) but is likely useful in other situations.
  571. *
  572. * This should only be added once; a second call will do nothing.
  573. *
  574. * XXX This will probably just shove the current time into "signerinfo"
  575. * but it will not actually get signed until the entire item is
  576. * processed for encoding. Is this (expected to be small) delay okay?
  577. */
  578. extern SECStatus
  579. NSS_CMSSignerInfo_AddSigningTime(NSSCMSSignerInfo *signerinfo, PRTime t);
  580. /*
  581. * NSS_CMSSignerInfo_AddSMIMECaps - add a SMIMECapabilities attribute to the
  582. * authenticated (i.e. signed) attributes of "signerinfo".
  583. *
  584. * This is expected to be included in outgoing signed
  585. * messages for email (S/MIME).
  586. */
  587. extern SECStatus
  588. NSS_CMSSignerInfo_AddSMIMECaps(NSSCMSSignerInfo *signerinfo);
  589. /*
  590. * NSS_CMSSignerInfo_AddSMIMEEncKeyPrefs - add a SMIMEEncryptionKeyPreferences attribute to the
  591. * authenticated (i.e. signed) attributes of "signerinfo".
  592. *
  593. * This is expected to be included in outgoing signed messages for email (S/MIME).
  594. */
  595. SECStatus
  596. NSS_CMSSignerInfo_AddSMIMEEncKeyPrefs(NSSCMSSignerInfo *signerinfo, CERTCertificate *cert, CERTCertDBHandle *certdb);
  597. /*
  598. * NSS_CMSSignerInfo_AddMSSMIMEEncKeyPrefs - add a SMIMEEncryptionKeyPreferences attribute to the
  599. * authenticated (i.e. signed) attributes of "signerinfo", using the OID preferred by Microsoft.
  600. *
  601. * This is expected to be included in outgoing signed messages for email (S/MIME),
  602. * if compatibility with Microsoft mail clients is wanted.
  603. */
  604. SECStatus
  605. NSS_CMSSignerInfo_AddMSSMIMEEncKeyPrefs(NSSCMSSignerInfo *signerinfo, CERTCertificate *cert, CERTCertDBHandle *certdb);
  606. /*
  607. * NSS_CMSSignerInfo_AddCounterSignature - countersign a signerinfo
  608. */
  609. extern SECStatus
  610. NSS_CMSSignerInfo_AddCounterSignature(NSSCMSSignerInfo *signerinfo,
  611. SECOidTag digestalg, CERTCertificate signingcert);
  612. /*
  613. * XXXX the following needs to be done in the S/MIME layer code
  614. * after signature of a signerinfo is verified
  615. */
  616. extern SECStatus
  617. NSS_SMIMESignerInfo_SaveSMIMEProfile(NSSCMSSignerInfo *signerinfo);
  618. /*
  619. * NSS_CMSSignerInfo_IncludeCerts - set cert chain inclusion mode for this signer
  620. */
  621. extern SECStatus
  622. NSS_CMSSignerInfo_IncludeCerts(NSSCMSSignerInfo *signerinfo, NSSCMSCertChainMode cm, SECCertUsage usage);
  623. /************************************************************************
  624. * cmsenvdata.c - CMS envelopedData methods
  625. ************************************************************************/
  626. /*
  627. * NSS_CMSEnvelopedData_Create - create an enveloped data message
  628. */
  629. extern NSSCMSEnvelopedData *
  630. NSS_CMSEnvelopedData_Create(NSSCMSMessage *cmsg, SECOidTag algorithm, int keysize);
  631. /*
  632. * NSS_CMSEnvelopedData_Destroy - destroy an enveloped data message
  633. */
  634. extern void
  635. NSS_CMSEnvelopedData_Destroy(NSSCMSEnvelopedData *edp);
  636. /*
  637. * NSS_CMSEnvelopedData_GetContentInfo - return pointer to this envelopedData's contentinfo
  638. */
  639. extern NSSCMSContentInfo *
  640. NSS_CMSEnvelopedData_GetContentInfo(NSSCMSEnvelopedData *envd);
  641. /*
  642. * NSS_CMSEnvelopedData_AddRecipient - add a recipientinfo to the enveloped data msg
  643. *
  644. * rip must be created on the same pool as edp - this is not enforced, though.
  645. */
  646. extern SECStatus
  647. NSS_CMSEnvelopedData_AddRecipient(NSSCMSEnvelopedData *edp, NSSCMSRecipientInfo *rip);
  648. /*
  649. * NSS_CMSEnvelopedData_Encode_BeforeStart - prepare this envelopedData for encoding
  650. *
  651. * at this point, we need
  652. * - recipientinfos set up with recipient's certificates
  653. * - a content encryption algorithm (if none, 3DES will be used)
  654. *
  655. * this function will generate a random content encryption key (aka bulk key),
  656. * initialize the recipientinfos with certificate identification and wrap the bulk key
  657. * using the proper algorithm for every certificiate.
  658. * it will finally set the bulk algorithm and key so that the encode step can find it.
  659. */
  660. extern SECStatus
  661. NSS_CMSEnvelopedData_Encode_BeforeStart(NSSCMSEnvelopedData *envd);
  662. /*
  663. * NSS_CMSEnvelopedData_Encode_BeforeData - set up encryption
  664. */
  665. extern SECStatus
  666. NSS_CMSEnvelopedData_Encode_BeforeData(NSSCMSEnvelopedData *envd);
  667. /*
  668. * NSS_CMSEnvelopedData_Encode_AfterData - finalize this envelopedData for encoding
  669. */
  670. extern SECStatus
  671. NSS_CMSEnvelopedData_Encode_AfterData(NSSCMSEnvelopedData *envd);
  672. /*
  673. * NSS_CMSEnvelopedData_Decode_BeforeData - find our recipientinfo,
  674. * derive bulk key & set up our contentinfo
  675. */
  676. extern SECStatus
  677. NSS_CMSEnvelopedData_Decode_BeforeData(NSSCMSEnvelopedData *envd);
  678. /*
  679. * NSS_CMSEnvelopedData_Decode_AfterData - finish decrypting this envelopedData's content
  680. */
  681. extern SECStatus
  682. NSS_CMSEnvelopedData_Decode_AfterData(NSSCMSEnvelopedData *envd);
  683. /*
  684. * NSS_CMSEnvelopedData_Decode_AfterEnd - finish decoding this envelopedData
  685. */
  686. extern SECStatus
  687. NSS_CMSEnvelopedData_Decode_AfterEnd(NSSCMSEnvelopedData *envd);
  688. /************************************************************************
  689. * cmsrecinfo.c - CMS recipientInfo methods
  690. ************************************************************************/
  691. /*
  692. * NSS_CMSRecipientInfo_Create - create a recipientinfo
  693. *
  694. * we currently do not create KeyAgreement recipientinfos with multiple recipientEncryptedKeys
  695. * the certificate is supposed to have been verified by the caller
  696. */
  697. extern NSSCMSRecipientInfo *
  698. NSS_CMSRecipientInfo_Create(NSSCMSMessage *cmsg, CERTCertificate *cert);
  699. extern NSSCMSRecipientInfo *
  700. NSS_CMSRecipientInfo_CreateWithSubjKeyID(NSSCMSMessage *cmsg,
  701. SECItem *subjKeyID,
  702. SECKEYPublicKey *pubKey);
  703. extern NSSCMSRecipientInfo *
  704. NSS_CMSRecipientInfo_CreateWithSubjKeyIDFromCert(NSSCMSMessage *cmsg,
  705. CERTCertificate *cert);
  706. /*
  707. * NSS_CMSRecipientInfo_CreateNew - create a blank recipientinfo for
  708. * applications which want to encode their own CMS structures and
  709. * key exchange types.
  710. */
  711. extern NSSCMSRecipientInfo *
  712. NSS_CMSRecipientInfo_CreateNew(void *pwfn_arg);
  713. /*
  714. * NSS_CMSRecipientInfo_CreateFromDER - create a recipientinfo from partially
  715. * decoded DER data for applications which want to encode their own CMS
  716. * structures and key exchange types.
  717. */
  718. extern NSSCMSRecipientInfo *
  719. NSS_CMSRecipientInfo_CreateFromDER(SECItem *input, void *pwfn_arg);
  720. extern void
  721. NSS_CMSRecipientInfo_Destroy(NSSCMSRecipientInfo *ri);
  722. /*
  723. * NSS_CMSRecipientInfo_GetCertAndKey - retrieve the cert and key from the
  724. * recipientInfo struct. If retcert or retkey are NULL, the cert or
  725. * key (respectively) would not be returned). This function is a no-op if both
  726. * retcert and retkey are NULL. Caller inherits ownership of the cert and key
  727. * he requested (and is responsible to free them).
  728. */
  729. SECStatus NSS_CMSRecipientInfo_GetCertAndKey(NSSCMSRecipientInfo *ri,
  730. CERTCertificate **retcert,
  731. SECKEYPrivateKey **retkey);
  732. extern int
  733. NSS_CMSRecipientInfo_GetVersion(NSSCMSRecipientInfo *ri);
  734. extern SECItem *
  735. NSS_CMSRecipientInfo_GetEncryptedKey(NSSCMSRecipientInfo *ri, int subIndex);
  736. /*
  737. * NSS_CMSRecipientInfo_Encode - encode an NSS_CMSRecipientInfo as ASN.1
  738. */
  739. SECStatus NSS_CMSRecipientInfo_Encode(PLArenaPool *poolp,
  740. const NSSCMSRecipientInfo *src,
  741. SECItem *returned);
  742. extern SECOidTag
  743. NSS_CMSRecipientInfo_GetKeyEncryptionAlgorithmTag(NSSCMSRecipientInfo *ri);
  744. extern SECStatus
  745. NSS_CMSRecipientInfo_WrapBulkKey(NSSCMSRecipientInfo *ri, PK11SymKey *bulkkey,
  746. SECOidTag bulkalgtag);
  747. extern PK11SymKey *
  748. NSS_CMSRecipientInfo_UnwrapBulkKey(NSSCMSRecipientInfo *ri, int subIndex,
  749. CERTCertificate *cert, SECKEYPrivateKey *privkey,
  750. SECOidTag bulkalgtag);
  751. /************************************************************************
  752. * cmsencdata.c - CMS encryptedData methods
  753. ************************************************************************/
  754. /*
  755. * NSS_CMSEncryptedData_Create - create an empty encryptedData object.
  756. *
  757. * "algorithm" specifies the bulk encryption algorithm to use.
  758. * "keysize" is the key size.
  759. *
  760. * An error results in a return value of NULL and an error set.
  761. * (Retrieve specific errors via PORT_GetError()/XP_GetError().)
  762. */
  763. extern NSSCMSEncryptedData *
  764. NSS_CMSEncryptedData_Create(NSSCMSMessage *cmsg, SECOidTag algorithm, int keysize);
  765. /*
  766. * NSS_CMSEncryptedData_Destroy - destroy an encryptedData object
  767. */
  768. extern void
  769. NSS_CMSEncryptedData_Destroy(NSSCMSEncryptedData *encd);
  770. /*
  771. * NSS_CMSEncryptedData_GetContentInfo - return pointer to encryptedData object's contentInfo
  772. */
  773. extern NSSCMSContentInfo *
  774. NSS_CMSEncryptedData_GetContentInfo(NSSCMSEncryptedData *encd);
  775. /*
  776. * NSS_CMSEncryptedData_Encode_BeforeStart - do all the necessary things to a EncryptedData
  777. * before encoding begins.
  778. *
  779. * In particular:
  780. * - set the correct version value.
  781. * - get the encryption key
  782. */
  783. extern SECStatus
  784. NSS_CMSEncryptedData_Encode_BeforeStart(NSSCMSEncryptedData *encd);
  785. /*
  786. * NSS_CMSEncryptedData_Encode_BeforeData - set up encryption
  787. */
  788. extern SECStatus
  789. NSS_CMSEncryptedData_Encode_BeforeData(NSSCMSEncryptedData *encd);
  790. /*
  791. * NSS_CMSEncryptedData_Encode_AfterData - finalize this encryptedData for encoding
  792. */
  793. extern SECStatus
  794. NSS_CMSEncryptedData_Encode_AfterData(NSSCMSEncryptedData *encd);
  795. /*
  796. * NSS_CMSEncryptedData_Decode_BeforeData - find bulk key & set up decryption
  797. */
  798. extern SECStatus
  799. NSS_CMSEncryptedData_Decode_BeforeData(NSSCMSEncryptedData *encd);
  800. /*
  801. * NSS_CMSEncryptedData_Decode_AfterData - finish decrypting this encryptedData's content
  802. */
  803. extern SECStatus
  804. NSS_CMSEncryptedData_Decode_AfterData(NSSCMSEncryptedData *encd);
  805. /*
  806. * NSS_CMSEncryptedData_Decode_AfterEnd - finish decoding this encryptedData
  807. */
  808. extern SECStatus
  809. NSS_CMSEncryptedData_Decode_AfterEnd(NSSCMSEncryptedData *encd);
  810. /************************************************************************
  811. * cmsdigdata.c - CMS encryptedData methods
  812. ************************************************************************/
  813. /*
  814. * NSS_CMSDigestedData_Create - create a digestedData object (presumably for encoding)
  815. *
  816. * version will be set by NSS_CMSDigestedData_Encode_BeforeStart
  817. * digestAlg is passed as parameter
  818. * contentInfo must be filled by the user
  819. * digest will be calculated while encoding
  820. */
  821. extern NSSCMSDigestedData *
  822. NSS_CMSDigestedData_Create(NSSCMSMessage *cmsg, SECAlgorithmID *digestalg);
  823. /*
  824. * NSS_CMSDigestedData_Destroy - destroy a digestedData object
  825. */
  826. extern void
  827. NSS_CMSDigestedData_Destroy(NSSCMSDigestedData *digd);
  828. /*
  829. * NSS_CMSDigestedData_GetContentInfo - return pointer to digestedData object's contentInfo
  830. */
  831. extern NSSCMSContentInfo *
  832. NSS_CMSDigestedData_GetContentInfo(NSSCMSDigestedData *digd);
  833. /*
  834. * NSS_CMSDigestedData_Encode_BeforeStart - do all the necessary things to a DigestedData
  835. * before encoding begins.
  836. *
  837. * In particular:
  838. * - set the right version number. The contentInfo's content type must be set up already.
  839. */
  840. extern SECStatus
  841. NSS_CMSDigestedData_Encode_BeforeStart(NSSCMSDigestedData *digd);
  842. /*
  843. * NSS_CMSDigestedData_Encode_BeforeData - do all the necessary things to a DigestedData
  844. * before the encapsulated data is passed through the encoder.
  845. *
  846. * In detail:
  847. * - set up the digests if necessary
  848. */
  849. extern SECStatus
  850. NSS_CMSDigestedData_Encode_BeforeData(NSSCMSDigestedData *digd);
  851. /*
  852. * NSS_CMSDigestedData_Encode_AfterData - do all the necessary things to a DigestedData
  853. * after all the encapsulated data was passed through the encoder.
  854. *
  855. * In detail:
  856. * - finish the digests
  857. */
  858. extern SECStatus
  859. NSS_CMSDigestedData_Encode_AfterData(NSSCMSDigestedData *digd);
  860. /*
  861. * NSS_CMSDigestedData_Decode_BeforeData - do all the necessary things to a DigestedData
  862. * before the encapsulated data is passed through the encoder.
  863. *
  864. * In detail:
  865. * - set up the digests if necessary
  866. */
  867. extern SECStatus
  868. NSS_CMSDigestedData_Decode_BeforeData(NSSCMSDigestedData *digd);
  869. /*
  870. * NSS_CMSDigestedData_Decode_AfterData - do all the necessary things to a DigestedData
  871. * after all the encapsulated data was passed through the encoder.
  872. *
  873. * In detail:
  874. * - finish the digests
  875. */
  876. extern SECStatus
  877. NSS_CMSDigestedData_Decode_AfterData(NSSCMSDigestedData *digd);
  878. /*
  879. * NSS_CMSDigestedData_Decode_AfterEnd - finalize a digestedData.
  880. *
  881. * In detail:
  882. * - check the digests for equality
  883. */
  884. extern SECStatus
  885. NSS_CMSDigestedData_Decode_AfterEnd(NSSCMSDigestedData *digd);
  886. /************************************************************************
  887. * cmsdigest.c - digestion routines
  888. ************************************************************************/
  889. /*
  890. * NSS_CMSDigestContext_StartMultiple - start digest calculation using all the
  891. * digest algorithms in "digestalgs" in parallel.
  892. */
  893. extern NSSCMSDigestContext *
  894. NSS_CMSDigestContext_StartMultiple(SECAlgorithmID **digestalgs);
  895. /*
  896. * NSS_CMSDigestContext_StartSingle - same as NSS_CMSDigestContext_StartMultiple, but
  897. * only one algorithm.
  898. */
  899. extern NSSCMSDigestContext *
  900. NSS_CMSDigestContext_StartSingle(SECAlgorithmID *digestalg);
  901. /*
  902. * NSS_CMSDigestContext_Update - feed more data into the digest machine
  903. */
  904. extern void
  905. NSS_CMSDigestContext_Update(NSSCMSDigestContext *cmsdigcx, const unsigned char *data, int len);
  906. /*
  907. * NSS_CMSDigestContext_Cancel - cancel digesting operation
  908. */
  909. extern void
  910. NSS_CMSDigestContext_Cancel(NSSCMSDigestContext *cmsdigcx);
  911. /*
  912. * NSS_CMSDigestContext_FinishMultiple - finish the digests and put them
  913. * into an array of SECItems (allocated on poolp)
  914. */
  915. extern SECStatus
  916. NSS_CMSDigestContext_FinishMultiple(NSSCMSDigestContext *cmsdigcx, PLArenaPool *poolp,
  917. SECItem ***digestsp);
  918. /*
  919. * NSS_CMSDigestContext_FinishSingle - same as NSS_CMSDigestContext_FinishMultiple,
  920. * but for one digest.
  921. */
  922. extern SECStatus
  923. NSS_CMSDigestContext_FinishSingle(NSSCMSDigestContext *cmsdigcx, PLArenaPool *poolp,
  924. SECItem *digest);
  925. /************************************************************************
  926. *
  927. ************************************************************************/
  928. /* shortcuts for basic use */
  929. /*
  930. * NSS_CMSDEREncode - DER Encode a CMS message, with input being
  931. * the plaintext message and derOut being the output,
  932. * stored in arena's pool.
  933. */
  934. extern SECStatus
  935. NSS_CMSDEREncode(NSSCMSMessage *cmsg, SECItem *input, SECItem *derOut,
  936. PLArenaPool *arena);
  937. /************************************************************************
  938. *
  939. ************************************************************************/
  940. /*
  941. * define new S/MIME content type entries
  942. *
  943. * S/MIME uses the builtin PKCS7 oid types for encoding and decoding the
  944. * various S/MIME content. Some applications have their own content type
  945. * which is different from the standard content type defined by S/MIME.
  946. *
  947. * This function allows you to register new content types. There are basically
  948. * Two different types of content, Wrappping content, and Data.
  949. *
  950. * For data types, All the functions below can be zero or NULL excext
  951. * type and is isData, which should be your oid tag and PR_FALSE respectively
  952. *
  953. * For wrapping types, everything must be provided, or you will get encoder
  954. * failures.
  955. *
  956. * If NSS doesn't already define the OID that you need, you can register
  957. * your own with SECOID_AddEntry.
  958. *
  959. * Once you have defined your new content type, you can pass your new content
  960. * type to NSS_CMSContentInfo_SetContent().
  961. *
  962. * If you are using a wrapping type you can pass your own data structure in
  963. * the ptr field, but it must contain and embedded NSSCMSGenericWrappingData
  964. * structure as the first element. The size you pass to
  965. * NSS_CMSType_RegisterContentType is the total size of your self defined
  966. * data structure. NSS_CMSContentInfo_GetContent will return that data
  967. * structure from the content info. Your ASN1Template will be evaluated
  968. * against that data structure.
  969. */
  970. SECStatus NSS_CMSType_RegisterContentType(SECOidTag type,
  971. SEC_ASN1Template *asn1Template, size_t size,
  972. NSSCMSGenericWrapperDataDestroy destroy,
  973. NSSCMSGenericWrapperDataCallback decode_before,
  974. NSSCMSGenericWrapperDataCallback decode_after,
  975. NSSCMSGenericWrapperDataCallback decode_end,
  976. NSSCMSGenericWrapperDataCallback encode_start,
  977. NSSCMSGenericWrapperDataCallback encode_before,
  978. NSSCMSGenericWrapperDataCallback encode_after,
  979. PRBool isData);
  980. /************************************************************************/
  981. SEC_END_PROTOS
  982. #endif /* _CMS_H_ */