00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059 #ifndef HEADER_PKCS7_H
00060 #define HEADER_PKCS7_H
00061
00062 #include <openssl/asn1.h>
00063 #include <openssl/bio.h>
00064 #include <openssl/e_os2.h>
00065
00066 #include <openssl/symhacks.h>
00067 #include <openssl/ossl_typ.h>
00068
00069 #ifdef __cplusplus
00070 extern "C" {
00071 #endif
00072
00073 #ifdef OPENSSL_SYS_WIN32
00074
00075 #undef PKCS7_ISSUER_AND_SERIAL
00076 #undef PKCS7_SIGNER_INFO
00077 #endif
00078
00079
00080
00081
00082
00083
00084
00085
00086 typedef struct pkcs7_issuer_and_serial_st
00087 {
00088 X509_NAME *issuer;
00089 ASN1_INTEGER *serial;
00090 } PKCS7_ISSUER_AND_SERIAL;
00091
00092 typedef struct pkcs7_signer_info_st
00093 {
00094 ASN1_INTEGER *version;
00095 PKCS7_ISSUER_AND_SERIAL *issuer_and_serial;
00096 X509_ALGOR *digest_alg;
00097 STACK_OF(X509_ATTRIBUTE) *auth_attr;
00098 X509_ALGOR *digest_enc_alg;
00099 ASN1_OCTET_STRING *enc_digest;
00100 STACK_OF(X509_ATTRIBUTE) *unauth_attr;
00101
00102
00103 EVP_PKEY *pkey;
00104 } PKCS7_SIGNER_INFO;
00105
00106 DECLARE_STACK_OF(PKCS7_SIGNER_INFO)
00107 DECLARE_ASN1_SET_OF(PKCS7_SIGNER_INFO)
00108
00109 typedef struct pkcs7_recip_info_st
00110 {
00111 ASN1_INTEGER *version;
00112 PKCS7_ISSUER_AND_SERIAL *issuer_and_serial;
00113 X509_ALGOR *key_enc_algor;
00114 ASN1_OCTET_STRING *enc_key;
00115 X509 *cert;
00116 } PKCS7_RECIP_INFO;
00117
00118 DECLARE_STACK_OF(PKCS7_RECIP_INFO)
00119 DECLARE_ASN1_SET_OF(PKCS7_RECIP_INFO)
00120
00121 typedef struct pkcs7_signed_st
00122 {
00123 ASN1_INTEGER *version;
00124 STACK_OF(X509_ALGOR) *md_algs;
00125 STACK_OF(X509) *cert;
00126 STACK_OF(X509_CRL) *crl;
00127 STACK_OF(PKCS7_SIGNER_INFO) *signer_info;
00128
00129 struct pkcs7_st *contents;
00130 } PKCS7_SIGNED;
00131
00132
00133
00134 typedef struct pkcs7_enc_content_st
00135 {
00136 ASN1_OBJECT *content_type;
00137 X509_ALGOR *algorithm;
00138 ASN1_OCTET_STRING *enc_data;
00139 const EVP_CIPHER *cipher;
00140 } PKCS7_ENC_CONTENT;
00141
00142 typedef struct pkcs7_enveloped_st
00143 {
00144 ASN1_INTEGER *version;
00145 STACK_OF(PKCS7_RECIP_INFO) *recipientinfo;
00146 PKCS7_ENC_CONTENT *enc_data;
00147 } PKCS7_ENVELOPE;
00148
00149 typedef struct pkcs7_signedandenveloped_st
00150 {
00151 ASN1_INTEGER *version;
00152 STACK_OF(X509_ALGOR) *md_algs;
00153 STACK_OF(X509) *cert;
00154 STACK_OF(X509_CRL) *crl;
00155 STACK_OF(PKCS7_SIGNER_INFO) *signer_info;
00156
00157 PKCS7_ENC_CONTENT *enc_data;
00158 STACK_OF(PKCS7_RECIP_INFO) *recipientinfo;
00159 } PKCS7_SIGN_ENVELOPE;
00160
00161 typedef struct pkcs7_digest_st
00162 {
00163 ASN1_INTEGER *version;
00164 X509_ALGOR *md;
00165 struct pkcs7_st *contents;
00166 ASN1_OCTET_STRING *digest;
00167 } PKCS7_DIGEST;
00168
00169 typedef struct pkcs7_encrypted_st
00170 {
00171 ASN1_INTEGER *version;
00172 PKCS7_ENC_CONTENT *enc_data;
00173 } PKCS7_ENCRYPT;
00174
00175 typedef struct pkcs7_st
00176 {
00177
00178
00179 unsigned char *asn1;
00180 long length;
00181
00182 #define PKCS7_S_HEADER 0
00183 #define PKCS7_S_BODY 1
00184 #define PKCS7_S_TAIL 2
00185 int state;
00186
00187 int detached;
00188
00189 ASN1_OBJECT *type;
00190
00191
00192
00193 union {
00194 char *ptr;
00195
00196
00197 ASN1_OCTET_STRING *data;
00198
00199
00200 PKCS7_SIGNED *sign;
00201
00202
00203 PKCS7_ENVELOPE *enveloped;
00204
00205
00206 PKCS7_SIGN_ENVELOPE *signed_and_enveloped;
00207
00208
00209 PKCS7_DIGEST *digest;
00210
00211
00212 PKCS7_ENCRYPT *encrypted;
00213
00214
00215 ASN1_TYPE *other;
00216 } d;
00217 } PKCS7;
00218
00219 DECLARE_STACK_OF(PKCS7)
00220 DECLARE_ASN1_SET_OF(PKCS7)
00221 DECLARE_PKCS12_STACK_OF(PKCS7)
00222
00223 #define PKCS7_OP_SET_DETACHED_SIGNATURE 1
00224 #define PKCS7_OP_GET_DETACHED_SIGNATURE 2
00225
00226 #define PKCS7_get_signed_attributes(si) ((si)->auth_attr)
00227 #define PKCS7_get_attributes(si) ((si)->unauth_attr)
00228
00229 #define PKCS7_type_is_signed(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_signed)
00230 #define PKCS7_type_is_encrypted(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_encrypted)
00231 #define PKCS7_type_is_enveloped(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_enveloped)
00232 #define PKCS7_type_is_signedAndEnveloped(a) \
00233 (OBJ_obj2nid((a)->type) == NID_pkcs7_signedAndEnveloped)
00234 #define PKCS7_type_is_data(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_data)
00235
00236 #define PKCS7_type_is_digest(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_digest)
00237
00238 #define PKCS7_set_detached(p,v) \
00239 PKCS7_ctrl(p,PKCS7_OP_SET_DETACHED_SIGNATURE,v,NULL)
00240 #define PKCS7_get_detached(p) \
00241 PKCS7_ctrl(p,PKCS7_OP_GET_DETACHED_SIGNATURE,0,NULL)
00242
00243 #define PKCS7_is_detached(p7) (PKCS7_type_is_signed(p7) && PKCS7_get_detached(p7))
00244
00245 #ifdef SSLEAY_MACROS
00246 #ifndef PKCS7_ISSUER_AND_SERIAL_digest
00247 #define PKCS7_ISSUER_AND_SERIAL_digest(data,type,md,len) \
00248 ASN1_digest((int (*)())i2d_PKCS7_ISSUER_AND_SERIAL,type,\
00249 (char *)data,md,len)
00250 #endif
00251 #endif
00252
00253
00254
00255 #define PKCS7_TEXT 0x1
00256 #define PKCS7_NOCERTS 0x2
00257 #define PKCS7_NOSIGS 0x4
00258 #define PKCS7_NOCHAIN 0x8
00259 #define PKCS7_NOINTERN 0x10
00260 #define PKCS7_NOVERIFY 0x20
00261 #define PKCS7_DETACHED 0x40
00262 #define PKCS7_BINARY 0x80
00263 #define PKCS7_NOATTR 0x100
00264 #define PKCS7_NOSMIMECAP 0x200
00265 #define PKCS7_NOOLDMIMETYPE 0x400
00266 #define PKCS7_CRLFEOL 0x800
00267 #define PKCS7_STREAM 0x1000
00268 #define PKCS7_NOCRL 0x2000
00269
00270
00271
00272 #define SMIME_TEXT PKCS7_TEXT
00273 #define SMIME_NOCERTS PKCS7_NOCERTS
00274 #define SMIME_NOSIGS PKCS7_NOSIGS
00275 #define SMIME_NOCHAIN PKCS7_NOCHAIN
00276 #define SMIME_NOINTERN PKCS7_NOINTERN
00277 #define SMIME_NOVERIFY PKCS7_NOVERIFY
00278 #define SMIME_DETACHED PKCS7_DETACHED
00279 #define SMIME_BINARY PKCS7_BINARY
00280 #define SMIME_NOATTR PKCS7_NOATTR
00281
00282 DECLARE_ASN1_FUNCTIONS(PKCS7_ISSUER_AND_SERIAL)
00283
00284 #ifndef SSLEAY_MACROS
00285 int PKCS7_ISSUER_AND_SERIAL_digest(PKCS7_ISSUER_AND_SERIAL *data,const EVP_MD *type,
00286 unsigned char *md,unsigned int *len);
00287 #ifndef OPENSSL_NO_FP_API
00288 PKCS7 *d2i_PKCS7_fp(FILE *fp,PKCS7 **p7);
00289 int i2d_PKCS7_fp(FILE *fp,PKCS7 *p7);
00290 #endif
00291 PKCS7 *PKCS7_dup(PKCS7 *p7);
00292 PKCS7 *d2i_PKCS7_bio(BIO *bp,PKCS7 **p7);
00293 int i2d_PKCS7_bio(BIO *bp,PKCS7 *p7);
00294 #endif
00295
00296 DECLARE_ASN1_FUNCTIONS(PKCS7_SIGNER_INFO)
00297 DECLARE_ASN1_FUNCTIONS(PKCS7_RECIP_INFO)
00298 DECLARE_ASN1_FUNCTIONS(PKCS7_SIGNED)
00299 DECLARE_ASN1_FUNCTIONS(PKCS7_ENC_CONTENT)
00300 DECLARE_ASN1_FUNCTIONS(PKCS7_ENVELOPE)
00301 DECLARE_ASN1_FUNCTIONS(PKCS7_SIGN_ENVELOPE)
00302 DECLARE_ASN1_FUNCTIONS(PKCS7_DIGEST)
00303 DECLARE_ASN1_FUNCTIONS(PKCS7_ENCRYPT)
00304 DECLARE_ASN1_FUNCTIONS(PKCS7)
00305
00306 DECLARE_ASN1_ITEM(PKCS7_ATTR_SIGN)
00307 DECLARE_ASN1_ITEM(PKCS7_ATTR_VERIFY)
00308
00309 DECLARE_ASN1_NDEF_FUNCTION(PKCS7)
00310
00311 long PKCS7_ctrl(PKCS7 *p7, int cmd, long larg, char *parg);
00312
00313 int PKCS7_set_type(PKCS7 *p7, int type);
00314 int PKCS7_set0_type_other(PKCS7 *p7, int type, ASN1_TYPE *other);
00315 int PKCS7_set_content(PKCS7 *p7, PKCS7 *p7_data);
00316 int PKCS7_SIGNER_INFO_set(PKCS7_SIGNER_INFO *p7i, X509 *x509, EVP_PKEY *pkey,
00317 const EVP_MD *dgst);
00318 int PKCS7_add_signer(PKCS7 *p7, PKCS7_SIGNER_INFO *p7i);
00319 int PKCS7_add_certificate(PKCS7 *p7, X509 *x509);
00320 int PKCS7_add_crl(PKCS7 *p7, X509_CRL *x509);
00321 int PKCS7_content_new(PKCS7 *p7, int nid);
00322 int PKCS7_dataVerify(X509_STORE *cert_store, X509_STORE_CTX *ctx,
00323 BIO *bio, PKCS7 *p7, PKCS7_SIGNER_INFO *si);
00324 int PKCS7_signatureVerify(BIO *bio, PKCS7 *p7, PKCS7_SIGNER_INFO *si,
00325 X509 *x509);
00326
00327 BIO *PKCS7_dataInit(PKCS7 *p7, BIO *bio);
00328 int PKCS7_dataFinal(PKCS7 *p7, BIO *bio);
00329 BIO *PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert);
00330
00331
00332 PKCS7_SIGNER_INFO *PKCS7_add_signature(PKCS7 *p7, X509 *x509,
00333 EVP_PKEY *pkey, const EVP_MD *dgst);
00334 X509 *PKCS7_cert_from_signer_info(PKCS7 *p7, PKCS7_SIGNER_INFO *si);
00335 int PKCS7_set_digest(PKCS7 *p7, const EVP_MD *md);
00336 STACK_OF(PKCS7_SIGNER_INFO) *PKCS7_get_signer_info(PKCS7 *p7);
00337
00338 PKCS7_RECIP_INFO *PKCS7_add_recipient(PKCS7 *p7, X509 *x509);
00339 int PKCS7_add_recipient_info(PKCS7 *p7, PKCS7_RECIP_INFO *ri);
00340 int PKCS7_RECIP_INFO_set(PKCS7_RECIP_INFO *p7i, X509 *x509);
00341 int PKCS7_set_cipher(PKCS7 *p7, const EVP_CIPHER *cipher);
00342
00343 PKCS7_ISSUER_AND_SERIAL *PKCS7_get_issuer_and_serial(PKCS7 *p7, int idx);
00344 ASN1_OCTET_STRING *PKCS7_digest_from_attributes(STACK_OF(X509_ATTRIBUTE) *sk);
00345 int PKCS7_add_signed_attribute(PKCS7_SIGNER_INFO *p7si,int nid,int type,
00346 void *data);
00347 int PKCS7_add_attribute (PKCS7_SIGNER_INFO *p7si, int nid, int atrtype,
00348 void *value);
00349 ASN1_TYPE *PKCS7_get_attribute(PKCS7_SIGNER_INFO *si, int nid);
00350 ASN1_TYPE *PKCS7_get_signed_attribute(PKCS7_SIGNER_INFO *si, int nid);
00351 int PKCS7_set_signed_attributes(PKCS7_SIGNER_INFO *p7si,
00352 STACK_OF(X509_ATTRIBUTE) *sk);
00353 int PKCS7_set_attributes(PKCS7_SIGNER_INFO *p7si,STACK_OF(X509_ATTRIBUTE) *sk);
00354
00355
00356 PKCS7 *PKCS7_sign(X509 *signcert, EVP_PKEY *pkey, STACK_OF(X509) *certs,
00357 BIO *data, int flags);
00358 int PKCS7_verify(PKCS7 *p7, STACK_OF(X509) *certs, X509_STORE *store,
00359 BIO *indata, BIO *out, int flags);
00360 STACK_OF(X509) *PKCS7_get0_signers(PKCS7 *p7, STACK_OF(X509) *certs, int flags);
00361 PKCS7 *PKCS7_encrypt(STACK_OF(X509) *certs, BIO *in, const EVP_CIPHER *cipher,
00362 int flags);
00363 int PKCS7_decrypt(PKCS7 *p7, EVP_PKEY *pkey, X509 *cert, BIO *data, int flags);
00364
00365 int PKCS7_add_attrib_smimecap(PKCS7_SIGNER_INFO *si,
00366 STACK_OF(X509_ALGOR) *cap);
00367 STACK_OF(X509_ALGOR) *PKCS7_get_smimecap(PKCS7_SIGNER_INFO *si);
00368 int PKCS7_simple_smimecap(STACK_OF(X509_ALGOR) *sk, int nid, int arg);
00369
00370 int SMIME_write_PKCS7(BIO *bio, PKCS7 *p7, BIO *data, int flags);
00371 PKCS7 *SMIME_read_PKCS7(BIO *bio, BIO **bcont);
00372 int SMIME_crlf_copy(BIO *in, BIO *out, int flags);
00373 int SMIME_text(BIO *in, BIO *out);
00374
00375
00376
00377
00378
00379 void ERR_load_PKCS7_strings(void);
00380
00381
00382
00383
00384 #define PKCS7_F_B64_READ_PKCS7 120
00385 #define PKCS7_F_B64_WRITE_PKCS7 121
00386 #define PKCS7_F_PKCS7_ADD_ATTRIB_SMIMECAP 118
00387 #define PKCS7_F_PKCS7_ADD_CERTIFICATE 100
00388 #define PKCS7_F_PKCS7_ADD_CRL 101
00389 #define PKCS7_F_PKCS7_ADD_RECIPIENT_INFO 102
00390 #define PKCS7_F_PKCS7_ADD_SIGNER 103
00391 #define PKCS7_F_PKCS7_BIO_ADD_DIGEST 125
00392 #define PKCS7_F_PKCS7_CTRL 104
00393 #define PKCS7_F_PKCS7_DATADECODE 112
00394 #define PKCS7_F_PKCS7_DATAFINAL 128
00395 #define PKCS7_F_PKCS7_DATAINIT 105
00396 #define PKCS7_F_PKCS7_DATASIGN 106
00397 #define PKCS7_F_PKCS7_DATAVERIFY 107
00398 #define PKCS7_F_PKCS7_DECRYPT 114
00399 #define PKCS7_F_PKCS7_ENCRYPT 115
00400 #define PKCS7_F_PKCS7_FIND_DIGEST 127
00401 #define PKCS7_F_PKCS7_GET0_SIGNERS 124
00402 #define PKCS7_F_PKCS7_SET_CIPHER 108
00403 #define PKCS7_F_PKCS7_SET_CONTENT 109
00404 #define PKCS7_F_PKCS7_SET_DIGEST 126
00405 #define PKCS7_F_PKCS7_SET_TYPE 110
00406 #define PKCS7_F_PKCS7_SIGN 116
00407 #define PKCS7_F_PKCS7_SIGNATUREVERIFY 113
00408 #define PKCS7_F_PKCS7_SIMPLE_SMIMECAP 119
00409 #define PKCS7_F_PKCS7_VERIFY 117
00410 #define PKCS7_F_SMIME_READ_PKCS7 122
00411 #define PKCS7_F_SMIME_TEXT 123
00412
00413
00414 #define PKCS7_R_CERTIFICATE_VERIFY_ERROR 117
00415 #define PKCS7_R_CIPHER_HAS_NO_OBJECT_IDENTIFIER 144
00416 #define PKCS7_R_CIPHER_NOT_INITIALIZED 116
00417 #define PKCS7_R_CONTENT_AND_DATA_PRESENT 118
00418 #define PKCS7_R_DECODE_ERROR 130
00419 #define PKCS7_R_DECRYPTED_KEY_IS_WRONG_LENGTH 100
00420 #define PKCS7_R_DECRYPT_ERROR 119
00421 #define PKCS7_R_DIGEST_FAILURE 101
00422 #define PKCS7_R_ERROR_ADDING_RECIPIENT 120
00423 #define PKCS7_R_ERROR_SETTING_CIPHER 121
00424 #define PKCS7_R_INVALID_MIME_TYPE 131
00425 #define PKCS7_R_INVALID_NULL_POINTER 143
00426 #define PKCS7_R_MIME_NO_CONTENT_TYPE 132
00427 #define PKCS7_R_MIME_PARSE_ERROR 133
00428 #define PKCS7_R_MIME_SIG_PARSE_ERROR 134
00429 #define PKCS7_R_MISSING_CERIPEND_INFO 103
00430 #define PKCS7_R_NO_CONTENT 122
00431 #define PKCS7_R_NO_CONTENT_TYPE 135
00432 #define PKCS7_R_NO_MULTIPART_BODY_FAILURE 136
00433 #define PKCS7_R_NO_MULTIPART_BOUNDARY 137
00434 #define PKCS7_R_NO_RECIPIENT_MATCHES_CERTIFICATE 115
00435 #define PKCS7_R_NO_RECIPIENT_MATCHES_KEY 146
00436 #define PKCS7_R_NO_SIGNATURES_ON_DATA 123
00437 #define PKCS7_R_NO_SIGNERS 142
00438 #define PKCS7_R_NO_SIG_CONTENT_TYPE 138
00439 #define PKCS7_R_OPERATION_NOT_SUPPORTED_ON_THIS_TYPE 104
00440 #define PKCS7_R_PKCS7_ADD_SIGNATURE_ERROR 124
00441 #define PKCS7_R_PKCS7_DATAFINAL 126
00442 #define PKCS7_R_PKCS7_DATAFINAL_ERROR 125
00443 #define PKCS7_R_PKCS7_DATASIGN 145
00444 #define PKCS7_R_PKCS7_PARSE_ERROR 139
00445 #define PKCS7_R_PKCS7_SIG_PARSE_ERROR 140
00446 #define PKCS7_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE 127
00447 #define PKCS7_R_SIGNATURE_FAILURE 105
00448 #define PKCS7_R_SIGNER_CERTIFICATE_NOT_FOUND 128
00449 #define PKCS7_R_SIG_INVALID_MIME_TYPE 141
00450 #define PKCS7_R_SMIME_TEXT_ERROR 129
00451 #define PKCS7_R_UNABLE_TO_FIND_CERTIFICATE 106
00452 #define PKCS7_R_UNABLE_TO_FIND_MEM_BIO 107
00453 #define PKCS7_R_UNABLE_TO_FIND_MESSAGE_DIGEST 108
00454 #define PKCS7_R_UNKNOWN_DIGEST_TYPE 109
00455 #define PKCS7_R_UNKNOWN_OPERATION 110
00456 #define PKCS7_R_UNSUPPORTED_CIPHER_TYPE 111
00457 #define PKCS7_R_UNSUPPORTED_CONTENT_TYPE 112
00458 #define PKCS7_R_WRONG_CONTENT_TYPE 113
00459 #define PKCS7_R_WRONG_PKCS7_TYPE 114
00460
00461 #ifdef __cplusplus
00462 }
00463 #endif
00464 #endif