1 /* Copyright (C) 2007-2012 Open Information Security Foundation
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
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.
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
21 * \author Anoop Saldanha <anoopsaldanha@gmail.com>
22 * \author Pierre Chifflier <pierre.chifflier@ssi.gouv.fr>
26 #ifndef __APP_LAYER_SSL_H__
27 #define __APP_LAYER_SSL_H__
29 #include "decode-events.h"
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
,
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
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
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
72 #define SSL_AL_FLAG_STATE_LOGGED 0x4000
75 #define SSL_TLS_LOG_PEM (1 << 0)
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 */
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,
90 typedef struct SSLCertsChain_
{
93 TAILQ_ENTRY(SSLCertsChain_
) next
;
97 typedef struct SSLStateConnp_
{
99 uint32_t record_length
;
100 /* record length's length for SSLv2 */
101 uint32_t record_lengths_length
;
103 /* offset of the beginning of the current message (including header) */
104 uint32_t message_start
;
105 uint32_t message_length
;
108 uint8_t content_type
;
110 uint8_t handshake_type
;
111 uint32_t handshake_length
;
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
;
118 /* sslv2 client hello session id length */
119 uint16_t session_id_length
;
122 char *cert0_issuerdn
;
123 char *cert0_fingerprint
;
126 uint32_t cert_input_len
;
128 TAILQ_HEAD(, SSLCertsChain_
) certs
;
130 uint32_t cert_log_flag
;
132 /* buffer for the tls record.
133 * We use a malloced buffer, if the record is fragmented */
140 * \brief SSLv[2.0|3.[0|1|2|3]] state structure.
142 * Structure to store the SSL state values.
144 typedef struct SSLState_
{
147 /* holds some state flags we need */
150 SSLStateConnp
*curr_connp
;
152 SSLStateConnp client_connp
;
153 SSLStateConnp server_connp
;
156 void RegisterSSLParsers(void);
157 void SSLParserRegisterTests(void);
159 #endif /* __APP_LAYER_SSL_H__ */