1*4724848cSchristos /*
2*4724848cSchristos * Copyright 2018 The OpenSSL Project Authors. All Rights Reserved.
3*4724848cSchristos *
4*4724848cSchristos * Licensed under the OpenSSL license (the "License"). You may not use
5*4724848cSchristos * this file except in compliance with the License. You can obtain a copy
6*4724848cSchristos * in the file LICENSE in the source distribution or at
7*4724848cSchristos * https://www.openssl.org/source/license.html
8*4724848cSchristos */
9*4724848cSchristos
10*4724848cSchristos #include "testutil.h"
11*4724848cSchristos #include <openssl/ssl.h>
12*4724848cSchristos
13*4724848cSchristos typedef struct {
14*4724848cSchristos int min_version;
15*4724848cSchristos int max_version;
16*4724848cSchristos int min_ok;
17*4724848cSchristos int max_ok;
18*4724848cSchristos int expected_min;
19*4724848cSchristos int expected_max;
20*4724848cSchristos } version_test;
21*4724848cSchristos
22*4724848cSchristos static const version_test version_testdata[] = {
23*4724848cSchristos /* min max ok expected min expected max */
24*4724848cSchristos {0, 0, 1, 1, 0, 0},
25*4724848cSchristos {TLS1_VERSION, TLS1_2_VERSION, 1, 1, TLS1_VERSION, TLS1_2_VERSION},
26*4724848cSchristos {TLS1_2_VERSION, TLS1_2_VERSION, 1, 1, TLS1_2_VERSION, TLS1_2_VERSION},
27*4724848cSchristos {TLS1_2_VERSION, TLS1_1_VERSION, 1, 0, TLS1_2_VERSION, 0},
28*4724848cSchristos {7, 42, 0, 0, 0, 0},
29*4724848cSchristos };
30*4724848cSchristos
test_set_min_max_version(int idx_tst)31*4724848cSchristos static int test_set_min_max_version(int idx_tst)
32*4724848cSchristos {
33*4724848cSchristos SSL_CTX *ctx = NULL;
34*4724848cSchristos SSL *ssl = NULL;
35*4724848cSchristos int testresult = 0;
36*4724848cSchristos version_test t = version_testdata[idx_tst];
37*4724848cSchristos
38*4724848cSchristos ctx = SSL_CTX_new(TLS_server_method());
39*4724848cSchristos if (ctx == NULL)
40*4724848cSchristos goto end;
41*4724848cSchristos
42*4724848cSchristos ssl = SSL_new(ctx);
43*4724848cSchristos if (ssl == NULL)
44*4724848cSchristos goto end;
45*4724848cSchristos
46*4724848cSchristos if (!TEST_int_eq(SSL_CTX_set_min_proto_version(ctx, t.min_version), t.min_ok))
47*4724848cSchristos goto end;
48*4724848cSchristos if (!TEST_int_eq(SSL_CTX_set_max_proto_version(ctx, t.max_version), t.max_ok))
49*4724848cSchristos goto end;
50*4724848cSchristos if (!TEST_int_eq(SSL_CTX_get_min_proto_version(ctx), t.expected_min))
51*4724848cSchristos goto end;
52*4724848cSchristos if (!TEST_int_eq(SSL_CTX_get_max_proto_version(ctx), t.expected_max))
53*4724848cSchristos goto end;
54*4724848cSchristos
55*4724848cSchristos if (!TEST_int_eq(SSL_set_min_proto_version(ssl, t.min_version), t.min_ok))
56*4724848cSchristos goto end;
57*4724848cSchristos if (!TEST_int_eq(SSL_set_max_proto_version(ssl, t.max_version), t.max_ok))
58*4724848cSchristos goto end;
59*4724848cSchristos if (!TEST_int_eq(SSL_get_min_proto_version(ssl), t.expected_min))
60*4724848cSchristos goto end;
61*4724848cSchristos if (!TEST_int_eq(SSL_get_max_proto_version(ssl), t.expected_max))
62*4724848cSchristos goto end;
63*4724848cSchristos
64*4724848cSchristos testresult = 1;
65*4724848cSchristos
66*4724848cSchristos end:
67*4724848cSchristos SSL_free(ssl);
68*4724848cSchristos SSL_CTX_free(ctx);
69*4724848cSchristos return testresult;
70*4724848cSchristos }
71*4724848cSchristos
setup_tests(void)72*4724848cSchristos int setup_tests(void)
73*4724848cSchristos {
74*4724848cSchristos ADD_ALL_TESTS(test_set_min_max_version, sizeof(version_testdata) / sizeof(version_test));
75*4724848cSchristos return 1;
76*4724848cSchristos }
77