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