suricata
app-layer-ssl.h
Go to the documentation of this file.
1/* Copyright (C) 2007-2022 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 SURICATA_APP_LAYER_SSL_H
27#define SURICATA_APP_LAYER_SSL_H
28
29#include "util-ja3.h"
30#include "rust.h"
31
33 TLS_FRAME_PDU = 0, /**< whole PDU, so header + data */
34 TLS_FRAME_HDR, /**< only header portion */
35 TLS_FRAME_DATA, /**< only data portion */
40};
41
42enum {
43 /* TLS protocol messages */
60 /* Certificates decoding messages */
75};
76
84
93
94/* Flag to indicate that server will now on send encrypted msgs */
95#define SSL_AL_FLAG_SERVER_CHANGE_CIPHER_SPEC BIT_U32(0)
96/* Flag to indicate that client will now on send encrypted msgs */
97#define SSL_AL_FLAG_CLIENT_CHANGE_CIPHER_SPEC BIT_U32(1)
98#define SSL_AL_FLAG_CHANGE_CIPHER_SPEC BIT_U32(2)
99
100/* SSL related flags */
101#define SSL_AL_FLAG_SSL_CLIENT_HS BIT_U32(3)
102#define SSL_AL_FLAG_SSL_SERVER_HS BIT_U32(4)
103#define SSL_AL_FLAG_SSL_CLIENT_MASTER_KEY BIT_U32(5)
104#define SSL_AL_FLAG_SSL_CLIENT_SSN_ENCRYPTED BIT_U32(6)
105#define SSL_AL_FLAG_SSL_SERVER_SSN_ENCRYPTED BIT_U32(7)
106#define SSL_AL_FLAG_SSL_NO_SESSION_ID BIT_U32(8)
107
108/* flags specific to detect-ssl-state keyword */
109#define SSL_AL_FLAG_STATE_CLIENT_HELLO BIT_U32(9)
110#define SSL_AL_FLAG_STATE_SERVER_HELLO BIT_U32(10)
111#define SSL_AL_FLAG_STATE_CLIENT_KEYX BIT_U32(11)
112#define SSL_AL_FLAG_STATE_SERVER_KEYX BIT_U32(12)
113#define SSL_AL_FLAG_STATE_UNKNOWN BIT_U32(13)
114
115/* flags specific to HeartBeat state */
116#define SSL_AL_FLAG_HB_INFLIGHT BIT_U32(15)
117#define SSL_AL_FLAG_HB_CLIENT_INIT BIT_U32(16)
118#define SSL_AL_FLAG_HB_SERVER_INIT BIT_U32(17)
119
120/* Session resumed without a full handshake */
121#define SSL_AL_FLAG_SESSION_RESUMED BIT_U32(20)
122
123/* Encountered a supported_versions extension in client hello */
124#define SSL_AL_FLAG_CH_VERSION_EXTENSION BIT_U32(21)
125
126/* Log the session even without ever seeing a certificate. This is used
127 to log TLSv1.3 sessions. */
128#define SSL_AL_FLAG_LOG_WITHOUT_CERT BIT_U32(22)
129
130/* Encountered a early data extension in client hello. This extension is
131 used by 0-RTT. */
132#define SSL_AL_FLAG_EARLY_DATA BIT_U32(23)
133
134/* flag to indicate that server random was filled */
135#define TLS_TS_RANDOM_SET BIT_U32(24)
136
137/* flag to indicate that client random was filled */
138#define TLS_TC_RANDOM_SET BIT_U32(25)
139
140#define SSL_AL_FLAG_NEED_CLIENT_CERT BIT_U32(26)
141
142/* config flags */
143#define SSL_TLS_LOG_PEM (1 << 0)
144
145/* extensions */
146#define SSL_EXTENSION_SNI 0x0000
147#define SSL_EXTENSION_ELLIPTIC_CURVES 0x000a
148#define SSL_EXTENSION_EC_POINT_FORMATS 0x000b
149#define SSL_EXTENSION_SIGNATURE_ALGORITHMS 0x000d
150#define SSL_EXTENSION_ALPN 0x0010
151#define SSL_EXTENSION_SESSION_TICKET 0x0023
152#define SSL_EXTENSION_EARLY_DATA 0x002a
153#define SSL_EXTENSION_SUPPORTED_VERSIONS 0x002b
154
155/* SNI types */
156#define SSL_SNI_TYPE_HOST_NAME 0
157
158/* TLS random bytes for the sticky buffer */
159#define TLS_RANDOM_LEN 32
160
166
167typedef struct SSLStateConnp_ {
168 /* record length */
170 /* record length's length for SSLv2 */
172
173 /* offset of the beginning of the current message (including header) */
175
176 uint16_t version;
178
180
181 /* the no of bytes processed in the currently parsed record */
183
185
193
196 /* ssl server name indication extension */
197 char *sni;
198
200
202
203 uint8_t *certs_buffer;
205
207
209 char *ja3_hash;
210
211 HandshakeParams *hs;
212
213 /* handshake tls fragmentation buffer. Handshake messages can be fragmented over multiple
214 * TLS records. */
215 uint8_t *hs_buffer;
218 uint32_t hs_buffer_size; /**< allocation size */
219 uint32_t hs_buffer_offset; /**< write offset */
221
222/**
223 * \brief SSLv[2.0|3.[0|1|2|3]] state structure.
224 *
225 * Structure to store the SSL state values.
226 */
227typedef struct SSLState_ {
229
232
233 /* holds some state flags we need */
234 uint32_t flags;
235
236 /* there might be a better place to store this*/
238
239 uint16_t events;
240
242
244
247
251
252void RegisterSSLParsers(void);
253void SSLEnableJA3(void);
254bool SSLJA3IsEnabled(void);
255void SSLEnableJA4(void);
256bool SSLJA4IsEnabled(void);
257
258#endif /* SURICATA_APP_LAYER_SSL_H */
struct HtpBodyChunk_ * next
struct AppLayerTxData AppLayerTxData
struct AppLayerStateData AppLayerStateData
void SSLEnableJA3(void)
if not explicitly disabled in config, enable ja3 support
@ TLS_DECODER_EVENT_INVALID_SSLV2_HEADER
@ TLS_DECODER_EVENT_INVALID_TLS_HEADER
@ TLS_DECODER_EVENT_INVALID_SNI_TYPE
@ TLS_DECODER_EVENT_CERTIFICATE_INVALID_DER
@ TLS_DECODER_EVENT_CERTIFICATE_INVALID_SERIAL
@ TLS_DECODER_EVENT_INVALID_SNI_LENGTH
@ TLS_DECODER_EVENT_CERTIFICATE_INVALID_EXTENSIONS
@ TLS_DECODER_EVENT_CERTIFICATE_INVALID_VERSION
@ TLS_DECODER_EVENT_TOO_MANY_RECORDS_IN_PACKET
@ TLS_DECODER_EVENT_INVALID_ALERT
@ TLS_DECODER_EVENT_INVALID_HANDSHAKE_MESSAGE
@ TLS_DECODER_EVENT_INVALID_RECORD_TYPE
@ TLS_DECODER_EVENT_OVERFLOW_HEARTBEAT
@ TLS_DECODER_EVENT_INVALID_SSL_RECORD
@ TLS_DECODER_EVENT_MULTIPLE_SNI_EXTENSIONS
@ TLS_DECODER_EVENT_INVALID_RECORD_VERSION
@ TLS_DECODER_EVENT_HEARTBEAT
@ TLS_DECODER_EVENT_CERTIFICATE_INVALID_DATE
@ TLS_DECODER_EVENT_HANDSHAKE_INVALID_LENGTH
@ TLS_DECODER_EVENT_CERTIFICATE_INVALID_VALIDITY
@ TLS_DECODER_EVENT_INVALID_HEARTBEAT
@ TLS_DECODER_EVENT_CERTIFICATE_INVALID_LENGTH
@ TLS_DECODER_EVENT_DATALEAK_HEARTBEAT_MISMATCH
@ TLS_DECODER_EVENT_CERTIFICATE_INVALID_X509NAME
@ TLS_DECODER_EVENT_ERROR_MSG_ENCOUNTERED
@ TLS_DECODER_EVENT_INVALID_RECORD_LENGTH
@ TLS_DECODER_EVENT_INVALID_CERTIFICATE
@ TLS_DECODER_EVENT_CERTIFICATE_INVALID_ALGORITHMIDENTIFIER
@ TLS_DECODER_EVENT_CERTIFICATE_INVALID_SUBJECT
@ TLS_DECODER_EVENT_CERTIFICATE_INVALID_ISSUER
bool SSLJA3IsEnabled(void)
return whether ja3 is effectively enabled
TlsStateClient
@ TLS_STATE_CLIENT_HELLO_DONE
@ TLS_STATE_CLIENT_FINISHED
@ TLS_STATE_CLIENT_HANDSHAKE_DONE
@ TLS_STATE_CLIENT_IN_PROGRESS
@ TLS_STATE_CLIENT_CERT_DONE
void SSLEnableJA4(void)
if not explicitly disabled in config, enable ja4 support
bool SSLJA4IsEnabled(void)
return whether ja4 is effectively enabled
TlsStateServer
@ TLS_STATE_SERVER_IN_PROGRESS
@ TLS_STATE_SERVER_HANDSHAKE_DONE
@ TLS_STATE_SERVER_FINISHED
@ TLS_STATE_SERVER_HELLO
@ TLS_STATE_SERVER_CERT_DONE
@ TLS_STATE_SERVER_HELLO_DONE
struct SSLStateConnp_ SSLStateConnp
struct SSLState_ SSLState
SSLv[2.0|3.[0|1|2|3]] state structure.
void RegisterSSLParsers(void)
Function to register the SSL protocol parser and other functions.
#define TLS_RANDOM_LEN
TlsFrameTypes
@ TLS_FRAME_HDR
@ TLS_FRAME_DATA
@ TLS_FRAME_ALERT_DATA
@ TLS_FRAME_SSLV2_PDU
@ TLS_FRAME_HB_DATA
@ TLS_FRAME_PDU
@ TLS_FRAME_SSLV2_HDR
struct SSLCertsChain_ SSLCertsChain
Flow data structure.
Definition flow.h:356
uint8_t * cert_data
TAILQ_ENTRY(SSLCertsChain_) next
uint32_t cert_log_flag
char * cert0_fingerprint
uint32_t hs_buffer_size
uint8_t handshake_type
uint32_t hs_buffer_message_size
uint16_t cert0_sans_len
uint8_t * certs_buffer
int64_t cert0_not_after
TAILQ_HEAD(, SSLCertsChain_) certs
uint32_t bytes_processed
uint8_t * hs_buffer
uint8_t random[TLS_RANDOM_LEN]
uint8_t hs_buffer_message_type
uint32_t record_length
uint16_t session_id_length
uint32_t certs_buffer_size
uint32_t record_lengths_length
JA3Buffer * ja3_str
int64_t cert0_not_before
HandshakeParams * hs
uint32_t hs_buffer_offset
uint32_t message_length
SSLv[2.0|3.[0|1|2|3]] state structure.
uint32_t hb_record_len
SSLStateConnp server_connp
uint16_t events
SSLStateConnp * curr_connp
SSLStateConnp client_connp
uint32_t current_flags
enum TlsStateServer server_state
AppLayerTxData tx_data
AppLayerStateData state_data
enum TlsStateClient client_state
uint32_t flags