150 {
"CERTIFICATE_INVALID_ALGORITHMIDENTIFIER",
186 #define SSL_CONFIG_DEFAULT_JA3 0
188 #define SSL_CONFIG_DEFAULT_JA4 0
210 #define SSLV3_CHANGE_CIPHER_SPEC 20
211 #define SSLV3_ALERT_PROTOCOL 21
212 #define SSLV3_HANDSHAKE_PROTOCOL 22
213 #define SSLV3_APPLICATION_PROTOCOL 23
214 #define SSLV3_HEARTBEAT_PROTOCOL 24
217 #define SSLV3_HS_HELLO_REQUEST 0
218 #define SSLV3_HS_CLIENT_HELLO 1
219 #define SSLV3_HS_SERVER_HELLO 2
220 #define SSLV3_HS_NEW_SESSION_TICKET 4
221 #define SSLV3_HS_CERTIFICATE 11
222 #define SSLV3_HS_SERVER_KEY_EXCHANGE 12
223 #define SSLV3_HS_CERTIFICATE_REQUEST 13
224 #define SSLV3_HS_SERVER_HELLO_DONE 14
225 #define SSLV3_HS_CERTIFICATE_VERIFY 15
226 #define SSLV3_HS_CLIENT_KEY_EXCHANGE 16
227 #define SSLV3_HS_FINISHED 20
228 #define SSLV3_HS_CERTIFICATE_URL 21
229 #define SSLV3_HS_CERTIFICATE_STATUS 22
232 #define SSLV2_MT_ERROR 0
233 #define SSLV2_MT_CLIENT_HELLO 1
234 #define SSLV2_MT_CLIENT_MASTER_KEY 2
235 #define SSLV2_MT_CLIENT_FINISHED 3
236 #define SSLV2_MT_SERVER_HELLO 4
237 #define SSLV2_MT_SERVER_VERIFY 5
238 #define SSLV2_MT_SERVER_FINISHED 6
239 #define SSLV2_MT_REQUEST_CERTIFICATE 7
240 #define SSLV2_MT_CLIENT_CERTIFICATE 8
242 #define SSLV3_RECORD_HDR_LEN 5
244 #define SSLV3_RECORD_MAX_LEN ((1 << 14) + 1024)
246 #define SSLV3_CLIENT_HELLO_VERSION_LEN 2
247 #define SSLV3_CLIENT_HELLO_RANDOM_LEN 32
250 #define TLS_HB_REQUEST 1
251 #define TLS_HB_RESPONSE 2
253 #define SSL_RECORD_MINIMUM_LENGTH 6
255 #define SHA1_STRING_LENGTH 60
257 #define HAS_SPACE(n) ((uint64_t)(input - initial_input) + (uint64_t)(n) <= (uint64_t)(input_len))
263 #define SSL_DECODER_ERROR(e) \
264 (struct SSLDecoderResult) \
268 #define SSL_DECODER_OK(c) \
269 (struct SSLDecoderResult) \
273 #define SSL_DECODER_INCOMPLETE(c, n) \
274 (struct SSLDecoderResult) \
279 static inline int SafeMemcpy(
void *
dst,
size_t dst_offset,
size_t dst_size,
280 const void *
src,
size_t src_offset,
size_t src_size,
size_t src_tocopy)
WARN_UNUSED;
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)
290 if (dst_offset < dst_size && src_offset < src_size &&
291 src_tocopy <= (src_size - src_offset) &&
292 src_tocopy <= (dst_size - dst_offset)) {
293 memcpy(
dst + dst_offset,
src + src_offset, src_tocopy);
299 #ifdef DEBUG_VALIDATION
300 #define ValidateRecordState(connp) \
302 DEBUG_VALIDATE_BUG_ON(((connp)->record_length + SSLV3_RECORD_HDR_LEN) < \
303 (connp)->bytes_processed); \
306 #define ValidateRecordState(...)
309 #define SSLParserHSReset(connp) \
311 (connp)->handshake_type = 0; \
312 (connp)->message_length = 0; \
315 #define SSLParserReset(state) \
317 SCLogDebug("resetting state"); \
318 (state)->curr_connp->bytes_processed = 0; \
319 SSLParserHSReset((state)->curr_connp); \
322 #define SSLSetEvent(ssl_state, event) \
324 SCLogDebug("setting event %u", (event)); \
325 if ((ssl_state) == NULL) { \
326 SCLogDebug("could not set decoder event %u", event); \
328 SCAppLayerDecoderEventsSetEventRaw(&(ssl_state)->tx_data.events, (event)); \
329 (ssl_state)->events++; \
333 static void *SSLGetTx(
void *state, uint64_t tx_id)
339 static uint64_t SSLGetTxCnt(
void *state)
354 SCLogDebug(
"toserver: state updated to %u from %u", s, old);
368 SCLogDebug(
"toclient: state updated to %u from %u", s, old);
373 static int SSLGetAlstateProgress(
void *tx, uint8_t direction)
376 if (direction & STREAM_TOCLIENT) {
395 static void TlsDecodeHSCertificateErrSetEvent(
SSLState *ssl_state, uint32_t err)
438 static inline int TlsDecodeHSCertificateFingerprint(
439 char **out,
const uint8_t *input, uint32_t cert_len)
446 if (SCSha1HashBuffer(input, cert_len, hash,
sizeof(hash)) == 1) {
452 static inline int TlsDecodeHSCertificateAddCertToChain(
453 SSLStateConnp *connp,
const uint8_t *input, uint32_t cert_len)
467 const uint8_t *
const initial_input,
const uint32_t input_len,
const int certn,
468 bool *extract_event_sent)
470 const uint8_t *input = (uint8_t *)initial_input;
471 uint32_t err_code = 0;
477 uint8_t *st_subject = NULL, *st_issuer = NULL, *st_serial = NULL;
479 char *st_fingerprint = NULL;
480 uint32_t st_subject_len = 0, st_issuer_len = 0, st_serial_len = 0;
481 uint16_t st_sans_num = 0;
482 int64_t st_not_before = 0, st_not_after = 0;
487 uint32_t cert_len = *input << 16 | *(input + 1) << 8 | *(input + 2);
496 x509 = SCX509Decode(input, cert_len, &err_code);
501 TlsDecodeHSCertificateErrSetEvent(ssl_state, err_code);
509 SCX509GetSubject(x509, &st_subject, &st_subject_len);
510 if (st_subject == NULL) {
515 SCX509GetIssuer(x509, &st_issuer, &st_issuer_len);
516 if (st_issuer == NULL) {
521 st_sans_num = SCX509GetSubjectAltNameLen(x509);
522 if (st_sans_num == TLS_MAX_SAN && !*extract_event_sent) {
524 *extract_event_sent =
true;
526 if (st_sans_num > 0) {
528 if (st_sans == NULL) {
532 for (uint16_t i = 0; i < st_sans_num; i++) {
533 SCX509GetSubjectAltNameAt(x509, i, &st_sans[i].san, &st_sans[i].san_len);
537 SCX509GetSerial(x509, &st_serial, &st_serial_len);
538 if (st_serial == NULL) {
543 rc = SCX509GetValidity(x509, &st_not_before, &st_not_after);
549 rc = TlsDecodeHSCertificateFingerprint(&st_fingerprint, input, cert_len);
551 SCLogDebug(
"TlsDecodeHSCertificateFingerprint failed with %d", rc);
567 st_subject = st_issuer = st_serial = NULL;
569 st_fingerprint = NULL;
576 rc = TlsDecodeHSCertificateAddCertToChain(connp, input, cert_len);
578 SCLogDebug(
"TlsDecodeHSCertificateAddCertToChain failed with %d", rc);
583 return (
int)(input - initial_input);
586 if (err_code != 0 && !*extract_event_sent) {
589 TlsDecodeHSCertificateErrSetEvent(ssl_state, err_code);
590 *extract_event_sent =
true;
595 if (st_subject != NULL)
596 SCX509ArrayFree(st_subject, st_subject_len);
597 if (st_issuer != NULL)
598 SCX509ArrayFree(st_issuer, st_issuer_len);
599 if (st_serial != NULL)
600 SCX509ArrayFree(st_serial, st_serial_len);
601 if (st_fingerprint != NULL)
603 if (st_sans != NULL) {
604 for (uint16_t i = 0; i < st_sans_num; i++)
605 SCX509ArrayFree(st_sans[i].san, st_sans[i].san_len);
627 const uint8_t *
const initial_input,
const uint32_t input_len)
629 const uint8_t *input = (uint8_t *)initial_input;
634 const uint32_t cert_chain_len = *input << 16 | *(input + 1) << 8 | *(input + 2);
660 uint32_t processed_len = 0;
661 bool cert_failed =
false;
662 bool extract_event_sent =
false;
664 while (processed_len < cert_chain_len) {
665 int rc = TlsDecodeHSCertificate(ssl_state, connp, connp->
certs_buffer + processed_len,
669 if (processed_len + (uint32_t)rc > cert_chain_len) {
672 processed_len += (uint32_t)rc;
679 const uint8_t *cert = connp->
certs_buffer + processed_len;
680 if (processed_len + 3 > cert_chain_len)
682 const uint32_t skip = cert[0] << 16 | cert[1] << 8 | cert[2];
683 if (processed_len + 3 + skip > cert_chain_len)
685 processed_len += 3 + skip;
697 return processed_len + 3;
711 static inline int TLSDecodeValueIsGREASE(
const uint16_t value)
737 static inline int TLSDecodeHSHelloVersion(
SSLState *ssl_state,
738 const uint8_t *
const initial_input,
739 const uint32_t input_len)
741 uint8_t *input = (uint8_t *)initial_input;
750 uint16_t
version = (uint16_t)(*input << 8) | *(input + 1);
792 return (
int)(input - initial_input);
795 static inline int TLSDecodeHSHelloRandom(
SSLState *ssl_state,
796 const uint8_t *
const initial_input,
797 const uint32_t input_len)
799 uint8_t *input = (uint8_t *)initial_input;
819 return (
int)(input - initial_input);
822 static inline int TLSDecodeHSHelloSessionID(
SSLState *ssl_state,
823 const uint8_t *
const initial_input,
824 const uint32_t input_len)
826 uint8_t *input = (uint8_t *)initial_input;
831 uint8_t session_id_length = *input;
845 input, 0, input_len, session_id_length) != 0) {
862 input += session_id_length;
864 return (
int)(input - initial_input);
873 static inline int TLSDecodeHSHelloCipherSuites(
SSLState *ssl_state,
874 const uint8_t *
const initial_input,
875 const uint32_t input_len)
877 const uint8_t *input = initial_input;
882 uint16_t cipher_suites_length;
885 cipher_suites_length = 2;
887 cipher_suites_length = (uint16_t)(*input << 8) | *(input + 1);
897 if ((cipher_suites_length % 2) != 0) {
901 const bool enable_ja3 =
908 if (ja3_cipher_suites == NULL)
912 uint16_t processed_len = 0;
914 while (processed_len < cipher_suites_length) {
922 uint16_t cipher_suite = (uint16_t)(*input << 8) | *(input + 1);
925 if (TLSDecodeValueIsGREASE(cipher_suite) != 1) {
928 SCTLSHandshakeAddCipher(ssl_state->
curr_connp->
hs, cipher_suite);
947 return (
int)(input - initial_input);
956 static inline int TLSDecodeHSHelloCompressionMethods(
SSLState *ssl_state,
957 const uint8_t *
const initial_input,
958 const uint32_t input_len)
960 const uint8_t *input = initial_input;
969 uint8_t compression_methods_length = *input;
972 if (!(
HAS_SPACE(compression_methods_length)))
975 input += compression_methods_length;
978 return (
int)(input - initial_input);
987 static inline int TLSDecodeHSHelloExtensionSni(
SSLState *ssl_state,
988 const uint8_t *
const initial_input,
989 const uint32_t input_len)
991 uint8_t *input = (uint8_t *)initial_input;
1004 goto invalid_length;
1006 uint8_t sni_type = *input;
1019 goto invalid_length;
1021 uint16_t sni_len = (uint16_t)(*input << 8) | *(input + 1);
1027 if (!(
HAS_SPACE(sni_len)) || sni_len > 255 || sni_len == 0) {
1040 return (
int)(input - initial_input);
1048 const size_t consumed = input - initial_input;
1049 if (SafeMemcpy(ssl_state->
curr_connp->
sni, 0, sni_len, initial_input, consumed, input_len,
1057 return (
int)(input - initial_input);
1068 static inline int TLSDecodeHSHelloExtensionSupportedVersions(
SSLState *ssl_state,
1069 const uint8_t *
const initial_input,
1070 const uint32_t input_len)
1072 const uint8_t *input = initial_input;
1080 goto invalid_length;
1082 uint8_t supported_ver_len = *input;
1085 if (supported_ver_len < 2)
1086 goto invalid_length;
1089 goto invalid_length;
1094 while (i + 1 < (uint16_t)supported_ver_len) {
1095 uint16_t ver = (uint16_t)(input[i] << 8) | input[i + 1];
1096 if (TLSVersionValid(ver)) {
1098 SCTLSHandshakeSetTLSVersion(ssl_state->
curr_connp->
hs, ver);
1107 input += supported_ver_len;
1111 goto invalid_length;
1113 uint16_t ver = (uint16_t)(*input << 8) | *(input + 1);
1116 (ver > TLS_VERSION_12)) {
1124 return (
int)(input - initial_input);
1134 static inline int TLSDecodeHSHelloExtensionEllipticCurves(
SSLState *ssl_state,
1135 const uint8_t *
const initial_input,
const uint32_t input_len,
1138 const uint8_t *input = initial_input;
1145 goto invalid_length;
1147 uint16_t elliptic_curves_len = (uint16_t)(*input << 8) | *(input + 1);
1151 goto invalid_length;
1154 *ja3_elliptic_curves != NULL) {
1155 uint16_t ec_processed_len = 0;
1157 while (ec_processed_len < elliptic_curves_len)
1160 goto invalid_length;
1162 uint16_t elliptic_curve = (uint16_t)(*input << 8) | *(input + 1);
1165 if (TLSDecodeValueIsGREASE(elliptic_curve) != 1) {
1171 ec_processed_len += 2;
1176 input += elliptic_curves_len;
1179 return (
int)(input - initial_input);
1189 static inline int TLSDecodeHSHelloExtensionEllipticCurvePF(
SSLState *ssl_state,
1190 const uint8_t *
const initial_input,
const uint32_t input_len,
1193 const uint8_t *input = initial_input;
1200 goto invalid_length;
1202 uint8_t ec_pf_len = *input;
1206 goto invalid_length;
1209 *ja3_elliptic_curves_pf != NULL) {
1210 uint8_t ec_pf_processed_len = 0;
1212 while (ec_pf_processed_len < ec_pf_len)
1214 uint8_t elliptic_curve_pf = *input;
1217 if (TLSDecodeValueIsGREASE(elliptic_curve_pf) != 1) {
1223 ec_pf_processed_len += 1;
1231 return (
int)(input - initial_input);
1241 static inline int TLSDecodeHSHelloExtensionSigAlgorithms(
1242 SSLState *ssl_state,
const uint8_t *
const initial_input,
const uint32_t input_len)
1244 const uint8_t *input = initial_input;
1251 goto invalid_length;
1253 uint16_t sigalgo_len = (uint16_t)(*input << 8) | *(input + 1);
1257 if ((sigalgo_len % 2) != 0) {
1258 goto invalid_length;
1262 goto invalid_length;
1265 uint16_t sigalgo_processed_len = 0;
1266 while (sigalgo_processed_len < sigalgo_len) {
1267 uint16_t sigalgo = (uint16_t)(*input << 8) | *(input + 1);
1269 sigalgo_processed_len += 2;
1271 SCTLSHandshakeAddSigAlgo(ssl_state->
curr_connp->
hs, sigalgo);
1275 input += sigalgo_len;
1278 return (
int)(input - initial_input);
1281 SCLogDebug(
"Signature algorithm list invalid length");
1287 static inline int TLSDecodeHSHelloExtensionALPN(
1288 SSLState *ssl_state,
const uint8_t *
const initial_input,
const uint32_t input_len)
1290 const uint8_t *input = initial_input;
1297 goto invalid_length;
1299 uint16_t alpn_len = (uint16_t)(*input << 8) | *(input + 1);
1303 goto invalid_length;
1307 uint32_t alpn_processed_len = 0;
1308 while (alpn_processed_len < alpn_len) {
1309 uint8_t protolen = *input;
1311 alpn_processed_len += 1;
1314 goto invalid_length;
1318 if (alpn_processed_len + protolen > ((uint32_t)alpn_len)) {
1319 input += alpn_len - alpn_processed_len;
1322 SCTLSHandshakeAddALPN(ssl_state->
curr_connp->
hs, (
const char *)input, protolen);
1324 alpn_processed_len += protolen;
1328 return (
int)(input - initial_input);
1337 static inline int TLSDecodeHSHelloExtensions(
SSLState *ssl_state,
1338 const uint8_t *
const initial_input,
1339 const uint32_t input_len)
1341 const uint8_t *input = initial_input;
1351 JA3Buffer *ja3_elliptic_curves_pf = NULL;
1355 if (ja3_extensions == NULL)
1360 if (ja3_elliptic_curves == NULL)
1364 if (ja3_elliptic_curves_pf == NULL)
1373 uint16_t extensions_len = (uint16_t)(*input << 8) | *(input + 1);
1377 goto invalid_length;
1379 uint32_t processed_len = 0;
1381 while (processed_len < (uint32_t)extensions_len) {
1383 goto invalid_length;
1385 uint16_t ext_type = (uint16_t)(*input << 8) | *(input + 1);
1389 goto invalid_length;
1391 uint16_t ext_len = (uint16_t)(*input << 8) | *(input + 1);
1395 goto invalid_length;
1397 if (processed_len + 4UL + (uint32_t)ext_len > (uint32_t)extensions_len)
1398 goto invalid_length;
1404 ret = TLSDecodeHSHelloExtensionSni(ssl_state, input,
1417 ret = TLSDecodeHSHelloExtensionEllipticCurves(
1418 ssl_state, input, ext_len, &ja3_elliptic_curves);
1430 ret = TLSDecodeHSHelloExtensionEllipticCurvePF(
1431 ssl_state, input, ext_len, &ja3_elliptic_curves_pf);
1442 ret = TLSDecodeHSHelloExtensionSigAlgorithms(ssl_state, input, ext_len);
1453 ret = TLSDecodeHSHelloExtensionALPN(ssl_state, input, ext_len);
1477 ret = TLSDecodeHSHelloExtensionSupportedVersions(ssl_state, input,
1508 if (TLSDecodeValueIsGREASE(ext_type) != 1) {
1517 if (TLSDecodeValueIsGREASE(ext_type) != 1) {
1518 SCTLSHandshakeAddExtension(ssl_state->
curr_connp->
hs, ext_type);
1522 processed_len += (uint32_t)ext_len + 4UL;
1534 &ja3_elliptic_curves);
1539 &ja3_elliptic_curves_pf);
1545 return (
int)(input - initial_input);
1553 if (ja3_extensions != NULL)
1555 if (ja3_elliptic_curves != NULL)
1557 if (ja3_elliptic_curves_pf != NULL)
1563 static int TLSDecodeHandshakeHello(
SSLState *ssl_state,
1564 const uint8_t *
const input,
1565 const uint32_t input_len)
1568 uint32_t parsed = 0;
1574 ret = TLSDecodeHSHelloVersion(ssl_state, input, input_len);
1580 ret = TLSDecodeHSHelloRandom(ssl_state, input + parsed, input_len - parsed);
1591 ret = TLSDecodeHSHelloSessionID(ssl_state, input + parsed,
1592 input_len - parsed);
1599 ret = TLSDecodeHSHelloCipherSuites(ssl_state, input + parsed,
1600 input_len - parsed);
1611 ret = TLSDecodeHSHelloCompressionMethods(ssl_state, input + parsed,
1612 input_len - parsed);
1619 ret = TLSDecodeHSHelloExtensions(ssl_state, input + parsed,
1620 input_len - parsed);
1637 #ifdef DEBUG_VALIDATION
1647 const uint8_t *
const initial_input,
const uint32_t input_len)
1649 int rc = TlsDecodeHSCertificates(ssl_state, connp, initial_input, input_len);
1654 }
else if (rc < 0) {
1655 SCLogDebug(
"error parsing cert, reset state");
1667 static int SupportedHandshakeType(
const uint8_t
type)
1697 static int SSLv3ParseHandshakeType(
SSLState *ssl_state,
const uint8_t *input,
1698 uint32_t input_len, uint8_t direction)
1700 const uint8_t *initial_input = input;
1712 rc = TLSDecodeHandshakeHello(ssl_state, input, input_len);
1724 rc = TLSDecodeHandshakeHello(ssl_state, input, input_len);
1749 rc = SSLv3ParseHandshakeTypeCertificate(ssl_state,
1799 static void SSLv3HandshakePhaseEnter(
SSLState *ssl_state,
const uint8_t hs_type)
1820 static void SSLv3HandshakePhaseLeave(
SSLState *ssl_state,
const uint8_t hs_type)
1834 static int SSLv3ParseHandshakeProtocol(
SSLState *ssl_state,
const uint8_t *input,
1835 uint32_t input_len, uint8_t direction)
1837 const uint8_t *initial_input = input;
1848 SCLogDebug(
"partial handshake record in place");
1851 const uint32_t add =
MIN(need, input_len);
1857 const uint32_t new_size = avail + (4096 - (avail % 4096));
1858 SCLogDebug(
"new_size %u, avail %u", new_size, avail);
1866 SCLogDebug(
"ssl_state->curr_connp->hs_buffer_offset %u "
1867 "ssl_state->curr_connp->hs_buffer_size %u",
1889 SCLogDebug(
"got all data now: handshake_type %u message_length %u",
1922 SCLogDebug(
"input %p input_len %u", input, input_len);
1924 const uint8_t *hs_hdr = input;
1925 if (input_len < 4 || ssl_state->curr_connp->
hs_hdr_len > 0) {
1929 input, 0, input_len, add) != 0) {
1938 return (
int)(input - initial_input);
1951 SCLogDebug(
"handshake_type %u message len %u input %p input_len %u",
1959 SCLogDebug(
"supported_type %s handshake_type %u/%02x", supported_type ?
"true" :
"false",
1961 if (!supported_type) {
1962 uint32_t avail_record_len =
MIN(input_len, record_len);
1963 input += avail_record_len;
1964 input_len -= avail_record_len;
1978 if (record_len > input_len) {
1979 const uint32_t avail = input_len;
1980 const uint32_t size = avail + (4096 - (avail % 4096));
1981 SCLogDebug(
"initial buffer size %u, based on input %u", size, avail);
1990 if (input_len > 0) {
1998 SCLogDebug(
"opened record buffer %p size %u offset %u type %u msg_size %u",
2005 return (
int)(input - initial_input);
2010 int retval = SSLv3ParseHandshakeType(
2012 if (retval < 0 || retval > (
int)input_len) {
2018 SCLogDebug(
"retval %d input_len %u", retval, input_len);
2019 SSLv3HandshakePhaseLeave(ssl_state, full_record_hs_type);
2021 input_len -= retval;
2027 return (
int)(input - initial_input);
2041 static int SSLv3ParseAlertProtocol(
2042 SSLState *ssl_state,
const uint8_t *input, uint32_t input_len, uint8_t direction)
2044 if (input_len < 2) {
2050 if (input_len == 2) {
2051 uint8_t level = input[0];
2074 static int SSLv3ParseHeartbeatProtocol(
SSLState *ssl_state,
const uint8_t *input,
2075 uint32_t input_len, uint8_t direction)
2079 uint32_t padding_len;
2082 if (input_len < 3) {
2099 SCLogDebug(
"HeartBeat Record type sent in the toclient direction!");
2102 SCLogDebug(
"HeartBeat Record type sent in the toserver direction!");
2110 SCLogDebug(
"Encrypted HeartBeat Request In-flight. Storing len %u",
2115 payload_len = (uint16_t)(*input << 8) | *(input + 1);
2120 SCLogDebug(
"We have a short record in HeartBeat Request");
2128 if (padding_len < 16) {
2129 SCLogDebug(
"We have a short record in HeartBeat Request");
2143 SCLogDebug(
"Multiple in-flight server initiated HeartBeats");
2149 SCLogDebug(
"Multiple in-flight client initiated HeartBeats");
2167 SCLogDebug(
"My heart is bleeding.. OpenSSL HeartBleed response (%u)",
2186 static int SSLv3ParseRecord(uint8_t direction,
SSLState *ssl_state,
2187 const uint8_t *input, uint32_t input_len)
2189 const uint8_t *initial_input = input;
2191 if (input_len == 0) {
2195 uint8_t skip_version = 0;
2199 if (direction == 0) {
2213 if (input_len >= 5) {
2215 if (!skip_version) {
2224 if (--input_len == 0)
2230 if (!skip_version) {
2235 if (--input_len == 0)
2240 if (!skip_version) {
2245 if (--input_len == 0)
2251 if (--input_len == 0)
2257 if (--input_len == 0)
2265 return (
int)(input - initial_input);
2268 static int SSLv2ParseRecord(uint8_t direction,
SSLState *ssl_state,
2269 const uint8_t *input, uint32_t input_len)
2271 const uint8_t *initial_input = input;
2273 if (input_len == 0) {
2288 if (--input_len == 0)
2295 if (--input_len == 0)
2302 if (--input_len == 0)
2319 if (--input_len == 0)
2326 if (--input_len == 0)
2333 if (--input_len == 0)
2340 if (--input_len == 0)
2349 return (
int)(input - initial_input);
2356 const uint8_t *initial_input = input;
2358 if (ssl_state->curr_connp->bytes_processed == 0) {
2359 if (input[0] & 0x80) {
2360 ssl_state->curr_connp->record_lengths_length = 2;
2362 ssl_state->curr_connp->record_lengths_length = 3;
2370 SCLogDebug(
"direction %u ssl_state->curr_connp->record_lengths_length + 1 %u, "
2371 "ssl_state->curr_connp->bytes_processed %u",
2372 direction, ssl_state->curr_connp->record_lengths_length + 1,
2373 ssl_state->curr_connp->bytes_processed);
2376 if (ssl_state->curr_connp->bytes_processed <
2377 (ssl_state->curr_connp->record_lengths_length + 1)) {
2378 const int retval = SSLv2ParseRecord(direction, ssl_state, input, input_len);
2380 ssl_state->curr_connp->record_length);
2381 if (retval < 0 || retval > (
int)input_len) {
2388 ssl_state->curr_connp->record_lengths_length + ssl_state->curr_connp->record_length,
2397 if (ssl_state->curr_connp->record_lengths_length + ssl_state->curr_connp->record_length >
2398 input_len + ssl_state->curr_connp->bytes_processed) {
2399 uint32_t
needed = ssl_state->curr_connp->record_length;
2400 SCLogDebug(
"record len %u input_len %u parsed %u: need %u bytes more data",
2401 ssl_state->curr_connp->record_length, input_len, (uint32_t)(input - initial_input),
2406 if (input_len == 0) {
2411 if (ssl_state->curr_connp->record_length == 0) {
2418 if (ssl_state->curr_connp->record_lengths_length == 0) {
2419 SCLogDebug(
"SSLv2 record lengths length is zero");
2424 switch (ssl_state->curr_connp->content_type) {
2426 SCLogDebug(
"SSLV2_MT_ERROR msg_type received. Error encountered "
2427 "in establishing the sslv2 session, may be version");
2438 if (input_len < 6 || ssl_state->curr_connp->
record_length < 7) {
2447 const uint16_t
version = (uint16_t)(input[0] << 8) | input[1];
2449 ssl_state->curr_connp->version =
version;
2450 ssl_state->curr_connp->hello_decoded =
true;
2451 uint16_t session_id_length = (input[5]) | (uint16_t)(input[4] << 8);
2454 ssl_state->curr_connp->bytes_processed += 6;
2455 if (session_id_length == 0) {
2462 SCLogDebug(
"Client hello is not seen before master key "
2470 if (direction == 1) {
2471 SCLogDebug(
"Incorrect SSL Record type sent in the toclient "
2484 if (direction == 0 &&
2485 !(ssl_state->curr_connp->content_type &
2487 SCLogDebug(
"Incorrect SSL Record type sent in the toserver "
2498 if (direction == 0) {
2501 SCLogDebug(
"SSLv2 client side has started the encryption");
2504 SCLogDebug(
"SSLv2 client side has started the encryption");
2508 SCLogDebug(
"SSLv2 Server side has started the encryption");
2522 SCLogDebug(
"SSLv2 No reassembly & inspection has been set");
2531 ssl_state->curr_connp->hello_decoded =
true;
2537 ssl_state->flags |= ssl_state->current_flags;
2539 if (ssl_state->curr_connp->bytes_processed >
2540 ssl_state->curr_connp->record_length + ssl_state->curr_connp->record_lengths_length) {
2541 SCLogDebug(
"SSLv2 bytes_processed (%u) exceeds record+hdr "
2542 "len (record_length=%u, lengths_length=%u)",
2543 ssl_state->curr_connp->bytes_processed, ssl_state->curr_connp->record_length,
2544 ssl_state->curr_connp->record_lengths_length);
2549 if (input_len + ssl_state->curr_connp->bytes_processed >=
2550 (ssl_state->curr_connp->record_length +
2551 ssl_state->curr_connp->record_lengths_length)) {
2554 uint32_t diff = ssl_state->curr_connp->record_length +
2555 ssl_state->curr_connp->record_lengths_length + -
2556 ssl_state->curr_connp->bytes_processed;
2564 ssl_state->curr_connp->bytes_processed += input_len;
2573 uint32_t parsed = 0;
2574 uint32_t record_len;
2575 const bool first_call = (ssl_state->curr_connp->bytes_processed == 0);
2578 const uint16_t prev_version = ssl_state->curr_connp->version;
2580 int retval = SSLv3ParseRecord(direction, ssl_state, input, input_len);
2581 if (retval < 0 || retval > (
int)input_len) {
2589 SCLogDebug(
"%s input %p record_length %u", (direction == 0) ?
"toserver" :
"toclient",
2590 input, ssl_state->curr_connp->record_length);
2603 "incomplete header, return %u bytes consumed and wait for more data", parsed);
2610 record_len =
MIN(input_len - parsed, ssl_state->curr_connp->record_length);
2612 "record_len %u (input_len %u, parsed %u, ssl_state->curr_connp->record_length %u)",
2613 record_len, input_len, parsed, ssl_state->curr_connp->record_length);
2615 bool unknown_record =
false;
2616 switch (ssl_state->curr_connp->content_type) {
2624 unknown_record =
true;
2630 if (prev_version == TLS_VERSION_10 || prev_version == TLS_VERSION_11) {
2631 if (unknown_record) {
2635 ssl_state->curr_connp->bytes_processed = 0;
2636 ssl_state->curr_connp->content_type = 0;
2637 ssl_state->curr_connp->record_length = 0;
2639 ssl_state->curr_connp->version = prev_version;
2643 if (unknown_record) {
2651 if (ssl_state->curr_connp->record_length == 0) {
2657 if (!TLSVersionValid(ssl_state->curr_connp->version)) {
2658 SCLogDebug(
"ssl_state->curr_connp->version %04x", ssl_state->curr_connp->version);
2672 record_len = (ssl_state->curr_connp->record_length +
SSLV3_RECORD_HDR_LEN)- ssl_state->curr_connp->bytes_processed;
2673 record_len =
MIN(input_len, record_len);
2675 SCLogDebug(
"record length %u processed %u got %u",
2676 ssl_state->curr_connp->record_length, ssl_state->curr_connp->bytes_processed, record_len);
2679 if (ssl_state->curr_connp->record_length > input_len - parsed) {
2685 uint32_t
needed = ssl_state->curr_connp->record_length;
2686 SCLogDebug(
"record len %u input_len %u parsed %u: need %u bytes more data",
2687 ssl_state->curr_connp->record_length, input_len, parsed,
needed);
2693 if (record_len == 0) {
2698 ssl_state->curr_connp->record_length, direction,
TLS_FRAME_DATA);
2700 switch (ssl_state->curr_connp->content_type) {
2719 int retval = SSLv3ParseAlertProtocol(ssl_state, input + parsed, record_len, direction);
2737 if (ssl_state->curr_connp == &ssl_state->client_connp) {
2744 SCLogDebug(
"setting APP_LAYER_PARSER_NO_INSPECTION_PAYLOAD");
2751 SCLogDebug(
"setting APP_LAYER_PARSER_NO_REASSEMBLY");
2764 (ssl_state->client_connp.version > TLS_VERSION_12) &&
2773 int retval = SSLv3ParseHandshakeProtocol(ssl_state, input + parsed,
2774 record_len, direction);
2776 if (retval < 0 || retval > (
int)record_len) {
2788 int retval = SSLv3ParseHeartbeatProtocol(ssl_state, input + parsed,
2789 record_len, direction);
2803 parsed += record_len;
2804 ssl_state->curr_connp->bytes_processed += record_len;
2806 if (ssl_state->curr_connp->bytes_processed >=
2810 ssl_state->f, direction == 0 ? STREAM_TOSERVER : STREAM_TOCLIENT);
2847 uint32_t counter = 0;
2849 const uint8_t *input = StreamSliceGetData(&stream_slice);
2850 const uint8_t *init_input = input;
2851 int32_t input_len = (int32_t)StreamSliceGetDataLen(&stream_slice);
2853 if ((input == NULL || input_len == 0) &&
2863 }
else if (input == NULL || input_len == 0) {
2879 while (input_len > 0) {
2880 if (counter > max_records) {
2881 SCLogDebug(
"Looks like we have looped quite a bit. Reset state "
2882 "and get out of here");
2893 if ((input[0] & 0x80) || (input[0] & 0x40)) {
2902 SCLogDebug(
"record %u: bytes_processed %u, version %02X, input_len %u", counter,
2909 SCLogDebug(
"Continuing parsing SSLv2 record");
2912 SSLv2Decode(direction, ssl_state, pstate, input, input_len, stream_slice);
2915 SCLogDebug(
"Error parsing SSLv2. Resetting parser "
2916 "state. Let's get outta here");
2923 SCLogDebug(
"returning consumed %" PRIuMAX
" needed %u",
2924 (uintmax_t)(input - init_input), r.
needed);
2929 SCLogDebug(
"SSLv2 decoder consumed %d bytes: %u left", r.
retval, input_len);
2932 SCLogDebug(
"New TLS record: record_length %u",
2935 SCLogDebug(
"Continuing parsing TLS record: record_length %u, bytes_processed %u",
2939 SSLv3Decode(direction, ssl_state, pstate, input, input_len, stream_slice);
2942 SCLogDebug(
"Error parsing TLS. Resetting parser "
2943 "state. Let's get outta here");
2948 SCLogDebug(
"returning consumed %" PRIuMAX
" needed %u",
2949 (uintmax_t)(input - init_input), r.
needed);
3030 static bool TlsConnpLogReady(
const SSLStateConnp *connp,
const uint8_t track_done)
3042 if (!TlsConnpLogReady(
3047 if (!TlsConnpLogReady(
3051 }
else if ((ssl_state->
flags &
3064 return SSLDecode(
f, 0 , alstate, pstate, stream_slice);
3070 return SSLDecode(
f, 1 , alstate, pstate, stream_slice);
3077 static void *SSLStateAlloc(
void *orig_state,
AppProto proto_orig)
3085 return (
void *)ssl_state;
3102 static void SSLStateFree(
void *
p)
3181 static void SSLStateTransactionFree(
void *state, uint64_t tx_id)
3187 const Flow *
f, uint8_t direction,
const uint8_t *input, uint32_t ilen, uint8_t *rdir)
3195 if ((input[0] & 0x80) && (input[2] == 0x01)) {
3202 static int SSLStateGetStateIdByName(
const char *
name,
const uint8_t direction)
3205 direction == STREAM_TOSERVER ? tls_state_client_table : tls_state_server_table;
3214 static const char *SSLStateGetStateNameById(
const int id,
const uint8_t direction)
3217 direction == STREAM_TOSERVER ? tls_state_client_table : tls_state_server_table;
3222 static int SSLStateGetFrameIdByName(
const char *frame_name)
3231 static const char *SSLStateGetFrameNameById(
const uint8_t frame_id)
3237 static int SSLStateGetEventInfo(
3247 static int SSLStateGetEventInfoById(
3251 if (*event_name == NULL) {
3253 "ssl's enum map table.",
3264 static int SSLRegisterPatternsForProtocolDetection(
void)
3267 STREAM_TOSERVER, SSLProbingParser, 0, 3) < 0) {
3273 IPPROTO_TCP,
ALPROTO_TLS,
"|01 03 00|", 3, 0, STREAM_TOSERVER) < 0) {
3277 IPPROTO_TCP,
ALPROTO_TLS,
"|16 03 00|", 3, 0, STREAM_TOSERVER) < 0) {
3283 IPPROTO_TCP,
ALPROTO_TLS,
"|01 03 01|", 3, 0, STREAM_TOSERVER) < 0) {
3287 IPPROTO_TCP,
ALPROTO_TLS,
"|16 03 01|", 3, 0, STREAM_TOSERVER) < 0) {
3293 IPPROTO_TCP,
ALPROTO_TLS,
"|01 03 02|", 3, 0, STREAM_TOSERVER) < 0) {
3297 IPPROTO_TCP,
ALPROTO_TLS,
"|16 03 02|", 3, 0, STREAM_TOSERVER) < 0) {
3303 IPPROTO_TCP,
ALPROTO_TLS,
"|01 03 03|", 3, 0, STREAM_TOSERVER) < 0) {
3307 IPPROTO_TCP,
ALPROTO_TLS,
"|16 03 03|", 3, 0, STREAM_TOSERVER) < 0) {
3314 IPPROTO_TCP,
ALPROTO_TLS,
"|15 03 00|", 3, 0, STREAM_TOCLIENT) < 0) {
3318 IPPROTO_TCP,
ALPROTO_TLS,
"|16 03 00|", 3, 0, STREAM_TOCLIENT) < 0) {
3322 IPPROTO_TCP,
ALPROTO_TLS,
"|17 03 00|", 3, 0, STREAM_TOCLIENT) < 0) {
3328 IPPROTO_TCP,
ALPROTO_TLS,
"|15 03 01|", 3, 0, STREAM_TOCLIENT) < 0) {
3332 IPPROTO_TCP,
ALPROTO_TLS,
"|16 03 01|", 3, 0, STREAM_TOCLIENT) < 0) {
3336 IPPROTO_TCP,
ALPROTO_TLS,
"|17 03 01|", 3, 0, STREAM_TOCLIENT) < 0) {
3342 IPPROTO_TCP,
ALPROTO_TLS,
"|15 03 02|", 3, 0, STREAM_TOCLIENT) < 0) {
3346 IPPROTO_TCP,
ALPROTO_TLS,
"|16 03 02|", 3, 0, STREAM_TOCLIENT) < 0) {
3350 IPPROTO_TCP,
ALPROTO_TLS,
"|17 03 02|", 3, 0, STREAM_TOCLIENT) < 0) {
3356 IPPROTO_TCP,
ALPROTO_TLS,
"|15 03 03|", 3, 0, STREAM_TOCLIENT) < 0) {
3360 IPPROTO_TCP,
ALPROTO_TLS,
"|16 03 03|", 3, 0, STREAM_TOCLIENT) < 0) {
3364 IPPROTO_TCP,
ALPROTO_TLS,
"|17 03 03|", 3, 0, STREAM_TOCLIENT) < 0) {
3374 "|01 03 00|", 5, 2, STREAM_TOSERVER) < 0)
3379 "|00 02|", 7, 5, STREAM_TOCLIENT) < 0)
3389 static void CheckJA3Enabled(
void)
3391 const char *strval = NULL;
3394 if (
SCConfGetNonNull(
"app-layer.protocols.tls.ja3-fingerprints", &strval) != 1) {
3396 }
else if (strcmp(strval,
"auto") == 0) {
3414 static void CheckJA4Enabled(
void)
3416 const char *strval = NULL;
3418 int enable_ja4 = SSL_CONFIG_DEFAULT_JA4;
3419 if (
SCConfGetNonNull(
"app-layer.protocols.tls.ja4-fingerprints", &strval) != 1) {
3420 enable_ja4 = SSL_CONFIG_DEFAULT_JA4;
3421 }
else if (strcmp(strval,
"auto") == 0) {
3422 enable_ja4 = SSL_CONFIG_DEFAULT_JA4;
3447 const char *proto_name =
"tls";
3455 if (SSLRegisterPatternsForProtocolDetection() < 0)
3460 IPPROTO_TCP,
"443",
ALPROTO_TLS, 0, 3, STREAM_TOSERVER, SSLProbingParser, NULL);
3463 0, 3, SSLProbingParser, NULL) == 0) {
3465 "enabling TLS detection on port 443.");
3467 STREAM_TOSERVER, SSLProbingParser, NULL);
3471 SCLogConfig(
"Protocol detection and parser disabled for %s protocol",
3478 SSLParseClientRecord);
3481 SSLParseServerRecord);
3483 IPPROTO_TCP,
ALPROTO_TLS, SSLStateGetStateIdByName, SSLStateGetStateNameById);
3485 IPPROTO_TCP,
ALPROTO_TLS, SSLStateGetFrameIdByName, SSLStateGetFrameNameById);
3513 if (enc_handle != NULL && enc_handle->
val != NULL) {
3514 SCLogDebug(
"have app-layer.protocols.tls.encryption-handling = %s", enc_handle->
val);
3515 if (strcmp(enc_handle->
val,
"full") == 0) {
3517 }
else if (strcmp(enc_handle->
val,
"bypass") == 0) {
3519 }
else if (strcmp(enc_handle->
val,
"track-only") == 0) {
3521 }
else if (strcmp(enc_handle->
val,
"default") == 0) {
3522 SCLogWarning(
"app-layer.protocols.tls.encryption-handling = default is deprecated "
3523 "and will be removed in Suricata 9, use \"track-only\" instead, "
3524 "(see ticket #7642)");
3531 if (
SCConfGetNode(
"app-layer.protocols.tls.no-reassemble") == NULL) {
3533 if (
SCConfGetBool(
"tls.no-reassemble", &value) == 1 && value == 1)
3537 if (
SCConfGetBool(
"app-layer.protocols.tls.no-reassemble", &value) == 1 &&
3553 SCLogWarning(
"MD5 calculation has been disabled, disabling JA3");
3557 SCLogWarning(
"Hashing has been disabled, disabling JA4");
3571 SCLogConfig(
"Parser disabled for %s protocol. Protocol detection still on.", proto_name);
3637 static int TLSPhaseStateTestClient(
void)
3639 const char *names[] = {
"client_started",
"client_hello",
"client_cert",
"client_data",
3640 "client_finished" };
3641 for (
int i = 0; i < 5; i++) {
3643 IPPROTO_TCP,
ALPROTO_TLS, names[i], STREAM_TOSERVER) != i);
3650 static int TLSPhaseStateTestServer(
void)
3652 const char *names[] = {
"server_started",
"server_hello",
"server_cert",
"server_data",
3653 "server_finished" };
3654 for (
int i = 0; i < 5; i++) {
3656 IPPROTO_TCP,
ALPROTO_TLS, names[i], STREAM_TOCLIENT) != i);
3663 static int TLSPhaseStateTestOldNamesGone(
void)
3665 const char *old_client[] = {
"client_in_progress",
"client_hello_done",
"client_cert_done",
3666 "client_handshake_done" };
3667 const char *old_server[] = {
"server_in_progress",
"server_hello_done",
"server_cert_done",
3668 "server_handshake_done" };
3669 for (
int i = 0; i < 4; i++) {
3671 IPPROTO_TCP,
ALPROTO_TLS, old_client[i], STREAM_TOSERVER) >= 0);
3673 IPPROTO_TCP,
ALPROTO_TLS, old_server[i], STREAM_TOCLIENT) >= 0);
3678 static int TLSPhaseStateTestCompletion(
void)
3691 SSLStateFree(ssl_state);
3700 static int TLSPhaseSuppressionTest(
void)
3703 if (ssl_state == NULL)
3708 const uint8_t p4[] = { 0x01, 0x00, 0x00, 0x06, 0x03, 0x03, 0x01, 0x02, 0x03, 0x04 };
3711 uint8_t p5[4 + 2 + 32 + 1 + 1 + 2 + 1];
3721 for (i = 0; i < 32; i++)
3722 p5[6 + i] = (uint8_t)i;
3729 const uint8_t p6[] = { 0x0b, 0x00, 0x00, 0x10, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x0a, 0x41, 0x41,
3730 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41 };
3738 rc = SSLv3ParseHandshakeProtocol(ssl_state, p4,
sizeof(p4), 0);
3749 rc = SSLv3ParseHandshakeProtocol(ssl_state, p5,
sizeof(p5), 1);
3763 rc = SSLv3ParseHandshakeProtocol(ssl_state, p6,
sizeof(p6), 1);
3770 SSLStateFree(ssl_state);
3784 static int TLSPhaseCertChainSkipTest(
void)
3786 static const uint8_t valid_cert[] = { 0x30, 0x82, 0x03, 0x0b, 0x30, 0x82, 0x01, 0xf3, 0xa0,
3787 0x03, 0x02, 0x01, 0x02, 0x02, 0x14, 0x16, 0x1b, 0x77, 0xa9, 0xae, 0xe9, 0xea, 0xaa, 0x2d,
3788 0xf9, 0xbb, 0xd6, 0xda, 0x13, 0x92, 0xf8, 0x73, 0xf8, 0x93, 0xa0, 0x30, 0x0d, 0x06, 0x09,
3789 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30, 0x15, 0x31, 0x13,
3790 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0a, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74,
3791 0x74, 0x65, 0x73, 0x74, 0x30, 0x1e, 0x17, 0x0d, 0x32, 0x36, 0x30, 0x39, 0x31, 0x38, 0x30,
3792 0x33, 0x34, 0x38, 0x35, 0x36, 0x5a, 0x17, 0x0d, 0x32, 0x36, 0x30, 0x39, 0x32, 0x30, 0x30,
3793 0x33, 0x34, 0x38, 0x35, 0x36, 0x5a, 0x30, 0x15, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55,
3794 0x04, 0x03, 0x0c, 0x0a, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x74, 0x65, 0x73, 0x74, 0x30,
3795 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01,
3796 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00, 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01,
3797 0x01, 0x00, 0xc7, 0xdc, 0x32, 0x3c, 0x76, 0x5d, 0x86, 0x02, 0xbd, 0x3e, 0xc0, 0x8e, 0x6f,
3798 0x34, 0x7e, 0xa2, 0x2c, 0x66, 0xe4, 0x20, 0x2f, 0x1c, 0xf4, 0x6c, 0x4d, 0xb6, 0x8e, 0xed,
3799 0x5c, 0xdf, 0x36, 0xdb, 0xa8, 0xea, 0xf9, 0x01, 0xbe, 0x20, 0x92, 0x85, 0x72, 0x9c, 0x5d,
3800 0x19, 0xf5, 0xa1, 0xa6, 0xdf, 0x60, 0x17, 0xc3, 0xba, 0xb7, 0xed, 0x57, 0x99, 0x19, 0x46,
3801 0xee, 0xb2, 0x04, 0xfe, 0x18, 0x17, 0x65, 0x62, 0xe2, 0xd7, 0x45, 0xb1, 0x0f, 0x0c, 0xc8,
3802 0x6b, 0xe4, 0x63, 0x4a, 0x6b, 0xd9, 0x30, 0xae, 0xf5, 0x81, 0xc5, 0xac, 0x50, 0x51, 0xc6,
3803 0x91, 0x5c, 0x78, 0xc0, 0x74, 0x2a, 0x47, 0x6b, 0xae, 0xc3, 0x4b, 0x7d, 0x54, 0x66, 0x0d,
3804 0xd7, 0xa1, 0x81, 0x07, 0x80, 0x44, 0xba, 0x30, 0x02, 0xeb, 0x82, 0x3c, 0x78, 0xbb, 0x9f,
3805 0x2b, 0xeb, 0x1b, 0x1c, 0x30, 0x41, 0x02, 0xeb, 0xf5, 0x9c, 0xb3, 0xef, 0x43, 0x52, 0x4b,
3806 0x54, 0x1f, 0xf3, 0x0d, 0xeb, 0xcc, 0x25, 0x97, 0xda, 0x52, 0x07, 0xdf, 0x54, 0x35, 0x4b,
3807 0x85, 0x63, 0x67, 0xd6, 0x60, 0x9f, 0x0f, 0x88, 0xbf, 0x7e, 0xc9, 0x44, 0x2f, 0x34, 0xd6,
3808 0x28, 0xad, 0x2d, 0x59, 0x7e, 0x56, 0xb6, 0x73, 0x5a, 0xe0, 0xb0, 0x1c, 0xc9, 0x23, 0x5f,
3809 0x2a, 0x3c, 0x46, 0x1c, 0x27, 0x7f, 0x0e, 0x25, 0x16, 0x19, 0xb0, 0x03, 0x71, 0x05, 0xd5,
3810 0xc6, 0xed, 0x49, 0x7c, 0x90, 0xca, 0x94, 0xfb, 0xe4, 0x75, 0x23, 0x67, 0x17, 0x37, 0x08,
3811 0x05, 0xb8, 0x58, 0x7f, 0x61, 0x16, 0x24, 0x91, 0xeb, 0x0c, 0x1c, 0x05, 0x0d, 0xa5, 0x45,
3812 0x55, 0x03, 0x2e, 0x60, 0x15, 0xc4, 0x6b, 0xcb, 0x68, 0x1f, 0xec, 0xbe, 0x59, 0xbf, 0x4a,
3813 0x93, 0x0b, 0xa3, 0x08, 0x86, 0xe0, 0xe9, 0x5c, 0x08, 0x23, 0x3b, 0x0f, 0xbd, 0xc9, 0x91,
3814 0xa1, 0x48, 0xf9, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x53, 0x30, 0x51, 0x30, 0x1d, 0x06,
3815 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0xae, 0xed, 0xef, 0x6c, 0xe0, 0xf6, 0xb7,
3816 0xe3, 0x8c, 0xd9, 0x37, 0x7f, 0x0b, 0x53, 0x36, 0x96, 0x06, 0x5d, 0x0f, 0x09, 0x30, 0x1f,
3817 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, 0x14, 0xae, 0xed, 0xef, 0x6c,
3818 0xe0, 0xf6, 0xb7, 0xe3, 0x8c, 0xd9, 0x37, 0x7f, 0x0b, 0x53, 0x36, 0x96, 0x06, 0x5d, 0x0f,
3819 0x09, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x01, 0x01, 0xff, 0x04, 0x05, 0x30, 0x03,
3820 0x01, 0x01, 0xff, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01,
3821 0x0b, 0x05, 0x00, 0x03, 0x82, 0x01, 0x01, 0x00, 0x08, 0x2e, 0x15, 0x02, 0x17, 0xcb, 0xf8,
3822 0x5b, 0x4b, 0x31, 0x47, 0xf4, 0x8d, 0x55, 0x53, 0xa4, 0x05, 0x46, 0x73, 0xb7, 0x6a, 0x79,
3823 0xfc, 0x02, 0xe4, 0x89, 0x09, 0xb9, 0x3d, 0x8c, 0xda, 0x98, 0x0d, 0x67, 0x83, 0x30, 0x00,
3824 0xe5, 0x3b, 0xc4, 0x7c, 0xc4, 0x63, 0xa7, 0x20, 0x97, 0x74, 0x8d, 0x18, 0xfa, 0xb1, 0xe7,
3825 0x67, 0x13, 0x48, 0x55, 0x99, 0xde, 0xca, 0x70, 0xe4, 0x7a, 0x3a, 0x65, 0x28, 0x08, 0xce,
3826 0xc3, 0x93, 0xbb, 0x95, 0x15, 0x10, 0x25, 0x67, 0x7a, 0xad, 0xe8, 0xbc, 0xfb, 0xee, 0x94,
3827 0xfa, 0x09, 0x6a, 0x3e, 0xa6, 0xb9, 0x9b, 0xd7, 0x01, 0xe4, 0x4f, 0x53, 0x69, 0x92, 0x8a,
3828 0xf4, 0x52, 0xbf, 0x44, 0xfd, 0x26, 0x80, 0xb3, 0xed, 0x9d, 0x25, 0xa8, 0x99, 0x24, 0x1e,
3829 0xd7, 0x29, 0xde, 0xa3, 0x08, 0x63, 0x44, 0x2a, 0xb9, 0x94, 0x19, 0x73, 0xb9, 0xf3, 0xee,
3830 0x67, 0xc1, 0x81, 0xdd, 0x78, 0x2f, 0x8c, 0x1d, 0x7e, 0xb5, 0x06, 0x97, 0x24, 0x60, 0xfb,
3831 0x27, 0xf1, 0x4d, 0x85, 0x2d, 0x1e, 0x8c, 0x13, 0x95, 0x2b, 0x5c, 0x12, 0x3a, 0xe3, 0x31,
3832 0x55, 0x07, 0xdd, 0xf2, 0x85, 0xc5, 0x2e, 0x28, 0x2a, 0x9b, 0x3a, 0x89, 0xef, 0xd6, 0xba,
3833 0x00, 0x55, 0xc2, 0x61, 0x74, 0xaf, 0xcc, 0xfd, 0x44, 0x7c, 0xae, 0xd8, 0xbb, 0xa7, 0xb7,
3834 0x93, 0xc1, 0x3a, 0x0d, 0xef, 0x7e, 0x14, 0x67, 0x3a, 0x0b, 0x62, 0x57, 0x5e, 0x78, 0x58,
3835 0x5c, 0x63, 0x2b, 0x79, 0x2d, 0x81, 0x61, 0x4d, 0xd2, 0xdb, 0x41, 0xe9, 0xbd, 0x00, 0xc8,
3836 0x26, 0xd3, 0xea, 0x6b, 0x10, 0xa9, 0x8e, 0xab, 0x64, 0x85, 0x6a, 0x55, 0xc1, 0x78, 0x65,
3837 0x31, 0x9b, 0x4d, 0x44, 0x84, 0xea, 0x60, 0x15, 0x52, 0x6b, 0x9d, 0x4b, 0x14, 0x5c, 0xba,
3838 0x4f, 0xa2, 0x53, 0x8f, 0x2a, 0x2c, 0xda, 0x36, 0x96
3844 const uint32_t bad_len = 10;
3845 const uint32_t good_len =
sizeof(valid_cert);
3846 const uint32_t chain_len = 3 + bad_len + 3 + good_len;
3847 const uint32_t hs_len = 3 + chain_len;
3848 const uint32_t msg_len = 4 + 3 + 3 + bad_len + 3 + good_len;
3849 uint8_t msg[msg_len];
3853 msg[2] = (hs_len >> 8) & 0xff;
3854 msg[3] = hs_len & 0xff;
3856 msg[5] = (chain_len >> 8) & 0xff;
3857 msg[6] = chain_len & 0xff;
3861 for (uint32_t k = 0; k < bad_len; k++)
3863 const uint32_t off = 10 + bad_len;
3865 msg[off + 1] = (good_len >> 8) & 0xff;
3866 msg[off + 2] = good_len & 0xff;
3867 memcpy(msg + off + 3, valid_cert, good_len);
3870 if (ssl_state == NULL)
3884 int rc = SSLv3ParseHandshakeProtocol(ssl_state, msg, msg_len, 1);
3900 X509 *ref = SCX509Decode(valid_cert,
sizeof(valid_cert), &errc);
3902 uint8_t *subj = NULL;
3903 uint32_t subj_len = 0;
3904 uint8_t *iss = NULL;
3905 uint32_t iss_len = 0;
3906 SCX509GetSubject(ref, &subj, &subj_len);
3907 SCX509GetIssuer(ref, &iss, &iss_len);
3908 FAIL_IF(subj == NULL || iss == NULL);
3914 SCX509ArrayFree(subj, subj_len);
3916 SCX509ArrayFree(iss, iss_len);
3924 const uint8_t shd[] = { 0x0e, 0x00, 0x00, 0x00 };
3928 rc = SSLv3ParseHandshakeProtocol(ssl_state, shd,
sizeof(shd), 1);
3939 const uint32_t mlen = 4 + 3 + 3 +
sizeof(valid_cert);
3941 memset(full, 0,
sizeof(full));
3943 full[1] = ((3 + 3 + good_len) >> 16) & 0xff;
3944 full[2] = ((3 + 3 + good_len) >> 8) & 0xff;
3945 full[3] = (3 + 3 + good_len) & 0xff;
3946 full[4] = ((3 + good_len) >> 16) & 0xff;
3947 full[5] = ((3 + good_len) >> 8) & 0xff;
3948 full[6] = (3 + good_len) & 0xff;
3949 full[7] = (good_len >> 16) & 0xff;
3950 full[8] = (good_len >> 8) & 0xff;
3951 full[9] = good_len & 0xff;
3952 memcpy(full + 10, valid_cert, good_len);
3956 rc = SSLv3ParseHandshakeProtocol(ssl_state, full, mlen, 0);
3969 rc = SSLv3ParseHandshakeProtocol(ssl_state, full, mlen, 1);
3973 SSLStateFree(ssl_state);
3983 static int TLSPhaseWrongDirectionKeyxTest(
void)
3986 if (ssl_state == NULL)
3990 const uint8_t ckx[] = { 0x10, 0x00, 0x00, 0x00 };
3994 int rc = SSLv3ParseHandshakeProtocol(ssl_state, ckx,
sizeof(ckx), 1);
3999 const uint8_t certreq[] = { 0x0d, 0x00, 0x00, 0x00 };
4003 rc = SSLv3ParseHandshakeProtocol(ssl_state, certreq,
sizeof(certreq), 1);
4014 rc = SSLv3ParseHandshakeProtocol(client_ckx, ckx,
sizeof(ckx), 0);
4018 SSLStateFree(ssl_state);
4019 SSLStateFree(client_ckx);
4025 UtRegisterTest(
"TLSPhaseStateTestClient", TLSPhaseStateTestClient);
4026 UtRegisterTest(
"TLSPhaseStateTestServer", TLSPhaseStateTestServer);
4027 UtRegisterTest(
"TLSPhaseStateTestOldNamesGone", TLSPhaseStateTestOldNamesGone);
4028 UtRegisterTest(
"TLSPhaseStateTestCompletion", TLSPhaseStateTestCompletion);
4029 UtRegisterTest(
"TLSPhaseSuppressionTest", TLSPhaseSuppressionTest);
4030 UtRegisterTest(
"TLSPhaseCertChainSkipTest", TLSPhaseCertChainSkipTest);
4031 UtRegisterTest(
"TLSPhaseWrongDirectionKeyxTest", TLSPhaseWrongDirectionKeyxTest);