1/* 2 * {- join("\n * ", @autowarntext) -} 3 * 4 * Copyright 2008-2022 The OpenSSL Project Authors. All Rights Reserved. 5 * 6 * Licensed under the Apache License 2.0 (the "License"). You may not use 7 * this file except in compliance with the License. You can obtain a copy 8 * in the file LICENSE in the source distribution or at 9 * https://www.openssl.org/source/license.html 10 */ 11 12{- 13use OpenSSL::stackhash qw(generate_stack_macros); 14-} 15 16#ifndef OPENSSL_CMS_H 17# define OPENSSL_CMS_H 18# pragma once 19 20# include <openssl/macros.h> 21# ifndef OPENSSL_NO_DEPRECATED_3_0 22# define HEADER_CMS_H 23# endif 24 25# include <openssl/opensslconf.h> 26 27# ifndef OPENSSL_NO_CMS 28# include <openssl/x509.h> 29# include <openssl/x509v3.h> 30# include <openssl/cmserr.h> 31# ifdef __cplusplus 32extern "C" { 33# endif 34 35typedef struct CMS_EnvelopedData_st CMS_EnvelopedData; 36typedef struct CMS_ContentInfo_st CMS_ContentInfo; 37typedef struct CMS_SignerInfo_st CMS_SignerInfo; 38typedef struct CMS_SignedData_st CMS_SignedData; 39typedef struct CMS_CertificateChoices CMS_CertificateChoices; 40typedef struct CMS_RevocationInfoChoice_st CMS_RevocationInfoChoice; 41typedef struct CMS_RecipientInfo_st CMS_RecipientInfo; 42typedef struct CMS_ReceiptRequest_st CMS_ReceiptRequest; 43typedef struct CMS_Receipt_st CMS_Receipt; 44typedef struct CMS_RecipientEncryptedKey_st CMS_RecipientEncryptedKey; 45typedef struct CMS_OtherKeyAttribute_st CMS_OtherKeyAttribute; 46 47{- 48 generate_stack_macros("CMS_SignerInfo") 49 .generate_stack_macros("CMS_RecipientEncryptedKey") 50 .generate_stack_macros("CMS_RecipientInfo") 51 .generate_stack_macros("CMS_RevocationInfoChoice"); 52-} 53 54DECLARE_ASN1_ITEM(CMS_EnvelopedData) 55DECLARE_ASN1_ALLOC_FUNCTIONS(CMS_SignedData) 56DECLARE_ASN1_FUNCTIONS(CMS_ContentInfo) 57DECLARE_ASN1_FUNCTIONS(CMS_ReceiptRequest) 58DECLARE_ASN1_PRINT_FUNCTION(CMS_ContentInfo) 59 60CMS_ContentInfo *CMS_ContentInfo_new_ex(OSSL_LIB_CTX *libctx, const char *propq); 61 62# define CMS_SIGNERINFO_ISSUER_SERIAL 0 63# define CMS_SIGNERINFO_KEYIDENTIFIER 1 64 65# define CMS_RECIPINFO_NONE -1 66# define CMS_RECIPINFO_TRANS 0 67# define CMS_RECIPINFO_AGREE 1 68# define CMS_RECIPINFO_KEK 2 69# define CMS_RECIPINFO_PASS 3 70# define CMS_RECIPINFO_OTHER 4 71 72/* S/MIME related flags */ 73 74# define CMS_TEXT 0x1 75# define CMS_NOCERTS 0x2 76# define CMS_NO_CONTENT_VERIFY 0x4 77# define CMS_NO_ATTR_VERIFY 0x8 78# define CMS_NOSIGS \ 79 (CMS_NO_CONTENT_VERIFY|CMS_NO_ATTR_VERIFY) 80# define CMS_NOINTERN 0x10 81# define CMS_NO_SIGNER_CERT_VERIFY 0x20 82# define CMS_NOVERIFY 0x20 83# define CMS_DETACHED 0x40 84# define CMS_BINARY 0x80 85# define CMS_NOATTR 0x100 86# define CMS_NOSMIMECAP 0x200 87# define CMS_NOOLDMIMETYPE 0x400 88# define CMS_CRLFEOL 0x800 89# define CMS_STREAM 0x1000 90# define CMS_NOCRL 0x2000 91# define CMS_PARTIAL 0x4000 92# define CMS_REUSE_DIGEST 0x8000 93# define CMS_USE_KEYID 0x10000 94# define CMS_DEBUG_DECRYPT 0x20000 95# define CMS_KEY_PARAM 0x40000 96# define CMS_ASCIICRLF 0x80000 97# define CMS_CADES 0x100000 98# define CMS_USE_ORIGINATOR_KEYID 0x200000 99 100const ASN1_OBJECT *CMS_get0_type(const CMS_ContentInfo *cms); 101 102BIO *CMS_dataInit(CMS_ContentInfo *cms, BIO *icont); 103int CMS_dataFinal(CMS_ContentInfo *cms, BIO *bio); 104 105ASN1_OCTET_STRING **CMS_get0_content(CMS_ContentInfo *cms); 106int CMS_is_detached(CMS_ContentInfo *cms); 107int CMS_set_detached(CMS_ContentInfo *cms, int detached); 108 109# ifdef OPENSSL_PEM_H 110DECLARE_PEM_rw(CMS, CMS_ContentInfo) 111# endif 112int CMS_stream(unsigned char ***boundary, CMS_ContentInfo *cms); 113CMS_ContentInfo *d2i_CMS_bio(BIO *bp, CMS_ContentInfo **cms); 114int i2d_CMS_bio(BIO *bp, CMS_ContentInfo *cms); 115 116BIO *BIO_new_CMS(BIO *out, CMS_ContentInfo *cms); 117int i2d_CMS_bio_stream(BIO *out, CMS_ContentInfo *cms, BIO *in, int flags); 118int PEM_write_bio_CMS_stream(BIO *out, CMS_ContentInfo *cms, BIO *in, 119 int flags); 120CMS_ContentInfo *SMIME_read_CMS(BIO *bio, BIO **bcont); 121CMS_ContentInfo *SMIME_read_CMS_ex(BIO *bio, int flags, BIO **bcont, CMS_ContentInfo **ci); 122int SMIME_write_CMS(BIO *bio, CMS_ContentInfo *cms, BIO *data, int flags); 123 124int CMS_final(CMS_ContentInfo *cms, BIO *data, BIO *dcont, 125 unsigned int flags); 126int CMS_final_digest(CMS_ContentInfo *cms, 127 const unsigned char *md, unsigned int mdlen, BIO *dcont, 128 unsigned int flags); 129 130CMS_ContentInfo *CMS_sign(X509 *signcert, EVP_PKEY *pkey, 131 STACK_OF(X509) *certs, BIO *data, 132 unsigned int flags); 133CMS_ContentInfo *CMS_sign_ex(X509 *signcert, EVP_PKEY *pkey, 134 STACK_OF(X509) *certs, BIO *data, 135 unsigned int flags, OSSL_LIB_CTX *libctx, 136 const char *propq); 137 138CMS_ContentInfo *CMS_sign_receipt(CMS_SignerInfo *si, 139 X509 *signcert, EVP_PKEY *pkey, 140 STACK_OF(X509) *certs, unsigned int flags); 141 142int CMS_data(CMS_ContentInfo *cms, BIO *out, unsigned int flags); 143CMS_ContentInfo *CMS_data_create(BIO *in, unsigned int flags); 144CMS_ContentInfo *CMS_data_create_ex(BIO *in, unsigned int flags, 145 OSSL_LIB_CTX *libctx, const char *propq); 146 147int CMS_digest_verify(CMS_ContentInfo *cms, BIO *dcont, BIO *out, 148 unsigned int flags); 149CMS_ContentInfo *CMS_digest_create(BIO *in, const EVP_MD *md, 150 unsigned int flags); 151CMS_ContentInfo *CMS_digest_create_ex(BIO *in, const EVP_MD *md, 152 unsigned int flags, OSSL_LIB_CTX *libctx, 153 const char *propq); 154 155int CMS_EncryptedData_decrypt(CMS_ContentInfo *cms, 156 const unsigned char *key, size_t keylen, 157 BIO *dcont, BIO *out, unsigned int flags); 158CMS_ContentInfo *CMS_EncryptedData_encrypt(BIO *in, const EVP_CIPHER *cipher, 159 const unsigned char *key, 160 size_t keylen, unsigned int flags); 161CMS_ContentInfo *CMS_EncryptedData_encrypt_ex(BIO *in, const EVP_CIPHER *cipher, 162 const unsigned char *key, 163 size_t keylen, unsigned int flags, 164 OSSL_LIB_CTX *libctx, 165 const char *propq); 166 167int CMS_EncryptedData_set1_key(CMS_ContentInfo *cms, const EVP_CIPHER *ciph, 168 const unsigned char *key, size_t keylen); 169 170int CMS_verify(CMS_ContentInfo *cms, STACK_OF(X509) *certs, 171 X509_STORE *store, BIO *dcont, BIO *out, unsigned int flags); 172 173int CMS_verify_receipt(CMS_ContentInfo *rcms, CMS_ContentInfo *ocms, 174 STACK_OF(X509) *certs, 175 X509_STORE *store, unsigned int flags); 176 177STACK_OF(X509) *CMS_get0_signers(CMS_ContentInfo *cms); 178 179CMS_ContentInfo *CMS_encrypt(STACK_OF(X509) *certs, BIO *in, 180 const EVP_CIPHER *cipher, unsigned int flags); 181CMS_ContentInfo *CMS_encrypt_ex(STACK_OF(X509) *certs, BIO *in, 182 const EVP_CIPHER *cipher, unsigned int flags, 183 OSSL_LIB_CTX *libctx, const char *propq); 184 185int CMS_decrypt(CMS_ContentInfo *cms, EVP_PKEY *pkey, X509 *cert, 186 BIO *dcont, BIO *out, unsigned int flags); 187 188int CMS_decrypt_set1_pkey(CMS_ContentInfo *cms, EVP_PKEY *pk, X509 *cert); 189int CMS_decrypt_set1_pkey_and_peer(CMS_ContentInfo *cms, EVP_PKEY *pk, 190 X509 *cert, X509 *peer); 191int CMS_decrypt_set1_key(CMS_ContentInfo *cms, 192 unsigned char *key, size_t keylen, 193 const unsigned char *id, size_t idlen); 194int CMS_decrypt_set1_password(CMS_ContentInfo *cms, 195 unsigned char *pass, ossl_ssize_t passlen); 196 197STACK_OF(CMS_RecipientInfo) *CMS_get0_RecipientInfos(CMS_ContentInfo *cms); 198int CMS_RecipientInfo_type(CMS_RecipientInfo *ri); 199EVP_PKEY_CTX *CMS_RecipientInfo_get0_pkey_ctx(CMS_RecipientInfo *ri); 200CMS_ContentInfo *CMS_AuthEnvelopedData_create(const EVP_CIPHER *cipher); 201CMS_ContentInfo * 202CMS_AuthEnvelopedData_create_ex(const EVP_CIPHER *cipher, OSSL_LIB_CTX *libctx, 203 const char *propq); 204CMS_ContentInfo *CMS_EnvelopedData_create(const EVP_CIPHER *cipher); 205CMS_ContentInfo *CMS_EnvelopedData_create_ex(const EVP_CIPHER *cipher, 206 OSSL_LIB_CTX *libctx, 207 const char *propq); 208BIO *CMS_EnvelopedData_decrypt(CMS_EnvelopedData *env, BIO *detached_data, 209 EVP_PKEY *pkey, X509 *cert, 210 ASN1_OCTET_STRING *secret, unsigned int flags, 211 OSSL_LIB_CTX *libctx, const char *propq); 212 213CMS_RecipientInfo *CMS_add1_recipient_cert(CMS_ContentInfo *cms, 214 X509 *recip, unsigned int flags); 215CMS_RecipientInfo *CMS_add1_recipient(CMS_ContentInfo *cms, X509 *recip, 216 EVP_PKEY *originatorPrivKey, X509 * originator, unsigned int flags); 217int CMS_RecipientInfo_set0_pkey(CMS_RecipientInfo *ri, EVP_PKEY *pkey); 218int CMS_RecipientInfo_ktri_cert_cmp(CMS_RecipientInfo *ri, X509 *cert); 219int CMS_RecipientInfo_ktri_get0_algs(CMS_RecipientInfo *ri, 220 EVP_PKEY **pk, X509 **recip, 221 X509_ALGOR **palg); 222int CMS_RecipientInfo_ktri_get0_signer_id(CMS_RecipientInfo *ri, 223 ASN1_OCTET_STRING **keyid, 224 X509_NAME **issuer, 225 ASN1_INTEGER **sno); 226 227CMS_RecipientInfo *CMS_add0_recipient_key(CMS_ContentInfo *cms, int nid, 228 unsigned char *key, size_t keylen, 229 unsigned char *id, size_t idlen, 230 ASN1_GENERALIZEDTIME *date, 231 ASN1_OBJECT *otherTypeId, 232 ASN1_TYPE *otherType); 233 234int CMS_RecipientInfo_kekri_get0_id(CMS_RecipientInfo *ri, 235 X509_ALGOR **palg, 236 ASN1_OCTET_STRING **pid, 237 ASN1_GENERALIZEDTIME **pdate, 238 ASN1_OBJECT **potherid, 239 ASN1_TYPE **pothertype); 240 241int CMS_RecipientInfo_set0_key(CMS_RecipientInfo *ri, 242 unsigned char *key, size_t keylen); 243 244int CMS_RecipientInfo_kekri_id_cmp(CMS_RecipientInfo *ri, 245 const unsigned char *id, size_t idlen); 246 247int CMS_RecipientInfo_set0_password(CMS_RecipientInfo *ri, 248 unsigned char *pass, 249 ossl_ssize_t passlen); 250 251CMS_RecipientInfo *CMS_add0_recipient_password(CMS_ContentInfo *cms, 252 int iter, int wrap_nid, 253 int pbe_nid, 254 unsigned char *pass, 255 ossl_ssize_t passlen, 256 const EVP_CIPHER *kekciph); 257 258int CMS_RecipientInfo_decrypt(CMS_ContentInfo *cms, CMS_RecipientInfo *ri); 259int CMS_RecipientInfo_encrypt(const CMS_ContentInfo *cms, CMS_RecipientInfo *ri); 260 261int CMS_uncompress(CMS_ContentInfo *cms, BIO *dcont, BIO *out, 262 unsigned int flags); 263CMS_ContentInfo *CMS_compress(BIO *in, int comp_nid, unsigned int flags); 264 265int CMS_set1_eContentType(CMS_ContentInfo *cms, const ASN1_OBJECT *oid); 266const ASN1_OBJECT *CMS_get0_eContentType(CMS_ContentInfo *cms); 267 268CMS_CertificateChoices *CMS_add0_CertificateChoices(CMS_ContentInfo *cms); 269int CMS_add0_cert(CMS_ContentInfo *cms, X509 *cert); 270int CMS_add1_cert(CMS_ContentInfo *cms, X509 *cert); 271STACK_OF(X509) *CMS_get1_certs(CMS_ContentInfo *cms); 272 273CMS_RevocationInfoChoice *CMS_add0_RevocationInfoChoice(CMS_ContentInfo *cms); 274int CMS_add0_crl(CMS_ContentInfo *cms, X509_CRL *crl); 275int CMS_add1_crl(CMS_ContentInfo *cms, X509_CRL *crl); 276STACK_OF(X509_CRL) *CMS_get1_crls(CMS_ContentInfo *cms); 277 278int CMS_SignedData_init(CMS_ContentInfo *cms); 279CMS_SignerInfo *CMS_add1_signer(CMS_ContentInfo *cms, 280 X509 *signer, EVP_PKEY *pk, const EVP_MD *md, 281 unsigned int flags); 282EVP_PKEY_CTX *CMS_SignerInfo_get0_pkey_ctx(CMS_SignerInfo *si); 283EVP_MD_CTX *CMS_SignerInfo_get0_md_ctx(CMS_SignerInfo *si); 284STACK_OF(CMS_SignerInfo) *CMS_get0_SignerInfos(CMS_ContentInfo *cms); 285 286void CMS_SignerInfo_set1_signer_cert(CMS_SignerInfo *si, X509 *signer); 287int CMS_SignerInfo_get0_signer_id(CMS_SignerInfo *si, 288 ASN1_OCTET_STRING **keyid, 289 X509_NAME **issuer, ASN1_INTEGER **sno); 290int CMS_SignerInfo_cert_cmp(CMS_SignerInfo *si, X509 *cert); 291int CMS_set1_signers_certs(CMS_ContentInfo *cms, STACK_OF(X509) *certs, 292 unsigned int flags); 293void CMS_SignerInfo_get0_algs(CMS_SignerInfo *si, EVP_PKEY **pk, 294 X509 **signer, X509_ALGOR **pdig, 295 X509_ALGOR **psig); 296ASN1_OCTET_STRING *CMS_SignerInfo_get0_signature(CMS_SignerInfo *si); 297int CMS_SignerInfo_sign(CMS_SignerInfo *si); 298int CMS_SignerInfo_verify(CMS_SignerInfo *si); 299int CMS_SignerInfo_verify_content(CMS_SignerInfo *si, BIO *chain); 300BIO *CMS_SignedData_verify(CMS_SignedData *sd, BIO *detached_data, 301 STACK_OF(X509) *scerts, X509_STORE *store, 302 STACK_OF(X509) *extra, STACK_OF(X509_CRL) *crls, 303 unsigned int flags, 304 OSSL_LIB_CTX *libctx, const char *propq); 305 306int CMS_add_smimecap(CMS_SignerInfo *si, STACK_OF(X509_ALGOR) *algs); 307int CMS_add_simple_smimecap(STACK_OF(X509_ALGOR) **algs, 308 int algnid, int keysize); 309int CMS_add_standard_smimecap(STACK_OF(X509_ALGOR) **smcap); 310 311int CMS_signed_get_attr_count(const CMS_SignerInfo *si); 312int CMS_signed_get_attr_by_NID(const CMS_SignerInfo *si, int nid, 313 int lastpos); 314int CMS_signed_get_attr_by_OBJ(const CMS_SignerInfo *si, const ASN1_OBJECT *obj, 315 int lastpos); 316X509_ATTRIBUTE *CMS_signed_get_attr(const CMS_SignerInfo *si, int loc); 317X509_ATTRIBUTE *CMS_signed_delete_attr(CMS_SignerInfo *si, int loc); 318int CMS_signed_add1_attr(CMS_SignerInfo *si, X509_ATTRIBUTE *attr); 319int CMS_signed_add1_attr_by_OBJ(CMS_SignerInfo *si, 320 const ASN1_OBJECT *obj, int type, 321 const void *bytes, int len); 322int CMS_signed_add1_attr_by_NID(CMS_SignerInfo *si, 323 int nid, int type, 324 const void *bytes, int len); 325int CMS_signed_add1_attr_by_txt(CMS_SignerInfo *si, 326 const char *attrname, int type, 327 const void *bytes, int len); 328void *CMS_signed_get0_data_by_OBJ(const CMS_SignerInfo *si, 329 const ASN1_OBJECT *oid, 330 int lastpos, int type); 331 332int CMS_unsigned_get_attr_count(const CMS_SignerInfo *si); 333int CMS_unsigned_get_attr_by_NID(const CMS_SignerInfo *si, int nid, 334 int lastpos); 335int CMS_unsigned_get_attr_by_OBJ(const CMS_SignerInfo *si, 336 const ASN1_OBJECT *obj, int lastpos); 337X509_ATTRIBUTE *CMS_unsigned_get_attr(const CMS_SignerInfo *si, int loc); 338X509_ATTRIBUTE *CMS_unsigned_delete_attr(CMS_SignerInfo *si, int loc); 339int CMS_unsigned_add1_attr(CMS_SignerInfo *si, X509_ATTRIBUTE *attr); 340int CMS_unsigned_add1_attr_by_OBJ(CMS_SignerInfo *si, 341 const ASN1_OBJECT *obj, int type, 342 const void *bytes, int len); 343int CMS_unsigned_add1_attr_by_NID(CMS_SignerInfo *si, 344 int nid, int type, 345 const void *bytes, int len); 346int CMS_unsigned_add1_attr_by_txt(CMS_SignerInfo *si, 347 const char *attrname, int type, 348 const void *bytes, int len); 349void *CMS_unsigned_get0_data_by_OBJ(CMS_SignerInfo *si, ASN1_OBJECT *oid, 350 int lastpos, int type); 351 352int CMS_get1_ReceiptRequest(CMS_SignerInfo *si, CMS_ReceiptRequest **prr); 353CMS_ReceiptRequest *CMS_ReceiptRequest_create0( 354 unsigned char *id, int idlen, int allorfirst, 355 STACK_OF(GENERAL_NAMES) *receiptList, 356 STACK_OF(GENERAL_NAMES) *receiptsTo); 357CMS_ReceiptRequest *CMS_ReceiptRequest_create0_ex( 358 unsigned char *id, int idlen, int allorfirst, 359 STACK_OF(GENERAL_NAMES) *receiptList, 360 STACK_OF(GENERAL_NAMES) *receiptsTo, 361 OSSL_LIB_CTX *libctx); 362 363int CMS_add1_ReceiptRequest(CMS_SignerInfo *si, CMS_ReceiptRequest *rr); 364void CMS_ReceiptRequest_get0_values(CMS_ReceiptRequest *rr, 365 ASN1_STRING **pcid, 366 int *pallorfirst, 367 STACK_OF(GENERAL_NAMES) **plist, 368 STACK_OF(GENERAL_NAMES) **prto); 369int CMS_RecipientInfo_kari_get0_alg(CMS_RecipientInfo *ri, 370 X509_ALGOR **palg, 371 ASN1_OCTET_STRING **pukm); 372STACK_OF(CMS_RecipientEncryptedKey) 373*CMS_RecipientInfo_kari_get0_reks(CMS_RecipientInfo *ri); 374 375int CMS_RecipientInfo_kari_get0_orig_id(CMS_RecipientInfo *ri, 376 X509_ALGOR **pubalg, 377 ASN1_BIT_STRING **pubkey, 378 ASN1_OCTET_STRING **keyid, 379 X509_NAME **issuer, 380 ASN1_INTEGER **sno); 381 382int CMS_RecipientInfo_kari_orig_id_cmp(CMS_RecipientInfo *ri, X509 *cert); 383 384int CMS_RecipientEncryptedKey_get0_id(CMS_RecipientEncryptedKey *rek, 385 ASN1_OCTET_STRING **keyid, 386 ASN1_GENERALIZEDTIME **tm, 387 CMS_OtherKeyAttribute **other, 388 X509_NAME **issuer, ASN1_INTEGER **sno); 389int CMS_RecipientEncryptedKey_cert_cmp(CMS_RecipientEncryptedKey *rek, 390 X509 *cert); 391int CMS_RecipientInfo_kari_set0_pkey(CMS_RecipientInfo *ri, EVP_PKEY *pk); 392int CMS_RecipientInfo_kari_set0_pkey_and_peer(CMS_RecipientInfo *ri, EVP_PKEY *pk, X509 *peer); 393EVP_CIPHER_CTX *CMS_RecipientInfo_kari_get0_ctx(CMS_RecipientInfo *ri); 394int CMS_RecipientInfo_kari_decrypt(CMS_ContentInfo *cms, 395 CMS_RecipientInfo *ri, 396 CMS_RecipientEncryptedKey *rek); 397 398int CMS_SharedInfo_encode(unsigned char **pder, X509_ALGOR *kekalg, 399 ASN1_OCTET_STRING *ukm, int keylen); 400 401/* Backward compatibility for spelling errors. */ 402# define CMS_R_UNKNOWN_DIGEST_ALGORITM CMS_R_UNKNOWN_DIGEST_ALGORITHM 403# define CMS_R_UNSUPPORTED_RECPIENTINFO_TYPE \ 404 CMS_R_UNSUPPORTED_RECIPIENTINFO_TYPE 405 406# ifdef __cplusplus 407} 408# endif 409# endif 410#endif 411