pkcs7.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /*
  2. * Copyright (C) 2003-2012 Free Software Foundation, Inc.
  3. * Copyright (C) 2015 Red Hat, Inc.
  4. *
  5. * Author: Nikos Mavrogiannopoulos
  6. *
  7. * This file is part of GnuTLS.
  8. *
  9. * The GnuTLS is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public License
  11. * as published by the Free Software Foundation; either version 2.1 of
  12. * the License, or (at your option) any later version.
  13. *
  14. * This library is distributed in the hope that it will be useful, but
  15. * WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>
  21. *
  22. */
  23. /* This file contains the types and prototypes for the X.509
  24. * certificate and CRL handling functions.
  25. */
  26. #ifndef GNUTLS_PKCS7_H
  27. #define GNUTLS_PKCS7_H
  28. #include <gnutls/gnutls.h>
  29. #include <gnutls/x509.h>
  30. /* *INDENT-OFF* */
  31. #ifdef __cplusplus
  32. extern "C" {
  33. #endif
  34. /* *INDENT-ON* */
  35. /* PKCS7 structures handling
  36. */
  37. struct gnutls_pkcs7_int;
  38. typedef struct gnutls_pkcs7_int *gnutls_pkcs7_t;
  39. int gnutls_pkcs7_init(gnutls_pkcs7_t * pkcs7);
  40. void gnutls_pkcs7_deinit(gnutls_pkcs7_t pkcs7);
  41. int gnutls_pkcs7_import(gnutls_pkcs7_t pkcs7,
  42. const gnutls_datum_t * data,
  43. gnutls_x509_crt_fmt_t format);
  44. int gnutls_pkcs7_export(gnutls_pkcs7_t pkcs7,
  45. gnutls_x509_crt_fmt_t format,
  46. void *output_data, size_t * output_data_size);
  47. int gnutls_pkcs7_export2(gnutls_pkcs7_t pkcs7,
  48. gnutls_x509_crt_fmt_t format,
  49. gnutls_datum_t * out);
  50. int gnutls_pkcs7_get_signature_count(gnutls_pkcs7_t pkcs7);
  51. #define GNUTLS_PKCS7_EDATA_GET_RAW (1<<24)
  52. int gnutls_pkcs7_get_embedded_data(gnutls_pkcs7_t pkcs7, unsigned flags, gnutls_datum_t *data);
  53. const char *
  54. gnutls_pkcs7_get_embedded_data_oid(gnutls_pkcs7_t pkcs7);
  55. int gnutls_pkcs7_get_crt_count(gnutls_pkcs7_t pkcs7);
  56. int gnutls_pkcs7_get_crt_raw(gnutls_pkcs7_t pkcs7, unsigned indx,
  57. void *certificate, size_t * certificate_size);
  58. int gnutls_pkcs7_set_crt_raw(gnutls_pkcs7_t pkcs7,
  59. const gnutls_datum_t * crt);
  60. int gnutls_pkcs7_set_crt(gnutls_pkcs7_t pkcs7, gnutls_x509_crt_t crt);
  61. int gnutls_pkcs7_delete_crt(gnutls_pkcs7_t pkcs7, int indx);
  62. int gnutls_pkcs7_get_crl_raw(gnutls_pkcs7_t pkcs7,
  63. unsigned indx, void *crl, size_t * crl_size);
  64. int gnutls_pkcs7_get_crl_count(gnutls_pkcs7_t pkcs7);
  65. int gnutls_pkcs7_set_crl_raw(gnutls_pkcs7_t pkcs7,
  66. const gnutls_datum_t * crl);
  67. int gnutls_pkcs7_set_crl(gnutls_pkcs7_t pkcs7, gnutls_x509_crl_t crl);
  68. int gnutls_pkcs7_delete_crl(gnutls_pkcs7_t pkcs7, int indx);
  69. typedef struct gnutls_pkcs7_attrs_st *gnutls_pkcs7_attrs_t;
  70. typedef struct gnutls_pkcs7_signature_info_st {
  71. gnutls_sign_algorithm_t algo;
  72. gnutls_datum_t sig;
  73. gnutls_datum_t issuer_dn;
  74. gnutls_datum_t signer_serial;
  75. gnutls_datum_t issuer_keyid;
  76. time_t signing_time;
  77. gnutls_pkcs7_attrs_t signed_attrs;
  78. gnutls_pkcs7_attrs_t unsigned_attrs;
  79. char pad[64];
  80. } gnutls_pkcs7_signature_info_st;
  81. void gnutls_pkcs7_signature_info_deinit(gnutls_pkcs7_signature_info_st *info);
  82. int gnutls_pkcs7_get_signature_info(gnutls_pkcs7_t pkcs7, unsigned idx, gnutls_pkcs7_signature_info_st *info);
  83. int gnutls_pkcs7_verify_direct(gnutls_pkcs7_t pkcs7, gnutls_x509_crt_t signer,
  84. unsigned idx, const gnutls_datum_t *data, unsigned flags);
  85. int gnutls_pkcs7_verify(gnutls_pkcs7_t pkcs7, gnutls_x509_trust_list_t tl,
  86. gnutls_typed_vdata_st * vdata, unsigned int vdata_size,
  87. unsigned idx, const gnutls_datum_t *data, unsigned flags);
  88. #define GNUTLS_PKCS7_ATTR_ENCODE_OCTET_STRING 1
  89. int gnutls_pkcs7_add_attr(gnutls_pkcs7_attrs_t *list, const char *oid, gnutls_datum_t *data, unsigned flags);
  90. void gnutls_pkcs7_attrs_deinit(gnutls_pkcs7_attrs_t list);
  91. int gnutls_pkcs7_get_attr(gnutls_pkcs7_attrs_t list, unsigned idx, char **oid, gnutls_datum_t *data, unsigned flags);
  92. /**
  93. * gnutls_pkcs7_sign_flags:
  94. * @GNUTLS_PKCS7_EMBED_DATA: The signed data will be embedded in the structure.
  95. * @GNUTLS_PKCS7_INCLUDE_TIME: The signing time will be included in the structure.
  96. * @GNUTLS_PKCS7_INCLUDE_CERT: The signer's certificate will be included in the cert list.
  97. * @GNUTLS_PKCS7_WRITE_SPKI: Use the signer's key identifier instead of name.
  98. *
  99. * Enumeration of the different PKCS #7 signature flags.
  100. */
  101. typedef enum gnutls_pkcs7_sign_flags {
  102. GNUTLS_PKCS7_EMBED_DATA = 1,
  103. GNUTLS_PKCS7_INCLUDE_TIME = (1<<1),
  104. GNUTLS_PKCS7_INCLUDE_CERT = (1<<2),
  105. GNUTLS_PKCS7_WRITE_SPKI = (1<<3)
  106. } gnutls_pkcs7_sign_flags;
  107. int gnutls_pkcs7_sign(gnutls_pkcs7_t pkcs7,
  108. gnutls_x509_crt_t signer,
  109. gnutls_privkey_t signer_key,
  110. const gnutls_datum_t *data,
  111. gnutls_pkcs7_attrs_t signed_attrs,
  112. gnutls_pkcs7_attrs_t unsigned_attrs,
  113. gnutls_digest_algorithm_t dig,
  114. unsigned flags);
  115. int
  116. gnutls_pkcs7_get_crt_raw2(gnutls_pkcs7_t pkcs7,
  117. unsigned indx, gnutls_datum_t *cert);
  118. int
  119. gnutls_pkcs7_get_crl_raw2(gnutls_pkcs7_t pkcs7,
  120. unsigned indx, gnutls_datum_t *crl);
  121. int gnutls_pkcs7_print(gnutls_pkcs7_t pkcs7,
  122. gnutls_certificate_print_formats_t format,
  123. gnutls_datum_t * out);
  124. /* *INDENT-OFF* */
  125. #ifdef __cplusplus
  126. }
  127. #endif
  128. /* *INDENT-ON* */
  129. #endif /* GNUTLS_PKCS7_H */