Use the new asn1_read_node_value()
[gnutls.git] / lib / x509 / common.h
blob1d7116ccb6e51c72181298f96b01af87fbf9f83d
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 int _gnutls_x509_set_time (ASN1_TYPE c2, const char *where, time_t tim, int general);
71 int _gnutls_x509_decode_octet_string (const char *string_type,
72 const uint8_t * der, size_t der_size,
73 uint8_t * output, size_t * output_size);
74 int _gnutls_x509_oid_data2string (const char *OID, void *value,
75 int value_size, char *res,
76 size_t * res_size);
77 int _gnutls_x509_data2hex (const void * data, size_t data_size,
78 void * out, size_t * sizeof_out);
80 const char *_gnutls_x509_oid2asn_string (const char *oid);
82 int _gnutls_x509_oid_data_choice (const char *OID);
83 int _gnutls_x509_oid_data_printable (const char *OID);
85 time_t _gnutls_x509_get_time (ASN1_TYPE c2, const char *when, int general);
87 gnutls_x509_subject_alt_name_t _gnutls_x509_san_find_type (char *str_type);
89 int _gnutls_x509_der_encode_and_copy (ASN1_TYPE src, const char *src_name,
90 ASN1_TYPE dest, const char *dest_name,
91 int str);
92 int _gnutls_x509_der_encode (ASN1_TYPE src, const char *src_name,
93 gnutls_datum_t * res, int str);
95 int _gnutls_x509_export_int (ASN1_TYPE asn1_data,
96 gnutls_x509_crt_fmt_t format,
97 const char *pem_header,
98 unsigned char *output_data,
99 size_t * output_data_size);
101 int _gnutls_x509_export_int_named (ASN1_TYPE asn1_data, const char *name,
102 gnutls_x509_crt_fmt_t format,
103 const char *pem_header,
104 unsigned char *output_data,
105 size_t * output_data_size);
107 int _gnutls_x509_read_value (ASN1_TYPE c, const char *root,
108 gnutls_datum_t * ret, int str);
109 int _gnutls_x509_write_value (ASN1_TYPE c, const char *root,
110 const gnutls_datum_t * data, int str);
112 int _gnutls_x509_encode_and_write_attribute (const char *given_oid,
113 ASN1_TYPE asn1_struct,
114 const char *where,
115 const void *data,
116 int sizeof_data, int multi);
117 int _gnutls_x509_decode_and_read_attribute (ASN1_TYPE asn1_struct,
118 const char *where, char *oid,
119 int oid_size,
120 gnutls_datum_t * value, int multi,
121 int octet);
123 int _gnutls_x509_get_pk_algorithm (ASN1_TYPE src, const char *src_name,
124 unsigned int *bits);
127 _gnutls_x509_get_signature_algorithm (ASN1_TYPE src, const char *src_name);
129 int _gnutls_x509_encode_and_copy_PKI_params (ASN1_TYPE dst,
130 const char *dst_name,
131 gnutls_pk_algorithm_t
132 pk_algorithm, gnutls_pk_params_st * params);
133 int _gnutls_x509_encode_PKI_params(gnutls_datum_t* der,
134 gnutls_pk_algorithm_t, gnutls_pk_params_st* params);
135 int _gnutls_asn1_copy_node (ASN1_TYPE * dst, const char *dst_name,
136 ASN1_TYPE src, const char *src_name);
138 int _gnutls_x509_get_signed_data (ASN1_TYPE src, const char *src_name,
139 gnutls_datum_t * signed_data);
140 int _gnutls_x509_get_signature (ASN1_TYPE src, const char *src_name,
141 gnutls_datum_t * signature);
144 int _gnutls_get_asn_mpis (ASN1_TYPE asn, const char *root,
145 gnutls_pk_params_st * params);
147 int _gnutls_get_key_id (gnutls_pk_algorithm_t pk, gnutls_pk_params_st*,
148 unsigned char *output_data,
149 size_t * output_data_size);
151 void _asnstr_append_name (char *name, size_t name_size, const char *part1,
152 const char *part2);
155 check_if_same_cert (gnutls_x509_crt_t cert1, gnutls_x509_crt_t cert2);
157 time_t _gnutls_x509_generalTime2gtime (const char *ttime);
159 int get_extension (ASN1_TYPE asn, const char *root,
160 const char *extension_id, int indx,
161 gnutls_datum_t * ret, unsigned int *_critical);
163 int set_extension (ASN1_TYPE asn, const char *root,
164 const char *ext_id,
165 const gnutls_datum_t * ext_data, unsigned int critical);
167 #endif