2015-01-22 03:40:55 +00:00
|
|
|
/*
|
2017-08-20 21:19:17 +00:00
|
|
|
* Copyright 2012-2017 The OpenSSL Project Authors. All Rights Reserved.
|
2012-07-04 13:15:10 +00:00
|
|
|
*
|
2018-12-06 12:40:06 +00:00
|
|
|
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
2016-05-17 18:24:46 +00: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 13:15:10 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <openssl/crypto.h>
|
2015-05-14 14:56:48 +00:00
|
|
|
#include "internal/cryptlib.h"
|
2012-07-04 13:15:10 +00:00
|
|
|
#include <openssl/conf.h>
|
|
|
|
#include <openssl/x509.h>
|
|
|
|
#include <openssl/x509v3.h>
|
2019-04-05 08:53:11 +00:00
|
|
|
#include <openssl/trace.h>
|
2012-07-04 13:15:10 +00:00
|
|
|
|
|
|
|
/* Algorithm configuration module. */
|
|
|
|
|
2019-04-05 08:53:11 +00:00
|
|
|
/* TODO(3.0): the config module functions should be passed a library context */
|
2012-07-04 13:15:10 +00:00
|
|
|
static int alg_module_init(CONF_IMODULE *md, const CONF *cnf)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
const char *oid_section;
|
|
|
|
STACK_OF(CONF_VALUE) *sktmp;
|
|
|
|
CONF_VALUE *oval;
|
2015-05-06 17:43:59 +00:00
|
|
|
|
2019-04-05 08:53:11 +00: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 03:40:55 +00:00
|
|
|
oid_section = CONF_imodule_get_value(md);
|
2015-05-06 17:43:59 +00:00
|
|
|
if ((sktmp = NCONF_get_section(cnf, oid_section)) == NULL) {
|
2015-01-22 03:40:55 +00: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-06 18:56:14 +00:00
|
|
|
if (strcmp(oval->name, "fips_mode") == 0) {
|
2015-01-22 03:40:55 +00:00
|
|
|
int m;
|
2019-04-05 08:53:11 +00:00
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
if (!X509V3_get_value_bool(oval, &m)) {
|
|
|
|
EVPerr(EVP_F_ALG_MODULE_INIT, EVP_R_INVALID_FIPS_MODE);
|
|
|
|
return 0;
|
|
|
|
}
|
2019-04-05 08:53:11 +00: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 03:40:55 +00: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 08:53:11 +00:00
|
|
|
return 0;
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
2012-07-04 13:15:10 +00:00
|
|
|
|
|
|
|
void EVP_add_alg_module(void)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
2019-04-05 08:53:11 +00:00
|
|
|
OSSL_TRACE(CONF, "Adding config module 'alg_section'\n");
|
2015-01-22 03:40:55 +00:00
|
|
|
CONF_module_add("alg_section", alg_module_init, 0);
|
|
|
|
}
|