suricata
app-layer-ssl.c
Go to the documentation of this file.
1 /* Copyright (C) 2007-2024 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  * \author Mats Klepsland <mats.klepsland@gmail.com>
24  *
25  */
26 
27 #include "suricata-common.h"
28 #include "decode.h"
29 
30 #include "app-layer.h"
31 #include "app-layer-detect-proto.h"
32 #include "app-layer-protos.h"
33 #include "app-layer-parser.h"
34 #include "app-layer-frames.h"
35 #include "app-layer-events.h"
36 #include "app-layer-ssl.h"
37 
38 #include "conf.h"
39 
40 #include "feature.h"
41 
42 #include "util-debug.h"
43 #include "util-ja3.h"
44 #include "util-enum.h"
45 #include "util-validate.h"
46 
47 static SCEnumCharMap tls_state_client_table[] = {
48  {
49  "client_in_progress",
51  },
52  {
53  "client_hello_done",
55  },
56  {
57  "client_cert_done",
59  },
60  {
61  "client_handshake_done",
63  },
64  {
65  "client_finished",
67  },
68  { NULL, -1 },
69 };
70 
71 static SCEnumCharMap tls_state_server_table[] = {
72  {
73  "server_in_progress",
75  },
76  {
77  "server_hello",
79  },
80  {
81  "server_cert_done",
83  },
84  {
85  "server_hello_done",
87  },
88  {
89  "server_handshake_done",
91  },
92  {
93  "server_finished",
95  },
96  { NULL, -1 },
97 };
98 
100  {
101  "pdu",
103  },
104  {
105  "hdr",
107  },
108  {
109  "data",
111  },
112  {
113  "alert",
115  },
116  {
117  "heartbeat",
119  },
120  {
121  "ssl2.hdr",
123  },
124  {
125  "ssl2.pdu",
127  },
128  { NULL, -1 },
129 };
130 
132  /* TLS protocol messages */
133  { "INVALID_SSLV2_HEADER", TLS_DECODER_EVENT_INVALID_SSLV2_HEADER },
134  { "INVALID_TLS_HEADER", TLS_DECODER_EVENT_INVALID_TLS_HEADER },
135  { "INVALID_RECORD_VERSION", TLS_DECODER_EVENT_INVALID_RECORD_VERSION },
136  { "INVALID_RECORD_TYPE", TLS_DECODER_EVENT_INVALID_RECORD_TYPE },
137  { "INVALID_RECORD_LENGTH", TLS_DECODER_EVENT_INVALID_RECORD_LENGTH },
138  { "INVALID_HANDSHAKE_MESSAGE", TLS_DECODER_EVENT_INVALID_HANDSHAKE_MESSAGE },
139  { "HEARTBEAT_MESSAGE", TLS_DECODER_EVENT_HEARTBEAT },
140  { "INVALID_HEARTBEAT_MESSAGE", TLS_DECODER_EVENT_INVALID_HEARTBEAT },
141  { "OVERFLOW_HEARTBEAT_MESSAGE", TLS_DECODER_EVENT_OVERFLOW_HEARTBEAT },
142  { "DATALEAK_HEARTBEAT_MISMATCH", TLS_DECODER_EVENT_DATALEAK_HEARTBEAT_MISMATCH },
143  { "HANDSHAKE_INVALID_LENGTH", TLS_DECODER_EVENT_HANDSHAKE_INVALID_LENGTH },
144  { "MULTIPLE_SNI_EXTENSIONS", TLS_DECODER_EVENT_MULTIPLE_SNI_EXTENSIONS },
145  { "INVALID_SNI_TYPE", TLS_DECODER_EVENT_INVALID_SNI_TYPE },
146  { "INVALID_SNI_LENGTH", TLS_DECODER_EVENT_INVALID_SNI_LENGTH },
147  { "TOO_MANY_RECORDS_IN_PACKET", TLS_DECODER_EVENT_TOO_MANY_RECORDS_IN_PACKET },
148  { "INVALID_ALERT_MESSAGE", TLS_DECODER_EVENT_INVALID_ALERT },
149  /* certificate decoding messages */
150  { "INVALID_CERTIFICATE", TLS_DECODER_EVENT_INVALID_CERTIFICATE },
151  { "CERTIFICATE_INVALID_LENGTH", TLS_DECODER_EVENT_CERTIFICATE_INVALID_LENGTH },
152  { "CERTIFICATE_INVALID_VERSION", TLS_DECODER_EVENT_CERTIFICATE_INVALID_VERSION },
153  { "CERTIFICATE_INVALID_SERIAL", TLS_DECODER_EVENT_CERTIFICATE_INVALID_SERIAL },
154  { "CERTIFICATE_INVALID_ALGORITHMIDENTIFIER",
156  { "CERTIFICATE_INVALID_X509NAME", TLS_DECODER_EVENT_CERTIFICATE_INVALID_X509NAME },
157  { "CERTIFICATE_INVALID_DATE", TLS_DECODER_EVENT_CERTIFICATE_INVALID_DATE },
158  { "CERTIFICATE_INVALID_EXTENSIONS", TLS_DECODER_EVENT_CERTIFICATE_INVALID_EXTENSIONS },
159  { "CERTIFICATE_INVALID_DER", TLS_DECODER_EVENT_CERTIFICATE_INVALID_DER },
160  { "CERTIFICATE_INVALID_SUBJECT", TLS_DECODER_EVENT_CERTIFICATE_INVALID_SUBJECT },
161  { "CERTIFICATE_INVALID_ISSUER", TLS_DECODER_EVENT_CERTIFICATE_INVALID_ISSUER },
162  { "CERTIFICATE_INVALID_VALIDITY", TLS_DECODER_EVENT_CERTIFICATE_INVALID_VALIDITY },
163  { "ERROR_MESSAGE_ENCOUNTERED", TLS_DECODER_EVENT_ERROR_MSG_ENCOUNTERED },
164  /* used as a generic error event */
165  { "INVALID_SSL_RECORD", TLS_DECODER_EVENT_INVALID_SSL_RECORD },
166  { NULL, -1 },
167 };
168 
169 enum {
170  /* X.509 error codes, returned by decoder
171  * THESE CONSTANTS MUST MATCH rust/src/x509/mod.rs ! */
181 
182  /* error getting data */
186 };
187 
188 /* JA3 and JA4 fingerprints are disabled by default */
189 #define SSL_CONFIG_DEFAULT_JA3 0
190 #ifdef HAVE_JA4
191 #define SSL_CONFIG_DEFAULT_JA4 0
192 #endif
193 
195  SSL_CNF_ENC_HANDLE_TRACK_ONLY = 0, /**< disable raw content, continue tracking */
196  SSL_CNF_ENC_HANDLE_BYPASS = 1, /**< skip processing of flow, bypass if possible */
197  SSL_CNF_ENC_HANDLE_FULL = 2, /**< handle fully like any other proto */
198 };
199 
200 typedef struct SslConfig_ {
202  /** dynamic setting for ja3 and ja4: can be enabled on demand if not
203  * explicitly disabled. */
204  SC_ATOMIC_DECLARE(int, enable_ja3);
205  bool disable_ja3; /**< ja3 explicitly disabled. Don't enable on demand. */
206  SC_ATOMIC_DECLARE(int, enable_ja4);
207  bool disable_ja4; /**< ja4 explicitly disabled. Don't enable on demand. */
209 
211 
212 /* SSLv3 record types */
213 #define SSLV3_CHANGE_CIPHER_SPEC 20
214 #define SSLV3_ALERT_PROTOCOL 21
215 #define SSLV3_HANDSHAKE_PROTOCOL 22
216 #define SSLV3_APPLICATION_PROTOCOL 23
217 #define SSLV3_HEARTBEAT_PROTOCOL 24
218 
219 /* SSLv3 handshake protocol types */
220 #define SSLV3_HS_HELLO_REQUEST 0
221 #define SSLV3_HS_CLIENT_HELLO 1
222 #define SSLV3_HS_SERVER_HELLO 2
223 #define SSLV3_HS_NEW_SESSION_TICKET 4
224 #define SSLV3_HS_CERTIFICATE 11
225 #define SSLV3_HS_SERVER_KEY_EXCHANGE 12
226 #define SSLV3_HS_CERTIFICATE_REQUEST 13
227 #define SSLV3_HS_SERVER_HELLO_DONE 14
228 #define SSLV3_HS_CERTIFICATE_VERIFY 15
229 #define SSLV3_HS_CLIENT_KEY_EXCHANGE 16
230 #define SSLV3_HS_FINISHED 20
231 #define SSLV3_HS_CERTIFICATE_URL 21
232 #define SSLV3_HS_CERTIFICATE_STATUS 22
233 
234 /* SSLv2 protocol message types */
235 #define SSLV2_MT_ERROR 0
236 #define SSLV2_MT_CLIENT_HELLO 1
237 #define SSLV2_MT_CLIENT_MASTER_KEY 2
238 #define SSLV2_MT_CLIENT_FINISHED 3
239 #define SSLV2_MT_SERVER_HELLO 4
240 #define SSLV2_MT_SERVER_VERIFY 5
241 #define SSLV2_MT_SERVER_FINISHED 6
242 #define SSLV2_MT_REQUEST_CERTIFICATE 7
243 #define SSLV2_MT_CLIENT_CERTIFICATE 8
244 
245 #define SSLV3_RECORD_HDR_LEN 5
246 /** max length according to RFC 5246 6.2.2 is 2^14 + 1024 */
247 #define SSLV3_RECORD_MAX_LEN ((1 << 14) + 1024)
248 
249 #define SSLV3_CLIENT_HELLO_VERSION_LEN 2
250 #define SSLV3_CLIENT_HELLO_RANDOM_LEN 32
251 
252 /* TLS heartbeat protocol types */
253 #define TLS_HB_REQUEST 1
254 #define TLS_HB_RESPONSE 2
255 
256 #define SSL_RECORD_MINIMUM_LENGTH 6
257 
258 #define SHA1_STRING_LENGTH 60
259 
260 #define HAS_SPACE(n) ((uint64_t)(input - initial_input) + (uint64_t)(n) <= (uint64_t)(input_len))
261 
263  int retval; // nr bytes consumed from input, or < 0 on error
264  uint32_t needed; // more bytes needed
265 };
266 #define SSL_DECODER_ERROR(e) \
267  (struct SSLDecoderResult) \
268  { \
269  (e), 0 \
270  }
271 #define SSL_DECODER_OK(c) \
272  (struct SSLDecoderResult) \
273  { \
274  (uint32_t)(c), 0 \
275  }
276 #define SSL_DECODER_INCOMPLETE(c, n) \
277  (struct SSLDecoderResult) \
278  { \
279  (uint32_t)(c), (n) \
280  }
281 
282 static inline int SafeMemcpy(void *dst, size_t dst_offset, size_t dst_size,
283  const void *src, size_t src_offset, size_t src_size, size_t src_tocopy) WARN_UNUSED;
284 
285 static inline int SafeMemcpy(void *dst, size_t dst_offset, size_t dst_size,
286  const void *src, size_t src_offset, size_t src_size, size_t src_tocopy)
287 {
288  DEBUG_VALIDATE_BUG_ON(dst_offset >= dst_size);
289  DEBUG_VALIDATE_BUG_ON(src_offset >= src_size);
290  DEBUG_VALIDATE_BUG_ON(src_tocopy > (src_size - src_offset));
291  DEBUG_VALIDATE_BUG_ON(src_tocopy > (dst_size - dst_offset));
292 
293  if (dst_offset < dst_size && src_offset < src_size &&
294  src_tocopy <= (src_size - src_offset) &&
295  src_tocopy <= (dst_size - dst_offset)) {
296  memcpy(dst + dst_offset, src + src_offset, src_tocopy);
297  return 0;
298  }
299  return -1;
300 }
301 
302 #ifdef DEBUG_VALIDATION
303 #define ValidateRecordState(connp) \
304  do { \
305  DEBUG_VALIDATE_BUG_ON(((connp)->record_length + SSLV3_RECORD_HDR_LEN) < \
306  (connp)->bytes_processed); \
307  } while(0);
308 #else
309 #define ValidateRecordState(...)
310 #endif
311 
312 #define SSLParserHSReset(connp) \
313  do { \
314  (connp)->handshake_type = 0; \
315  (connp)->message_length = 0; \
316  } while (0)
317 
318 #define SSLParserReset(state) \
319  do { \
320  SCLogDebug("resetting state"); \
321  (state)->curr_connp->bytes_processed = 0; \
322  SSLParserHSReset((state)->curr_connp); \
323  } while(0)
324 
325 #define SSLSetEvent(ssl_state, event) \
326  do { \
327  SCLogDebug("setting event %u", (event)); \
328  if ((ssl_state) == NULL) { \
329  SCLogDebug("could not set decoder event %u", event); \
330  } else { \
331  SCAppLayerDecoderEventsSetEventRaw(&(ssl_state)->tx_data.events, (event)); \
332  (ssl_state)->events++; \
333  } \
334  } while (0)
335 
336 static void *SSLGetTx(void *state, uint64_t tx_id)
337 {
338  SSLState *ssl_state = (SSLState *)state;
339  return ssl_state;
340 }
341 
342 static uint64_t SSLGetTxCnt(void *state)
343 {
344  /* single tx */
345  return 1;
346 }
347 
348 static void UpdateClientState(SSLState *ssl_state, enum TlsStateClient s)
349 {
350 #ifdef DEBUG
351  enum TlsStateClient old = ssl_state->client_state;
352 #endif
353  ssl_state->client_state = s;
354 #ifdef DEBUG
355  SCLogDebug("toserver: state updated to %u from %u", s, old);
356 #endif
357 }
358 
359 static void UpdateServerState(SSLState *ssl_state, enum TlsStateServer s)
360 {
361 #ifdef DEBUG
362  enum TlsStateServer old = ssl_state->server_state;
363 #endif
364  ssl_state->server_state = s;
365 #ifdef DEBUG
366  SCLogDebug("toclient: state updated to %u from %u", s, old);
367 #endif
368 }
369 
370 static int SSLGetAlstateProgress(void *tx, uint8_t direction)
371 {
372  SSLState *ssl_state = (SSLState *)tx;
373  if (direction & STREAM_TOCLIENT) {
374  return ssl_state->server_state;
375  } else {
376  return ssl_state->client_state;
377  }
378 }
379 
380 static AppLayerTxData *SSLGetTxData(void *vtx)
381 {
382  SSLState *ssl_state = (SSLState *)vtx;
383  return &ssl_state->tx_data;
384 }
385 
386 static AppLayerStateData *SSLGetStateData(void *vstate)
387 {
388  SSLState *ssl_state = (SSLState *)vstate;
389  return &ssl_state->state_data;
390 }
391 
392 static void TlsDecodeHSCertificateErrSetEvent(SSLState *ssl_state, uint32_t err)
393 {
394  switch(err) {
397  break;
398  case ERR_EXTRACT_ISSUER:
400  break;
401  case ERR_EXTRACT_SUBJECT:
403  break;
404  case ERR_INVALID_DER:
406  break;
409  break;
410  case ERR_INVALID_DATE:
412  break;
415  break;
418  break;
419  case ERR_INVALID_SERIAL:
421  break;
422  case ERR_INVALID_VERSION:
424  break;
425  case ERR_INVALID_LENGTH:
427  break;
429  default:
431  break;
432  }
433 }
434 
435 static inline int TlsDecodeHSCertificateFingerprint(
436  SSLStateConnp *connp, const uint8_t *input, uint32_t cert_len)
437 {
438  if (unlikely(connp->cert0_fingerprint != NULL))
439  return 0;
440 
442  if (connp->cert0_fingerprint == NULL)
443  return -1;
444 
445  uint8_t hash[SC_SHA1_LEN];
446  if (SCSha1HashBuffer(input, cert_len, hash, sizeof(hash)) == 1) {
447  SCToHex_sep(
448  (uint8_t *)connp->cert0_fingerprint, SHA1_STRING_LENGTH, ':', hash, SC_SHA1_LEN);
449  }
450  return 0;
451 }
452 
453 static inline int TlsDecodeHSCertificateAddCertToChain(
454  SSLStateConnp *connp, const uint8_t *input, uint32_t cert_len)
455 {
456  SSLCertsChain *cert = SCCalloc(1, sizeof(SSLCertsChain));
457  if (cert == NULL)
458  return -1;
459 
460  cert->cert_data = (uint8_t *)input;
461  cert->cert_len = cert_len;
462  TAILQ_INSERT_TAIL(&connp->certs, cert, next);
463 
464  return 0;
465 }
466 
467 static int TlsDecodeHSCertificate(SSLState *ssl_state, SSLStateConnp *connp,
468  const uint8_t *const initial_input, const uint32_t input_len, const int certn)
469 {
470  const uint8_t *input = (uint8_t *)initial_input;
471  uint32_t err_code = 0;
472  X509 *x509 = NULL;
473  int rc = 0;
474 
475  if (!(HAS_SPACE(3)))
476  goto invalid_cert;
477 
478  uint32_t cert_len = *input << 16 | *(input + 1) << 8 | *(input + 2);
479  input += 3;
480 
481  if (!(HAS_SPACE(cert_len)))
482  goto invalid_cert;
483 
484  /* only store fields from the first certificate in the chain */
485  if (certn == 0 && connp->cert0_subject == NULL && connp->cert0_issuerdn == NULL &&
486  connp->cert0_serial == NULL) {
487  x509 = SCX509Decode(input, cert_len, &err_code);
488  if (x509 == NULL) {
489  TlsDecodeHSCertificateErrSetEvent(ssl_state, err_code);
490  goto next;
491  }
492 
493  SCX509GetSubject(x509, &connp->cert0_subject, &connp->cert0_subject_len);
494  if (connp->cert0_subject == NULL) {
495  err_code = ERR_EXTRACT_SUBJECT;
496  goto error;
497  }
498 
499  SCX509GetIssuer(x509, &connp->cert0_issuerdn, &connp->cert0_issuerdn_len);
500  if (connp->cert0_issuerdn == NULL) {
501  err_code = ERR_EXTRACT_ISSUER;
502  goto error;
503  }
504 
505  connp->cert0_sans_num = SCX509GetSubjectAltNameLen(x509);
506  connp->cert0_sans = SCCalloc(connp->cert0_sans_num, sizeof(SSLSubjectAltName));
507  if (connp->cert0_sans == NULL) {
508  goto error;
509  }
510  for (uint16_t i = 0; i < connp->cert0_sans_num; i++) {
511  SCX509GetSubjectAltNameAt(
512  x509, i, &connp->cert0_sans[i].san, &connp->cert0_sans[i].san_len);
513  }
514 
515  SCX509GetSerial(x509, &connp->cert0_serial, &connp->cert0_serial_len);
516  if (connp->cert0_serial == NULL) {
517  err_code = ERR_INVALID_SERIAL;
518  goto error;
519  }
520 
521  rc = SCX509GetValidity(x509, &connp->cert0_not_before, &connp->cert0_not_after);
522  if (rc != 0) {
523  err_code = ERR_EXTRACT_VALIDITY;
524  goto error;
525  }
526 
527  SCX509Free(x509);
528  x509 = NULL;
529 
530  rc = TlsDecodeHSCertificateFingerprint(connp, input, cert_len);
531  if (rc != 0) {
532  SCLogDebug("TlsDecodeHSCertificateFingerprint failed with %d", rc);
533  goto error;
534  }
535  }
536 
537  rc = TlsDecodeHSCertificateAddCertToChain(connp, input, cert_len);
538  if (rc != 0) {
539  SCLogDebug("TlsDecodeHSCertificateAddCertToChain failed with %d", rc);
540  goto error;
541  }
542 
543 next:
544  input += cert_len;
545  return (int)(input - initial_input);
546 
547 error:
548  if (err_code != 0)
549  TlsDecodeHSCertificateErrSetEvent(ssl_state, err_code);
550  if (x509 != NULL)
551  SCX509Free(x509);
552 
553  return -1;
554 
555 invalid_cert:
556  SCLogDebug("TLS invalid certificate");
558  return -1;
559 }
560 
561 /** \internal
562  * \brief parse cert data in a certificate handshake message
563  * will be called with all data.
564  * \retval consumed bytes consumed or -1 on error
565  */
566 static int TlsDecodeHSCertificates(SSLState *ssl_state, SSLStateConnp *connp,
567  const uint8_t *const initial_input, const uint32_t input_len)
568 {
569  const uint8_t *input = (uint8_t *)initial_input;
570 
571  if (!(HAS_SPACE(3)))
572  return -1;
573 
574  const uint32_t cert_chain_len = *input << 16 | *(input + 1) << 8 | *(input + 2);
575  input += 3;
576 
577  if (!(HAS_SPACE(cert_chain_len)))
578  return -1;
579 
580  if (connp->certs_buffer != NULL) {
581  // TODO should we set an event here?
582  return -1;
583  }
584 
585  connp->certs_buffer = SCCalloc(1, cert_chain_len);
586  if (connp->certs_buffer == NULL) {
587  return -1;
588  }
589  connp->certs_buffer_size = cert_chain_len;
590  memcpy(connp->certs_buffer, input, cert_chain_len);
591 
592  int cert_cnt = 0;
593  uint32_t processed_len = 0;
594  /* coverity[tainted_data] */
595  while (processed_len < cert_chain_len) {
596  int rc = TlsDecodeHSCertificate(ssl_state, connp, connp->certs_buffer + processed_len,
597  connp->certs_buffer_size - processed_len, cert_cnt);
598  if (rc <= 0) { // 0 should be impossible, but lets be defensive
599  return -1;
600  }
601  DEBUG_VALIDATE_BUG_ON(processed_len + (uint32_t)rc > cert_chain_len);
602  if (processed_len + (uint32_t)rc > cert_chain_len) {
603  return -1;
604  }
605 
606  processed_len += (uint32_t)rc;
607  }
608 
609  return processed_len + 3;
610 }
611 
612 /**
613  * \inline
614  * \brief Check if value is GREASE.
615  *
616  * http://tools.ietf.org/html/draft-davidben-tls-grease-00
617  *
618  * \param value Value to check.
619  *
620  * \retval 1 if is GREASE.
621  * \retval 0 if not is GREASE.
622  */
623 static inline int TLSDecodeValueIsGREASE(const uint16_t value)
624 {
625  switch (value)
626  {
627  case 0x0a0a:
628  case 0x1a1a:
629  case 0x2a2a:
630  case 0x3a3a:
631  case 0x4a4a:
632  case 0x5a5a:
633  case 0x6a6a:
634  case 0x7a7a:
635  case 0x8a8a:
636  case 0x9a9a:
637  case 0xaaaa:
638  case 0xbaba:
639  case 0xcaca:
640  case 0xdada:
641  case 0xeaea:
642  case 0xfafa:
643  return 1;
644  default:
645  return 0;
646  }
647 }
648 
649 static inline int TLSDecodeHSHelloVersion(SSLState *ssl_state,
650  const uint8_t * const initial_input,
651  const uint32_t input_len)
652 {
653  uint8_t *input = (uint8_t *)initial_input;
654 
656  SCLogDebug("TLS handshake invalid length");
657  SSLSetEvent(ssl_state,
659  return -1;
660  }
661 
662  uint16_t version = (uint16_t)(*input << 8) | *(input + 1);
663  ssl_state->curr_connp->version = version;
664 
665  if (ssl_state->current_flags &
667  SCTLSHandshakeSetTLSVersion(ssl_state->curr_connp->hs, version);
668  }
669 
670  /* TLSv1.3 draft1 to draft21 use the version field as earlier TLS
671  versions, instead of using the supported versions extension. */
672  if ((ssl_state->current_flags & SSL_AL_FLAG_STATE_SERVER_HELLO) &&
673  ((ssl_state->curr_connp->version == TLS_VERSION_13) ||
674  (((ssl_state->curr_connp->version >> 8) & 0xff) == 0x7f))) {
675  ssl_state->flags |= SSL_AL_FLAG_LOG_WITHOUT_CERT;
676  }
677 
678  /* Catch some early TLSv1.3 draft implementations that does not conform
679  to the draft version. */
680  if ((ssl_state->curr_connp->version >= 0x7f01) &&
681  (ssl_state->curr_connp->version < 0x7f10)) {
682  ssl_state->curr_connp->version = TLS_VERSION_13_PRE_DRAFT16;
683  }
684 
685  /* TLSv1.3 drafts from draft1 to draft15 use 0x0304 (TLSv1.3) as the
686  version number, which makes it hard to accurately pinpoint the
687  exact draft version. */
688  else if (ssl_state->curr_connp->version == TLS_VERSION_13) {
689  ssl_state->curr_connp->version = TLS_VERSION_13_PRE_DRAFT16;
690  }
691 
692  if (SC_ATOMIC_GET(ssl_config.enable_ja3) && ssl_state->curr_connp->ja3_str == NULL) {
693  ssl_state->curr_connp->ja3_str = Ja3BufferInit();
694  if (ssl_state->curr_connp->ja3_str == NULL)
695  return -1;
696 
697  int rc = Ja3BufferAddValue(&ssl_state->curr_connp->ja3_str, version);
698  if (rc != 0)
699  return -1;
700  }
701 
703 
704  return (int)(input - initial_input);
705 }
706 
707 static inline int TLSDecodeHSHelloRandom(SSLState *ssl_state,
708  const uint8_t * const initial_input,
709  const uint32_t input_len)
710 {
711  uint8_t *input = (uint8_t *)initial_input;
712 
714  SCLogDebug("TLS handshake invalid length");
715  SSLSetEvent(ssl_state,
717  return -1;
718  }
719 
721  memcpy(ssl_state->server_connp.random, input, TLS_RANDOM_LEN);
722  ssl_state->flags |= TLS_TS_RANDOM_SET;
723  } else if (ssl_state->current_flags & SSL_AL_FLAG_STATE_CLIENT_HELLO) {
724  memcpy(ssl_state->client_connp.random, input, TLS_RANDOM_LEN);
725  ssl_state->flags |= TLS_TC_RANDOM_SET;
726  }
727 
728  /* Skip random */
730 
731  return (int)(input - initial_input);
732 }
733 
734 static inline int TLSDecodeHSHelloSessionID(SSLState *ssl_state,
735  const uint8_t * const initial_input,
736  const uint32_t input_len)
737 {
738  uint8_t *input = (uint8_t *)initial_input;
739 
740  if (!(HAS_SPACE(1)))
741  goto invalid_length;
742 
743  uint8_t session_id_length = *input;
744  input += 1;
745 
746  if (!(HAS_SPACE(session_id_length)))
747  goto invalid_length;
748 
749  if (session_id_length != 0 && ssl_state->curr_connp->session_id == NULL) {
750  ssl_state->curr_connp->session_id = SCMalloc(session_id_length);
751 
752  if (unlikely(ssl_state->curr_connp->session_id == NULL)) {
753  return -1;
754  }
755 
756  if (SafeMemcpy(ssl_state->curr_connp->session_id, 0, session_id_length,
757  input, 0, input_len, session_id_length) != 0) {
758  return -1;
759  }
760  ssl_state->curr_connp->session_id_length = session_id_length;
761 
762  if ((ssl_state->current_flags & SSL_AL_FLAG_STATE_SERVER_HELLO) &&
763  ssl_state->client_connp.session_id != NULL &&
764  ssl_state->server_connp.session_id != NULL) {
765  if ((ssl_state->client_connp.session_id_length ==
766  ssl_state->server_connp.session_id_length) &&
767  (memcmp(ssl_state->server_connp.session_id,
768  ssl_state->client_connp.session_id, session_id_length) == 0)) {
769  ssl_state->flags |= SSL_AL_FLAG_SESSION_RESUMED;
770  }
771  }
772  }
773 
774  input += session_id_length;
775 
776  return (int)(input - initial_input);
777 
778 invalid_length:
779  SCLogDebug("TLS handshake invalid length");
780  SSLSetEvent(ssl_state,
782  return -1;
783 }
784 
785 static inline int TLSDecodeHSHelloCipherSuites(SSLState *ssl_state,
786  const uint8_t * const initial_input,
787  const uint32_t input_len)
788 {
789  const uint8_t *input = initial_input;
790 
791  if (!(HAS_SPACE(2)))
792  goto invalid_length;
793 
794  uint16_t cipher_suites_length;
795 
797  cipher_suites_length = 2;
798  } else if (ssl_state->current_flags & SSL_AL_FLAG_STATE_CLIENT_HELLO) {
799  cipher_suites_length = (uint16_t)(*input << 8) | *(input + 1);
800  input += 2;
801  } else {
802  return -1;
803  }
804 
805  if (!(HAS_SPACE(cipher_suites_length)))
806  goto invalid_length;
807 
808  /* Cipher suites length should always be divisible by 2 */
809  if ((cipher_suites_length % 2) != 0) {
810  goto invalid_length;
811  }
812 
813  const bool enable_ja3 =
814  SC_ATOMIC_GET(ssl_config.enable_ja3) && ssl_state->curr_connp->ja3_hash == NULL;
815 
816  JA3Buffer *ja3_cipher_suites = NULL;
817 
818  if (enable_ja3) {
819  ja3_cipher_suites = Ja3BufferInit();
820  if (ja3_cipher_suites == NULL)
821  return -1;
822  }
823 
824  uint16_t processed_len = 0;
825  /* coverity[tainted_data] */
826  while (processed_len < cipher_suites_length) {
827  if (!(HAS_SPACE(2))) {
828  if (enable_ja3) {
829  Ja3BufferFree(&ja3_cipher_suites);
830  }
831  goto invalid_length;
832  }
833 
834  uint16_t cipher_suite = (uint16_t)(*input << 8) | *(input + 1);
835  input += 2;
836 
837  if (TLSDecodeValueIsGREASE(cipher_suite) != 1) {
838  if (ssl_state->current_flags &
840  SCTLSHandshakeAddCipher(ssl_state->curr_connp->hs, cipher_suite);
841  }
842  if (enable_ja3) {
843  int rc = Ja3BufferAddValue(&ja3_cipher_suites, cipher_suite);
844  if (rc != 0) {
845  return -1;
846  }
847  }
848  }
849  processed_len += 2;
850  }
851 
852  if (enable_ja3) {
853  int rc = Ja3BufferAppendBuffer(&ssl_state->curr_connp->ja3_str, &ja3_cipher_suites);
854  if (rc == -1) {
855  return -1;
856  }
857  }
858 
859  return (int)(input - initial_input);
860 
861 invalid_length:
862  SCLogDebug("TLS handshake invalid length");
863  SSLSetEvent(ssl_state,
865  return -1;
866 }
867 
868 static inline int TLSDecodeHSHelloCompressionMethods(SSLState *ssl_state,
869  const uint8_t * const initial_input,
870  const uint32_t input_len)
871 {
872  const uint8_t *input = initial_input;
873 
874  if (!(HAS_SPACE(1)))
875  goto invalid_length;
876 
877  /* Skip compression methods */
879  input += 1;
880  } else {
881  uint8_t compression_methods_length = *input;
882  input += 1;
883 
884  if (!(HAS_SPACE(compression_methods_length)))
885  goto invalid_length;
886 
887  input += compression_methods_length;
888  }
889 
890  return (int)(input - initial_input);
891 
892 invalid_length:
893  SCLogDebug("TLS handshake invalid_length");
894  SSLSetEvent(ssl_state,
896  return -1;
897 }
898 
899 static inline int TLSDecodeHSHelloExtensionSni(SSLState *ssl_state,
900  const uint8_t * const initial_input,
901  const uint32_t input_len)
902 {
903  uint8_t *input = (uint8_t *)initial_input;
904 
905  /* Empty extension */
906  if (input_len == 0)
907  return 0;
908 
909  if (!(HAS_SPACE(2)))
910  goto invalid_length;
911 
912  /* Skip sni_list_length */
913  input += 2;
914 
915  if (!(HAS_SPACE(1)))
916  goto invalid_length;
917 
918  uint8_t sni_type = *input;
919  input += 1;
920 
921  /* Currently the only type allowed is host_name
922  (RFC6066 section 3). */
923  if (sni_type != SSL_SNI_TYPE_HOST_NAME) {
924  SCLogDebug("Unknown SNI type");
925  SSLSetEvent(ssl_state,
927  return -1;
928  }
929 
930  if (!(HAS_SPACE(2)))
931  goto invalid_length;
932 
933  uint16_t sni_len = (uint16_t)(*input << 8) | *(input + 1);
934  input += 2;
935 
936  /* host_name contains the fully qualified domain name,
937  and should therefore be limited by the maximum domain
938  name length. */
939  if (!(HAS_SPACE(sni_len)) || sni_len > 255 || sni_len == 0) {
940  SSLSetEvent(ssl_state,
942  return -1;
943  }
944 
945  /* There must not be more than one extension of the same
946  type (RFC5246 section 7.4.1.4). */
947  if (ssl_state->curr_connp->sni) {
948  SCLogDebug("Multiple SNI extensions");
949  SSLSetEvent(ssl_state,
951  input += sni_len;
952  return (int)(input - initial_input);
953  }
954 
955  ssl_state->curr_connp->sni_len = sni_len;
956  ssl_state->curr_connp->sni = SCMalloc(sni_len);
957  if (unlikely(ssl_state->curr_connp->sni == NULL))
958  return -1;
959 
960  const size_t consumed = input - initial_input;
961  if (SafeMemcpy(ssl_state->curr_connp->sni, 0, sni_len, initial_input, consumed, input_len,
962  sni_len) != 0) {
963  SCFree(ssl_state->curr_connp->sni);
964  ssl_state->curr_connp->sni = NULL;
965  return -1;
966  }
967  input += sni_len;
968 
969  return (int)(input - initial_input);
970 
971 invalid_length:
972  SCLogDebug("TLS handshake invalid length");
973  SSLSetEvent(ssl_state,
975 
976 
977  return -1;
978 }
979 
980 static inline int TLSDecodeHSHelloExtensionSupportedVersions(SSLState *ssl_state,
981  const uint8_t * const initial_input,
982  const uint32_t input_len)
983 {
984  const uint8_t *input = initial_input;
985 
986  /* Empty extension */
987  if (input_len == 0)
988  return 0;
989 
991  if (!(HAS_SPACE(1)))
992  goto invalid_length;
993 
994  uint8_t supported_ver_len = *input;
995  input += 1;
996 
997  if (supported_ver_len < 2)
998  goto invalid_length;
999 
1000  if (!(HAS_SPACE(supported_ver_len)))
1001  goto invalid_length;
1002 
1003  /* Use the first (and preferred) valid version as client version,
1004  * skip over GREASE and other possible noise. */
1005  uint16_t i = 0;
1006  while (i + 1 < (uint16_t)supported_ver_len) {
1007  uint16_t ver = (uint16_t)(input[i] << 8) | input[i + 1];
1008  if (TLSVersionValid(ver)) {
1009  ssl_state->curr_connp->version = ver;
1010  SCTLSHandshakeSetTLSVersion(ssl_state->curr_connp->hs, ver);
1011  break;
1012  }
1013  i += 2;
1014  }
1015 
1016  /* Set a flag to indicate that we have seen this extension */
1018 
1019  input += supported_ver_len;
1020  }
1021  else if (ssl_state->current_flags & SSL_AL_FLAG_STATE_SERVER_HELLO) {
1022  if (!(HAS_SPACE(2)))
1023  goto invalid_length;
1024 
1025  uint16_t ver = (uint16_t)(*input << 8) | *(input + 1);
1026 
1027  if ((ssl_state->flags & SSL_AL_FLAG_CH_VERSION_EXTENSION) &&
1028  (ver > TLS_VERSION_12)) {
1029  ssl_state->flags |= SSL_AL_FLAG_LOG_WITHOUT_CERT;
1030  }
1031 
1032  ssl_state->curr_connp->version = ver;
1033  input += 2;
1034  }
1035 
1036  return (int)(input - initial_input);
1037 
1038 invalid_length:
1039  SCLogDebug("TLS handshake invalid length");
1040  SSLSetEvent(ssl_state,
1042 
1043  return -1;
1044 }
1045 
1046 static inline int TLSDecodeHSHelloExtensionEllipticCurves(SSLState *ssl_state,
1047  const uint8_t * const initial_input,
1048  const uint32_t input_len,
1049  JA3Buffer *ja3_elliptic_curves)
1050 {
1051  const uint8_t *input = initial_input;
1052 
1053  /* Empty extension */
1054  if (input_len == 0)
1055  return 0;
1056 
1057  if (!(HAS_SPACE(2)))
1058  goto invalid_length;
1059 
1060  uint16_t elliptic_curves_len = (uint16_t)(*input << 8) | *(input + 1);
1061  input += 2;
1062 
1063  if (!(HAS_SPACE(elliptic_curves_len)))
1064  goto invalid_length;
1065 
1066  if ((ssl_state->current_flags & SSL_AL_FLAG_STATE_CLIENT_HELLO) && ja3_elliptic_curves) {
1067  uint16_t ec_processed_len = 0;
1068  /* coverity[tainted_data] */
1069  while (ec_processed_len < elliptic_curves_len)
1070  {
1071  if (!(HAS_SPACE(2)))
1072  goto invalid_length;
1073 
1074  uint16_t elliptic_curve = (uint16_t)(*input << 8) | *(input + 1);
1075  input += 2;
1076 
1077  if (TLSDecodeValueIsGREASE(elliptic_curve) != 1) {
1078  int rc = Ja3BufferAddValue(&ja3_elliptic_curves,
1079  elliptic_curve);
1080  if (rc != 0)
1081  return -1;
1082  }
1083 
1084  ec_processed_len += 2;
1085  }
1086 
1087  } else {
1088  /* Skip elliptic curves */
1089  input += elliptic_curves_len;
1090  }
1091 
1092  return (int)(input - initial_input);
1093 
1094 invalid_length:
1095  SCLogDebug("TLS handshake invalid length");
1096  SSLSetEvent(ssl_state,
1098 
1099  return -1;
1100 }
1101 
1102 static inline int TLSDecodeHSHelloExtensionEllipticCurvePF(SSLState *ssl_state,
1103  const uint8_t * const initial_input,
1104  const uint32_t input_len,
1105  JA3Buffer *ja3_elliptic_curves_pf)
1106 {
1107  const uint8_t *input = initial_input;
1108 
1109  /* Empty extension */
1110  if (input_len == 0)
1111  return 0;
1112 
1113  if (!(HAS_SPACE(1)))
1114  goto invalid_length;
1115 
1116  uint8_t ec_pf_len = *input;
1117  input += 1;
1118 
1119  if (!(HAS_SPACE(ec_pf_len)))
1120  goto invalid_length;
1121 
1122  if ((ssl_state->current_flags & SSL_AL_FLAG_STATE_CLIENT_HELLO) && ja3_elliptic_curves_pf) {
1123  uint8_t ec_pf_processed_len = 0;
1124  /* coverity[tainted_data] */
1125  while (ec_pf_processed_len < ec_pf_len)
1126  {
1127  uint8_t elliptic_curve_pf = *input;
1128  input += 1;
1129 
1130  if (TLSDecodeValueIsGREASE(elliptic_curve_pf) != 1) {
1131  int rc = Ja3BufferAddValue(&ja3_elliptic_curves_pf,
1132  elliptic_curve_pf);
1133  if (rc != 0)
1134  return -1;
1135  }
1136 
1137  ec_pf_processed_len += 1;
1138  }
1139 
1140  } else {
1141  /* Skip elliptic curve point formats */
1142  input += ec_pf_len;
1143  }
1144 
1145  return (int)(input - initial_input);
1146 
1147 invalid_length:
1148  SCLogDebug("TLS handshake invalid length");
1149  SSLSetEvent(ssl_state,
1151 
1152  return -1;
1153 }
1154 
1155 static inline int TLSDecodeHSHelloExtensionSigAlgorithms(
1156  SSLState *ssl_state, const uint8_t *const initial_input, const uint32_t input_len)
1157 {
1158  const uint8_t *input = initial_input;
1159 
1160  /* Empty extension */
1161  if (input_len == 0)
1162  return 0;
1163 
1164  if (!(HAS_SPACE(2)))
1165  goto invalid_length;
1166 
1167  uint16_t sigalgo_len = (uint16_t)(*input << 8) | *(input + 1);
1168  input += 2;
1169 
1170  /* Signature algorithms length should always be divisible by 2 */
1171  if ((sigalgo_len % 2) != 0) {
1172  goto invalid_length;
1173  }
1174 
1175  if (!(HAS_SPACE(sigalgo_len)))
1176  goto invalid_length;
1177 
1178  if (ssl_state->current_flags & SSL_AL_FLAG_STATE_CLIENT_HELLO) {
1179  uint16_t sigalgo_processed_len = 0;
1180  while (sigalgo_processed_len < sigalgo_len) {
1181  uint16_t sigalgo = (uint16_t)(*input << 8) | *(input + 1);
1182  input += 2;
1183  sigalgo_processed_len += 2;
1184 
1185  SCTLSHandshakeAddSigAlgo(ssl_state->curr_connp->hs, sigalgo);
1186  }
1187  } else {
1188  /* Skip signature algorithms */
1189  input += sigalgo_len;
1190  }
1191 
1192  return (int)(input - initial_input);
1193 
1194 invalid_length:
1195  SCLogDebug("Signature algorithm list invalid length");
1197 
1198  return -1;
1199 }
1200 
1201 static inline int TLSDecodeHSHelloExtensionALPN(
1202  SSLState *ssl_state, const uint8_t *const initial_input, const uint32_t input_len)
1203 {
1204  const uint8_t *input = initial_input;
1205 
1206  /* Empty extension */
1207  if (input_len == 0)
1208  return 0;
1209 
1210  if (!(HAS_SPACE(2)))
1211  goto invalid_length;
1212 
1213  uint16_t alpn_len = (uint16_t)(*input << 8) | *(input + 1);
1214  input += 2;
1215 
1216  if (!(HAS_SPACE(alpn_len)))
1217  goto invalid_length;
1218 
1219  /* We use 32 bits here to avoid potentially overflowing a value that
1220  needs to be compared to an unsigned 16-bit value. */
1221  uint32_t alpn_processed_len = 0;
1222  while (alpn_processed_len < alpn_len) {
1223  uint8_t protolen = *input;
1224  input += 1;
1225  alpn_processed_len += 1;
1226 
1227  if (!(HAS_SPACE(protolen)))
1228  goto invalid_length;
1229 
1230  /* Check if reading another protolen bytes would exceed the
1231  overall ALPN length; if so, skip and continue */
1232  if (alpn_processed_len + protolen > ((uint32_t)alpn_len)) {
1233  input += alpn_len - alpn_processed_len;
1234  break;
1235  }
1236  SCTLSHandshakeAddALPN(ssl_state->curr_connp->hs, (const char *)input, protolen);
1237 
1238  alpn_processed_len += protolen;
1239  input += protolen;
1240  }
1241 
1242  return (int)(input - initial_input);
1243 
1244 invalid_length:
1245  SCLogDebug("ALPN list invalid length");
1247 
1248  return -1;
1249 }
1250 
1251 static inline int TLSDecodeHSHelloExtensions(SSLState *ssl_state,
1252  const uint8_t * const initial_input,
1253  const uint32_t input_len)
1254 {
1255  const uint8_t *input = initial_input;
1256 
1257  int ret;
1258  int rc;
1259  // if ja3_hash is already computed, do not use new hello to augment ja3_str
1260  const bool ja3 =
1261  (SC_ATOMIC_GET(ssl_config.enable_ja3) == 1) && ssl_state->curr_connp->ja3_hash == NULL;
1262 
1263  JA3Buffer *ja3_extensions = NULL;
1264  JA3Buffer *ja3_elliptic_curves = NULL;
1265  JA3Buffer *ja3_elliptic_curves_pf = NULL;
1266 
1267  if (ja3) {
1268  ja3_extensions = Ja3BufferInit();
1269  if (ja3_extensions == NULL)
1270  goto error;
1271 
1272  if (ssl_state->current_flags & SSL_AL_FLAG_STATE_CLIENT_HELLO) {
1273  ja3_elliptic_curves = Ja3BufferInit();
1274  if (ja3_elliptic_curves == NULL)
1275  goto error;
1276 
1277  ja3_elliptic_curves_pf = Ja3BufferInit();
1278  if (ja3_elliptic_curves_pf == NULL)
1279  goto error;
1280  }
1281  }
1282 
1283  /* Extensions are optional (RFC5246 section 7.4.1.2) */
1284  if (!(HAS_SPACE(2)))
1285  goto end;
1286 
1287  uint16_t extensions_len = (uint16_t)(*input << 8) | *(input + 1);
1288  input += 2;
1289 
1290  if (!(HAS_SPACE(extensions_len)))
1291  goto invalid_length;
1292 
1293  uint32_t processed_len = 0;
1294  /* coverity[tainted_data] */
1295  while (processed_len < (uint32_t)extensions_len) {
1296  if (!(HAS_SPACE(2)))
1297  goto invalid_length;
1298 
1299  uint16_t ext_type = (uint16_t)(*input << 8) | *(input + 1);
1300  input += 2;
1301 
1302  if (!(HAS_SPACE(2)))
1303  goto invalid_length;
1304 
1305  uint16_t ext_len = (uint16_t)(*input << 8) | *(input + 1);
1306  input += 2;
1307 
1308  if (!(HAS_SPACE(ext_len)))
1309  goto invalid_length;
1310 
1311  if (processed_len + 4UL + (uint32_t)ext_len > (uint32_t)extensions_len)
1312  goto invalid_length;
1313 
1314  switch (ext_type) {
1315  case SSL_EXTENSION_SNI:
1316  {
1317  /* coverity[tainted_data] */
1318  ret = TLSDecodeHSHelloExtensionSni(ssl_state, input,
1319  ext_len);
1320  if (ret < 0)
1321  goto end;
1322 
1323  input += ext_len;
1324 
1325  break;
1326  }
1327 
1329  {
1330  /* coverity[tainted_data] */
1331  ret = TLSDecodeHSHelloExtensionEllipticCurves(ssl_state, input,
1332  ext_len,
1333  ja3_elliptic_curves);
1334  if (ret < 0)
1335  goto end;
1336 
1337  input += ext_len;
1338 
1339  break;
1340  }
1341 
1343  {
1344  /* coverity[tainted_data] */
1345  ret = TLSDecodeHSHelloExtensionEllipticCurvePF(ssl_state, input,
1346  ext_len,
1347  ja3_elliptic_curves_pf);
1348  if (ret < 0)
1349  goto end;
1350 
1351  input += ext_len;
1352 
1353  break;
1354  }
1355 
1357  /* coverity[tainted_data] */
1358  ret = TLSDecodeHSHelloExtensionSigAlgorithms(ssl_state, input, ext_len);
1359  if (ret < 0)
1360  goto end;
1361 
1362  input += ext_len;
1363 
1364  break;
1365  }
1366 
1367  case SSL_EXTENSION_ALPN: {
1368  /* coverity[tainted_data] */
1369  ret = TLSDecodeHSHelloExtensionALPN(ssl_state, input, ext_len);
1370  if (ret < 0)
1371  goto end;
1372 
1373  input += ext_len;
1374 
1375  break;
1376  }
1377 
1379  {
1380  if (ssl_state->current_flags & SSL_AL_FLAG_STATE_CLIENT_HELLO) {
1381  /* Used by 0-RTT to indicate that encrypted data will
1382  be sent right after the ClientHello record. */
1383  ssl_state->flags |= SSL_AL_FLAG_EARLY_DATA;
1384  }
1385 
1386  input += ext_len;
1387 
1388  break;
1389  }
1390 
1392  {
1393  ret = TLSDecodeHSHelloExtensionSupportedVersions(ssl_state, input,
1394  ext_len);
1395  if (ret < 0)
1396  goto end;
1397 
1398  input += ext_len;
1399 
1400  break;
1401  }
1402 
1404  {
1405  if (ssl_state->current_flags & SSL_AL_FLAG_STATE_CLIENT_HELLO) {
1406  /* This has to be verified later on by checking if a
1407  certificate record has been sent by the server. */
1408  ssl_state->flags |= SSL_AL_FLAG_SESSION_RESUMED;
1409  }
1410 
1411  input += ext_len;
1412 
1413  break;
1414  }
1415 
1416  default:
1417  {
1418  input += ext_len;
1419  break;
1420  }
1421  }
1422 
1423  if (ja3) {
1424  if (TLSDecodeValueIsGREASE(ext_type) != 1) {
1425  rc = Ja3BufferAddValue(&ja3_extensions, ext_type);
1426  if (rc != 0)
1427  goto error;
1428  }
1429  }
1430 
1431  if (ssl_state->current_flags &
1433  if (TLSDecodeValueIsGREASE(ext_type) != 1) {
1434  SCTLSHandshakeAddExtension(ssl_state->curr_connp->hs, ext_type);
1435  }
1436  }
1437 
1438  processed_len += (uint32_t)ext_len + 4UL;
1439  }
1440 
1441 end:
1442  if (ja3) {
1443  rc = Ja3BufferAppendBuffer(&ssl_state->curr_connp->ja3_str,
1444  &ja3_extensions);
1445  if (rc == -1)
1446  goto error;
1447 
1448  if (ssl_state->current_flags & SSL_AL_FLAG_STATE_CLIENT_HELLO) {
1449  rc = Ja3BufferAppendBuffer(&ssl_state->curr_connp->ja3_str,
1450  &ja3_elliptic_curves);
1451  if (rc == -1)
1452  goto error;
1453 
1454  rc = Ja3BufferAppendBuffer(&ssl_state->curr_connp->ja3_str,
1455  &ja3_elliptic_curves_pf);
1456  if (rc == -1)
1457  goto error;
1458  }
1459  }
1460 
1461  return (int)(input - initial_input);
1462 
1463 invalid_length:
1464  SCLogDebug("TLS handshake invalid length");
1465  SSLSetEvent(ssl_state,
1467 
1468 error:
1469  if (ja3_extensions != NULL)
1470  Ja3BufferFree(&ja3_extensions);
1471  if (ja3_elliptic_curves != NULL)
1472  Ja3BufferFree(&ja3_elliptic_curves);
1473  if (ja3_elliptic_curves_pf != NULL)
1474  Ja3BufferFree(&ja3_elliptic_curves_pf);
1475 
1476  return -1;
1477 }
1478 
1479 static int TLSDecodeHandshakeHello(SSLState *ssl_state,
1480  const uint8_t * const input,
1481  const uint32_t input_len)
1482 {
1483  int ret;
1484  uint32_t parsed = 0;
1485 
1486  ret = TLSDecodeHSHelloVersion(ssl_state, input, input_len);
1487  if (ret < 0)
1488  goto end;
1489 
1490  parsed += ret;
1491 
1492  ret = TLSDecodeHSHelloRandom(ssl_state, input + parsed, input_len - parsed);
1493  if (ret < 0)
1494  goto end;
1495 
1496  parsed += ret;
1497 
1498  /* The session id field in the server hello record was removed in
1499  TLSv1.3 draft1, but was readded in draft22. */
1500  if ((ssl_state->current_flags & SSL_AL_FLAG_STATE_CLIENT_HELLO) ||
1502  ((ssl_state->flags & SSL_AL_FLAG_LOG_WITHOUT_CERT) == 0))) {
1503  ret = TLSDecodeHSHelloSessionID(ssl_state, input + parsed,
1504  input_len - parsed);
1505  if (ret < 0)
1506  goto end;
1507 
1508  parsed += ret;
1509  }
1510 
1511  ret = TLSDecodeHSHelloCipherSuites(ssl_state, input + parsed,
1512  input_len - parsed);
1513  if (ret < 0)
1514  goto end;
1515 
1516  parsed += ret;
1517 
1518  /* The compression methods field in the server hello record was
1519  removed in TLSv1.3 draft1, but was readded in draft22. */
1520  if ((ssl_state->current_flags & SSL_AL_FLAG_STATE_CLIENT_HELLO) ||
1522  ((ssl_state->flags & SSL_AL_FLAG_LOG_WITHOUT_CERT) == 0))) {
1523  ret = TLSDecodeHSHelloCompressionMethods(ssl_state, input + parsed,
1524  input_len - parsed);
1525  if (ret < 0)
1526  goto end;
1527 
1528  parsed += ret;
1529  }
1530 
1531  ret = TLSDecodeHSHelloExtensions(ssl_state, input + parsed,
1532  input_len - parsed);
1533  if (ret < 0)
1534  goto end;
1535 
1536  if (SC_ATOMIC_GET(ssl_config.enable_ja3) && ssl_state->curr_connp->ja3_hash == NULL) {
1537  ssl_state->curr_connp->ja3_hash = Ja3GenerateHash(ssl_state->curr_connp->ja3_str);
1538  }
1539 
1540  if (ssl_state->curr_connp == &ssl_state->client_connp) {
1541  UpdateClientState(ssl_state, TLS_STATE_CLIENT_HELLO_DONE);
1542  } else {
1543  UpdateServerState(ssl_state, TLS_STATE_SERVER_HELLO);
1544  }
1545 end:
1546  return 0;
1547 }
1548 
1549 #ifdef DEBUG_VALIDATION
1550 static inline bool
1551 RecordAlreadyProcessed(const SSLStateConnp *curr_connp)
1552 {
1553  return ((curr_connp->record_length + SSLV3_RECORD_HDR_LEN) <
1554  curr_connp->bytes_processed);
1555 }
1556 #endif
1557 
1558 static inline int SSLv3ParseHandshakeTypeCertificate(SSLState *ssl_state, SSLStateConnp *connp,
1559  const uint8_t *const initial_input, const uint32_t input_len)
1560 {
1561  int rc = TlsDecodeHSCertificates(ssl_state, connp, initial_input, input_len);
1562  SCLogDebug("rc %d", rc);
1563  if (rc > 0) {
1564  DEBUG_VALIDATE_BUG_ON(rc > (int)input_len);
1565  SSLParserHSReset(connp);
1566  } else if (rc < 0) {
1567  SCLogDebug("error parsing cert, reset state");
1568  SSLParserHSReset(connp);
1569  /* fall through to still consume the cert bytes */
1570  }
1571  if (connp == &ssl_state->client_connp) {
1572  UpdateClientState(ssl_state, TLS_STATE_CLIENT_CERT_DONE);
1573  } else {
1574  UpdateServerState(ssl_state, TLS_STATE_SERVER_CERT_DONE);
1575  }
1576  return input_len;
1577 }
1578 
1579 static int SupportedHandshakeType(const uint8_t type)
1580 {
1581  switch (type) {
1582  case SSLV3_HS_CLIENT_HELLO:
1583  case SSLV3_HS_SERVER_HELLO:
1586  case SSLV3_HS_CERTIFICATE:
1590  case SSLV3_HS_FINISHED:
1595  return true;
1596  break;
1597 
1598  default:
1599  return false;
1600  break;
1601  }
1602 }
1603 
1604 /**
1605  * \param input_len length of bytes after record header. Can be 0 (e.g. for server hello done).
1606  * \retval parsed number of consumed bytes
1607  * \retval < 0 error
1608  */
1609 static int SSLv3ParseHandshakeType(SSLState *ssl_state, const uint8_t *input,
1610  uint32_t input_len, uint8_t direction)
1611 {
1612  const uint8_t *initial_input = input;
1613  int rc;
1614 
1615  DEBUG_VALIDATE_BUG_ON(RecordAlreadyProcessed(ssl_state->curr_connp));
1616 
1617  switch (ssl_state->curr_connp->handshake_type) {
1618  case SSLV3_HS_CLIENT_HELLO:
1620 
1621  if (ssl_state->curr_connp->hs == NULL)
1622  ssl_state->curr_connp->hs = SCTLSHandshakeNew();
1623 
1624  rc = TLSDecodeHandshakeHello(ssl_state, input, input_len);
1625  if (rc < 0)
1626  return rc;
1627  break;
1628 
1629  case SSLV3_HS_SERVER_HELLO:
1631 
1632  DEBUG_VALIDATE_BUG_ON(ssl_state->curr_connp->message_length != input_len);
1633  if (ssl_state->curr_connp->hs == NULL)
1634  ssl_state->curr_connp->hs = SCTLSHandshakeNew();
1635 
1636  rc = TLSDecodeHandshakeHello(ssl_state, input, input_len);
1637  if (rc < 0)
1638  return rc;
1639  break;
1640 
1643  break;
1644 
1647  break;
1648 
1649  case SSLV3_HS_CERTIFICATE:
1650  rc = SSLv3ParseHandshakeTypeCertificate(ssl_state,
1651  direction ? &ssl_state->server_connp : &ssl_state->client_connp, initial_input,
1652  input_len);
1653  if (rc < 0)
1654  return rc;
1655  break;
1656 
1658  break;
1660  if (direction) {
1662  }
1663  break;
1665  case SSLV3_HS_FINISHED:
1668  break;
1670  SCLogDebug("new session ticket");
1671  break;
1673  if (direction) {
1674  UpdateServerState(ssl_state, TLS_STATE_SERVER_HELLO_DONE);
1675  }
1676  break;
1677  default:
1679  return -1;
1680  }
1681 
1682  ssl_state->flags |= ssl_state->current_flags;
1683 
1684  SCLogDebug("message: length %u", ssl_state->curr_connp->message_length);
1685  SCLogDebug("input_len %u ssl_state->curr_connp->bytes_processed %u", input_len, ssl_state->curr_connp->bytes_processed);
1686 
1687  return input_len;
1688 }
1689 
1690 static int SSLv3ParseHandshakeProtocol(SSLState *ssl_state, const uint8_t *input,
1691  uint32_t input_len, uint8_t direction)
1692 {
1693  const uint8_t *initial_input = input;
1694 
1695  if (input_len == 0 || ssl_state->curr_connp->bytes_processed ==
1696  (ssl_state->curr_connp->record_length + SSLV3_RECORD_HDR_LEN)) {
1697  SCReturnInt(0);
1698  }
1699 
1700  while (input_len) {
1701  SCLogDebug("input_len %u", input_len);
1702 
1703  if (ssl_state->curr_connp->hs_buffer != NULL) {
1704  SCLogDebug("partial handshake record in place");
1705  const uint32_t need = ssl_state->curr_connp->hs_buffer_message_size -
1706  ssl_state->curr_connp->hs_buffer_offset;
1707  const uint32_t add = MIN(need, input_len);
1708 
1709  /* grow buffer to next multiple of 4k that fits all data we have */
1710  if (ssl_state->curr_connp->hs_buffer_offset + add >
1711  ssl_state->curr_connp->hs_buffer_size) {
1712  const uint32_t avail = ssl_state->curr_connp->hs_buffer_offset + add;
1713  const uint32_t new_size = avail + (4096 - (avail % 4096));
1714  SCLogDebug("new_size %u, avail %u", new_size, avail);
1715  void *ptr = SCRealloc(ssl_state->curr_connp->hs_buffer, new_size);
1716  if (ptr == NULL)
1717  return -1;
1718  ssl_state->curr_connp->hs_buffer = ptr;
1719  ssl_state->curr_connp->hs_buffer_size = new_size;
1720  }
1721 
1722  SCLogDebug("ssl_state->curr_connp->hs_buffer_offset %u "
1723  "ssl_state->curr_connp->hs_buffer_size %u",
1724  ssl_state->curr_connp->hs_buffer_offset, ssl_state->curr_connp->hs_buffer_size);
1725  SCLogDebug("to add %u total %u", add, ssl_state->curr_connp->hs_buffer_offset + add);
1726 
1727  if (SafeMemcpy(ssl_state->curr_connp->hs_buffer,
1728  ssl_state->curr_connp->hs_buffer_offset,
1729  ssl_state->curr_connp->hs_buffer_size, input, 0, add, add) != 0) {
1730  SCLogDebug("copy failed");
1731  return -1;
1732  }
1733  ssl_state->curr_connp->hs_buffer_offset += add;
1734 
1735  if (ssl_state->curr_connp->hs_buffer_message_size <=
1736  ssl_state->curr_connp->hs_buffer_offset) {
1738  ssl_state->curr_connp->hs_buffer_offset);
1739 
1740  ssl_state->curr_connp->handshake_type =
1741  ssl_state->curr_connp->hs_buffer_message_type;
1742  ssl_state->curr_connp->message_length =
1743  ssl_state->curr_connp->hs_buffer_message_size;
1744 
1745  SCLogDebug("got all data now: handshake_type %u message_length %u",
1746  ssl_state->curr_connp->handshake_type,
1747  ssl_state->curr_connp->message_length);
1748 
1749  int retval = SSLv3ParseHandshakeType(ssl_state, ssl_state->curr_connp->hs_buffer,
1750  ssl_state->curr_connp->hs_buffer_offset, direction);
1751  if (retval < 0) {
1752  SSLParserHSReset(ssl_state->curr_connp);
1753  return (retval);
1754  }
1755  SCLogDebug("retval %d", retval);
1756 
1757  /* data processed, reset buffer */
1758  SCFree(ssl_state->curr_connp->hs_buffer);
1759  ssl_state->curr_connp->hs_buffer = NULL;
1760  ssl_state->curr_connp->hs_buffer_size = 0;
1761  ssl_state->curr_connp->hs_buffer_message_size = 0;
1762  ssl_state->curr_connp->hs_buffer_message_type = 0;
1763  ssl_state->curr_connp->hs_buffer_offset = 0;
1764  } else {
1765  SCLogDebug("partial data");
1766  }
1767 
1768  input += add;
1769  input_len -= add;
1770  SCLogDebug("input_len %u", input_len);
1771  SSLParserHSReset(ssl_state->curr_connp);
1772  continue;
1773  }
1774 
1775  SCLogDebug("bytes_processed %u", ssl_state->curr_connp->bytes_processed);
1776  SCLogDebug("input %p input_len %u", input, input_len);
1777 
1778  if (input_len < 4) {
1780  SCReturnInt(-1);
1781  }
1782 
1783  ssl_state->curr_connp->handshake_type = input[0];
1784  ssl_state->curr_connp->message_length = input[1] << 16 | input[2] << 8 | input[3];
1785  SCLogDebug("handshake_type %u message len %u input %p input_len %u",
1786  ssl_state->curr_connp->handshake_type, ssl_state->curr_connp->message_length, input,
1787  input_len);
1788  input += 4;
1789  input_len -= 4;
1790 
1791  const uint32_t record_len = ssl_state->curr_connp->message_length;
1792  /* see if we support this type. We check here to not use the fragment
1793  * handling on things we don't support. */
1794  const bool supported_type = SupportedHandshakeType(ssl_state->curr_connp->handshake_type);
1795  SCLogDebug("supported_type %s handshake_type %u/%02x", supported_type ? "true" : "false",
1796  ssl_state->curr_connp->handshake_type, ssl_state->curr_connp->handshake_type);
1797  if (!supported_type) {
1798  uint32_t avail_record_len = MIN(input_len, record_len);
1799  input += avail_record_len;
1800  input_len -= avail_record_len;
1801 
1802  SSLParserHSReset(ssl_state->curr_connp);
1803 
1804  if ((direction && (ssl_state->flags & SSL_AL_FLAG_SERVER_CHANGE_CIPHER_SPEC)) ||
1805  (!direction && (ssl_state->flags & SSL_AL_FLAG_CLIENT_CHANGE_CIPHER_SPEC))) {
1806  // after Change Cipher Spec we get Encrypted Handshake Messages
1807  } else {
1809  }
1810  continue;
1811  }
1812 
1813  /* if the message length exceeds our input_len, we have a tls fragment. */
1814  if (record_len > input_len) {
1815  const uint32_t avail = input_len;
1816  const uint32_t size = avail + (4096 - (avail % 4096));
1817  SCLogDebug("initial buffer size %u, based on input %u", size, avail);
1818  ssl_state->curr_connp->hs_buffer = SCCalloc(1, size);
1819  if (ssl_state->curr_connp->hs_buffer == NULL) {
1820  return -1;
1821  }
1822  ssl_state->curr_connp->hs_buffer_size = size;
1823  ssl_state->curr_connp->hs_buffer_message_size = record_len;
1824  ssl_state->curr_connp->hs_buffer_message_type = ssl_state->curr_connp->handshake_type;
1825 
1826  if (input_len > 0) {
1827  if (SafeMemcpy(ssl_state->curr_connp->hs_buffer, 0,
1828  ssl_state->curr_connp->hs_buffer_size, input, 0, input_len,
1829  input_len) != 0) {
1830  return -1;
1831  }
1832  ssl_state->curr_connp->hs_buffer_offset = input_len;
1833  }
1834  SCLogDebug("opened record buffer %p size %u offset %u type %u msg_size %u",
1835  ssl_state->curr_connp->hs_buffer, ssl_state->curr_connp->hs_buffer_size,
1836  ssl_state->curr_connp->hs_buffer_offset,
1837  ssl_state->curr_connp->hs_buffer_message_type,
1838  ssl_state->curr_connp->hs_buffer_message_size);
1839  input += input_len;
1840  SSLParserHSReset(ssl_state->curr_connp);
1841  return (int)(input - initial_input);
1842 
1843  } else {
1844  /* full record, parse it now */
1845  int retval = SSLv3ParseHandshakeType(
1846  ssl_state, input, ssl_state->curr_connp->message_length, direction);
1847  if (retval < 0 || retval > (int)input_len) {
1848  DEBUG_VALIDATE_BUG_ON(retval > (int)input_len);
1849  return (retval);
1850  }
1851  SCLogDebug("retval %d input_len %u", retval, input_len);
1852  input += retval;
1853  input_len -= retval;
1854 
1855  SSLParserHSReset(ssl_state->curr_connp);
1856  }
1857  SCLogDebug("input_len left %u", input_len);
1858  }
1859  return (int)(input - initial_input);
1860 }
1861 
1862 /**
1863  * \internal
1864  * \brief TLS Alert parser
1865  *
1866  * \param sslstate Pointer to the SSL state.
1867  * \param input Pointer to the received input data.
1868  * \param input_len Length in bytes of the received data.
1869  * \param direction 1 toclient, 0 toserver
1870  *
1871  * \retval The number of bytes parsed on success, 0 if nothing parsed, -1 on failure.
1872  */
1873 static int SSLv3ParseAlertProtocol(
1874  SSLState *ssl_state, const uint8_t *input, uint32_t input_len, uint8_t direction)
1875 {
1876  if (input_len < 2) {
1878  return -1;
1879  }
1880 
1881  /* assume a record > 2 to be an encrypted alert record */
1882  if (input_len == 2) {
1883  uint8_t level = input[0];
1884  // uint8_t desc = input[1];
1885 
1886  /* if level Fatal, we consider the tx finished */
1887  if (level == 2) {
1888  UpdateClientState(ssl_state, TLS_STATE_CLIENT_FINISHED);
1889  UpdateServerState(ssl_state, TLS_STATE_SERVER_FINISHED);
1890  }
1891  }
1892  return 0;
1893 }
1894 
1895 /**
1896  * \internal
1897  * \brief TLS Heartbeat parser (see RFC 6520)
1898  *
1899  * \param sslstate Pointer to the SSL state.
1900  * \param input Pointer to the received input data.
1901  * \param input_len Length in bytes of the received data.
1902  * \param direction 1 toclient, 0 toserver
1903  *
1904  * \retval The number of bytes parsed on success, 0 if nothing parsed, -1 on failure.
1905  */
1906 static int SSLv3ParseHeartbeatProtocol(SSLState *ssl_state, const uint8_t *input,
1907  uint32_t input_len, uint8_t direction)
1908 {
1909  uint8_t hb_type;
1910  uint16_t payload_len;
1911  uint32_t padding_len;
1912 
1913  /* expect at least 3 bytes: heartbeat type (1) + length (2) */
1914  if (input_len < 3) {
1915  return 0;
1916  }
1917 
1918  hb_type = *input++;
1919 
1920  if (!(ssl_state->flags & SSL_AL_FLAG_CHANGE_CIPHER_SPEC)) {
1921  if (!(hb_type == TLS_HB_REQUEST || hb_type == TLS_HB_RESPONSE)) {
1923  return -1;
1924  }
1925  }
1926 
1927  if ((ssl_state->flags & SSL_AL_FLAG_HB_INFLIGHT) == 0) {
1928  ssl_state->flags |= SSL_AL_FLAG_HB_INFLIGHT;
1929 
1930  if (direction) {
1931  SCLogDebug("HeartBeat Record type sent in the toclient direction!");
1932  ssl_state->flags |= SSL_AL_FLAG_HB_SERVER_INIT;
1933  } else {
1934  SCLogDebug("HeartBeat Record type sent in the toserver direction!");
1935  ssl_state->flags |= SSL_AL_FLAG_HB_CLIENT_INIT;
1936  }
1937 
1938  /* if we reach this point, then we can assume that the HB request
1939  is encrypted. If so, let's set the HB record length */
1940  if (ssl_state->flags & SSL_AL_FLAG_CHANGE_CIPHER_SPEC) {
1941  ssl_state->hb_record_len = ssl_state->curr_connp->record_length;
1942  SCLogDebug("Encrypted HeartBeat Request In-flight. Storing len %u",
1943  ssl_state->hb_record_len);
1944  return (ssl_state->curr_connp->record_length - 3);
1945  }
1946 
1947  payload_len = (uint16_t)(*input << 8) | *(input + 1);
1948 
1949  /* check that the requested payload length is really present in
1950  the record (CVE-2014-0160) */
1951  if ((uint32_t)(payload_len+3) > ssl_state->curr_connp->record_length) {
1952  SCLogDebug("We have a short record in HeartBeat Request");
1954  return -1;
1955  }
1956 
1957  /* check the padding length. It must be at least 16 bytes
1958  (RFC 6520, section 4) */
1959  padding_len = ssl_state->curr_connp->record_length - payload_len - 3;
1960  if (padding_len < 16) {
1961  SCLogDebug("We have a short record in HeartBeat Request");
1963  return -1;
1964  }
1965 
1966  /* we don't have the payload */
1967  if (input_len < payload_len + padding_len) {
1968  return 0;
1969  }
1970 
1971  /* OpenSSL still seems to discard multiple in-flight
1972  heartbeats although some tools send multiple at once */
1973  } else if (direction == 1 && (ssl_state->flags & SSL_AL_FLAG_HB_INFLIGHT) &&
1974  (ssl_state->flags & SSL_AL_FLAG_HB_SERVER_INIT)) {
1975  SCLogDebug("Multiple in-flight server initiated HeartBeats");
1977  return -1;
1978 
1979  } else if (direction == 0 && (ssl_state->flags & SSL_AL_FLAG_HB_INFLIGHT) &&
1980  (ssl_state->flags & SSL_AL_FLAG_HB_CLIENT_INIT)) {
1981  SCLogDebug("Multiple in-flight client initiated HeartBeats");
1983  return -1;
1984 
1985  } else {
1986  /* we have a HB record in the opposite direction of the request,
1987  let's reset our flags */
1988  ssl_state->flags &= ~SSL_AL_FLAG_HB_INFLIGHT;
1989  ssl_state->flags &= ~SSL_AL_FLAG_HB_SERVER_INIT;
1990  ssl_state->flags &= ~SSL_AL_FLAG_HB_CLIENT_INIT;
1991 
1992  /* if we reach this point, then we can assume that the HB request
1993  is encrypted. If so, let's set the HB record length */
1994  if (ssl_state->flags & SSL_AL_FLAG_CHANGE_CIPHER_SPEC) {
1995  /* check to see if the encrypted response is longer than the
1996  encrypted request */
1997  if (ssl_state->hb_record_len > 0 && ssl_state->hb_record_len <
1998  ssl_state->curr_connp->record_length) {
1999  SCLogDebug("My heart is bleeding.. OpenSSL HeartBleed response (%u)",
2000  ssl_state->hb_record_len);
2001  SSLSetEvent(ssl_state,
2003  ssl_state->hb_record_len = 0;
2004  return -1;
2005  }
2006  }
2007 
2008  /* reset the HB record length in case we have a legit HB followed
2009  by a bad one */
2010  ssl_state->hb_record_len = 0;
2011  }
2012 
2013  /* skip the HeartBeat, 3 bytes were already parsed,
2014  e.g |18 03 02| for TLS 1.2 */
2015  return (ssl_state->curr_connp->record_length - 3);
2016 }
2017 
2018 static int SSLv3ParseRecord(uint8_t direction, SSLState *ssl_state,
2019  const uint8_t *input, uint32_t input_len)
2020 {
2021  const uint8_t *initial_input = input;
2022 
2023  if (input_len == 0) {
2024  return 0;
2025  }
2026 
2027  uint8_t skip_version = 0;
2028 
2029  /* Only set SSL/TLS version here if it has not already been set in
2030  client/server hello. */
2031  if (direction == 0) {
2032  if ((ssl_state->flags & SSL_AL_FLAG_STATE_CLIENT_HELLO) &&
2033  (ssl_state->client_connp.version != TLS_VERSION_UNKNOWN)) {
2034  skip_version = 1;
2035  }
2036  } else {
2037  if ((ssl_state->flags & SSL_AL_FLAG_STATE_SERVER_HELLO) &&
2038  (ssl_state->server_connp.version != TLS_VERSION_UNKNOWN)) {
2039  skip_version = 1;
2040  }
2041  }
2042 
2043  switch (ssl_state->curr_connp->bytes_processed) {
2044  case 0:
2045  if (input_len >= 5) {
2046  ssl_state->curr_connp->content_type = input[0];
2047  if (!skip_version) {
2048  ssl_state->curr_connp->version = (uint16_t)(input[1] << 8) | input[2];
2049  }
2050  ssl_state->curr_connp->record_length = input[3] << 8;
2051  ssl_state->curr_connp->record_length |= input[4];
2053  return SSLV3_RECORD_HDR_LEN;
2054  } else {
2055  ssl_state->curr_connp->content_type = *(input++);
2056  if (--input_len == 0)
2057  break;
2058  }
2059 
2060  /* fall through */
2061  case 1:
2062  if (!skip_version) {
2063  ssl_state->curr_connp->version = (uint16_t)(*(input++) << 8);
2064  } else {
2065  input++;
2066  }
2067  if (--input_len == 0)
2068  break;
2069 
2070  /* fall through */
2071  case 2:
2072  if (!skip_version) {
2073  ssl_state->curr_connp->version |= *(input++);
2074  } else {
2075  input++;
2076  }
2077  if (--input_len == 0)
2078  break;
2079 
2080  /* fall through */
2081  case 3:
2082  ssl_state->curr_connp->record_length = *(input++) << 8;
2083  if (--input_len == 0)
2084  break;
2085 
2086  /* fall through */
2087  case 4:
2088  ssl_state->curr_connp->record_length |= *(input++);
2089  if (--input_len == 0)
2090  break;
2091 
2092  /* fall through */
2093  }
2094 
2095  ssl_state->curr_connp->bytes_processed += (input - initial_input);
2096 
2097  return (int)(input - initial_input);
2098 }
2099 
2100 static int SSLv2ParseRecord(uint8_t direction, SSLState *ssl_state,
2101  const uint8_t *input, uint32_t input_len)
2102 {
2103  const uint8_t *initial_input = input;
2104 
2105  if (input_len == 0) {
2106  return 0;
2107  }
2108 
2109  if (ssl_state->curr_connp->record_lengths_length == 2) {
2110  switch (ssl_state->curr_connp->bytes_processed) {
2111  case 0:
2112  if (input_len >= ssl_state->curr_connp->record_lengths_length + 1) {
2113  ssl_state->curr_connp->record_length = (0x7f & input[0]) << 8 | input[1];
2114  ssl_state->curr_connp->content_type = input[2];
2115  ssl_state->curr_connp->version = SSL_VERSION_2;
2116  ssl_state->curr_connp->bytes_processed += 3;
2117  return 3;
2118  } else {
2119  ssl_state->curr_connp->record_length = (0x7f & *(input++)) << 8;
2120  if (--input_len == 0)
2121  break;
2122  }
2123 
2124  /* fall through */
2125  case 1:
2126  ssl_state->curr_connp->record_length |= *(input++);
2127  if (--input_len == 0)
2128  break;
2129 
2130  /* fall through */
2131  case 2:
2132  ssl_state->curr_connp->content_type = *(input++);
2133  ssl_state->curr_connp->version = SSL_VERSION_2;
2134  if (--input_len == 0)
2135  break;
2136 
2137  /* fall through */
2138  }
2139 
2140  } else {
2141  switch (ssl_state->curr_connp->bytes_processed) {
2142  case 0:
2143  if (input_len >= ssl_state->curr_connp->record_lengths_length + 1) {
2144  ssl_state->curr_connp->record_length = (0x3f & input[0]) << 8 | input[1];
2145  ssl_state->curr_connp->content_type = input[3];
2146  ssl_state->curr_connp->version = SSL_VERSION_2;
2147  ssl_state->curr_connp->bytes_processed += 4;
2148  return 4;
2149  } else {
2150  ssl_state->curr_connp->record_length = (0x3f & *(input++)) << 8;
2151  if (--input_len == 0)
2152  break;
2153  }
2154 
2155  /* fall through */
2156  case 1:
2157  ssl_state->curr_connp->record_length |= *(input++);
2158  if (--input_len == 0)
2159  break;
2160 
2161  /* fall through */
2162  case 2:
2163  /* padding */
2164  input++;
2165  if (--input_len == 0)
2166  break;
2167 
2168  /* fall through */
2169  case 3:
2170  ssl_state->curr_connp->content_type = *(input++);
2171  ssl_state->curr_connp->version = SSL_VERSION_2;
2172  if (--input_len == 0)
2173  break;
2174 
2175  /* fall through */
2176  }
2177  }
2178 
2179  ssl_state->curr_connp->bytes_processed += (input - initial_input);
2180 
2181  return (int)(input - initial_input);
2182 }
2183 
2184 static struct SSLDecoderResult SSLv2Decode(uint8_t direction, SSLState *ssl_state,
2185  AppLayerParserState *pstate, const uint8_t *input, uint32_t input_len,
2186  const StreamSlice stream_slice)
2187 {
2188  const uint8_t *initial_input = input;
2189 
2190  if (ssl_state->curr_connp->bytes_processed == 0) {
2191  if (input[0] & 0x80) {
2192  ssl_state->curr_connp->record_lengths_length = 2;
2193  } else {
2194  ssl_state->curr_connp->record_lengths_length = 3;
2195  }
2196 
2197  SCLogDebug("record start: ssl2.hdr frame");
2198  AppLayerFrameNewByPointer(ssl_state->f, &stream_slice, input,
2199  ssl_state->curr_connp->record_lengths_length + 1, direction, TLS_FRAME_SSLV2_HDR);
2200  }
2201 
2202  SCLogDebug("direction %u ssl_state->curr_connp->record_lengths_length + 1 %u, "
2203  "ssl_state->curr_connp->bytes_processed %u",
2204  direction, ssl_state->curr_connp->record_lengths_length + 1,
2205  ssl_state->curr_connp->bytes_processed);
2206  /* the +1 is because we read one extra byte inside SSLv2ParseRecord
2207  to read the msg_type */
2208  if (ssl_state->curr_connp->bytes_processed <
2209  (ssl_state->curr_connp->record_lengths_length + 1)) {
2210  const int retval = SSLv2ParseRecord(direction, ssl_state, input, input_len);
2211  SCLogDebug("retval %d ssl_state->curr_connp->record_length %u", retval,
2212  ssl_state->curr_connp->record_length);
2213  if (retval < 0 || retval > (int)input_len) {
2214  DEBUG_VALIDATE_BUG_ON(retval > (int)input_len);
2216  return SSL_DECODER_ERROR(-1);
2217  }
2218 
2219  AppLayerFrameNewByPointer(ssl_state->f, &stream_slice, input,
2220  ssl_state->curr_connp->record_lengths_length + ssl_state->curr_connp->record_length,
2221  direction, TLS_FRAME_SSLV2_PDU);
2222  SCLogDebug("record start: ssl2.pdu frame");
2223 
2224  input += retval;
2225  input_len -= retval;
2226  }
2227 
2228  /* if we don't have the full record, we return incomplete */
2229  if (ssl_state->curr_connp->record_lengths_length + ssl_state->curr_connp->record_length >
2230  input_len + ssl_state->curr_connp->bytes_processed) {
2231  uint32_t needed = ssl_state->curr_connp->record_length;
2232  SCLogDebug("record len %u input_len %u parsed %u: need %u bytes more data",
2233  ssl_state->curr_connp->record_length, input_len, (uint32_t)(input - initial_input),
2234  needed);
2235  return SSL_DECODER_INCOMPLETE((input - initial_input), needed);
2236  }
2237 
2238  if (input_len == 0) {
2239  return SSL_DECODER_OK((input - initial_input));
2240  }
2241 
2242  /* record_length should never be zero */
2243  if (ssl_state->curr_connp->record_length == 0) {
2244  SCLogDebug("SSLv2 record length is zero");
2246  return SSL_DECODER_ERROR(-1);
2247  }
2248 
2249  /* record_lengths_length should never be zero */
2250  if (ssl_state->curr_connp->record_lengths_length == 0) {
2251  SCLogDebug("SSLv2 record lengths length is zero");
2253  return SSL_DECODER_ERROR(-1);
2254  }
2255 
2256  switch (ssl_state->curr_connp->content_type) {
2257  case SSLV2_MT_ERROR:
2258  SCLogDebug("SSLV2_MT_ERROR msg_type received. Error encountered "
2259  "in establishing the sslv2 session, may be version");
2261 
2262  break;
2263 
2264  case SSLV2_MT_CLIENT_HELLO:
2265  if (input_len < 6) {
2267  return SSL_DECODER_ERROR(-1);
2268  }
2269 
2270  ssl_state->current_flags = SSL_AL_FLAG_STATE_CLIENT_HELLO;
2271  ssl_state->current_flags |= SSL_AL_FLAG_SSL_CLIENT_HS;
2272  UpdateClientState(ssl_state, TLS_STATE_CLIENT_HELLO_DONE);
2273 
2274  const uint16_t version = (uint16_t)(input[0] << 8) | input[1];
2275  SCLogDebug("SSLv2: version %04x", version);
2276  ssl_state->curr_connp->version = version;
2277  uint16_t session_id_length = (input[5]) | (uint16_t)(input[4] << 8);
2278  input += 6;
2279  input_len -= 6;
2280  ssl_state->curr_connp->bytes_processed += 6;
2281  if (session_id_length == 0) {
2282  ssl_state->current_flags |= SSL_AL_FLAG_SSL_NO_SESSION_ID;
2283  }
2284  break;
2285 
2287  if (!(ssl_state->flags & SSL_AL_FLAG_SSL_CLIENT_HS)) {
2288  SCLogDebug("Client hello is not seen before master key "
2289  "message!");
2290  }
2291  ssl_state->current_flags = SSL_AL_FLAG_SSL_CLIENT_MASTER_KEY;
2292 
2293  break;
2294 
2296  if (direction == 1) {
2297  SCLogDebug("Incorrect SSL Record type sent in the toclient "
2298  "direction!");
2299  } else {
2300  ssl_state->current_flags = SSL_AL_FLAG_STATE_CLIENT_KEYX;
2301  }
2302  UpdateServerState(ssl_state, TLS_STATE_SERVER_CERT_DONE);
2303 
2304  /* fall through */
2307  if (direction == 0 &&
2308  !(ssl_state->curr_connp->content_type &
2310  SCLogDebug("Incorrect SSL Record type sent in the toserver "
2311  "direction!");
2312  }
2313 
2314  /* fall through */
2317  /* both client hello and server hello must be seen */
2318  if ((ssl_state->flags & SSL_AL_FLAG_SSL_CLIENT_HS) &&
2319  (ssl_state->flags & SSL_AL_FLAG_SSL_SERVER_HS)) {
2320 
2321  if (direction == 0) {
2322  if (ssl_state->flags & SSL_AL_FLAG_SSL_NO_SESSION_ID) {
2323  ssl_state->current_flags |= SSL_AL_FLAG_SSL_CLIENT_SSN_ENCRYPTED;
2324  SCLogDebug("SSLv2 client side has started the encryption");
2325  } else if (ssl_state->flags & SSL_AL_FLAG_SSL_CLIENT_MASTER_KEY) {
2326  ssl_state->current_flags = SSL_AL_FLAG_SSL_CLIENT_SSN_ENCRYPTED;
2327  SCLogDebug("SSLv2 client side has started the encryption");
2328  }
2329  } else {
2330  ssl_state->current_flags = SSL_AL_FLAG_SSL_SERVER_SSN_ENCRYPTED;
2331  SCLogDebug("SSLv2 Server side has started the encryption");
2332  }
2333 
2334  if ((ssl_state->flags & SSL_AL_FLAG_SSL_CLIENT_SSN_ENCRYPTED) &&
2335  (ssl_state->flags & SSL_AL_FLAG_SSL_SERVER_SSN_ENCRYPTED))
2336  {
2338  SCAppLayerParserStateSetFlag(pstate, APP_LAYER_PARSER_NO_INSPECTION);
2339  }
2340 
2342  SCAppLayerParserStateSetFlag(pstate, APP_LAYER_PARSER_NO_REASSEMBLY);
2343  SCAppLayerParserStateSetFlag(pstate, APP_LAYER_PARSER_BYPASS_READY);
2344  }
2345  SCLogDebug("SSLv2 No reassembly & inspection has been set");
2346  }
2347  }
2348 
2349  break;
2350 
2351  case SSLV2_MT_SERVER_HELLO:
2352  ssl_state->current_flags = SSL_AL_FLAG_STATE_SERVER_HELLO;
2353  ssl_state->current_flags |= SSL_AL_FLAG_SSL_SERVER_HS;
2354  UpdateServerState(ssl_state, TLS_STATE_SERVER_HELLO);
2355 
2356  break;
2357  }
2358 
2359  ssl_state->flags |= ssl_state->current_flags;
2360 
2361  if (input_len + ssl_state->curr_connp->bytes_processed >=
2362  (ssl_state->curr_connp->record_length +
2363  ssl_state->curr_connp->record_lengths_length)) {
2364 
2365  /* looks like we have another record after this */
2366  uint32_t diff = ssl_state->curr_connp->record_length +
2367  ssl_state->curr_connp->record_lengths_length + -
2368  ssl_state->curr_connp->bytes_processed;
2369  input += diff;
2370  SSLParserReset(ssl_state);
2371 
2372  /* we still don't have the entire record for the one we are
2373  currently parsing */
2374  } else {
2375  input += input_len;
2376  ssl_state->curr_connp->bytes_processed += input_len;
2377  }
2378  return SSL_DECODER_OK((input - initial_input));
2379 }
2380 
2381 static struct SSLDecoderResult SSLv3Decode(uint8_t direction, SSLState *ssl_state,
2382  AppLayerParserState *pstate, const uint8_t *input, const uint32_t input_len,
2383  const StreamSlice stream_slice)
2384 {
2385  uint32_t parsed = 0;
2386  uint32_t record_len; /* slice of input_len for the current record */
2387  const bool first_call = (ssl_state->curr_connp->bytes_processed == 0);
2388 
2389  if (ssl_state->curr_connp->bytes_processed < SSLV3_RECORD_HDR_LEN) {
2390  const uint16_t prev_version = ssl_state->curr_connp->version;
2391 
2392  int retval = SSLv3ParseRecord(direction, ssl_state, input, input_len);
2393  if (retval < 0 || retval > (int)input_len) {
2394  DEBUG_VALIDATE_BUG_ON(retval > (int)input_len);
2395  SCLogDebug("SSLv3ParseRecord returned %d", retval);
2397  return SSL_DECODER_ERROR(-1);
2398  }
2399  parsed = retval;
2400 
2401  SCLogDebug("%s input %p record_length %u", (direction == 0) ? "toserver" : "toclient",
2402  input, ssl_state->curr_connp->record_length);
2403 
2404  /* first the hdr frame at our first chance */
2405  if (first_call) {
2406  AppLayerFrameNewByPointer(ssl_state->f, &stream_slice, input, SSLV3_RECORD_HDR_LEN,
2407  direction, TLS_FRAME_HDR);
2408  }
2409 
2410  /* parser is streaming for the initial header, then switches to incomplete
2411  * API: so if we don't have the hdr yet, return consumed bytes and wait
2412  * until we are called again with new data. */
2413  if (ssl_state->curr_connp->bytes_processed < SSLV3_RECORD_HDR_LEN) {
2414  SCLogDebug(
2415  "incomplete header, return %u bytes consumed and wait for more data", parsed);
2416  return SSL_DECODER_OK(parsed);
2417  }
2418 
2419  /* pdu frame needs record length, so only create it when hdr fully parsed. */
2420  AppLayerFrameNewByPointer(ssl_state->f, &stream_slice, input,
2421  ssl_state->curr_connp->record_length + retval, direction, TLS_FRAME_PDU);
2422  record_len = MIN(input_len - parsed, ssl_state->curr_connp->record_length);
2423  SCLogDebug(
2424  "record_len %u (input_len %u, parsed %u, ssl_state->curr_connp->record_length %u)",
2425  record_len, input_len, parsed, ssl_state->curr_connp->record_length);
2426 
2427  bool unknown_record = false;
2428  switch (ssl_state->curr_connp->content_type) {
2430  case SSLV3_ALERT_PROTOCOL:
2434  break;
2435  default:
2436  unknown_record = true;
2437  break;
2438  }
2439 
2440  /* unknown record type. For TLS 1.0, 1.1 and 1.2 this is ok. For the rest it is fatal. Based
2441  * on Wireshark logic. */
2442  if (prev_version == TLS_VERSION_10 || prev_version == TLS_VERSION_11) {
2443  if (unknown_record) {
2444  SCLogDebug("unknown record, ignore it");
2446 
2447  ssl_state->curr_connp->bytes_processed = 0; // TODO review this reset logic
2448  ssl_state->curr_connp->content_type = 0;
2449  ssl_state->curr_connp->record_length = 0;
2450  // restore last good version
2451  ssl_state->curr_connp->version = prev_version;
2452  return SSL_DECODER_OK(input_len); // consume everything
2453  }
2454  } else {
2455  if (unknown_record) {
2456  SCLogDebug("unknown record, fatal");
2458  return SSL_DECODER_ERROR(-1);
2459  }
2460  }
2461 
2462  /* record_length should never be zero */
2463  if (ssl_state->curr_connp->record_length == 0) {
2464  SCLogDebug("SSLv3 Record length is 0");
2466  return SSL_DECODER_ERROR(-1);
2467  }
2468 
2469  if (!TLSVersionValid(ssl_state->curr_connp->version)) {
2470  SCLogDebug("ssl_state->curr_connp->version %04x", ssl_state->curr_connp->version);
2472  return SSL_DECODER_ERROR(-1);
2473  }
2474 
2475  if (ssl_state->curr_connp->bytes_processed == SSLV3_RECORD_HDR_LEN &&
2476  ssl_state->curr_connp->record_length > SSLV3_RECORD_MAX_LEN) {
2478  return SSL_DECODER_ERROR(-1);
2479  }
2480  DEBUG_VALIDATE_BUG_ON(ssl_state->curr_connp->bytes_processed > SSLV3_RECORD_HDR_LEN);
2481  } else {
2482  ValidateRecordState(ssl_state->curr_connp);
2483 
2484  record_len = (ssl_state->curr_connp->record_length + SSLV3_RECORD_HDR_LEN)- ssl_state->curr_connp->bytes_processed;
2485  record_len = MIN(input_len, record_len);
2486  }
2487  SCLogDebug("record length %u processed %u got %u",
2488  ssl_state->curr_connp->record_length, ssl_state->curr_connp->bytes_processed, record_len);
2489 
2490  /* if we don't have the full record, we return incomplete */
2491  if (ssl_state->curr_connp->record_length > input_len - parsed) {
2492  /* no need to use incomplete api buffering for application
2493  * records that we'll not use anyway. */
2494  if (ssl_state->curr_connp->content_type == SSLV3_APPLICATION_PROTOCOL) {
2495  SCLogDebug("application record");
2496  } else {
2497  uint32_t needed = ssl_state->curr_connp->record_length;
2498  SCLogDebug("record len %u input_len %u parsed %u: need %u bytes more data",
2499  ssl_state->curr_connp->record_length, input_len, parsed, needed);
2501  return SSL_DECODER_INCOMPLETE(parsed, needed);
2502  }
2503  }
2504 
2505  if (record_len == 0) {
2506  return SSL_DECODER_OK(parsed);
2507  }
2508 
2509  AppLayerFrameNewByPointer(ssl_state->f, &stream_slice, input + parsed,
2510  ssl_state->curr_connp->record_length, direction, TLS_FRAME_DATA);
2511 
2512  switch (ssl_state->curr_connp->content_type) {
2513  /* we don't need any data from these types */
2515  ssl_state->flags |= SSL_AL_FLAG_CHANGE_CIPHER_SPEC;
2516 
2517  if (direction) {
2518  ssl_state->flags |= SSL_AL_FLAG_SERVER_CHANGE_CIPHER_SPEC;
2519  } else {
2520  ssl_state->flags |= SSL_AL_FLAG_CLIENT_CHANGE_CIPHER_SPEC;
2521 
2522  // TODO TLS 1.3
2523  UpdateClientState(ssl_state, TLS_STATE_CLIENT_HANDSHAKE_DONE);
2524  }
2525  break;
2526 
2527  case SSLV3_ALERT_PROTOCOL: {
2528  AppLayerFrameNewByPointer(ssl_state->f, &stream_slice, input + parsed,
2529  ssl_state->curr_connp->record_length, direction, TLS_FRAME_ALERT_DATA);
2530 
2531  int retval = SSLv3ParseAlertProtocol(ssl_state, input + parsed, record_len, direction);
2532  if (retval < 0) {
2533  SCLogDebug("SSLv3ParseAlertProtocol returned %d", retval);
2534  return SSL_DECODER_ERROR(-1);
2535  }
2536  break;
2537  }
2539  /* In TLSv1.3 early data (0-RTT) could be sent before the
2540  handshake is complete (rfc8446, section 2.3). We should
2541  therefore not mark the handshake as done before we have
2542  seen the ServerHello record. */
2543  if ((ssl_state->flags & SSL_AL_FLAG_EARLY_DATA) &&
2544  ((ssl_state->flags & SSL_AL_FLAG_STATE_SERVER_HELLO) == 0))
2545  break;
2546 
2547  /* if we see (encrypted) application data, then this means the
2548  handshake must be done */
2549  if (ssl_state->curr_connp == &ssl_state->client_connp) {
2550  UpdateClientState(ssl_state, TLS_STATE_CLIENT_HANDSHAKE_DONE);
2551  } else {
2552  UpdateServerState(ssl_state, TLS_STATE_SERVER_HANDSHAKE_DONE);
2553  }
2554 
2556  SCLogDebug("setting APP_LAYER_PARSER_NO_INSPECTION_PAYLOAD");
2557  SCAppLayerParserStateSetFlag(pstate, APP_LAYER_PARSER_NO_INSPECTION_PAYLOAD);
2558  }
2559 
2560  /* Encrypted data, reassembly not asked, bypass asked, let's sacrifice
2561  * heartbeat lke inspection to be able to be able to bypass the flow */
2563  SCLogDebug("setting APP_LAYER_PARSER_NO_REASSEMBLY");
2564  SCAppLayerParserStateSetFlag(pstate, APP_LAYER_PARSER_NO_REASSEMBLY);
2565  SCAppLayerParserStateSetFlag(pstate, APP_LAYER_PARSER_NO_INSPECTION);
2566  SCAppLayerParserStateSetFlag(pstate, APP_LAYER_PARSER_BYPASS_READY);
2567  }
2568  break;
2569 
2570  case SSLV3_HANDSHAKE_PROTOCOL: {
2571  if (ssl_state->flags & SSL_AL_FLAG_CHANGE_CIPHER_SPEC) {
2572  /* In TLSv1.3, ChangeCipherSpec is only used for middlebox
2573  compatibility (rfc8446, appendix D.4). */
2574  // Client hello flags is needed to have a valid version
2575  if ((ssl_state->flags & SSL_AL_FLAG_STATE_CLIENT_HELLO) &&
2576  (ssl_state->client_connp.version > TLS_VERSION_12) &&
2577  ((ssl_state->flags & SSL_AL_FLAG_STATE_SERVER_HELLO) == 0)) {
2578  /* do nothing */
2579  } else {
2580  // if we started parsing this, we must stop
2581  break;
2582  }
2583  }
2584 
2585  if (ssl_state->curr_connp->record_length < 4) {
2586  SSLParserReset(ssl_state);
2588  SCLogDebug("record len < 4 => %u", ssl_state->curr_connp->record_length);
2589  return SSL_DECODER_ERROR(-1);
2590  }
2591 
2592  int retval = SSLv3ParseHandshakeProtocol(ssl_state, input + parsed,
2593  record_len, direction);
2594  SCLogDebug("retval %d", retval);
2595  if (retval < 0 || retval > (int)record_len) {
2596  DEBUG_VALIDATE_BUG_ON(retval > (int)record_len);
2598  SCLogDebug("SSLv3ParseHandshakeProtocol returned %d", retval);
2599  return SSL_DECODER_ERROR(-1);
2600  }
2601  ValidateRecordState(ssl_state->curr_connp);
2602  break;
2603  }
2604  case SSLV3_HEARTBEAT_PROTOCOL: {
2605  AppLayerFrameNewByPointer(ssl_state->f, &stream_slice, input + parsed,
2606  ssl_state->curr_connp->record_length, direction, TLS_FRAME_HB_DATA);
2607  int retval = SSLv3ParseHeartbeatProtocol(ssl_state, input + parsed,
2608  record_len, direction);
2609  if (retval < 0) {
2610  SCLogDebug("SSLv3ParseHeartbeatProtocol returned %d", retval);
2611  return SSL_DECODER_ERROR(-1);
2612  }
2613  break;
2614  }
2615  default:
2616  // should be unreachable now that we check after header parsing
2618  SCLogDebug("unsupported record type");
2619  return SSL_DECODER_ERROR(-1);
2620  }
2621 
2622  parsed += record_len;
2623  ssl_state->curr_connp->bytes_processed += record_len;
2624 
2625  if (ssl_state->curr_connp->bytes_processed >=
2626  ssl_state->curr_connp->record_length + SSLV3_RECORD_HDR_LEN) {
2627  SCLogDebug("record complete, trigger RAW");
2629  ssl_state->f, direction == 0 ? STREAM_TOSERVER : STREAM_TOCLIENT);
2630  SSLParserReset(ssl_state);
2631  ValidateRecordState(ssl_state->curr_connp);
2632  return SSL_DECODER_OK(parsed);
2633 
2634  } else {
2635  /* we still don't have the entire record for the one we are
2636  currently parsing */
2637  ValidateRecordState(ssl_state->curr_connp);
2638  return SSL_DECODER_OK(parsed);
2639  }
2640 }
2641 
2642 /**
2643  * \internal
2644  * \brief SSLv2, SSLv23, SSLv3, TLSv1.1, TLSv1.2, TLSv1.3 parser.
2645  *
2646  * On parsing error, this should be the only function that should reset
2647  * the parser state, to avoid multiple functions in the chain resetting
2648  * the parser state.
2649  *
2650  * \param direction 0 for toserver, 1 for toclient.
2651  * \param alstate Pointer to the state.
2652  * \param pstate Application layer parser state for this session.
2653  * \param output Pointer to the list of parsed output elements.
2654  *
2655  * \todo On reaching an inconsistent state, check if the input has
2656  * another new record, instead of just returning after the reset
2657  *
2658  * \retval >=0 On success.
2659  */
2660 static AppLayerResult SSLDecode(Flow *f, uint8_t direction, void *alstate,
2661  AppLayerParserState *pstate, StreamSlice stream_slice)
2662 {
2663  SSLState *ssl_state = (SSLState *)alstate;
2664  ssl_state->tx_data.updated_tc = true;
2665  ssl_state->tx_data.updated_ts = true;
2666  uint32_t counter = 0;
2667  ssl_state->f = f;
2668  const uint8_t *input = StreamSliceGetData(&stream_slice);
2669  const uint8_t *init_input = input;
2670  int32_t input_len = (int32_t)StreamSliceGetDataLen(&stream_slice);
2671 
2672  if ((input == NULL || input_len == 0) &&
2673  ((direction == 0 && SCAppLayerParserStateIssetFlag(pstate, APP_LAYER_PARSER_EOF_TS)) ||
2674  (direction == 1 &&
2675  SCAppLayerParserStateIssetFlag(pstate, APP_LAYER_PARSER_EOF_TC)))) {
2676  /* flag session as finished if APP_LAYER_PARSER_EOF is set */
2677  if (direction == 0)
2678  UpdateClientState(ssl_state, TLS_STATE_CLIENT_FINISHED);
2679  else
2680  UpdateServerState(ssl_state, TLS_STATE_SERVER_FINISHED);
2682  } else if (input == NULL || input_len == 0) {
2684  }
2685 
2686  if (direction == 0)
2687  ssl_state->curr_connp = &ssl_state->client_connp;
2688  else
2689  ssl_state->curr_connp = &ssl_state->server_connp;
2690 
2691  /* If entering on a new record, reset the current flags. */
2692  if (ssl_state->curr_connp->bytes_processed == 0) {
2693  ssl_state->current_flags = 0;
2694  }
2695 
2696  /* if we have more than one record */
2697  uint32_t max_records = MAX((input_len / SSL_RECORD_MINIMUM_LENGTH),1);
2698  while (input_len > 0) {
2699  if (counter > max_records) {
2700  SCLogDebug("Looks like we have looped quite a bit. Reset state "
2701  "and get out of here");
2702  SSLParserReset(ssl_state);
2703  SSLSetEvent(ssl_state,
2705  return APP_LAYER_ERROR;
2706  }
2707 
2708  /* ssl_state->bytes_processed is zero for a fresh record or
2709  positive to indicate a record currently being parsed */
2710 
2711  if (ssl_state->curr_connp->bytes_processed == 0) {
2712  if ((input[0] & 0x80) || (input[0] & 0x40)) {
2713  /* only SSLv2, has one of the top 2 bits set */
2714  ssl_state->curr_connp->version = SSL_VERSION_2;
2715  SCLogDebug("SSLv2 detected");
2716  } else if (ssl_state->curr_connp->version == SSL_VERSION_2) {
2717  ssl_state->curr_connp->version = TLS_VERSION_UNKNOWN;
2718  SCLogDebug("SSL/TLS version reset");
2719  }
2720  }
2721  SCLogDebug("record %u: bytes_processed %u, version %02X, input_len %u", counter,
2722  ssl_state->curr_connp->bytes_processed, ssl_state->curr_connp->version, input_len);
2723 
2724  if (ssl_state->curr_connp->version == SSL_VERSION_2) {
2725  if (ssl_state->curr_connp->bytes_processed == 0) {
2726  SCLogDebug("New SSLv2 record parsing");
2727  } else {
2728  SCLogDebug("Continuing parsing SSLv2 record");
2729  }
2730  struct SSLDecoderResult r =
2731  SSLv2Decode(direction, ssl_state, pstate, input, input_len, stream_slice);
2732  if (r.retval < 0 || r.retval > input_len) {
2733  DEBUG_VALIDATE_BUG_ON(r.retval > input_len);
2734  SCLogDebug("Error parsing SSLv2. Resetting parser "
2735  "state. Let's get outta here");
2736  SSLParserReset(ssl_state);
2737  SSLSetEvent(ssl_state,
2739  return APP_LAYER_ERROR;
2740  } else if (r.needed) {
2741  input += r.retval;
2742  SCLogDebug("returning consumed %" PRIuMAX " needed %u",
2743  (uintmax_t)(input - init_input), r.needed);
2744  SCReturnStruct(APP_LAYER_INCOMPLETE((uint32_t)(input - init_input), r.needed));
2745  }
2746  input_len -= r.retval;
2747  input += r.retval;
2748  SCLogDebug("SSLv2 decoder consumed %d bytes: %u left", r.retval, input_len);
2749  } else {
2750  if (ssl_state->curr_connp->bytes_processed == 0) {
2751  SCLogDebug("New TLS record: record_length %u",
2752  ssl_state->curr_connp->record_length);
2753  } else {
2754  SCLogDebug("Continuing parsing TLS record: record_length %u, bytes_processed %u",
2755  ssl_state->curr_connp->record_length, ssl_state->curr_connp->bytes_processed);
2756  }
2757  struct SSLDecoderResult r =
2758  SSLv3Decode(direction, ssl_state, pstate, input, input_len, stream_slice);
2759  if (r.retval < 0 || r.retval > input_len) {
2760  DEBUG_VALIDATE_BUG_ON(r.retval > input_len);
2761  SCLogDebug("Error parsing TLS. Resetting parser "
2762  "state. Let's get outta here");
2763  SSLParserReset(ssl_state);
2764  return APP_LAYER_ERROR;
2765  } else if (r.needed) {
2766  input += r.retval;
2767  SCLogDebug("returning consumed %" PRIuMAX " needed %u",
2768  (uintmax_t)(input - init_input), r.needed);
2769  SCReturnStruct(APP_LAYER_INCOMPLETE((uint32_t)(input - init_input), r.needed));
2770  }
2771  input_len -= r.retval;
2772  input += r.retval;
2773  SCLogDebug("TLS decoder consumed %d bytes: %u left", r.retval, input_len);
2774 
2776  && ssl_state->curr_connp->record_length == 0) {
2777  SCLogDebug("TLS empty record");
2778  /* empty record */
2779  SSLParserReset(ssl_state);
2780  }
2781  }
2782  counter++;
2783  } /* while (input_len) */
2784 
2785  /* mark handshake as done if we have subject and issuer */
2786  if ((ssl_state->flags & SSL_AL_FLAG_NEED_CLIENT_CERT) &&
2787  ssl_state->client_connp.cert0_subject && ssl_state->client_connp.cert0_issuerdn) {
2788  /* update both sides to keep existing behavior */
2789  UpdateClientState(ssl_state, TLS_STATE_CLIENT_HANDSHAKE_DONE);
2790  UpdateServerState(ssl_state, TLS_STATE_SERVER_HANDSHAKE_DONE);
2791  } else if ((ssl_state->flags & SSL_AL_FLAG_NEED_CLIENT_CERT) == 0 &&
2792  ssl_state->server_connp.cert0_subject && ssl_state->server_connp.cert0_issuerdn) {
2793  /* update both sides to keep existing behavior */
2794  UpdateClientState(ssl_state, TLS_STATE_CLIENT_HANDSHAKE_DONE);
2795  UpdateServerState(ssl_state, TLS_STATE_SERVER_HANDSHAKE_DONE);
2796  }
2797 
2798  /* flag session as finished if APP_LAYER_PARSER_EOF is set */
2799  if (SCAppLayerParserStateIssetFlag(pstate, APP_LAYER_PARSER_EOF_TS) &&
2800  SCAppLayerParserStateIssetFlag(pstate, APP_LAYER_PARSER_EOF_TC)) {
2801  /* update both sides to keep existing behavior */
2802  UpdateClientState(ssl_state, TLS_STATE_CLIENT_FINISHED);
2803  UpdateServerState(ssl_state, TLS_STATE_SERVER_FINISHED);
2804  }
2805 
2806  return APP_LAYER_OK;
2807 }
2808 
2809 static AppLayerResult SSLParseClientRecord(Flow *f, void *alstate, AppLayerParserState *pstate,
2810  StreamSlice stream_slice, void *local_data)
2811 {
2812  return SSLDecode(f, 0 /* toserver */, alstate, pstate, stream_slice);
2813 }
2814 
2815 static AppLayerResult SSLParseServerRecord(Flow *f, void *alstate, AppLayerParserState *pstate,
2816  StreamSlice stream_slice, void *local_data)
2817 {
2818  return SSLDecode(f, 1 /* toclient */, alstate, pstate, stream_slice);
2819 }
2820 
2821 /**
2822  * \internal
2823  * \brief Function to allocate the SSL state memory.
2824  */
2825 static void *SSLStateAlloc(void *orig_state, AppProto proto_orig)
2826 {
2827  SSLState *ssl_state = SCCalloc(1, sizeof(SSLState));
2828  if (unlikely(ssl_state == NULL))
2829  return NULL;
2830  TAILQ_INIT(&ssl_state->server_connp.certs);
2831  TAILQ_INIT(&ssl_state->client_connp.certs);
2832 
2833  return (void *)ssl_state;
2834 }
2835 
2836 static void SSLStateCertSANFree(SSLStateConnp *connp)
2837 {
2838  if (connp->cert0_sans) {
2839  for (uint16_t i = 0; i < connp->cert0_sans_num; i++) {
2840  SCX509ArrayFree(connp->cert0_sans[i].san, connp->cert0_sans[i].san_len);
2841  }
2842  SCFree(connp->cert0_sans);
2843  }
2844 }
2845 
2846 /**
2847  * \internal
2848  * \brief Function to free the SSL state memory.
2849  */
2850 static void SSLStateFree(void *p)
2851 {
2852  SSLState *ssl_state = (SSLState *)p;
2853  SSLCertsChain *item;
2854 
2855  if (ssl_state->client_connp.cert0_subject)
2856  SCX509ArrayFree(
2857  ssl_state->client_connp.cert0_subject, ssl_state->client_connp.cert0_subject_len);
2858  if (ssl_state->client_connp.cert0_issuerdn)
2859  SCX509ArrayFree(
2861  if (ssl_state->client_connp.cert0_serial)
2862  SCX509ArrayFree(
2863  ssl_state->client_connp.cert0_serial, ssl_state->client_connp.cert0_serial_len);
2864  if (ssl_state->client_connp.cert0_fingerprint)
2866  if (ssl_state->client_connp.sni)
2867  SCFree(ssl_state->client_connp.sni);
2868  if (ssl_state->client_connp.session_id)
2869  SCFree(ssl_state->client_connp.session_id);
2870  if (ssl_state->client_connp.hs_buffer)
2871  SCFree(ssl_state->client_connp.hs_buffer);
2872 
2873  if (ssl_state->server_connp.cert0_subject)
2874  SCX509ArrayFree(
2875  ssl_state->server_connp.cert0_subject, ssl_state->server_connp.cert0_subject_len);
2876  if (ssl_state->server_connp.cert0_issuerdn)
2877  SCX509ArrayFree(
2879  if (ssl_state->server_connp.cert0_serial)
2880  SCX509ArrayFree(
2881  ssl_state->server_connp.cert0_serial, ssl_state->server_connp.cert0_serial_len);
2882  if (ssl_state->server_connp.cert0_fingerprint)
2884  if (ssl_state->server_connp.sni)
2885  SCFree(ssl_state->server_connp.sni);
2886  if (ssl_state->server_connp.session_id)
2887  SCFree(ssl_state->server_connp.session_id);
2888 
2889  if (ssl_state->client_connp.hs)
2890  SCTLSHandshakeFree(ssl_state->client_connp.hs);
2891  if (ssl_state->client_connp.ja3_str)
2892  Ja3BufferFree(&ssl_state->client_connp.ja3_str);
2893  if (ssl_state->client_connp.ja3_hash)
2894  SCFree(ssl_state->client_connp.ja3_hash);
2895  if (ssl_state->server_connp.hs)
2896  SCTLSHandshakeFree(ssl_state->server_connp.hs);
2897  if (ssl_state->server_connp.ja3_str)
2898  Ja3BufferFree(&ssl_state->server_connp.ja3_str);
2899  if (ssl_state->server_connp.ja3_hash)
2900  SCFree(ssl_state->server_connp.ja3_hash);
2901  if (ssl_state->server_connp.hs_buffer)
2902  SCFree(ssl_state->server_connp.hs_buffer);
2903 
2904  SSLStateCertSANFree(&ssl_state->server_connp);
2905  SSLStateCertSANFree(&ssl_state->client_connp);
2906 
2907  SCAppLayerTxDataCleanup(&ssl_state->tx_data);
2908 
2909  /* Free certificate chain */
2910  if (ssl_state->server_connp.certs_buffer)
2911  SCFree(ssl_state->server_connp.certs_buffer);
2912  while ((item = TAILQ_FIRST(&ssl_state->server_connp.certs))) {
2913  TAILQ_REMOVE(&ssl_state->server_connp.certs, item, next);
2914  SCFree(item);
2915  }
2916  TAILQ_INIT(&ssl_state->server_connp.certs);
2917  /* Free certificate chain */
2918  if (ssl_state->client_connp.certs_buffer)
2919  SCFree(ssl_state->client_connp.certs_buffer);
2920  while ((item = TAILQ_FIRST(&ssl_state->client_connp.certs))) {
2921  TAILQ_REMOVE(&ssl_state->client_connp.certs, item, next);
2922  SCFree(item);
2923  }
2924  TAILQ_INIT(&ssl_state->client_connp.certs);
2925 
2926  SCFree(ssl_state);
2927 }
2928 
2929 static void SSLStateTransactionFree(void *state, uint64_t tx_id)
2930 {
2931  /* do nothing */
2932 }
2933 
2934 static AppProto SSLProbingParser(
2935  const Flow *f, uint8_t direction, const uint8_t *input, uint32_t ilen, uint8_t *rdir)
2936 {
2937  /* probably a rst/fin sending an eof */
2938  if (ilen < 3)
2939  return ALPROTO_UNKNOWN;
2940 
2941  /* for now just the 3 byte header ones */
2942  /* \todo Detect the 2 byte ones */
2943  if ((input[0] & 0x80) && (input[2] == 0x01)) {
2944  return ALPROTO_TLS;
2945  }
2946 
2947  return ALPROTO_FAILED;
2948 }
2949 
2950 static int SSLStateGetStateIdByName(const char *name, const uint8_t direction)
2951 {
2952  SCEnumCharMap *map =
2953  direction == STREAM_TOSERVER ? tls_state_client_table : tls_state_server_table;
2954 
2955  int id = SCMapEnumNameToValue(name, map);
2956  if (id < 0) {
2957  return -1;
2958  }
2959  return id;
2960 }
2961 
2962 static const char *SSLStateGetStateNameById(const int id, const uint8_t direction)
2963 {
2964  SCEnumCharMap *map =
2965  direction == STREAM_TOSERVER ? tls_state_client_table : tls_state_server_table;
2966  const char *name = SCMapEnumValueToName(id, map);
2967  return name;
2968 }
2969 
2970 static int SSLStateGetFrameIdByName(const char *frame_name)
2971 {
2972  int id = SCMapEnumNameToValue(frame_name, tls_frame_table);
2973  if (id < 0) {
2974  return -1;
2975  }
2976  return id;
2977 }
2978 
2979 static const char *SSLStateGetFrameNameById(const uint8_t frame_id)
2980 {
2981  const char *name = SCMapEnumValueToName(frame_id, tls_frame_table);
2982  return name;
2983 }
2984 
2985 static int SSLStateGetEventInfo(
2986  const char *event_name, uint8_t *event_id, AppLayerEventType *event_type)
2987 {
2988  if (SCAppLayerGetEventIdByName(event_name, tls_decoder_event_table, event_id) == 0) {
2989  *event_type = APP_LAYER_EVENT_TYPE_TRANSACTION;
2990  return 0;
2991  }
2992  return -1;
2993 }
2994 
2995 static int SSLStateGetEventInfoById(
2996  uint8_t event_id, const char **event_name, AppLayerEventType *event_type)
2997 {
2998  *event_name = SCMapEnumValueToName(event_id, tls_decoder_event_table);
2999  if (*event_name == NULL) {
3000  SCLogError("event \"%d\" not present in "
3001  "ssl's enum map table.",
3002  event_id);
3003  /* yes this is fatal */
3004  return -1;
3005  }
3006 
3007  *event_type = APP_LAYER_EVENT_TYPE_TRANSACTION;
3008 
3009  return 0;
3010 }
3011 
3012 static int SSLRegisterPatternsForProtocolDetection(void)
3013 {
3014  if (SCAppLayerProtoDetectPMRegisterPatternCSwPP(IPPROTO_TCP, ALPROTO_TLS, "|01 00 02|", 5, 2,
3015  STREAM_TOSERVER, SSLProbingParser, 0, 3) < 0) {
3016  return -1;
3017  }
3018 
3019  /** SSLv3 */
3021  IPPROTO_TCP, ALPROTO_TLS, "|01 03 00|", 3, 0, STREAM_TOSERVER) < 0) {
3022  return -1;
3023  }
3025  IPPROTO_TCP, ALPROTO_TLS, "|16 03 00|", 3, 0, STREAM_TOSERVER) < 0) {
3026  return -1;
3027  }
3028 
3029  /** TLSv1 */
3031  IPPROTO_TCP, ALPROTO_TLS, "|01 03 01|", 3, 0, STREAM_TOSERVER) < 0) {
3032  return -1;
3033  }
3035  IPPROTO_TCP, ALPROTO_TLS, "|16 03 01|", 3, 0, STREAM_TOSERVER) < 0) {
3036  return -1;
3037  }
3038 
3039  /** TLSv1.1 */
3041  IPPROTO_TCP, ALPROTO_TLS, "|01 03 02|", 3, 0, STREAM_TOSERVER) < 0) {
3042  return -1;
3043  }
3045  IPPROTO_TCP, ALPROTO_TLS, "|16 03 02|", 3, 0, STREAM_TOSERVER) < 0) {
3046  return -1;
3047  }
3048 
3049  /** TLSv1.2 */
3051  IPPROTO_TCP, ALPROTO_TLS, "|01 03 03|", 3, 0, STREAM_TOSERVER) < 0) {
3052  return -1;
3053  }
3055  IPPROTO_TCP, ALPROTO_TLS, "|16 03 03|", 3, 0, STREAM_TOSERVER) < 0) {
3056  return -1;
3057  }
3058 
3059  /***** toclient direction *****/
3060 
3062  IPPROTO_TCP, ALPROTO_TLS, "|15 03 00|", 3, 0, STREAM_TOCLIENT) < 0) {
3063  return -1;
3064  }
3066  IPPROTO_TCP, ALPROTO_TLS, "|16 03 00|", 3, 0, STREAM_TOCLIENT) < 0) {
3067  return -1;
3068  }
3070  IPPROTO_TCP, ALPROTO_TLS, "|17 03 00|", 3, 0, STREAM_TOCLIENT) < 0) {
3071  return -1;
3072  }
3073 
3074  /** TLSv1 */
3076  IPPROTO_TCP, ALPROTO_TLS, "|15 03 01|", 3, 0, STREAM_TOCLIENT) < 0) {
3077  return -1;
3078  }
3080  IPPROTO_TCP, ALPROTO_TLS, "|16 03 01|", 3, 0, STREAM_TOCLIENT) < 0) {
3081  return -1;
3082  }
3084  IPPROTO_TCP, ALPROTO_TLS, "|17 03 01|", 3, 0, STREAM_TOCLIENT) < 0) {
3085  return -1;
3086  }
3087 
3088  /** TLSv1.1 */
3090  IPPROTO_TCP, ALPROTO_TLS, "|15 03 02|", 3, 0, STREAM_TOCLIENT) < 0) {
3091  return -1;
3092  }
3094  IPPROTO_TCP, ALPROTO_TLS, "|16 03 02|", 3, 0, STREAM_TOCLIENT) < 0) {
3095  return -1;
3096  }
3098  IPPROTO_TCP, ALPROTO_TLS, "|17 03 02|", 3, 0, STREAM_TOCLIENT) < 0) {
3099  return -1;
3100  }
3101 
3102  /** TLSv1.2 */
3104  IPPROTO_TCP, ALPROTO_TLS, "|15 03 03|", 3, 0, STREAM_TOCLIENT) < 0) {
3105  return -1;
3106  }
3108  IPPROTO_TCP, ALPROTO_TLS, "|16 03 03|", 3, 0, STREAM_TOCLIENT) < 0) {
3109  return -1;
3110  }
3112  IPPROTO_TCP, ALPROTO_TLS, "|17 03 03|", 3, 0, STREAM_TOCLIENT) < 0) {
3113  return -1;
3114  }
3115 
3116  /* Subsection - SSLv2 style record by client, but informing the server
3117  * the max version it supports.
3118  * Updated by Anoop Saldanha. Disabled it for now. We'll get back to
3119  * it after some tests */
3120 #if 0
3122  "|01 03 00|", 5, 2, STREAM_TOSERVER) < 0)
3123  {
3124  return -1;
3125  }
3127  "|00 02|", 7, 5, STREAM_TOCLIENT) < 0)
3128  {
3129  return -1;
3130  }
3131 #endif
3132 
3133  return 0;
3134 }
3135 
3136 #ifdef HAVE_JA3
3137 static void CheckJA3Enabled(void)
3138 {
3139  const char *strval = NULL;
3140  /* Check if we should generate JA3 fingerprints */
3141  int enable_ja3 = SSL_CONFIG_DEFAULT_JA3;
3142  if (SCConfGetNonNull("app-layer.protocols.tls.ja3-fingerprints", &strval) != 1) {
3143  enable_ja3 = SSL_CONFIG_DEFAULT_JA3;
3144  } else if (strcmp(strval, "auto") == 0) {
3145  enable_ja3 = SSL_CONFIG_DEFAULT_JA3;
3146  } else if (SCConfValIsFalse(strval)) {
3147  enable_ja3 = 0;
3148  ssl_config.disable_ja3 = true;
3149  } else if (SCConfValIsTrue(strval)) {
3150  enable_ja3 = true;
3151  }
3152  SC_ATOMIC_SET(ssl_config.enable_ja3, enable_ja3);
3154  /* The feature is available, i.e. _could_ be activated by a rule or
3155  even is enabled in the configuration. */
3157  }
3158 }
3159 #endif /* HAVE_JA3 */
3160 
3161 #ifdef HAVE_JA4
3162 static void CheckJA4Enabled(void)
3163 {
3164  const char *strval = NULL;
3165  /* Check if we should generate JA4 fingerprints */
3166  int enable_ja4 = SSL_CONFIG_DEFAULT_JA4;
3167  if (SCConfGetNonNull("app-layer.protocols.tls.ja4-fingerprints", &strval) != 1) {
3168  enable_ja4 = SSL_CONFIG_DEFAULT_JA4;
3169  } else if (strcmp(strval, "auto") == 0) {
3170  enable_ja4 = SSL_CONFIG_DEFAULT_JA4;
3171  } else if (SCConfValIsFalse(strval)) {
3172  enable_ja4 = 0;
3173  ssl_config.disable_ja4 = true;
3174  } else if (SCConfValIsTrue(strval)) {
3175  enable_ja4 = true;
3176  }
3177  SC_ATOMIC_SET(ssl_config.enable_ja4, enable_ja4);
3179  /* The feature is available, i.e. _could_ be activated by a rule or
3180  even is enabled in the configuration. */
3182  }
3183 }
3184 #endif /* HAVE_JA4 */
3185 
3186 /**
3187  * \brief Function to register the SSL protocol parser and other functions
3188  */
3190 {
3191  const char *proto_name = "tls";
3192 
3193  SC_ATOMIC_INIT(ssl_config.enable_ja3);
3194 
3195  /** SSLv2 and SSLv23*/
3196  if (SCAppLayerProtoDetectConfProtoDetectionEnabled("tcp", proto_name)) {
3198 
3199  if (SSLRegisterPatternsForProtocolDetection() < 0)
3200  return;
3201 
3202  if (RunmodeIsUnittests()) {
3204  IPPROTO_TCP, "443", ALPROTO_TLS, 0, 3, STREAM_TOSERVER, SSLProbingParser, NULL);
3205  } else {
3206  if (SCAppLayerProtoDetectPPParseConfPorts("tcp", IPPROTO_TCP, proto_name, ALPROTO_TLS,
3207  0, 3, SSLProbingParser, NULL) == 0) {
3208  SCLogConfig("no TLS config found, "
3209  "enabling TLS detection on port 443.");
3210  SCAppLayerProtoDetectPPRegister(IPPROTO_TCP, "443", ALPROTO_TLS, 0, 3,
3211  STREAM_TOSERVER, SSLProbingParser, NULL);
3212  }
3213  }
3214  } else {
3215  SCLogConfig("Protocol detection and parser disabled for %s protocol",
3216  proto_name);
3217  return;
3218  }
3219 
3220  if (SCAppLayerParserConfParserEnabled("tcp", proto_name)) {
3221  AppLayerParserRegisterParser(IPPROTO_TCP, ALPROTO_TLS, STREAM_TOSERVER,
3222  SSLParseClientRecord);
3223 
3224  AppLayerParserRegisterParser(IPPROTO_TCP, ALPROTO_TLS, STREAM_TOCLIENT,
3225  SSLParseServerRecord);
3227  IPPROTO_TCP, ALPROTO_TLS, SSLStateGetStateIdByName, SSLStateGetStateNameById);
3229  IPPROTO_TCP, ALPROTO_TLS, SSLStateGetFrameIdByName, SSLStateGetFrameNameById);
3230  AppLayerParserRegisterGetEventInfo(IPPROTO_TCP, ALPROTO_TLS, SSLStateGetEventInfo);
3231  AppLayerParserRegisterGetEventInfoById(IPPROTO_TCP, ALPROTO_TLS, SSLStateGetEventInfoById);
3232 
3233  AppLayerParserRegisterStateFuncs(IPPROTO_TCP, ALPROTO_TLS, SSLStateAlloc, SSLStateFree);
3234 
3236  IPPROTO_TCP, ALPROTO_TLS, STREAM_TOSERVER);
3237 
3238  AppLayerParserRegisterTxFreeFunc(IPPROTO_TCP, ALPROTO_TLS, SSLStateTransactionFree);
3239 
3240  AppLayerParserRegisterGetTx(IPPROTO_TCP, ALPROTO_TLS, SSLGetTx);
3241  AppLayerParserRegisterTxDataFunc(IPPROTO_TCP, ALPROTO_TLS, SSLGetTxData);
3242  AppLayerParserRegisterStateDataFunc(IPPROTO_TCP, ALPROTO_TLS, SSLGetStateData);
3243 
3244  AppLayerParserRegisterGetTxCnt(IPPROTO_TCP, ALPROTO_TLS, SSLGetTxCnt);
3245 
3246  AppLayerParserRegisterGetStateProgressFunc(IPPROTO_TCP, ALPROTO_TLS, SSLGetAlstateProgress);
3247 
3250 
3251  SCConfNode *enc_handle = SCConfGetNode("app-layer.protocols.tls.encryption-handling");
3252  if (enc_handle != NULL && enc_handle->val != NULL) {
3253  SCLogDebug("have app-layer.protocols.tls.encryption-handling = %s", enc_handle->val);
3254  if (strcmp(enc_handle->val, "full") == 0) {
3256  } else if (strcmp(enc_handle->val, "bypass") == 0) {
3258  } else if (strcmp(enc_handle->val, "track-only") == 0) {
3260  } else if (strcmp(enc_handle->val, "default") == 0) {
3261  SCLogWarning("app-layer.protocols.tls.encryption-handling = default is deprecated "
3262  "and will be removed in Suricata 9, use \"track-only\" instead, "
3263  "(see ticket #7642)");
3265  } else {
3267  }
3268  } else {
3269  /* Get the value of no reassembly option from the config file */
3270  if (SCConfGetNode("app-layer.protocols.tls.no-reassemble") == NULL) {
3271  int value = 0;
3272  if (SCConfGetBool("tls.no-reassemble", &value) == 1 && value == 1)
3274  } else {
3275  int value = 0;
3276  if (SCConfGetBool("app-layer.protocols.tls.no-reassemble", &value) == 1 &&
3277  value == 1)
3279  }
3280  }
3281  SCLogDebug("ssl_config.encrypt_mode %u", ssl_config.encrypt_mode);
3282 
3283 #ifdef HAVE_JA3
3284  CheckJA3Enabled();
3285 #endif /* HAVE_JA3 */
3286 #ifdef HAVE_JA4
3287  CheckJA4Enabled();
3288 #endif /* HAVE_JA4 */
3289 
3290  if (g_disable_hashing) {
3291  if (SC_ATOMIC_GET(ssl_config.enable_ja3)) {
3292  SCLogWarning("MD5 calculation has been disabled, disabling JA3");
3293  SC_ATOMIC_SET(ssl_config.enable_ja3, 0);
3294  }
3295  if (SC_ATOMIC_GET(ssl_config.enable_ja4)) {
3296  SCLogWarning("Hashing has been disabled, disabling JA4");
3297  SC_ATOMIC_SET(ssl_config.enable_ja4, 0);
3298  }
3299  } else {
3300  if (RunmodeIsUnittests()) {
3301 #ifdef HAVE_JA3
3302  SC_ATOMIC_SET(ssl_config.enable_ja3, 1);
3303 #endif /* HAVE_JA3 */
3304 #ifdef HAVE_JA4
3305  SC_ATOMIC_SET(ssl_config.enable_ja4, 1);
3306 #endif /* HAVE_JA4 */
3307  }
3308  }
3309  } else {
3310  SCLogConfig("Parser disabled for %s protocol. Protocol detection still on.", proto_name);
3311  }
3312 }
3313 
3314 /**
3315  * \brief if not explicitly disabled in config, enable ja3 support
3316  *
3317  * Implemented using atomic to allow rule reloads to do this at
3318  * runtime.
3319  */
3320 void SSLEnableJA3(void)
3321 {
3323  return;
3324  }
3325  if (SC_ATOMIC_GET(ssl_config.enable_ja3)) {
3326  return;
3327  }
3328  SC_ATOMIC_SET(ssl_config.enable_ja3, 1);
3329 }
3330 
3331 /**
3332  * \brief if not explicitly disabled in config, enable ja4 support
3333  *
3334  * Implemented using atomic to allow rule reloads to do this at
3335  * runtime.
3336  */
3337 void SSLEnableJA4(void)
3338 {
3339  // only caller has #ifdef HAVE_JA4
3341  return;
3342  }
3343  if (SC_ATOMIC_GET(ssl_config.enable_ja4)) {
3344  return;
3345  }
3346  SC_ATOMIC_SET(ssl_config.enable_ja4, 1);
3347 }
3348 
3349 /**
3350  * \brief return whether ja3 is effectively enabled
3351  *
3352  * This means that it either has been enabled explicitly or has been
3353  * enabled by having loaded a rule while not being explicitly disabled.
3354  *
3355  * \retval true if enabled, false otherwise
3356  */
3358 {
3359  return SC_ATOMIC_GET(ssl_config.enable_ja3);
3360 }
3361 
3362 /**
3363  * \brief return whether ja4 is effectively enabled
3364  *
3365  * This means that it either has been enabled explicitly or has been
3366  * enabled by having loaded a rule while not being explicitly disabled.
3367  *
3368  * \retval true if enabled, false otherwise
3369  */
3371 {
3372  return SC_ATOMIC_GET(ssl_config.enable_ja4);
3373 }
SSLV3_CHANGE_CIPHER_SPEC
#define SSLV3_CHANGE_CIPHER_SPEC
Definition: app-layer-ssl.c:213
ERR_INVALID_SERIAL
@ ERR_INVALID_SERIAL
Definition: app-layer-ssl.c:175
tls_frame_table
SCEnumCharMap tls_frame_table[]
Definition: app-layer-ssl.c:99
StreamSlice
Definition: app-layer-parser.h:120
TLS_DECODER_EVENT_CERTIFICATE_INVALID_ISSUER
@ TLS_DECODER_EVENT_CERTIFICATE_INVALID_ISSUER
Definition: app-layer-ssl.h:72
AppLayerParserRegisterGetStateProgressFunc
void AppLayerParserRegisterGetStateProgressFunc(uint8_t ipproto, AppProto alproto, int(*StateGetProgress)(void *alstate, uint8_t direction))
Definition: app-layer-parser.c:536
SSLState_
SSLv[2.0|3.[0|1|2|3]] state structure.
Definition: app-layer-ssl.h:237
SslConfig_::disable_ja3
bool disable_ja3
Definition: app-layer-ssl.c:205
SSL_EXTENSION_EC_POINT_FORMATS
#define SSL_EXTENSION_EC_POINT_FORMATS
Definition: app-layer-ssl.h:149
SSLSubjectAltName_::san_len
uint32_t san_len
Definition: app-layer-ssl.h:170
SCConfValIsTrue
int SCConfValIsTrue(const char *val)
Check if a value is true.
Definition: conf.c:578
SCAppLayerParserStateIssetFlag
uint16_t SCAppLayerParserStateIssetFlag(AppLayerParserState *pstate, uint16_t flag)
Definition: app-layer-parser.c:2105
JA3Buffer_
Definition: util-ja3.h:31
TLS_DECODER_EVENT_DATALEAK_HEARTBEAT_MISMATCH
@ TLS_DECODER_EVENT_DATALEAK_HEARTBEAT_MISMATCH
Definition: app-layer-ssl.h:54
SSLCertsChain_::cert_len
uint32_t cert_len
Definition: app-layer-ssl.h:164
TLS_DECODER_EVENT_HEARTBEAT
@ TLS_DECODER_EVENT_HEARTBEAT
Definition: app-layer-ssl.h:51
TLS_HB_RESPONSE
#define TLS_HB_RESPONSE
Definition: app-layer-ssl.c:254
SHA1_STRING_LENGTH
#define SHA1_STRING_LENGTH
Definition: app-layer-ssl.c:258
TAILQ_INIT
#define TAILQ_INIT(head)
Definition: queue.h:262
TLS_DECODER_EVENT_OVERFLOW_HEARTBEAT
@ TLS_DECODER_EVENT_OVERFLOW_HEARTBEAT
Definition: app-layer-ssl.h:53
SC_ATOMIC_INIT
#define SC_ATOMIC_INIT(name)
wrapper for initializing an atomic variable.
Definition: util-atomic.h:314
TLS_DECODER_EVENT_ERROR_MSG_ENCOUNTERED
@ TLS_DECODER_EVENT_ERROR_MSG_ENCOUNTERED
Definition: app-layer-ssl.h:74
ERR_EXTRACT_SUBJECT
@ ERR_EXTRACT_SUBJECT
Definition: app-layer-ssl.c:183
SSLV3_HS_FINISHED
#define SSLV3_HS_FINISHED
Definition: app-layer-ssl.c:230
SSLState_::hb_record_len
uint32_t hb_record_len
Definition: app-layer-ssl.h:247
unlikely
#define unlikely(expr)
Definition: util-optimize.h:35
SSL_EXTENSION_ELLIPTIC_CURVES
#define SSL_EXTENSION_ELLIPTIC_CURVES
Definition: app-layer-ssl.h:148
SC_ATOMIC_SET
#define SC_ATOMIC_SET(name, val)
Set the value for the atomic variable.
Definition: util-atomic.h:386
SSLStateConnp_::message_length
uint32_t message_length
Definition: app-layer-ssl.h:180
SSLState_::client_connp
SSLStateConnp client_connp
Definition: app-layer-ssl.h:258
TLS_DECODER_EVENT_INVALID_HANDSHAKE_MESSAGE
@ TLS_DECODER_EVENT_INVALID_HANDSHAKE_MESSAGE
Definition: app-layer-ssl.h:50
TLS_FRAME_DATA
@ TLS_FRAME_DATA
Definition: app-layer-ssl.h:36
ALPROTO_TLS
@ ALPROTO_TLS
Definition: app-layer-protos.h:39
SSLEnableJA4
void SSLEnableJA4(void)
if not explicitly disabled in config, enable ja4 support
Definition: app-layer-ssl.c:3337
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:282
SSL_AL_FLAG_EARLY_DATA
#define SSL_AL_FLAG_EARLY_DATA
Definition: app-layer-ssl.h:133
SSLStateConnp_::bytes_processed
uint32_t bytes_processed
Definition: app-layer-ssl.h:188
SCAppLayerTxDataCleanup
void SCAppLayerTxDataCleanup(AppLayerTxData *txd)
Definition: app-layer-parser.c:823
next
struct HtpBodyChunk_ * next
Definition: app-layer-htp.h:0
SSLV2_MT_SERVER_FINISHED
#define SSLV2_MT_SERVER_FINISHED
Definition: app-layer-ssl.c:241
SSLState_::server_connp
SSLStateConnp server_connp
Definition: app-layer-ssl.h:259
SSLStateConnp_::cert0_not_before
int64_t cert0_not_before
Definition: app-layer-ssl.h:199
name
const char * name
Definition: detect-engine-proto.c:48
SSL_AL_FLAG_SESSION_RESUMED
#define SSL_AL_FLAG_SESSION_RESUMED
Definition: app-layer-ssl.h:122
AppProto
uint16_t AppProto
Definition: app-layer-protos.h:87
ValidateRecordState
#define ValidateRecordState(...)
Definition: app-layer-ssl.c:309
SSLStateConnp_
Definition: app-layer-ssl.h:173
SSLStateConnp_::ja3_hash
char * ja3_hash
Definition: app-layer-ssl.h:219
SSL_CONFIG_DEFAULT_JA3
#define SSL_CONFIG_DEFAULT_JA3
Definition: app-layer-ssl.c:189
type
uint8_t type
Definition: decode-sctp.h:0
SCAppLayerParserStateSetFlag
void SCAppLayerParserStateSetFlag(AppLayerParserState *pstate, uint16_t flag)
Definition: app-layer-parser.c:2097
SSLStateConnp_::session_id_length
uint16_t session_id_length
Definition: app-layer-ssl.h:190
AppLayerStateData
Definition: app-layer-parser.h:149
tls_decoder_event_table
SCEnumCharMap tls_decoder_event_table[]
Definition: app-layer-ssl.c:131
Flow_
Flow data structure.
Definition: flow.h:354
SSL_EXTENSION_SUPPORTED_VERSIONS
#define SSL_EXTENSION_SUPPORTED_VERSIONS
Definition: app-layer-ssl.h:154
SSLState_::f
Flow * f
Definition: app-layer-ssl.h:238
SSL_AL_FLAG_STATE_SERVER_HELLO
#define SSL_AL_FLAG_STATE_SERVER_HELLO
Definition: app-layer-ssl.h:111
SC_SHA1_LEN
#define SC_SHA1_LEN
Definition: util-file.h:107
SSLV3_HS_SERVER_HELLO
#define SSLV3_HS_SERVER_HELLO
Definition: app-layer-ssl.c:222
AppLayerParserRegisterStateProgressCompletionStatus
void AppLayerParserRegisterStateProgressCompletionStatus(AppProto alproto, const int ts, const int tc)
Definition: app-layer-parser.c:584
SSLState_::tx_data
AppLayerTxData tx_data
Definition: app-layer-ssl.h:241
SSLParserHSReset
#define SSLParserHSReset(connp)
Definition: app-layer-ssl.c:312
SSLV3_HS_CERTIFICATE
#define SSLV3_HS_CERTIFICATE
Definition: app-layer-ssl.c:224
ERR_INVALID_X509NAME
@ ERR_INVALID_X509NAME
Definition: app-layer-ssl.c:177
AppLayerParserRegisterTxFreeFunc
void AppLayerParserRegisterTxFreeFunc(uint8_t ipproto, AppProto alproto, void(*StateTransactionFree)(void *, uint64_t))
Definition: app-layer-parser.c:546
SSLV3_HEARTBEAT_PROTOCOL
#define SSLV3_HEARTBEAT_PROTOCOL
Definition: app-layer-ssl.c:217
SSLV2_MT_SERVER_HELLO
#define SSLV2_MT_SERVER_HELLO
Definition: app-layer-ssl.c:239
SSLState_::curr_connp
SSLStateConnp * curr_connp
Definition: app-layer-ssl.h:253
Ja3BufferAddValue
int Ja3BufferAddValue(JA3Buffer **buffer, uint32_t value)
Definition: util-ja3.c:314
SSLV3_HS_CERTIFICATE_URL
#define SSLV3_HS_CERTIFICATE_URL
Definition: app-layer-ssl.c:231
TLS_STATE_SERVER_HELLO_DONE
@ TLS_STATE_SERVER_HELLO_DONE
Definition: app-layer-ssl.h:90
MIN
#define MIN(x, y)
Definition: suricata-common.h:416
SCConfGetBool
int SCConfGetBool(const char *name, int *val)
Retrieve a configuration value as a boolean.
Definition: conf.c:524
AppLayerParserRegisterGetStateFuncs
void AppLayerParserRegisterGetStateFuncs(uint8_t ipproto, AppProto alproto, AppLayerParserGetStateIdByNameFn GetIdByNameFunc, AppLayerParserGetStateNameByIdFn GetNameByIdFunc)
Definition: app-layer-parser.c:643
util-ja3.h
SCConfValIsFalse
int SCConfValIsFalse(const char *val)
Check if a value is false.
Definition: conf.c:603
ERR_INVALID_ALGORITHMIDENTIFIER
@ ERR_INVALID_ALGORITHMIDENTIFIER
Definition: app-layer-ssl.c:176
SSL_AL_FLAG_STATE_SERVER_KEYX
#define SSL_AL_FLAG_STATE_SERVER_KEYX
Definition: app-layer-ssl.h:113
SSLState_::state_data
AppLayerStateData state_data
Definition: app-layer-ssl.h:240
TAILQ_INSERT_TAIL
#define TAILQ_INSERT_TAIL(head, elm, field)
Definition: queue.h:294
p
Packet * p
Definition: fuzz_iprep.c:21
SSLV3_HS_CERTIFICATE_VERIFY
#define SSLV3_HS_CERTIFICATE_VERIFY
Definition: app-layer-ssl.c:228
TLS_DECODER_EVENT_INVALID_TLS_HEADER
@ TLS_DECODER_EVENT_INVALID_TLS_HEADER
Definition: app-layer-ssl.h:46
SSL_CNF_ENC_HANDLE_TRACK_ONLY
@ SSL_CNF_ENC_HANDLE_TRACK_ONLY
Definition: app-layer-ssl.c:195
MAX
#define MAX(x, y)
Definition: suricata-common.h:420
SSLStateConnp_::hs_buffer_message_type
uint8_t hs_buffer_message_type
Definition: app-layer-ssl.h:226
TLS_DECODER_EVENT_INVALID_SSL_RECORD
@ TLS_DECODER_EVENT_INVALID_SSL_RECORD
Definition: app-layer-ssl.h:75
TLS_DECODER_EVENT_TOO_MANY_RECORDS_IN_PACKET
@ TLS_DECODER_EVENT_TOO_MANY_RECORDS_IN_PACKET
Definition: app-layer-ssl.h:59
TLS_DECODER_EVENT_MULTIPLE_SNI_EXTENSIONS
@ TLS_DECODER_EVENT_MULTIPLE_SNI_EXTENSIONS
Definition: app-layer-ssl.h:56
SSLStateConnp_::record_lengths_length
uint32_t record_lengths_length
Definition: app-layer-ssl.h:177
SSLSubjectAltName_::san
uint8_t * san
Definition: app-layer-ssl.h:169
TLS_FRAME_SSLV2_HDR
@ TLS_FRAME_SSLV2_HDR
Definition: app-layer-ssl.h:39
SSL_AL_FLAG_CHANGE_CIPHER_SPEC
#define SSL_AL_FLAG_CHANGE_CIPHER_SPEC
Definition: app-layer-ssl.h:99
SCAppLayerProtoDetectPMRegisterPatternCSwPP
int SCAppLayerProtoDetectPMRegisterPatternCSwPP(uint8_t ipproto, AppProto alproto, const char *pattern, uint16_t depth, uint16_t offset, uint8_t direction, ProbingParserFPtr PPFunc, uint16_t pp_min_depth, uint16_t pp_max_depth)
Definition: app-layer-detect-proto.c:1651
ERR_INVALID_DATE
@ ERR_INVALID_DATE
Definition: app-layer-ssl.c:178
SSLStateConnp_::hs_buffer_size
uint32_t hs_buffer_size
Definition: app-layer-ssl.h:228
TLS_DECODER_EVENT_CERTIFICATE_INVALID_DER
@ TLS_DECODER_EVENT_CERTIFICATE_INVALID_DER
Definition: app-layer-ssl.h:70
TLS_DECODER_EVENT_CERTIFICATE_INVALID_LENGTH
@ TLS_DECODER_EVENT_CERTIFICATE_INVALID_LENGTH
Definition: app-layer-ssl.h:63
TLS_FRAME_HB_DATA
@ TLS_FRAME_HB_DATA
Definition: app-layer-ssl.h:38
SSL_AL_FLAG_SSL_CLIENT_MASTER_KEY
#define SSL_AL_FLAG_SSL_CLIENT_MASTER_KEY
Definition: app-layer-ssl.h:104
SSL_AL_FLAG_SSL_CLIENT_SSN_ENCRYPTED
#define SSL_AL_FLAG_SSL_CLIENT_SSN_ENCRYPTED
Definition: app-layer-ssl.h:105
SSLStateConnp_::cert0_not_after
int64_t cert0_not_after
Definition: app-layer-ssl.h:200
SCAppLayerProtoDetectConfProtoDetectionEnabled
int SCAppLayerProtoDetectConfProtoDetectionEnabled(const char *ipproto, const char *alproto)
Given a protocol name, checks if proto detection is enabled in the conf file.
Definition: app-layer-detect-proto.c:1995
ERR_INVALID_LENGTH
@ ERR_INVALID_LENGTH
Definition: app-layer-ssl.c:173
SSLState_::current_flags
uint32_t current_flags
Definition: app-layer-ssl.h:251
SSLStateConnp_::cert0_sans
SSLSubjectAltName * cert0_sans
Definition: app-layer-ssl.h:203
AppLayerResult
Definition: app-layer-parser.h:114
SSL_AL_FLAG_HB_SERVER_INIT
#define SSL_AL_FLAG_HB_SERVER_INIT
Definition: app-layer-ssl.h:119
SCAppLayerParserTriggerRawStreamInspection
void SCAppLayerParserTriggerRawStreamInspection(Flow *f, int direction)
Definition: app-layer-parser.c:1813
TLS_DECODER_EVENT_CERTIFICATE_INVALID_VALIDITY
@ TLS_DECODER_EVENT_CERTIFICATE_INVALID_VALIDITY
Definition: app-layer-ssl.h:73
SSLV2_MT_SERVER_VERIFY
#define SSLV2_MT_SERVER_VERIFY
Definition: app-layer-ssl.c:240
app-layer-detect-proto.h
SSLDecoderResult::needed
uint32_t needed
Definition: app-layer-ssl.c:264
Ja3BufferInit
JA3Buffer * Ja3BufferInit(void)
Allocate new buffer.
Definition: util-ja3.c:39
APP_LAYER_INCOMPLETE
#define APP_LAYER_INCOMPLETE(c, n)
Definition: app-layer-parser.h:70
Ja3BufferFree
void Ja3BufferFree(JA3Buffer **buffer)
Free allocated buffer.
Definition: util-ja3.c:54
TAILQ_REMOVE
#define TAILQ_REMOVE(head, elm, field)
Definition: queue.h:312
feature.h
decode.h
util-debug.h
TLS_STATE_CLIENT_HANDSHAKE_DONE
@ TLS_STATE_CLIENT_HANDSHAKE_DONE
Definition: app-layer-ssl.h:82
TAILQ_FIRST
#define TAILQ_FIRST(head)
Definition: queue.h:250
AppLayerParserState_
Definition: app-layer-parser.c:148
TLS_HB_REQUEST
#define TLS_HB_REQUEST
Definition: app-layer-ssl.c:253
SSLJA3IsEnabled
bool SSLJA3IsEnabled(void)
return whether ja3 is effectively enabled
Definition: app-layer-ssl.c:3357
TLS_TC_RANDOM_SET
#define TLS_TC_RANDOM_SET
Definition: app-layer-ssl.h:139
AppLayerTxData
Definition: app-layer-parser.h:166
SCAppLayerParserConfParserEnabled
int SCAppLayerParserConfParserEnabled(const char *ipproto, const char *alproto_name)
check if a parser is enabled in the config Returns enabled always if: were running unittests
Definition: app-layer-parser.c:377
TLS_DECODER_EVENT_INVALID_RECORD_TYPE
@ TLS_DECODER_EVENT_INVALID_RECORD_TYPE
Definition: app-layer-ssl.h:48
ERR_INVALID_CERTIFICATE
@ ERR_INVALID_CERTIFICATE
Definition: app-layer-ssl.c:172
SSLState_::client_state
enum TlsStateClient client_state
Definition: app-layer-ssl.h:255
APP_LAYER_EVENT_TYPE_TRANSACTION
@ APP_LAYER_EVENT_TYPE_TRANSACTION
Definition: app-layer-events.h:55
AppLayerEventType
AppLayerEventType
Definition: app-layer-events.h:54
Ja3BufferAppendBuffer
int Ja3BufferAppendBuffer(JA3Buffer **buffer1, JA3Buffer **buffer2)
Definition: util-ja3.c:309
SSLStateConnp_::handshake_type
uint8_t handshake_type
Definition: app-layer-ssl.h:185
SSLV2_MT_REQUEST_CERTIFICATE
#define SSLV2_MT_REQUEST_CERTIFICATE
Definition: app-layer-ssl.c:242
SSLDecoderResult::retval
int retval
Definition: app-layer-ssl.c:263
SSLStateConnp_::hs_buffer_offset
uint32_t hs_buffer_offset
Definition: app-layer-ssl.h:229
SSLStateConnp_::certs_buffer
uint8_t * certs_buffer
Definition: app-layer-ssl.h:213
TLS_STATE_CLIENT_HELLO_DONE
@ TLS_STATE_CLIENT_HELLO_DONE
Definition: app-layer-ssl.h:80
TLS_DECODER_EVENT_INVALID_RECORD_VERSION
@ TLS_DECODER_EVENT_INVALID_RECORD_VERSION
Definition: app-layer-ssl.h:47
TlsStateServer
TlsStateServer
Definition: app-layer-ssl.h:86
TLS_DECODER_EVENT_CERTIFICATE_INVALID_DATE
@ TLS_DECODER_EVENT_CERTIFICATE_INVALID_DATE
Definition: app-layer-ssl.h:68
SSLCertsChain_
Definition: app-layer-ssl.h:162
SSLStateConnp_::cert0_serial_len
uint32_t cert0_serial_len
Definition: app-layer-ssl.h:198
AppLayerParserRegisterGetFrameFuncs
void AppLayerParserRegisterGetFrameFuncs(uint8_t ipproto, AppProto alproto, AppLayerParserGetFrameIdByNameFn GetIdByNameFunc, AppLayerParserGetFrameNameByIdFn GetNameByIdFunc)
Definition: app-layer-parser.c:653
TLS_DECODER_EVENT_CERTIFICATE_INVALID_SERIAL
@ TLS_DECODER_EVENT_CERTIFICATE_INVALID_SERIAL
Definition: app-layer-ssl.h:65
SSLParserReset
#define SSLParserReset(state)
Definition: app-layer-ssl.c:318
SCConfGetNonNull
int SCConfGetNonNull(const char *name, const char **vptr)
Retrieve the non-null value of a configuration node.
Definition: conf.c:381
TlsStateClient
TlsStateClient
Definition: app-layer-ssl.h:78
TLS_DECODER_EVENT_CERTIFICATE_INVALID_SUBJECT
@ TLS_DECODER_EVENT_CERTIFICATE_INVALID_SUBJECT
Definition: app-layer-ssl.h:71
TLS_TS_RANDOM_SET
#define TLS_TS_RANDOM_SET
Definition: app-layer-ssl.h:136
AppLayerParserRegisterStateFuncs
void AppLayerParserRegisterStateFuncs(uint8_t ipproto, AppProto alproto, void *(*StateAlloc)(void *, AppProto), void(*StateFree)(void *))
Definition: app-layer-parser.c:485
SSL_AL_FLAG_STATE_CLIENT_HELLO
#define SSL_AL_FLAG_STATE_CLIENT_HELLO
Definition: app-layer-ssl.h:110
TLS_STATE_SERVER_FINISHED
@ TLS_STATE_SERVER_FINISHED
Definition: app-layer-ssl.h:92
SCLogWarning
#define SCLogWarning(...)
Macro used to log WARNING messages.
Definition: util-debug.h:262
TLS_RANDOM_LEN
#define TLS_RANDOM_LEN
Definition: app-layer-ssl.h:160
SSLStateConnp_::cert0_serial
uint8_t * cert0_serial
Definition: app-layer-ssl.h:197
SslConfig_::SC_ATOMIC_DECLARE
SC_ATOMIC_DECLARE(int, enable_ja3)
app-layer-parser.h
TLS_STATE_CLIENT_IN_PROGRESS
@ TLS_STATE_CLIENT_IN_PROGRESS
Definition: app-layer-ssl.h:79
TLS_FRAME_SSLV2_PDU
@ TLS_FRAME_SSLV2_PDU
Definition: app-layer-ssl.h:40
AppLayerParserRegisterGetEventInfo
void AppLayerParserRegisterGetEventInfo(uint8_t ipproto, AppProto alproto, int(*StateGetEventInfo)(const char *event_name, uint8_t *event_id, AppLayerEventType *event_type))
Definition: app-layer-parser.c:663
SslConfigEncryptHandling
SslConfigEncryptHandling
Definition: app-layer-ssl.c:194
SSL_AL_FLAG_HB_CLIENT_INIT
#define SSL_AL_FLAG_HB_CLIENT_INIT
Definition: app-layer-ssl.h:118
SSL_AL_FLAG_STATE_CLIENT_KEYX
#define SSL_AL_FLAG_STATE_CLIENT_KEYX
Definition: app-layer-ssl.h:112
SSLV3_RECORD_HDR_LEN
#define SSLV3_RECORD_HDR_LEN
Definition: app-layer-ssl.c:245
SSLV2_MT_CLIENT_MASTER_KEY
#define SSLV2_MT_CLIENT_MASTER_KEY
Definition: app-layer-ssl.c:237
SSL_EXTENSION_ALPN
#define SSL_EXTENSION_ALPN
Definition: app-layer-ssl.h:151
TLS_DECODER_EVENT_INVALID_SSLV2_HEADER
@ TLS_DECODER_EVENT_INVALID_SSLV2_HEADER
Definition: app-layer-ssl.h:45
TLS_DECODER_EVENT_INVALID_RECORD_LENGTH
@ TLS_DECODER_EVENT_INVALID_RECORD_LENGTH
Definition: app-layer-ssl.h:49
conf.h
ERR_EXTRACT_ISSUER
@ ERR_EXTRACT_ISSUER
Definition: app-layer-ssl.c:184
SSL_AL_FLAG_CH_VERSION_EXTENSION
#define SSL_AL_FLAG_CH_VERSION_EXTENSION
Definition: app-layer-ssl.h:125
SSLStateConnp_::cert0_issuerdn
uint8_t * cert0_issuerdn
Definition: app-layer-ssl.h:195
SSLState_::server_state
enum TlsStateServer server_state
Definition: app-layer-ssl.h:256
SSLEnableJA3
void SSLEnableJA3(void)
if not explicitly disabled in config, enable ja3 support
Definition: app-layer-ssl.c:3320
SSLStateConnp_::record_length
uint32_t record_length
Definition: app-layer-ssl.h:175
SslConfig_
Definition: app-layer-ssl.c:200
SSLV2_MT_CLIENT_HELLO
#define SSLV2_MT_CLIENT_HELLO
Definition: app-layer-ssl.c:236
AppLayerProtoDetectRegisterProtocol
void AppLayerProtoDetectRegisterProtocol(AppProto alproto, const char *alproto_name)
Registers a protocol for protocol detection phase.
Definition: app-layer-detect-proto.c:1782
TLS_STATE_SERVER_CERT_DONE
@ TLS_STATE_SERVER_CERT_DONE
Definition: app-layer-ssl.h:89
SSLV3_APPLICATION_PROTOCOL
#define SSLV3_APPLICATION_PROTOCOL
Definition: app-layer-ssl.c:216
SSLV3_ALERT_PROTOCOL
#define SSLV3_ALERT_PROTOCOL
Definition: app-layer-ssl.c:214
SSLV2_MT_CLIENT_CERTIFICATE
#define SSLV2_MT_CLIENT_CERTIFICATE
Definition: app-layer-ssl.c:243
SSLStateConnp_::sni
uint8_t * sni
Definition: app-layer-ssl.h:206
SSLCertsChain_::cert_data
uint8_t * cert_data
Definition: app-layer-ssl.h:163
SSLStateConnp_::cert0_sans_num
uint16_t cert0_sans_num
Definition: app-layer-ssl.h:204
RunmodeIsUnittests
int RunmodeIsUnittests(void)
Definition: suricata.c:292
SSLStateConnp_::certs_buffer_size
uint32_t certs_buffer_size
Definition: app-layer-ssl.h:214
AppLayerParserRegisterParser
int AppLayerParserRegisterParser(uint8_t ipproto, AppProto alproto, uint8_t direction, AppLayerParserFPtr Parser)
Register app layer parser for the protocol.
Definition: app-layer-parser.c:452
TLS_DECODER_EVENT_INVALID_HEARTBEAT
@ TLS_DECODER_EVENT_INVALID_HEARTBEAT
Definition: app-layer-ssl.h:52
SSL_AL_FLAG_NEED_CLIENT_CERT
#define SSL_AL_FLAG_NEED_CLIENT_CERT
Definition: app-layer-ssl.h:141
SSLV3_HS_CLIENT_KEY_EXCHANGE
#define SSLV3_HS_CLIENT_KEY_EXCHANGE
Definition: app-layer-ssl.c:229
SSL_AL_FLAG_SERVER_CHANGE_CIPHER_SPEC
#define SSL_AL_FLAG_SERVER_CHANGE_CIPHER_SPEC
Definition: app-layer-ssl.h:96
SCRealloc
#define SCRealloc(ptr, sz)
Definition: util-mem.h:50
HAS_SPACE
#define HAS_SPACE(n)
Definition: app-layer-ssl.c:260
SCAppLayerProtoDetectPPRegister
void SCAppLayerProtoDetectPPRegister(uint8_t ipproto, const char *portstr, AppProto alproto, uint16_t min_depth, uint16_t max_depth, uint8_t direction, ProbingParserFPtr ProbingParser1, ProbingParserFPtr ProbingParser2)
register parser at a port
Definition: app-layer-detect-proto.c:1541
AppLayerParserRegisterGetTx
void AppLayerParserRegisterGetTx(uint8_t ipproto, AppProto alproto, void *(StateGetTx)(void *alstate, uint64_t tx_id))
Definition: app-layer-parser.c:566
TLS_DECODER_EVENT_HANDSHAKE_INVALID_LENGTH
@ TLS_DECODER_EVENT_HANDSHAKE_INVALID_LENGTH
Definition: app-layer-ssl.h:55
SSLDecoderResult
Definition: app-layer-ssl.c:262
APP_LAYER_OK
#define APP_LAYER_OK
Definition: app-layer-parser.h:58
TLS_DECODER_EVENT_CERTIFICATE_INVALID_VERSION
@ TLS_DECODER_EVENT_CERTIFICATE_INVALID_VERSION
Definition: app-layer-ssl.h:64
SSLStateConnp_::random
uint8_t random[TLS_RANDOM_LEN]
Definition: app-layer-ssl.h:192
SSLV3_RECORD_MAX_LEN
#define SSLV3_RECORD_MAX_LEN
Definition: app-layer-ssl.c:247
app-layer-frames.h
SSL_DECODER_ERROR
#define SSL_DECODER_ERROR(e)
Definition: app-layer-ssl.c:266
SSL_AL_FLAG_SSL_CLIENT_HS
#define SSL_AL_FLAG_SSL_CLIENT_HS
Definition: app-layer-ssl.h:102
SCMapEnumValueToName
const char * SCMapEnumValueToName(int enum_value, SCEnumCharMap *table)
Maps an enum value to a string name, from the supplied table.
Definition: util-enum.c:68
SCReturnStruct
#define SCReturnStruct(x)
Definition: util-debug.h:304
ERR_EXTRACT_VALIDITY
@ ERR_EXTRACT_VALIDITY
Definition: app-layer-ssl.c:185
TLS_DECODER_EVENT_INVALID_CERTIFICATE
@ TLS_DECODER_EVENT_INVALID_CERTIFICATE
Definition: app-layer-ssl.h:62
RegisterSSLParsers
void RegisterSSLParsers(void)
Function to register the SSL protocol parser and other functions.
Definition: app-layer-ssl.c:3189
SSLStateConnp_::cert0_subject_len
uint32_t cert0_subject_len
Definition: app-layer-ssl.h:194
SSLV3_CLIENT_HELLO_VERSION_LEN
#define SSLV3_CLIENT_HELLO_VERSION_LEN
Definition: app-layer-ssl.c:249
SCMapEnumNameToValue
int SCMapEnumNameToValue(const char *enum_name, SCEnumCharMap *table)
Maps a string name to an enum value from the supplied table. Please specify the last element of any m...
Definition: util-enum.c:40
SSL_DECODER_OK
#define SSL_DECODER_OK(c)
Definition: app-layer-ssl.c:271
suricata-common.h
TLS_FRAME_PDU
@ TLS_FRAME_PDU
Definition: app-layer-ssl.h:34
SSL_EXTENSION_SESSION_TICKET
#define SSL_EXTENSION_SESSION_TICKET
Definition: app-layer-ssl.h:152
SSL_EXTENSION_SIGNATURE_ALGORITHMS
#define SSL_EXTENSION_SIGNATURE_ALGORITHMS
Definition: app-layer-ssl.h:150
AppLayerTxData::updated_tc
bool updated_tc
Definition: app-layer-parser.h:173
Ja3GenerateHash
char * Ja3GenerateHash(JA3Buffer *buffer)
Definition: util-ja3.c:319
SSL_EXTENSION_EARLY_DATA
#define SSL_EXTENSION_EARLY_DATA
Definition: app-layer-ssl.h:153
SCEnumCharMap_
Definition: util-enum.h:27
SCAppLayerParserRegisterParserAcceptableDataDirection
void SCAppLayerParserRegisterParserAcceptableDataDirection(uint8_t ipproto, AppProto alproto, uint8_t direction)
Definition: app-layer-parser.c:464
version
uint8_t version
Definition: decode-gre.h:1
SSLStateConnp_::content_type
uint8_t content_type
Definition: app-layer-ssl.h:183
SSLSetEvent
#define SSLSetEvent(ssl_state, event)
Definition: app-layer-ssl.c:325
AppLayerParserRegisterStateDataFunc
void AppLayerParserRegisterStateDataFunc(uint8_t ipproto, AppProto alproto, AppLayerStateData *(*GetStateData)(void *state))
Definition: app-layer-parser.c:684
SSLStateConnp_::hs_buffer_message_size
uint32_t hs_buffer_message_size
Definition: app-layer-ssl.h:227
TLS_DECODER_EVENT_CERTIFICATE_INVALID_ALGORITHMIDENTIFIER
@ TLS_DECODER_EVENT_CERTIFICATE_INVALID_ALGORITHMIDENTIFIER
Definition: app-layer-ssl.h:66
SSL_DECODER_INCOMPLETE
#define SSL_DECODER_INCOMPLETE(c, n)
Definition: app-layer-ssl.c:276
AppLayerParserRegisterTxDataFunc
void AppLayerParserRegisterTxDataFunc(uint8_t ipproto, AppProto alproto, AppLayerTxData *(*GetTxData)(void *tx))
Definition: app-layer-parser.c:674
TLS_DECODER_EVENT_INVALID_SNI_TYPE
@ TLS_DECODER_EVENT_INVALID_SNI_TYPE
Definition: app-layer-ssl.h:57
AppLayerFrameNewByPointer
Frame * AppLayerFrameNewByPointer(Flow *f, const StreamSlice *stream_slice, const uint8_t *frame_start, const int64_t len, int dir, uint8_t frame_type)
create new frame using a pointer to start of the frame
Definition: app-layer-frames.c:465
FEATURE_JA4
#define FEATURE_JA4
Definition: feature.h:30
SslConfig_::encrypt_mode
enum SslConfigEncryptHandling encrypt_mode
Definition: app-layer-ssl.c:201
TLS_STATE_CLIENT_CERT_DONE
@ TLS_STATE_CLIENT_CERT_DONE
Definition: app-layer-ssl.h:81
SSLV3_HS_HELLO_REQUEST
#define SSLV3_HS_HELLO_REQUEST
Definition: app-layer-ssl.c:220
app-layer-events.h
SSL_AL_FLAG_CLIENT_CHANGE_CIPHER_SPEC
#define SSL_AL_FLAG_CLIENT_CHANGE_CIPHER_SPEC
Definition: app-layer-ssl.h:98
SSLV3_HS_CERTIFICATE_REQUEST
#define SSLV3_HS_CERTIFICATE_REQUEST
Definition: app-layer-ssl.c:226
util-validate.h
SSL_SNI_TYPE_HOST_NAME
#define SSL_SNI_TYPE_HOST_NAME
Definition: app-layer-ssl.h:157
SCMalloc
#define SCMalloc(sz)
Definition: util-mem.h:47
SCLogConfig
struct SCLogConfig_ SCLogConfig
Holds the config state used by the logging api.
SSLV2_MT_CLIENT_FINISHED
#define SSLV2_MT_CLIENT_FINISHED
Definition: app-layer-ssl.c:238
ssl_config
SslConfig ssl_config
Definition: app-layer-ssl.c:210
SCAppLayerProtoDetectPMRegisterPatternCS
int SCAppLayerProtoDetectPMRegisterPatternCS(uint8_t ipproto, AppProto alproto, const char *pattern, uint16_t depth, uint16_t offset, uint8_t direction)
Registers a case-sensitive pattern for protocol detection.
Definition: app-layer-detect-proto.c:1640
SCConfGetNode
SCConfNode * SCConfGetNode(const char *name)
Get a SCConfNode by name.
Definition: conf.c:184
SCLogError
#define SCLogError(...)
Macro used to log ERROR messages.
Definition: util-debug.h:274
SCFree
#define SCFree(p)
Definition: util-mem.h:61
SCAppLayerProtoDetectPPParseConfPorts
int SCAppLayerProtoDetectPPParseConfPorts(const char *ipproto_name, uint8_t ipproto, const char *alproto_name, AppProto alproto, uint16_t min_depth, uint16_t max_depth, ProbingParserFPtr ProbingParserTs, ProbingParserFPtr ProbingParserTc)
Definition: app-layer-detect-proto.c:1577
SSLSubjectAltName_
Definition: app-layer-ssl.h:168
TLS_STATE_SERVER_IN_PROGRESS
@ TLS_STATE_SERVER_IN_PROGRESS
Definition: app-layer-ssl.h:87
TLS_DECODER_EVENT_CERTIFICATE_INVALID_X509NAME
@ TLS_DECODER_EVENT_CERTIFICATE_INVALID_X509NAME
Definition: app-layer-ssl.h:67
src
uint16_t src
Definition: app-layer-dnp3.h:5
payload_len
uint16_t payload_len
Definition: stream-tcp-private.h:1
SSLV2_MT_ERROR
#define SSLV2_MT_ERROR
Definition: app-layer-ssl.c:235
SSL_AL_FLAG_SSL_SERVER_SSN_ENCRYPTED
#define SSL_AL_FLAG_SSL_SERVER_SSN_ENCRYPTED
Definition: app-layer-ssl.h:106
SSLV3_HANDSHAKE_PROTOCOL
#define SSLV3_HANDSHAKE_PROTOCOL
Definition: app-layer-ssl.c:215
SSLJA4IsEnabled
bool SSLJA4IsEnabled(void)
return whether ja4 is effectively enabled
Definition: app-layer-ssl.c:3370
WARN_UNUSED
#define WARN_UNUSED
Definition: bindgen.h:33
SslConfig_::disable_ja4
bool disable_ja4
Definition: app-layer-ssl.c:207
ALPROTO_UNKNOWN
@ ALPROTO_UNKNOWN
Definition: app-layer-protos.h:29
ALPROTO_FAILED
@ ALPROTO_FAILED
Definition: app-layer-protos.h:33
SSLV3_HS_CLIENT_HELLO
#define SSLV3_HS_CLIENT_HELLO
Definition: app-layer-ssl.c:221
TLS_DECODER_EVENT_CERTIFICATE_INVALID_EXTENSIONS
@ TLS_DECODER_EVENT_CERTIFICATE_INVALID_EXTENSIONS
Definition: app-layer-ssl.h:69
SSLV3_CLIENT_HELLO_RANDOM_LEN
#define SSLV3_CLIENT_HELLO_RANDOM_LEN
Definition: app-layer-ssl.c:250
ProvidesFeature
void ProvidesFeature(const char *feature_name)
Definition: feature.c:106
SslConfig_::SC_ATOMIC_DECLARE
SC_ATOMIC_DECLARE(int, enable_ja4)
app-layer-protos.h
TLS_DECODER_EVENT_INVALID_SNI_LENGTH
@ TLS_DECODER_EVENT_INVALID_SNI_LENGTH
Definition: app-layer-ssl.h:58
ERR_INVALID_DER
@ ERR_INVALID_DER
Definition: app-layer-ssl.c:180
AppLayerParserRegisterGetTxCnt
void AppLayerParserRegisterGetTxCnt(uint8_t ipproto, AppProto alproto, uint64_t(*StateGetTxCnt)(void *alstate))
Definition: app-layer-parser.c:556
SSL_CNF_ENC_HANDLE_BYPASS
@ SSL_CNF_ENC_HANDLE_BYPASS
Definition: app-layer-ssl.c:196
APP_LAYER_ERROR
#define APP_LAYER_ERROR
Definition: app-layer-parser.h:62
SslConfig
struct SslConfig_ SslConfig
SSLStateConnp_::hs
HandshakeParams * hs
Definition: app-layer-ssl.h:221
FEATURE_JA3
#define FEATURE_JA3
Definition: feature.h:29
SSLStateConnp_::cert0_issuerdn_len
uint32_t cert0_issuerdn_len
Definition: app-layer-ssl.h:196
AppLayerParserRegisterGetEventInfoById
void AppLayerParserRegisterGetEventInfoById(uint8_t ipproto, AppProto alproto, int(*StateGetEventInfoById)(uint8_t event_id, const char **event_name, AppLayerEventType *event_type))
Definition: app-layer-parser.c:599
TLS_FRAME_ALERT_DATA
@ TLS_FRAME_ALERT_DATA
Definition: app-layer-ssl.h:37
SSL_AL_FLAG_SSL_NO_SESSION_ID
#define SSL_AL_FLAG_SSL_NO_SESSION_ID
Definition: app-layer-ssl.h:107
TLS_STATE_SERVER_HELLO
@ TLS_STATE_SERVER_HELLO
Definition: app-layer-ssl.h:88
SSLStateConnp_::session_id
char * session_id
Definition: app-layer-ssl.h:209
TLS_FRAME_HDR
@ TLS_FRAME_HDR
Definition: app-layer-ssl.h:35
SC_ATOMIC_GET
#define SC_ATOMIC_GET(name)
Get the value from the atomic variable.
Definition: util-atomic.h:375
dst
uint16_t dst
Definition: app-layer-dnp3.h:4
TLS_DECODER_EVENT_INVALID_ALERT
@ TLS_DECODER_EVENT_INVALID_ALERT
Definition: app-layer-ssl.h:60
SSL_EXTENSION_SNI
#define SSL_EXTENSION_SNI
Definition: app-layer-ssl.h:147
SSLStateConnp_::cert0_fingerprint
char * cert0_fingerprint
Definition: app-layer-ssl.h:201
SSL_RECORD_MINIMUM_LENGTH
#define SSL_RECORD_MINIMUM_LENGTH
Definition: app-layer-ssl.c:256
SSLStateConnp_::sni_len
uint16_t sni_len
Definition: app-layer-ssl.h:207
SSLStateConnp_::ja3_str
JA3Buffer * ja3_str
Definition: app-layer-ssl.h:218
TLS_STATE_SERVER_HANDSHAKE_DONE
@ TLS_STATE_SERVER_HANDSHAKE_DONE
Definition: app-layer-ssl.h:91
SCCalloc
#define SCCalloc(nm, sz)
Definition: util-mem.h:53
ERR_INVALID_EXTENSIONS
@ ERR_INVALID_EXTENSIONS
Definition: app-layer-ssl.c:179
SSLV3_HS_SERVER_HELLO_DONE
#define SSLV3_HS_SERVER_HELLO_DONE
Definition: app-layer-ssl.c:227
util-enum.h
SCReturnInt
#define SCReturnInt(x)
Definition: util-debug.h:288
SCConfNode_
Definition: conf.h:37
SSLStateConnp_::hs_buffer
uint8_t * hs_buffer
Definition: app-layer-ssl.h:225
SCConfNode_::val
char * val
Definition: conf.h:39
ERR_INVALID_VERSION
@ ERR_INVALID_VERSION
Definition: app-layer-ssl.c:174
TLS_STATE_CLIENT_FINISHED
@ TLS_STATE_CLIENT_FINISHED
Definition: app-layer-ssl.h:83
DEBUG_VALIDATE_BUG_ON
#define DEBUG_VALIDATE_BUG_ON(exp)
Definition: util-validate.h:109
app-layer-ssl.h
SSLV3_HS_NEW_SESSION_TICKET
#define SSLV3_HS_NEW_SESSION_TICKET
Definition: app-layer-ssl.c:223
SCAppLayerGetEventIdByName
int SCAppLayerGetEventIdByName(const char *event_name, SCEnumCharMap *table, uint8_t *event_id)
Definition: app-layer-events.c:30
SSL_AL_FLAG_LOG_WITHOUT_CERT
#define SSL_AL_FLAG_LOG_WITHOUT_CERT
Definition: app-layer-ssl.h:129
SSLV3_HS_CERTIFICATE_STATUS
#define SSLV3_HS_CERTIFICATE_STATUS
Definition: app-layer-ssl.c:232
SSL_AL_FLAG_HB_INFLIGHT
#define SSL_AL_FLAG_HB_INFLIGHT
Definition: app-layer-ssl.h:117
SSL_AL_FLAG_SSL_SERVER_HS
#define SSL_AL_FLAG_SSL_SERVER_HS
Definition: app-layer-ssl.h:103
AppLayerTxData::updated_ts
bool updated_ts
Definition: app-layer-parser.h:174
app-layer.h
SSL_CNF_ENC_HANDLE_FULL
@ SSL_CNF_ENC_HANDLE_FULL
Definition: app-layer-ssl.c:197
SSLStateConnp_::cert0_subject
uint8_t * cert0_subject
Definition: app-layer-ssl.h:193
SSLState_::flags
uint32_t flags
Definition: app-layer-ssl.h:244
SSLStateConnp_::version
uint16_t version
Definition: app-layer-ssl.h:182
SSLV3_HS_SERVER_KEY_EXCHANGE
#define SSLV3_HS_SERVER_KEY_EXCHANGE
Definition: app-layer-ssl.c:225
g_disable_hashing
bool g_disable_hashing
Definition: suricata.c:218