1 1.1 christos /* 2 1.1.1.2 christos * Copyright 2021-2025 The OpenSSL Project Authors. All Rights Reserved. 3 1.1 christos * 4 1.1 christos * Licensed under the Apache License 2.0 (the "License"). You may not use 5 1.1 christos * this file except in compliance with the License. You can obtain a copy 6 1.1 christos * in the file LICENSE in the source distribution or at 7 1.1 christos * https://www.openssl.org/source/license.html 8 1.1 christos */ 9 1.1 christos 10 1.1 christos #include <stddef.h> 11 1.1 christos #include <string.h> 12 1.1 christos #include <openssl/provider.h> 13 1.1 christos #include <openssl/params.h> 14 1.1 christos #include <openssl/core_names.h> 15 1.1 christos #include <openssl/evp.h> 16 1.1 christos #include <openssl/store.h> 17 1.1 christos #include <openssl/ui.h> 18 1.1 christos #include "testutil.h" 19 1.1 christos #include "fake_rsaprov.h" 20 1.1 christos 21 1.1 christos static OSSL_LIB_CTX *libctx = NULL; 22 1.1 christos extern int key_deleted; /* From fake_rsaprov.c */ 23 1.1 christos 24 1.1 christos /* Fetch SIGNATURE method using a libctx and propq */ 25 1.1 christos static int fetch_sig(OSSL_LIB_CTX *ctx, const char *alg, const char *propq, 26 1.1.1.2 christos OSSL_PROVIDER *expected_prov) 27 1.1 christos { 28 1.1 christos OSSL_PROVIDER *prov; 29 1.1 christos EVP_SIGNATURE *sig = EVP_SIGNATURE_fetch(ctx, "RSA", propq); 30 1.1 christos int ret = 0; 31 1.1 christos 32 1.1 christos if (!TEST_ptr(sig)) 33 1.1 christos return 0; 34 1.1 christos 35 1.1 christos if (!TEST_ptr(prov = EVP_SIGNATURE_get0_provider(sig))) 36 1.1 christos goto end; 37 1.1 christos 38 1.1 christos if (!TEST_ptr_eq(prov, expected_prov)) { 39 1.1 christos TEST_info("Fetched provider: %s, Expected provider: %s", 40 1.1.1.2 christos OSSL_PROVIDER_get0_name(prov), 41 1.1.1.2 christos OSSL_PROVIDER_get0_name(expected_prov)); 42 1.1 christos goto end; 43 1.1 christos } 44 1.1 christos 45 1.1 christos ret = 1; 46 1.1 christos end: 47 1.1 christos EVP_SIGNATURE_free(sig); 48 1.1 christos return ret; 49 1.1 christos } 50 1.1 christos 51 1.1 christos static int test_pkey_sig(void) 52 1.1 christos { 53 1.1 christos OSSL_PROVIDER *deflt = NULL; 54 1.1 christos OSSL_PROVIDER *fake_rsa = NULL; 55 1.1 christos int i, ret = 0; 56 1.1 christos EVP_PKEY *pkey = NULL; 57 1.1 christos EVP_PKEY_CTX *ctx = NULL; 58 1.1 christos 59 1.1 christos if (!TEST_ptr(fake_rsa = fake_rsa_start(libctx))) 60 1.1 christos return 0; 61 1.1 christos 62 1.1 christos if (!TEST_ptr(deflt = OSSL_PROVIDER_load(libctx, "default"))) 63 1.1 christos goto end; 64 1.1 christos 65 1.1 christos /* Do a direct fetch to see it works */ 66 1.1 christos if (!TEST_true(fetch_sig(libctx, "RSA", "provider=fake-rsa", fake_rsa)) 67 1.1 christos || !TEST_true(fetch_sig(libctx, "RSA", "?provider=fake-rsa", fake_rsa))) 68 1.1 christos goto end; 69 1.1 christos 70 1.1 christos /* Construct a pkey using precise propq to use our provider */ 71 1.1 christos if (!TEST_ptr(ctx = EVP_PKEY_CTX_new_from_name(libctx, "RSA", 72 1.1.1.2 christos "provider=fake-rsa")) 73 1.1 christos || !TEST_true(EVP_PKEY_fromdata_init(ctx)) 74 1.1 christos || !TEST_true(EVP_PKEY_fromdata(ctx, &pkey, EVP_PKEY_KEYPAIR, NULL)) 75 1.1 christos || !TEST_ptr(pkey)) 76 1.1 christos goto end; 77 1.1 christos 78 1.1 christos EVP_PKEY_CTX_free(ctx); 79 1.1 christos ctx = NULL; 80 1.1 christos 81 1.1 christos /* try exercising signature_init ops a few times */ 82 1.1 christos for (i = 0; i < 3; i++) { 83 1.1 christos size_t siglen; 84 1.1 christos 85 1.1 christos /* 86 1.1 christos * Create a signing context for our pkey with optional propq. 87 1.1 christos * The sign init should pick both keymgmt and signature from 88 1.1 christos * fake-rsa as the key is not exportable. 89 1.1 christos */ 90 1.1 christos if (!TEST_ptr(ctx = EVP_PKEY_CTX_new_from_pkey(libctx, pkey, 91 1.1.1.2 christos "?provider=default"))) 92 1.1 christos goto end; 93 1.1 christos 94 1.1 christos /* 95 1.1 christos * If this picks the wrong signature without realizing it 96 1.1 christos * we can get a segfault or some internal error. At least watch 97 1.1 christos * whether fake-rsa sign_init is exercised by calling sign. 98 1.1 christos */ 99 1.1 christos if (!TEST_int_eq(EVP_PKEY_sign_init(ctx), 1)) 100 1.1 christos goto end; 101 1.1 christos 102 1.1 christos if (!TEST_int_eq(EVP_PKEY_sign(ctx, NULL, &siglen, NULL, 0), 1) 103 1.1 christos || !TEST_size_t_eq(siglen, 256)) 104 1.1 christos goto end; 105 1.1 christos 106 1.1 christos EVP_PKEY_CTX_free(ctx); 107 1.1 christos ctx = NULL; 108 1.1 christos } 109 1.1 christos 110 1.1 christos ret = 1; 111 1.1 christos 112 1.1 christos end: 113 1.1 christos fake_rsa_finish(fake_rsa); 114 1.1 christos OSSL_PROVIDER_unload(deflt); 115 1.1 christos EVP_PKEY_CTX_free(ctx); 116 1.1 christos EVP_PKEY_free(pkey); 117 1.1 christos return ret; 118 1.1 christos } 119 1.1 christos 120 1.1 christos static int test_alternative_keygen_init(void) 121 1.1 christos { 122 1.1 christos EVP_PKEY_CTX *ctx = NULL; 123 1.1 christos OSSL_PROVIDER *deflt = NULL; 124 1.1 christos OSSL_PROVIDER *fake_rsa = NULL; 125 1.1 christos const OSSL_PROVIDER *provider; 126 1.1 christos const char *provname; 127 1.1 christos int ret = 0; 128 1.1 christos 129 1.1 christos if (!TEST_ptr(deflt = OSSL_PROVIDER_load(libctx, "default"))) 130 1.1 christos goto end; 131 1.1 christos 132 1.1 christos /* first try without the fake RSA provider loaded */ 133 1.1 christos if (!TEST_ptr(ctx = EVP_PKEY_CTX_new_from_name(libctx, "RSA", NULL))) 134 1.1 christos goto end; 135 1.1 christos 136 1.1 christos if (!TEST_int_gt(EVP_PKEY_keygen_init(ctx), 0)) 137 1.1 christos goto end; 138 1.1 christos 139 1.1 christos if (!TEST_ptr(provider = EVP_PKEY_CTX_get0_provider(ctx))) 140 1.1 christos goto end; 141 1.1 christos 142 1.1 christos if (!TEST_ptr(provname = OSSL_PROVIDER_get0_name(provider))) 143 1.1 christos goto end; 144 1.1 christos 145 1.1 christos if (!TEST_str_eq(provname, "default")) 146 1.1 christos goto end; 147 1.1 christos 148 1.1 christos EVP_PKEY_CTX_free(ctx); 149 1.1 christos ctx = NULL; 150 1.1 christos 151 1.1 christos /* now load fake RSA and try again */ 152 1.1 christos if (!TEST_ptr(fake_rsa = fake_rsa_start(libctx))) 153 1.1 christos return 0; 154 1.1 christos 155 1.1 christos if (!TEST_ptr(ctx = EVP_PKEY_CTX_new_from_name(libctx, "RSA", 156 1.1.1.2 christos "?provider=fake-rsa"))) 157 1.1 christos goto end; 158 1.1 christos 159 1.1 christos if (!TEST_int_gt(EVP_PKEY_keygen_init(ctx), 0)) 160 1.1 christos goto end; 161 1.1 christos 162 1.1 christos if (!TEST_ptr(provider = EVP_PKEY_CTX_get0_provider(ctx))) 163 1.1 christos goto end; 164 1.1 christos 165 1.1 christos if (!TEST_ptr(provname = OSSL_PROVIDER_get0_name(provider))) 166 1.1 christos goto end; 167 1.1 christos 168 1.1 christos if (!TEST_str_eq(provname, "fake-rsa")) 169 1.1 christos goto end; 170 1.1 christos 171 1.1 christos ret = 1; 172 1.1 christos 173 1.1 christos end: 174 1.1 christos fake_rsa_finish(fake_rsa); 175 1.1 christos OSSL_PROVIDER_unload(deflt); 176 1.1 christos EVP_PKEY_CTX_free(ctx); 177 1.1 christos return ret; 178 1.1 christos } 179 1.1 christos 180 1.1 christos static int test_pkey_eq(void) 181 1.1 christos { 182 1.1 christos OSSL_PROVIDER *deflt = NULL; 183 1.1 christos OSSL_PROVIDER *fake_rsa = NULL; 184 1.1 christos EVP_PKEY *pkey_fake = NULL; 185 1.1 christos EVP_PKEY *pkey_dflt = NULL; 186 1.1 christos EVP_PKEY_CTX *ctx = NULL; 187 1.1 christos OSSL_PARAM *params = NULL; 188 1.1 christos int ret = 0; 189 1.1 christos 190 1.1 christos if (!TEST_ptr(fake_rsa = fake_rsa_start(libctx))) 191 1.1 christos return 0; 192 1.1 christos 193 1.1 christos if (!TEST_ptr(deflt = OSSL_PROVIDER_load(libctx, "default"))) 194 1.1 christos goto end; 195 1.1 christos 196 1.1 christos /* Construct a public key for fake-rsa */ 197 1.1 christos if (!TEST_ptr(params = fake_rsa_key_params(0)) 198 1.1 christos || !TEST_ptr(ctx = EVP_PKEY_CTX_new_from_name(libctx, "RSA", 199 1.1.1.2 christos "provider=fake-rsa")) 200 1.1 christos || !TEST_true(EVP_PKEY_fromdata_init(ctx)) 201 1.1 christos || !TEST_true(EVP_PKEY_fromdata(ctx, &pkey_fake, EVP_PKEY_PUBLIC_KEY, 202 1.1.1.2 christos params)) 203 1.1 christos || !TEST_ptr(pkey_fake)) 204 1.1 christos goto end; 205 1.1 christos 206 1.1 christos EVP_PKEY_CTX_free(ctx); 207 1.1 christos ctx = NULL; 208 1.1 christos OSSL_PARAM_free(params); 209 1.1 christos params = NULL; 210 1.1 christos 211 1.1 christos /* Construct a public key for default */ 212 1.1 christos if (!TEST_ptr(params = fake_rsa_key_params(0)) 213 1.1 christos || !TEST_ptr(ctx = EVP_PKEY_CTX_new_from_name(libctx, "RSA", 214 1.1.1.2 christos "provider=default")) 215 1.1 christos || !TEST_true(EVP_PKEY_fromdata_init(ctx)) 216 1.1 christos || !TEST_true(EVP_PKEY_fromdata(ctx, &pkey_dflt, EVP_PKEY_PUBLIC_KEY, 217 1.1.1.2 christos params)) 218 1.1 christos || !TEST_ptr(pkey_dflt)) 219 1.1 christos goto end; 220 1.1 christos 221 1.1 christos EVP_PKEY_CTX_free(ctx); 222 1.1 christos ctx = NULL; 223 1.1 christos OSSL_PARAM_free(params); 224 1.1 christos params = NULL; 225 1.1 christos 226 1.1 christos /* now test for equality */ 227 1.1 christos if (!TEST_int_eq(EVP_PKEY_eq(pkey_fake, pkey_dflt), 1)) 228 1.1 christos goto end; 229 1.1 christos 230 1.1 christos ret = 1; 231 1.1 christos end: 232 1.1 christos fake_rsa_finish(fake_rsa); 233 1.1 christos OSSL_PROVIDER_unload(deflt); 234 1.1 christos EVP_PKEY_CTX_free(ctx); 235 1.1 christos EVP_PKEY_free(pkey_fake); 236 1.1 christos EVP_PKEY_free(pkey_dflt); 237 1.1 christos OSSL_PARAM_free(params); 238 1.1 christos return ret; 239 1.1 christos } 240 1.1 christos 241 1.1.1.2 christos static int test_pkey_can_sign(void) 242 1.1.1.2 christos { 243 1.1.1.2 christos OSSL_PROVIDER *fake_rsa = NULL; 244 1.1.1.2 christos EVP_PKEY *pkey_fake = NULL; 245 1.1.1.2 christos EVP_PKEY_CTX *ctx = NULL; 246 1.1.1.2 christos OSSL_PARAM *params = NULL; 247 1.1.1.2 christos int ret = 0; 248 1.1.1.2 christos 249 1.1.1.2 christos if (!TEST_ptr(fake_rsa = fake_rsa_start(libctx))) 250 1.1.1.2 christos return 0; 251 1.1.1.2 christos 252 1.1.1.2 christos /* 253 1.1.1.2 christos * Ensure other tests did not forget to reset fake_rsa_query_operation_name 254 1.1.1.2 christos * to its default value: 0 255 1.1.1.2 christos */ 256 1.1.1.2 christos if (!TEST_int_eq(fake_rsa_query_operation_name, 0)) 257 1.1.1.2 christos goto end; 258 1.1.1.2 christos 259 1.1.1.2 christos if (!TEST_ptr(params = fake_rsa_key_params(0)) 260 1.1.1.2 christos || !TEST_ptr(ctx = EVP_PKEY_CTX_new_from_name(libctx, "RSA", 261 1.1.1.2 christos "provider=fake-rsa")) 262 1.1.1.2 christos || !TEST_true(EVP_PKEY_fromdata_init(ctx)) 263 1.1.1.2 christos || !TEST_true(EVP_PKEY_fromdata(ctx, &pkey_fake, EVP_PKEY_PUBLIC_KEY, 264 1.1.1.2 christos params)) 265 1.1.1.2 christos || !TEST_true(EVP_PKEY_can_sign(pkey_fake)) 266 1.1.1.2 christos || !TEST_ptr(pkey_fake)) 267 1.1.1.2 christos goto end; 268 1.1.1.2 christos 269 1.1.1.2 christos EVP_PKEY_CTX_free(ctx); 270 1.1.1.2 christos ctx = NULL; 271 1.1.1.2 christos EVP_PKEY_free(pkey_fake); 272 1.1.1.2 christos pkey_fake = NULL; 273 1.1.1.2 christos OSSL_PARAM_free(params); 274 1.1.1.2 christos params = NULL; 275 1.1.1.2 christos 276 1.1.1.2 christos /* 277 1.1.1.2 christos * Documented behavior for OSSL_FUNC_keymgmt_query_operation_name() 278 1.1.1.2 christos * allows it to return NULL, in which case the fallback should be to use 279 1.1.1.2 christos * EVP_KEYMGMT_get0_name(). That is exactly the thing we are testing here. 280 1.1.1.2 christos */ 281 1.1.1.2 christos fake_rsa_query_operation_name = 1; 282 1.1.1.2 christos 283 1.1.1.2 christos if (!TEST_ptr(params = fake_rsa_key_params(0)) 284 1.1.1.2 christos || !TEST_ptr(ctx = EVP_PKEY_CTX_new_from_name(libctx, "RSA", 285 1.1.1.2 christos "provider=fake-rsa")) 286 1.1.1.2 christos || !TEST_true(EVP_PKEY_fromdata_init(ctx)) 287 1.1.1.2 christos || !TEST_true(EVP_PKEY_fromdata(ctx, &pkey_fake, EVP_PKEY_PUBLIC_KEY, 288 1.1.1.2 christos params)) 289 1.1.1.2 christos || !TEST_true(EVP_PKEY_can_sign(pkey_fake)) 290 1.1.1.2 christos || !TEST_ptr(pkey_fake)) 291 1.1.1.2 christos goto end; 292 1.1.1.2 christos 293 1.1.1.2 christos EVP_PKEY_CTX_free(ctx); 294 1.1.1.2 christos ctx = NULL; 295 1.1.1.2 christos EVP_PKEY_free(pkey_fake); 296 1.1.1.2 christos pkey_fake = NULL; 297 1.1.1.2 christos OSSL_PARAM_free(params); 298 1.1.1.2 christos params = NULL; 299 1.1.1.2 christos 300 1.1.1.2 christos ret = 1; 301 1.1.1.2 christos end: 302 1.1.1.2 christos 303 1.1.1.2 christos EVP_PKEY_CTX_free(ctx); 304 1.1.1.2 christos EVP_PKEY_free(pkey_fake); 305 1.1.1.2 christos OSSL_PARAM_free(params); 306 1.1.1.2 christos fake_rsa_query_operation_name = 0; 307 1.1.1.2 christos 308 1.1.1.2 christos fake_rsa_finish(fake_rsa); 309 1.1.1.2 christos return ret; 310 1.1.1.2 christos } 311 1.1.1.2 christos 312 1.1 christos static int test_pkey_store(int idx) 313 1.1 christos { 314 1.1 christos OSSL_PROVIDER *deflt = NULL; 315 1.1 christos OSSL_PROVIDER *fake_rsa = NULL; 316 1.1 christos int ret = 0; 317 1.1 christos EVP_PKEY *pkey = NULL; 318 1.1 christos OSSL_STORE_LOADER *loader = NULL; 319 1.1 christos OSSL_STORE_CTX *ctx = NULL; 320 1.1 christos OSSL_STORE_INFO *info; 321 1.1 christos const char *propq = idx == 0 ? "?provider=fake-rsa" 322 1.1 christos : "?provider=default"; 323 1.1 christos 324 1.1 christos /* It's important to load the default provider first for this test */ 325 1.1 christos if (!TEST_ptr(deflt = OSSL_PROVIDER_load(libctx, "default"))) 326 1.1 christos goto end; 327 1.1 christos 328 1.1 christos if (!TEST_ptr(fake_rsa = fake_rsa_start(libctx))) 329 1.1 christos goto end; 330 1.1 christos 331 1.1 christos if (!TEST_ptr(loader = OSSL_STORE_LOADER_fetch(libctx, "fake_rsa", 332 1.1.1.2 christos propq))) 333 1.1 christos goto end; 334 1.1 christos 335 1.1 christos OSSL_STORE_LOADER_free(loader); 336 1.1 christos 337 1.1 christos if (!TEST_ptr(ctx = OSSL_STORE_open_ex("fake_rsa:test", libctx, propq, 338 1.1.1.2 christos NULL, NULL, NULL, NULL, NULL))) 339 1.1 christos goto end; 340 1.1 christos 341 1.1 christos while (!OSSL_STORE_eof(ctx) 342 1.1.1.2 christos && (info = OSSL_STORE_load(ctx)) != NULL 343 1.1.1.2 christos && pkey == NULL) { 344 1.1 christos if (OSSL_STORE_INFO_get_type(info) == OSSL_STORE_INFO_PKEY) 345 1.1 christos pkey = OSSL_STORE_INFO_get1_PKEY(info); 346 1.1 christos OSSL_STORE_INFO_free(info); 347 1.1 christos info = NULL; 348 1.1 christos } 349 1.1 christos 350 1.1 christos if (!TEST_ptr(pkey) || !TEST_int_eq(EVP_PKEY_is_a(pkey, "RSA"), 1)) 351 1.1 christos goto end; 352 1.1 christos 353 1.1 christos ret = 1; 354 1.1 christos 355 1.1 christos end: 356 1.1 christos fake_rsa_finish(fake_rsa); 357 1.1 christos OSSL_PROVIDER_unload(deflt); 358 1.1 christos OSSL_STORE_close(ctx); 359 1.1 christos EVP_PKEY_free(pkey); 360 1.1 christos return ret; 361 1.1 christos } 362 1.1 christos 363 1.1 christos static int test_pkey_delete(void) 364 1.1 christos { 365 1.1 christos OSSL_PROVIDER *deflt = NULL; 366 1.1 christos OSSL_PROVIDER *fake_rsa = NULL; 367 1.1 christos int ret = 0; 368 1.1 christos EVP_PKEY *pkey = NULL; 369 1.1 christos OSSL_STORE_LOADER *loader = NULL; 370 1.1 christos OSSL_STORE_CTX *ctx = NULL; 371 1.1 christos OSSL_STORE_INFO *info; 372 1.1 christos const char *propq = "?provider=fake-rsa"; 373 1.1 christos 374 1.1 christos /* It's important to load the default provider first for this test */ 375 1.1 christos if (!TEST_ptr(deflt = OSSL_PROVIDER_load(libctx, "default"))) 376 1.1 christos goto end; 377 1.1 christos 378 1.1 christos if (!TEST_ptr(fake_rsa = fake_rsa_start(libctx))) 379 1.1 christos goto end; 380 1.1 christos 381 1.1 christos if (!TEST_ptr(loader = OSSL_STORE_LOADER_fetch(libctx, "fake_rsa", 382 1.1.1.2 christos propq))) 383 1.1 christos goto end; 384 1.1 christos 385 1.1 christos OSSL_STORE_LOADER_free(loader); 386 1.1 christos 387 1.1 christos /* First iteration: load key, check it, delete it */ 388 1.1 christos if (!TEST_ptr(ctx = OSSL_STORE_open_ex("fake_rsa:test", libctx, propq, 389 1.1.1.2 christos NULL, NULL, NULL, NULL, NULL))) 390 1.1 christos goto end; 391 1.1 christos 392 1.1 christos while (!OSSL_STORE_eof(ctx) 393 1.1.1.2 christos && (info = OSSL_STORE_load(ctx)) != NULL 394 1.1.1.2 christos && pkey == NULL) { 395 1.1 christos if (OSSL_STORE_INFO_get_type(info) == OSSL_STORE_INFO_PKEY) 396 1.1 christos pkey = OSSL_STORE_INFO_get1_PKEY(info); 397 1.1 christos OSSL_STORE_INFO_free(info); 398 1.1 christos info = NULL; 399 1.1 christos } 400 1.1 christos 401 1.1 christos if (!TEST_ptr(pkey) || !TEST_int_eq(EVP_PKEY_is_a(pkey, "RSA"), 1)) 402 1.1 christos goto end; 403 1.1 christos EVP_PKEY_free(pkey); 404 1.1 christos pkey = NULL; 405 1.1 christos 406 1.1 christos if (!TEST_int_eq(OSSL_STORE_delete("fake_rsa:test", libctx, propq, 407 1.1.1.2 christos NULL, NULL, NULL), 408 1.1.1.2 christos 1)) 409 1.1 christos goto end; 410 1.1 christos if (!TEST_int_eq(OSSL_STORE_close(ctx), 1)) 411 1.1 christos goto end; 412 1.1 christos 413 1.1 christos /* Second iteration: load key should fail */ 414 1.1 christos if (!TEST_ptr(ctx = OSSL_STORE_open_ex("fake_rsa:test", libctx, propq, 415 1.1.1.2 christos NULL, NULL, NULL, NULL, NULL))) 416 1.1 christos goto end; 417 1.1 christos 418 1.1 christos while (!OSSL_STORE_eof(ctx)) { 419 1.1.1.2 christos info = OSSL_STORE_load(ctx); 420 1.1.1.2 christos if (!TEST_ptr_null(info)) 421 1.1.1.2 christos goto end; 422 1.1 christos } 423 1.1 christos 424 1.1 christos ret = 1; 425 1.1 christos 426 1.1 christos end: 427 1.1 christos fake_rsa_finish(fake_rsa); 428 1.1 christos OSSL_PROVIDER_unload(deflt); 429 1.1 christos OSSL_STORE_close(ctx); 430 1.1 christos fake_rsa_restore_store_state(); 431 1.1 christos return ret; 432 1.1 christos } 433 1.1 christos 434 1.1 christos static int fake_pw_read_string(UI *ui, UI_STRING *uis) 435 1.1 christos { 436 1.1 christos const char *passphrase = FAKE_PASSPHRASE; 437 1.1 christos 438 1.1 christos if (UI_get_string_type(uis) == UIT_PROMPT) { 439 1.1 christos UI_set_result(ui, uis, passphrase); 440 1.1 christos return 1; 441 1.1 christos } 442 1.1 christos 443 1.1 christos return 0; 444 1.1 christos } 445 1.1 christos 446 1.1 christos static int test_pkey_store_open_ex(void) 447 1.1 christos { 448 1.1 christos OSSL_PROVIDER *deflt = NULL; 449 1.1 christos OSSL_PROVIDER *fake_rsa = NULL; 450 1.1 christos int ret = 0; 451 1.1 christos EVP_PKEY *pkey = NULL; 452 1.1 christos OSSL_STORE_LOADER *loader = NULL; 453 1.1 christos OSSL_STORE_CTX *ctx = NULL; 454 1.1 christos const char *propq = "?provider=fake-rsa"; 455 1.1 christos UI_METHOD *ui_method = NULL; 456 1.1 christos 457 1.1 christos /* It's important to load the default provider first for this test */ 458 1.1 christos if (!TEST_ptr(deflt = OSSL_PROVIDER_load(libctx, "default"))) 459 1.1 christos goto end; 460 1.1 christos 461 1.1 christos if (!TEST_ptr(fake_rsa = fake_rsa_start(libctx))) 462 1.1 christos goto end; 463 1.1 christos 464 1.1 christos if (!TEST_ptr(loader = OSSL_STORE_LOADER_fetch(libctx, "fake_rsa", 465 1.1.1.2 christos propq))) 466 1.1 christos goto end; 467 1.1 christos 468 1.1 christos OSSL_STORE_LOADER_free(loader); 469 1.1 christos 470 1.1.1.2 christos if (!TEST_ptr(ui_method = UI_create_method("PW Callbacks"))) 471 1.1 christos goto end; 472 1.1 christos 473 1.1 christos if (UI_method_set_reader(ui_method, fake_pw_read_string)) 474 1.1 christos goto end; 475 1.1 christos 476 1.1 christos if (!TEST_ptr(ctx = OSSL_STORE_open_ex("fake_rsa:openpwtest", libctx, propq, 477 1.1.1.2 christos ui_method, NULL, NULL, NULL, NULL))) 478 1.1 christos goto end; 479 1.1 christos 480 1.1 christos /* retry w/o ui_method to ensure we actually enter pw checks and fail */ 481 1.1 christos OSSL_STORE_close(ctx); 482 1.1 christos if (!TEST_ptr_null(ctx = OSSL_STORE_open_ex("fake_rsa:openpwtest", libctx, 483 1.1.1.2 christos propq, NULL, NULL, NULL, NULL, 484 1.1.1.2 christos NULL))) 485 1.1 christos goto end; 486 1.1 christos 487 1.1 christos ret = 1; 488 1.1 christos 489 1.1 christos end: 490 1.1 christos UI_destroy_method(ui_method); 491 1.1 christos fake_rsa_finish(fake_rsa); 492 1.1 christos OSSL_PROVIDER_unload(deflt); 493 1.1 christos OSSL_STORE_close(ctx); 494 1.1 christos EVP_PKEY_free(pkey); 495 1.1 christos return ret; 496 1.1 christos } 497 1.1 christos 498 1.1.1.2 christos #define DEFAULT_PROVIDER_IDX 0 499 1.1.1.2 christos #define FAKE_RSA_PROVIDER_IDX 1 500 1.1.1.2 christos 501 1.1.1.2 christos static int reset_ctx_providers(OSSL_LIB_CTX **ctx, OSSL_PROVIDER *providers[2], const char *prop) 502 1.1.1.2 christos { 503 1.1.1.2 christos OSSL_PROVIDER_unload(providers[DEFAULT_PROVIDER_IDX]); 504 1.1.1.2 christos providers[DEFAULT_PROVIDER_IDX] = NULL; 505 1.1.1.2 christos fake_rsa_finish(providers[FAKE_RSA_PROVIDER_IDX]); 506 1.1.1.2 christos providers[FAKE_RSA_PROVIDER_IDX] = NULL; 507 1.1.1.2 christos OSSL_LIB_CTX_free(*ctx); 508 1.1.1.2 christos *ctx = NULL; 509 1.1.1.2 christos 510 1.1.1.2 christos if (!TEST_ptr(*ctx = OSSL_LIB_CTX_new()) 511 1.1.1.2 christos || !TEST_ptr(providers[DEFAULT_PROVIDER_IDX] = OSSL_PROVIDER_load(*ctx, "default")) 512 1.1.1.2 christos || !TEST_ptr(providers[FAKE_RSA_PROVIDER_IDX] = fake_rsa_start(*ctx)) 513 1.1.1.2 christos || !TEST_true(EVP_set_default_properties(*ctx, prop))) 514 1.1.1.2 christos return 0; 515 1.1.1.2 christos return 1; 516 1.1.1.2 christos } 517 1.1.1.2 christos 518 1.1.1.2 christos struct test_pkey_decoder_properties_t { 519 1.1.1.2 christos const char *provider_props; 520 1.1.1.2 christos const char *explicit_props; 521 1.1.1.2 christos int curr_provider_idx; 522 1.1.1.2 christos }; 523 1.1.1.2 christos 524 1.1.1.2 christos static int test_pkey_provider_decoder_props(void) 525 1.1.1.2 christos { 526 1.1.1.2 christos OSSL_LIB_CTX *my_libctx = NULL; 527 1.1.1.2 christos OSSL_PROVIDER *providers[2] = { NULL }; 528 1.1.1.2 christos struct test_pkey_decoder_properties_t properties_test[] = { 529 1.1.1.2 christos { "?provider=fake-rsa", NULL, FAKE_RSA_PROVIDER_IDX }, 530 1.1.1.2 christos { "?provider=default", NULL, DEFAULT_PROVIDER_IDX }, 531 1.1.1.2 christos { NULL, "?provider=fake-rsa", FAKE_RSA_PROVIDER_IDX }, 532 1.1.1.2 christos { NULL, "?provider=default", DEFAULT_PROVIDER_IDX }, 533 1.1.1.2 christos { NULL, "provider=fake-rsa", FAKE_RSA_PROVIDER_IDX }, 534 1.1.1.2 christos { NULL, "provider=default", DEFAULT_PROVIDER_IDX }, 535 1.1.1.2 christos }; 536 1.1.1.2 christos EVP_PKEY *pkey = NULL; 537 1.1.1.2 christos BIO *bio_priv = NULL; 538 1.1.1.2 christos unsigned char *encoded_pub = NULL; 539 1.1.1.2 christos int len_pub; 540 1.1.1.2 christos const unsigned char *p; 541 1.1.1.2 christos PKCS8_PRIV_KEY_INFO *p8 = NULL; 542 1.1.1.2 christos size_t i; 543 1.1.1.2 christos int ret = 0; 544 1.1.1.2 christos const char pem_rsa_priv_key[] = { 545 1.1.1.2 christos 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x42, 0x45, 0x47, 0x49, 0x4E, 0x20, 0x50, 546 1.1.1.2 christos 0x52, 0x49, 0x56, 0x41, 0x54, 0x45, 0x20, 0x4B, 0x45, 0x59, 0x2D, 0x2D, 547 1.1.1.2 christos 0x2D, 0x2D, 0x2D, 0x0A, 0x4D, 0x49, 0x49, 0x45, 0x76, 0x51, 0x49, 0x42, 548 1.1.1.2 christos 0x41, 0x44, 0x41, 0x4E, 0x42, 0x67, 0x6B, 0x71, 0x68, 0x6B, 0x69, 0x47, 549 1.1.1.2 christos 0x39, 0x77, 0x30, 0x42, 0x41, 0x51, 0x45, 0x46, 0x41, 0x41, 0x53, 0x43, 550 1.1.1.2 christos 0x42, 0x4B, 0x63, 0x77, 0x67, 0x67, 0x53, 0x6A, 0x41, 0x67, 0x45, 0x41, 551 1.1.1.2 christos 0x41, 0x6F, 0x49, 0x42, 0x41, 0x51, 0x44, 0x45, 0x6B, 0x43, 0x34, 0x5A, 552 1.1.1.2 christos 0x57, 0x76, 0x33, 0x75, 0x63, 0x46, 0x62, 0x55, 0x0A, 0x46, 0x38, 0x59, 553 1.1.1.2 christos 0x77, 0x6C, 0x55, 0x72, 0x6D, 0x51, 0x6C, 0x4C, 0x43, 0x5A, 0x77, 0x41, 554 1.1.1.2 christos 0x67, 0x72, 0x34, 0x44, 0x50, 0x55, 0x41, 0x46, 0x56, 0x48, 0x6C, 0x2B, 555 1.1.1.2 christos 0x77, 0x46, 0x63, 0x58, 0x79, 0x70, 0x56, 0x67, 0x53, 0x63, 0x56, 0x59, 556 1.1.1.2 christos 0x34, 0x4B, 0x37, 0x51, 0x6D, 0x64, 0x57, 0x4B, 0x73, 0x59, 0x71, 0x62, 557 1.1.1.2 christos 0x38, 0x74, 0x70, 0x4F, 0x78, 0x71, 0x77, 0x30, 0x4E, 0x77, 0x5A, 0x57, 558 1.1.1.2 christos 0x58, 0x0A, 0x4F, 0x2B, 0x74, 0x61, 0x34, 0x2B, 0x79, 0x32, 0x37, 0x43, 559 1.1.1.2 christos 0x4F, 0x75, 0x66, 0x6F, 0x4F, 0x68, 0x52, 0x54, 0x4D, 0x77, 0x4E, 0x79, 560 1.1.1.2 christos 0x4E, 0x32, 0x4C, 0x77, 0x53, 0x4E, 0x54, 0x50, 0x4E, 0x33, 0x65, 0x45, 561 1.1.1.2 christos 0x6B, 0x34, 0x65, 0x65, 0x35, 0x51, 0x6E, 0x70, 0x70, 0x45, 0x79, 0x44, 562 1.1.1.2 christos 0x72, 0x71, 0x6F, 0x43, 0x67, 0x76, 0x54, 0x6C, 0x41, 0x41, 0x64, 0x54, 563 1.1.1.2 christos 0x6F, 0x46, 0x61, 0x58, 0x76, 0x6A, 0x0A, 0x78, 0x31, 0x33, 0x59, 0x62, 564 1.1.1.2 christos 0x6A, 0x37, 0x6A, 0x66, 0x68, 0x77, 0x4E, 0x37, 0x34, 0x71, 0x4B, 0x64, 565 1.1.1.2 christos 0x71, 0x73, 0x53, 0x45, 0x74, 0x50, 0x57, 0x79, 0x67, 0x67, 0x65, 0x6F, 566 1.1.1.2 christos 0x74, 0x69, 0x51, 0x53, 0x50, 0x79, 0x36, 0x4B, 0x79, 0x42, 0x49, 0x75, 567 1.1.1.2 christos 0x57, 0x74, 0x49, 0x78, 0x50, 0x41, 0x41, 0x38, 0x6A, 0x41, 0x76, 0x66, 568 1.1.1.2 christos 0x41, 0x6E, 0x51, 0x6A, 0x31, 0x65, 0x58, 0x68, 0x67, 0x68, 0x46, 0x0A, 569 1.1.1.2 christos 0x4E, 0x32, 0x4E, 0x78, 0x6B, 0x71, 0x67, 0x78, 0x76, 0x42, 0x59, 0x64, 570 1.1.1.2 christos 0x4E, 0x79, 0x31, 0x6D, 0x33, 0x2B, 0x6A, 0x58, 0x41, 0x43, 0x50, 0x4C, 571 1.1.1.2 christos 0x52, 0x7A, 0x63, 0x31, 0x31, 0x5A, 0x62, 0x4E, 0x48, 0x4B, 0x69, 0x77, 572 1.1.1.2 christos 0x68, 0x43, 0x59, 0x31, 0x2F, 0x48, 0x69, 0x53, 0x42, 0x6B, 0x77, 0x48, 573 1.1.1.2 christos 0x6C, 0x49, 0x4B, 0x2B, 0x2F, 0x56, 0x4C, 0x6A, 0x32, 0x73, 0x6D, 0x43, 574 1.1.1.2 christos 0x4B, 0x64, 0x55, 0x51, 0x0A, 0x67, 0x76, 0x4C, 0x58, 0x53, 0x6E, 0x6E, 575 1.1.1.2 christos 0x56, 0x67, 0x51, 0x75, 0x6C, 0x48, 0x69, 0x6F, 0x44, 0x36, 0x55, 0x67, 576 1.1.1.2 christos 0x59, 0x38, 0x78, 0x41, 0x32, 0x61, 0x34, 0x4D, 0x31, 0x72, 0x68, 0x59, 577 1.1.1.2 christos 0x75, 0x54, 0x56, 0x38, 0x42, 0x72, 0x50, 0x52, 0x5A, 0x34, 0x42, 0x46, 578 1.1.1.2 christos 0x78, 0x32, 0x6F, 0x30, 0x6A, 0x59, 0x57, 0x76, 0x47, 0x62, 0x41, 0x2F, 579 1.1.1.2 christos 0x48, 0x6C, 0x70, 0x37, 0x66, 0x54, 0x4F, 0x79, 0x2B, 0x0A, 0x46, 0x35, 580 1.1.1.2 christos 0x4F, 0x6B, 0x69, 0x48, 0x53, 0x37, 0x41, 0x67, 0x4D, 0x42, 0x41, 0x41, 581 1.1.1.2 christos 0x45, 0x43, 0x67, 0x67, 0x45, 0x41, 0x59, 0x67, 0x43, 0x75, 0x38, 0x31, 582 1.1.1.2 christos 0x5A, 0x69, 0x51, 0x42, 0x56, 0x44, 0x76, 0x57, 0x69, 0x44, 0x47, 0x4B, 583 1.1.1.2 christos 0x72, 0x2B, 0x31, 0x70, 0x49, 0x66, 0x32, 0x43, 0x78, 0x70, 0x72, 0x47, 584 1.1.1.2 christos 0x4A, 0x45, 0x6D, 0x31, 0x68, 0x38, 0x36, 0x5A, 0x63, 0x45, 0x78, 0x33, 585 1.1.1.2 christos 0x4C, 0x37, 0x0A, 0x71, 0x46, 0x44, 0x57, 0x2B, 0x67, 0x38, 0x48, 0x47, 586 1.1.1.2 christos 0x57, 0x64, 0x30, 0x34, 0x53, 0x33, 0x71, 0x76, 0x68, 0x39, 0x4C, 0x75, 587 1.1.1.2 christos 0x62, 0x6C, 0x41, 0x4A, 0x7A, 0x65, 0x74, 0x41, 0x50, 0x78, 0x52, 0x58, 588 1.1.1.2 christos 0x4C, 0x39, 0x7A, 0x78, 0x33, 0x50, 0x58, 0x6A, 0x4A, 0x5A, 0x73, 0x37, 589 1.1.1.2 christos 0x65, 0x33, 0x48, 0x4C, 0x45, 0x75, 0x6E, 0x79, 0x33, 0x54, 0x61, 0x57, 590 1.1.1.2 christos 0x65, 0x7A, 0x30, 0x58, 0x49, 0x30, 0x4F, 0x0A, 0x34, 0x4C, 0x53, 0x59, 591 1.1.1.2 christos 0x38, 0x53, 0x38, 0x64, 0x36, 0x70, 0x56, 0x42, 0x50, 0x6D, 0x55, 0x45, 592 1.1.1.2 christos 0x74, 0x77, 0x47, 0x57, 0x4E, 0x34, 0x76, 0x59, 0x71, 0x48, 0x6E, 0x4B, 593 1.1.1.2 christos 0x4C, 0x58, 0x4F, 0x62, 0x34, 0x51, 0x51, 0x41, 0x58, 0x73, 0x34, 0x4D, 594 1.1.1.2 christos 0x7A, 0x66, 0x6B, 0x4D, 0x2F, 0x4D, 0x65, 0x2F, 0x62, 0x2B, 0x7A, 0x64, 595 1.1.1.2 christos 0x75, 0x31, 0x75, 0x6D, 0x77, 0x6A, 0x4D, 0x6C, 0x33, 0x44, 0x75, 0x64, 596 1.1.1.2 christos 0x0A, 0x35, 0x72, 0x56, 0x68, 0x6B, 0x67, 0x76, 0x74, 0x38, 0x75, 0x68, 597 1.1.1.2 christos 0x44, 0x55, 0x47, 0x33, 0x58, 0x53, 0x48, 0x65, 0x6F, 0x4A, 0x59, 0x42, 598 1.1.1.2 christos 0x4D, 0x62, 0x54, 0x39, 0x69, 0x6B, 0x4A, 0x44, 0x56, 0x4D, 0x4A, 0x35, 599 1.1.1.2 christos 0x31, 0x72, 0x72, 0x65, 0x2F, 0x31, 0x52, 0x69, 0x64, 0x64, 0x67, 0x78, 600 1.1.1.2 christos 0x70, 0x38, 0x53, 0x6B, 0x74, 0x56, 0x6B, 0x76, 0x47, 0x6D, 0x4D, 0x6C, 601 1.1.1.2 christos 0x39, 0x6B, 0x51, 0x52, 0x38, 0x0A, 0x38, 0x64, 0x76, 0x33, 0x50, 0x78, 602 1.1.1.2 christos 0x2F, 0x6B, 0x54, 0x4E, 0x39, 0x34, 0x45, 0x75, 0x52, 0x67, 0x30, 0x43, 603 1.1.1.2 christos 0x6B, 0x58, 0x42, 0x68, 0x48, 0x70, 0x6F, 0x47, 0x6F, 0x34, 0x71, 0x6E, 604 1.1.1.2 christos 0x4D, 0x33, 0x51, 0x33, 0x42, 0x35, 0x50, 0x6C, 0x6D, 0x53, 0x4B, 0x35, 605 1.1.1.2 christos 0x67, 0x6B, 0x75, 0x50, 0x76, 0x57, 0x79, 0x39, 0x6C, 0x38, 0x4C, 0x2F, 606 1.1.1.2 christos 0x54, 0x56, 0x74, 0x38, 0x4C, 0x62, 0x36, 0x2F, 0x7A, 0x4C, 0x0A, 0x42, 607 1.1.1.2 christos 0x79, 0x51, 0x57, 0x2B, 0x67, 0x30, 0x32, 0x77, 0x78, 0x65, 0x4E, 0x47, 608 1.1.1.2 christos 0x68, 0x77, 0x31, 0x66, 0x6B, 0x44, 0x2B, 0x58, 0x46, 0x48, 0x37, 0x4B, 609 1.1.1.2 christos 0x6B, 0x53, 0x65, 0x57, 0x6C, 0x2B, 0x51, 0x6E, 0x72, 0x4C, 0x63, 0x65, 610 1.1.1.2 christos 0x50, 0x4D, 0x30, 0x68, 0x51, 0x4B, 0x42, 0x67, 0x51, 0x44, 0x78, 0x6F, 611 1.1.1.2 christos 0x71, 0x55, 0x6B, 0x30, 0x50, 0x4C, 0x4F, 0x59, 0x35, 0x57, 0x67, 0x4F, 612 1.1.1.2 christos 0x6B, 0x67, 0x72, 0x0A, 0x75, 0x6D, 0x67, 0x69, 0x65, 0x2F, 0x4B, 0x31, 613 1.1.1.2 christos 0x57, 0x4B, 0x73, 0x2B, 0x69, 0x7A, 0x54, 0x74, 0x41, 0x70, 0x6A, 0x7A, 614 1.1.1.2 christos 0x63, 0x4D, 0x37, 0x36, 0x73, 0x7A, 0x61, 0x36, 0x33, 0x62, 0x35, 0x52, 615 1.1.1.2 christos 0x39, 0x77, 0x2B, 0x50, 0x2B, 0x4E, 0x73, 0x73, 0x4D, 0x56, 0x34, 0x61, 616 1.1.1.2 christos 0x65, 0x56, 0x39, 0x65, 0x70, 0x45, 0x47, 0x5A, 0x4F, 0x36, 0x38, 0x49, 617 1.1.1.2 christos 0x55, 0x6D, 0x69, 0x30, 0x51, 0x6A, 0x76, 0x51, 0x0A, 0x6E, 0x70, 0x6C, 618 1.1.1.2 christos 0x75, 0x51, 0x6F, 0x61, 0x64, 0x46, 0x59, 0x77, 0x65, 0x46, 0x77, 0x53, 619 1.1.1.2 christos 0x51, 0x31, 0x31, 0x42, 0x58, 0x48, 0x6F, 0x65, 0x51, 0x42, 0x41, 0x34, 620 1.1.1.2 christos 0x6E, 0x4E, 0x70, 0x6B, 0x72, 0x56, 0x35, 0x38, 0x68, 0x67, 0x7A, 0x5A, 621 1.1.1.2 christos 0x4E, 0x33, 0x6D, 0x39, 0x4A, 0x4C, 0x52, 0x37, 0x4A, 0x78, 0x79, 0x72, 622 1.1.1.2 christos 0x49, 0x71, 0x58, 0x73, 0x52, 0x6E, 0x55, 0x7A, 0x6C, 0x31, 0x33, 0x4B, 623 1.1.1.2 christos 0x6A, 0x0A, 0x47, 0x7A, 0x5A, 0x42, 0x43, 0x4A, 0x78, 0x43, 0x70, 0x4A, 624 1.1.1.2 christos 0x6A, 0x66, 0x54, 0x7A, 0x65, 0x2F, 0x79, 0x6D, 0x65, 0x38, 0x64, 0x33, 625 1.1.1.2 christos 0x70, 0x61, 0x35, 0x51, 0x4B, 0x42, 0x67, 0x51, 0x44, 0x51, 0x50, 0x35, 626 1.1.1.2 christos 0x6D, 0x42, 0x34, 0x6A, 0x49, 0x2B, 0x67, 0x33, 0x58, 0x48, 0x33, 0x4D, 627 1.1.1.2 christos 0x75, 0x4C, 0x79, 0x42, 0x6A, 0x4D, 0x6F, 0x54, 0x49, 0x76, 0x6F, 0x79, 628 1.1.1.2 christos 0x37, 0x43, 0x59, 0x4D, 0x68, 0x5A, 0x0A, 0x36, 0x2F, 0x2B, 0x4B, 0x6B, 629 1.1.1.2 christos 0x70, 0x77, 0x31, 0x33, 0x32, 0x4A, 0x31, 0x36, 0x6D, 0x71, 0x6B, 0x4C, 630 1.1.1.2 christos 0x72, 0x77, 0x55, 0x4F, 0x5A, 0x66, 0x54, 0x30, 0x65, 0x31, 0x72, 0x4A, 631 1.1.1.2 christos 0x42, 0x73, 0x43, 0x55, 0x6B, 0x45, 0x6F, 0x42, 0x6D, 0x67, 0x4B, 0x4E, 632 1.1.1.2 christos 0x74, 0x52, 0x6B, 0x48, 0x6F, 0x33, 0x2F, 0x53, 0x6A, 0x55, 0x49, 0x2F, 633 1.1.1.2 christos 0x39, 0x66, 0x48, 0x6A, 0x33, 0x75, 0x53, 0x74, 0x50, 0x48, 0x56, 0x0A, 634 1.1.1.2 christos 0x6F, 0x50, 0x63, 0x66, 0x58, 0x6A, 0x2F, 0x67, 0x46, 0x52, 0x55, 0x6B, 635 1.1.1.2 christos 0x44, 0x44, 0x7A, 0x59, 0x2B, 0x61, 0x75, 0x42, 0x33, 0x64, 0x48, 0x4F, 636 1.1.1.2 christos 0x4E, 0x46, 0x31, 0x55, 0x31, 0x7A, 0x30, 0x36, 0x45, 0x41, 0x4E, 0x6B, 637 1.1.1.2 christos 0x6B, 0x50, 0x43, 0x43, 0x33, 0x61, 0x35, 0x33, 0x38, 0x55, 0x41, 0x4E, 638 1.1.1.2 christos 0x42, 0x49, 0x61, 0x50, 0x6A, 0x77, 0x70, 0x52, 0x64, 0x42, 0x7A, 0x4E, 639 1.1.1.2 christos 0x77, 0x31, 0x78, 0x6C, 0x0A, 0x62, 0x76, 0x6E, 0x35, 0x61, 0x43, 0x74, 640 1.1.1.2 christos 0x33, 0x48, 0x77, 0x4B, 0x42, 0x67, 0x42, 0x66, 0x4F, 0x6C, 0x34, 0x6A, 641 1.1.1.2 christos 0x47, 0x45, 0x58, 0x59, 0x6D, 0x4E, 0x36, 0x4B, 0x2B, 0x75, 0x30, 0x65, 642 1.1.1.2 christos 0x62, 0x71, 0x52, 0x44, 0x6B, 0x74, 0x32, 0x67, 0x49, 0x6F, 0x57, 0x36, 643 1.1.1.2 christos 0x62, 0x46, 0x6F, 0x37, 0x58, 0x64, 0x36, 0x78, 0x63, 0x69, 0x2F, 0x67, 644 1.1.1.2 christos 0x46, 0x57, 0x6A, 0x6F, 0x56, 0x43, 0x4F, 0x42, 0x59, 0x0A, 0x67, 0x43, 645 1.1.1.2 christos 0x38, 0x47, 0x4C, 0x4D, 0x6E, 0x77, 0x33, 0x7A, 0x32, 0x71, 0x67, 0x61, 646 1.1.1.2 christos 0x76, 0x34, 0x63, 0x51, 0x49, 0x67, 0x38, 0x45, 0x44, 0x59, 0x70, 0x62, 647 1.1.1.2 christos 0x70, 0x45, 0x34, 0x46, 0x48, 0x51, 0x6E, 0x6E, 0x74, 0x50, 0x6B, 0x4B, 648 1.1.1.2 christos 0x57, 0x2F, 0x62, 0x72, 0x75, 0x30, 0x4E, 0x74, 0x33, 0x79, 0x61, 0x4E, 649 1.1.1.2 christos 0x62, 0x38, 0x69, 0x67, 0x79, 0x31, 0x61, 0x5A, 0x4F, 0x52, 0x66, 0x49, 650 1.1.1.2 christos 0x76, 0x5A, 0x0A, 0x71, 0x54, 0x4D, 0x4C, 0x45, 0x33, 0x6D, 0x65, 0x6C, 651 1.1.1.2 christos 0x63, 0x5A, 0x57, 0x37, 0x4C, 0x61, 0x69, 0x71, 0x65, 0x4E, 0x31, 0x56, 652 1.1.1.2 christos 0x30, 0x76, 0x48, 0x2F, 0x4D, 0x43, 0x55, 0x64, 0x70, 0x58, 0x39, 0x59, 653 1.1.1.2 christos 0x31, 0x34, 0x4B, 0x39, 0x43, 0x4A, 0x59, 0x78, 0x7A, 0x73, 0x52, 0x4F, 654 1.1.1.2 christos 0x67, 0x50, 0x71, 0x64, 0x45, 0x67, 0x4D, 0x57, 0x59, 0x44, 0x46, 0x41, 655 1.1.1.2 christos 0x6F, 0x47, 0x41, 0x41, 0x65, 0x39, 0x6C, 0x0A, 0x58, 0x4D, 0x69, 0x65, 656 1.1.1.2 christos 0x55, 0x4F, 0x68, 0x6C, 0x30, 0x73, 0x71, 0x68, 0x64, 0x5A, 0x59, 0x52, 657 1.1.1.2 christos 0x62, 0x4F, 0x31, 0x65, 0x69, 0x77, 0x54, 0x49, 0x4C, 0x58, 0x51, 0x36, 658 1.1.1.2 christos 0x79, 0x47, 0x4D, 0x69, 0x42, 0x38, 0x61, 0x65, 0x2F, 0x76, 0x30, 0x70, 659 1.1.1.2 christos 0x62, 0x42, 0x45, 0x57, 0x6C, 0x70, 0x6E, 0x38, 0x6B, 0x32, 0x2B, 0x4A, 660 1.1.1.2 christos 0x6B, 0x71, 0x56, 0x54, 0x77, 0x48, 0x67, 0x67, 0x62, 0x43, 0x41, 0x5A, 661 1.1.1.2 christos 0x0A, 0x6A, 0x4F, 0x61, 0x71, 0x56, 0x74, 0x58, 0x31, 0x6D, 0x55, 0x79, 662 1.1.1.2 christos 0x54, 0x59, 0x7A, 0x6A, 0x73, 0x54, 0x7A, 0x34, 0x5A, 0x59, 0x6A, 0x68, 663 1.1.1.2 christos 0x61, 0x48, 0x4A, 0x33, 0x6A, 0x31, 0x57, 0x6C, 0x65, 0x67, 0x6F, 0x4D, 664 1.1.1.2 christos 0x63, 0x73, 0x74, 0x64, 0x66, 0x54, 0x2B, 0x74, 0x78, 0x4D, 0x55, 0x37, 665 1.1.1.2 christos 0x34, 0x6F, 0x67, 0x64, 0x4F, 0x71, 0x4D, 0x7A, 0x68, 0x78, 0x53, 0x55, 666 1.1.1.2 christos 0x4F, 0x34, 0x35, 0x67, 0x38, 0x0A, 0x66, 0x39, 0x57, 0x38, 0x39, 0x6D, 667 1.1.1.2 christos 0x70, 0x61, 0x38, 0x62, 0x42, 0x6A, 0x4F, 0x50, 0x75, 0x2B, 0x79, 0x46, 668 1.1.1.2 christos 0x79, 0x36, 0x36, 0x74, 0x44, 0x61, 0x5A, 0x36, 0x73, 0x57, 0x45, 0x37, 669 1.1.1.2 christos 0x63, 0x35, 0x53, 0x58, 0x45, 0x48, 0x58, 0x6C, 0x38, 0x43, 0x67, 0x59, 670 1.1.1.2 christos 0x45, 0x41, 0x74, 0x41, 0x57, 0x77, 0x46, 0x50, 0x6F, 0x44, 0x53, 0x54, 671 1.1.1.2 christos 0x64, 0x7A, 0x6F, 0x58, 0x41, 0x77, 0x52, 0x6F, 0x66, 0x30, 0x0A, 0x51, 672 1.1.1.2 christos 0x4D, 0x4F, 0x30, 0x38, 0x2B, 0x50, 0x6E, 0x51, 0x47, 0x6F, 0x50, 0x62, 673 1.1.1.2 christos 0x4D, 0x4A, 0x54, 0x71, 0x72, 0x67, 0x78, 0x72, 0x48, 0x59, 0x43, 0x53, 674 1.1.1.2 christos 0x38, 0x75, 0x34, 0x63, 0x59, 0x53, 0x48, 0x64, 0x44, 0x4D, 0x4A, 0x44, 675 1.1.1.2 christos 0x43, 0x4F, 0x4D, 0x6F, 0x35, 0x67, 0x46, 0x58, 0x79, 0x43, 0x2B, 0x35, 676 1.1.1.2 christos 0x46, 0x66, 0x54, 0x69, 0x47, 0x77, 0x42, 0x68, 0x79, 0x35, 0x38, 0x7A, 677 1.1.1.2 christos 0x35, 0x62, 0x37, 0x0A, 0x67, 0x42, 0x77, 0x46, 0x4B, 0x49, 0x39, 0x52, 678 1.1.1.2 christos 0x67, 0x52, 0x66, 0x56, 0x31, 0x44, 0x2F, 0x4E, 0x69, 0x6D, 0x78, 0x50, 679 1.1.1.2 christos 0x72, 0x6C, 0x6A, 0x33, 0x57, 0x48, 0x79, 0x65, 0x63, 0x31, 0x2F, 0x43, 680 1.1.1.2 christos 0x73, 0x2B, 0x42, 0x72, 0x2B, 0x2F, 0x76, 0x65, 0x6B, 0x4D, 0x56, 0x46, 681 1.1.1.2 christos 0x67, 0x35, 0x67, 0x65, 0x6B, 0x65, 0x48, 0x72, 0x34, 0x61, 0x47, 0x53, 682 1.1.1.2 christos 0x46, 0x34, 0x62, 0x6B, 0x30, 0x41, 0x6A, 0x56, 0x0A, 0x54, 0x76, 0x2F, 683 1.1.1.2 christos 0x70, 0x51, 0x6A, 0x79, 0x52, 0x75, 0x5A, 0x41, 0x74, 0x36, 0x36, 0x49, 684 1.1.1.2 christos 0x62, 0x52, 0x5A, 0x64, 0x6C, 0x32, 0x49, 0x49, 0x3D, 0x0A, 0x2D, 0x2D, 685 1.1.1.2 christos 0x2D, 0x2D, 0x2D, 0x45, 0x4E, 0x44, 0x20, 0x50, 0x52, 0x49, 0x56, 0x41, 686 1.1.1.2 christos 0x54, 0x45, 0x20, 0x4B, 0x45, 0x59, 0x2D, 0x2D, 0x2D, 0x2D, 0x2D 687 1.1.1.2 christos }; 688 1.1.1.2 christos /* 689 1.1.1.2 christos * PEM of pem_rsa_priv_key: 690 1.1.1.2 christos * -----BEGIN PRIVATE KEY----- 691 1.1.1.2 christos * MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDEkC4ZWv3ucFbU 692 1.1.1.2 christos * F8YwlUrmQlLCZwAgr4DPUAFVHl+wFcXypVgScVY4K7QmdWKsYqb8tpOxqw0NwZWX 693 1.1.1.2 christos * O+ta4+y27COufoOhRTMwNyN2LwSNTPN3eEk4ee5QnppEyDrqoCgvTlAAdToFaXvj 694 1.1.1.2 christos * x13Ybj7jfhwN74qKdqsSEtPWyggeotiQSPy6KyBIuWtIxPAA8jAvfAnQj1eXhghF 695 1.1.1.2 christos * N2NxkqgxvBYdNy1m3+jXACPLRzc11ZbNHKiwhCY1/HiSBkwHlIK+/VLj2smCKdUQ 696 1.1.1.2 christos * gvLXSnnVgQulHioD6UgY8xA2a4M1rhYuTV8BrPRZ4BFx2o0jYWvGbA/Hlp7fTOy+ 697 1.1.1.2 christos * F5OkiHS7AgMBAAECggEAYgCu81ZiQBVDvWiDGKr+1pIf2CxprGJEm1h86ZcEx3L7 698 1.1.1.2 christos * qFDW+g8HGWd04S3qvh9LublAJzetAPxRXL9zx3PXjJZs7e3HLEuny3TaWez0XI0O 699 1.1.1.2 christos * 4LSY8S8d6pVBPmUEtwGWN4vYqHnKLXOb4QQAXs4MzfkM/Me/b+zdu1umwjMl3Dud 700 1.1.1.2 christos * 5rVhkgvt8uhDUG3XSHeoJYBMbT9ikJDVMJ51rre/1Riddgxp8SktVkvGmMl9kQR8 701 1.1.1.2 christos * 8dv3Px/kTN94EuRg0CkXBhHpoGo4qnM3Q3B5PlmSK5gkuPvWy9l8L/TVt8Lb6/zL 702 1.1.1.2 christos * ByQW+g02wxeNGhw1fkD+XFH7KkSeWl+QnrLcePM0hQKBgQDxoqUk0PLOY5WgOkgr 703 1.1.1.2 christos * umgie/K1WKs+izTtApjzcM76sza63b5R9w+P+NssMV4aeV9epEGZO68IUmi0QjvQ 704 1.1.1.2 christos * npluQoadFYweFwSQ11BXHoeQBA4nNpkrV58hgzZN3m9JLR7JxyrIqXsRnUzl13Kj 705 1.1.1.2 christos * GzZBCJxCpJjfTze/yme8d3pa5QKBgQDQP5mB4jI+g3XH3MuLyBjMoTIvoy7CYMhZ 706 1.1.1.2 christos * 6/+Kkpw132J16mqkLrwUOZfT0e1rJBsCUkEoBmgKNtRkHo3/SjUI/9fHj3uStPHV 707 1.1.1.2 christos * oPcfXj/gFRUkDDzY+auB3dHONF1U1z06EANkkPCC3a538UANBIaPjwpRdBzNw1xl 708 1.1.1.2 christos * bvn5aCt3HwKBgBfOl4jGEXYmN6K+u0ebqRDkt2gIoW6bFo7Xd6xci/gFWjoVCOBY 709 1.1.1.2 christos * gC8GLMnw3z2qgav4cQIg8EDYpbpE4FHQnntPkKW/bru0Nt3yaNb8igy1aZORfIvZ 710 1.1.1.2 christos * qTMLE3melcZW7LaiqeN1V0vH/MCUdpX9Y14K9CJYxzsROgPqdEgMWYDFAoGAAe9l 711 1.1.1.2 christos * XMieUOhl0sqhdZYRbO1eiwTILXQ6yGMiB8ae/v0pbBEWlpn8k2+JkqVTwHggbCAZ 712 1.1.1.2 christos * jOaqVtX1mUyTYzjsTz4ZYjhaHJ3j1WlegoMcstdfT+txMU74ogdOqMzhxSUO45g8 713 1.1.1.2 christos * f9W89mpa8bBjOPu+yFy66tDaZ6sWE7c5SXEHXl8CgYEAtAWwFPoDSTdzoXAwRof0 714 1.1.1.2 christos * QMO08+PnQGoPbMJTqrgxrHYCS8u4cYSHdDMJDCOMo5gFXyC+5FfTiGwBhy58z5b7 715 1.1.1.2 christos * gBwFKI9RgRfV1D/NimxPrlj3WHyec1/Cs+Br+/vekMVFg5gekeHr4aGSF4bk0AjV 716 1.1.1.2 christos * Tv/pQjyRuZAt66IbRZdl2II= 717 1.1.1.2 christos * -----END PRIVATE KEY----- 718 1.1.1.2 christos */ 719 1.1.1.2 christos 720 1.1.1.2 christos /* Load private key BIO, DER-encoded public key and PKCS#8 private key for testing */ 721 1.1.1.2 christos if (!TEST_ptr(bio_priv = BIO_new(BIO_s_mem())) 722 1.1.1.2 christos || !TEST_int_gt(BIO_write(bio_priv, pem_rsa_priv_key, sizeof(pem_rsa_priv_key)), 0) 723 1.1.1.2 christos || !TEST_ptr(pkey = PEM_read_bio_PrivateKey_ex(bio_priv, NULL, NULL, NULL, NULL, NULL)) 724 1.1.1.2 christos || !TEST_int_ge(BIO_seek(bio_priv, 0), 0) 725 1.1.1.2 christos || !TEST_int_gt((len_pub = i2d_PUBKEY(pkey, &encoded_pub)), 0) 726 1.1.1.2 christos || !TEST_ptr(p8 = EVP_PKEY2PKCS8(pkey))) 727 1.1.1.2 christos goto end; 728 1.1.1.2 christos EVP_PKEY_free(pkey); 729 1.1.1.2 christos pkey = NULL; 730 1.1.1.2 christos 731 1.1.1.2 christos for (i = 0; i < OSSL_NELEM(properties_test); i++) { 732 1.1.1.2 christos const char *libctx_prop = properties_test[i].provider_props; 733 1.1.1.2 christos const char *explicit_prop = properties_test[i].explicit_props; 734 1.1.1.2 christos /* *curr_provider will be updated in reset_ctx_providers */ 735 1.1.1.2 christos OSSL_PROVIDER **curr_provider = &providers[properties_test[i].curr_provider_idx]; 736 1.1.1.2 christos 737 1.1.1.2 christos /* 738 1.1.1.2 christos * Decoding a PEM-encoded key uses the properties to select the right provider. 739 1.1.1.2 christos * Using a PEM-encoding adds an extra decoder before the key is created. 740 1.1.1.2 christos */ 741 1.1.1.2 christos if (!TEST_int_eq(reset_ctx_providers(&my_libctx, providers, libctx_prop), 1)) 742 1.1.1.2 christos goto end; 743 1.1.1.2 christos if (!TEST_int_ge(BIO_seek(bio_priv, 0), 0) 744 1.1.1.2 christos || !TEST_ptr(pkey = PEM_read_bio_PrivateKey_ex(bio_priv, NULL, NULL, NULL, my_libctx, 745 1.1.1.2 christos explicit_prop)) 746 1.1.1.2 christos || !TEST_ptr_eq(EVP_PKEY_get0_provider(pkey), *curr_provider)) 747 1.1.1.2 christos goto end; 748 1.1.1.2 christos EVP_PKEY_free(pkey); 749 1.1.1.2 christos pkey = NULL; 750 1.1.1.2 christos 751 1.1.1.2 christos /* Decoding a DER-encoded X509_PUBKEY uses the properties to select the right provider */ 752 1.1.1.2 christos if (!TEST_int_eq(reset_ctx_providers(&my_libctx, providers, libctx_prop), 1)) 753 1.1.1.2 christos goto end; 754 1.1.1.2 christos p = encoded_pub; 755 1.1.1.2 christos if (!TEST_ptr(pkey = d2i_PUBKEY_ex(NULL, &p, len_pub, my_libctx, explicit_prop)) 756 1.1.1.2 christos || !TEST_ptr_eq(EVP_PKEY_get0_provider(pkey), *curr_provider)) 757 1.1.1.2 christos goto end; 758 1.1.1.2 christos EVP_PKEY_free(pkey); 759 1.1.1.2 christos pkey = NULL; 760 1.1.1.2 christos 761 1.1.1.2 christos /* Decoding a PKCS8_PRIV_KEY_INFO uses the properties to select the right provider */ 762 1.1.1.2 christos if (!TEST_int_eq(reset_ctx_providers(&my_libctx, providers, libctx_prop), 1)) 763 1.1.1.2 christos goto end; 764 1.1.1.2 christos if (!TEST_ptr(pkey = EVP_PKCS82PKEY_ex(p8, my_libctx, explicit_prop)) 765 1.1.1.2 christos || !TEST_ptr_eq(EVP_PKEY_get0_provider(pkey), *curr_provider)) 766 1.1.1.2 christos goto end; 767 1.1.1.2 christos EVP_PKEY_free(pkey); 768 1.1.1.2 christos pkey = NULL; 769 1.1.1.2 christos } 770 1.1.1.2 christos 771 1.1.1.2 christos ret = 1; 772 1.1.1.2 christos 773 1.1.1.2 christos end: 774 1.1.1.2 christos PKCS8_PRIV_KEY_INFO_free(p8); 775 1.1.1.2 christos BIO_free(bio_priv); 776 1.1.1.2 christos OPENSSL_free(encoded_pub); 777 1.1.1.2 christos EVP_PKEY_free(pkey); 778 1.1.1.2 christos OSSL_PROVIDER_unload(providers[DEFAULT_PROVIDER_IDX]); 779 1.1.1.2 christos fake_rsa_finish(providers[FAKE_RSA_PROVIDER_IDX]); 780 1.1.1.2 christos OSSL_LIB_CTX_free(my_libctx); 781 1.1.1.2 christos return ret; 782 1.1.1.2 christos } 783 1.1.1.2 christos 784 1.1 christos int setup_tests(void) 785 1.1 christos { 786 1.1 christos libctx = OSSL_LIB_CTX_new(); 787 1.1 christos if (libctx == NULL) 788 1.1 christos return 0; 789 1.1 christos 790 1.1 christos ADD_TEST(test_pkey_sig); 791 1.1 christos ADD_TEST(test_alternative_keygen_init); 792 1.1 christos ADD_TEST(test_pkey_eq); 793 1.1.1.2 christos ADD_TEST(test_pkey_can_sign); 794 1.1 christos ADD_ALL_TESTS(test_pkey_store, 2); 795 1.1 christos ADD_TEST(test_pkey_delete); 796 1.1 christos ADD_TEST(test_pkey_store_open_ex); 797 1.1.1.2 christos ADD_TEST(test_pkey_provider_decoder_props); 798 1.1 christos 799 1.1 christos return 1; 800 1.1 christos } 801 1.1 christos 802 1.1 christos void cleanup_tests(void) 803 1.1 christos { 804 1.1 christos OSSL_LIB_CTX_free(libctx); 805 1.1 christos } 806