Eneboo - Documentación para desarrolladores
src/libdigidoc/openssl/crypto/cms/cms_lcl.h
Ir a la documentación de este archivo.
00001 /* crypto/cms/cms_lcl.h */
00002 /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
00003  * project.
00004  */
00005 /* ====================================================================
00006  * Copyright (c) 2008 The OpenSSL Project.  All rights reserved.
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted provided that the following conditions
00010  * are met:
00011  *
00012  * 1. Redistributions of source code must retain the above copyright
00013  *    notice, this list of conditions and the following disclaimer. 
00014  *
00015  * 2. Redistributions in binary form must reproduce the above copyright
00016  *    notice, this list of conditions and the following disclaimer in
00017  *    the documentation and/or other materials provided with the
00018  *    distribution.
00019  *
00020  * 3. All advertising materials mentioning features or use of this
00021  *    software must display the following acknowledgment:
00022  *    "This product includes software developed by the OpenSSL Project
00023  *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
00024  *
00025  * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
00026  *    endorse or promote products derived from this software without
00027  *    prior written permission. For written permission, please contact
00028  *    licensing@OpenSSL.org.
00029  *
00030  * 5. Products derived from this software may not be called "OpenSSL"
00031  *    nor may "OpenSSL" appear in their names without prior written
00032  *    permission of the OpenSSL Project.
00033  *
00034  * 6. Redistributions of any form whatsoever must retain the following
00035  *    acknowledgment:
00036  *    "This product includes software developed by the OpenSSL Project
00037  *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
00038  *
00039  * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
00040  * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00041  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00042  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
00043  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00044  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00045  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00046  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00047  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
00048  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00049  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
00050  * OF THE POSSIBILITY OF SUCH DAMAGE.
00051  * ====================================================================
00052  */
00053 
00054 #ifndef HEADER_CMS_LCL_H
00055 #define HEADER_CMS_LCL_H
00056 
00057 #ifdef __cplusplus
00058 extern "C" {
00059 #endif
00060 
00061 #include <openssl/x509.h>
00062 
00063 /* Cryptographic message syntax (CMS) structures: taken
00064  * from RFC3852
00065  */
00066 
00067 /* Forward references */
00068 
00069 typedef struct CMS_IssuerAndSerialNumber_st CMS_IssuerAndSerialNumber;
00070 typedef struct CMS_EncapsulatedContentInfo_st CMS_EncapsulatedContentInfo;
00071 typedef struct CMS_SignerIdentifier_st CMS_SignerIdentifier;
00072 typedef struct CMS_SignedData_st CMS_SignedData;
00073 typedef struct CMS_OtherRevocationInfoFormat_st CMS_OtherRevocationInfoFormat;
00074 typedef struct CMS_OriginatorInfo_st CMS_OriginatorInfo;
00075 typedef struct CMS_EncryptedContentInfo_st CMS_EncryptedContentInfo;
00076 typedef struct CMS_EnvelopedData_st CMS_EnvelopedData;
00077 typedef struct CMS_DigestedData_st CMS_DigestedData;
00078 typedef struct CMS_EncryptedData_st CMS_EncryptedData;
00079 typedef struct CMS_AuthenticatedData_st CMS_AuthenticatedData;
00080 typedef struct CMS_CompressedData_st CMS_CompressedData;
00081 typedef struct CMS_OtherCertificateFormat_st CMS_OtherCertificateFormat;
00082 typedef struct CMS_KeyTransRecipientInfo_st CMS_KeyTransRecipientInfo;
00083 typedef struct CMS_OriginatorPublicKey_st CMS_OriginatorPublicKey;
00084 typedef struct CMS_OriginatorIdentifierOrKey_st CMS_OriginatorIdentifierOrKey;
00085 typedef struct CMS_KeyAgreeRecipientInfo_st CMS_KeyAgreeRecipientInfo;
00086 typedef struct CMS_OtherKeyAttribute_st CMS_OtherKeyAttribute;
00087 typedef struct CMS_RecipientKeyIdentifier_st CMS_RecipientKeyIdentifier;
00088 typedef struct CMS_KeyAgreeRecipientIdentifier_st CMS_KeyAgreeRecipientIdentifier;
00089 typedef struct CMS_RecipientEncryptedKey_st CMS_RecipientEncryptedKey;
00090 typedef struct CMS_KEKIdentifier_st CMS_KEKIdentifier;
00091 typedef struct CMS_KEKRecipientInfo_st CMS_KEKRecipientInfo;
00092 typedef struct CMS_PasswordRecipientInfo_st CMS_PasswordRecipientInfo;
00093 typedef struct CMS_OtherRecipientInfo_st CMS_OtherRecipientInfo;
00094 typedef struct CMS_ReceiptsFrom_st CMS_ReceiptsFrom;
00095 
00096 struct CMS_ContentInfo_st
00097         {
00098         ASN1_OBJECT *contentType;
00099         union   {
00100                 ASN1_OCTET_STRING *data;
00101                 CMS_SignedData *signedData;
00102                 CMS_EnvelopedData *envelopedData;
00103                 CMS_DigestedData *digestedData;
00104                 CMS_EncryptedData *encryptedData;
00105                 CMS_AuthenticatedData *authenticatedData;
00106                 CMS_CompressedData *compressedData;
00107                 ASN1_TYPE *other;
00108                 /* Other types ... */
00109                 void *otherData;
00110                 } d;
00111         };
00112 
00113 struct CMS_SignedData_st
00114         {
00115         long version;
00116         STACK_OF(X509_ALGOR) *digestAlgorithms;
00117         CMS_EncapsulatedContentInfo *encapContentInfo;
00118         STACK_OF(CMS_CertificateChoices) *certificates;
00119         STACK_OF(CMS_RevocationInfoChoice) *crls;
00120         STACK_OF(CMS_SignerInfo) *signerInfos;
00121         };
00122  
00123 struct CMS_EncapsulatedContentInfo_st
00124         {
00125         ASN1_OBJECT *eContentType;
00126         ASN1_OCTET_STRING *eContent;
00127         /* Set to 1 if incomplete structure only part set up */
00128         int partial;
00129         };
00130 
00131 struct CMS_SignerInfo_st
00132         {
00133         long version;
00134         CMS_SignerIdentifier *sid;
00135         X509_ALGOR *digestAlgorithm;
00136         STACK_OF(X509_ATTRIBUTE) *signedAttrs;
00137         X509_ALGOR *signatureAlgorithm;
00138         ASN1_OCTET_STRING *signature;
00139         STACK_OF(X509_ATTRIBUTE) *unsignedAttrs;
00140         /* Signing certificate and key */
00141         X509 *signer;
00142         EVP_PKEY *pkey;
00143         };
00144 
00145 struct CMS_SignerIdentifier_st
00146         {
00147         int type;
00148         union   {
00149                 CMS_IssuerAndSerialNumber *issuerAndSerialNumber;
00150                 ASN1_OCTET_STRING *subjectKeyIdentifier;
00151                 } d;
00152         };
00153 
00154 struct CMS_EnvelopedData_st
00155         {
00156         long version;
00157         CMS_OriginatorInfo *originatorInfo;
00158         STACK_OF(CMS_RecipientInfo) *recipientInfos;
00159         CMS_EncryptedContentInfo *encryptedContentInfo;
00160         STACK_OF(X509_ATTRIBUTE) *unprotectedAttrs;
00161         };
00162 
00163 struct CMS_OriginatorInfo_st
00164         {
00165         STACK_OF(CMS_CertificateChoices) *certificates;
00166         STACK_OF(CMS_RevocationInfoChoice) *crls;
00167         };
00168 
00169 struct CMS_EncryptedContentInfo_st
00170         {
00171         ASN1_OBJECT *contentType;
00172         X509_ALGOR *contentEncryptionAlgorithm;
00173         ASN1_OCTET_STRING *encryptedContent;
00174         /* Content encryption algorithm and key */
00175         const EVP_CIPHER *cipher;
00176         unsigned char *key;
00177         size_t keylen;
00178         };
00179 
00180 struct CMS_RecipientInfo_st
00181         {
00182         int type;
00183         union   {
00184                 CMS_KeyTransRecipientInfo *ktri;
00185                 CMS_KeyAgreeRecipientInfo *kari;
00186                 CMS_KEKRecipientInfo *kekri;
00187                 CMS_PasswordRecipientInfo *pwri;
00188                 CMS_OtherRecipientInfo *ori;
00189                 } d;
00190         };
00191 
00192 typedef CMS_SignerIdentifier CMS_RecipientIdentifier;
00193 
00194 struct CMS_KeyTransRecipientInfo_st
00195         {
00196         long version;
00197         CMS_RecipientIdentifier *rid;
00198         X509_ALGOR *keyEncryptionAlgorithm;
00199         ASN1_OCTET_STRING *encryptedKey;
00200         /* Recipient Key and cert */
00201         X509 *recip;
00202         EVP_PKEY *pkey;
00203         };
00204 
00205 struct CMS_KeyAgreeRecipientInfo_st
00206         {
00207         long version;
00208         CMS_OriginatorIdentifierOrKey *originator;
00209         ASN1_OCTET_STRING *ukm;
00210         X509_ALGOR *keyEncryptionAlgorithm;
00211         STACK_OF(CMS_RecipientEncryptedKey) *recipientEncryptedKeys;
00212         };
00213 
00214 struct CMS_OriginatorIdentifierOrKey_st
00215         {
00216         int type;
00217         union   {
00218                 CMS_IssuerAndSerialNumber *issuerAndSerialNumber;
00219                 ASN1_OCTET_STRING *subjectKeyIdentifier;
00220                 CMS_OriginatorPublicKey *originatorKey;
00221                 } d;
00222         };
00223 
00224 struct CMS_OriginatorPublicKey_st
00225         {
00226         X509_ALGOR *algorithm;
00227         ASN1_BIT_STRING *publicKey;
00228         };
00229 
00230 struct CMS_RecipientEncryptedKey_st
00231         {
00232         CMS_KeyAgreeRecipientIdentifier *rid;
00233         ASN1_OCTET_STRING *encryptedKey;
00234         };
00235 
00236 struct CMS_KeyAgreeRecipientIdentifier_st
00237         {
00238         int type;
00239         union   {
00240                 CMS_IssuerAndSerialNumber *issuerAndSerialNumber;
00241                 CMS_RecipientKeyIdentifier *rKeyId;
00242                 } d;
00243         };
00244 
00245 struct CMS_RecipientKeyIdentifier_st
00246         {
00247         ASN1_OCTET_STRING *subjectKeyIdentifier;
00248         ASN1_GENERALIZEDTIME *date;
00249         CMS_OtherKeyAttribute *other;
00250         };
00251 
00252 struct CMS_KEKRecipientInfo_st
00253         {
00254         long version;
00255         CMS_KEKIdentifier *kekid;
00256         X509_ALGOR *keyEncryptionAlgorithm;
00257         ASN1_OCTET_STRING *encryptedKey;
00258         /* Extra info: symmetric key to use */
00259         unsigned char *key;
00260         size_t keylen;
00261         };
00262 
00263 struct CMS_KEKIdentifier_st
00264         {
00265         ASN1_OCTET_STRING *keyIdentifier;
00266         ASN1_GENERALIZEDTIME *date;
00267         CMS_OtherKeyAttribute *other;
00268         };
00269 
00270 struct CMS_PasswordRecipientInfo_st
00271         {
00272         long version;
00273         X509_ALGOR *keyDerivationAlgorithm;
00274         X509_ALGOR *keyEncryptionAlgorithm;
00275         ASN1_OCTET_STRING *encryptedKey;
00276         };
00277 
00278 struct CMS_OtherRecipientInfo_st
00279         {
00280         ASN1_OBJECT *oriType;
00281         ASN1_TYPE *oriValue;
00282         };
00283 
00284 struct CMS_DigestedData_st
00285         {
00286         long version;
00287         X509_ALGOR *digestAlgorithm;
00288         CMS_EncapsulatedContentInfo *encapContentInfo;
00289         ASN1_OCTET_STRING *digest;
00290         };
00291 
00292 struct CMS_EncryptedData_st
00293         {
00294         long version;
00295         CMS_EncryptedContentInfo *encryptedContentInfo;
00296         STACK_OF(X509_ATTRIBUTE) *unprotectedAttrs;
00297         };
00298 
00299 struct CMS_AuthenticatedData_st
00300         {
00301         long version;
00302         CMS_OriginatorInfo *originatorInfo;
00303         STACK_OF(CMS_RecipientInfo) *recipientInfos;
00304         X509_ALGOR *macAlgorithm;
00305         X509_ALGOR *digestAlgorithm;
00306         CMS_EncapsulatedContentInfo *encapContentInfo;
00307         STACK_OF(X509_ATTRIBUTE) *authAttrs;
00308         ASN1_OCTET_STRING *mac;
00309         STACK_OF(X509_ATTRIBUTE) *unauthAttrs;
00310         };
00311 
00312 struct CMS_CompressedData_st
00313         {
00314         long version;
00315         X509_ALGOR *compressionAlgorithm;
00316         STACK_OF(CMS_RecipientInfo) *recipientInfos;
00317         CMS_EncapsulatedContentInfo *encapContentInfo;
00318         };
00319 
00320 struct CMS_RevocationInfoChoice_st
00321         {
00322         int type;
00323         union   {
00324                 X509_CRL *crl;
00325                 CMS_OtherRevocationInfoFormat *other;
00326                 } d;
00327         };
00328 
00329 #define CMS_REVCHOICE_CRL               0
00330 #define CMS_REVCHOICE_OTHER             1
00331 
00332 struct CMS_OtherRevocationInfoFormat_st
00333         {
00334         ASN1_OBJECT *otherRevInfoFormat;
00335         ASN1_TYPE *otherRevInfo;
00336         };
00337 
00338 struct CMS_CertificateChoices
00339         {
00340         int type;
00341                 union {
00342                 X509 *certificate;
00343                 ASN1_STRING *extendedCertificate;       /* Obsolete */
00344                 ASN1_STRING *v1AttrCert;        /* Left encoded for now */
00345                 ASN1_STRING *v2AttrCert;        /* Left encoded for now */
00346                 CMS_OtherCertificateFormat *other;
00347                 } d;
00348         };
00349 
00350 #define CMS_CERTCHOICE_CERT             0
00351 #define CMS_CERTCHOICE_EXCERT           1
00352 #define CMS_CERTCHOICE_V1ACERT          2
00353 #define CMS_CERTCHOICE_V2ACERT          3
00354 #define CMS_CERTCHOICE_OTHER            4
00355 
00356 struct CMS_OtherCertificateFormat_st
00357         {
00358         ASN1_OBJECT *otherCertFormat;
00359         ASN1_TYPE *otherCert;
00360         };
00361 
00362 /* This is also defined in pkcs7.h but we duplicate it
00363  * to allow the CMS code to be independent of PKCS#7
00364  */
00365 
00366 struct CMS_IssuerAndSerialNumber_st
00367         {
00368         X509_NAME *issuer;
00369         ASN1_INTEGER *serialNumber;
00370         };
00371 
00372 struct CMS_OtherKeyAttribute_st
00373         {
00374         ASN1_OBJECT *keyAttrId;
00375         ASN1_TYPE *keyAttr;
00376         };
00377 
00378 /* ESS structures */
00379 
00380 #ifdef HEADER_X509V3_H
00381 
00382 struct CMS_ReceiptRequest_st
00383         {
00384         ASN1_OCTET_STRING *signedContentIdentifier;
00385         CMS_ReceiptsFrom *receiptsFrom;
00386         STACK_OF(GENERAL_NAMES) *receiptsTo;
00387         };
00388 
00389 
00390 struct CMS_ReceiptsFrom_st
00391         {
00392         int type;
00393         union
00394                 {
00395                 long allOrFirstTier;
00396                 STACK_OF(GENERAL_NAMES) *receiptList;
00397                 } d;
00398         };
00399 #endif
00400 
00401 struct CMS_Receipt_st
00402         {
00403         long version;
00404         ASN1_OBJECT *contentType;
00405         ASN1_OCTET_STRING *signedContentIdentifier;
00406         ASN1_OCTET_STRING *originatorSignatureValue;
00407         };
00408 
00409 DECLARE_ASN1_ITEM(CMS_SignerInfo)
00410 DECLARE_ASN1_ITEM(CMS_IssuerAndSerialNumber)
00411 DECLARE_ASN1_ITEM(CMS_Attributes_Sign)
00412 DECLARE_ASN1_ITEM(CMS_Attributes_Verify)
00413 DECLARE_ASN1_ALLOC_FUNCTIONS(CMS_IssuerAndSerialNumber)
00414 
00415 #define CMS_SIGNERINFO_ISSUER_SERIAL    0
00416 #define CMS_SIGNERINFO_KEYIDENTIFIER    1
00417 
00418 #define CMS_RECIPINFO_ISSUER_SERIAL     0
00419 #define CMS_RECIPINFO_KEYIDENTIFIER     1
00420 
00421 BIO *cms_content_bio(CMS_ContentInfo *cms);
00422 
00423 CMS_ContentInfo *cms_Data_create(void);
00424 
00425 CMS_ContentInfo *cms_DigestedData_create(const EVP_MD *md);
00426 BIO *cms_DigestedData_init_bio(CMS_ContentInfo *cms);
00427 int cms_DigestedData_do_final(CMS_ContentInfo *cms, BIO *chain, int verify);
00428 
00429 BIO *cms_SignedData_init_bio(CMS_ContentInfo *cms);
00430 int cms_SignedData_final(CMS_ContentInfo *cms, BIO *chain);
00431 int cms_set1_SignerIdentifier(CMS_SignerIdentifier *sid, X509 *cert, int type);
00432 int cms_SignerIdentifier_get0_signer_id(CMS_SignerIdentifier *sid,
00433                                         ASN1_OCTET_STRING **keyid,
00434                                         X509_NAME **issuer, ASN1_INTEGER **sno);
00435 int cms_SignerIdentifier_cert_cmp(CMS_SignerIdentifier *sid, X509 *cert);
00436 
00437 CMS_ContentInfo *cms_CompressedData_create(int comp_nid);
00438 BIO *cms_CompressedData_init_bio(CMS_ContentInfo *cms);
00439 
00440 void cms_DigestAlgorithm_set(X509_ALGOR *alg, const EVP_MD *md);
00441 BIO *cms_DigestAlgorithm_init_bio(X509_ALGOR *digestAlgorithm);
00442 int cms_DigestAlgorithm_find_ctx(EVP_MD_CTX *mctx, BIO *chain,
00443                                         X509_ALGOR *mdalg);
00444 
00445 BIO *cms_EncryptedContent_init_bio(CMS_EncryptedContentInfo *ec);
00446 BIO *cms_EncryptedData_init_bio(CMS_ContentInfo *cms);
00447 int cms_EncryptedContent_init(CMS_EncryptedContentInfo *ec, 
00448                                 const EVP_CIPHER *cipher,
00449                                 const unsigned char *key, size_t keylen);
00450 
00451 int cms_Receipt_verify(CMS_ContentInfo *cms, CMS_ContentInfo *req_cms);
00452 int cms_msgSigDigest_add1(CMS_SignerInfo *dest, CMS_SignerInfo *src);
00453 ASN1_OCTET_STRING *cms_encode_Receipt(CMS_SignerInfo *si);
00454 
00455 BIO *cms_EnvelopedData_init_bio(CMS_ContentInfo *cms);
00456         
00457 #ifdef  __cplusplus
00458 }
00459 #endif
00460 #endif
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'