Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (C) 2000-2012 Free Software Foundation, Inc. |
3 | | * |
4 | | * Author: Nikos Mavrogiannopoulos |
5 | | * |
6 | | * This file is part of GnuTLS. |
7 | | * |
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 2.1 of |
11 | | * the License, or (at your option) any later version. |
12 | | * |
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. |
17 | | * |
18 | | * You should have received a copy of the GNU Lesser General Public License |
19 | | * along with this program. If not, see <https://www.gnu.org/licenses/> |
20 | | * |
21 | | */ |
22 | | |
23 | | #ifndef GNUTLS_LIB_ERRORS_H |
24 | | # define GNUTLS_LIB_ERRORS_H |
25 | | |
26 | | # include "gnutls_int.h" |
27 | | # include <global.h> |
28 | | # include <mpi.h> |
29 | | # include <gnutls/x509.h> |
30 | | |
31 | | # ifdef __FILE__ |
32 | | # ifdef __LINE__ |
33 | 0 | # define gnutls_assert() _gnutls_assert_log( "ASSERT: %s[%s]:%d\n", __FILE__,__func__,__LINE__); |
34 | | # else |
35 | | # define gnutls_assert() |
36 | | # endif |
37 | | # else /* __FILE__ not defined */ |
38 | | # define gnutls_assert() |
39 | | # endif |
40 | | |
41 | | inline static int _gnutls_asn2err(int asn_err) __GNUTLS_CONST__; |
42 | | |
43 | | inline static int _gnutls_asn2err(int asn_err) |
44 | 0 | { |
45 | 0 | switch (asn_err) { |
46 | 0 | # ifdef ASN1_TIME_ENCODING_ERROR |
47 | 0 | case ASN1_TIME_ENCODING_ERROR: |
48 | 0 | return GNUTLS_E_ASN1_TIME_ERROR; |
49 | 0 | # endif |
50 | 0 | case ASN1_FILE_NOT_FOUND: |
51 | 0 | return GNUTLS_E_FILE_ERROR; |
52 | 0 | case ASN1_ELEMENT_NOT_FOUND: |
53 | 0 | return GNUTLS_E_ASN1_ELEMENT_NOT_FOUND; |
54 | 0 | case ASN1_IDENTIFIER_NOT_FOUND: |
55 | 0 | return GNUTLS_E_ASN1_IDENTIFIER_NOT_FOUND; |
56 | 0 | case ASN1_DER_ERROR: |
57 | 0 | return GNUTLS_E_ASN1_DER_ERROR; |
58 | 0 | case ASN1_VALUE_NOT_FOUND: |
59 | 0 | return GNUTLS_E_ASN1_VALUE_NOT_FOUND; |
60 | 0 | case ASN1_GENERIC_ERROR: |
61 | 0 | return GNUTLS_E_ASN1_GENERIC_ERROR; |
62 | 0 | case ASN1_VALUE_NOT_VALID: |
63 | 0 | return GNUTLS_E_ASN1_VALUE_NOT_VALID; |
64 | 0 | case ASN1_TAG_ERROR: |
65 | 0 | return GNUTLS_E_ASN1_TAG_ERROR; |
66 | 0 | case ASN1_TAG_IMPLICIT: |
67 | 0 | return GNUTLS_E_ASN1_TAG_IMPLICIT; |
68 | 0 | case ASN1_ERROR_TYPE_ANY: |
69 | 0 | return GNUTLS_E_ASN1_TYPE_ANY_ERROR; |
70 | 0 | case ASN1_SYNTAX_ERROR: |
71 | 0 | return GNUTLS_E_ASN1_SYNTAX_ERROR; |
72 | 0 | case ASN1_MEM_ERROR: |
73 | 0 | return GNUTLS_E_SHORT_MEMORY_BUFFER; |
74 | 0 | case ASN1_MEM_ALLOC_ERROR: |
75 | 0 | return GNUTLS_E_MEMORY_ERROR; |
76 | 0 | case ASN1_DER_OVERFLOW: |
77 | 0 | return GNUTLS_E_ASN1_DER_OVERFLOW; |
78 | 0 | default: |
79 | 0 | return GNUTLS_E_ASN1_GENERIC_ERROR; |
80 | 0 | } |
81 | 0 | } Unexecuted instantiation: privkey.c:_gnutls_asn2err Unexecuted instantiation: common.c:_gnutls_asn2err Unexecuted instantiation: crl.c:_gnutls_asn2err Unexecuted instantiation: crq.c:_gnutls_asn2err Unexecuted instantiation: dn.c:_gnutls_asn2err Unexecuted instantiation: extensions.c:_gnutls_asn2err Unexecuted instantiation: hostname-verify.c:_gnutls_asn2err Unexecuted instantiation: key_decode.c:_gnutls_asn2err Unexecuted instantiation: key_encode.c:_gnutls_asn2err Unexecuted instantiation: mpi.c:_gnutls_asn2err Unexecuted instantiation: ocsp.c:_gnutls_asn2err Unexecuted instantiation: output.c:_gnutls_asn2err Unexecuted instantiation: pkcs12.c:_gnutls_asn2err Unexecuted instantiation: pkcs12_bag.c:_gnutls_asn2err Unexecuted instantiation: pkcs12_encr.c:_gnutls_asn2err Unexecuted instantiation: pkcs7-crypt.c:_gnutls_asn2err Unexecuted instantiation: privkey_openssl.c:_gnutls_asn2err Unexecuted instantiation: privkey_pkcs8.c:_gnutls_asn2err Unexecuted instantiation: privkey_pkcs8_pbes1.c:_gnutls_asn2err Unexecuted instantiation: prov-seed.c:_gnutls_asn2err Unexecuted instantiation: sign.c:_gnutls_asn2err Unexecuted instantiation: time.c:_gnutls_asn2err Unexecuted instantiation: tls_features.c:_gnutls_asn2err Unexecuted instantiation: verify-high.c:_gnutls_asn2err Unexecuted instantiation: verify-high2.c:_gnutls_asn2err Unexecuted instantiation: verify.c:_gnutls_asn2err Unexecuted instantiation: virt-san.c:_gnutls_asn2err Unexecuted instantiation: x509.c:_gnutls_asn2err Unexecuted instantiation: x509_dn.c:_gnutls_asn2err Unexecuted instantiation: x509_ext.c:_gnutls_asn2err Unexecuted instantiation: x509_write.c:_gnutls_asn2err Unexecuted instantiation: attributes.c:_gnutls_asn2err Unexecuted instantiation: email-verify.c:_gnutls_asn2err Unexecuted instantiation: ip.c:_gnutls_asn2err Unexecuted instantiation: krb5.c:_gnutls_asn2err Unexecuted instantiation: name_constraints.c:_gnutls_asn2err |
82 | | |
83 | | void _gnutls_log(int, const char *fmt, ...) |
84 | | # ifdef __GNUC__ |
85 | | __attribute__((format(printf, 2, 3))); |
86 | | # else |
87 | | ; |
88 | | # endif |
89 | | |
90 | | void _gnutls_audit_log(gnutls_session_t, const char *fmt, ...) |
91 | | # ifdef __GNUC__ |
92 | | __attribute__((format(printf, 2, 3))); |
93 | | # else |
94 | | ; |
95 | | # endif |
96 | | |
97 | | void _gnutls_mpi_log(const char *prefix, bigint_t a); |
98 | | |
99 | | # define _gnutls_cert_log(str, cert) \ |
100 | 0 | do { \ |
101 | 0 | if (unlikely(_gnutls_log_level >= 3)) { \ |
102 | 0 | gnutls_datum_t _cl_out; int _cl_ret; \ |
103 | 0 | _cl_ret = gnutls_x509_crt_print(cert, GNUTLS_CRT_PRINT_ONELINE, &_cl_out); \ |
104 | 0 | if (_cl_ret >= 0) { \ |
105 | 0 | _gnutls_log( 3, "%s: %s\n", str, _cl_out.data); \ |
106 | 0 | gnutls_free(_cl_out.data); \ |
107 | 0 | } \ |
108 | 0 | } \ |
109 | 0 | } while(0) |
110 | | |
111 | | # define _gnutls_dn_log(str, dn) \ |
112 | | do { \ |
113 | | if (unlikely(_gnutls_log_level >= 3)) { \ |
114 | | gnutls_datum_t _cl_out; int _cl_ret; \ |
115 | | _cl_ret = gnutls_x509_rdn_get2((dn), &_cl_out, 0); \ |
116 | | if (_cl_ret >= 0) { \ |
117 | | _gnutls_log( 3, "%s: %s\n", str, _cl_out.data); \ |
118 | | gnutls_free(_cl_out.data); \ |
119 | | } \ |
120 | | } \ |
121 | | } while(0) |
122 | | |
123 | | # define _gnutls_reason_log(str, status) \ |
124 | 0 | do { \ |
125 | 0 | if (unlikely(_gnutls_log_level >= 3)) { \ |
126 | 0 | gnutls_datum_t _cl_out; int _cl_ret; \ |
127 | 0 | _cl_ret = gnutls_certificate_verification_status_print(status, GNUTLS_CRT_X509, &_cl_out, 0); \ |
128 | 0 | if (_cl_ret >= 0) { \ |
129 | 0 | _gnutls_log( 3, "%s: %s\n", str, _cl_out.data); \ |
130 | 0 | gnutls_free(_cl_out.data); \ |
131 | 0 | } \ |
132 | 0 | } \ |
133 | 0 | } while(0) |
134 | | |
135 | | # ifdef C99_MACROS |
136 | 0 | # define LEVEL(l, ...) do { if (unlikely(_gnutls_log_level >= l)) \ |
137 | 0 | _gnutls_log( l, __VA_ARGS__); } while(0) |
138 | | |
139 | 0 | # define _gnutls_debug_log(...) LEVEL(2, __VA_ARGS__) |
140 | 0 | # define _gnutls_assert_log(...) LEVEL(3, __VA_ARGS__) |
141 | | # define _gnutls_handshake_log(...) LEVEL(4, __VA_ARGS__) |
142 | | # define _gnutls_record_log(...) LEVEL(5, __VA_ARGS__) |
143 | | # define _gnutls_dtls_log(...) LEVEL(6, __VA_ARGS__) |
144 | | |
145 | 0 | # define _gnutls_hard_log(...) LEVEL(9, __VA_ARGS__) |
146 | | |
147 | | # define _gnutls_read_log(...) LEVEL(10, __VA_ARGS__) |
148 | | # define _gnutls_write_log(...) LEVEL(11, __VA_ARGS__) |
149 | | # define _gnutls_io_log(...) LEVEL(12, __VA_ARGS__) |
150 | | # define _gnutls_buffers_log(...) LEVEL(13, __VA_ARGS__) |
151 | | # define _gnutls_no_log(...) LEVEL(INT_MAX, __VA_ARGS__) |
152 | | # else |
153 | | # define _gnutls_debug_log _gnutls_null_log |
154 | | # define _gnutls_assert_log _gnutls_null_log |
155 | | # define _gnutls_handshake_log _gnutls_null_log |
156 | | # define _gnutls_io_log _gnutls_null_log |
157 | | # define _gnutls_buffers_log _gnutls_null_log |
158 | | # define _gnutls_hard_log _gnutls_null_log |
159 | | # define _gnutls_record_log _gnutls_null_log |
160 | | # define _gnutls_dtls_log _gnutls_null_log |
161 | | # define _gnutls_read_log _gnutls_null_log |
162 | | # define _gnutls_write_log _gnutls_null_log |
163 | | # define _gnutls_no_log _gnutle_null_log |
164 | | |
165 | | void _gnutls_null_log(void *, ...); |
166 | | |
167 | | # endif /* C99_MACROS */ |
168 | | |
169 | | /* GCC won't inline this by itself and results in a "fatal warning" |
170 | | otherwise. Making this a macro has been tried, but it interacts |
171 | | badly with the do..while in the expansion. Welcome to the dark |
172 | | side. */ |
173 | | static inline |
174 | | # ifdef __GNUC__ |
175 | | __attribute__((always_inline)) |
176 | | # endif |
177 | | int gnutls_assert_val_int(int val, const char *file, const char *func, int line) |
178 | 0 | { |
179 | 0 | _gnutls_assert_log("ASSERT: %s[%s]:%d\n", file, func, line); |
180 | 0 | return val; |
181 | 0 | } Unexecuted instantiation: common.c:gnutls_assert_val_int Unexecuted instantiation: crl.c:gnutls_assert_val_int Unexecuted instantiation: crq.c:gnutls_assert_val_int Unexecuted instantiation: dn.c:gnutls_assert_val_int Unexecuted instantiation: extensions.c:gnutls_assert_val_int Unexecuted instantiation: hostname-verify.c:gnutls_assert_val_int Unexecuted instantiation: key_decode.c:gnutls_assert_val_int Unexecuted instantiation: key_encode.c:gnutls_assert_val_int Unexecuted instantiation: mpi.c:gnutls_assert_val_int Unexecuted instantiation: ocsp.c:gnutls_assert_val_int Unexecuted instantiation: output.c:gnutls_assert_val_int Unexecuted instantiation: pkcs12.c:gnutls_assert_val_int Unexecuted instantiation: pkcs12_bag.c:gnutls_assert_val_int Unexecuted instantiation: pkcs12_encr.c:gnutls_assert_val_int Unexecuted instantiation: pkcs7-crypt.c:gnutls_assert_val_int Unexecuted instantiation: privkey_openssl.c:gnutls_assert_val_int Unexecuted instantiation: privkey_pkcs8.c:gnutls_assert_val_int Unexecuted instantiation: privkey_pkcs8_pbes1.c:gnutls_assert_val_int Unexecuted instantiation: prov-seed.c:gnutls_assert_val_int Unexecuted instantiation: sign.c:gnutls_assert_val_int Unexecuted instantiation: time.c:gnutls_assert_val_int Unexecuted instantiation: tls_features.c:gnutls_assert_val_int Unexecuted instantiation: verify-high.c:gnutls_assert_val_int Unexecuted instantiation: verify-high2.c:gnutls_assert_val_int Unexecuted instantiation: verify.c:gnutls_assert_val_int Unexecuted instantiation: virt-san.c:gnutls_assert_val_int Unexecuted instantiation: x509.c:gnutls_assert_val_int Unexecuted instantiation: x509_dn.c:gnutls_assert_val_int Unexecuted instantiation: x509_ext.c:gnutls_assert_val_int Unexecuted instantiation: x509_write.c:gnutls_assert_val_int Unexecuted instantiation: attributes.c:gnutls_assert_val_int Unexecuted instantiation: email-verify.c:gnutls_assert_val_int Unexecuted instantiation: ip.c:gnutls_assert_val_int Unexecuted instantiation: krb5.c:gnutls_assert_val_int Unexecuted instantiation: name_constraints.c:gnutls_assert_val_int |
182 | | |
183 | 0 | # define gnutls_assert_val(x) gnutls_assert_val_int(x, __FILE__, __func__, __LINE__) |
184 | | # define gnutls_assert_val_fatal(x) (((x)!=GNUTLS_E_AGAIN && (x)!=GNUTLS_E_INTERRUPTED)?gnutls_assert_val_int(x, __FILE__, __func__, __LINE__):(x)) |
185 | | |
186 | | #endif /* GNUTLS_LIB_ERRORS_H */ |