summaryrefslogtreecommitdiff
path: root/src/libtls/tls_alert.h
blob: 8ce50f83d3e0d059f2a9461fcbe99304969ade3f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*
 * Copyright (C) 2010 Martin Willi
 * Copyright (C) 2010 revosec AG
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or (at your
 * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * for more details.
 */

/**
 * @defgroup tls_alert tls_alert
 * @{ @ingroup libtls
 */

#ifndef TLS_ALERT_H_
#define TLS_ALERT_H_

#include <library.h>

typedef struct tls_alert_t tls_alert_t;
typedef enum tls_alert_level_t tls_alert_level_t;
typedef enum tls_alert_desc_t tls_alert_desc_t;

/**
 * Level of a TLS alert
 */
enum tls_alert_level_t {
	TLS_WARNING = 1,
	TLS_FATAL = 2,
};

/**
 * Description of a TLS alert
 */
enum tls_alert_desc_t {
	TLS_CLOSE_NOTIFY = 0,
	TLS_UNEXPECTED_MESSAGE = 10,
	TLS_BAD_RECORD_MAC = 20,
	TLS_DECRYPTION_FAILED = 21,
	TLS_RECORD_OVERFLOW = 22,
	TLS_DECOMPRESSION_FAILURE = 30,
	TLS_HANDSHAKE_FAILURE = 40,
	TLS_NO_CERTIFICATE = 41,
	TLS_BAD_CERTIFICATE = 42,
	TLS_UNSUPPORTED_CERTIFICATE = 43,
	TLS_CERTIFICATE_REVOKED = 44,
	TLS_CERTIFICATE_EXPIRED = 45,
	TLS_CERTIFICATE_UNKNOWN = 46,
	TLS_ILLEGAL_PARAMETER = 47,
	TLS_UNKNOWN_CA = 48,
	TLS_ACCESS_DENIED = 49,
	TLS_DECODE_ERROR = 50,
	TLS_DECRYPT_ERROR = 51,
	TLS_EXPORT_RESTRICTION = 60,
	TLS_PROTOCOL_VERSION = 70,
	TLS_INSUFFICIENT_SECURITY = 71,
	TLS_INTERNAL_ERROR = 80,
	TLS_USER_CANCELED = 90,
	TLS_NO_RENEGOTIATION = 100,
	TLS_UNSUPPORTED_EXTENSION = 110,
};

/**
 * Enum names for alert descriptions
 */
extern enum_name_t *tls_alert_desc_names;

/**
 * TLS alert handling.
 */
struct tls_alert_t {

	/**
	 * Add an alert to the TLS alert queue, will be sent.
	 *
	 * @param level			level of TLS alert
	 * @param description	description of alert
	 */
	void (*add)(tls_alert_t *this, tls_alert_level_t level,
				tls_alert_desc_t description);

	/**
	 * Get an alert pushed to the alert queue, to send.
	 *
	 * @param level			receives TLS alert level
	 * @param description	receives TLS alert description
	 * @return				TRUE if returned an alert
	 */
	bool (*get)(tls_alert_t *this, tls_alert_level_t *level,
				tls_alert_desc_t *description);

	/**
	 * Did a fatal alert occur?.
	 *
	 * @return				TRUE if a fatal alert has occurred
	 */
	bool (*fatal)(tls_alert_t *this);

	/**
	 * Process a received TLS alert.
	 *
	 * @param level			level of received alert
	 * @param description	alert description
	 * @return				status to pass down to TLS stack
	 */
	status_t (*process)(tls_alert_t *this, tls_alert_level_t level,
						tls_alert_desc_t description);

	/**
	 * Destroy a tls_alert_t.
	 */
	void (*destroy)(tls_alert_t *this);
};

/**
 * Create a tls_alert instance.
 */
tls_alert_t *tls_alert_create();

#endif /** TLS_ALERT_H_ @}*/