| 
									
										
										
										
											2020-05-23 22:34:07 +08:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2021-06-17 20:24:59 +08:00
										 |  |  |  * Copyright 2020-2021 The OpenSSL Project Authors. All Rights Reserved. | 
					
						
							| 
									
										
										
										
											2020-05-23 22:34:07 +08:00
										 |  |  |  * | 
					
						
							|  |  |  |  * Licensed under the Apache License 2.0 (the "License").  You may not use | 
					
						
							|  |  |  |  * this file except in compliance with the License.  You can obtain a copy | 
					
						
							|  |  |  |  * in the file LICENSE in the source distribution or at | 
					
						
							|  |  |  |  * https://www.openssl.org/source/license.html
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <stddef.h>
 | 
					
						
							|  |  |  | #include <openssl/provider.h>
 | 
					
						
							|  |  |  | #include <openssl/evp.h>
 | 
					
						
							|  |  |  | #include "testutil.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-15 17:55:50 +08:00
										 |  |  | static int test_provider(OSSL_LIB_CTX *ctx) | 
					
						
							| 
									
										
										
										
											2020-05-23 22:34:07 +08:00
										 |  |  | { | 
					
						
							|  |  |  |     EVP_KEYMGMT *rsameth = NULL; | 
					
						
							|  |  |  |     const OSSL_PROVIDER *prov = NULL; | 
					
						
							|  |  |  |     int ok; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ok = TEST_true(OSSL_PROVIDER_available(ctx, "default")) | 
					
						
							|  |  |  |         && TEST_ptr(rsameth = EVP_KEYMGMT_fetch(ctx, "RSA", NULL)) | 
					
						
							| 
									
										
										
											
												Rename all getters to use get/get0 in name
For functions that exist in 1.1.1 provide a simple aliases via #define.
Fixes #15236
Functions with OSSL_DECODER_, OSSL_ENCODER_, OSSL_STORE_LOADER_,
EVP_KEYEXCH_, EVP_KEM_, EVP_ASYM_CIPHER_, EVP_SIGNATURE_,
EVP_KEYMGMT_, EVP_RAND_, EVP_MAC_, EVP_KDF_, EVP_PKEY_,
EVP_MD_, and EVP_CIPHER_ prefixes are renamed.
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15405)
											
										 
											2021-05-21 22:58:08 +08:00
										 |  |  |         && TEST_ptr(prov = EVP_KEYMGMT_get0_provider(rsameth)) | 
					
						
							| 
									
										
										
										
											2021-05-28 22:57:22 +08:00
										 |  |  |         && TEST_str_eq(OSSL_PROVIDER_get0_name(prov), "default"); | 
					
						
							| 
									
										
										
										
											2020-05-23 22:34:07 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     EVP_KEYMGMT_free(rsameth); | 
					
						
							|  |  |  |     return ok; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int test_fallback_provider(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return test_provider(NULL); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int test_explicit_provider(void) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-10-15 17:55:50 +08:00
										 |  |  |     OSSL_LIB_CTX *ctx = NULL; | 
					
						
							| 
									
										
										
										
											2020-05-23 22:34:07 +08:00
										 |  |  |     OSSL_PROVIDER *prov = NULL; | 
					
						
							|  |  |  |     int ok; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-15 17:55:50 +08:00
										 |  |  |     ok = TEST_ptr(ctx = OSSL_LIB_CTX_new()) | 
					
						
							| 
									
										
										
										
											2020-05-23 22:34:07 +08:00
										 |  |  |         && TEST_ptr(prov = OSSL_PROVIDER_load(ctx, "default")) | 
					
						
							|  |  |  |         && test_provider(ctx) | 
					
						
							|  |  |  |         && TEST_true(OSSL_PROVIDER_unload(prov)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-15 17:55:50 +08:00
										 |  |  |     OSSL_LIB_CTX_free(ctx); | 
					
						
							| 
									
										
										
										
											2020-05-23 22:34:07 +08:00
										 |  |  |     return ok; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int setup_tests(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     ADD_TEST(test_fallback_provider); | 
					
						
							|  |  |  |     ADD_TEST(test_explicit_provider); | 
					
						
							|  |  |  |     return 1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 |