cms.h 16 KB

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