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/>
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"
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_string (unsigned int etype
,
72 const uint8_t * der
, size_t der_size
,
73 gnutls_datum_t
*output
);
75 int _gnutls_x509_encode_string(unsigned int etype
,
76 const void* input_data
, size_t input_size
,
77 gnutls_datum_t
* output
);
79 int _gnutls_x509_dn_to_string (const char *OID
, void *value
,
80 int value_size
, gnutls_datum_t
* out
);
81 int _gnutls_x509_data2hex (const void * data
, size_t data_size
,
82 void * out
, size_t * sizeof_out
);
84 time_t _gnutls_x509_get_time (ASN1_TYPE c2
, const char *when
, int general
);
86 gnutls_x509_subject_alt_name_t
_gnutls_x509_san_find_type (char *str_type
);
88 int _gnutls_x509_der_encode_and_copy (ASN1_TYPE src
, const char *src_name
,
89 ASN1_TYPE dest
, const char *dest_name
,
91 int _gnutls_x509_der_encode (ASN1_TYPE src
, const char *src_name
,
92 gnutls_datum_t
* res
, int str
);
94 #define _gnutls_x509_export_int(asn1, format, header, out, out_size) \
95 _gnutls_x509_export_int_named(asn1, "", format, header, out, out_size)
97 int _gnutls_x509_export_int_named (ASN1_TYPE asn1_data
, const char *name
,
98 gnutls_x509_crt_fmt_t format
,
99 const char *pem_header
,
100 unsigned char *output_data
,
101 size_t * output_data_size
);
103 #define _gnutls_x509_export_int2(asn1, format, header, out) \
104 _gnutls_x509_export_int_named2(asn1, "", format, header, out)
105 int _gnutls_x509_export_int_named2 (ASN1_TYPE asn1_data
, const char *name
,
106 gnutls_x509_crt_fmt_t format
,
107 const char *pem_header
,
108 gnutls_datum_t
* out
);
110 int _gnutls_x509_read_value (ASN1_TYPE c
, const char *root
,
111 gnutls_datum_t
* ret
);
112 int _gnutls_x509_read_string (ASN1_TYPE c
, const char *root
,
113 gnutls_datum_t
* ret
, unsigned int etype
);
114 int _gnutls_x509_write_value (ASN1_TYPE c
, const char *root
,
115 const gnutls_datum_t
* data
);
117 int _gnutls_x509_write_string (ASN1_TYPE c
, const char *root
,
118 const gnutls_datum_t
* data
, unsigned int etype
);
120 int _gnutls_x509_encode_and_write_attribute (const char *given_oid
,
121 ASN1_TYPE asn1_struct
,
124 int sizeof_data
, int multi
);
125 int _gnutls_x509_decode_and_read_attribute (ASN1_TYPE asn1_struct
,
126 const char *where
, char *oid
,
128 gnutls_datum_t
* value
, int multi
,
131 int _gnutls_x509_get_pk_algorithm (ASN1_TYPE src
, const char *src_name
,
135 _gnutls_x509_get_signature_algorithm (ASN1_TYPE src
, const char *src_name
);
137 int _gnutls_x509_encode_and_copy_PKI_params (ASN1_TYPE dst
,
138 const char *dst_name
,
139 gnutls_pk_algorithm_t
140 pk_algorithm
, gnutls_pk_params_st
* params
);
141 int _gnutls_x509_encode_PKI_params(gnutls_datum_t
* der
,
142 gnutls_pk_algorithm_t
, gnutls_pk_params_st
* params
);
143 int _gnutls_asn1_copy_node (ASN1_TYPE
* dst
, const char *dst_name
,
144 ASN1_TYPE src
, const char *src_name
);
146 int _gnutls_x509_get_signed_data (ASN1_TYPE src
, const char *src_name
,
147 gnutls_datum_t
* signed_data
);
148 int _gnutls_x509_get_signature (ASN1_TYPE src
, const char *src_name
,
149 gnutls_datum_t
* signature
);
152 int _gnutls_get_asn_mpis (ASN1_TYPE asn
, const char *root
,
153 gnutls_pk_params_st
* params
);
155 int _gnutls_get_key_id (gnutls_pk_algorithm_t pk
, gnutls_pk_params_st
*,
156 unsigned char *output_data
,
157 size_t * output_data_size
);
159 void _asnstr_append_name (char *name
, size_t name_size
, const char *part1
,
163 check_if_same_cert (gnutls_x509_crt_t cert1
, gnutls_x509_crt_t cert2
);
165 time_t _gnutls_x509_generalTime2gtime (const char *ttime
);
167 int get_extension (ASN1_TYPE asn
, const char *root
,
168 const char *extension_id
, int indx
,
169 gnutls_datum_t
* ret
, unsigned int *_critical
);
171 int set_extension (ASN1_TYPE asn
, const char *root
,
173 const gnutls_datum_t
* ext_data
, unsigned int critical
);
175 int _gnutls_strdatum_to_buf (gnutls_datum_t
* d
, void* buf
, size_t * sizeof_buf
);