Added functions to export structures in an allocated buffer.
[gnutls.git] / lib / includes / gnutls / pkcs12.h
blob02f6351c174ca3201cc5d1ce4d726fe03fbe4f2f
1 /*
2 * Copyright (C) 2003-2012 Free Software Foundation, Inc.
4 * Author: Nikos Mavrogiannopoulos
6 * This file is part of GnuTLS.
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 3 of
11 * the License, or (at your option) any later version.
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.
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/>
23 #ifndef GNUTLS_PKCS12_H
24 #define GNUTLS_PKCS12_H
26 #include <gnutls/x509.h>
28 #ifdef __cplusplus
29 extern "C"
31 #endif
33 /* PKCS12 structures handling
35 struct gnutls_pkcs12_int;
36 typedef struct gnutls_pkcs12_int *gnutls_pkcs12_t;
38 struct gnutls_pkcs12_bag_int;
39 typedef struct gnutls_pkcs12_bag_int *gnutls_pkcs12_bag_t;
41 int gnutls_pkcs12_init (gnutls_pkcs12_t * pkcs12);
42 void gnutls_pkcs12_deinit (gnutls_pkcs12_t pkcs12);
43 int gnutls_pkcs12_import (gnutls_pkcs12_t pkcs12,
44 const gnutls_datum_t * data,
45 gnutls_x509_crt_fmt_t format, unsigned int flags);
46 int gnutls_pkcs12_export (gnutls_pkcs12_t pkcs12,
47 gnutls_x509_crt_fmt_t format,
48 void *output_data, size_t * output_data_size);
49 int gnutls_pkcs12_export2 (gnutls_pkcs12_t pkcs12,
50 gnutls_x509_crt_fmt_t format,
51 gnutls_datum_t *out);
53 int gnutls_pkcs12_get_bag (gnutls_pkcs12_t pkcs12,
54 int indx, gnutls_pkcs12_bag_t bag);
55 int gnutls_pkcs12_set_bag (gnutls_pkcs12_t pkcs12, gnutls_pkcs12_bag_t bag);
57 int gnutls_pkcs12_generate_mac (gnutls_pkcs12_t pkcs12, const char *pass);
58 int gnutls_pkcs12_verify_mac (gnutls_pkcs12_t pkcs12, const char *pass);
60 int gnutls_pkcs12_bag_decrypt (gnutls_pkcs12_bag_t bag, const char *pass);
61 int gnutls_pkcs12_bag_encrypt (gnutls_pkcs12_bag_t bag, const char *pass,
62 unsigned int flags);
64 #define GNUTLS_PKCS12_SP_INCLUDE_SELF_SIGNED 1
65 int gnutls_pkcs12_simple_parse (gnutls_pkcs12_t p12,
66 const char *password,
67 gnutls_x509_privkey_t * key,
68 gnutls_x509_crt_t ** chain,
69 unsigned int * chain_len,
70 gnutls_x509_crt_t ** extra_certs,
71 unsigned int * extra_certs_len,
72 gnutls_x509_crl_t * crl,
73 unsigned int flags);
75 /**
76 * gnutls_pkcs12_bag_type_t:
77 * @GNUTLS_BAG_EMPTY: Empty PKCS-12 bag.
78 * @GNUTLS_BAG_PKCS8_ENCRYPTED_KEY: PKCS-12 bag with PKCS-8 encrypted key.
79 * @GNUTLS_BAG_PKCS8_KEY: PKCS-12 bag with PKCS-8 key.
80 * @GNUTLS_BAG_CERTIFICATE: PKCS-12 bag with certificate.
81 * @GNUTLS_BAG_CRL: PKCS-12 bag with CRL.
82 * @GNUTLS_BAG_SECRET: PKCS-12 bag with secret PKCS-9 keys.
83 * @GNUTLS_BAG_ENCRYPTED: Encrypted PKCS-12 bag.
84 * @GNUTLS_BAG_UNKNOWN: Unknown PKCS-12 bag.
86 * Enumeration of different PKCS 12 bag types.
88 typedef enum gnutls_pkcs12_bag_type_t
90 GNUTLS_BAG_EMPTY = 0,
91 GNUTLS_BAG_PKCS8_ENCRYPTED_KEY = 1,
92 GNUTLS_BAG_PKCS8_KEY = 2,
93 GNUTLS_BAG_CERTIFICATE = 3,
94 GNUTLS_BAG_CRL = 4,
95 GNUTLS_BAG_SECRET = 5, /* Secret data. Underspecified in pkcs-12,
96 * gnutls extension. We use the PKCS-9
97 * random nonce ID 1.2.840.113549.1.9.25.3
98 * to store randomly generated keys.
100 GNUTLS_BAG_ENCRYPTED = 10,
101 GNUTLS_BAG_UNKNOWN = 20
102 } gnutls_pkcs12_bag_type_t;
104 gnutls_pkcs12_bag_type_t
105 gnutls_pkcs12_bag_get_type (gnutls_pkcs12_bag_t bag, int indx);
106 int gnutls_pkcs12_bag_get_data (gnutls_pkcs12_bag_t bag, int indx,
107 gnutls_datum_t * data);
108 int gnutls_pkcs12_bag_set_data (gnutls_pkcs12_bag_t bag,
109 gnutls_pkcs12_bag_type_t type,
110 const gnutls_datum_t * data);
111 int gnutls_pkcs12_bag_set_crl (gnutls_pkcs12_bag_t bag,
112 gnutls_x509_crl_t crl);
113 int gnutls_pkcs12_bag_set_crt (gnutls_pkcs12_bag_t bag,
114 gnutls_x509_crt_t crt);
116 int gnutls_pkcs12_bag_init (gnutls_pkcs12_bag_t * bag);
117 void gnutls_pkcs12_bag_deinit (gnutls_pkcs12_bag_t bag);
118 int gnutls_pkcs12_bag_get_count (gnutls_pkcs12_bag_t bag);
120 int gnutls_pkcs12_bag_get_key_id (gnutls_pkcs12_bag_t bag, int indx,
121 gnutls_datum_t * id);
122 int gnutls_pkcs12_bag_set_key_id (gnutls_pkcs12_bag_t bag, int indx,
123 const gnutls_datum_t * id);
125 int gnutls_pkcs12_bag_get_friendly_name (gnutls_pkcs12_bag_t bag, int indx,
126 char **name);
127 int gnutls_pkcs12_bag_set_friendly_name (gnutls_pkcs12_bag_t bag, int indx,
128 const char *name);
130 #ifdef __cplusplus
132 #endif
134 #endif /* GNUTLS_PKCS12_H */