cms.h 16 KB

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