pkcs12.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /*
  2. * Copyright (C) 2003-2012 Free Software Foundation, Inc.
  3. *
  4. * Author: Nikos Mavrogiannopoulos
  5. *
  6. * This file is part of GnuTLS.
  7. *
  8. * The GnuTLS is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public License
  10. * as published by the Free Software Foundation; either version 2.1 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>
  20. *
  21. */
  22. #ifndef GNUTLS_PKCS12_H
  23. #define GNUTLS_PKCS12_H
  24. #include <gnutls/x509.h>
  25. /* *INDENT-OFF* */
  26. #ifdef __cplusplus
  27. extern "C" {
  28. #endif
  29. /* *INDENT-ON* */
  30. /* PKCS12 structures handling
  31. */
  32. struct gnutls_pkcs12_int;
  33. typedef struct gnutls_pkcs12_int *gnutls_pkcs12_t;
  34. struct gnutls_pkcs12_bag_int;
  35. typedef struct gnutls_pkcs12_bag_int *gnutls_pkcs12_bag_t;
  36. int gnutls_pkcs12_init(gnutls_pkcs12_t * pkcs12);
  37. void gnutls_pkcs12_deinit(gnutls_pkcs12_t pkcs12);
  38. int gnutls_pkcs12_import(gnutls_pkcs12_t pkcs12,
  39. const gnutls_datum_t * data,
  40. gnutls_x509_crt_fmt_t format, unsigned int flags);
  41. int gnutls_pkcs12_export(gnutls_pkcs12_t pkcs12,
  42. gnutls_x509_crt_fmt_t format,
  43. void *output_data, size_t * output_data_size);
  44. int gnutls_pkcs12_export2(gnutls_pkcs12_t pkcs12,
  45. gnutls_x509_crt_fmt_t format,
  46. gnutls_datum_t * out);
  47. int gnutls_pkcs12_get_bag(gnutls_pkcs12_t pkcs12,
  48. int indx, gnutls_pkcs12_bag_t bag);
  49. int gnutls_pkcs12_set_bag(gnutls_pkcs12_t pkcs12, gnutls_pkcs12_bag_t bag);
  50. int gnutls_pkcs12_generate_mac(gnutls_pkcs12_t pkcs12, const char *pass);
  51. int gnutls_pkcs12_generate_mac2(gnutls_pkcs12_t pkcs12, gnutls_mac_algorithm_t mac, const char *pass);
  52. int gnutls_pkcs12_verify_mac(gnutls_pkcs12_t pkcs12, const char *pass);
  53. int gnutls_pkcs12_bag_decrypt(gnutls_pkcs12_bag_t bag, const char *pass);
  54. int gnutls_pkcs12_bag_encrypt(gnutls_pkcs12_bag_t bag,
  55. const char *pass, unsigned int flags);
  56. int
  57. gnutls_pkcs12_bag_enc_info(gnutls_pkcs12_bag_t bag, unsigned int *schema, unsigned int *cipher,
  58. void *salt, unsigned int *salt_size, unsigned int *iter_count, char **oid);
  59. int
  60. gnutls_pkcs12_mac_info(gnutls_pkcs12_t pkcs12, unsigned int *mac,
  61. void *salt, unsigned int *salt_size, unsigned int *iter_count, char **oid);
  62. #define GNUTLS_PKCS12_SP_INCLUDE_SELF_SIGNED 1
  63. int gnutls_pkcs12_simple_parse(gnutls_pkcs12_t p12,
  64. const char *password,
  65. gnutls_x509_privkey_t * key,
  66. gnutls_x509_crt_t ** chain,
  67. unsigned int *chain_len,
  68. gnutls_x509_crt_t ** extra_certs,
  69. unsigned int *extra_certs_len,
  70. gnutls_x509_crl_t * crl,
  71. unsigned int flags);
  72. /**
  73. * gnutls_pkcs12_bag_type_t:
  74. * @GNUTLS_BAG_EMPTY: Empty PKCS-12 bag.
  75. * @GNUTLS_BAG_PKCS8_ENCRYPTED_KEY: PKCS-12 bag with PKCS-8 encrypted key.
  76. * @GNUTLS_BAG_PKCS8_KEY: PKCS-12 bag with PKCS-8 key.
  77. * @GNUTLS_BAG_CERTIFICATE: PKCS-12 bag with certificate.
  78. * @GNUTLS_BAG_CRL: PKCS-12 bag with CRL.
  79. * @GNUTLS_BAG_SECRET: PKCS-12 bag with secret PKCS-9 keys.
  80. * @GNUTLS_BAG_ENCRYPTED: Encrypted PKCS-12 bag.
  81. * @GNUTLS_BAG_UNKNOWN: Unknown PKCS-12 bag.
  82. *
  83. * Enumeration of different PKCS 12 bag types.
  84. */
  85. typedef enum gnutls_pkcs12_bag_type_t {
  86. GNUTLS_BAG_EMPTY = 0,
  87. GNUTLS_BAG_PKCS8_ENCRYPTED_KEY = 1,
  88. GNUTLS_BAG_PKCS8_KEY = 2,
  89. GNUTLS_BAG_CERTIFICATE = 3,
  90. GNUTLS_BAG_CRL = 4,
  91. GNUTLS_BAG_SECRET = 5, /* Secret data. Underspecified in pkcs-12,
  92. * gnutls extension. We use the PKCS-9
  93. * random nonce ID 1.2.840.113549.1.9.25.3
  94. * to store randomly generated keys.
  95. */
  96. GNUTLS_BAG_ENCRYPTED = 10,
  97. GNUTLS_BAG_UNKNOWN = 20
  98. } gnutls_pkcs12_bag_type_t;
  99. int
  100. gnutls_pkcs12_bag_get_type(gnutls_pkcs12_bag_t bag, unsigned indx);
  101. int gnutls_pkcs12_bag_get_data(gnutls_pkcs12_bag_t bag, unsigned indx,
  102. gnutls_datum_t * data);
  103. int gnutls_pkcs12_bag_set_data(gnutls_pkcs12_bag_t bag,
  104. gnutls_pkcs12_bag_type_t type,
  105. const gnutls_datum_t * data);
  106. int gnutls_pkcs12_bag_set_crl(gnutls_pkcs12_bag_t bag,
  107. gnutls_x509_crl_t crl);
  108. int gnutls_pkcs12_bag_set_crt(gnutls_pkcs12_bag_t bag,
  109. gnutls_x509_crt_t crt);
  110. int
  111. gnutls_pkcs12_bag_set_privkey(gnutls_pkcs12_bag_t bag,
  112. gnutls_x509_privkey_t privkey,
  113. const char *password, unsigned flags);
  114. int gnutls_pkcs12_bag_init(gnutls_pkcs12_bag_t * bag);
  115. void gnutls_pkcs12_bag_deinit(gnutls_pkcs12_bag_t bag);
  116. int gnutls_pkcs12_bag_get_count(gnutls_pkcs12_bag_t bag);
  117. int gnutls_pkcs12_bag_get_key_id(gnutls_pkcs12_bag_t bag, unsigned indx,
  118. gnutls_datum_t * id);
  119. int gnutls_pkcs12_bag_set_key_id(gnutls_pkcs12_bag_t bag, unsigned indx,
  120. const gnutls_datum_t * id);
  121. int gnutls_pkcs12_bag_get_friendly_name(gnutls_pkcs12_bag_t bag,
  122. unsigned indx, char **name);
  123. int gnutls_pkcs12_bag_set_friendly_name(gnutls_pkcs12_bag_t bag,
  124. unsigned indx, const char *name);
  125. /* *INDENT-OFF* */
  126. #ifdef __cplusplus
  127. }
  128. #endif
  129. /* *INDENT-ON* */
  130. #endif /* GNUTLS_PKCS12_H */