/*
- * Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved.
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
*
* Licensed under the Apache License 2.0 (the "License"). You may not use
*/
#include <stdarg.h>
+#include <openssl/evp.h>
#include "testutil.h"
#include "internal/nelem.h"
#include "internal/property.h"
-#include "../crypto/property/property_lcl.h"
+#include "../crypto/property/property_local.h"
static int add_property_names(const char *n, ...)
{
return res;
}
+static int up_ref(void *p)
+{
+ return 1;
+}
+
+static void down_ref(void *p)
+{
+}
+
static int test_property_string(void)
{
OSSL_METHOD_STORE *store;
const char *query;
int e;
} parser_tests[] = {
- { "", "sky=blue", 0 },
+ { "", "sky=blue", -1 },
{ "", "sky!=blue", 1 },
- { "groan", "", 1 },
+ { "groan", "", 0 },
{ "cold=yes", "cold=yes", 1 },
{ "cold=yes", "cold", 1 },
{ "cold=yes", "cold!=no", 1 },
{ "groan", "groan=yes", 1 },
- { "groan", "groan=no", 0 },
- { "groan", "groan!=yes", 0 },
- { "cold=no", "cold", 0 },
+ { "groan", "groan=no", -1 },
+ { "groan", "groan!=yes", -1 },
+ { "cold=no", "cold", -1 },
+ { "cold=no", "?cold", 0 },
{ "cold=no", "cold=no", 1 },
- { "groan", "cold", 0 },
+ { "groan", "cold", -1 },
{ "groan", "cold=no", 1 },
{ "groan", "cold!=yes", 1 },
- { "groan=blue", "groan=yellow", 0 },
+ { "groan=blue", "groan=yellow", -1 },
+ { "groan=blue", "?groan=yellow", 0 },
{ "groan=blue", "groan!=yellow", 1 },
+ { "groan=blue", "?groan!=yellow", 1 },
{ "today=monday, tomorrow=3", "today!=2", 1 },
- { "today=monday, tomorrow=3", "today!='monday'", 0 },
+ { "today=monday, tomorrow=3", "today!='monday'", -1 },
{ "today=monday, tomorrow=3", "tomorrow=3", 1 },
{ "n=0x3", "n=3", 1 },
- { "n=0x3", "n=-3", 0 },
+ { "n=0x3", "n=-3", -1 },
{ "n=0x33", "n=51", 1 },
{ "n=033", "n=27", 1 },
{ "n=0", "n=00", 1 },
{ "n=0x0", "n=0", 1 },
+ { "n=0, sky=blue", "?n=0, sky=blue", 2 },
+ { "n=1, sky=blue", "?n=0, sky=blue", 1 },
};
static int test_property_parse(int n)
NULL)
&& TEST_ptr(p = ossl_parse_property(NULL, parser_tests[n].defn))
&& TEST_ptr(q = ossl_parse_query(NULL, parser_tests[n].query))
- && TEST_int_eq(ossl_property_match(q, p), parser_tests[n].e))
+ && TEST_int_eq(ossl_property_match_count(q, p), parser_tests[n].e))
r = 1;
ossl_property_free(p);
ossl_property_free(q);
&& TEST_ptr(q_global = ossl_parse_query(NULL, merge_tests[n].q_global))
&& TEST_ptr(q_local = ossl_parse_query(NULL, merge_tests[n].q_local))
&& TEST_ptr(q_combined = ossl_property_merge(q_local, q_global))
- && TEST_true(ossl_property_match(q_combined, prop)))
+ && TEST_int_ge(ossl_property_match_count(q_combined, prop), 0))
r = 1;
ossl_property_free(q_global);
ossl_property_free(q_local);
int e;
} definition_tests[] = {
{ "alpha", "alpha=yes", 1 },
- { "alpha=no", "alpha", 0 },
+ { "alpha=no", "alpha", -1 },
{ "alpha=1", "alpha=1", 1 },
- { "alpha=2", "alpha=1", 0 },
- { "alpha", "omega", 0 }
+ { "alpha=2", "alpha=1",-1 },
+ { "alpha", "omega", -1 },
+ { "alpha", "?omega", 0 },
+ { "alpha", "?omega=1", 0 },
+ { "alpha", "?omega=no", 1 },
+ { "alpha", "?omega=yes", 0 },
+ { "alpha, omega", "?omega=yes", 1 },
+ { "alpha, omega", "?omega=no", 0 }
};
static int test_definition_compares(int n)
&& add_property_names("alpha", "omega", NULL)
&& TEST_ptr(d = ossl_parse_property(NULL, definition_tests[n].defn))
&& TEST_ptr(q = ossl_parse_query(NULL, definition_tests[n].query))
- && TEST_int_eq(ossl_property_match(q, d), definition_tests[n].e);
+ && TEST_int_eq(ossl_property_match_count(q, d), definition_tests[n].e);
ossl_property_free(d);
ossl_property_free(q);
goto err;
for (i = 0; i < OSSL_NELEM(impls); i++)
- if (!TEST_true(ossl_method_store_add(store, impls[i].nid, impls[i].prop,
- impls[i].impl, NULL))) {
+ if (!TEST_true(ossl_method_store_add(store, NULL, impls[i].nid,
+ impls[i].prop, impls[i].impl,
+ &up_ref, &down_ref))) {
TEST_note("iteration %zd", i + 1);
goto err;
}
goto err;
for (i = 0; i < OSSL_NELEM(impls); i++)
- if (!TEST_true(ossl_method_store_add(store, impls[i].nid, impls[i].prop,
- impls[i].impl, NULL))) {
+ if (!TEST_true(ossl_method_store_add(store, NULL, impls[i].nid,
+ impls[i].prop, impls[i].impl,
+ &up_ref, &down_ref))) {
TEST_note("iteration %zd", i + 1);
goto err;
}
for (i = 1; i <= max; i++) {
v[i] = 2 * i;
BIO_snprintf(buf, sizeof(buf), "n=%d\n", i);
- if (!TEST_true(ossl_method_store_add(store, i, buf, "abc", NULL))
- || !TEST_true(ossl_method_store_cache_set(store, i, buf, v + i))
+ if (!TEST_true(ossl_method_store_add(store, NULL, i, buf, "abc",
+ &up_ref, &down_ref))
+ || !TEST_true(ossl_method_store_cache_set(store, i, buf, v + i,
+ &up_ref, &down_ref))
|| !TEST_true(ossl_method_store_cache_set(store, i, "n=1234",
- "miss"))) {
+ "miss", &up_ref,
+ &down_ref))) {
TEST_note("iteration %d", i);
goto err;
}
return res;
}
+static int test_fips_mode(void)
+{
+ int ret = 0;
+ OPENSSL_CTX *ctx = NULL;
+
+ if (!TEST_ptr(ctx = OPENSSL_CTX_new()))
+ goto err;
+
+ ret = TEST_true(EVP_set_default_properties(ctx, "default=yes,fips=yes"))
+ && TEST_true(EVP_default_properties_is_fips_enabled(ctx))
+ && TEST_true(EVP_set_default_properties(ctx, "fips=no,default=yes"))
+ && TEST_false(EVP_default_properties_is_fips_enabled(ctx))
+ && TEST_true(EVP_set_default_properties(ctx, "fips=no"))
+ && TEST_false(EVP_default_properties_is_fips_enabled(ctx))
+ && TEST_true(EVP_set_default_properties(ctx, "fips!=no"))
+ && TEST_true(EVP_default_properties_is_fips_enabled(ctx))
+ && TEST_true(EVP_set_default_properties(ctx, "fips=no"))
+ && TEST_false(EVP_default_properties_is_fips_enabled(ctx))
+ && TEST_true(EVP_set_default_properties(ctx, "fips=no,default=yes"))
+ && TEST_true(EVP_default_properties_enable_fips(ctx, 1))
+ && TEST_true(EVP_default_properties_is_fips_enabled(ctx))
+ && TEST_true(EVP_default_properties_enable_fips(ctx, 0))
+ && TEST_false(EVP_default_properties_is_fips_enabled(ctx));
+err:
+ OPENSSL_CTX_free(ctx);
+ return ret;
+}
+
+
int setup_tests(void)
{
ADD_TEST(test_property_string);
ADD_TEST(test_register_deregister);
ADD_TEST(test_property);
ADD_TEST(test_query_cache_stochastic);
+ ADD_TEST(test_fips_mode);
return 1;
}