suricata
detect-ssl-version.c
Go to the documentation of this file.
1/* Copyright (C) 2007-2019 Open Information Security Foundation
2 *
3 * You can copy, redistribute or modify this Program under the terms of
4 * the GNU General Public License version 2 as published by the Free
5 * Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * version 2 along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15 * 02110-1301, USA.
16 */
17
18/**
19 * \file detect-ssl-version.c
20 *
21 * \author Gurvinder Singh <gurvindersinghdahiya@gmail.com>
22 *
23 */
24
25#include "detect-engine-build.h"
26
27/**
28 * \test DetectSslVersionTestParse01 is a test to make sure that we parse the
29 * "ssl_version" option correctly when given valid ssl_version option
30 */
31static int DetectSslVersionTestParse01(void)
32{
33 DetectSslVersionData *ssl = NULL;
34 ssl = DetectSslVersionParse(NULL, "SSlv3");
35 FAIL_IF_NULL(ssl);
36 FAIL_IF_NOT(ssl->data[SSLv3].ver == SSL_VERSION_3);
37 DetectSslVersionFree(NULL, ssl);
38 PASS;
39}
40
41/**
42 * \test DetectSslVersionTestParse02 is a test to make sure that we parse the
43 * "ssl_version" option correctly when given an invalid ssl_version option
44 * it should return ssl = NULL
45 */
46static int DetectSslVersionTestParse02(void)
47{
48 DetectSslVersionData *ssl = NULL;
49 ssl = DetectSslVersionParse(NULL, "2.5");
51 DetectSslVersionFree(NULL, ssl);
52 ssl = DetectSslVersionParse(NULL, "tls1.0, !");
54 DetectSslVersionFree(NULL, ssl);
55 ssl = DetectSslVersionParse(NULL, "tls1.0, !tls1.0");
57 DetectSslVersionFree(NULL, ssl);
58 ssl = DetectSslVersionParse(NULL, "tls1.1, tls1.1");
60 DetectSslVersionFree(NULL, ssl);
61 ssl = DetectSslVersionParse(NULL, "tls1.1, !tls1.2");
63 DetectSslVersionFree(NULL, ssl);
64 PASS;
65}
66
67/**
68 * \test DetectSslVersionTestParse03 is a test to make sure that we parse the
69 * "ssl_version" options correctly when given valid ssl_version options
70 */
71static int DetectSslVersionTestParse03(void)
72{
73 DetectSslVersionData *ssl = NULL;
74 ssl = DetectSslVersionParse(NULL, "SSlv3 , tls1.0");
75 FAIL_IF_NULL(ssl);
76 FAIL_IF_NOT(ssl->data[SSLv3].ver == SSL_VERSION_3);
77 FAIL_IF_NOT(ssl->data[TLS10].ver == TLS_VERSION_10);
78 DetectSslVersionFree(NULL, ssl);
79 ssl = DetectSslVersionParse(NULL, " !tls1.2");
80 FAIL_IF_NULL(ssl);
81 FAIL_IF_NOT(ssl->data[TLS12].ver == TLS_VERSION_12);
83 DetectSslVersionFree(NULL, ssl);
84 PASS;
85}
86
87/**
88 * \brief this function registers unit tests for DetectSslVersion
89 */
90static void DetectSslVersionRegisterTests(void)
91{
92 UtRegisterTest("DetectSslVersionTestParse01", DetectSslVersionTestParse01);
93 UtRegisterTest("DetectSslVersionTestParse02", DetectSslVersionTestParse02);
94 UtRegisterTest("DetectSslVersionTestParse03", DetectSslVersionTestParse03);
95}
#define DETECT_SSL_VERSION_NEGATED
#define FAIL_IF_NULL(expr)
Fail a test if expression evaluates to NULL.
void UtRegisterTest(const char *name, int(*TestFn)(void))
Register unit test.
#define FAIL_IF_NOT(expr)
Fail a test if expression evaluates to false.
#define PASS
Pass the test.
#define FAIL_IF_NOT_NULL(expr)
Fail a test if expression evaluates to non-NULL.
SSLVersionData data[TLS_SIZE]