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 if (input_len < 4) {
1933 SCLogDebug(
"handshake_type %u message len %u input %p input_len %u",
1943 SCLogDebug(
"supported_type %s handshake_type %u/%02x", supported_type ?
"true" :
"false",
1945 if (!supported_type) {
1946 uint32_t avail_record_len =
MIN(input_len, record_len);
1947 input += avail_record_len;
1948 input_len -= avail_record_len;
1962 if (record_len > input_len) {
1963 const uint32_t avail = input_len;
1964 const uint32_t size = avail + (4096 - (avail % 4096));
1965 SCLogDebug(
"initial buffer size %u, based on input %u", size, avail);
1974 if (input_len > 0) {
1982 SCLogDebug(
"opened record buffer %p size %u offset %u type %u msg_size %u",
1989 return (
int)(input - initial_input);
1994 int retval = SSLv3ParseHandshakeType(
1996 if (retval < 0 || retval > (
int)input_len) {
2002 SCLogDebug(
"retval %d input_len %u", retval, input_len);
2003 SSLv3HandshakePhaseLeave(ssl_state, full_record_hs_type);
2005 input_len -= retval;
2011 return (
int)(input - initial_input);
2025 static int SSLv3ParseAlertProtocol(
2026 SSLState *ssl_state,
const uint8_t *input, uint32_t input_len, uint8_t direction)
2028 if (input_len < 2) {
2034 if (input_len == 2) {
2035 uint8_t level = input[0];
2058 static int SSLv3ParseHeartbeatProtocol(
SSLState *ssl_state,
const uint8_t *input,
2059 uint32_t input_len, uint8_t direction)
2063 uint32_t padding_len;
2066 if (input_len < 3) {
2083 SCLogDebug(
"HeartBeat Record type sent in the toclient direction!");
2086 SCLogDebug(
"HeartBeat Record type sent in the toserver direction!");
2094 SCLogDebug(
"Encrypted HeartBeat Request In-flight. Storing len %u",
2099 payload_len = (uint16_t)(*input << 8) | *(input + 1);
2104 SCLogDebug(
"We have a short record in HeartBeat Request");
2112 if (padding_len < 16) {
2113 SCLogDebug(
"We have a short record in HeartBeat Request");
2127 SCLogDebug(
"Multiple in-flight server initiated HeartBeats");
2133 SCLogDebug(
"Multiple in-flight client initiated HeartBeats");
2151 SCLogDebug(
"My heart is bleeding.. OpenSSL HeartBleed response (%u)",
2170 static int SSLv3ParseRecord(uint8_t direction,
SSLState *ssl_state,
2171 const uint8_t *input, uint32_t input_len)
2173 const uint8_t *initial_input = input;
2175 if (input_len == 0) {
2179 uint8_t skip_version = 0;
2183 if (direction == 0) {
2197 if (input_len >= 5) {
2199 if (!skip_version) {
2208 if (--input_len == 0)
2214 if (!skip_version) {
2219 if (--input_len == 0)
2224 if (!skip_version) {
2229 if (--input_len == 0)
2235 if (--input_len == 0)
2241 if (--input_len == 0)
2249 return (
int)(input - initial_input);
2252 static int SSLv2ParseRecord(uint8_t direction,
SSLState *ssl_state,
2253 const uint8_t *input, uint32_t input_len)
2255 const uint8_t *initial_input = input;
2257 if (input_len == 0) {
2272 if (--input_len == 0)
2279 if (--input_len == 0)
2286 if (--input_len == 0)
2303 if (--input_len == 0)
2310 if (--input_len == 0)
2317 if (--input_len == 0)
2324 if (--input_len == 0)
2333 return (
int)(input - initial_input);
2340 const uint8_t *initial_input = input;
2342 if (ssl_state->curr_connp->bytes_processed == 0) {
2343 if (input[0] & 0x80) {
2344 ssl_state->curr_connp->record_lengths_length = 2;
2346 ssl_state->curr_connp->record_lengths_length = 3;
2354 SCLogDebug(
"direction %u ssl_state->curr_connp->record_lengths_length + 1 %u, "
2355 "ssl_state->curr_connp->bytes_processed %u",
2356 direction, ssl_state->curr_connp->record_lengths_length + 1,
2357 ssl_state->curr_connp->bytes_processed);
2360 if (ssl_state->curr_connp->bytes_processed <
2361 (ssl_state->curr_connp->record_lengths_length + 1)) {
2362 const int retval = SSLv2ParseRecord(direction, ssl_state, input, input_len);
2364 ssl_state->curr_connp->record_length);
2365 if (retval < 0 || retval > (
int)input_len) {
2372 ssl_state->curr_connp->record_lengths_length + ssl_state->curr_connp->record_length,
2381 if (ssl_state->curr_connp->record_lengths_length + ssl_state->curr_connp->record_length >
2382 input_len + ssl_state->curr_connp->bytes_processed) {
2383 uint32_t
needed = ssl_state->curr_connp->record_length;
2384 SCLogDebug(
"record len %u input_len %u parsed %u: need %u bytes more data",
2385 ssl_state->curr_connp->record_length, input_len, (uint32_t)(input - initial_input),
2390 if (input_len == 0) {
2395 if (ssl_state->curr_connp->record_length == 0) {
2402 if (ssl_state->curr_connp->record_lengths_length == 0) {
2403 SCLogDebug(
"SSLv2 record lengths length is zero");
2408 switch (ssl_state->curr_connp->content_type) {
2410 SCLogDebug(
"SSLV2_MT_ERROR msg_type received. Error encountered "
2411 "in establishing the sslv2 session, may be version");
2422 if (input_len < 6 || ssl_state->curr_connp->
record_length < 7) {
2431 const uint16_t
version = (uint16_t)(input[0] << 8) | input[1];
2433 ssl_state->curr_connp->version =
version;
2434 ssl_state->curr_connp->hello_decoded =
true;
2435 uint16_t session_id_length = (input[5]) | (uint16_t)(input[4] << 8);
2438 ssl_state->curr_connp->bytes_processed += 6;
2439 if (session_id_length == 0) {
2446 SCLogDebug(
"Client hello is not seen before master key "
2454 if (direction == 1) {
2455 SCLogDebug(
"Incorrect SSL Record type sent in the toclient "
2468 if (direction == 0 &&
2469 !(ssl_state->curr_connp->content_type &
2471 SCLogDebug(
"Incorrect SSL Record type sent in the toserver "
2482 if (direction == 0) {
2485 SCLogDebug(
"SSLv2 client side has started the encryption");
2488 SCLogDebug(
"SSLv2 client side has started the encryption");
2492 SCLogDebug(
"SSLv2 Server side has started the encryption");
2506 SCLogDebug(
"SSLv2 No reassembly & inspection has been set");
2515 ssl_state->curr_connp->hello_decoded =
true;
2521 ssl_state->flags |= ssl_state->current_flags;
2523 if (ssl_state->curr_connp->bytes_processed >
2524 ssl_state->curr_connp->record_length + ssl_state->curr_connp->record_lengths_length) {
2525 SCLogDebug(
"SSLv2 bytes_processed (%u) exceeds record+hdr "
2526 "len (record_length=%u, lengths_length=%u)",
2527 ssl_state->curr_connp->bytes_processed, ssl_state->curr_connp->record_length,
2528 ssl_state->curr_connp->record_lengths_length);
2533 if (input_len + ssl_state->curr_connp->bytes_processed >=
2534 (ssl_state->curr_connp->record_length +
2535 ssl_state->curr_connp->record_lengths_length)) {
2538 uint32_t diff = ssl_state->curr_connp->record_length +
2539 ssl_state->curr_connp->record_lengths_length + -
2540 ssl_state->curr_connp->bytes_processed;
2548 ssl_state->curr_connp->bytes_processed += input_len;
2557 uint32_t parsed = 0;
2558 uint32_t record_len;
2559 const bool first_call = (ssl_state->curr_connp->bytes_processed == 0);
2562 const uint16_t prev_version = ssl_state->curr_connp->version;
2564 int retval = SSLv3ParseRecord(direction, ssl_state, input, input_len);
2565 if (retval < 0 || retval > (
int)input_len) {
2573 SCLogDebug(
"%s input %p record_length %u", (direction == 0) ?
"toserver" :
"toclient",
2574 input, ssl_state->curr_connp->record_length);
2587 "incomplete header, return %u bytes consumed and wait for more data", parsed);
2594 record_len =
MIN(input_len - parsed, ssl_state->curr_connp->record_length);
2596 "record_len %u (input_len %u, parsed %u, ssl_state->curr_connp->record_length %u)",
2597 record_len, input_len, parsed, ssl_state->curr_connp->record_length);
2599 bool unknown_record =
false;
2600 switch (ssl_state->curr_connp->content_type) {
2608 unknown_record =
true;
2614 if (prev_version == TLS_VERSION_10 || prev_version == TLS_VERSION_11) {
2615 if (unknown_record) {
2619 ssl_state->curr_connp->bytes_processed = 0;
2620 ssl_state->curr_connp->content_type = 0;
2621 ssl_state->curr_connp->record_length = 0;
2623 ssl_state->curr_connp->version = prev_version;
2627 if (unknown_record) {
2635 if (ssl_state->curr_connp->record_length == 0) {
2641 if (!TLSVersionValid(ssl_state->curr_connp->version)) {
2642 SCLogDebug(
"ssl_state->curr_connp->version %04x", ssl_state->curr_connp->version);
2656 record_len = (ssl_state->curr_connp->record_length +
SSLV3_RECORD_HDR_LEN)- ssl_state->curr_connp->bytes_processed;
2657 record_len =
MIN(input_len, record_len);
2659 SCLogDebug(
"record length %u processed %u got %u",
2660 ssl_state->curr_connp->record_length, ssl_state->curr_connp->bytes_processed, record_len);
2663 if (ssl_state->curr_connp->record_length > input_len - parsed) {
2669 uint32_t
needed = ssl_state->curr_connp->record_length;
2670 SCLogDebug(
"record len %u input_len %u parsed %u: need %u bytes more data",
2671 ssl_state->curr_connp->record_length, input_len, parsed,
needed);
2677 if (record_len == 0) {
2682 ssl_state->curr_connp->record_length, direction,
TLS_FRAME_DATA);
2684 switch (ssl_state->curr_connp->content_type) {
2703 int retval = SSLv3ParseAlertProtocol(ssl_state, input + parsed, record_len, direction);
2721 if (ssl_state->curr_connp == &ssl_state->client_connp) {
2728 SCLogDebug(
"setting APP_LAYER_PARSER_NO_INSPECTION_PAYLOAD");
2735 SCLogDebug(
"setting APP_LAYER_PARSER_NO_REASSEMBLY");
2748 (ssl_state->client_connp.version > TLS_VERSION_12) &&
2757 if (ssl_state->curr_connp->record_length < 4) {
2760 SCLogDebug(
"record len < 4 => %u", ssl_state->curr_connp->record_length);
2764 int retval = SSLv3ParseHandshakeProtocol(ssl_state, input + parsed,
2765 record_len, direction);
2767 if (retval < 0 || retval > (
int)record_len) {
2779 int retval = SSLv3ParseHeartbeatProtocol(ssl_state, input + parsed,
2780 record_len, direction);
2794 parsed += record_len;
2795 ssl_state->curr_connp->bytes_processed += record_len;
2797 if (ssl_state->curr_connp->bytes_processed >=
2801 ssl_state->f, direction == 0 ? STREAM_TOSERVER : STREAM_TOCLIENT);
2838 uint32_t counter = 0;
2840 const uint8_t *input = StreamSliceGetData(&stream_slice);
2841 const uint8_t *init_input = input;
2842 int32_t input_len = (int32_t)StreamSliceGetDataLen(&stream_slice);
2844 if ((input == NULL || input_len == 0) &&
2854 }
else if (input == NULL || input_len == 0) {
2870 while (input_len > 0) {
2871 if (counter > max_records) {
2872 SCLogDebug(
"Looks like we have looped quite a bit. Reset state "
2873 "and get out of here");
2884 if ((input[0] & 0x80) || (input[0] & 0x40)) {
2893 SCLogDebug(
"record %u: bytes_processed %u, version %02X, input_len %u", counter,
2900 SCLogDebug(
"Continuing parsing SSLv2 record");
2903 SSLv2Decode(direction, ssl_state, pstate, input, input_len, stream_slice);
2906 SCLogDebug(
"Error parsing SSLv2. Resetting parser "
2907 "state. Let's get outta here");
2914 SCLogDebug(
"returning consumed %" PRIuMAX
" needed %u",
2915 (uintmax_t)(input - init_input), r.
needed);
2920 SCLogDebug(
"SSLv2 decoder consumed %d bytes: %u left", r.
retval, input_len);
2923 SCLogDebug(
"New TLS record: record_length %u",
2926 SCLogDebug(
"Continuing parsing TLS record: record_length %u, bytes_processed %u",
2930 SSLv3Decode(direction, ssl_state, pstate, input, input_len, stream_slice);
2933 SCLogDebug(
"Error parsing TLS. Resetting parser "
2934 "state. Let's get outta here");
2939 SCLogDebug(
"returning consumed %" PRIuMAX
" needed %u",
2940 (uintmax_t)(input - init_input), r.
needed);
3021 static bool TlsConnpLogReady(
const SSLStateConnp *connp,
const uint8_t track_done)
3033 if (!TlsConnpLogReady(
3038 if (!TlsConnpLogReady(
3042 }
else if ((ssl_state->
flags &
3055 return SSLDecode(
f, 0 , alstate, pstate, stream_slice);
3061 return SSLDecode(
f, 1 , alstate, pstate, stream_slice);
3068 static void *SSLStateAlloc(
void *orig_state,
AppProto proto_orig)
3076 return (
void *)ssl_state;
3093 static void SSLStateFree(
void *
p)
3172 static void SSLStateTransactionFree(
void *state, uint64_t tx_id)
3178 const Flow *
f, uint8_t direction,
const uint8_t *input, uint32_t ilen, uint8_t *rdir)
3186 if ((input[0] & 0x80) && (input[2] == 0x01)) {
3193 static int SSLStateGetStateIdByName(
const char *
name,
const uint8_t direction)
3196 direction == STREAM_TOSERVER ? tls_state_client_table : tls_state_server_table;
3205 static const char *SSLStateGetStateNameById(
const int id,
const uint8_t direction)
3208 direction == STREAM_TOSERVER ? tls_state_client_table : tls_state_server_table;
3213 static int SSLStateGetFrameIdByName(
const char *frame_name)
3222 static const char *SSLStateGetFrameNameById(
const uint8_t frame_id)
3228 static int SSLStateGetEventInfo(
3238 static int SSLStateGetEventInfoById(
3242 if (*event_name == NULL) {
3244 "ssl's enum map table.",
3255 static int SSLRegisterPatternsForProtocolDetection(
void)
3258 STREAM_TOSERVER, SSLProbingParser, 0, 3) < 0) {
3264 IPPROTO_TCP,
ALPROTO_TLS,
"|01 03 00|", 3, 0, STREAM_TOSERVER) < 0) {
3268 IPPROTO_TCP,
ALPROTO_TLS,
"|16 03 00|", 3, 0, STREAM_TOSERVER) < 0) {
3274 IPPROTO_TCP,
ALPROTO_TLS,
"|01 03 01|", 3, 0, STREAM_TOSERVER) < 0) {
3278 IPPROTO_TCP,
ALPROTO_TLS,
"|16 03 01|", 3, 0, STREAM_TOSERVER) < 0) {
3284 IPPROTO_TCP,
ALPROTO_TLS,
"|01 03 02|", 3, 0, STREAM_TOSERVER) < 0) {
3288 IPPROTO_TCP,
ALPROTO_TLS,
"|16 03 02|", 3, 0, STREAM_TOSERVER) < 0) {
3294 IPPROTO_TCP,
ALPROTO_TLS,
"|01 03 03|", 3, 0, STREAM_TOSERVER) < 0) {
3298 IPPROTO_TCP,
ALPROTO_TLS,
"|16 03 03|", 3, 0, STREAM_TOSERVER) < 0) {
3305 IPPROTO_TCP,
ALPROTO_TLS,
"|15 03 00|", 3, 0, STREAM_TOCLIENT) < 0) {
3309 IPPROTO_TCP,
ALPROTO_TLS,
"|16 03 00|", 3, 0, STREAM_TOCLIENT) < 0) {
3313 IPPROTO_TCP,
ALPROTO_TLS,
"|17 03 00|", 3, 0, STREAM_TOCLIENT) < 0) {
3319 IPPROTO_TCP,
ALPROTO_TLS,
"|15 03 01|", 3, 0, STREAM_TOCLIENT) < 0) {
3323 IPPROTO_TCP,
ALPROTO_TLS,
"|16 03 01|", 3, 0, STREAM_TOCLIENT) < 0) {
3327 IPPROTO_TCP,
ALPROTO_TLS,
"|17 03 01|", 3, 0, STREAM_TOCLIENT) < 0) {
3333 IPPROTO_TCP,
ALPROTO_TLS,
"|15 03 02|", 3, 0, STREAM_TOCLIENT) < 0) {
3337 IPPROTO_TCP,
ALPROTO_TLS,
"|16 03 02|", 3, 0, STREAM_TOCLIENT) < 0) {
3341 IPPROTO_TCP,
ALPROTO_TLS,
"|17 03 02|", 3, 0, STREAM_TOCLIENT) < 0) {
3347 IPPROTO_TCP,
ALPROTO_TLS,
"|15 03 03|", 3, 0, STREAM_TOCLIENT) < 0) {
3351 IPPROTO_TCP,
ALPROTO_TLS,
"|16 03 03|", 3, 0, STREAM_TOCLIENT) < 0) {
3355 IPPROTO_TCP,
ALPROTO_TLS,
"|17 03 03|", 3, 0, STREAM_TOCLIENT) < 0) {
3365 "|01 03 00|", 5, 2, STREAM_TOSERVER) < 0)
3370 "|00 02|", 7, 5, STREAM_TOCLIENT) < 0)
3380 static void CheckJA3Enabled(
void)
3382 const char *strval = NULL;
3385 if (
SCConfGetNonNull(
"app-layer.protocols.tls.ja3-fingerprints", &strval) != 1) {
3387 }
else if (strcmp(strval,
"auto") == 0) {
3405 static void CheckJA4Enabled(
void)
3407 const char *strval = NULL;
3409 int enable_ja4 = SSL_CONFIG_DEFAULT_JA4;
3410 if (
SCConfGetNonNull(
"app-layer.protocols.tls.ja4-fingerprints", &strval) != 1) {
3411 enable_ja4 = SSL_CONFIG_DEFAULT_JA4;
3412 }
else if (strcmp(strval,
"auto") == 0) {
3413 enable_ja4 = SSL_CONFIG_DEFAULT_JA4;
3438 const char *proto_name =
"tls";
3446 if (SSLRegisterPatternsForProtocolDetection() < 0)
3451 IPPROTO_TCP,
"443",
ALPROTO_TLS, 0, 3, STREAM_TOSERVER, SSLProbingParser, NULL);
3454 0, 3, SSLProbingParser, NULL) == 0) {
3456 "enabling TLS detection on port 443.");
3458 STREAM_TOSERVER, SSLProbingParser, NULL);
3462 SCLogConfig(
"Protocol detection and parser disabled for %s protocol",
3469 SSLParseClientRecord);
3472 SSLParseServerRecord);
3474 IPPROTO_TCP,
ALPROTO_TLS, SSLStateGetStateIdByName, SSLStateGetStateNameById);
3476 IPPROTO_TCP,
ALPROTO_TLS, SSLStateGetFrameIdByName, SSLStateGetFrameNameById);
3504 if (enc_handle != NULL && enc_handle->
val != NULL) {
3505 SCLogDebug(
"have app-layer.protocols.tls.encryption-handling = %s", enc_handle->
val);
3506 if (strcmp(enc_handle->
val,
"full") == 0) {
3508 }
else if (strcmp(enc_handle->
val,
"bypass") == 0) {
3510 }
else if (strcmp(enc_handle->
val,
"track-only") == 0) {
3512 }
else if (strcmp(enc_handle->
val,
"default") == 0) {
3513 SCLogWarning(
"app-layer.protocols.tls.encryption-handling = default is deprecated "
3514 "and will be removed in Suricata 9, use \"track-only\" instead, "
3515 "(see ticket #7642)");
3522 if (
SCConfGetNode(
"app-layer.protocols.tls.no-reassemble") == NULL) {
3524 if (
SCConfGetBool(
"tls.no-reassemble", &value) == 1 && value == 1)
3528 if (
SCConfGetBool(
"app-layer.protocols.tls.no-reassemble", &value) == 1 &&
3544 SCLogWarning(
"MD5 calculation has been disabled, disabling JA3");
3548 SCLogWarning(
"Hashing has been disabled, disabling JA4");
3562 SCLogConfig(
"Parser disabled for %s protocol. Protocol detection still on.", proto_name);
3628 static int TLSPhaseStateTestClient(
void)
3630 const char *names[] = {
"client_started",
"client_hello",
"client_cert",
"client_data",
3631 "client_finished" };
3632 for (
int i = 0; i < 5; i++) {
3634 IPPROTO_TCP,
ALPROTO_TLS, names[i], STREAM_TOSERVER) != i);
3641 static int TLSPhaseStateTestServer(
void)
3643 const char *names[] = {
"server_started",
"server_hello",
"server_cert",
"server_data",
3644 "server_finished" };
3645 for (
int i = 0; i < 5; i++) {
3647 IPPROTO_TCP,
ALPROTO_TLS, names[i], STREAM_TOCLIENT) != i);
3654 static int TLSPhaseStateTestOldNamesGone(
void)
3656 const char *old_client[] = {
"client_in_progress",
"client_hello_done",
"client_cert_done",
3657 "client_handshake_done" };
3658 const char *old_server[] = {
"server_in_progress",
"server_hello_done",
"server_cert_done",
3659 "server_handshake_done" };
3660 for (
int i = 0; i < 4; i++) {
3662 IPPROTO_TCP,
ALPROTO_TLS, old_client[i], STREAM_TOSERVER) >= 0);
3664 IPPROTO_TCP,
ALPROTO_TLS, old_server[i], STREAM_TOCLIENT) >= 0);
3669 static int TLSPhaseStateTestCompletion(
void)
3682 SSLStateFree(ssl_state);
3691 static int TLSPhaseSuppressionTest(
void)
3694 if (ssl_state == NULL)
3699 const uint8_t p4[] = { 0x01, 0x00, 0x00, 0x06, 0x03, 0x03, 0x01, 0x02, 0x03, 0x04 };
3702 uint8_t p5[4 + 2 + 32 + 1 + 1 + 2 + 1];
3712 for (i = 0; i < 32; i++)
3713 p5[6 + i] = (uint8_t)i;
3720 const uint8_t p6[] = { 0x0b, 0x00, 0x00, 0x10, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x0a, 0x41, 0x41,
3721 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41 };
3729 rc = SSLv3ParseHandshakeProtocol(ssl_state, p4,
sizeof(p4), 0);
3740 rc = SSLv3ParseHandshakeProtocol(ssl_state, p5,
sizeof(p5), 1);
3754 rc = SSLv3ParseHandshakeProtocol(ssl_state, p6,
sizeof(p6), 1);
3761 SSLStateFree(ssl_state);
3775 static int TLSPhaseCertChainSkipTest(
void)
3777 static const uint8_t valid_cert[] = { 0x30, 0x82, 0x03, 0x0b, 0x30, 0x82, 0x01, 0xf3, 0xa0,
3778 0x03, 0x02, 0x01, 0x02, 0x02, 0x14, 0x16, 0x1b, 0x77, 0xa9, 0xae, 0xe9, 0xea, 0xaa, 0x2d,
3779 0xf9, 0xbb, 0xd6, 0xda, 0x13, 0x92, 0xf8, 0x73, 0xf8, 0x93, 0xa0, 0x30, 0x0d, 0x06, 0x09,
3780 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30, 0x15, 0x31, 0x13,
3781 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0a, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74,
3782 0x74, 0x65, 0x73, 0x74, 0x30, 0x1e, 0x17, 0x0d, 0x32, 0x36, 0x30, 0x39, 0x31, 0x38, 0x30,
3783 0x33, 0x34, 0x38, 0x35, 0x36, 0x5a, 0x17, 0x0d, 0x32, 0x36, 0x30, 0x39, 0x32, 0x30, 0x30,
3784 0x33, 0x34, 0x38, 0x35, 0x36, 0x5a, 0x30, 0x15, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55,
3785 0x04, 0x03, 0x0c, 0x0a, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x74, 0x65, 0x73, 0x74, 0x30,
3786 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01,
3787 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00, 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01,
3788 0x01, 0x00, 0xc7, 0xdc, 0x32, 0x3c, 0x76, 0x5d, 0x86, 0x02, 0xbd, 0x3e, 0xc0, 0x8e, 0x6f,
3789 0x34, 0x7e, 0xa2, 0x2c, 0x66, 0xe4, 0x20, 0x2f, 0x1c, 0xf4, 0x6c, 0x4d, 0xb6, 0x8e, 0xed,
3790 0x5c, 0xdf, 0x36, 0xdb, 0xa8, 0xea, 0xf9, 0x01, 0xbe, 0x20, 0x92, 0x85, 0x72, 0x9c, 0x5d,
3791 0x19, 0xf5, 0xa1, 0xa6, 0xdf, 0x60, 0x17, 0xc3, 0xba, 0xb7, 0xed, 0x57, 0x99, 0x19, 0x46,
3792 0xee, 0xb2, 0x04, 0xfe, 0x18, 0x17, 0x65, 0x62, 0xe2, 0xd7, 0x45, 0xb1, 0x0f, 0x0c, 0xc8,
3793 0x6b, 0xe4, 0x63, 0x4a, 0x6b, 0xd9, 0x30, 0xae, 0xf5, 0x81, 0xc5, 0xac, 0x50, 0x51, 0xc6,
3794 0x91, 0x5c, 0x78, 0xc0, 0x74, 0x2a, 0x47, 0x6b, 0xae, 0xc3, 0x4b, 0x7d, 0x54, 0x66, 0x0d,
3795 0xd7, 0xa1, 0x81, 0x07, 0x80, 0x44, 0xba, 0x30, 0x02, 0xeb, 0x82, 0x3c, 0x78, 0xbb, 0x9f,
3796 0x2b, 0xeb, 0x1b, 0x1c, 0x30, 0x41, 0x02, 0xeb, 0xf5, 0x9c, 0xb3, 0xef, 0x43, 0x52, 0x4b,
3797 0x54, 0x1f, 0xf3, 0x0d, 0xeb, 0xcc, 0x25, 0x97, 0xda, 0x52, 0x07, 0xdf, 0x54, 0x35, 0x4b,
3798 0x85, 0x63, 0x67, 0xd6, 0x60, 0x9f, 0x0f, 0x88, 0xbf, 0x7e, 0xc9, 0x44, 0x2f, 0x34, 0xd6,
3799 0x28, 0xad, 0x2d, 0x59, 0x7e, 0x56, 0xb6, 0x73, 0x5a, 0xe0, 0xb0, 0x1c, 0xc9, 0x23, 0x5f,
3800 0x2a, 0x3c, 0x46, 0x1c, 0x27, 0x7f, 0x0e, 0x25, 0x16, 0x19, 0xb0, 0x03, 0x71, 0x05, 0xd5,
3801 0xc6, 0xed, 0x49, 0x7c, 0x90, 0xca, 0x94, 0xfb, 0xe4, 0x75, 0x23, 0x67, 0x17, 0x37, 0x08,
3802 0x05, 0xb8, 0x58, 0x7f, 0x61, 0x16, 0x24, 0x91, 0xeb, 0x0c, 0x1c, 0x05, 0x0d, 0xa5, 0x45,
3803 0x55, 0x03, 0x2e, 0x60, 0x15, 0xc4, 0x6b, 0xcb, 0x68, 0x1f, 0xec, 0xbe, 0x59, 0xbf, 0x4a,
3804 0x93, 0x0b, 0xa3, 0x08, 0x86, 0xe0, 0xe9, 0x5c, 0x08, 0x23, 0x3b, 0x0f, 0xbd, 0xc9, 0x91,
3805 0xa1, 0x48, 0xf9, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x53, 0x30, 0x51, 0x30, 0x1d, 0x06,
3806 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0xae, 0xed, 0xef, 0x6c, 0xe0, 0xf6, 0xb7,
3807 0xe3, 0x8c, 0xd9, 0x37, 0x7f, 0x0b, 0x53, 0x36, 0x96, 0x06, 0x5d, 0x0f, 0x09, 0x30, 0x1f,
3808 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, 0x14, 0xae, 0xed, 0xef, 0x6c,
3809 0xe0, 0xf6, 0xb7, 0xe3, 0x8c, 0xd9, 0x37, 0x7f, 0x0b, 0x53, 0x36, 0x96, 0x06, 0x5d, 0x0f,
3810 0x09, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x01, 0x01, 0xff, 0x04, 0x05, 0x30, 0x03,
3811 0x01, 0x01, 0xff, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01,
3812 0x0b, 0x05, 0x00, 0x03, 0x82, 0x01, 0x01, 0x00, 0x08, 0x2e, 0x15, 0x02, 0x17, 0xcb, 0xf8,
3813 0x5b, 0x4b, 0x31, 0x47, 0xf4, 0x8d, 0x55, 0x53, 0xa4, 0x05, 0x46, 0x73, 0xb7, 0x6a, 0x79,
3814 0xfc, 0x02, 0xe4, 0x89, 0x09, 0xb9, 0x3d, 0x8c, 0xda, 0x98, 0x0d, 0x67, 0x83, 0x30, 0x00,
3815 0xe5, 0x3b, 0xc4, 0x7c, 0xc4, 0x63, 0xa7, 0x20, 0x97, 0x74, 0x8d, 0x18, 0xfa, 0xb1, 0xe7,
3816 0x67, 0x13, 0x48, 0x55, 0x99, 0xde, 0xca, 0x70, 0xe4, 0x7a, 0x3a, 0x65, 0x28, 0x08, 0xce,
3817 0xc3, 0x93, 0xbb, 0x95, 0x15, 0x10, 0x25, 0x67, 0x7a, 0xad, 0xe8, 0xbc, 0xfb, 0xee, 0x94,
3818 0xfa, 0x09, 0x6a, 0x3e, 0xa6, 0xb9, 0x9b, 0xd7, 0x01, 0xe4, 0x4f, 0x53, 0x69, 0x92, 0x8a,
3819 0xf4, 0x52, 0xbf, 0x44, 0xfd, 0x26, 0x80, 0xb3, 0xed, 0x9d, 0x25, 0xa8, 0x99, 0x24, 0x1e,
3820 0xd7, 0x29, 0xde, 0xa3, 0x08, 0x63, 0x44, 0x2a, 0xb9, 0x94, 0x19, 0x73, 0xb9, 0xf3, 0xee,
3821 0x67, 0xc1, 0x81, 0xdd, 0x78, 0x2f, 0x8c, 0x1d, 0x7e, 0xb5, 0x06, 0x97, 0x24, 0x60, 0xfb,
3822 0x27, 0xf1, 0x4d, 0x85, 0x2d, 0x1e, 0x8c, 0x13, 0x95, 0x2b, 0x5c, 0x12, 0x3a, 0xe3, 0x31,
3823 0x55, 0x07, 0xdd, 0xf2, 0x85, 0xc5, 0x2e, 0x28, 0x2a, 0x9b, 0x3a, 0x89, 0xef, 0xd6, 0xba,
3824 0x00, 0x55, 0xc2, 0x61, 0x74, 0xaf, 0xcc, 0xfd, 0x44, 0x7c, 0xae, 0xd8, 0xbb, 0xa7, 0xb7,
3825 0x93, 0xc1, 0x3a, 0x0d, 0xef, 0x7e, 0x14, 0x67, 0x3a, 0x0b, 0x62, 0x57, 0x5e, 0x78, 0x58,
3826 0x5c, 0x63, 0x2b, 0x79, 0x2d, 0x81, 0x61, 0x4d, 0xd2, 0xdb, 0x41, 0xe9, 0xbd, 0x00, 0xc8,
3827 0x26, 0xd3, 0xea, 0x6b, 0x10, 0xa9, 0x8e, 0xab, 0x64, 0x85, 0x6a, 0x55, 0xc1, 0x78, 0x65,
3828 0x31, 0x9b, 0x4d, 0x44, 0x84, 0xea, 0x60, 0x15, 0x52, 0x6b, 0x9d, 0x4b, 0x14, 0x5c, 0xba,
3829 0x4f, 0xa2, 0x53, 0x8f, 0x2a, 0x2c, 0xda, 0x36, 0x96
3835 const uint32_t bad_len = 10;
3836 const uint32_t good_len =
sizeof(valid_cert);
3837 const uint32_t chain_len = 3 + bad_len + 3 + good_len;
3838 const uint32_t hs_len = 3 + chain_len;
3839 const uint32_t msg_len = 4 + 3 + 3 + bad_len + 3 + good_len;
3840 uint8_t msg[msg_len];
3844 msg[2] = (hs_len >> 8) & 0xff;
3845 msg[3] = hs_len & 0xff;
3847 msg[5] = (chain_len >> 8) & 0xff;
3848 msg[6] = chain_len & 0xff;
3852 for (uint32_t k = 0; k < bad_len; k++)
3854 const uint32_t off = 10 + bad_len;
3856 msg[off + 1] = (good_len >> 8) & 0xff;
3857 msg[off + 2] = good_len & 0xff;
3858 memcpy(msg + off + 3, valid_cert, good_len);
3861 if (ssl_state == NULL)
3875 int rc = SSLv3ParseHandshakeProtocol(ssl_state, msg, msg_len, 1);
3891 X509 *ref = SCX509Decode(valid_cert,
sizeof(valid_cert), &errc);
3893 uint8_t *subj = NULL;
3894 uint32_t subj_len = 0;
3895 uint8_t *iss = NULL;
3896 uint32_t iss_len = 0;
3897 SCX509GetSubject(ref, &subj, &subj_len);
3898 SCX509GetIssuer(ref, &iss, &iss_len);
3899 FAIL_IF(subj == NULL || iss == NULL);
3905 SCX509ArrayFree(subj, subj_len);
3907 SCX509ArrayFree(iss, iss_len);
3915 const uint8_t shd[] = { 0x0e, 0x00, 0x00, 0x00 };
3919 rc = SSLv3ParseHandshakeProtocol(ssl_state, shd,
sizeof(shd), 1);
3930 const uint32_t mlen = 4 + 3 + 3 +
sizeof(valid_cert);
3932 memset(full, 0,
sizeof(full));
3934 full[1] = ((3 + 3 + good_len) >> 16) & 0xff;
3935 full[2] = ((3 + 3 + good_len) >> 8) & 0xff;
3936 full[3] = (3 + 3 + good_len) & 0xff;
3937 full[4] = ((3 + good_len) >> 16) & 0xff;
3938 full[5] = ((3 + good_len) >> 8) & 0xff;
3939 full[6] = (3 + good_len) & 0xff;
3940 full[7] = (good_len >> 16) & 0xff;
3941 full[8] = (good_len >> 8) & 0xff;
3942 full[9] = good_len & 0xff;
3943 memcpy(full + 10, valid_cert, good_len);
3947 rc = SSLv3ParseHandshakeProtocol(ssl_state, full, mlen, 0);
3960 rc = SSLv3ParseHandshakeProtocol(ssl_state, full, mlen, 1);
3964 SSLStateFree(ssl_state);
3974 static int TLSPhaseWrongDirectionKeyxTest(
void)
3977 if (ssl_state == NULL)
3981 const uint8_t ckx[] = { 0x10, 0x00, 0x00, 0x00 };
3985 int rc = SSLv3ParseHandshakeProtocol(ssl_state, ckx,
sizeof(ckx), 1);
3990 const uint8_t certreq[] = { 0x0d, 0x00, 0x00, 0x00 };
3994 rc = SSLv3ParseHandshakeProtocol(ssl_state, certreq,
sizeof(certreq), 1);
4005 rc = SSLv3ParseHandshakeProtocol(client_ckx, ckx,
sizeof(ckx), 0);
4009 SSLStateFree(ssl_state);
4010 SSLStateFree(client_ckx);
4016 UtRegisterTest(
"TLSPhaseStateTestClient", TLSPhaseStateTestClient);
4017 UtRegisterTest(
"TLSPhaseStateTestServer", TLSPhaseStateTestServer);
4018 UtRegisterTest(
"TLSPhaseStateTestOldNamesGone", TLSPhaseStateTestOldNamesGone);
4019 UtRegisterTest(
"TLSPhaseStateTestCompletion", TLSPhaseStateTestCompletion);
4020 UtRegisterTest(
"TLSPhaseSuppressionTest", TLSPhaseSuppressionTest);
4021 UtRegisterTest(
"TLSPhaseCertChainSkipTest", TLSPhaseCertChainSkipTest);
4022 UtRegisterTest(
"TLSPhaseWrongDirectionKeyxTest", TLSPhaseWrongDirectionKeyxTest);