check for either iconv or libiconv.
[gnutls.git] / lib / x509 / common.h
blob4b38884434492e893951df9a5c852477d1f6bdde
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 COMMON_H
24 #define COMMON_H
26 #include <algorithms.h>
27 #include <abstract_int.h>
28 #include <x509/x509_int.h>
30 #define MAX_STRING_LEN 512
32 #define GNUTLS_XML_SHOW_ALL 1
34 #define PEM_CRL "X509 CRL"
35 #define PEM_X509_CERT "X509 CERTIFICATE"
36 #define PEM_X509_CERT2 "CERTIFICATE"
37 #define PEM_PKCS7 "PKCS7"
38 #define PEM_PKCS12 "PKCS12"
40 /* public key algorithm's OIDs
42 #define PK_PKIX1_RSA_OID "1.2.840.113549.1.1.1"
43 #define PK_X509_RSA_OID "2.5.8.1.1"
44 #define PK_DSA_OID "1.2.840.10040.4.1"
45 #define PK_GOST_R3410_94_OID "1.2.643.2.2.20"
46 #define PK_GOST_R3410_2001_OID "1.2.643.2.2.19"
48 /* signature OIDs
50 #define SIG_DSA_SHA1_OID "1.2.840.10040.4.3"
51 /* those two from draft-ietf-pkix-sha2-dsa-ecdsa-06 */
52 #define SIG_DSA_SHA224_OID "2.16.840.1.101.3.4.3.1"
53 #define SIG_DSA_SHA256_OID "2.16.840.1.101.3.4.3.2"
55 #define SIG_RSA_MD5_OID "1.2.840.113549.1.1.4"
56 #define SIG_RSA_MD2_OID "1.2.840.113549.1.1.2"
57 #define SIG_RSA_SHA1_OID "1.2.840.113549.1.1.5"
58 #define SIG_RSA_SHA224_OID "1.2.840.113549.1.1.14"
59 #define SIG_RSA_SHA256_OID "1.2.840.113549.1.1.11"
60 #define SIG_RSA_SHA384_OID "1.2.840.113549.1.1.12"
61 #define SIG_RSA_SHA512_OID "1.2.840.113549.1.1.13"
62 #define SIG_RSA_RMD160_OID "1.3.36.3.3.1.2"
63 #define SIG_GOST_R3410_94_OID "1.2.643.2.2.4"
64 #define SIG_GOST_R3410_2001_OID "1.2.643.2.2.3"
66 #define ASN1_NULL "\x05\x00"
67 #define ASN1_NULL_SIZE 2
69 typedef enum x509_string_type {
70 RV_RAW,
71 RV_OCTET_STRING,
72 RV_BIT_STRING,
73 RV_IA5STRING,
74 RV_UTF8STRING
75 } x509_string_type;
77 int _gnutls_x509_set_time (ASN1_TYPE c2, const char *where, time_t tim, int general);
79 int _gnutls_x509_decode_string (const char *string_type,
80 const uint8_t * der, size_t der_size,
81 gnutls_datum_t *output);
83 int _gnutls_x509_encode_string(const char* string_type,
84 const void* input_data, size_t input_size,
85 gnutls_datum_t* output);
87 int _gnutls_x509_oid_data2string (const char *OID, void *value,
88 int value_size, char *res,
89 size_t * res_size);
90 int _gnutls_x509_data2hex (const void * data, size_t data_size,
91 void * out, size_t * sizeof_out);
93 const char *_gnutls_x509_oid2asn_string (const char *oid);
95 int _gnutls_x509_oid_data_choice (const char *OID);
96 int _gnutls_x509_oid_data_printable (const char *OID);
98 time_t _gnutls_x509_get_time (ASN1_TYPE c2, const char *when, int general);
100 gnutls_x509_subject_alt_name_t _gnutls_x509_san_find_type (char *str_type);
102 int _gnutls_x509_der_encode_and_copy (ASN1_TYPE src, const char *src_name,
103 ASN1_TYPE dest, const char *dest_name,
104 int str);
105 int _gnutls_x509_der_encode (ASN1_TYPE src, const char *src_name,
106 gnutls_datum_t * res, int str);
108 #define _gnutls_x509_export_int(asn1, format, header, out, out_size) \
109 _gnutls_x509_export_int_named(asn1, "", format, header, out, out_size)
111 int _gnutls_x509_export_int_named (ASN1_TYPE asn1_data, const char *name,
112 gnutls_x509_crt_fmt_t format,
113 const char *pem_header,
114 unsigned char *output_data,
115 size_t * output_data_size);
117 #define _gnutls_x509_export_int2(asn1, format, header, out) \
118 _gnutls_x509_export_int_named2(asn1, "", format, header, out)
119 int _gnutls_x509_export_int_named2 (ASN1_TYPE asn1_data, const char *name,
120 gnutls_x509_crt_fmt_t format,
121 const char *pem_header,
122 gnutls_datum_t * out);
124 int _gnutls_x509_read_value (ASN1_TYPE c, const char *root,
125 gnutls_datum_t * ret);
126 int _gnutls_x509_read_string (ASN1_TYPE c, const char *root,
127 gnutls_datum_t * ret, x509_string_type type);
128 int _gnutls_x509_write_value (ASN1_TYPE c, const char *root,
129 const gnutls_datum_t * data, x509_string_type type);
131 int _gnutls_x509_encode_and_write_attribute (const char *given_oid,
132 ASN1_TYPE asn1_struct,
133 const char *where,
134 const void *data,
135 int sizeof_data, int multi);
136 int _gnutls_x509_decode_and_read_attribute (ASN1_TYPE asn1_struct,
137 const char *where, char *oid,
138 int oid_size,
139 gnutls_datum_t * value, int multi,
140 int octet);
142 int _gnutls_x509_get_pk_algorithm (ASN1_TYPE src, const char *src_name,
143 unsigned int *bits);
146 _gnutls_x509_get_signature_algorithm (ASN1_TYPE src, const char *src_name);
148 int _gnutls_x509_encode_and_copy_PKI_params (ASN1_TYPE dst,
149 const char *dst_name,
150 gnutls_pk_algorithm_t
151 pk_algorithm, gnutls_pk_params_st * params);
152 int _gnutls_x509_encode_PKI_params(gnutls_datum_t* der,
153 gnutls_pk_algorithm_t, gnutls_pk_params_st* params);
154 int _gnutls_asn1_copy_node (ASN1_TYPE * dst, const char *dst_name,
155 ASN1_TYPE src, const char *src_name);
157 int _gnutls_x509_get_signed_data (ASN1_TYPE src, const char *src_name,
158 gnutls_datum_t * signed_data);
159 int _gnutls_x509_get_signature (ASN1_TYPE src, const char *src_name,
160 gnutls_datum_t * signature);
163 int _gnutls_get_asn_mpis (ASN1_TYPE asn, const char *root,
164 gnutls_pk_params_st * params);
166 int _gnutls_get_key_id (gnutls_pk_algorithm_t pk, gnutls_pk_params_st*,
167 unsigned char *output_data,
168 size_t * output_data_size);
170 void _asnstr_append_name (char *name, size_t name_size, const char *part1,
171 const char *part2);
174 check_if_same_cert (gnutls_x509_crt_t cert1, gnutls_x509_crt_t cert2);
176 time_t _gnutls_x509_generalTime2gtime (const char *ttime);
178 int get_extension (ASN1_TYPE asn, const char *root,
179 const char *extension_id, int indx,
180 gnutls_datum_t * ret, unsigned int *_critical);
182 int set_extension (ASN1_TYPE asn, const char *root,
183 const char *ext_id,
184 const gnutls_datum_t * ext_data, unsigned int critical);
186 #endif