]> git.ipfire.org Git - people/ms/suricata.git/blob - src/app-layer-ssl.h
TLS: add detection for malicious heartbeats (AKA heartbleed)
[people/ms/suricata.git] / src / app-layer-ssl.h
1 /* Copyright (C) 2007-2012 Open Information Security Foundation
2 *
3 * You can copy, redistribute or modify this Program under the terms of
4 * the GNU General Public License version 2 as published by the Free
5 * Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * version 2 along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15 * 02110-1301, USA.
16 */
17
18 /**
19 * \file
20 *
21 * \author Anoop Saldanha <anoopsaldanha@gmail.com>
22 * \author Pierre Chifflier <pierre.chifflier@ssi.gouv.fr>
23 *
24 */
25
26 #ifndef __APP_LAYER_SSL_H__
27 #define __APP_LAYER_SSL_H__
28
29 #include "decode-events.h"
30 #include "queue.h"
31
32 enum {
33 /* TLS protocol messages */
34 TLS_DECODER_EVENT_INVALID_SSLV2_HEADER,
35 TLS_DECODER_EVENT_INVALID_TLS_HEADER,
36 TLS_DECODER_EVENT_INVALID_RECORD_TYPE,
37 TLS_DECODER_EVENT_INVALID_HANDSHAKE_MESSAGE,
38 TLS_DECODER_EVENT_HEARTBEAT,
39 TLS_DECODER_EVENT_INVALID_HEARTBEAT,
40 TLS_DECODER_EVENT_OVERFLOW_HEARTBEAT,
41 /* Certificates decoding messages */
42 TLS_DECODER_EVENT_INVALID_CERTIFICATE,
43 TLS_DECODER_EVENT_CERTIFICATE_MISSING_ELEMENT,
44 TLS_DECODER_EVENT_CERTIFICATE_UNKNOWN_ELEMENT,
45 TLS_DECODER_EVENT_CERTIFICATE_INVALID_LENGTH,
46 TLS_DECODER_EVENT_CERTIFICATE_INVALID_STRING,
47 TLS_DECODER_EVENT_ERROR_MSG_ENCOUNTERED,
48 TLS_DECODER_EVENT_INVALID_SSL_RECORD,
49 };
50
51 /* Flag to indicate that server will now on send encrypted msgs */
52 #define SSL_AL_FLAG_SERVER_CHANGE_CIPHER_SPEC 0x0001
53 /* Flag to indicate that client will now on send encrypted msgs */
54 #define SSL_AL_FLAG_CLIENT_CHANGE_CIPHER_SPEC 0x0002
55 #define SSL_AL_FLAG_CHANGE_CIPHER_SPEC 0x0004
56
57 /* SSL related flags */
58 #define SSL_AL_FLAG_SSL_CLIENT_HS 0x0008
59 #define SSL_AL_FLAG_SSL_SERVER_HS 0x0010
60 #define SSL_AL_FLAG_SSL_CLIENT_MASTER_KEY 0x0020
61 #define SSL_AL_FLAG_SSL_CLIENT_SSN_ENCRYPTED 0x0040
62 #define SSL_AL_FLAG_SSL_SERVER_SSN_ENCRYPTED 0x0080
63 #define SSL_AL_FLAG_SSL_NO_SESSION_ID 0x0100
64
65 /* flags specific to detect-ssl-state keyword */
66 #define SSL_AL_FLAG_STATE_CLIENT_HELLO 0x0200
67 #define SSL_AL_FLAG_STATE_SERVER_HELLO 0x0400
68 #define SSL_AL_FLAG_STATE_CLIENT_KEYX 0x0800
69 #define SSL_AL_FLAG_STATE_SERVER_KEYX 0x1000
70 #define SSL_AL_FLAG_STATE_UNKNOWN 0x2000
71
72 #define SSL_AL_FLAG_STATE_LOGGED 0x4000
73
74 /* config flags */
75 #define SSL_TLS_LOG_PEM (1 << 0)
76
77
78
79 /* SSL versions. We'll use a unified format for all, with the top byte
80 * holding the major version and the lower byte the minor version */
81 enum {
82 TLS_VERSION_UNKNOWN = 0x0000,
83 SSL_VERSION_2 = 0x0200,
84 SSL_VERSION_3 = 0x0300,
85 TLS_VERSION_10 = 0x0301,
86 TLS_VERSION_11 = 0x0302,
87 TLS_VERSION_12 = 0x0303,
88 };
89
90 typedef struct SSLCertsChain_ {
91 uint8_t *cert_data;
92 uint32_t cert_len;
93 TAILQ_ENTRY(SSLCertsChain_) next;
94 } SSLCertsChain;
95
96
97 typedef struct SSLStateConnp_ {
98 /* record length */
99 uint32_t record_length;
100 /* record length's length for SSLv2 */
101 uint32_t record_lengths_length;
102
103 /* offset of the beginning of the current message (including header) */
104 uint32_t message_start;
105 uint32_t message_length;
106
107 uint16_t version;
108 uint8_t content_type;
109
110 uint8_t handshake_type;
111 uint32_t handshake_length;
112
113 /* the no of bytes processed in the currently parsed record */
114 uint16_t bytes_processed;
115 /* the no of bytes processed in the currently parsed handshake */
116 uint16_t hs_bytes_processed;
117
118 /* sslv2 client hello session id length */
119 uint16_t session_id_length;
120
121 char *cert0_subject;
122 char *cert0_issuerdn;
123 char *cert0_fingerprint;
124
125 uint8_t *cert_input;
126 uint32_t cert_input_len;
127
128 TAILQ_HEAD(, SSLCertsChain_) certs;
129
130 uint32_t cert_log_flag;
131
132 /* buffer for the tls record.
133 * We use a malloced buffer, if the record is fragmented */
134 uint8_t *trec;
135 uint32_t trec_len;
136 uint32_t trec_pos;
137 } SSLStateConnp;
138
139 /**
140 * \brief SSLv[2.0|3.[0|1|2|3]] state structure.
141 *
142 * Structure to store the SSL state values.
143 */
144 typedef struct SSLState_ {
145 Flow *f;
146
147 /* holds some state flags we need */
148 uint32_t flags;
149
150 SSLStateConnp *curr_connp;
151
152 SSLStateConnp client_connp;
153 SSLStateConnp server_connp;
154 } SSLState;
155
156 void RegisterSSLParsers(void);
157 void SSLParserRegisterTests(void);
158
159 #endif /* __APP_LAYER_SSL_H__ */