Tizen 2.0 Release
[external/libgnutls26.git] / lib / includes / gnutls / openpgp.h
1 /*
2  * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free
3  * Software Foundation, 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
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
22  * USA
23  *
24  */
25
26 /* This file contains the types and prototypes for the OpenPGP
27  * key and private key parsing functions.
28  */
29
30 #ifndef GNUTLS_OPENPGP_H
31 #define GNUTLS_OPENPGP_H
32
33 #include <gnutls/gnutls.h>
34
35 #ifdef __cplusplus
36 extern "C"
37 {
38 #endif
39
40 /* Openpgp certificate stuff
41  */
42
43 /**
44  * gnutls_openpgp_crt_fmt_t:
45  * @GNUTLS_OPENPGP_FMT_RAW: OpenPGP certificate in raw format.
46  * @GNUTLS_OPENPGP_FMT_BASE64: OpenPGP certificate in base64 format.
47  *
48  * Enumeration of different OpenPGP key formats.
49  */
50   typedef enum gnutls_openpgp_crt_fmt
51   {
52     GNUTLS_OPENPGP_FMT_RAW,
53     GNUTLS_OPENPGP_FMT_BASE64
54   } gnutls_openpgp_crt_fmt_t;
55
56 #define GNUTLS_OPENPGP_KEYID_SIZE 8
57   typedef unsigned char gnutls_openpgp_keyid_t[GNUTLS_OPENPGP_KEYID_SIZE];
58
59 /* gnutls_openpgp_cert_t should be defined in gnutls.h
60  */
61
62   /* initializes the memory for gnutls_openpgp_crt_t struct */
63   int gnutls_openpgp_crt_init (gnutls_openpgp_crt_t * key);
64   /* frees all memory */
65   void gnutls_openpgp_crt_deinit (gnutls_openpgp_crt_t key);
66
67   int gnutls_openpgp_crt_import (gnutls_openpgp_crt_t key,
68                                  const gnutls_datum_t * data,
69                                  gnutls_openpgp_crt_fmt_t format);
70   int gnutls_openpgp_crt_export (gnutls_openpgp_crt_t key,
71                                  gnutls_openpgp_crt_fmt_t format,
72                                  void *output_data,
73                                  size_t * output_data_size);
74
75   int gnutls_openpgp_crt_print (gnutls_openpgp_crt_t cert,
76                                 gnutls_certificate_print_formats_t format,
77                                 gnutls_datum_t * out);
78
79 /* The key_usage flags are defined in gnutls.h. They are
80  * the GNUTLS_KEY_* definitions.
81  */
82   int gnutls_openpgp_crt_get_key_usage (gnutls_openpgp_crt_t key,
83                                         unsigned int *key_usage);
84   int gnutls_openpgp_crt_get_fingerprint (gnutls_openpgp_crt_t key, void *fpr,
85                                           size_t * fprlen);
86   int gnutls_openpgp_crt_get_subkey_fingerprint (gnutls_openpgp_crt_t key,
87                                                  unsigned int idx,
88                                                  void *fpr, size_t * fprlen);
89
90   int gnutls_openpgp_crt_get_name (gnutls_openpgp_crt_t key,
91                                    int idx, char *buf, size_t * sizeof_buf);
92
93     gnutls_pk_algorithm_t
94     gnutls_openpgp_crt_get_pk_algorithm (gnutls_openpgp_crt_t key,
95                                          unsigned int *bits);
96
97   int gnutls_openpgp_crt_get_version (gnutls_openpgp_crt_t key);
98
99   time_t gnutls_openpgp_crt_get_creation_time (gnutls_openpgp_crt_t key);
100   time_t gnutls_openpgp_crt_get_expiration_time (gnutls_openpgp_crt_t key);
101
102   int gnutls_openpgp_crt_get_key_id (gnutls_openpgp_crt_t key,
103                                      gnutls_openpgp_keyid_t keyid);
104
105   int gnutls_openpgp_crt_check_hostname (gnutls_openpgp_crt_t key,
106                                          const char *hostname);
107
108   int gnutls_openpgp_crt_get_revoked_status (gnutls_openpgp_crt_t key);
109
110   int gnutls_openpgp_crt_get_subkey_count (gnutls_openpgp_crt_t key);
111   int gnutls_openpgp_crt_get_subkey_idx (gnutls_openpgp_crt_t key,
112                                          const gnutls_openpgp_keyid_t keyid);
113   int gnutls_openpgp_crt_get_subkey_revoked_status (gnutls_openpgp_crt_t key,
114                                                     unsigned int idx);
115     gnutls_pk_algorithm_t
116     gnutls_openpgp_crt_get_subkey_pk_algorithm (gnutls_openpgp_crt_t key,
117                                                 unsigned int idx,
118                                                 unsigned int *bits);
119   time_t gnutls_openpgp_crt_get_subkey_creation_time (gnutls_openpgp_crt_t
120                                                       key, unsigned int idx);
121   time_t gnutls_openpgp_crt_get_subkey_expiration_time (gnutls_openpgp_crt_t
122                                                         key,
123                                                         unsigned int idx);
124   int gnutls_openpgp_crt_get_subkey_id (gnutls_openpgp_crt_t key,
125                                         unsigned int idx,
126                                         gnutls_openpgp_keyid_t keyid);
127   int gnutls_openpgp_crt_get_subkey_usage (gnutls_openpgp_crt_t key,
128                                            unsigned int idx,
129                                            unsigned int *key_usage);
130
131   int gnutls_openpgp_crt_get_subkey_pk_dsa_raw (gnutls_openpgp_crt_t crt,
132                                                 unsigned int idx,
133                                                 gnutls_datum_t * p,
134                                                 gnutls_datum_t * q,
135                                                 gnutls_datum_t * g,
136                                                 gnutls_datum_t * y);
137   int gnutls_openpgp_crt_get_subkey_pk_rsa_raw (gnutls_openpgp_crt_t crt,
138                                                 unsigned int idx,
139                                                 gnutls_datum_t * m,
140                                                 gnutls_datum_t * e);
141   int gnutls_openpgp_crt_get_pk_dsa_raw (gnutls_openpgp_crt_t crt,
142                                          gnutls_datum_t * p,
143                                          gnutls_datum_t * q,
144                                          gnutls_datum_t * g,
145                                          gnutls_datum_t * y);
146   int gnutls_openpgp_crt_get_pk_rsa_raw (gnutls_openpgp_crt_t crt,
147                                          gnutls_datum_t * m,
148                                          gnutls_datum_t * e);
149
150   int gnutls_openpgp_crt_get_preferred_key_id (gnutls_openpgp_crt_t key,
151                                                gnutls_openpgp_keyid_t keyid);
152   int
153     gnutls_openpgp_crt_set_preferred_key_id (gnutls_openpgp_crt_t key,
154                                              const gnutls_openpgp_keyid_t
155                                              keyid);
156
157 /* privkey stuff.
158  */
159   int gnutls_openpgp_privkey_init (gnutls_openpgp_privkey_t * key);
160   void gnutls_openpgp_privkey_deinit (gnutls_openpgp_privkey_t key);
161     gnutls_pk_algorithm_t
162     gnutls_openpgp_privkey_get_pk_algorithm (gnutls_openpgp_privkey_t key,
163                                              unsigned int *bits);
164
165     gnutls_sec_param_t
166     gnutls_openpgp_privkey_sec_param (gnutls_openpgp_privkey_t key);
167   int gnutls_openpgp_privkey_import (gnutls_openpgp_privkey_t key,
168                                      const gnutls_datum_t * data,
169                                      gnutls_openpgp_crt_fmt_t format,
170                                      const char *password,
171                                      unsigned int flags);
172
173   int gnutls_openpgp_privkey_get_fingerprint (gnutls_openpgp_privkey_t key,
174                                               void *fpr, size_t * fprlen);
175   int gnutls_openpgp_privkey_get_subkey_fingerprint (gnutls_openpgp_privkey_t
176                                                      key, unsigned int idx,
177                                                      void *fpr,
178                                                      size_t * fprlen);
179   int gnutls_openpgp_privkey_get_key_id (gnutls_openpgp_privkey_t key,
180                                          gnutls_openpgp_keyid_t keyid);
181   int gnutls_openpgp_privkey_get_subkey_count (gnutls_openpgp_privkey_t key);
182   int gnutls_openpgp_privkey_get_subkey_idx (gnutls_openpgp_privkey_t key,
183                                              const gnutls_openpgp_keyid_t
184                                              keyid);
185
186   int
187     gnutls_openpgp_privkey_get_subkey_revoked_status (gnutls_openpgp_privkey_t
188                                                       key, unsigned int idx);
189
190   int gnutls_openpgp_privkey_get_revoked_status (gnutls_openpgp_privkey_t
191                                                  key);
192
193     gnutls_pk_algorithm_t
194     gnutls_openpgp_privkey_get_subkey_pk_algorithm (gnutls_openpgp_privkey_t
195                                                     key, unsigned int idx,
196                                                     unsigned int *bits);
197
198     time_t
199     gnutls_openpgp_privkey_get_subkey_expiration_time
200     (gnutls_openpgp_privkey_t key, unsigned int idx);
201
202   int gnutls_openpgp_privkey_get_subkey_id (gnutls_openpgp_privkey_t key,
203                                             unsigned int idx,
204                                             gnutls_openpgp_keyid_t keyid);
205
206     time_t
207     gnutls_openpgp_privkey_get_subkey_creation_time (gnutls_openpgp_privkey_t
208                                                      key, unsigned int idx);
209
210   int
211     gnutls_openpgp_privkey_export_subkey_dsa_raw (gnutls_openpgp_privkey_t
212                                                   pkey, unsigned int idx,
213                                                   gnutls_datum_t * p,
214                                                   gnutls_datum_t * q,
215                                                   gnutls_datum_t * g,
216                                                   gnutls_datum_t * y,
217                                                   gnutls_datum_t * x);
218   int gnutls_openpgp_privkey_export_subkey_rsa_raw (gnutls_openpgp_privkey_t
219                                                     pkey, unsigned int idx,
220                                                     gnutls_datum_t * m,
221                                                     gnutls_datum_t * e,
222                                                     gnutls_datum_t * d,
223                                                     gnutls_datum_t * p,
224                                                     gnutls_datum_t * q,
225                                                     gnutls_datum_t * u);
226
227   int gnutls_openpgp_privkey_export_dsa_raw (gnutls_openpgp_privkey_t pkey,
228                                              gnutls_datum_t * p,
229                                              gnutls_datum_t * q,
230                                              gnutls_datum_t * g,
231                                              gnutls_datum_t * y,
232                                              gnutls_datum_t * x);
233   int gnutls_openpgp_privkey_export_rsa_raw (gnutls_openpgp_privkey_t pkey,
234                                              gnutls_datum_t * m,
235                                              gnutls_datum_t * e,
236                                              gnutls_datum_t * d,
237                                              gnutls_datum_t * p,
238                                              gnutls_datum_t * q,
239                                              gnutls_datum_t * u);
240
241   int gnutls_openpgp_privkey_export (gnutls_openpgp_privkey_t key,
242                                      gnutls_openpgp_crt_fmt_t format,
243                                      const char *password,
244                                      unsigned int flags,
245                                      void *output_data,
246                                      size_t * output_data_size);
247
248   int
249     gnutls_openpgp_privkey_set_preferred_key_id (gnutls_openpgp_privkey_t key,
250                                                  const gnutls_openpgp_keyid_t
251                                                  keyid);
252   int gnutls_openpgp_privkey_get_preferred_key_id (gnutls_openpgp_privkey_t
253                                                    key,
254                                                    gnutls_openpgp_keyid_t
255                                                    keyid);
256
257   int gnutls_openpgp_crt_get_auth_subkey (gnutls_openpgp_crt_t crt,
258                                           gnutls_openpgp_keyid_t keyid,
259                                           unsigned int flag);
260
261 /* Keyring stuff.
262  */
263
264   int gnutls_openpgp_keyring_init (gnutls_openpgp_keyring_t * keyring);
265   void gnutls_openpgp_keyring_deinit (gnutls_openpgp_keyring_t keyring);
266
267   int gnutls_openpgp_keyring_import (gnutls_openpgp_keyring_t keyring,
268                                      const gnutls_datum_t * data,
269                                      gnutls_openpgp_crt_fmt_t format);
270
271   int gnutls_openpgp_keyring_check_id (gnutls_openpgp_keyring_t ring,
272                                        const gnutls_openpgp_keyid_t keyid,
273                                        unsigned int flags);
274
275
276   int gnutls_openpgp_crt_verify_ring (gnutls_openpgp_crt_t key,
277                                       gnutls_openpgp_keyring_t keyring,
278                                       unsigned int flags, unsigned int *verify
279                                       /* the output of the verification */ );
280
281   int gnutls_openpgp_crt_verify_self (gnutls_openpgp_crt_t key,
282                                       unsigned int flags,
283                                       unsigned int *verify);
284
285   int gnutls_openpgp_keyring_get_crt (gnutls_openpgp_keyring_t ring,
286                                       unsigned int idx,
287                                       gnutls_openpgp_crt_t * cert);
288
289   int gnutls_openpgp_keyring_get_crt_count (gnutls_openpgp_keyring_t ring);
290
291
292
293 /**
294  * gnutls_openpgp_recv_key_func:
295  * @session: a TLS session
296  * @keyfpr: key fingerprint
297  * @keyfpr_length: length of key fingerprint
298  * @key: output key.
299  *
300  * A callback of this type is used to retrieve OpenPGP keys.  Only
301  * useful on the server, and will only be used if the peer send a key
302  * fingerprint instead of a full key.  See also
303  * gnutls_openpgp_set_recv_key_function().
304  *
305  * Returns: On success, %GNUTLS_E_SUCCESS (zero) is returned,
306  *   otherwise an error code is returned.
307  */
308   typedef int (*gnutls_openpgp_recv_key_func) (gnutls_session_t session,
309                                                const unsigned char *keyfpr,
310                                                unsigned int keyfpr_length,
311                                                gnutls_datum_t * key);
312
313   void
314     gnutls_openpgp_set_recv_key_function (gnutls_session_t session,
315                                           gnutls_openpgp_recv_key_func func);
316
317
318
319 /* certificate authentication stuff.
320  */
321   int gnutls_certificate_set_openpgp_key (gnutls_certificate_credentials_t
322                                           res, gnutls_openpgp_crt_t key,
323                                           gnutls_openpgp_privkey_t pkey);
324
325   int
326     gnutls_certificate_set_openpgp_key_file (gnutls_certificate_credentials_t
327                                              res, const char *certfile,
328                                              const char *keyfile,
329                                              gnutls_openpgp_crt_fmt_t format);
330   int gnutls_certificate_set_openpgp_key_mem (gnutls_certificate_credentials_t
331                                               res,
332                                               const gnutls_datum_t * cert,
333                                               const gnutls_datum_t * key,
334                                               gnutls_openpgp_crt_fmt_t
335                                               format);
336
337   int
338     gnutls_certificate_set_openpgp_key_file2 (gnutls_certificate_credentials_t
339                                               res, const char *certfile,
340                                               const char *keyfile,
341                                               const char *subkey_id,
342                                               gnutls_openpgp_crt_fmt_t
343                                               format);
344   int
345     gnutls_certificate_set_openpgp_key_mem2 (gnutls_certificate_credentials_t
346                                              res, const gnutls_datum_t * cert,
347                                              const gnutls_datum_t * key,
348                                              const char *subkey_id,
349                                              gnutls_openpgp_crt_fmt_t format);
350
351   int
352     gnutls_certificate_set_openpgp_keyring_mem
353     (gnutls_certificate_credentials_t c, const unsigned char *data,
354      size_t dlen, gnutls_openpgp_crt_fmt_t format);
355
356   int
357     gnutls_certificate_set_openpgp_keyring_file
358     (gnutls_certificate_credentials_t c, const char *file,
359      gnutls_openpgp_crt_fmt_t format);
360
361 #ifdef __cplusplus
362 }
363 #endif
364
365 #endif                          /* GNUTLS_OPENPGP_H */