provider_fallback_test.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * Copyright 2020-2021 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License 2.0 (the "License"). You may not use
  5. * this file except in compliance with the License. You can obtain a copy
  6. * in the file LICENSE in the source distribution or at
  7. * https://www.openssl.org/source/license.html
  8. */
  9. #include <stddef.h>
  10. #include <openssl/provider.h>
  11. #include <openssl/evp.h>
  12. #include "testutil.h"
  13. static int test_provider(OSSL_LIB_CTX *ctx)
  14. {
  15. EVP_KEYMGMT *rsameth = NULL;
  16. const OSSL_PROVIDER *prov = NULL;
  17. int ok;
  18. ok = TEST_true(OSSL_PROVIDER_available(ctx, "default"))
  19. && TEST_ptr(rsameth = EVP_KEYMGMT_fetch(ctx, "RSA", NULL))
  20. && TEST_ptr(prov = EVP_KEYMGMT_get0_provider(rsameth))
  21. && TEST_str_eq(OSSL_PROVIDER_get0_name(prov), "default");
  22. EVP_KEYMGMT_free(rsameth);
  23. return ok;
  24. }
  25. static int test_fallback_provider(void)
  26. {
  27. return test_provider(NULL);
  28. }
  29. static int test_explicit_provider(void)
  30. {
  31. OSSL_LIB_CTX *ctx = NULL;
  32. OSSL_PROVIDER *prov = NULL;
  33. int ok;
  34. ok = TEST_ptr(ctx = OSSL_LIB_CTX_new())
  35. && TEST_ptr(prov = OSSL_PROVIDER_load(ctx, "default"))
  36. && test_provider(ctx)
  37. && TEST_true(OSSL_PROVIDER_unload(prov));
  38. OSSL_LIB_CTX_free(ctx);
  39. return ok;
  40. }
  41. int setup_tests(void)
  42. {
  43. ADD_TEST(test_fallback_provider);
  44. ADD_TEST(test_explicit_provider);
  45. return 1;
  46. }