Imported Upstream version 3.4.11
[platform/upstream/gnutls.git] / src / certtool-common.h
1 /*
2  * Copyright (C) 2003-2012 Free Software Foundation, Inc.
3  *
4  * This file is part of GnuTLS.
5  *
6  * GnuTLS is free software: you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * GnuTLS is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see
18  * <http://www.gnu.org/licenses/>.
19  */
20
21 #ifndef CERTTOOL_COMMON_H
22 #define CERTTOOL_COMMON_H
23
24 #include <gnutls/x509.h>
25 #include <stdio.h>
26
27 #define TYPE_CRT 1
28 #define TYPE_CRQ 2
29
30 void certtool_version(void);
31
32 #include <gnutls/x509.h>
33 #include <gnutls/abstract.h>
34
35 typedef struct common_info {
36         const char *secret_key;
37         const char *privkey;
38         const char *pubkey;
39         int pkcs8;
40         int incert_format;
41         int outcert_format;
42         const char *cert;
43
44         const char *request;
45         const char *crl;
46         const char *ca;
47         const char *data_file;
48         const char *ca_privkey;
49         unsigned bits;
50         const char *sec_param;
51         const char *pkcs_cipher;
52         const char *password;
53         int null_password;
54         int empty_password;
55         unsigned int crq_extensions;
56         unsigned int v1_cert;
57
58         const char *pin;
59         const char *so_pin;
60
61         int cprint;
62         unsigned key_usage;
63
64         unsigned int batch;
65         /* when printing PKCS #11 objects, only print urls */
66         unsigned int only_urls;
67         unsigned int verbose;
68 } common_info_st;
69
70 gnutls_pubkey_t load_public_key_or_import(int mand,
71                                           gnutls_privkey_t privkey,
72                                           common_info_st * info);
73 gnutls_privkey_t load_private_key(int mand, common_info_st * info);
74 gnutls_x509_privkey_t load_x509_private_key(int mand,
75                                             common_info_st * info);
76 gnutls_x509_privkey_t *load_privkey_list(int mand, size_t * privkey_size,
77                                          common_info_st * info);
78 gnutls_x509_crq_t load_request(common_info_st * info);
79 gnutls_privkey_t load_ca_private_key(common_info_st * info);
80 gnutls_x509_crt_t load_ca_cert(unsigned mand, common_info_st * info);
81 gnutls_x509_crt_t load_cert(int mand, common_info_st * info);
82 gnutls_datum_t *load_secret_key(int mand, common_info_st * info);
83 gnutls_pubkey_t load_pubkey(int mand, common_info_st * info);
84 gnutls_x509_crt_t *load_cert_list(int mand, size_t * size,
85                                   common_info_st * info);
86 gnutls_x509_crl_t *load_crl_list(int mand, size_t * size,
87                                   common_info_st * info);
88 int get_bits(gnutls_pk_algorithm_t key_type, int info_bits,
89              const char *info_sec_param, int warn);
90
91 gnutls_sec_param_t str_to_sec_param(const char *str);
92 gnutls_ecc_curve_t str_to_curve(const char *str);
93
94 /* prime.c */
95 int generate_prime(FILE * outfile, int how, common_info_st * info);
96 void dh_info(FILE * infile, FILE * outfile, common_info_st * ci);
97
98 gnutls_x509_privkey_t *load_privkey_list(int mand, size_t * privkey_size,
99                                          common_info_st * info);
100
101 void _pubkey_info(FILE * outfile, gnutls_certificate_print_formats_t,
102                   gnutls_pubkey_t pubkey);
103 void print_ecc_pkey(FILE * outfile, gnutls_ecc_curve_t curve,
104                     gnutls_datum_t * k, gnutls_datum_t * x,
105                     gnutls_datum_t * y, int cprint);
106 void print_rsa_pkey(FILE * outfile, gnutls_datum_t * m, gnutls_datum_t * e,
107                     gnutls_datum_t * d, gnutls_datum_t * p,
108                     gnutls_datum_t * q, gnutls_datum_t * u,
109                     gnutls_datum_t * exp1, gnutls_datum_t * exp2,
110                     int cprint);
111 void print_dsa_pkey(FILE * outfile, gnutls_datum_t * x, gnutls_datum_t * y,
112                     gnutls_datum_t * p, gnutls_datum_t * q,
113                     gnutls_datum_t * g, int cprint);
114
115 FILE *safe_open_rw(const char *file, int privkey_op);
116
117 const char *get_password(common_info_st * cinfo, unsigned int *flags,
118                          int confirm);
119
120 extern unsigned char *lbuffer;
121 extern unsigned long lbuffer_size;
122
123 void fix_lbuffer(unsigned long);
124
125 #endif