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  |  | #include "gnutls_int.h"  | 
24  |  | #include "errors.h"  | 
25  |  | #include <stdarg.h>  | 
26  |  | #include "str.h"  | 
27  |  |  | 
28  |  | #define ERROR_ENTRY(desc, name) { desc, #name, name } | 
29  |  |  | 
30  |  | struct gnutls_error_entry { | 
31  |  |   const char *desc;  | 
32  |  |   const char *_name;  | 
33  |  |   int number;  | 
34  |  | };  | 
35  |  | typedef struct gnutls_error_entry gnutls_error_entry;  | 
36  |  |  | 
37  |  | static const gnutls_error_entry error_entries[] = { | 
38  |  |   /* "Short Description", Error code define, critical (0,1) -- 1 in most cases */  | 
39  |  |   ERROR_ENTRY(N_("Could not negotiate a supported cipher suite."), | 
40  |  |         GNUTLS_E_UNKNOWN_CIPHER_SUITE),  | 
41  |  |   ERROR_ENTRY(N_("No or insufficient priorities were set."), | 
42  |  |         GNUTLS_E_NO_PRIORITIES_WERE_SET),  | 
43  |  |   ERROR_ENTRY(N_("The cipher type is unsupported."), | 
44  |  |         GNUTLS_E_UNKNOWN_CIPHER_TYPE),  | 
45  |  |   ERROR_ENTRY(N_("The certificate and the given key do not match."), | 
46  |  |         GNUTLS_E_CERTIFICATE_KEY_MISMATCH),  | 
47  |  |   ERROR_ENTRY(N_("Could not negotiate a supported compression method."), | 
48  |  |         GNUTLS_E_UNKNOWN_COMPRESSION_ALGORITHM),  | 
49  |  |   ERROR_ENTRY(N_("An unknown public key algorithm was encountered."), | 
50  |  |         GNUTLS_E_UNKNOWN_PK_ALGORITHM),  | 
51  |  |  | 
52  |  |   ERROR_ENTRY(N_("An algorithm that is not enabled was negotiated."), | 
53  |  |         GNUTLS_E_UNWANTED_ALGORITHM),  | 
54  |  |   ERROR_ENTRY(  | 
55  |  |     N_("A packet with illegal or unsupported version was received."), | 
56  |  |     GNUTLS_E_UNSUPPORTED_VERSION_PACKET),  | 
57  |  |   ERROR_ENTRY(  | 
58  |  |     N_("The Diffie-Hellman prime sent by the server is not acceptable (not long enough)."), | 
59  |  |     GNUTLS_E_DH_PRIME_UNACCEPTABLE),  | 
60  |  |   ERROR_ENTRY(N_("Error decoding the received TLS packet."), | 
61  |  |         GNUTLS_E_UNEXPECTED_PACKET_LENGTH),  | 
62  |  |   ERROR_ENTRY(N_("A TLS record packet with invalid length was received."), | 
63  |  |         GNUTLS_E_RECORD_OVERFLOW),  | 
64  |  |   ERROR_ENTRY(N_("The TLS connection was non-properly terminated."), | 
65  |  |         GNUTLS_E_PREMATURE_TERMINATION),  | 
66  |  |   ERROR_ENTRY(  | 
67  |  |     N_("The specified session has been invalidated for some reason."), | 
68  |  |     GNUTLS_E_INVALID_SESSION),  | 
69  |  |  | 
70  |  |   ERROR_ENTRY(N_("GnuTLS internal error."), GNUTLS_E_INTERNAL_ERROR), | 
71  |  |   ERROR_ENTRY(  | 
72  |  |     N_("A connection with inappropriate fallback was attempted."), | 
73  |  |     GNUTLS_E_INAPPROPRIATE_FALLBACK),  | 
74  |  |   ERROR_ENTRY(N_("An illegal TLS extension was received."), | 
75  |  |         GNUTLS_E_RECEIVED_ILLEGAL_EXTENSION),  | 
76  |  |   ERROR_ENTRY(N_("An required TLS extension was received."), | 
77  |  |         GNUTLS_E_MISSING_EXTENSION),  | 
78  |  |   ERROR_ENTRY(N_("A TLS fatal alert has been received."), | 
79  |  |         GNUTLS_E_FATAL_ALERT_RECEIVED),  | 
80  |  |   ERROR_ENTRY(N_("An unexpected TLS packet was received."), | 
81  |  |         GNUTLS_E_UNEXPECTED_PACKET),  | 
82  |  |   ERROR_ENTRY(N_("Failed to import the key into store."), | 
83  |  |         GNUTLS_E_KEY_IMPORT_FAILED),  | 
84  |  |   ERROR_ENTRY(  | 
85  |  |     N_("An error was encountered at the TLS Finished packet calculation."), | 
86  |  |     GNUTLS_E_ERROR_IN_FINISHED_PACKET),  | 
87  |  |   ERROR_ENTRY(N_("No certificate was found."), | 
88  |  |         GNUTLS_E_NO_CERTIFICATE_FOUND),  | 
89  |  |   ERROR_ENTRY(N_("Certificate is required."), | 
90  |  |         GNUTLS_E_CERTIFICATE_REQUIRED),  | 
91  |  |   ERROR_ENTRY(  | 
92  |  |     N_("The given DSA key is incompatible with the selected TLS protocol."), | 
93  |  |     GNUTLS_E_INCOMPAT_DSA_KEY_WITH_TLS_PROTOCOL),  | 
94  |  |   ERROR_ENTRY(  | 
95  |  |     N_("There is already a crypto algorithm with lower priority."), | 
96  |  |     GNUTLS_E_CRYPTO_ALREADY_REGISTERED),  | 
97  |  |  | 
98  |  |   ERROR_ENTRY(N_("No temporary RSA parameters were found."), | 
99  |  |         GNUTLS_E_NO_TEMPORARY_RSA_PARAMS),  | 
100  |  |   ERROR_ENTRY(N_("No temporary DH parameters were found."), | 
101  |  |         GNUTLS_E_NO_TEMPORARY_DH_PARAMS),  | 
102  |  |   ERROR_ENTRY(N_("An unexpected TLS handshake packet was received."), | 
103  |  |         GNUTLS_E_UNEXPECTED_HANDSHAKE_PACKET),  | 
104  |  |   ERROR_ENTRY(N_("The scanning of a large integer has failed."), | 
105  |  |         GNUTLS_E_MPI_SCAN_FAILED),  | 
106  |  |   ERROR_ENTRY(N_("Could not export a large integer."), | 
107  |  |         GNUTLS_E_MPI_PRINT_FAILED),  | 
108  |  |   ERROR_ENTRY(N_("Decryption has failed."), GNUTLS_E_DECRYPTION_FAILED), | 
109  |  |   ERROR_ENTRY(N_("Encryption has failed."), GNUTLS_E_ENCRYPTION_FAILED), | 
110  |  |   ERROR_ENTRY(N_("Public key decryption has failed."), | 
111  |  |         GNUTLS_E_PK_DECRYPTION_FAILED),  | 
112  |  |   ERROR_ENTRY(N_("Public key encryption has failed."), | 
113  |  |         GNUTLS_E_PK_ENCRYPTION_FAILED),  | 
114  |  |   ERROR_ENTRY(N_("Public key signing has failed."), | 
115  |  |         GNUTLS_E_PK_SIGN_FAILED),  | 
116  |  |   ERROR_ENTRY(N_("Public key signature verification has failed."), | 
117  |  |         GNUTLS_E_PK_SIG_VERIFY_FAILED),  | 
118  |  |   ERROR_ENTRY(N_("Decompression of the TLS record packet has failed."), | 
119  |  |         GNUTLS_E_DECOMPRESSION_FAILED),  | 
120  |  |   ERROR_ENTRY(N_("Compression of the TLS record packet has failed."), | 
121  |  |         GNUTLS_E_COMPRESSION_FAILED),  | 
122  |  |  | 
123  |  |   ERROR_ENTRY(N_("Internal error in memory allocation."), | 
124  |  |         GNUTLS_E_MEMORY_ERROR),  | 
125  |  |   ERROR_ENTRY(  | 
126  |  |     N_("An unimplemented or disabled feature has been requested."), | 
127  |  |     GNUTLS_E_UNIMPLEMENTED_FEATURE),  | 
128  |  |   ERROR_ENTRY(N_("Insufficient credentials for that request."), | 
129  |  |         GNUTLS_E_INSUFFICIENT_CREDENTIALS),  | 
130  |  |   ERROR_ENTRY(N_("Error in password/key file."), GNUTLS_E_SRP_PWD_ERROR), | 
131  |  |   ERROR_ENTRY(N_("Wrong padding in PKCS1 packet."), | 
132  |  |         GNUTLS_E_PKCS1_WRONG_PAD),  | 
133  |  |   ERROR_ENTRY(N_("The session or certificate has expired."), | 
134  |  |         GNUTLS_E_EXPIRED),  | 
135  |  |   ERROR_ENTRY(N_("The certificate is not yet activated."), | 
136  |  |         GNUTLS_E_NOT_YET_ACTIVATED),  | 
137  |  |   ERROR_ENTRY(N_("Hashing has failed."), GNUTLS_E_HASH_FAILED), | 
138  |  |   ERROR_ENTRY(N_("Base64 decoding error."), | 
139  |  |         GNUTLS_E_BASE64_DECODING_ERROR),  | 
140  |  |   ERROR_ENTRY(N_("Base64 unexpected header error."), | 
141  |  |         GNUTLS_E_BASE64_UNEXPECTED_HEADER_ERROR),  | 
142  |  |   ERROR_ENTRY(N_("Base64 encoding error."), | 
143  |  |         GNUTLS_E_BASE64_ENCODING_ERROR),  | 
144  |  |   ERROR_ENTRY(N_("Parsing error in password/key file."), | 
145  |  |         GNUTLS_E_SRP_PWD_PARSING_ERROR),  | 
146  |  |   ERROR_ENTRY(N_("The requested data were not available."), | 
147  |  |         GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE),  | 
148  |  |   ERROR_ENTRY(N_("There are no embedded data in the structure."), | 
149  |  |         GNUTLS_E_NO_EMBEDDED_DATA),  | 
150  |  |   ERROR_ENTRY(N_("Error in the pull function."), GNUTLS_E_PULL_ERROR), | 
151  |  |   ERROR_ENTRY(N_("Error in the push function."), GNUTLS_E_PUSH_ERROR), | 
152  |  |   ERROR_ENTRY(  | 
153  |  |     N_("The upper limit of record packet sequence numbers has been reached. Wow!"), | 
154  |  |     GNUTLS_E_RECORD_LIMIT_REACHED),  | 
155  |  |   ERROR_ENTRY(N_("Error in the certificate."), | 
156  |  |         GNUTLS_E_CERTIFICATE_ERROR),  | 
157  |  |   ERROR_ENTRY(N_("Error in the time fields of certificate."), | 
158  |  |         GNUTLS_E_CERTIFICATE_TIME_ERROR),  | 
159  |  |   ERROR_ENTRY(N_("Error in the certificate verification."), | 
160  |  |         GNUTLS_E_CERTIFICATE_VERIFICATION_ERROR),  | 
161  |  |   ERROR_ENTRY(N_("Error in the CRL verification."), | 
162  |  |         GNUTLS_E_CRL_VERIFICATION_ERROR),  | 
163  |  |   ERROR_ENTRY(  | 
164  |  |     N_("Error in the private key verification; seed doesn't match."), | 
165  |  |     GNUTLS_E_PRIVKEY_VERIFICATION_ERROR),  | 
166  |  |   ERROR_ENTRY(N_("Could not authenticate peer."), GNUTLS_E_AUTH_ERROR), | 
167  |  |   ERROR_ENTRY(N_("Unknown Subject Alternative name in X.509 certificate."), | 
168  |  |         GNUTLS_E_X509_UNKNOWN_SAN),  | 
169  |  |   ERROR_ENTRY(  | 
170  |  |     N_("CIDR name constraint is malformed in size or structure."), | 
171  |  |     GNUTLS_E_MALFORMED_CIDR),  | 
172  |  |  | 
173  |  |   ERROR_ENTRY(N_("Unsupported critical extension in X.509 certificate."), | 
174  |  |         GNUTLS_E_X509_UNSUPPORTED_CRITICAL_EXTENSION),  | 
175  |  |   ERROR_ENTRY(N_("Unsupported extension in X.509 certificate."), | 
176  |  |         GNUTLS_E_X509_UNSUPPORTED_EXTENSION),  | 
177  |  |   ERROR_ENTRY(N_("Duplicate extension in X.509 certificate."), | 
178  |  |         GNUTLS_E_X509_DUPLICATE_EXTENSION),  | 
179  |  |   ERROR_ENTRY(N_("Key usage violation in certificate has been detected."), | 
180  |  |         GNUTLS_E_KEY_USAGE_VIOLATION),  | 
181  |  |   ERROR_ENTRY(N_("Function was interrupted."), GNUTLS_E_INTERRUPTED), | 
182  |  |   ERROR_ENTRY(  | 
183  |  |     N_("TLS Application data were received, while expecting handshake data."), | 
184  |  |     GNUTLS_E_GOT_APPLICATION_DATA),  | 
185  |  |   ERROR_ENTRY(N_("Error in Database backend."), GNUTLS_E_DB_ERROR), | 
186  |  |   ERROR_ENTRY(N_("The Database entry already exists."), | 
187  |  |         GNUTLS_E_DB_ENTRY_EXISTS),  | 
188  |  |   ERROR_ENTRY(N_("The certificate type is not supported."), | 
189  |  |         GNUTLS_E_UNSUPPORTED_CERTIFICATE_TYPE),  | 
190  |  |   ERROR_ENTRY(  | 
191  |  |     N_("The given memory buffer is too short to hold parameters."), | 
192  |  |     GNUTLS_E_SHORT_MEMORY_BUFFER),  | 
193  |  |   ERROR_ENTRY(N_("The request is invalid."), GNUTLS_E_INVALID_REQUEST), | 
194  |  |   ERROR_ENTRY(N_("The cookie was bad."), GNUTLS_E_BAD_COOKIE), | 
195  |  |   ERROR_ENTRY(N_("An illegal parameter has been received."), | 
196  |  |         GNUTLS_E_RECEIVED_ILLEGAL_PARAMETER),  | 
197  |  |   ERROR_ENTRY(N_("An illegal parameter was found."), | 
198  |  |         GNUTLS_E_ILLEGAL_PARAMETER),  | 
199  |  |   ERROR_ENTRY(N_("Error while reading file."), GNUTLS_E_FILE_ERROR), | 
200  |  |   ERROR_ENTRY(N_("A disallowed SNI server name has been received."), | 
201  |  |         GNUTLS_E_RECEIVED_DISALLOWED_NAME),  | 
202  |  |  | 
203  |  |   ERROR_ENTRY(N_("ASN1 parser: Element was not found."), | 
204  |  |         GNUTLS_E_ASN1_ELEMENT_NOT_FOUND),  | 
205  |  |   ERROR_ENTRY(N_("ASN1 parser: Identifier was not found"), | 
206  |  |         GNUTLS_E_ASN1_IDENTIFIER_NOT_FOUND),  | 
207  |  |   ERROR_ENTRY(N_("ASN1 parser: Error in DER parsing."), | 
208  |  |         GNUTLS_E_ASN1_DER_ERROR),  | 
209  |  |   ERROR_ENTRY(N_("ASN1 parser: Value was not found."), | 
210  |  |         GNUTLS_E_ASN1_VALUE_NOT_FOUND),  | 
211  |  |   ERROR_ENTRY(N_("ASN1 parser: Generic parsing error."), | 
212  |  |         GNUTLS_E_ASN1_GENERIC_ERROR),  | 
213  |  |   ERROR_ENTRY(N_("ASN1 parser: Value is not valid."), | 
214  |  |         GNUTLS_E_ASN1_VALUE_NOT_VALID),  | 
215  |  |   ERROR_ENTRY(N_("ASN1 parser: Error in TAG."), GNUTLS_E_ASN1_TAG_ERROR), | 
216  |  |   ERROR_ENTRY(N_("ASN1 parser: error in implicit tag"), | 
217  |  |         GNUTLS_E_ASN1_TAG_IMPLICIT),  | 
218  |  |   ERROR_ENTRY(N_("ASN1 parser: Error in type 'ANY'."), | 
219  |  |         GNUTLS_E_ASN1_TYPE_ANY_ERROR),  | 
220  |  |   ERROR_ENTRY(N_("ASN1 parser: Syntax error."), | 
221  |  |         GNUTLS_E_ASN1_SYNTAX_ERROR),  | 
222  |  |   ERROR_ENTRY(N_("ASN1 parser: Overflow in DER parsing."), | 
223  |  |         GNUTLS_E_ASN1_DER_OVERFLOW),  | 
224  |  |  | 
225  |  |   ERROR_ENTRY(N_("Too many empty record packets have been received."), | 
226  |  |         GNUTLS_E_TOO_MANY_EMPTY_PACKETS),  | 
227  |  |   ERROR_ENTRY(N_("Too many handshake packets have been received."), | 
228  |  |         GNUTLS_E_TOO_MANY_HANDSHAKE_PACKETS),  | 
229  |  |   ERROR_ENTRY(N_("More than a single object matches the criteria."), | 
230  |  |         GNUTLS_E_TOO_MANY_MATCHES),  | 
231  |  |   ERROR_ENTRY(N_("The crypto library version is too old."), | 
232  |  |         GNUTLS_E_INCOMPATIBLE_GCRYPT_LIBRARY),  | 
233  |  |  | 
234  |  |   ERROR_ENTRY(N_("The tasn1 library version is too old."), | 
235  |  |         GNUTLS_E_INCOMPATIBLE_LIBTASN1_LIBRARY),  | 
236  |  |   ERROR_ENTRY(N_("The OpenPGP User ID is revoked."), | 
237  |  |         GNUTLS_E_OPENPGP_UID_REVOKED),  | 
238  |  |   ERROR_ENTRY(N_("The OpenPGP key has not a preferred key set."), | 
239  |  |         GNUTLS_E_OPENPGP_PREFERRED_KEY_ERROR),  | 
240  |  |   ERROR_ENTRY(N_("Error loading the keyring."), | 
241  |  |         GNUTLS_E_OPENPGP_KEYRING_ERROR),  | 
242  |  |   ERROR_ENTRY(N_("The initialization of crypto backend has failed."), | 
243  |  |         GNUTLS_E_CRYPTO_INIT_FAILED),  | 
244  |  |   ERROR_ENTRY(N_("No supported compression algorithms have been found."), | 
245  |  |         GNUTLS_E_NO_COMPRESSION_ALGORITHMS),  | 
246  |  |   ERROR_ENTRY(N_("No supported cipher suites have been found."), | 
247  |  |         GNUTLS_E_NO_CIPHER_SUITES),  | 
248  |  |   ERROR_ENTRY(N_("Could not get OpenPGP key."), | 
249  |  |         GNUTLS_E_OPENPGP_GETKEY_FAILED),  | 
250  |  |   ERROR_ENTRY(N_("Could not find OpenPGP subkey."), | 
251  |  |         GNUTLS_E_OPENPGP_SUBKEY_ERROR),  | 
252  |  |   ERROR_ENTRY(N_("Safe renegotiation failed."), | 
253  |  |         GNUTLS_E_SAFE_RENEGOTIATION_FAILED),  | 
254  |  |   ERROR_ENTRY(N_("Unsafe renegotiation denied."), | 
255  |  |         GNUTLS_E_UNSAFE_RENEGOTIATION_DENIED),  | 
256  |  |  | 
257  |  |   ERROR_ENTRY(N_("The SRP username supplied is illegal."), | 
258  |  |         GNUTLS_E_ILLEGAL_SRP_USERNAME),  | 
259  |  |   ERROR_ENTRY(N_("The username supplied is unknown."), | 
260  |  |         GNUTLS_E_UNKNOWN_SRP_USERNAME),  | 
261  |  |  | 
262  |  |   ERROR_ENTRY(N_("The OpenPGP fingerprint is not supported."), | 
263  |  |         GNUTLS_E_OPENPGP_FINGERPRINT_UNSUPPORTED),  | 
264  |  |   ERROR_ENTRY(N_("The signature algorithm is not supported."), | 
265  |  |         GNUTLS_E_UNSUPPORTED_SIGNATURE_ALGORITHM),  | 
266  |  |   ERROR_ENTRY(N_("The certificate has unsupported attributes."), | 
267  |  |         GNUTLS_E_X509_UNSUPPORTED_ATTRIBUTE),  | 
268  |  |   ERROR_ENTRY(N_("The OID is not supported."), | 
269  |  |         GNUTLS_E_X509_UNSUPPORTED_OID),  | 
270  |  |   ERROR_ENTRY(N_("The hash algorithm is unknown."), | 
271  |  |         GNUTLS_E_UNKNOWN_HASH_ALGORITHM),  | 
272  |  |   ERROR_ENTRY(N_("The PKCS structure's content type is unknown."), | 
273  |  |         GNUTLS_E_UNKNOWN_PKCS_CONTENT_TYPE),  | 
274  |  |   ERROR_ENTRY(N_("The PKCS structure's bag type is unknown."), | 
275  |  |         GNUTLS_E_UNKNOWN_PKCS_BAG_TYPE),  | 
276  |  |   ERROR_ENTRY(N_("The given password contains invalid characters."), | 
277  |  |         GNUTLS_E_INVALID_PASSWORD),  | 
278  |  |   ERROR_ENTRY(N_("The given string contains invalid UTF-8 characters."), | 
279  |  |         GNUTLS_E_INVALID_UTF8_STRING),  | 
280  |  |   ERROR_ENTRY(  | 
281  |  |     N_("The given email string contains non-ASCII characters before '@'."), | 
282  |  |     GNUTLS_E_INVALID_UTF8_EMAIL),  | 
283  |  |   ERROR_ENTRY(N_("The given password contains invalid characters."), | 
284  |  |         GNUTLS_E_INVALID_PASSWORD_STRING),  | 
285  |  |   ERROR_ENTRY(N_("The Message Authentication Code verification failed."), | 
286  |  |         GNUTLS_E_MAC_VERIFY_FAILED),  | 
287  |  |   ERROR_ENTRY(N_("Some constraint limits were reached."), | 
288  |  |         GNUTLS_E_CONSTRAINT_ERROR),  | 
289  |  |   ERROR_ENTRY(N_("Failed to acquire random data."), | 
290  |  |         GNUTLS_E_RANDOM_FAILED),  | 
291  |  |   ERROR_ENTRY(N_("Verifying TLS/IA phase checksum failed"), | 
292  |  |         GNUTLS_E_IA_VERIFY_FAILED),  | 
293  |  |  | 
294  |  |   ERROR_ENTRY(N_("The specified algorithm or protocol is unknown."), | 
295  |  |         GNUTLS_E_UNKNOWN_ALGORITHM),  | 
296  |  |  | 
297  |  |   ERROR_ENTRY(N_("The handshake data size is too large."), | 
298  |  |         GNUTLS_E_HANDSHAKE_TOO_LARGE),  | 
299  |  |  | 
300  |  |   ERROR_ENTRY(N_("Error opening /dev/crypto"), | 
301  |  |         GNUTLS_E_CRYPTODEV_DEVICE_ERROR),  | 
302  |  |  | 
303  |  |   ERROR_ENTRY(N_("Error interfacing with /dev/crypto"), | 
304  |  |         GNUTLS_E_CRYPTODEV_IOCTL_ERROR),  | 
305  |  |   ERROR_ENTRY(N_("Peer has terminated the connection"), | 
306  |  |         GNUTLS_E_SESSION_EOF),  | 
307  |  |   ERROR_ENTRY(N_("Channel binding data not available"), | 
308  |  |         GNUTLS_E_CHANNEL_BINDING_NOT_AVAILABLE),  | 
309  |  |  | 
310  |  |   ERROR_ENTRY(N_("TPM error."), GNUTLS_E_TPM_ERROR), | 
311  |  |   ERROR_ENTRY(N_("The TPM library (trousers) cannot be found."), | 
312  |  |         GNUTLS_E_TPM_NO_LIB),  | 
313  |  |   ERROR_ENTRY(N_("TPM is not initialized."), GNUTLS_E_TPM_UNINITIALIZED), | 
314  |  |   ERROR_ENTRY(N_("TPM key was not found in persistent storage."), | 
315  |  |         GNUTLS_E_TPM_KEY_NOT_FOUND),  | 
316  |  |   ERROR_ENTRY(N_("Cannot initialize a session with the TPM."), | 
317  |  |         GNUTLS_E_TPM_SESSION_ERROR),  | 
318  |  |   ERROR_ENTRY(N_("PKCS #11 error."), GNUTLS_E_PKCS11_ERROR), | 
319  |  |   ERROR_ENTRY(N_("PKCS #11 initialization error."), | 
320  |  |         GNUTLS_E_PKCS11_LOAD_ERROR),  | 
321  |  |   ERROR_ENTRY(N_("Error in parsing."), GNUTLS_E_PARSING_ERROR), | 
322  |  |   ERROR_ENTRY(N_("Error in provided PIN."), GNUTLS_E_PKCS11_PIN_ERROR), | 
323  |  |   ERROR_ENTRY(N_("Error in provided SRK password for TPM."), | 
324  |  |         GNUTLS_E_TPM_SRK_PASSWORD_ERROR),  | 
325  |  |   ERROR_ENTRY(  | 
326  |  |     N_("Error in provided password for key to be loaded in TPM."), | 
327  |  |     GNUTLS_E_TPM_KEY_PASSWORD_ERROR),  | 
328  |  |   ERROR_ENTRY(N_("PKCS #11 error in slot"), GNUTLS_E_PKCS11_SLOT_ERROR), | 
329  |  |   ERROR_ENTRY(N_("Thread locking error"), GNUTLS_E_LOCKING_ERROR), | 
330  |  |   ERROR_ENTRY(N_("PKCS #11 error in attribute"), | 
331  |  |         GNUTLS_E_PKCS11_ATTRIBUTE_ERROR),  | 
332  |  |   ERROR_ENTRY(N_("PKCS #11 error in device"), | 
333  |  |         GNUTLS_E_PKCS11_DEVICE_ERROR),  | 
334  |  |   ERROR_ENTRY(N_("PKCS #11 error in data"), GNUTLS_E_PKCS11_DATA_ERROR), | 
335  |  |   ERROR_ENTRY(N_("PKCS #11 unsupported feature"), | 
336  |  |         GNUTLS_E_PKCS11_UNSUPPORTED_FEATURE_ERROR),  | 
337  |  |   ERROR_ENTRY(N_("PKCS #11 error in key"), GNUTLS_E_PKCS11_KEY_ERROR), | 
338  |  |   ERROR_ENTRY(N_("PKCS #11 PIN expired"), GNUTLS_E_PKCS11_PIN_EXPIRED), | 
339  |  |   ERROR_ENTRY(N_("PKCS #11 PIN locked"), GNUTLS_E_PKCS11_PIN_LOCKED), | 
340  |  |   ERROR_ENTRY(N_("PKCS #11 error in session"), | 
341  |  |         GNUTLS_E_PKCS11_SESSION_ERROR),  | 
342  |  |   ERROR_ENTRY(N_("PKCS #11 error in signature"), | 
343  |  |         GNUTLS_E_PKCS11_SIGNATURE_ERROR),  | 
344  |  |   ERROR_ENTRY(N_("PKCS #11 error in token"), GNUTLS_E_PKCS11_TOKEN_ERROR), | 
345  |  |   ERROR_ENTRY(N_("PKCS #11 user error"), GNUTLS_E_PKCS11_USER_ERROR), | 
346  |  |   ERROR_ENTRY(N_("The operation timed out"), GNUTLS_E_TIMEDOUT), | 
347  |  |   ERROR_ENTRY(N_("The operation was cancelled due to user error"), | 
348  |  |         GNUTLS_E_USER_ERROR),  | 
349  |  |   ERROR_ENTRY(N_("No supported ECC curves were found"), | 
350  |  |         GNUTLS_E_ECC_NO_SUPPORTED_CURVES),  | 
351  |  |   ERROR_ENTRY(N_("The curve is unsupported"), | 
352  |  |         GNUTLS_E_ECC_UNSUPPORTED_CURVE),  | 
353  |  |   ERROR_ENTRY(N_("The requested PKCS #11 object is not available"), | 
354  |  |         GNUTLS_E_PKCS11_REQUESTED_OBJECT_NOT_AVAILBLE),  | 
355  |  |   ERROR_ENTRY(  | 
356  |  |     N_("The provided X.509 certificate list is not sorted (in subject to issuer order)"), | 
357  |  |     GNUTLS_E_CERTIFICATE_LIST_UNSORTED),  | 
358  |  |   ERROR_ENTRY(N_("The OCSP response is invalid"), | 
359  |  |         GNUTLS_E_OCSP_RESPONSE_ERROR),  | 
360  |  |   ERROR_ENTRY(  | 
361  |  |     N_("The OCSP response provided doesn't match the available certificates"), | 
362  |  |     GNUTLS_E_OCSP_MISMATCH_WITH_CERTS),  | 
363  |  |   ERROR_ENTRY(N_("There is no certificate status (OCSP)."), | 
364  |  |         GNUTLS_E_NO_CERTIFICATE_STATUS),  | 
365  |  |   ERROR_ENTRY(N_("Error in the system's randomness device."), | 
366  |  |         GNUTLS_E_RANDOM_DEVICE_ERROR),  | 
367  |  |   ERROR_ENTRY(N_("No common application protocol could be negotiated."), | 
368  |  |         GNUTLS_E_NO_APPLICATION_PROTOCOL),  | 
369  |  |   ERROR_ENTRY(N_("Error while performing self checks."), | 
370  |  |         GNUTLS_E_SELF_TEST_ERROR),  | 
371  |  |   ERROR_ENTRY(N_("There is no self test for this algorithm."), | 
372  |  |         GNUTLS_E_NO_SELF_TEST),  | 
373  |  |   ERROR_ENTRY(  | 
374  |  |     N_("An error has been detected in the library and cannot continue operations."), | 
375  |  |     GNUTLS_E_LIB_IN_ERROR_STATE),  | 
376  |  |   ERROR_ENTRY(N_("Error in sockets initialization."), | 
377  |  |         GNUTLS_E_SOCKETS_INIT_ERROR),  | 
378  |  |   ERROR_ENTRY(N_("Error in public key generation."), | 
379  |  |         GNUTLS_E_PK_GENERATION_ERROR),  | 
380  |  |   ERROR_ENTRY(N_("Invalid TLS extensions length field."), | 
381  |  |         GNUTLS_E_UNEXPECTED_EXTENSIONS_LENGTH),  | 
382  |  |   ERROR_ENTRY(  | 
383  |  |     N_("Peer's certificate or username has changed during a rehandshake."), | 
384  |  |     GNUTLS_E_SESSION_USER_ID_CHANGED),  | 
385  |  |   ERROR_ENTRY(N_("The provided string has an embedded null."), | 
386  |  |         GNUTLS_E_ASN1_EMBEDDED_NULL_IN_STRING),  | 
387  |  |   ERROR_ENTRY(N_("Attempted handshake during false start."), | 
388  |  |         GNUTLS_E_HANDSHAKE_DURING_FALSE_START),  | 
389  |  |   ERROR_ENTRY(N_("The SNI host name not recognised."), | 
390  |  |         GNUTLS_E_UNRECOGNIZED_NAME),  | 
391  |  |   ERROR_ENTRY(N_("There was an issue converting to or from UTF8."), | 
392  |  |         GNUTLS_E_IDNA_ERROR),  | 
393  |  |   ERROR_ENTRY(  | 
394  |  |     N_("Cannot perform this action while handshake is in progress."), | 
395  |  |     GNUTLS_E_UNAVAILABLE_DURING_HANDSHAKE),  | 
396  |  |   ERROR_ENTRY(N_("The public key is invalid."), | 
397  |  |         GNUTLS_E_PK_INVALID_PUBKEY),  | 
398  |  |   ERROR_ENTRY(N_("There are no validation parameters present."), | 
399  |  |         GNUTLS_E_PK_NO_VALIDATION_PARAMS),  | 
400  |  |   ERROR_ENTRY(N_("The public key parameters are invalid."), | 
401  |  |         GNUTLS_E_PK_INVALID_PUBKEY_PARAMS),  | 
402  |  |   ERROR_ENTRY(N_("The private key is invalid."), | 
403  |  |         GNUTLS_E_PK_INVALID_PRIVKEY),  | 
404  |  |   ERROR_ENTRY(N_("The DER time encoding is invalid."), | 
405  |  |         GNUTLS_E_ASN1_TIME_ERROR),  | 
406  |  |   ERROR_ENTRY(N_("The signature is incompatible with the public key."), | 
407  |  |         GNUTLS_E_INCOMPATIBLE_SIG_WITH_KEY),  | 
408  |  |   ERROR_ENTRY(  | 
409  |  |     N_("One of the involved algorithms has insufficient security level."), | 
410  |  |     GNUTLS_E_INSUFFICIENT_SECURITY),  | 
411  |  |   ERROR_ENTRY(N_("No common key share with peer."), | 
412  |  |         GNUTLS_E_NO_COMMON_KEY_SHARE),  | 
413  |  |   ERROR_ENTRY(N_("The early data were rejected."), | 
414  |  |         GNUTLS_E_EARLY_DATA_REJECTED),  | 
415  |  |   ERROR_ENTRY(N_("The encryption algorithm is not supported."), | 
416  |  |         GNUTLS_E_UNSUPPORTED_ENCRYPTION_ALGORITHM),  | 
417  |  |   { NULL, NULL, 0 } | 
418  |  | };  | 
419  |  |  | 
420  |  | static const gnutls_error_entry non_fatal_error_entries[] = { | 
421  |  |   ERROR_ENTRY(N_("Success."), GNUTLS_E_SUCCESS), | 
422  |  |   ERROR_ENTRY(N_("A TLS warning alert has been received."), | 
423  |  |         GNUTLS_E_WARNING_ALERT_RECEIVED),  | 
424  |  |   ERROR_ENTRY(N_("A heartbeat pong message was received."), | 
425  |  |         GNUTLS_E_HEARTBEAT_PONG_RECEIVED),  | 
426  |  |   ERROR_ENTRY(N_("A heartbeat ping message was received."), | 
427  |  |         GNUTLS_E_HEARTBEAT_PING_RECEIVED),  | 
428  |  |   ERROR_ENTRY(N_("Resource temporarily unavailable, try again."), | 
429  |  |         GNUTLS_E_AGAIN),  | 
430  |  |   ERROR_ENTRY(N_("The transmitted packet is too large (EMSGSIZE)."), | 
431  |  |         GNUTLS_E_LARGE_PACKET),  | 
432  |  |   ERROR_ENTRY(N_("Function was interrupted."), GNUTLS_E_INTERRUPTED), | 
433  |  |   ERROR_ENTRY(N_("Rehandshake was requested by the peer."), | 
434  |  |         GNUTLS_E_REHANDSHAKE),  | 
435  |  |   ERROR_ENTRY(N_("Re-authentication was requested by the peer."), | 
436  |  |         GNUTLS_E_REAUTH_REQUEST),  | 
437  |  |   /* Only non fatal (for handshake) errors here */  | 
438  |  |   { NULL, NULL, 0 } | 
439  |  | };  | 
440  |  |  | 
441  |  | /**  | 
442  |  |  * gnutls_error_is_fatal:  | 
443  |  |  * @error: is a GnuTLS error code, a negative error code  | 
444  |  |  *  | 
445  |  |  * If a GnuTLS function returns a negative error code you may feed that  | 
446  |  |  * value to this function to see if the error condition is fatal to  | 
447  |  |  * a TLS session (i.e., must be terminated).  | 
448  |  |  *  | 
449  |  |  * Note that you may also want to check the error code manually, since some  | 
450  |  |  * non-fatal errors to the protocol (such as a warning alert or  | 
451  |  |  * a rehandshake request) may be fatal for your program.  | 
452  |  |  *  | 
453  |  |  * This function is only useful if you are dealing with errors from  | 
454  |  |  * functions that relate to a TLS session (e.g., record layer or handshake  | 
455  |  |  * layer handling functions).  | 
456  |  |  *  | 
457  |  |  * Returns: Non-zero value on fatal errors or zero on non-fatal.  | 
458  |  |  **/  | 
459  |  | int gnutls_error_is_fatal(int error)  | 
460  | 0  | { | 
461  | 0  |   int ret = 1;  | 
462  | 0  |   const gnutls_error_entry *p;  | 
463  |  |  | 
464  |  |   /* Input sanitzation.  Positive values are not errors at all, and  | 
465  |  |      definitely not fatal. */  | 
466  | 0  |   if (error > 0)  | 
467  | 0  |     return 0;  | 
468  |  |  | 
469  | 0  |   for (p = non_fatal_error_entries; p->desc != NULL; p++) { | 
470  | 0  |     if (p->number == error) { | 
471  | 0  |       ret = 0;  | 
472  | 0  |       break;  | 
473  | 0  |     }  | 
474  | 0  |   }  | 
475  |  | 
  | 
476  | 0  |   return ret;  | 
477  | 0  | }  | 
478  |  |  | 
479  |  | /**  | 
480  |  |  * gnutls_perror:  | 
481  |  |  * @error: is a GnuTLS error code, a negative error code  | 
482  |  |  *  | 
483  |  |  * This function is like perror(). The only difference is that it  | 
484  |  |  * accepts an error number returned by a gnutls function.  | 
485  |  |  **/  | 
486  |  | void gnutls_perror(int error)  | 
487  | 0  | { | 
488  | 0  |   fprintf(stderr, "GnuTLS error: %s\n", gnutls_strerror(error));  | 
489  | 0  | }  | 
490  |  |  | 
491  |  | /**  | 
492  |  |  * gnutls_strerror:  | 
493  |  |  * @error: is a GnuTLS error code, a negative error code  | 
494  |  |  *  | 
495  |  |  * This function is similar to strerror.  The difference is that it  | 
496  |  |  * accepts an error number returned by a gnutls function; In case of  | 
497  |  |  * an unknown error a descriptive string is sent instead of %NULL.  | 
498  |  |  *  | 
499  |  |  * Error codes are always a negative error code.  | 
500  |  |  *  | 
501  |  |  * Returns: A string explaining the GnuTLS error message.  | 
502  |  |  **/  | 
503  |  | const char *gnutls_strerror(int error)  | 
504  | 0  | { | 
505  | 0  |   const char *ret = NULL;  | 
506  | 0  |   const gnutls_error_entry *p;  | 
507  |  | 
  | 
508  | 0  |   for (p = error_entries; p->desc != NULL; p++) { | 
509  | 0  |     if (p->number == error) { | 
510  | 0  |       ret = p->desc;  | 
511  | 0  |       break;  | 
512  | 0  |     }  | 
513  | 0  |   }  | 
514  |  | 
  | 
515  | 0  |   if (ret == NULL) { | 
516  | 0  |     for (p = non_fatal_error_entries; p->desc != NULL; p++) { | 
517  | 0  |       if (p->number == error) { | 
518  | 0  |         ret = p->desc;  | 
519  | 0  |         break;  | 
520  | 0  |       }  | 
521  | 0  |     }  | 
522  | 0  |   }  | 
523  |  |  | 
524  |  |   /* avoid prefix */  | 
525  | 0  |   if (ret == NULL)  | 
526  | 0  |     return _("(unknown error code)"); | 
527  |  |  | 
528  | 0  |   return _(ret);  | 
529  | 0  | }  | 
530  |  |  | 
531  |  | /**  | 
532  |  |  * gnutls_strerror_name:  | 
533  |  |  * @error: is an error returned by a gnutls function.  | 
534  |  |  *  | 
535  |  |  * Return the GnuTLS error code define as a string.  For example,  | 
536  |  |  * gnutls_strerror_name (GNUTLS_E_DH_PRIME_UNACCEPTABLE) will return  | 
537  |  |  * the string "GNUTLS_E_DH_PRIME_UNACCEPTABLE".  | 
538  |  |  *  | 
539  |  |  * Returns: A string corresponding to the symbol name of the error  | 
540  |  |  * code.  | 
541  |  |  *  | 
542  |  |  * Since: 2.6.0  | 
543  |  |  **/  | 
544  |  | const char *gnutls_strerror_name(int error)  | 
545  | 0  | { | 
546  | 0  |   const char *ret = NULL;  | 
547  | 0  |   const gnutls_error_entry *p;  | 
548  |  | 
  | 
549  | 0  |   for (p = error_entries; p->desc != NULL; p++) { | 
550  | 0  |     if (p->number == error) { | 
551  | 0  |       ret = p->_name;  | 
552  | 0  |       break;  | 
553  | 0  |     }  | 
554  | 0  |   }  | 
555  |  | 
  | 
556  | 0  |   if (ret == NULL) { | 
557  | 0  |     for (p = non_fatal_error_entries; p->desc != NULL; p++) { | 
558  | 0  |       if (p->number == error) { | 
559  | 0  |         ret = p->_name;  | 
560  | 0  |         break;  | 
561  | 0  |       }  | 
562  | 0  |     }  | 
563  | 0  |   }  | 
564  |  | 
  | 
565  | 0  |   return ret;  | 
566  | 0  | }  | 
567  |  |  | 
568  |  | void _gnutls_mpi_log(const char *prefix, bigint_t a)  | 
569  | 0  | { | 
570  | 0  |   size_t binlen = 0;  | 
571  | 0  |   void *binbuf;  | 
572  | 0  |   size_t hexlen;  | 
573  | 0  |   char *hexbuf;  | 
574  | 0  |   int res;  | 
575  |  | 
  | 
576  | 0  |   if (_gnutls_log_level < 2)  | 
577  | 0  |     return;  | 
578  |  |  | 
579  | 0  |   res = _gnutls_mpi_print(a, NULL, &binlen);  | 
580  | 0  |   if (res < 0 && res != GNUTLS_E_SHORT_MEMORY_BUFFER) { | 
581  | 0  |     gnutls_assert();  | 
582  | 0  |     _gnutls_hard_log("MPI: %s can't print value (%d/%d)\n", prefix, | 
583  | 0  |          res, (int)binlen);  | 
584  | 0  |     return;  | 
585  | 0  |   }  | 
586  |  |  | 
587  | 0  |   if (binlen > 1024 * 1024) { | 
588  | 0  |     gnutls_assert();  | 
589  | 0  |     _gnutls_hard_log("MPI: %s too large mpi (%d)\n", prefix, | 
590  | 0  |          (int)binlen);  | 
591  | 0  |     return;  | 
592  | 0  |   }  | 
593  |  |  | 
594  | 0  |   binbuf = gnutls_malloc(binlen);  | 
595  | 0  |   if (!binbuf) { | 
596  | 0  |     gnutls_assert();  | 
597  | 0  |     _gnutls_hard_log("MPI: %s out of memory (%d)\n", prefix, | 
598  | 0  |          (int)binlen);  | 
599  | 0  |     return;  | 
600  | 0  |   }  | 
601  |  |  | 
602  | 0  |   res = _gnutls_mpi_print(a, binbuf, &binlen);  | 
603  | 0  |   if (res != 0) { | 
604  | 0  |     gnutls_assert();  | 
605  | 0  |     _gnutls_hard_log("MPI: %s can't print value (%d/%d)\n", prefix, | 
606  | 0  |          res, (int)binlen);  | 
607  | 0  |     gnutls_free(binbuf);  | 
608  | 0  |     return;  | 
609  | 0  |   }  | 
610  |  |  | 
611  | 0  |   hexlen = 2 * binlen + 1;  | 
612  | 0  |   hexbuf = gnutls_malloc(hexlen);  | 
613  |  | 
  | 
614  | 0  |   if (!hexbuf) { | 
615  | 0  |     gnutls_assert();  | 
616  | 0  |     _gnutls_hard_log("MPI: %s out of memory (hex %d)\n", prefix, | 
617  | 0  |          (int)hexlen);  | 
618  | 0  |     gnutls_free(binbuf);  | 
619  | 0  |     return;  | 
620  | 0  |   }  | 
621  |  |  | 
622  | 0  |   _gnutls_bin2hex(binbuf, binlen, hexbuf, hexlen, NULL);  | 
623  |  | 
  | 
624  | 0  |   _gnutls_hard_log("MPI: length: %d\n\t%s%s\n", (int)binlen, prefix, | 
625  | 0  |        hexbuf);  | 
626  |  | 
  | 
627  | 0  |   gnutls_free(hexbuf);  | 
628  | 0  |   gnutls_free(binbuf);  | 
629  | 0  | }  | 
630  |  |  | 
631  |  | /* this function will output a message using the  | 
632  |  |  * caller provided function  | 
633  |  |  */  | 
634  |  | void _gnutls_log(int level, const char *fmt, ...)  | 
635  | 0  | { | 
636  | 0  |   va_list args;  | 
637  | 0  |   char *str;  | 
638  | 0  |   int ret;  | 
639  |  | 
  | 
640  | 0  |   if (_gnutls_log_func == NULL)  | 
641  | 0  |     return;  | 
642  |  |  | 
643  | 0  |   va_start(args, fmt);  | 
644  | 0  |   ret = vasprintf(&str, fmt, args);  | 
645  | 0  |   va_end(args);  | 
646  |  | 
  | 
647  | 0  |   if (ret >= 0) { | 
648  | 0  |     _gnutls_log_func(level, str);  | 
649  | 0  |     free(str);  | 
650  | 0  |   }  | 
651  | 0  | }  | 
652  |  |  | 
653  |  | void _gnutls_audit_log(gnutls_session_t session, const char *fmt, ...)  | 
654  | 0  | { | 
655  | 0  |   va_list args;  | 
656  | 0  |   char *str;  | 
657  | 0  |   int ret;  | 
658  |  | 
  | 
659  | 0  |   if (_gnutls_audit_log_func == NULL && _gnutls_log_func == NULL)  | 
660  | 0  |     return;  | 
661  |  |  | 
662  | 0  |   va_start(args, fmt);  | 
663  | 0  |   ret = vasprintf(&str, fmt, args);  | 
664  | 0  |   va_end(args);  | 
665  |  | 
  | 
666  | 0  |   if (ret >= 0) { | 
667  | 0  |     if (_gnutls_audit_log_func)  | 
668  | 0  |       _gnutls_audit_log_func(session, str);  | 
669  | 0  |     else  | 
670  | 0  |       _gnutls_log_func(1, str);  | 
671  | 0  |     free(str);  | 
672  | 0  |   }  | 
673  | 0  | }  | 
674  |  |  | 
675  |  | #ifndef DEBUG  | 
676  |  | #ifndef C99_MACROS  | 
677  |  |  | 
678  |  | /* Without C99 macros these functions have to  | 
679  |  |  * be called. This may affect performance.  | 
680  |  |  */  | 
681  |  | void _gnutls_null_log(void *x, ...)  | 
682  |  | { | 
683  |  |   return;  | 
684  |  | }  | 
685  |  |  | 
686  |  | #endif /* C99_MACROS */  | 
687  |  | #endif /* DEBUG */  |