2015-01-22 11:40:55 +08:00
|
|
|
/*
|
2021-05-06 20:03:23 +08:00
|
|
|
* Copyright 2012-2021 The OpenSSL Project Authors. All Rights Reserved.
|
2012-07-04 21:15:10 +08:00
|
|
|
*
|
2018-12-06 20:40:06 +08:00
|
|
|
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
2016-05-18 02:24:46 +08:00
|
|
|
* 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
|
2012-07-04 21:15:10 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <openssl/crypto.h>
|
2015-05-14 22:56:48 +08:00
|
|
|
#include "internal/cryptlib.h"
|
2012-07-04 21:15:10 +08:00
|
|
|
#include <openssl/conf.h>
|
|
|
|
#include <openssl/x509.h>
|
|
|
|
#include <openssl/x509v3.h>
|
2019-04-05 16:53:11 +08:00
|
|
|
#include <openssl/trace.h>
|
2020-08-01 00:29:21 +08:00
|
|
|
#include "crypto/evp.h"
|
2012-07-04 21:15:10 +08:00
|
|
|
|
|
|
|
/* Algorithm configuration module. */
|
|
|
|
|
|
|
|
static int alg_module_init(CONF_IMODULE *md, const CONF *cnf)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
const char *oid_section;
|
|
|
|
STACK_OF(CONF_VALUE) *sktmp;
|
|
|
|
CONF_VALUE *oval;
|
2015-05-07 01:43:59 +08:00
|
|
|
|
2019-04-05 16:53:11 +08:00
|
|
|
OSSL_TRACE2(CONF, "Loading EVP module: name %s, value %s\n",
|
|
|
|
CONF_imodule_get_name(md), CONF_imodule_get_value(md));
|
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
oid_section = CONF_imodule_get_value(md);
|
2015-05-07 01:43:59 +08:00
|
|
|
if ((sktmp = NCONF_get_section(cnf, oid_section)) == NULL) {
|
2020-11-04 19:23:19 +08:00
|
|
|
ERR_raise(ERR_LIB_EVP, EVP_R_ERROR_LOADING_SECTION);
|
2015-01-22 11:40:55 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
for (i = 0; i < sk_CONF_VALUE_num(sktmp); i++) {
|
|
|
|
oval = sk_CONF_VALUE_value(sktmp, i);
|
2015-05-07 02:56:14 +08:00
|
|
|
if (strcmp(oval->name, "fips_mode") == 0) {
|
2015-01-22 11:40:55 +08:00
|
|
|
int m;
|
2019-04-05 16:53:11 +08:00
|
|
|
|
2021-05-05 00:05:54 +08:00
|
|
|
/* Detailed error already reported. */
|
|
|
|
if (!X509V3_get_value_bool(oval, &m))
|
2015-01-22 11:40:55 +08:00
|
|
|
return 0;
|
2021-05-05 00:05:54 +08:00
|
|
|
|
2019-04-05 16:53:11 +08:00
|
|
|
/*
|
|
|
|
* fips_mode is deprecated and should not be used in new
|
2020-05-02 12:17:54 +08:00
|
|
|
* configurations.
|
2019-04-05 16:53:11 +08:00
|
|
|
*/
|
2021-07-27 23:59:59 +08:00
|
|
|
if (!evp_default_properties_enable_fips_int(
|
|
|
|
NCONF_get0_libctx((CONF *)cnf), m > 0, 0)) {
|
2020-11-04 19:23:19 +08:00
|
|
|
ERR_raise(ERR_LIB_EVP, EVP_R_SET_DEFAULT_PROPERTY_FAILURE);
|
2020-05-02 12:17:54 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2019-04-05 16:53:11 +08:00
|
|
|
} else if (strcmp(oval->name, "default_properties") == 0) {
|
2021-05-26 02:48:41 +08:00
|
|
|
if (!evp_set_default_properties_int(NCONF_get0_libctx((CONF *)cnf),
|
|
|
|
oval->value, 0, 0)) {
|
2020-11-04 19:23:19 +08:00
|
|
|
ERR_raise(ERR_LIB_EVP, EVP_R_SET_DEFAULT_PROPERTY_FAILURE);
|
2020-05-02 12:17:54 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2015-01-22 11:40:55 +08:00
|
|
|
} else {
|
2020-11-04 23:14:00 +08:00
|
|
|
ERR_raise_data(ERR_LIB_EVP, EVP_R_UNKNOWN_OPTION,
|
|
|
|
"name=%s, value=%s", oval->name, oval->value);
|
2019-04-05 16:53:11 +08:00
|
|
|
return 0;
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
2012-07-04 21:15:10 +08:00
|
|
|
|
|
|
|
void EVP_add_alg_module(void)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
2019-04-05 16:53:11 +08:00
|
|
|
OSSL_TRACE(CONF, "Adding config module 'alg_section'\n");
|
2015-01-22 11:40:55 +08:00
|
|
|
CONF_module_add("alg_section", alg_module_init, 0);
|
|
|
|
}
|