1*e71b7053SJung-uk Kim /* 2*e71b7053SJung-uk Kim * Copyright 2001-2016 The OpenSSL Project Authors. All Rights Reserved. 35c87c606SMark Murray * 4*e71b7053SJung-uk Kim * Licensed under the OpenSSL license (the "License"). You may not use 5*e71b7053SJung-uk Kim * this file except in compliance with the License. You can obtain a copy 6*e71b7053SJung-uk Kim * in the file LICENSE in the source distribution or at 7*e71b7053SJung-uk Kim * https://www.openssl.org/source/license.html 85c87c606SMark Murray */ 95c87c606SMark Murray 105c87c606SMark Murray #include "eng_int.h" 115c87c606SMark Murray 125c87c606SMark Murray /* Basic get/set stuff */ 135c87c606SMark Murray 146f9291ceSJung-uk Kim int ENGINE_set_load_privkey_function(ENGINE *e, 156f9291ceSJung-uk Kim ENGINE_LOAD_KEY_PTR loadpriv_f) 165c87c606SMark Murray { 175c87c606SMark Murray e->load_privkey = loadpriv_f; 185c87c606SMark Murray return 1; 195c87c606SMark Murray } 205c87c606SMark Murray 215c87c606SMark Murray int ENGINE_set_load_pubkey_function(ENGINE *e, ENGINE_LOAD_KEY_PTR loadpub_f) 225c87c606SMark Murray { 235c87c606SMark Murray e->load_pubkey = loadpub_f; 245c87c606SMark Murray return 1; 255c87c606SMark Murray } 265c87c606SMark Murray 27db522d3aSSimon L. B. Nielsen int ENGINE_set_load_ssl_client_cert_function(ENGINE *e, 286f9291ceSJung-uk Kim ENGINE_SSL_CLIENT_CERT_PTR 296f9291ceSJung-uk Kim loadssl_f) 30db522d3aSSimon L. B. Nielsen { 31db522d3aSSimon L. B. Nielsen e->load_ssl_client_cert = loadssl_f; 32db522d3aSSimon L. B. Nielsen return 1; 33db522d3aSSimon L. B. Nielsen } 34db522d3aSSimon L. B. Nielsen 355c87c606SMark Murray ENGINE_LOAD_KEY_PTR ENGINE_get_load_privkey_function(const ENGINE *e) 365c87c606SMark Murray { 375c87c606SMark Murray return e->load_privkey; 385c87c606SMark Murray } 395c87c606SMark Murray 405c87c606SMark Murray ENGINE_LOAD_KEY_PTR ENGINE_get_load_pubkey_function(const ENGINE *e) 415c87c606SMark Murray { 425c87c606SMark Murray return e->load_pubkey; 435c87c606SMark Murray } 445c87c606SMark Murray 456f9291ceSJung-uk Kim ENGINE_SSL_CLIENT_CERT_PTR ENGINE_get_ssl_client_cert_function(const ENGINE 466f9291ceSJung-uk Kim *e) 47db522d3aSSimon L. B. Nielsen { 48db522d3aSSimon L. B. Nielsen return e->load_ssl_client_cert; 49db522d3aSSimon L. B. Nielsen } 50db522d3aSSimon L. B. Nielsen 515c87c606SMark Murray /* API functions to load public/private keys */ 525c87c606SMark Murray 535c87c606SMark Murray EVP_PKEY *ENGINE_load_private_key(ENGINE *e, const char *key_id, 545c87c606SMark Murray UI_METHOD *ui_method, void *callback_data) 555c87c606SMark Murray { 565c87c606SMark Murray EVP_PKEY *pkey; 575c87c606SMark Murray 586f9291ceSJung-uk Kim if (e == NULL) { 595c87c606SMark Murray ENGINEerr(ENGINE_F_ENGINE_LOAD_PRIVATE_KEY, 605c87c606SMark Murray ERR_R_PASSED_NULL_PARAMETER); 615c87c606SMark Murray return 0; 625c87c606SMark Murray } 63*e71b7053SJung-uk Kim CRYPTO_THREAD_write_lock(global_engine_lock); 646f9291ceSJung-uk Kim if (e->funct_ref == 0) { 65*e71b7053SJung-uk Kim CRYPTO_THREAD_unlock(global_engine_lock); 666f9291ceSJung-uk Kim ENGINEerr(ENGINE_F_ENGINE_LOAD_PRIVATE_KEY, ENGINE_R_NOT_INITIALISED); 675c87c606SMark Murray return 0; 685c87c606SMark Murray } 69*e71b7053SJung-uk Kim CRYPTO_THREAD_unlock(global_engine_lock); 706f9291ceSJung-uk Kim if (!e->load_privkey) { 715c87c606SMark Murray ENGINEerr(ENGINE_F_ENGINE_LOAD_PRIVATE_KEY, 725c87c606SMark Murray ENGINE_R_NO_LOAD_FUNCTION); 735c87c606SMark Murray return 0; 745c87c606SMark Murray } 755c87c606SMark Murray pkey = e->load_privkey(e, key_id, ui_method, callback_data); 766f9291ceSJung-uk Kim if (!pkey) { 775c87c606SMark Murray ENGINEerr(ENGINE_F_ENGINE_LOAD_PRIVATE_KEY, 785c87c606SMark Murray ENGINE_R_FAILED_LOADING_PRIVATE_KEY); 795c87c606SMark Murray return 0; 805c87c606SMark Murray } 815c87c606SMark Murray return pkey; 825c87c606SMark Murray } 835c87c606SMark Murray 845c87c606SMark Murray EVP_PKEY *ENGINE_load_public_key(ENGINE *e, const char *key_id, 855c87c606SMark Murray UI_METHOD *ui_method, void *callback_data) 865c87c606SMark Murray { 875c87c606SMark Murray EVP_PKEY *pkey; 885c87c606SMark Murray 896f9291ceSJung-uk Kim if (e == NULL) { 905c87c606SMark Murray ENGINEerr(ENGINE_F_ENGINE_LOAD_PUBLIC_KEY, 915c87c606SMark Murray ERR_R_PASSED_NULL_PARAMETER); 925c87c606SMark Murray return 0; 935c87c606SMark Murray } 94*e71b7053SJung-uk Kim CRYPTO_THREAD_write_lock(global_engine_lock); 956f9291ceSJung-uk Kim if (e->funct_ref == 0) { 96*e71b7053SJung-uk Kim CRYPTO_THREAD_unlock(global_engine_lock); 976f9291ceSJung-uk Kim ENGINEerr(ENGINE_F_ENGINE_LOAD_PUBLIC_KEY, ENGINE_R_NOT_INITIALISED); 985c87c606SMark Murray return 0; 995c87c606SMark Murray } 100*e71b7053SJung-uk Kim CRYPTO_THREAD_unlock(global_engine_lock); 1016f9291ceSJung-uk Kim if (!e->load_pubkey) { 1026f9291ceSJung-uk Kim ENGINEerr(ENGINE_F_ENGINE_LOAD_PUBLIC_KEY, ENGINE_R_NO_LOAD_FUNCTION); 1035c87c606SMark Murray return 0; 1045c87c606SMark Murray } 1055c87c606SMark Murray pkey = e->load_pubkey(e, key_id, ui_method, callback_data); 1066f9291ceSJung-uk Kim if (!pkey) { 1075c87c606SMark Murray ENGINEerr(ENGINE_F_ENGINE_LOAD_PUBLIC_KEY, 1085c87c606SMark Murray ENGINE_R_FAILED_LOADING_PUBLIC_KEY); 1095c87c606SMark Murray return 0; 1105c87c606SMark Murray } 1115c87c606SMark Murray return pkey; 1125c87c606SMark Murray } 113db522d3aSSimon L. B. Nielsen 114db522d3aSSimon L. B. Nielsen int ENGINE_load_ssl_client_cert(ENGINE *e, SSL *s, 1156f9291ceSJung-uk Kim STACK_OF(X509_NAME) *ca_dn, X509 **pcert, 1166f9291ceSJung-uk Kim EVP_PKEY **ppkey, STACK_OF(X509) **pother, 1176f9291ceSJung-uk Kim UI_METHOD *ui_method, void *callback_data) 118db522d3aSSimon L. B. Nielsen { 119db522d3aSSimon L. B. Nielsen 1206f9291ceSJung-uk Kim if (e == NULL) { 121db522d3aSSimon L. B. Nielsen ENGINEerr(ENGINE_F_ENGINE_LOAD_SSL_CLIENT_CERT, 122db522d3aSSimon L. B. Nielsen ERR_R_PASSED_NULL_PARAMETER); 123db522d3aSSimon L. B. Nielsen return 0; 124db522d3aSSimon L. B. Nielsen } 125*e71b7053SJung-uk Kim CRYPTO_THREAD_write_lock(global_engine_lock); 1266f9291ceSJung-uk Kim if (e->funct_ref == 0) { 127*e71b7053SJung-uk Kim CRYPTO_THREAD_unlock(global_engine_lock); 128db522d3aSSimon L. B. Nielsen ENGINEerr(ENGINE_F_ENGINE_LOAD_SSL_CLIENT_CERT, 129db522d3aSSimon L. B. Nielsen ENGINE_R_NOT_INITIALISED); 130db522d3aSSimon L. B. Nielsen return 0; 131db522d3aSSimon L. B. Nielsen } 132*e71b7053SJung-uk Kim CRYPTO_THREAD_unlock(global_engine_lock); 1336f9291ceSJung-uk Kim if (!e->load_ssl_client_cert) { 134db522d3aSSimon L. B. Nielsen ENGINEerr(ENGINE_F_ENGINE_LOAD_SSL_CLIENT_CERT, 135db522d3aSSimon L. B. Nielsen ENGINE_R_NO_LOAD_FUNCTION); 136db522d3aSSimon L. B. Nielsen return 0; 137db522d3aSSimon L. B. Nielsen } 138db522d3aSSimon L. B. Nielsen return e->load_ssl_client_cert(e, s, ca_dn, pcert, ppkey, pother, 139db522d3aSSimon L. B. Nielsen ui_method, callback_data); 140db522d3aSSimon L. B. Nielsen } 141