2015-01-22 11:40:55 +08:00
|
|
|
/*
|
2017-08-21 05:19:17 +08:00
|
|
|
* Copyright 2012-2017 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>
|
2012-07-04 21:15:10 +08:00
|
|
|
|
|
|
|
/* Algorithm configuration module. */
|
|
|
|
|
2019-04-05 16:53:11 +08:00
|
|
|
/* TODO(3.0): the config module functions should be passed a library context */
|
2012-07-04 21:15:10 +08:00
|
|
|
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) {
|
2015-01-22 11:40:55 +08:00
|
|
|
EVPerr(EVP_F_ALG_MODULE_INIT, EVP_R_ERROR_LOADING_SECTION);
|
|
|
|
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
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
if (!X509V3_get_value_bool(oval, &m)) {
|
|
|
|
EVPerr(EVP_F_ALG_MODULE_INIT, EVP_R_INVALID_FIPS_MODE);
|
|
|
|
return 0;
|
|
|
|
}
|
2019-04-05 16:53:11 +08:00
|
|
|
/*
|
|
|
|
* fips_mode is deprecated and should not be used in new
|
|
|
|
* configurations. Old configurations are likely to ONLY
|
|
|
|
* have this, so we assume that no default properties have
|
|
|
|
* been set before this.
|
|
|
|
*/
|
|
|
|
if (m > 0)
|
|
|
|
EVP_set_default_properties(NULL, "fips=yes");
|
|
|
|
} else if (strcmp(oval->name, "default_properties") == 0) {
|
|
|
|
EVP_set_default_properties(NULL, oval->value);
|
2015-01-22 11:40:55 +08:00
|
|
|
} else {
|
|
|
|
EVPerr(EVP_F_ALG_MODULE_INIT, EVP_R_UNKNOWN_OPTION);
|
|
|
|
ERR_add_error_data(4, "name=", oval->name,
|
|
|
|
", value=", 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);
|
|
|
|
}
|