From: Mats Klepsland Date: Fri, 23 Sep 2016 11:52:28 +0000 (+0200) Subject: app-layer-ssl: use new unit test macros X-Git-Tag: suricata-3.2beta1~293 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b91486169221fdc2dfdeb3933bcd57de4b9a023f;p=thirdparty%2Fsuricata.git app-layer-ssl: use new unit test macros --- diff --git a/src/app-layer-ssl.c b/src/app-layer-ssl.c index 40954dfdfd..3b75427c90 100644 --- a/src/app-layer-ssl.c +++ b/src/app-layer-ssl.c @@ -1830,7 +1830,6 @@ void RegisterSSLParsers(void) */ static int SSLParserTest01(void) { - int result = 1; Flow f; uint8_t tlsbuf[] = { 0x16, 0x03, 0x01 }; uint32_t tlslen = sizeof(tlsbuf); @@ -1848,46 +1847,26 @@ static int SSLParserTest01(void) FLOWLOCK_WRLOCK(&f); int r = AppLayerParserParse(alp_tctx, &f, ALPROTO_TLS, STREAM_TOSERVER | STREAM_EOF, tlsbuf, tlslen); - if (r != 0) { - printf("toserver chunk 1 returned %" PRId32 ", expected 0: ", r); - result = 0; - FLOWLOCK_UNLOCK(&f); - goto end; - } FLOWLOCK_UNLOCK(&f); + FAIL_IF(r != 0); SSLState *ssl_state = f.alstate; - if (ssl_state == NULL) { - printf("no tls state: "); - result = 0; - goto end; - } + FAIL_IF_NULL(ssl_state); - if (ssl_state->client_connp.content_type != 0x16) { - printf("expected content_type %" PRIu8 ", got %" PRIu8 ": ", 0x16, - ssl_state->client_connp.content_type); - result = 0; - goto end; - } + FAIL_IF(ssl_state->client_connp.content_type != 0x16); - if (ssl_state->client_connp.version != TLS_VERSION_10) { - printf("expected version %04" PRIu16 ", got %04" PRIu16 ": ", - TLS_VERSION_10, ssl_state->client_connp.version); - result = 0; - goto end; - } -end: - if (alp_tctx != NULL) - AppLayerParserThreadCtxFree(alp_tctx); + FAIL_IF(ssl_state->client_connp.version != TLS_VERSION_10); + + AppLayerParserThreadCtxFree(alp_tctx); StreamTcpFreeConfig(TRUE); FLOW_DESTROY(&f); - return result; + + PASS; } /** \test Send a get request in two chunks. */ static int SSLParserTest02(void) { - int result = 1; Flow f; uint8_t tlsbuf1[] = { 0x16 }; uint32_t tlslen1 = sizeof(tlsbuf1); @@ -1906,56 +1885,31 @@ static int SSLParserTest02(void) FLOWLOCK_WRLOCK(&f); int r = AppLayerParserParse(alp_tctx, &f, ALPROTO_TLS, STREAM_TOSERVER, tlsbuf1, tlslen1); - if (r != 0) { - printf("toserver chunk 1 returned %" PRId32 ", expected 0: ", r); - result = 0; - FLOWLOCK_UNLOCK(&f); - goto end; - } FLOWLOCK_UNLOCK(&f); + FAIL_IF(r != 0); FLOWLOCK_WRLOCK(&f); r = AppLayerParserParse(alp_tctx, &f, ALPROTO_TLS, STREAM_TOSERVER, tlsbuf2, tlslen2); - if (r != 0) { - printf("toserver chunk 2 returned %" PRId32 ", expected 0: ", r); - result = 0; - FLOWLOCK_UNLOCK(&f); - goto end; - } FLOWLOCK_UNLOCK(&f); + FAIL_IF(r != 0); SSLState *ssl_state = f.alstate; - if (ssl_state == NULL) { - printf("no tls state: "); - result = 0; - goto end; - } + FAIL_IF_NULL(ssl_state); - if (ssl_state->client_connp.content_type != 0x16) { - printf("expected content_type %" PRIu8 ", got %" PRIu8 ": ", 0x16, - ssl_state->client_connp.content_type); - result = 0; - goto end; - } + FAIL_IF(ssl_state->client_connp.content_type != 0x16); - if (ssl_state->client_connp.version != TLS_VERSION_10) { - printf("expected version %04" PRIu16 ", got %04" PRIu16 ": ", - TLS_VERSION_10, ssl_state->client_connp.version); - result = 0; - goto end; - } -end: - if (alp_tctx != NULL) - AppLayerParserThreadCtxFree(alp_tctx); + FAIL_IF(ssl_state->client_connp.version != TLS_VERSION_10); + + AppLayerParserThreadCtxFree(alp_tctx); StreamTcpFreeConfig(TRUE); FLOW_DESTROY(&f); - return result; + + PASS; } /** \test Send a get request in three chunks. */ static int SSLParserTest03(void) { - int result = 1; Flow f; uint8_t tlsbuf1[] = { 0x16 }; uint32_t tlslen1 = sizeof(tlsbuf1); @@ -1976,66 +1930,36 @@ static int SSLParserTest03(void) FLOWLOCK_WRLOCK(&f); int r = AppLayerParserParse(alp_tctx, &f, ALPROTO_TLS, STREAM_TOSERVER, tlsbuf1, tlslen1); - if (r != 0) { - printf("toserver chunk 1 returned %" PRId32 ", expected 0: ", r); - result = 0; - FLOWLOCK_UNLOCK(&f); - goto end; - } FLOWLOCK_UNLOCK(&f); + FAIL_IF(r != 0); FLOWLOCK_WRLOCK(&f); r = AppLayerParserParse(alp_tctx, &f, ALPROTO_TLS, STREAM_TOSERVER, tlsbuf2, tlslen2); - if (r != 0) { - printf("toserver chunk 2 returned %" PRId32 ", expected 0: ", r); - result = 0; - FLOWLOCK_UNLOCK(&f); - goto end; - } FLOWLOCK_UNLOCK(&f); + FAIL_IF(r != 0); FLOWLOCK_WRLOCK(&f); r = AppLayerParserParse(alp_tctx, &f, ALPROTO_TLS, STREAM_TOSERVER, tlsbuf3, tlslen3); - if (r != 0) { - printf("toserver chunk 3 returned %" PRId32 ", expected 0: ", r); - result = 0; - FLOWLOCK_UNLOCK(&f); - goto end; - } FLOWLOCK_UNLOCK(&f); + FAIL_IF(r != 0); SSLState *ssl_state = f.alstate; - if (ssl_state == NULL) { - printf("no tls state: "); - result = 0; - goto end; - } + FAIL_IF_NULL(ssl_state); - if (ssl_state->client_connp.content_type != 0x16) { - printf("expected content_type %" PRIu8 ", got %" PRIu8 ": ", 0x16, - ssl_state->client_connp.content_type); - result = 0; - goto end; - } + FAIL_IF(ssl_state->client_connp.content_type != 0x16); - if (ssl_state->client_connp.version != TLS_VERSION_10) { - printf("expected version %04" PRIu16 ", got %04" PRIu16 ": ", - TLS_VERSION_10, ssl_state->client_connp.version); - result = 0; - goto end; - } -end: - if (alp_tctx != NULL) - AppLayerParserThreadCtxFree(alp_tctx); + FAIL_IF(ssl_state->client_connp.version != TLS_VERSION_10); + + AppLayerParserThreadCtxFree(alp_tctx); StreamTcpFreeConfig(TRUE); FLOW_DESTROY(&f); - return result; + + PASS; } /** \test Send a get request in three chunks + more data. */ static int SSLParserTest04(void) { - int result = 1; Flow f; uint8_t tlsbuf1[] = { 0x16 }; uint32_t tlslen1 = sizeof(tlsbuf1); @@ -2058,70 +1982,36 @@ static int SSLParserTest04(void) FLOWLOCK_WRLOCK(&f); int r = AppLayerParserParse(alp_tctx, &f, ALPROTO_TLS, STREAM_TOSERVER, tlsbuf1, tlslen1); - if (r != 0) { - printf("toserver chunk 1 returned %" PRId32 ", expected 0: ", r); - result = 0; - FLOWLOCK_UNLOCK(&f); - goto end; - } FLOWLOCK_UNLOCK(&f); + FAIL_IF(r != 0); FLOWLOCK_WRLOCK(&f); r = AppLayerParserParse(alp_tctx, &f, ALPROTO_TLS, STREAM_TOSERVER, tlsbuf2, tlslen2); - if (r != 0) { - printf("toserver chunk 2 returned %" PRId32 ", expected 0: ", r); - result = 0; - FLOWLOCK_UNLOCK(&f); - goto end; - } FLOWLOCK_UNLOCK(&f); + FAIL_IF(r != 0); FLOWLOCK_WRLOCK(&f); r = AppLayerParserParse(alp_tctx, &f, ALPROTO_TLS, STREAM_TOSERVER, tlsbuf3, tlslen3); - if (r != 0) { - printf("toserver chunk 3 returned %" PRId32 ", expected 0: ", r); - result = 0; - FLOWLOCK_UNLOCK(&f); - goto end; - } FLOWLOCK_UNLOCK(&f); + FAIL_IF(r != 0); FLOWLOCK_WRLOCK(&f); r = AppLayerParserParse(alp_tctx, &f, ALPROTO_TLS, STREAM_TOSERVER, tlsbuf4, tlslen4); - if (r != 0) { - printf("toserver chunk 4 returned %" PRId32 ", expected 0: ", r); - result = 0; - FLOWLOCK_UNLOCK(&f); - goto end; - } FLOWLOCK_UNLOCK(&f); + FAIL_IF(r != 0); SSLState *ssl_state = f.alstate; - if (ssl_state == NULL) { - printf("no tls state: "); - result = 0; - goto end; - } + FAIL_IF_NULL(ssl_state); - if (ssl_state->client_connp.content_type != 0x16) { - printf("expected content_type %" PRIu8 ", got %" PRIu8 ": ", 0x16, - ssl_state->client_connp.content_type); - result = 0; - goto end; - } + FAIL_IF(ssl_state->client_connp.content_type != 0x16); - if (ssl_state->client_connp.version != TLS_VERSION_10) { - printf("expected version %04" PRIu16 ", got %04" PRIu16 ": ", - TLS_VERSION_10, ssl_state->client_connp.version); - result = 0; - goto end; - } -end: - if (alp_tctx != NULL) - AppLayerParserThreadCtxFree(alp_tctx); + FAIL_IF(ssl_state->client_connp.version != TLS_VERSION_10); + + AppLayerParserThreadCtxFree(alp_tctx); StreamTcpFreeConfig(TRUE); FLOW_DESTROY(&f); - return result; + + PASS; } #if 0 @@ -2364,7 +2254,6 @@ end: /** \test multimsg test */ static int SSLParserMultimsgTest01(void) { - int result = 1; Flow f; /* 3 msgs */ uint8_t tlsbuf1[] = { @@ -2408,46 +2297,26 @@ static int SSLParserMultimsgTest01(void) FLOWLOCK_WRLOCK(&f); int r = AppLayerParserParse(alp_tctx, &f, ALPROTO_TLS, STREAM_TOSERVER, tlsbuf1, tlslen1); - if (r != 0) { - printf("toserver chunk 1 returned %" PRId32 ", expected 0: ", r); - result = 0; - FLOWLOCK_UNLOCK(&f); - goto end; - } FLOWLOCK_UNLOCK(&f); + FAIL_IF(r != 0); SSLState *ssl_state = f.alstate; - if (ssl_state == NULL) { - printf("no tls state: "); - result = 0; - goto end; - } + FAIL_IF_NULL(ssl_state); - if (ssl_state->client_connp.content_type != 0x16) { - printf("expected content_type %" PRIu8 ", got %" PRIu8 ": ", 0x16, - ssl_state->client_connp.content_type); - result = 0; - goto end; - } + FAIL_IF(ssl_state->client_connp.content_type != 0x16); - if (ssl_state->client_connp.version != TLS_VERSION_10) { - printf("expected version %04" PRIu16 ", got %04" PRIu16 ": ", - TLS_VERSION_10, ssl_state->client_connp.version); - result = 0; - goto end; - } -end: - if (alp_tctx != NULL) - AppLayerParserThreadCtxFree(alp_tctx); + FAIL_IF(ssl_state->client_connp.version != TLS_VERSION_10); + + AppLayerParserThreadCtxFree(alp_tctx); StreamTcpFreeConfig(TRUE); FLOW_DESTROY(&f); - return result; + + PASS; } /** \test multimsg test server */ static int SSLParserMultimsgTest02(void) { - int result = 1; Flow f; /* 3 msgs */ uint8_t tlsbuf1[] = { @@ -2491,40 +2360,21 @@ static int SSLParserMultimsgTest02(void) FLOWLOCK_WRLOCK(&f); int r = AppLayerParserParse(alp_tctx, &f, ALPROTO_TLS, STREAM_TOCLIENT, tlsbuf1, tlslen1); - if (r != 0) { - printf("toserver chunk 1 returned %" PRId32 ", expected 0: ", r); - result = 0; - FLOWLOCK_UNLOCK(&f); - goto end; - } FLOWLOCK_UNLOCK(&f); + FAIL_IF(r != 0); SSLState *ssl_state = f.alstate; - if (ssl_state == NULL) { - printf("no tls state: "); - result = 0; - goto end; - } + FAIL_IF_NULL(ssl_state); - if (ssl_state->server_connp.content_type != 0x16) { - printf("expected content_type %" PRIu8 ", got %" PRIu8 ": ", 0x16, - ssl_state->server_connp.content_type); - result = 0; - goto end; - } + FAIL_IF(ssl_state->server_connp.content_type != 0x16); - if (ssl_state->server_connp.version != 0x0301) { - printf("expected version %04" PRIu16 ", got %04" PRIu16 ": ", 0x0301, - ssl_state->server_connp.version); - result = 0; - goto end; - } -end: - if (alp_tctx != NULL) - AppLayerParserThreadCtxFree(alp_tctx); + FAIL_IF(ssl_state->server_connp.version != 0x0301); + + AppLayerParserThreadCtxFree(alp_tctx); StreamTcpFreeConfig(TRUE); FLOW_DESTROY(&f); - return result; + + PASS; } /** @@ -2532,7 +2382,6 @@ end: */ static int SSLParserTest07(void) { - int result = 1; Flow f; uint8_t tlsbuf[] = { 0x16, 0x03, 0x00, 0x00, 0x4c, 0x01, 0x00, 0x00, 0x48, 0x03, 0x00, 0x57, 0x04, 0x9f, @@ -2559,41 +2408,21 @@ static int SSLParserTest07(void) FLOWLOCK_WRLOCK(&f); int r = AppLayerParserParse(alp_tctx, &f, ALPROTO_TLS, STREAM_TOSERVER, tlsbuf, tlslen); - if (r != 0) { - printf("toserver chunk 1 returned %" PRId32 ", expected 0: ", r); - result = 0; - FLOWLOCK_UNLOCK(&f); - goto end; - } FLOWLOCK_UNLOCK(&f); + FAIL_IF(r != 0); SSLState *ssl_state = f.alstate; - if (ssl_state == NULL) { - printf("no tls state: "); - result = 0; - goto end; - } + FAIL_IF_NULL(ssl_state); - if (ssl_state->client_connp.content_type != 0x16) { - printf("expected content_type %" PRIu8 ", got %" PRIu8 ": ", 0x17, - ssl_state->client_connp.content_type); - result = 0; - goto end; - } + FAIL_IF(ssl_state->client_connp.content_type != 0x16); - if (ssl_state->client_connp.version != SSL_VERSION_3) { - printf("expected version %04" PRIu16 ", got %04" PRIu16 ": ", - SSL_VERSION_3, ssl_state->client_connp.version); - result = 0; - goto end; - } + FAIL_IF(ssl_state->client_connp.version != SSL_VERSION_3); -end: - if (alp_tctx != NULL) - AppLayerParserThreadCtxFree(alp_tctx); + AppLayerParserThreadCtxFree(alp_tctx); StreamTcpFreeConfig(TRUE); FLOW_DESTROY(&f); - return result; + + PASS; } #if 0 @@ -2711,7 +2540,6 @@ end: */ static int SSLParserTest09(void) { - int result = 1; Flow f; uint8_t buf1[] = { 0x16, @@ -2745,51 +2573,26 @@ static int SSLParserTest09(void) FLOWLOCK_WRLOCK(&f); int r = AppLayerParserParse(alp_tctx, &f, ALPROTO_TLS, STREAM_TOSERVER, buf1, buf1_len); - if (r != 0) { - printf("toserver chunk 1 returned %" PRId32 ", expected 0: ", r); - result = 0; - FLOWLOCK_UNLOCK(&f); - goto end; - } FLOWLOCK_UNLOCK(&f); + FAIL_IF(r != 0); FLOWLOCK_WRLOCK(&f); r = AppLayerParserParse(alp_tctx, &f, ALPROTO_TLS, STREAM_TOSERVER, buf2, buf2_len); - if (r != 0) { - printf("toserver chunk 1 returned %" PRId32 ", expected 0: ", r); - result = 0; - FLOWLOCK_UNLOCK(&f); - goto end; - } FLOWLOCK_UNLOCK(&f); + FAIL_IF(r != 0); SSLState *ssl_state = f.alstate; - if (ssl_state == NULL) { - printf("no tls state: "); - result = 0; - goto end; - } + FAIL_IF_NULL(ssl_state); - if (ssl_state->client_connp.content_type != 0x16) { - printf("expected content_type %" PRIu8 ", got %" PRIu8 ": ", 0x17, - ssl_state->client_connp.content_type); - result = 0; - goto end; - } + FAIL_IF(ssl_state->client_connp.content_type != 0x16); - if (ssl_state->client_connp.version != SSL_VERSION_3) { - printf("expected version %04" PRIu16 ", got %04" PRIu16 ": ", - SSL_VERSION_3, ssl_state->client_connp.version); - result = 0; - goto end; - } + FAIL_IF(ssl_state->client_connp.version != SSL_VERSION_3); -end: - if (alp_tctx != NULL) - AppLayerParserThreadCtxFree(alp_tctx); + AppLayerParserThreadCtxFree(alp_tctx); StreamTcpFreeConfig(TRUE); FLOW_DESTROY(&f); - return result; + + PASS; } /** @@ -2797,7 +2600,6 @@ end: */ static int SSLParserTest10(void) { - int result = 1; Flow f; uint8_t buf1[] = { 0x16, 0x03, @@ -2831,51 +2633,26 @@ static int SSLParserTest10(void) FLOWLOCK_WRLOCK(&f); int r = AppLayerParserParse(alp_tctx, &f, ALPROTO_TLS, STREAM_TOSERVER, buf1, buf1_len); - if (r != 0) { - printf("toserver chunk 1 returned %" PRId32 ", expected 0: ", r); - result = 0; - FLOWLOCK_UNLOCK(&f); - goto end; - } FLOWLOCK_UNLOCK(&f); + FAIL_IF(r != 0); FLOWLOCK_WRLOCK(&f); r = AppLayerParserParse(alp_tctx, &f, ALPROTO_TLS, STREAM_TOSERVER, buf2, buf2_len); - if (r != 0) { - printf("toserver chunk 1 returned %" PRId32 ", expected 0: ", r); - result = 0; - FLOWLOCK_UNLOCK(&f); - goto end; - } FLOWLOCK_UNLOCK(&f); + FAIL_IF(r != 0); SSLState *ssl_state = f.alstate; - if (ssl_state == NULL) { - printf("no tls state: "); - result = 0; - goto end; - } + FAIL_IF_NULL(ssl_state); - if (ssl_state->client_connp.content_type != 0x16) { - printf("expected content_type %" PRIu8 ", got %" PRIu8 ": ", 0x17, - ssl_state->client_connp.content_type); - result = 0; - goto end; - } + FAIL_IF(ssl_state->client_connp.content_type != 0x16); - if (ssl_state->client_connp.version != SSL_VERSION_3) { - printf("expected version %04" PRIu16 ", got %04" PRIu16 ": ", - SSL_VERSION_3, ssl_state->client_connp.version); - result = 0; - goto end; - } + FAIL_IF(ssl_state->client_connp.version != SSL_VERSION_3); -end: - if (alp_tctx != NULL) - AppLayerParserThreadCtxFree(alp_tctx); + AppLayerParserThreadCtxFree(alp_tctx); StreamTcpFreeConfig(TRUE); FLOW_DESTROY(&f); - return result; + + PASS; } /** @@ -2883,7 +2660,6 @@ end: */ static int SSLParserTest11(void) { - int result = 1; Flow f; uint8_t buf1[] = { 0x16, 0x03, 0x00, 0x00, 0x4c, 0x01, @@ -2916,51 +2692,26 @@ static int SSLParserTest11(void) FLOWLOCK_WRLOCK(&f); int r = AppLayerParserParse(alp_tctx, &f, ALPROTO_TLS, STREAM_TOSERVER, buf1, buf1_len); - if (r != 0) { - printf("toserver chunk 1 returned %" PRId32 ", expected 0: ", r); - result = 0; - FLOWLOCK_UNLOCK(&f); - goto end; - } FLOWLOCK_UNLOCK(&f); + FAIL_IF(r != 0); FLOWLOCK_WRLOCK(&f); r = AppLayerParserParse(alp_tctx, &f, ALPROTO_TLS, STREAM_TOSERVER, buf2, buf2_len); - if (r != 0) { - printf("toserver chunk 1 returned %" PRId32 ", expected 0: ", r); - result = 0; - FLOWLOCK_UNLOCK(&f); - goto end; - } FLOWLOCK_UNLOCK(&f); + FAIL_IF(r != 0); SSLState *ssl_state = f.alstate; - if (ssl_state == NULL) { - printf("no tls state: "); - result = 0; - goto end; - } + FAIL_IF_NULL(ssl_state); - if (ssl_state->client_connp.content_type != 0x16) { - printf("expected content_type %" PRIu8 ", got %" PRIu8 ": ", 0x17, - ssl_state->client_connp.content_type); - result = 0; - goto end; - } + FAIL_IF(ssl_state->client_connp.content_type != 0x16); - if (ssl_state->client_connp.version != SSL_VERSION_3) { - printf("expected version %04" PRIu16 ", got %04" PRIu16 ": ", - SSL_VERSION_3, ssl_state->client_connp.version); - result = 0; - goto end; - } + FAIL_IF(ssl_state->client_connp.version != SSL_VERSION_3); -end: - if (alp_tctx != NULL) - AppLayerParserThreadCtxFree(alp_tctx); + AppLayerParserThreadCtxFree(alp_tctx); StreamTcpFreeConfig(TRUE); FLOW_DESTROY(&f); - return result; + + PASS; } /** @@ -2968,7 +2719,6 @@ end: */ static int SSLParserTest12(void) { - int result = 1; Flow f; uint8_t buf1[] = { 0x16, 0x03, 0x00, 0x00, 0x4c, 0x01, @@ -3006,61 +2756,31 @@ static int SSLParserTest12(void) FLOWLOCK_WRLOCK(&f); int r = AppLayerParserParse(alp_tctx, &f, ALPROTO_TLS, STREAM_TOSERVER, buf1, buf1_len); - if (r != 0) { - printf("toserver chunk 1 returned %" PRId32 ", expected 0: ", r); - result = 0; - FLOWLOCK_UNLOCK(&f); - goto end; - } FLOWLOCK_UNLOCK(&f); + FAIL_IF(r != 0); FLOWLOCK_WRLOCK(&f); r = AppLayerParserParse(alp_tctx, &f, ALPROTO_TLS, STREAM_TOSERVER, buf2, buf2_len); - if (r != 0) { - printf("toserver chunk 1 returned %" PRId32 ", expected 0: ", r); - result = 0; - FLOWLOCK_UNLOCK(&f); - goto end; - } FLOWLOCK_UNLOCK(&f); + FAIL_IF(r != 0); FLOWLOCK_WRLOCK(&f); r = AppLayerParserParse(alp_tctx, &f, ALPROTO_TLS, STREAM_TOSERVER, buf3, buf3_len); - if (r != 0) { - printf("toserver chunk 1 returned %" PRId32 ", expected 0: ", r); - result = 0; - FLOWLOCK_UNLOCK(&f); - goto end; - } FLOWLOCK_UNLOCK(&f); + FAIL_IF(r != 0); SSLState *ssl_state = f.alstate; - if (ssl_state == NULL) { - printf("no tls state: "); - result = 0; - goto end; - } + FAIL_IF_NULL(ssl_state); - if (ssl_state->client_connp.content_type != 0x16) { - printf("expected content_type %" PRIu8 ", got %" PRIu8 ": ", 0x17, - ssl_state->client_connp.content_type); - result = 0; - goto end; - } + FAIL_IF(ssl_state->client_connp.content_type != 0x16); - if (ssl_state->client_connp.version != SSL_VERSION_3) { - printf("expected version %04" PRIu16 ", got %04" PRIu16 ": ", - SSL_VERSION_3, ssl_state->client_connp.version); - result = 0; - goto end; - } + FAIL_IF(ssl_state->client_connp.version != SSL_VERSION_3); -end: - if (alp_tctx != NULL) - AppLayerParserThreadCtxFree(alp_tctx); + AppLayerParserThreadCtxFree(alp_tctx); StreamTcpFreeConfig(TRUE); FLOW_DESTROY(&f); - return result; + + PASS; } /** @@ -3068,7 +2788,6 @@ end: */ static int SSLParserTest13(void) { - int result = 1; Flow f; uint8_t buf1[] = { 0x16, 0x03, 0x00, 0x00, 0x4c, 0x01, @@ -3111,71 +2830,36 @@ static int SSLParserTest13(void) FLOWLOCK_WRLOCK(&f); int r = AppLayerParserParse(alp_tctx, &f, ALPROTO_TLS, STREAM_TOSERVER, buf1, buf1_len); - if (r != 0) { - printf("toserver chunk 1 returned %" PRId32 ", expected 0: ", r); - result = 0; - FLOWLOCK_UNLOCK(&f); - goto end; - } FLOWLOCK_UNLOCK(&f); + FAIL_IF(r != 0); FLOWLOCK_WRLOCK(&f); r = AppLayerParserParse(alp_tctx, &f, ALPROTO_TLS, STREAM_TOSERVER, buf2, buf2_len); - if (r != 0) { - printf("toserver chunk 1 returned %" PRId32 ", expected 0: ", r); - result = 0; - FLOWLOCK_UNLOCK(&f); - goto end; - } FLOWLOCK_UNLOCK(&f); + FAIL_IF(r != 0); FLOWLOCK_WRLOCK(&f); r = AppLayerParserParse(alp_tctx, &f, ALPROTO_TLS, STREAM_TOSERVER, buf3, buf3_len); - if (r != 0) { - printf("toserver chunk 1 returned %" PRId32 ", expected 0: ", r); - result = 0; - FLOWLOCK_UNLOCK(&f); - goto end; - } FLOWLOCK_UNLOCK(&f); + FAIL_IF(r != 0); FLOWLOCK_WRLOCK(&f); r = AppLayerParserParse(alp_tctx, &f, ALPROTO_TLS, STREAM_TOSERVER, buf4, buf4_len); - if (r != 0) { - printf("toserver chunk 1 returned %" PRId32 ", expected 0: ", r); - result = 0; - FLOWLOCK_UNLOCK(&f); - goto end; - } FLOWLOCK_UNLOCK(&f); + FAIL_IF(r != 0); SSLState *ssl_state = f.alstate; - if (ssl_state == NULL) { - printf("no tls state: "); - result = 0; - goto end; - } + FAIL_IF_NULL(ssl_state); - if (ssl_state->client_connp.content_type != 0x16) { - printf("expected content_type %" PRIu8 ", got %" PRIu8 ": ", 0x17, - ssl_state->client_connp.content_type); - result = 0; - goto end; - } + FAIL_IF(ssl_state->client_connp.content_type != 0x16); - if (ssl_state->client_connp.version != SSL_VERSION_3) { - printf("expected version %04" PRIu16 ", got %04" PRIu16 ": ", - SSL_VERSION_3, ssl_state->client_connp.version); - result = 0; - goto end; - } + FAIL_IF(ssl_state->client_connp.version != SSL_VERSION_3); -end: - if (alp_tctx != NULL) - AppLayerParserThreadCtxFree(alp_tctx); + AppLayerParserThreadCtxFree(alp_tctx); StreamTcpFreeConfig(TRUE); FLOW_DESTROY(&f); - return result; + + PASS; } /** @@ -3183,7 +2867,6 @@ end: */ static int SSLParserTest14(void) { - int result = 1; Flow f; uint8_t buf1[] = { @@ -3209,37 +2892,22 @@ static int SSLParserTest14(void) FLOWLOCK_WRLOCK(&f); int r = AppLayerParserParse(alp_tctx, &f, ALPROTO_TLS, STREAM_TOSERVER, buf1, buf1_len); - if (r != 0) { - printf("toserver chunk 1 returned %" PRId32 ", expected 0: ", r); - result = 0; - FLOWLOCK_UNLOCK(&f); - goto end; - } FLOWLOCK_UNLOCK(&f); + FAIL_IF(r != 0); FLOWLOCK_WRLOCK(&f); r = AppLayerParserParse(alp_tctx, &f, ALPROTO_TLS, STREAM_TOSERVER, buf2, buf2_len); - if (r != 0) { - printf("toserver chunk 1 returned %" PRId32 ", expected 0: ", r); - result = 0; - FLOWLOCK_UNLOCK(&f); - goto end; - } FLOWLOCK_UNLOCK(&f); + FAIL_IF(r != 0); SSLState *ssl_state = f.alstate; - if (ssl_state == NULL) { - printf("no tls state: "); - result = 0; - goto end; - } + FAIL_IF_NULL(ssl_state); -end: - if (alp_tctx != NULL) - AppLayerParserThreadCtxFree(alp_tctx); + AppLayerParserThreadCtxFree(alp_tctx); StreamTcpFreeConfig(TRUE); FLOW_DESTROY(&f); - return result; + + PASS; } /** @@ -3247,7 +2915,6 @@ end: */ static int SSLParserTest15(void) { - int result = 1; Flow f; uint8_t buf1[] = { @@ -3268,20 +2935,14 @@ static int SSLParserTest15(void) FLOWLOCK_WRLOCK(&f); int r = AppLayerParserParse(alp_tctx, &f, ALPROTO_TLS, STREAM_TOSERVER, buf1, buf1_len); - if (r == 0) { - printf("toserver chunk 1 returned %" PRId32 ", expected 0: ", r); - result = 0; - FLOWLOCK_UNLOCK(&f); - goto end; - } - FLOWLOCK_UNLOCK(&f); - -end: - if (alp_tctx != NULL) - AppLayerParserThreadCtxFree(alp_tctx); + FLOWLOCK_UNLOCK(&f); + FAIL_IF(r == 0); + + AppLayerParserThreadCtxFree(alp_tctx); StreamTcpFreeConfig(TRUE); FLOW_DESTROY(&f); - return result; + + PASS; } /** @@ -3289,7 +2950,6 @@ end: */ static int SSLParserTest16(void) { - int result = 1; Flow f; uint8_t buf1[] = { @@ -3310,20 +2970,14 @@ static int SSLParserTest16(void) FLOWLOCK_WRLOCK(&f); int r = AppLayerParserParse(alp_tctx, &f, ALPROTO_TLS, STREAM_TOSERVER, buf1, buf1_len); - if (r == 0) { - printf("toserver chunk 1 returned %" PRId32 ", expected 0: ", r); - result = 0; - FLOWLOCK_UNLOCK(&f); - goto end; - } FLOWLOCK_UNLOCK(&f); + FAIL_IF(r == 0); -end: - if (alp_tctx != NULL) - AppLayerParserThreadCtxFree(alp_tctx); + AppLayerParserThreadCtxFree(alp_tctx); StreamTcpFreeConfig(TRUE); FLOW_DESTROY(&f); - return result; + + PASS; } /** @@ -3331,7 +2985,6 @@ end: */ static int SSLParserTest17(void) { - int result = 1; Flow f; uint8_t buf1[] = { @@ -3352,20 +3005,14 @@ static int SSLParserTest17(void) FLOWLOCK_WRLOCK(&f); int r = AppLayerParserParse(alp_tctx, &f, ALPROTO_TLS, STREAM_TOSERVER, buf1, buf1_len); - if (r == 0) { - printf("toserver chunk 1 returned %" PRId32 ", expected 0: ", r); - result = 0; - FLOWLOCK_UNLOCK(&f); - goto end; - } FLOWLOCK_UNLOCK(&f); + FAIL_IF(r == 0); -end: - if (alp_tctx != NULL) - AppLayerParserThreadCtxFree(alp_tctx); + AppLayerParserThreadCtxFree(alp_tctx); StreamTcpFreeConfig(TRUE); FLOW_DESTROY(&f); - return result; + + PASS; } /** @@ -3373,7 +3020,6 @@ end: */ static int SSLParserTest18(void) { - int result = 1; Flow f; uint8_t buf1[] = { @@ -3400,37 +3046,22 @@ static int SSLParserTest18(void) FLOWLOCK_WRLOCK(&f); int r = AppLayerParserParse(alp_tctx, &f, ALPROTO_TLS, STREAM_TOSERVER, buf1, buf1_len); - if (r != 0) { - printf("toserver chunk 1 returned %" PRId32 ", expected 0: ", r); - result = 0; - FLOWLOCK_UNLOCK(&f); - goto end; - } FLOWLOCK_UNLOCK(&f); + FAIL_IF(r != 0); FLOWLOCK_WRLOCK(&f); r = AppLayerParserParse(alp_tctx, &f, ALPROTO_TLS, STREAM_TOSERVER, buf2, buf2_len); - if (r != 0) { - printf("toserver chunk 1 returned %" PRId32 ", expected 0: ", r); - result = 0; - FLOWLOCK_UNLOCK(&f); - goto end; - } FLOWLOCK_UNLOCK(&f); + FAIL_IF(r != 0); SSLState *ssl_state = f.alstate; - if (ssl_state == NULL) { - printf("no tls state: "); - result = 0; - goto end; - } + FAIL_IF_NULL(ssl_state); -end: - if (alp_tctx != NULL) - AppLayerParserThreadCtxFree(alp_tctx); + AppLayerParserThreadCtxFree(alp_tctx); StreamTcpFreeConfig(TRUE); FLOW_DESTROY(&f); - return result; + + PASS; } /** @@ -3438,7 +3069,6 @@ end: */ static int SSLParserTest19(void) { - int result = 1; Flow f; uint8_t buf1[] = { @@ -3460,27 +3090,17 @@ static int SSLParserTest19(void) FLOWLOCK_WRLOCK(&f); int r = AppLayerParserParse(alp_tctx, &f, ALPROTO_TLS, STREAM_TOSERVER, buf1, buf1_len); - if (r != 0) { - printf("toserver chunk 1 returned %" PRId32 ", expected 0: ", r); - result = 0; - FLOWLOCK_UNLOCK(&f); - goto end; - } FLOWLOCK_UNLOCK(&f); + FAIL_IF(r != 0); SSLState *ssl_state = f.alstate; - if (ssl_state == NULL) { - printf("no tls state: "); - result = 0; - goto end; - } + FAIL_IF_NULL(ssl_state); -end: - if (alp_tctx != NULL) - AppLayerParserThreadCtxFree(alp_tctx); + AppLayerParserThreadCtxFree(alp_tctx); StreamTcpFreeConfig(TRUE); FLOW_DESTROY(&f); - return result; + + PASS; } /** @@ -3488,7 +3108,6 @@ end: */ static int SSLParserTest20(void) { - int result = 1; Flow f; uint8_t buf1[] = { @@ -3510,20 +3129,14 @@ static int SSLParserTest20(void) FLOWLOCK_WRLOCK(&f); int r = AppLayerParserParse(alp_tctx, &f, ALPROTO_TLS, STREAM_TOSERVER, buf1, buf1_len); - if (r == 0) { - printf("toserver chunk 1 returned %" PRId32 ", expected 0: ", r); - result = 0; - FLOWLOCK_UNLOCK(&f); - goto end; - } FLOWLOCK_UNLOCK(&f); + FAIL_IF(r == 0); -end: - if (alp_tctx != NULL) - AppLayerParserThreadCtxFree(alp_tctx); + AppLayerParserThreadCtxFree(alp_tctx); StreamTcpFreeConfig(TRUE); FLOW_DESTROY(&f); - return result; + + PASS; } /** @@ -3531,7 +3144,6 @@ end: */ static int SSLParserTest21(void) { - int result = 0; Flow f; uint8_t buf[] = { 0x80, 0x31, 0x01, 0x00, 0x02, 0x00, 0x00, 0x00, @@ -3554,38 +3166,21 @@ static int SSLParserTest21(void) FLOWLOCK_WRLOCK(&f); int r = AppLayerParserParse(alp_tctx, &f, ALPROTO_TLS, STREAM_TOSERVER | STREAM_EOF, buf, buf_len); - if (r != 0) { - printf("toserver chunk 1 returned %" PRId32 ", expected 0: ", r); - FLOWLOCK_UNLOCK(&f); - goto end; - } FLOWLOCK_UNLOCK(&f); + FAIL_IF(r != 0); SSLState *app_state = f.alstate; - if (app_state == NULL) { - printf("no ssl state: "); - goto end; - } + FAIL_IF_NULL(app_state); - if (app_state->client_connp.content_type != SSLV2_MT_CLIENT_HELLO) { - printf("expected content_type %" PRIu8 ", got %" PRIu8 ": ", - SSLV2_MT_SERVER_HELLO, app_state->client_connp.content_type); - goto end; - } + FAIL_IF(app_state->client_connp.content_type != SSLV2_MT_CLIENT_HELLO); - if (app_state->client_connp.version != SSL_VERSION_2) { - printf("expected version %04" PRIu16 ", got %04" PRIu16 ": ", - SSL_VERSION_2, app_state->client_connp.version); - goto end; - } + FAIL_IF(app_state->client_connp.version != SSL_VERSION_2); - result = 1; -end: - if (alp_tctx != NULL) - AppLayerParserThreadCtxFree(alp_tctx); + AppLayerParserThreadCtxFree(alp_tctx); StreamTcpFreeConfig(TRUE); FLOW_DESTROY(&f); - return result; + + PASS; } /** @@ -3593,7 +3188,6 @@ end: */ static int SSLParserTest22(void) { - int result = 1; Flow f; uint8_t buf[] = { 0x80, 0x31, 0x04, 0x00, 0x01, 0x00, @@ -3621,40 +3215,21 @@ static int SSLParserTest22(void) FLOWLOCK_WRLOCK(&f); int r = AppLayerParserParse(alp_tctx, &f, ALPROTO_TLS, STREAM_TOCLIENT | STREAM_EOF, buf, buf_len); - if (r != 0) { - printf("toserver chunk 1 returned %" PRId32 ", expected 0: ", r); - result = 0; - FLOWLOCK_UNLOCK(&f); - goto end; - } FLOWLOCK_UNLOCK(&f); + FAIL_IF(r != 0); SSLState *app_state = f.alstate; - if (app_state == NULL) { - printf("no ssl state: "); - result = 0; - goto end; - } + FAIL_IF_NULL(app_state); - if (app_state->server_connp.content_type != SSLV2_MT_SERVER_HELLO) { - printf("expected content_type %" PRIu8 ", got %" PRIu8 ": ", - SSLV2_MT_SERVER_HELLO, app_state->server_connp.content_type); - result = 0; - goto end; - } + FAIL_IF(app_state->server_connp.content_type != SSLV2_MT_SERVER_HELLO); - if (app_state->server_connp.version != SSL_VERSION_2) { - printf("expected version %04" PRIu16 ", got %04" PRIu16 ": ", - SSL_VERSION_2, app_state->server_connp.version); - result = 0; - goto end; - } -end: - if (alp_tctx != NULL) - AppLayerParserThreadCtxFree(alp_tctx); + FAIL_IF(app_state->server_connp.version != SSL_VERSION_2); + + AppLayerParserThreadCtxFree(alp_tctx); StreamTcpFreeConfig(TRUE); FLOW_DESTROY(&f); - return result; + + PASS; } /** @@ -3662,7 +3237,6 @@ end: */ static int SSLParserTest23(void) { - int result = 1; Flow f; uint8_t chello_buf[] = { 0x80, 0x67, 0x01, 0x03, 0x00, 0x00, 0x4e, 0x00, @@ -3926,209 +3500,103 @@ static int SSLParserTest23(void) FLOWLOCK_WRLOCK(&f); int r = AppLayerParserParse(alp_tctx, &f, ALPROTO_TLS, STREAM_TOSERVER | STREAM_START, chello_buf, chello_buf_len); - if (r != 0) { - printf("toserver chunk 1 returned %" PRId32 ", expected 0: ", r); - result = 0; - FLOWLOCK_UNLOCK(&f); - goto end; - } FLOWLOCK_UNLOCK(&f); + FAIL_IF(r != 0); SSLState *app_state = f.alstate; - if (app_state == NULL) { - printf("no ssl state: "); - result = 0; - goto end; - } - - if (app_state->client_connp.content_type != SSLV2_MT_CLIENT_HELLO) { - printf("expected content_type %" PRIu8 ", got %" PRIu8 ": ", - SSLV2_MT_CLIENT_HELLO, app_state->client_connp.content_type); - result = 0; - goto end; - } + FAIL_IF_NULL(app_state); - if (app_state->client_connp.version != SSL_VERSION_2) { - printf("expected version %04" PRIu16 ", got %04" PRIu16 ": ", - SSL_VERSION_2, app_state->client_connp.version); - result = 0; - goto end; - } + FAIL_IF(app_state->client_connp.content_type != SSLV2_MT_CLIENT_HELLO); - if ((app_state->flags & SSL_AL_FLAG_STATE_CLIENT_HELLO) == 0 || - (app_state->flags & SSL_AL_FLAG_SSL_CLIENT_HS) == 0 || - (app_state->flags & SSL_AL_FLAG_SSL_NO_SESSION_ID) == 0) { - printf("flags not set\n"); - result = 0; - goto end; - } + FAIL_IF(app_state->client_connp.version != SSL_VERSION_2); + FAIL_IF((app_state->flags & SSL_AL_FLAG_STATE_CLIENT_HELLO) == 0); + FAIL_IF((app_state->flags & SSL_AL_FLAG_SSL_CLIENT_HS) == 0); + FAIL_IF((app_state->flags & SSL_AL_FLAG_SSL_NO_SESSION_ID) == 0); FLOWLOCK_WRLOCK(&f); r = AppLayerParserParse(alp_tctx, &f, ALPROTO_TLS, STREAM_TOCLIENT, shello_buf, shello_buf_len); - if (r != 0) { - printf("toclient chunk 1 returned %" PRId32 ", expected 0: ", r); - result = 0; - FLOWLOCK_UNLOCK(&f); - goto end; - } FLOWLOCK_UNLOCK(&f); + FAIL_IF(r != 0); - if (app_state->server_connp.content_type != SSLV3_HANDSHAKE_PROTOCOL) { - printf("expected content_type %" PRIu8 ", got %" PRIu8 ": ", - SSLV3_HANDSHAKE_PROTOCOL, app_state->server_connp.content_type); - result = 0; - goto end; - } + FAIL_IF(app_state->server_connp.content_type != SSLV3_HANDSHAKE_PROTOCOL); - if (app_state->server_connp.version != SSL_VERSION_3) { - printf("expected version %04" PRIu16 ", got %04" PRIu16 ": ", - SSL_VERSION_3, app_state->server_connp.version); - result = 0; - goto end; - } + FAIL_IF(app_state->server_connp.version != SSL_VERSION_3); - if ((app_state->flags & SSL_AL_FLAG_STATE_CLIENT_HELLO) == 0 || - (app_state->flags & SSL_AL_FLAG_SSL_CLIENT_HS) == 0 || - (app_state->flags & SSL_AL_FLAG_SSL_NO_SESSION_ID) == 0 || - (app_state->flags & SSL_AL_FLAG_STATE_SERVER_HELLO) == 0) { - printf("flags not set\n"); - result = 0; - goto end; - } + FAIL_IF((app_state->flags & SSL_AL_FLAG_STATE_CLIENT_HELLO) == 0); + FAIL_IF((app_state->flags & SSL_AL_FLAG_SSL_CLIENT_HS) == 0); + FAIL_IF((app_state->flags & SSL_AL_FLAG_SSL_NO_SESSION_ID) == 0); + FAIL_IF((app_state->flags & SSL_AL_FLAG_STATE_SERVER_HELLO) == 0); FLOWLOCK_WRLOCK(&f); r = AppLayerParserParse(alp_tctx, &f, ALPROTO_TLS, STREAM_TOSERVER, client_change_cipher_spec_buf, client_change_cipher_spec_buf_len); - if (r != 0) { - printf("toserver chunk 1 returned %" PRId32 ", expected 0: ", r); - result = 0; - FLOWLOCK_UNLOCK(&f); - goto end; - } FLOWLOCK_UNLOCK(&f); + FAIL_IF(r != 0); /* with multiple records the client content type hold the type from the last * record */ - if (app_state->client_connp.content_type != SSLV3_HANDSHAKE_PROTOCOL) { - printf("expected content_type %" PRIu8 ", got %" PRIu8 ": ", - SSLV3_HANDSHAKE_PROTOCOL, app_state->client_connp.content_type); - result = 0; - goto end; - } + FAIL_IF(app_state->client_connp.content_type != SSLV3_HANDSHAKE_PROTOCOL); - if (app_state->client_connp.version != SSL_VERSION_3) { - printf("expected version %04" PRIu16 ", got %04" PRIu16 ": ", - SSL_VERSION_3, app_state->client_connp.version); - result = 0; - goto end; - } + FAIL_IF(app_state->client_connp.version != SSL_VERSION_3); - if ((app_state->flags & SSL_AL_FLAG_STATE_CLIENT_HELLO) == 0 || - (app_state->flags & SSL_AL_FLAG_SSL_CLIENT_HS) == 0 || - (app_state->flags & SSL_AL_FLAG_SSL_NO_SESSION_ID) == 0 || - (app_state->flags & SSL_AL_FLAG_STATE_SERVER_HELLO) == 0 || - (app_state->flags & SSL_AL_FLAG_STATE_CLIENT_KEYX) == 0 || - (app_state->flags & SSL_AL_FLAG_CLIENT_CHANGE_CIPHER_SPEC) == 0 || - (app_state->flags & SSL_AL_FLAG_CHANGE_CIPHER_SPEC) == 0) { - printf("flags not set\n"); - result = 0; - goto end; - } + FAIL_IF((app_state->flags & SSL_AL_FLAG_STATE_CLIENT_HELLO) == 0); + FAIL_IF((app_state->flags & SSL_AL_FLAG_SSL_CLIENT_HS) == 0); + FAIL_IF((app_state->flags & SSL_AL_FLAG_SSL_NO_SESSION_ID) == 0); + FAIL_IF((app_state->flags & SSL_AL_FLAG_STATE_SERVER_HELLO) == 0); + FAIL_IF((app_state->flags & SSL_AL_FLAG_STATE_CLIENT_KEYX) == 0); + FAIL_IF((app_state->flags & SSL_AL_FLAG_CLIENT_CHANGE_CIPHER_SPEC) == 0); + FAIL_IF((app_state->flags & SSL_AL_FLAG_CHANGE_CIPHER_SPEC) == 0); FLOWLOCK_WRLOCK(&f); r = AppLayerParserParse(alp_tctx, &f, ALPROTO_TLS, STREAM_TOCLIENT, server_change_cipher_spec_buf, server_change_cipher_spec_buf_len); - if (r != 0) { - printf("toclient chunk 1 returned %" PRId32 ", expected 0: ", r); - result = 0; - FLOWLOCK_UNLOCK(&f); - goto end; - } FLOWLOCK_UNLOCK(&f); + FAIL_IF(r != 0); /* with multiple records the serve content type hold the type from the last * record */ - if (app_state->server_connp.content_type != SSLV3_HANDSHAKE_PROTOCOL) { - printf("expected content_type %" PRIu8 ", got %" PRIu8 ": ", - SSLV3_HANDSHAKE_PROTOCOL, app_state->server_connp.content_type); - result = 0; - goto end; - } + FAIL_IF(app_state->server_connp.content_type != SSLV3_HANDSHAKE_PROTOCOL); - if (app_state->server_connp.version != SSL_VERSION_3) { - printf("expected version %04" PRIu16 ", got %04" PRIu16 ": ", - SSL_VERSION_3, app_state->server_connp.version); - result = 0; - goto end; - } + FAIL_IF(app_state->server_connp.version != SSL_VERSION_3); - if ((app_state->flags & SSL_AL_FLAG_STATE_CLIENT_HELLO) == 0 || - (app_state->flags & SSL_AL_FLAG_SSL_CLIENT_HS) == 0 || - (app_state->flags & SSL_AL_FLAG_SSL_NO_SESSION_ID) == 0 || - (app_state->flags & SSL_AL_FLAG_STATE_SERVER_HELLO) == 0 || - (app_state->flags & SSL_AL_FLAG_STATE_CLIENT_KEYX) == 0 || - (app_state->flags & SSL_AL_FLAG_CLIENT_CHANGE_CIPHER_SPEC) == 0 || - (app_state->flags & SSL_AL_FLAG_CHANGE_CIPHER_SPEC) == 0 || - (app_state->flags & SSL_AL_FLAG_SERVER_CHANGE_CIPHER_SPEC) == 0 || - (app_state->flags & SSL_AL_FLAG_CHANGE_CIPHER_SPEC) == 0) { - printf("flags not set\n"); - result = 0; - goto end; - } + FAIL_IF((app_state->flags & SSL_AL_FLAG_STATE_CLIENT_HELLO) == 0); + FAIL_IF((app_state->flags & SSL_AL_FLAG_SSL_CLIENT_HS) == 0); + FAIL_IF((app_state->flags & SSL_AL_FLAG_SSL_NO_SESSION_ID) == 0); + FAIL_IF((app_state->flags & SSL_AL_FLAG_STATE_SERVER_HELLO) == 0); + FAIL_IF((app_state->flags & SSL_AL_FLAG_STATE_CLIENT_KEYX) == 0); + FAIL_IF((app_state->flags & SSL_AL_FLAG_CLIENT_CHANGE_CIPHER_SPEC) == 0); + FAIL_IF((app_state->flags & SSL_AL_FLAG_SERVER_CHANGE_CIPHER_SPEC) == 0); + FAIL_IF((app_state->flags & SSL_AL_FLAG_CHANGE_CIPHER_SPEC) == 0); FLOWLOCK_WRLOCK(&f); r = AppLayerParserParse(alp_tctx, &f, ALPROTO_TLS, STREAM_TOSERVER, toserver_app_data_buf, toserver_app_data_buf_len); - if (r != 0) { - printf("toserver chunk 1 returned %" PRId32 ", expected 0: ", r); - result = 0; - FLOWLOCK_UNLOCK(&f); - goto end; - } FLOWLOCK_UNLOCK(&f); + FAIL_IF(r != 0); - if (app_state->client_connp.content_type != SSLV3_APPLICATION_PROTOCOL) { - printf("expected content_type %" PRIu8 ", got %" PRIu8 ": ", - SSLV3_APPLICATION_PROTOCOL, app_state->client_connp.content_type); - result = 0; - goto end; - } + FAIL_IF(app_state->client_connp.content_type != SSLV3_APPLICATION_PROTOCOL); - if (app_state->client_connp.version != SSL_VERSION_3) { - printf("expected version %04" PRIu16 ", got %04" PRIu16 ": ", - SSL_VERSION_3, app_state->client_connp.version); - result = 0; - goto end; - } + FAIL_IF(app_state->client_connp.version != SSL_VERSION_3); - if ((app_state->flags & SSL_AL_FLAG_STATE_CLIENT_HELLO) == 0 || - (app_state->flags & SSL_AL_FLAG_SSL_CLIENT_HS) == 0 || - (app_state->flags & SSL_AL_FLAG_SSL_NO_SESSION_ID) == 0 || - (app_state->flags & SSL_AL_FLAG_STATE_SERVER_HELLO) == 0 || - (app_state->flags & SSL_AL_FLAG_STATE_CLIENT_KEYX) == 0 || - (app_state->flags & SSL_AL_FLAG_CLIENT_CHANGE_CIPHER_SPEC) == 0 || - (app_state->flags & SSL_AL_FLAG_CHANGE_CIPHER_SPEC) == 0 || - (app_state->flags & SSL_AL_FLAG_SERVER_CHANGE_CIPHER_SPEC) == 0 || - (app_state->flags & SSL_AL_FLAG_CHANGE_CIPHER_SPEC) == 0) { - printf("flags not set\n"); - result = 0; - goto end; - } + FAIL_IF((app_state->flags & SSL_AL_FLAG_STATE_CLIENT_HELLO) == 0); + FAIL_IF((app_state->flags & SSL_AL_FLAG_SSL_CLIENT_HS) == 0); + FAIL_IF((app_state->flags & SSL_AL_FLAG_SSL_NO_SESSION_ID) == 0); + FAIL_IF((app_state->flags & SSL_AL_FLAG_STATE_SERVER_HELLO) == 0); + FAIL_IF((app_state->flags & SSL_AL_FLAG_STATE_CLIENT_KEYX) == 0); + FAIL_IF((app_state->flags & SSL_AL_FLAG_CLIENT_CHANGE_CIPHER_SPEC) == 0); + FAIL_IF((app_state->flags & SSL_AL_FLAG_SERVER_CHANGE_CIPHER_SPEC) == 0); + FAIL_IF((app_state->flags & SSL_AL_FLAG_CHANGE_CIPHER_SPEC) == 0); - if (!(f.flags & FLOW_NOPAYLOAD_INSPECTION)) { - printf("The flags should be set\n"); - result = 0; - goto end; - } + FAIL_IF_NOT(f.flags & FLOW_NOPAYLOAD_INSPECTION); -end: if (alp_tctx != NULL) AppLayerParserThreadCtxFree(alp_tctx); StreamTcpFreeConfig(TRUE); FLOW_DESTROY(&f); - return result; + + PASS; } /** @@ -4136,7 +3604,6 @@ end: */ static int SSLParserTest24(void) { - int result = 1; Flow f; uint8_t buf1[] = { 0x16, 0x03, 0x00, 0x00, 0x6f, 0x01, 0x00, 0x00, @@ -4174,51 +3641,26 @@ static int SSLParserTest24(void) FLOWLOCK_WRLOCK(&f); int r = AppLayerParserParse(alp_tctx, &f, ALPROTO_TLS, STREAM_TOSERVER, buf1, buf1_len); - if (r != 0) { - printf("toserver chunk 1 returned %" PRId32 ", expected 0: ", r); - result = 0; - FLOWLOCK_UNLOCK(&f); - goto end; - } FLOWLOCK_UNLOCK(&f); + FAIL_IF(r != 0); FLOWLOCK_WRLOCK(&f); r = AppLayerParserParse(alp_tctx, &f, ALPROTO_TLS, STREAM_TOSERVER, buf2, buf2_len); - if (r != 0) { - printf("toserver chunk 1 returned %" PRId32 ", expected 0: ", r); - result = 0; - FLOWLOCK_UNLOCK(&f); - goto end; - } FLOWLOCK_UNLOCK(&f); + FAIL_IF(r != 0); SSLState *ssl_state = f.alstate; - if (ssl_state == NULL) { - printf("no tls state: "); - result = 0; - goto end; - } + FAIL_IF_NULL(ssl_state); - if (ssl_state->client_connp.content_type != 0x16) { - printf("expected content_type %" PRIu8 ", got %" PRIu8 ": ", 0x16, - ssl_state->client_connp.content_type); - result = 0; - goto end; - } + FAIL_IF(ssl_state->client_connp.content_type != 0x16); - if (ssl_state->client_connp.version != SSL_VERSION_3) { - printf("expected version %04" PRIu16 ", got %04" PRIu16 ": ", - SSL_VERSION_3, ssl_state->client_connp.version); - result = 0; - goto end; - } + FAIL_IF(ssl_state->client_connp.version != SSL_VERSION_3); -end: - if (alp_tctx != NULL) - AppLayerParserThreadCtxFree(alp_tctx); + AppLayerParserThreadCtxFree(alp_tctx); StreamTcpFreeConfig(TRUE); FLOW_DESTROY(&f); - return result; + + PASS; } /** @@ -4227,7 +3669,6 @@ end: */ static int SSLParserTest25(void) { - int result = 0; Flow f; uint8_t client_hello[] = { 0x16, 0x03, 0x01, 0x00, 0xd3, 0x01, 0x00, 0x00, @@ -4555,54 +3996,31 @@ static int SSLParserTest25(void) FLOWLOCK_WRLOCK(&f); int r = AppLayerParserParse(alp_tctx, &f, ALPROTO_TLS, STREAM_TOSERVER, client_hello, client_hello_len); - if (r != 0) { - printf("toserver chunk 1 returned %" PRId32 ", expected 0: ", r); - FLOWLOCK_UNLOCK(&f); - goto end; - } FLOWLOCK_UNLOCK(&f); + FAIL_IF(r != 0); SSLState *ssl_state = f.alstate; - if (ssl_state == NULL) { - printf("no tls state: "); - goto end; - } + FAIL_IF_NULL(ssl_state); - if (ssl_state->client_connp.bytes_processed != 0 || - ssl_state->client_connp.hs_bytes_processed != 0) - { - printf("client_hello error\n"); - goto end; - } + FAIL_IF(ssl_state->client_connp.bytes_processed != 0); + FAIL_IF(ssl_state->client_connp.hs_bytes_processed != 0); FLOWLOCK_WRLOCK(&f); r = AppLayerParserParse(alp_tctx, &f, ALPROTO_TLS, STREAM_TOCLIENT, server_hello_certificate_done, server_hello_certificate_done_len); - if (r != 0) { - printf("toserver chunk 1 returned %" PRId32 ", expected 0: ", r); - FLOWLOCK_UNLOCK(&f); - goto end; - } FLOWLOCK_UNLOCK(&f); + FAIL_IF(r != 0); - if (ssl_state->client_connp.bytes_processed != 0 || - ssl_state->client_connp.hs_bytes_processed != 0) - { - printf("server_hello_certificate_done error\n"); - goto end; - } + FAIL_IF(ssl_state->client_connp.bytes_processed != 0); + FAIL_IF(ssl_state->client_connp.hs_bytes_processed != 0); FLOWLOCK_WRLOCK(&f); r = AppLayerParserParse(alp_tctx, &f, ALPROTO_TLS, STREAM_TOSERVER, client_key_exchange_cipher_enc_hs, client_key_exchange_cipher_enc_hs_len); - if (r != 0) { - printf("toserver chunk 1 returned %" PRId32 ", expected 0: ", r); - FLOWLOCK_UNLOCK(&f); - goto end; - } FLOWLOCK_UNLOCK(&f); + FAIL_IF(r != 0); /* The reason hs_bytes_processed is 2 is because, the record * immediately after the client key exchange is 2 bytes long, @@ -4611,20 +4029,14 @@ static int SSLParserTest25(void) * handshake, we immediately break and don't parse the pdu from * where we left off, and leave the hs_bytes_processed var * isn't reset. */ - if (ssl_state->client_connp.bytes_processed != 0 || - ssl_state->client_connp.hs_bytes_processed != 2) - { - printf("client_key_exchange_cipher_enc_hs error\n"); - goto end; - } + FAIL_IF(ssl_state->client_connp.bytes_processed != 0); + FAIL_IF(ssl_state->client_connp.hs_bytes_processed != 2); - result = 1; -end: - if (alp_tctx != NULL) - AppLayerParserThreadCtxFree(alp_tctx); + AppLayerParserThreadCtxFree(alp_tctx); StreamTcpFreeConfig(TRUE); FLOW_DESTROY(&f); - return result; + + PASS; } #endif /* UNITTESTS */