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