]>
Commit | Line | Data |
---|---|---|
1bdbdaff | 1 | /* |
3c2bdd7d | 2 | * Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved. |
1bdbdaff P |
3 | * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. |
4 | * | |
5 | * Licensed under the Apache License 2.0 (the "License"). You may not use | |
6 | * this file except in compliance with the License. You can obtain a copy | |
7 | * in the file LICENSE in the source distribution or at | |
8 | * https://www.openssl.org/source/license.html | |
9 | */ | |
10 | ||
11 | #include <stdarg.h> | |
e0624f0d | 12 | #include <openssl/evp.h> |
1bdbdaff P |
13 | #include "testutil.h" |
14 | #include "internal/nelem.h" | |
15 | #include "internal/property.h" | |
706457b7 | 16 | #include "../crypto/property/property_local.h" |
1bdbdaff P |
17 | |
18 | static int add_property_names(const char *n, ...) | |
19 | { | |
20 | va_list args; | |
21 | int res = 1; | |
22 | ||
23 | va_start(args, n); | |
24 | do { | |
1aedc35f | 25 | if (!TEST_int_ne(ossl_property_name(NULL, n, 1), 0)) |
1bdbdaff P |
26 | res = 0; |
27 | } while ((n = va_arg(args, const char *)) != NULL); | |
28 | va_end(args); | |
29 | return res; | |
30 | } | |
31 | ||
bdbf2df2 P |
32 | static int up_ref(void *p) |
33 | { | |
34 | return 1; | |
35 | } | |
36 | ||
37 | static void down_ref(void *p) | |
38 | { | |
39 | } | |
40 | ||
1bdbdaff P |
41 | static int test_property_string(void) |
42 | { | |
43 | OSSL_METHOD_STORE *store; | |
44 | int res = 0; | |
45 | OSSL_PROPERTY_IDX i, j; | |
46 | ||
1aedc35f MC |
47 | if (TEST_ptr(store = ossl_method_store_new(NULL)) |
48 | && TEST_int_eq(ossl_property_name(NULL, "fnord", 0), 0) | |
49 | && TEST_int_ne(ossl_property_name(NULL, "fnord", 1), 0) | |
50 | && TEST_int_ne(ossl_property_name(NULL, "name", 1), 0) | |
1bdbdaff | 51 | /* Property value checks */ |
1aedc35f MC |
52 | && TEST_int_eq(ossl_property_value(NULL, "fnord", 0), 0) |
53 | && TEST_int_ne(i = ossl_property_value(NULL, "no", 0), 0) | |
54 | && TEST_int_ne(j = ossl_property_value(NULL, "yes", 0), 0) | |
1bdbdaff | 55 | && TEST_int_ne(i, j) |
1aedc35f MC |
56 | && TEST_int_eq(ossl_property_value(NULL, "yes", 1), j) |
57 | && TEST_int_eq(ossl_property_value(NULL, "no", 1), i) | |
58 | && TEST_int_ne(i = ossl_property_value(NULL, "illuminati", 1), 0) | |
59 | && TEST_int_eq(j = ossl_property_value(NULL, "fnord", 1), i + 1) | |
60 | && TEST_int_eq(ossl_property_value(NULL, "fnord", 1), j) | |
1bdbdaff | 61 | /* Check name and values are distinct */ |
1aedc35f MC |
62 | && TEST_int_eq(ossl_property_value(NULL, "cold", 0), 0) |
63 | && TEST_int_ne(ossl_property_name(NULL, "fnord", 0), | |
64 | ossl_property_value(NULL, "fnord", 0))) | |
1bdbdaff P |
65 | res = 1; |
66 | ossl_method_store_free(store); | |
67 | return res; | |
68 | } | |
69 | ||
70 | static const struct { | |
71 | const char *defn; | |
72 | const char *query; | |
73 | int e; | |
74 | } parser_tests[] = { | |
da89ac0b | 75 | { "", "sky=blue", -1 }, |
1bdbdaff | 76 | { "", "sky!=blue", 1 }, |
da89ac0b | 77 | { "groan", "", 0 }, |
1bdbdaff P |
78 | { "cold=yes", "cold=yes", 1 }, |
79 | { "cold=yes", "cold", 1 }, | |
80 | { "cold=yes", "cold!=no", 1 }, | |
81 | { "groan", "groan=yes", 1 }, | |
da89ac0b P |
82 | { "groan", "groan=no", -1 }, |
83 | { "groan", "groan!=yes", -1 }, | |
84 | { "cold=no", "cold", -1 }, | |
85 | { "cold=no", "?cold", 0 }, | |
1bdbdaff | 86 | { "cold=no", "cold=no", 1 }, |
da89ac0b | 87 | { "groan", "cold", -1 }, |
1bdbdaff P |
88 | { "groan", "cold=no", 1 }, |
89 | { "groan", "cold!=yes", 1 }, | |
da89ac0b P |
90 | { "groan=blue", "groan=yellow", -1 }, |
91 | { "groan=blue", "?groan=yellow", 0 }, | |
1bdbdaff | 92 | { "groan=blue", "groan!=yellow", 1 }, |
da89ac0b | 93 | { "groan=blue", "?groan!=yellow", 1 }, |
1bdbdaff | 94 | { "today=monday, tomorrow=3", "today!=2", 1 }, |
da89ac0b | 95 | { "today=monday, tomorrow=3", "today!='monday'", -1 }, |
1bdbdaff P |
96 | { "today=monday, tomorrow=3", "tomorrow=3", 1 }, |
97 | { "n=0x3", "n=3", 1 }, | |
da89ac0b | 98 | { "n=0x3", "n=-3", -1 }, |
1bdbdaff P |
99 | { "n=0x33", "n=51", 1 }, |
100 | { "n=033", "n=27", 1 }, | |
101 | { "n=0", "n=00", 1 }, | |
102 | { "n=0x0", "n=0", 1 }, | |
da89ac0b P |
103 | { "n=0, sky=blue", "?n=0, sky=blue", 2 }, |
104 | { "n=1, sky=blue", "?n=0, sky=blue", 1 }, | |
1bdbdaff P |
105 | }; |
106 | ||
107 | static int test_property_parse(int n) | |
108 | { | |
109 | OSSL_METHOD_STORE *store; | |
110 | OSSL_PROPERTY_LIST *p = NULL, *q = NULL; | |
111 | int r = 0; | |
112 | ||
1aedc35f | 113 | if (TEST_ptr(store = ossl_method_store_new(NULL)) |
1bdbdaff P |
114 | && add_property_names("sky", "groan", "cold", "today", "tomorrow", "n", |
115 | NULL) | |
1aedc35f | 116 | && TEST_ptr(p = ossl_parse_property(NULL, parser_tests[n].defn)) |
1e08f3ba | 117 | && TEST_ptr(q = ossl_parse_query(NULL, parser_tests[n].query, 0)) |
da89ac0b | 118 | && TEST_int_eq(ossl_property_match_count(q, p), parser_tests[n].e)) |
1bdbdaff P |
119 | r = 1; |
120 | ossl_property_free(p); | |
121 | ossl_property_free(q); | |
122 | ossl_method_store_free(store); | |
123 | return r; | |
124 | } | |
125 | ||
1e08f3ba P |
126 | static int test_property_query_value_create(void) |
127 | { | |
128 | OSSL_METHOD_STORE *store; | |
129 | OSSL_PROPERTY_LIST *p = NULL, *q = NULL, *o = NULL; | |
130 | int r = 0; | |
131 | ||
a289d3a4 | 132 | /* The property value used here must not be used in other test cases */ |
1e08f3ba | 133 | if (TEST_ptr(store = ossl_method_store_new(NULL)) |
a289d3a4 TM |
134 | && add_property_names("wood", NULL) |
135 | && TEST_ptr(p = ossl_parse_query(NULL, "wood=oak", 0)) /* undefined */ | |
136 | && TEST_ptr(q = ossl_parse_query(NULL, "wood=oak", 1)) /* creates */ | |
137 | && TEST_ptr(o = ossl_parse_query(NULL, "wood=oak", 0)) /* defined */ | |
1e08f3ba P |
138 | && TEST_int_eq(ossl_property_match_count(q, p), -1) |
139 | && TEST_int_eq(ossl_property_match_count(q, o), 1)) | |
140 | r = 1; | |
141 | ossl_property_free(o); | |
142 | ossl_property_free(p); | |
143 | ossl_property_free(q); | |
144 | ossl_method_store_free(store); | |
145 | return r; | |
146 | } | |
147 | ||
747d1423 P |
148 | static const struct { |
149 | int query; | |
150 | const char *ps; | |
151 | } parse_error_tests[] = { | |
152 | { 0, "n=1, n=1" }, /* duplicate name */ | |
153 | { 0, "n=1, a=hi, n=1" }, /* duplicate name */ | |
154 | { 1, "n=1, a=bye, ?n=0" }, /* duplicate name */ | |
155 | { 0, "a=abc,#@!, n=1" }, /* non-ASCII character located */ | |
156 | { 1, "a='Hello" }, /* Unterminated string */ | |
157 | { 0, "a=\"World" }, /* Unterminated string */ | |
158 | { 1, "a=2, n=012345678" }, /* Bad octal digit */ | |
159 | { 0, "n=0x28FG, a=3" }, /* Bad hex digit */ | |
160 | { 0, "n=145d, a=2" }, /* Bad decimal digit */ | |
161 | { 1, "@='hello'" }, /* Invalid name */ | |
162 | { 1, "n0123456789012345678901234567890123456789" | |
163 | "0123456789012345678901234567890123456789" | |
164 | "0123456789012345678901234567890123456789" | |
165 | "0123456789012345678901234567890123456789=yes" }, /* Name too long */ | |
166 | { 0, ".n=3" }, /* Invalid name */ | |
167 | { 1, "fnord.fnord.=3" } /* Invalid name */ | |
168 | }; | |
169 | ||
170 | static int test_property_parse_error(int n) | |
171 | { | |
172 | OSSL_METHOD_STORE *store; | |
173 | OSSL_PROPERTY_LIST *p = NULL; | |
174 | int r = 0; | |
175 | const char *ps; | |
176 | ||
177 | if (!TEST_ptr(store = ossl_method_store_new(NULL)) | |
178 | || !add_property_names("a", "n", NULL)) | |
179 | goto err; | |
180 | ps = parse_error_tests[n].ps; | |
181 | if (parse_error_tests[n].query) { | |
182 | if (!TEST_ptr_null(p = ossl_parse_query(NULL, ps, 1))) | |
183 | goto err; | |
184 | } else if (!TEST_ptr_null(p = ossl_parse_property(NULL, ps))) { | |
185 | goto err; | |
186 | } | |
187 | r = 1; | |
188 | err: | |
189 | ossl_property_free(p); | |
190 | ossl_method_store_free(store); | |
191 | return r; | |
192 | } | |
193 | ||
1bdbdaff P |
194 | static const struct { |
195 | const char *q_global; | |
196 | const char *q_local; | |
197 | const char *prop; | |
198 | } merge_tests[] = { | |
199 | { "", "colour=blue", "colour=blue" }, | |
200 | { "colour=blue", "", "colour=blue" }, | |
201 | { "colour=red", "colour=blue", "colour=blue" }, | |
202 | { "clouds=pink, urn=red", "urn=blue, colour=green", | |
203 | "urn=blue, colour=green, clouds=pink" }, | |
204 | { "pot=gold", "urn=blue", "pot=gold, urn=blue" }, | |
205 | { "night", "day", "day=yes, night=yes" }, | |
206 | { "day", "night", "day=yes, night=yes" }, | |
207 | { "", "", "" }, | |
208 | /* | |
209 | * The following four leave 'day' unspecified in the query, and will match | |
210 | * any definition | |
211 | */ | |
212 | { "day=yes", "-day", "day=no" }, | |
213 | { "day=yes", "-day", "day=yes" }, | |
214 | { "day=yes", "-day", "day=arglebargle" }, | |
215 | { "day=yes", "-day", "pot=sesquioxidizing" }, | |
216 | { "day, night", "-night, day", "day=yes, night=no" }, | |
217 | { "-day", "day=yes", "day=yes" }, | |
218 | }; | |
219 | ||
220 | static int test_property_merge(int n) | |
221 | { | |
222 | OSSL_METHOD_STORE *store; | |
223 | OSSL_PROPERTY_LIST *q_global = NULL, *q_local = NULL; | |
224 | OSSL_PROPERTY_LIST *q_combined = NULL, *prop = NULL; | |
225 | int r = 0; | |
226 | ||
1aedc35f | 227 | if (TEST_ptr(store = ossl_method_store_new(NULL)) |
1bdbdaff P |
228 | && add_property_names("colour", "urn", "clouds", "pot", "day", "night", |
229 | NULL) | |
1aedc35f | 230 | && TEST_ptr(prop = ossl_parse_property(NULL, merge_tests[n].prop)) |
1e08f3ba P |
231 | && TEST_ptr(q_global = ossl_parse_query(NULL, merge_tests[n].q_global, |
232 | 0)) | |
233 | && TEST_ptr(q_local = ossl_parse_query(NULL, merge_tests[n].q_local, 0)) | |
1bdbdaff | 234 | && TEST_ptr(q_combined = ossl_property_merge(q_local, q_global)) |
da89ac0b | 235 | && TEST_int_ge(ossl_property_match_count(q_combined, prop), 0)) |
1bdbdaff P |
236 | r = 1; |
237 | ossl_property_free(q_global); | |
238 | ossl_property_free(q_local); | |
239 | ossl_property_free(q_combined); | |
240 | ossl_property_free(prop); | |
241 | ossl_method_store_free(store); | |
242 | return r; | |
243 | } | |
244 | ||
245 | static int test_property_defn_cache(void) | |
246 | { | |
247 | OSSL_METHOD_STORE *store; | |
248 | OSSL_PROPERTY_LIST *red, *blue; | |
249 | int r = 0; | |
250 | ||
1aedc35f | 251 | if (TEST_ptr(store = ossl_method_store_new(NULL)) |
1bdbdaff | 252 | && add_property_names("red", "blue", NULL) |
1aedc35f MC |
253 | && TEST_ptr(red = ossl_parse_property(NULL, "red")) |
254 | && TEST_ptr(blue = ossl_parse_property(NULL, "blue")) | |
1bdbdaff | 255 | && TEST_ptr_ne(red, blue) |
1aedc35f MC |
256 | && TEST_true(ossl_prop_defn_set(NULL, "red", red)) |
257 | && TEST_true(ossl_prop_defn_set(NULL, "blue", blue)) | |
258 | && TEST_ptr_eq(ossl_prop_defn_get(NULL, "red"), red) | |
259 | && TEST_ptr_eq(ossl_prop_defn_get(NULL, "blue"), blue)) | |
1bdbdaff P |
260 | r = 1; |
261 | ossl_method_store_free(store); | |
262 | return r; | |
263 | } | |
264 | ||
265 | static const struct { | |
266 | const char *defn; | |
267 | const char *query; | |
268 | int e; | |
269 | } definition_tests[] = { | |
270 | { "alpha", "alpha=yes", 1 }, | |
da89ac0b | 271 | { "alpha=no", "alpha", -1 }, |
1bdbdaff | 272 | { "alpha=1", "alpha=1", 1 }, |
da89ac0b P |
273 | { "alpha=2", "alpha=1",-1 }, |
274 | { "alpha", "omega", -1 }, | |
275 | { "alpha", "?omega", 0 }, | |
276 | { "alpha", "?omega=1", 0 }, | |
277 | { "alpha", "?omega=no", 1 }, | |
278 | { "alpha", "?omega=yes", 0 }, | |
279 | { "alpha, omega", "?omega=yes", 1 }, | |
280 | { "alpha, omega", "?omega=no", 0 } | |
1bdbdaff P |
281 | }; |
282 | ||
283 | static int test_definition_compares(int n) | |
284 | { | |
285 | OSSL_METHOD_STORE *store; | |
286 | OSSL_PROPERTY_LIST *d = NULL, *q = NULL; | |
287 | int r; | |
288 | ||
1aedc35f | 289 | r = TEST_ptr(store = ossl_method_store_new(NULL)) |
1bdbdaff | 290 | && add_property_names("alpha", "omega", NULL) |
1aedc35f | 291 | && TEST_ptr(d = ossl_parse_property(NULL, definition_tests[n].defn)) |
1e08f3ba | 292 | && TEST_ptr(q = ossl_parse_query(NULL, definition_tests[n].query, 0)) |
da89ac0b | 293 | && TEST_int_eq(ossl_property_match_count(q, d), definition_tests[n].e); |
1bdbdaff P |
294 | |
295 | ossl_property_free(d); | |
296 | ossl_property_free(q); | |
297 | ossl_method_store_free(store); | |
298 | return r; | |
299 | } | |
300 | ||
301 | static int test_register_deregister(void) | |
302 | { | |
303 | static const struct { | |
304 | int nid; | |
305 | const char *prop; | |
306 | char *impl; | |
307 | } impls[] = { | |
308 | { 6, "position=1", "a" }, | |
309 | { 6, "position=2", "b" }, | |
310 | { 6, "position=3", "c" }, | |
311 | { 6, "position=4", "d" }, | |
312 | }; | |
313 | size_t i; | |
314 | int ret = 0; | |
315 | OSSL_METHOD_STORE *store; | |
316 | ||
1aedc35f | 317 | if (!TEST_ptr(store = ossl_method_store_new(NULL)) |
1bdbdaff P |
318 | || !add_property_names("position", NULL)) |
319 | goto err; | |
320 | ||
321 | for (i = 0; i < OSSL_NELEM(impls); i++) | |
c1d56231 RL |
322 | if (!TEST_true(ossl_method_store_add(store, NULL, impls[i].nid, |
323 | impls[i].prop, impls[i].impl, | |
bdbf2df2 | 324 | &up_ref, &down_ref))) { |
1bdbdaff P |
325 | TEST_note("iteration %zd", i + 1); |
326 | goto err; | |
327 | } | |
328 | ||
329 | /* Deregister in a different order to registration */ | |
330 | for (i = 0; i < OSSL_NELEM(impls); i++) { | |
331 | const size_t j = (1 + i * 3) % OSSL_NELEM(impls); | |
332 | int nid = impls[j].nid; | |
333 | void *impl = impls[j].impl; | |
334 | ||
335 | if (!TEST_true(ossl_method_store_remove(store, nid, impl)) | |
336 | || !TEST_false(ossl_method_store_remove(store, nid, impl))) { | |
337 | TEST_note("iteration %zd, position %zd", i + 1, j + 1); | |
338 | goto err; | |
339 | } | |
340 | } | |
341 | ||
342 | if (TEST_false(ossl_method_store_remove(store, impls[0].nid, impls[0].impl))) | |
343 | ret = 1; | |
344 | err: | |
345 | ossl_method_store_free(store); | |
346 | return ret; | |
347 | } | |
348 | ||
349 | static int test_property(void) | |
350 | { | |
351 | static const struct { | |
352 | int nid; | |
353 | const char *prop; | |
354 | char *impl; | |
355 | } impls[] = { | |
356 | { 1, "fast=no, colour=green", "a" }, | |
357 | { 1, "fast, colour=blue", "b" }, | |
358 | { 1, "", "-" }, | |
359 | { 9, "sky=blue, furry", "c" }, | |
360 | { 3, NULL, "d" }, | |
361 | { 6, "sky.colour=blue, sky=green, old.data", "e" }, | |
362 | }; | |
363 | static struct { | |
364 | int nid; | |
365 | const char *prop; | |
366 | char *expected; | |
367 | } queries[] = { | |
368 | { 1, "fast", "b" }, | |
369 | { 1, "fast=yes", "b" }, | |
370 | { 1, "fast=no, colour=green", "a" }, | |
371 | { 1, "colour=blue, fast", "b" }, | |
372 | { 1, "colour=blue", "b" }, | |
373 | { 9, "furry", "c" }, | |
374 | { 6, "sky.colour=blue", "e" }, | |
375 | { 6, "old.data", "e" }, | |
376 | { 9, "furry=yes, sky=blue", "c" }, | |
377 | { 1, "", "a" }, | |
378 | { 3, "", "d" }, | |
379 | }; | |
380 | OSSL_METHOD_STORE *store; | |
381 | size_t i; | |
382 | int ret = 0; | |
383 | void *result; | |
384 | ||
1aedc35f | 385 | if (!TEST_ptr(store = ossl_method_store_new(NULL)) |
1bdbdaff P |
386 | || !add_property_names("fast", "colour", "sky", "furry", NULL)) |
387 | goto err; | |
388 | ||
389 | for (i = 0; i < OSSL_NELEM(impls); i++) | |
c1d56231 RL |
390 | if (!TEST_true(ossl_method_store_add(store, NULL, impls[i].nid, |
391 | impls[i].prop, impls[i].impl, | |
bdbf2df2 | 392 | &up_ref, &down_ref))) { |
1bdbdaff P |
393 | TEST_note("iteration %zd", i + 1); |
394 | goto err; | |
395 | } | |
396 | for (i = 0; i < OSSL_NELEM(queries); i++) { | |
397 | OSSL_PROPERTY_LIST *pq = NULL; | |
398 | ||
ef9f6066 P |
399 | if (!TEST_true(ossl_method_store_fetch(store, queries[i].nid, |
400 | queries[i].prop, &result)) | |
1bdbdaff P |
401 | || !TEST_str_eq((char *)result, queries[i].expected)) { |
402 | TEST_note("iteration %zd", i + 1); | |
403 | ossl_property_free(pq); | |
404 | goto err; | |
405 | } | |
406 | ossl_property_free(pq); | |
407 | } | |
408 | ret = 1; | |
409 | err: | |
410 | ossl_method_store_free(store); | |
411 | return ret; | |
412 | } | |
413 | ||
414 | static int test_query_cache_stochastic(void) | |
415 | { | |
416 | const int max = 10000, tail = 10; | |
417 | OSSL_METHOD_STORE *store; | |
418 | int i, res = 0; | |
419 | char buf[50]; | |
420 | void *result; | |
421 | int errors = 0; | |
422 | int v[10001]; | |
423 | ||
1aedc35f | 424 | if (!TEST_ptr(store = ossl_method_store_new(NULL)) |
1bdbdaff P |
425 | || !add_property_names("n", NULL)) |
426 | goto err; | |
427 | ||
428 | for (i = 1; i <= max; i++) { | |
429 | v[i] = 2 * i; | |
430 | BIO_snprintf(buf, sizeof(buf), "n=%d\n", i); | |
c1d56231 | 431 | if (!TEST_true(ossl_method_store_add(store, NULL, i, buf, "abc", |
bdbf2df2 P |
432 | &up_ref, &down_ref)) |
433 | || !TEST_true(ossl_method_store_cache_set(store, i, buf, v + i, | |
434 | &up_ref, &down_ref)) | |
1bdbdaff | 435 | || !TEST_true(ossl_method_store_cache_set(store, i, "n=1234", |
bdbf2df2 P |
436 | "miss", &up_ref, |
437 | &down_ref))) { | |
1bdbdaff P |
438 | TEST_note("iteration %d", i); |
439 | goto err; | |
440 | } | |
441 | } | |
442 | for (i = 1; i <= max; i++) { | |
443 | BIO_snprintf(buf, sizeof(buf), "n=%d\n", i); | |
444 | if (!ossl_method_store_cache_get(store, i, buf, &result) | |
445 | || result != v + i) | |
446 | errors++; | |
447 | } | |
448 | /* There is a tiny probability that this will fail when it shouldn't */ | |
449 | res = TEST_int_gt(errors, tail) && TEST_int_lt(errors, max - tail); | |
450 | ||
451 | err: | |
452 | ossl_method_store_free(store); | |
453 | return res; | |
454 | } | |
455 | ||
e0624f0d SL |
456 | static int test_fips_mode(void) |
457 | { | |
458 | int ret = 0; | |
b4250010 | 459 | OSSL_LIB_CTX *ctx = NULL; |
e0624f0d | 460 | |
b4250010 | 461 | if (!TEST_ptr(ctx = OSSL_LIB_CTX_new())) |
e0624f0d SL |
462 | goto err; |
463 | ||
464 | ret = TEST_true(EVP_set_default_properties(ctx, "default=yes,fips=yes")) | |
465 | && TEST_true(EVP_default_properties_is_fips_enabled(ctx)) | |
466 | && TEST_true(EVP_set_default_properties(ctx, "fips=no,default=yes")) | |
467 | && TEST_false(EVP_default_properties_is_fips_enabled(ctx)) | |
468 | && TEST_true(EVP_set_default_properties(ctx, "fips=no")) | |
469 | && TEST_false(EVP_default_properties_is_fips_enabled(ctx)) | |
470 | && TEST_true(EVP_set_default_properties(ctx, "fips!=no")) | |
471 | && TEST_true(EVP_default_properties_is_fips_enabled(ctx)) | |
472 | && TEST_true(EVP_set_default_properties(ctx, "fips=no")) | |
473 | && TEST_false(EVP_default_properties_is_fips_enabled(ctx)) | |
474 | && TEST_true(EVP_set_default_properties(ctx, "fips=no,default=yes")) | |
475 | && TEST_true(EVP_default_properties_enable_fips(ctx, 1)) | |
476 | && TEST_true(EVP_default_properties_is_fips_enabled(ctx)) | |
477 | && TEST_true(EVP_default_properties_enable_fips(ctx, 0)) | |
478 | && TEST_false(EVP_default_properties_is_fips_enabled(ctx)); | |
479 | err: | |
b4250010 | 480 | OSSL_LIB_CTX_free(ctx); |
e0624f0d SL |
481 | return ret; |
482 | } | |
483 | ||
862497a9 P |
484 | static struct { |
485 | const char *in; | |
486 | const char *out; | |
487 | } to_string_tests[] = { | |
488 | { "fips=yes", "fips=yes" }, | |
489 | { "fips!=yes", "fips!=yes" }, | |
490 | { "fips = yes", "fips=yes" }, | |
491 | { "fips", "fips=yes" }, | |
492 | { "fips=no", "fips=no" }, | |
493 | { "-fips", "-fips" }, | |
494 | { "?fips=yes", "?fips=yes" }, | |
495 | { "fips=yes,provider=fips", "fips=yes,provider=fips" }, | |
496 | { "fips = yes , provider = fips", "fips=yes,provider=fips" }, | |
497 | { "fips=yes,provider!=fips", "fips=yes,provider!=fips" }, | |
498 | { "fips=yes,?provider=fips", "fips=yes,?provider=fips" }, | |
499 | { "fips=yes,-provider", "fips=yes,-provider" }, | |
500 | /* foo is an unknown internal name */ | |
501 | { "foo=yes,fips=yes", "fips=yes"}, | |
502 | { "", "" }, | |
503 | { "fips=3", "fips=3" }, | |
504 | { "fips=-3", "fips=-3" }, | |
505 | { NULL, "" } | |
506 | }; | |
507 | ||
508 | static int test_property_list_to_string(int i) | |
ad8570a8 MC |
509 | { |
510 | OSSL_PROPERTY_LIST *pl = NULL; | |
511 | int ret = 0; | |
862497a9 | 512 | size_t bufsize; |
ad8570a8 MC |
513 | char *buf = NULL; |
514 | ||
862497a9 P |
515 | if (to_string_tests[i].in != NULL |
516 | && !TEST_ptr(pl = ossl_parse_query(NULL, to_string_tests[i].in, 1))) | |
517 | goto err; | |
518 | bufsize = ossl_property_list_to_string(NULL, pl, NULL, 0); | |
519 | if (!TEST_size_t_gt(bufsize, 0)) | |
520 | goto err; | |
521 | buf = OPENSSL_malloc(bufsize); | |
522 | if (!TEST_ptr(buf) | |
523 | || !TEST_size_t_eq(ossl_property_list_to_string(NULL, pl, buf, | |
524 | bufsize), | |
525 | bufsize) | |
526 | || !TEST_str_eq(to_string_tests[i].out, buf) | |
527 | || !TEST_size_t_eq(bufsize, strlen(to_string_tests[i].out) + 1)) | |
528 | goto err; | |
ad8570a8 MC |
529 | |
530 | ret = 1; | |
531 | err: | |
532 | OPENSSL_free(buf); | |
533 | ossl_property_free(pl); | |
534 | return ret; | |
535 | } | |
e0624f0d | 536 | |
1bdbdaff P |
537 | int setup_tests(void) |
538 | { | |
539 | ADD_TEST(test_property_string); | |
1e08f3ba | 540 | ADD_TEST(test_property_query_value_create); |
1bdbdaff | 541 | ADD_ALL_TESTS(test_property_parse, OSSL_NELEM(parser_tests)); |
747d1423 | 542 | ADD_ALL_TESTS(test_property_parse_error, OSSL_NELEM(parse_error_tests)); |
1bdbdaff P |
543 | ADD_ALL_TESTS(test_property_merge, OSSL_NELEM(merge_tests)); |
544 | ADD_TEST(test_property_defn_cache); | |
545 | ADD_ALL_TESTS(test_definition_compares, OSSL_NELEM(definition_tests)); | |
546 | ADD_TEST(test_register_deregister); | |
547 | ADD_TEST(test_property); | |
548 | ADD_TEST(test_query_cache_stochastic); | |
e0624f0d | 549 | ADD_TEST(test_fips_mode); |
862497a9 | 550 | ADD_ALL_TESTS(test_property_list_to_string, OSSL_NELEM(to_string_tests)); |
1bdbdaff P |
551 | return 1; |
552 | } |