Coverage Report

Created: 2024-06-20 06:28

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