diff options
author | tb <> | 2022-07-20 14:50:03 +0000 |
---|---|---|
committer | tb <> | 2022-07-20 14:50:03 +0000 |
commit | 092061456d6b13c6cbba85209f26edbbd36c79f8 (patch) | |
tree | 8bb407c3ae23e11f397a2538c7c6c25f9dd1d333 /src | |
parent | 5ae6724d02a1463d602c5981c8b42ce23b5958f1 (diff) | |
download | openbsd-092061456d6b13c6cbba85209f26edbbd36c79f8.tar.gz openbsd-092061456d6b13c6cbba85209f26edbbd36c79f8.tar.bz2 openbsd-092061456d6b13c6cbba85209f26edbbd36c79f8.zip |
Add a quick and dirty regress for SSL{_CTX,}_set_alpn_protos()
Diffstat (limited to 'src')
-rw-r--r-- | src/regress/lib/libssl/unit/ssl_set_alpn_protos.c | 156 |
1 files changed, 156 insertions, 0 deletions
diff --git a/src/regress/lib/libssl/unit/ssl_set_alpn_protos.c b/src/regress/lib/libssl/unit/ssl_set_alpn_protos.c new file mode 100644 index 0000000000..e32cf83f30 --- /dev/null +++ b/src/regress/lib/libssl/unit/ssl_set_alpn_protos.c | |||
@@ -0,0 +1,156 @@ | |||
1 | /* $OpenBSD: ssl_set_alpn_protos.c,v 1.1 2022/07/20 14:50:03 tb Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2022 Theo Buehler <tb@openbsd.org> | ||
4 | * | ||
5 | * Permission to use, copy, modify, and distribute this software for any | ||
6 | * purpose with or without fee is hereby granted, provided that the above | ||
7 | * copyright notice and this permission notice appear in all copies. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
16 | */ | ||
17 | |||
18 | #include <err.h> | ||
19 | #include <stdio.h> | ||
20 | |||
21 | #include <openssl/ssl.h> | ||
22 | |||
23 | static const uint8_t valid[] = { | ||
24 | 6, 's', 'p', 'd', 'y', '/', '1', | ||
25 | 8, 'h', 't', 't', 'p', '/', '1', '.', '1', | ||
26 | }; | ||
27 | |||
28 | static const uint8_t invalid_len1[] = { | ||
29 | 0, | ||
30 | }; | ||
31 | |||
32 | static const uint8_t invalid_contains_len0_proto[] = { | ||
33 | 8, 'h', 't', 't', 'p', '/', '1', '.', '1', | ||
34 | 0, | ||
35 | 6, 's', 'p', 'd', 'y', '/', '1', | ||
36 | }; | ||
37 | |||
38 | static const uint8_t invalid_proto_len_too_short[] = { | ||
39 | 6, 'h', 't', 't', 'p', '/', '1', '.', '1', | ||
40 | }; | ||
41 | |||
42 | static const uint8_t invalid_proto_len_too_long[] = { | ||
43 | 8, 's', 'p', 'd', 'y', '/', '1', | ||
44 | }; | ||
45 | |||
46 | static int | ||
47 | test_ssl_set_alpn_protos(void) | ||
48 | { | ||
49 | SSL_CTX *ctx; | ||
50 | SSL *ssl = NULL; | ||
51 | int failed = 0; | ||
52 | |||
53 | if ((ctx = SSL_CTX_new(TLS_client_method())) == NULL) | ||
54 | errx(1, "SSL_CTX_new"); | ||
55 | |||
56 | if (SSL_CTX_set_alpn_protos(ctx, valid, sizeof(valid)) != 0) { | ||
57 | warnx("setting valid protocols on SSL_CTX failed"); | ||
58 | failed = 1; | ||
59 | } | ||
60 | |||
61 | if (SSL_CTX_set_alpn_protos(ctx, NULL, 0) != 0) { | ||
62 | warnx("setting 'NULL, 0' on SSL_CTX failed"); | ||
63 | failed = 1; | ||
64 | } | ||
65 | if (SSL_CTX_set_alpn_protos(ctx, valid, 0) != 0) { | ||
66 | warnx("setting 'valid, 0' on SSL_CTX failed"); | ||
67 | failed = 1; | ||
68 | } | ||
69 | if (SSL_CTX_set_alpn_protos(ctx, NULL, 43) != 0) { | ||
70 | warnx("setting 'valid, 43' on SSL_CTX failed"); | ||
71 | failed = 1; | ||
72 | } | ||
73 | |||
74 | if (SSL_CTX_set_alpn_protos(ctx, invalid_len1, sizeof(invalid_len1)) | ||
75 | != 1) { | ||
76 | warnx("setting invalid_len1 on SSL_CTX succeeded"); | ||
77 | failed = 1; | ||
78 | } | ||
79 | if (SSL_CTX_set_alpn_protos(ctx, invalid_contains_len0_proto, | ||
80 | sizeof(invalid_contains_len0_proto)) != 1) { | ||
81 | warnx("setting invalid_contains_len0_proto on SSL_CTX " | ||
82 | "succeeded"); | ||
83 | failed = 1; | ||
84 | } | ||
85 | if (SSL_CTX_set_alpn_protos(ctx, invalid_proto_len_too_short, | ||
86 | sizeof(invalid_proto_len_too_short)) != 1) { | ||
87 | warnx("setting invalid_proto_len_too_short on SSL_CTX " | ||
88 | "succeeded"); | ||
89 | failed = 1; | ||
90 | } | ||
91 | if (SSL_CTX_set_alpn_protos(ctx, invalid_proto_len_too_long, | ||
92 | sizeof(invalid_proto_len_too_long)) != 1) { | ||
93 | warnx("setting invalid_proto_len_too_long on SSL_CTX " | ||
94 | "succeeded"); | ||
95 | failed = 1; | ||
96 | } | ||
97 | |||
98 | if ((ssl = SSL_new(ctx)) == NULL) | ||
99 | errx(1, "SSL_new"); | ||
100 | |||
101 | if (SSL_set_alpn_protos(ssl, valid, sizeof(valid)) != 0) { | ||
102 | warnx("setting valid protocols on SSL failed"); | ||
103 | failed = 1; | ||
104 | } | ||
105 | if (SSL_set_alpn_protos(ssl, NULL, 0) != 0) { | ||
106 | warnx("setting 'NULL, 0' on SSL failed"); | ||
107 | failed = 1; | ||
108 | } | ||
109 | if (SSL_set_alpn_protos(ssl, valid, 0) != 0) { | ||
110 | warnx("setting 'valid, 0' on SSL failed"); | ||
111 | failed = 1; | ||
112 | } | ||
113 | if (SSL_set_alpn_protos(ssl, NULL, 43) != 0) { | ||
114 | warnx("setting 'valid, 43' on SSL failed"); | ||
115 | failed = 1; | ||
116 | } | ||
117 | |||
118 | if (SSL_set_alpn_protos(ssl, invalid_len1, sizeof(invalid_len1)) | ||
119 | != 1) { | ||
120 | warnx("setting invalid_len1 on SSL succeeded"); | ||
121 | failed = 1; | ||
122 | } | ||
123 | if (SSL_set_alpn_protos(ssl, invalid_contains_len0_proto, | ||
124 | sizeof(invalid_contains_len0_proto)) != 1) { | ||
125 | warnx("setting invalid_contains_len0_proto on SSL succeeded"); | ||
126 | failed = 1; | ||
127 | } | ||
128 | if (SSL_set_alpn_protos(ssl, invalid_proto_len_too_short, | ||
129 | sizeof(invalid_proto_len_too_short)) != 1) { | ||
130 | warnx("setting invalid_proto_len_too_short on SSL succeeded"); | ||
131 | failed = 1; | ||
132 | } | ||
133 | if (SSL_set_alpn_protos(ssl, invalid_proto_len_too_long, | ||
134 | sizeof(invalid_proto_len_too_long)) != 1) { | ||
135 | warnx("setting invalid_proto_len_too_long on SSL succeeded"); | ||
136 | failed = 1; | ||
137 | } | ||
138 | |||
139 | SSL_CTX_free(ctx); | ||
140 | SSL_free(ssl); | ||
141 | |||
142 | return failed; | ||
143 | } | ||
144 | |||
145 | int | ||
146 | main(void) | ||
147 | { | ||
148 | int failed; | ||
149 | |||
150 | failed = test_ssl_set_alpn_protos(); | ||
151 | |||
152 | if (!failed) | ||
153 | printf("PASS %s\n", __FILE__); | ||
154 | |||
155 | return failed; | ||
156 | } | ||