1e1051a39Sopenharmony_ci/* 2e1051a39Sopenharmony_ci * Copyright 2012-2021 The OpenSSL Project Authors. All Rights Reserved. 3e1051a39Sopenharmony_ci * 4e1051a39Sopenharmony_ci * Licensed under the Apache License 2.0 (the "License"). You may not use 5e1051a39Sopenharmony_ci * this file except in compliance with the License. You can obtain a copy 6e1051a39Sopenharmony_ci * in the file LICENSE in the source distribution or at 7e1051a39Sopenharmony_ci * https://www.openssl.org/source/license.html 8e1051a39Sopenharmony_ci */ 9e1051a39Sopenharmony_ci 10e1051a39Sopenharmony_ci#include <stdio.h> 11e1051a39Sopenharmony_ci#include <openssl/crypto.h> 12e1051a39Sopenharmony_ci#include "internal/cryptlib.h" 13e1051a39Sopenharmony_ci#include <openssl/conf.h> 14e1051a39Sopenharmony_ci#include <openssl/x509.h> 15e1051a39Sopenharmony_ci#include <openssl/x509v3.h> 16e1051a39Sopenharmony_ci#include <openssl/trace.h> 17e1051a39Sopenharmony_ci#include "crypto/evp.h" 18e1051a39Sopenharmony_ci 19e1051a39Sopenharmony_ci/* Algorithm configuration module. */ 20e1051a39Sopenharmony_ci 21e1051a39Sopenharmony_cistatic int alg_module_init(CONF_IMODULE *md, const CONF *cnf) 22e1051a39Sopenharmony_ci{ 23e1051a39Sopenharmony_ci int i; 24e1051a39Sopenharmony_ci const char *oid_section; 25e1051a39Sopenharmony_ci STACK_OF(CONF_VALUE) *sktmp; 26e1051a39Sopenharmony_ci CONF_VALUE *oval; 27e1051a39Sopenharmony_ci 28e1051a39Sopenharmony_ci OSSL_TRACE2(CONF, "Loading EVP module: name %s, value %s\n", 29e1051a39Sopenharmony_ci CONF_imodule_get_name(md), CONF_imodule_get_value(md)); 30e1051a39Sopenharmony_ci 31e1051a39Sopenharmony_ci oid_section = CONF_imodule_get_value(md); 32e1051a39Sopenharmony_ci if ((sktmp = NCONF_get_section(cnf, oid_section)) == NULL) { 33e1051a39Sopenharmony_ci ERR_raise(ERR_LIB_EVP, EVP_R_ERROR_LOADING_SECTION); 34e1051a39Sopenharmony_ci return 0; 35e1051a39Sopenharmony_ci } 36e1051a39Sopenharmony_ci for (i = 0; i < sk_CONF_VALUE_num(sktmp); i++) { 37e1051a39Sopenharmony_ci oval = sk_CONF_VALUE_value(sktmp, i); 38e1051a39Sopenharmony_ci if (strcmp(oval->name, "fips_mode") == 0) { 39e1051a39Sopenharmony_ci int m; 40e1051a39Sopenharmony_ci 41e1051a39Sopenharmony_ci /* Detailed error already reported. */ 42e1051a39Sopenharmony_ci if (!X509V3_get_value_bool(oval, &m)) 43e1051a39Sopenharmony_ci return 0; 44e1051a39Sopenharmony_ci 45e1051a39Sopenharmony_ci /* 46e1051a39Sopenharmony_ci * fips_mode is deprecated and should not be used in new 47e1051a39Sopenharmony_ci * configurations. 48e1051a39Sopenharmony_ci */ 49e1051a39Sopenharmony_ci if (!evp_default_properties_enable_fips_int( 50e1051a39Sopenharmony_ci NCONF_get0_libctx((CONF *)cnf), m > 0, 0)) { 51e1051a39Sopenharmony_ci ERR_raise(ERR_LIB_EVP, EVP_R_SET_DEFAULT_PROPERTY_FAILURE); 52e1051a39Sopenharmony_ci return 0; 53e1051a39Sopenharmony_ci } 54e1051a39Sopenharmony_ci } else if (strcmp(oval->name, "default_properties") == 0) { 55e1051a39Sopenharmony_ci if (!evp_set_default_properties_int(NCONF_get0_libctx((CONF *)cnf), 56e1051a39Sopenharmony_ci oval->value, 0, 0)) { 57e1051a39Sopenharmony_ci ERR_raise(ERR_LIB_EVP, EVP_R_SET_DEFAULT_PROPERTY_FAILURE); 58e1051a39Sopenharmony_ci return 0; 59e1051a39Sopenharmony_ci } 60e1051a39Sopenharmony_ci } else { 61e1051a39Sopenharmony_ci ERR_raise_data(ERR_LIB_EVP, EVP_R_UNKNOWN_OPTION, 62e1051a39Sopenharmony_ci "name=%s, value=%s", oval->name, oval->value); 63e1051a39Sopenharmony_ci return 0; 64e1051a39Sopenharmony_ci } 65e1051a39Sopenharmony_ci 66e1051a39Sopenharmony_ci } 67e1051a39Sopenharmony_ci return 1; 68e1051a39Sopenharmony_ci} 69e1051a39Sopenharmony_ci 70e1051a39Sopenharmony_civoid EVP_add_alg_module(void) 71e1051a39Sopenharmony_ci{ 72e1051a39Sopenharmony_ci OSSL_TRACE(CONF, "Adding config module 'alg_section'\n"); 73e1051a39Sopenharmony_ci CONF_module_add("alg_section", alg_module_init, 0); 74e1051a39Sopenharmony_ci} 75