Coverage Report

Created: 2024-07-23 07:36

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