evp_cnf.c revision 280304
190792Sgshapiro/* evp_cnf.c */
2261370Sgshapiro/*
390792Sgshapiro * Written by Stephen Henson (steve@openssl.org) for the OpenSSL project
490792Sgshapiro * 2007.
590792Sgshapiro */
690792Sgshapiro/* ====================================================================
790792Sgshapiro * Copyright (c) 2007 The OpenSSL Project.  All rights reserved.
890792Sgshapiro *
990792Sgshapiro * Redistribution and use in source and binary forms, with or without
1090792Sgshapiro * modification, are permitted provided that the following conditions
11266711Sgshapiro * are met:
1290792Sgshapiro *
1390792Sgshapiro * 1. Redistributions of source code must retain the above copyright
1490792Sgshapiro *    notice, this list of conditions and the following disclaimer.
1590792Sgshapiro *
1690792Sgshapiro * 2. Redistributions in binary form must reproduce the above copyright
1790792Sgshapiro *    notice, this list of conditions and the following disclaimer in
1890792Sgshapiro *    the documentation and/or other materials provided with the
1990792Sgshapiro *    distribution.
2090792Sgshapiro *
2190792Sgshapiro * 3. All advertising materials mentioning features or use of this
2290792Sgshapiro *    software must display the following acknowledgment:
2390792Sgshapiro *    "This product includes software developed by the OpenSSL Project
2490792Sgshapiro *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
2590792Sgshapiro *
2690792Sgshapiro * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
2790792Sgshapiro *    endorse or promote products derived from this software without
2890792Sgshapiro *    prior written permission. For written permission, please contact
2990792Sgshapiro *    licensing@OpenSSL.org.
3090792Sgshapiro *
3190792Sgshapiro * 5. Products derived from this software may not be called "OpenSSL"
3290792Sgshapiro *    nor may "OpenSSL" appear in their names without prior written
3390792Sgshapiro *    permission of the OpenSSL Project.
3490792Sgshapiro *
3590792Sgshapiro * 6. Redistributions of any form whatsoever must retain the following
3690792Sgshapiro *    acknowledgment:
3790792Sgshapiro *    "This product includes software developed by the OpenSSL Project
3890792Sgshapiro *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
3990792Sgshapiro *
4090792Sgshapiro * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
4190792Sgshapiro * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
4290792Sgshapiro * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
4390792Sgshapiro * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
4490792Sgshapiro * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
4590792Sgshapiro * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
4690792Sgshapiro * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
4790792Sgshapiro * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48132943Sgshapiro * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
4990792Sgshapiro * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
5090792Sgshapiro * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
5190792Sgshapiro * OF THE POSSIBILITY OF SUCH DAMAGE.
5290792Sgshapiro * ====================================================================
5390792Sgshapiro *
5490792Sgshapiro * This product includes cryptographic software written by Eric Young
5590792Sgshapiro * (eay@cryptsoft.com).  This product includes software written by Tim
5690792Sgshapiro * Hudson (tjh@cryptsoft.com).
5790792Sgshapiro *
5890792Sgshapiro */
5990792Sgshapiro
6090792Sgshapiro#include <stdio.h>
6190792Sgshapiro#include <ctype.h>
6290792Sgshapiro#include <openssl/crypto.h>
6390792Sgshapiro#include "cryptlib.h"
6490792Sgshapiro#include <openssl/conf.h>
6590792Sgshapiro#include <openssl/dso.h>
6690792Sgshapiro#include <openssl/x509.h>
6790792Sgshapiro#include <openssl/x509v3.h>
6890792Sgshapiro#ifdef OPENSSL_FIPS
6990792Sgshapiro# include <openssl/fips.h>
7090792Sgshapiro#endif
7190792Sgshapiro
7290792Sgshapiro/* Algorithm configuration module. */
7390792Sgshapiro
7490792Sgshapirostatic int alg_module_init(CONF_IMODULE *md, const CONF *cnf)
7590792Sgshapiro{
7690792Sgshapiro    int i;
7790792Sgshapiro    const char *oid_section;
7890792Sgshapiro    STACK_OF(CONF_VALUE) *sktmp;
7990792Sgshapiro    CONF_VALUE *oval;
8090792Sgshapiro    oid_section = CONF_imodule_get_value(md);
8190792Sgshapiro    if (!(sktmp = NCONF_get_section(cnf, oid_section))) {
8290792Sgshapiro        EVPerr(EVP_F_ALG_MODULE_INIT, EVP_R_ERROR_LOADING_SECTION);
8390792Sgshapiro        return 0;
8490792Sgshapiro    }
8590792Sgshapiro    for (i = 0; i < sk_CONF_VALUE_num(sktmp); i++) {
86147078Sgshapiro        oval = sk_CONF_VALUE_value(sktmp, i);
87147078Sgshapiro        if (!strcmp(oval->name, "fips_mode")) {
88147078Sgshapiro            int m;
89147078Sgshapiro            if (!X509V3_get_value_bool(oval, &m)) {
9090792Sgshapiro                EVPerr(EVP_F_ALG_MODULE_INIT, EVP_R_INVALID_FIPS_MODE);
9190792Sgshapiro                return 0;
9290792Sgshapiro            }
9390792Sgshapiro            if (m > 0) {
9490792Sgshapiro#ifdef OPENSSL_FIPS
9590792Sgshapiro                if (!FIPS_mode() && !FIPS_mode_set(1)) {
9690792Sgshapiro                    EVPerr(EVP_F_ALG_MODULE_INIT,
9790792Sgshapiro                           EVP_R_ERROR_SETTING_FIPS_MODE);
9890792Sgshapiro                    return 0;
9990792Sgshapiro                }
10090792Sgshapiro#else
10190792Sgshapiro                EVPerr(EVP_F_ALG_MODULE_INIT, EVP_R_FIPS_MODE_NOT_SUPPORTED);
10290792Sgshapiro                return 0;
10390792Sgshapiro#endif
10490792Sgshapiro            }
10590792Sgshapiro        } else {
10690792Sgshapiro            EVPerr(EVP_F_ALG_MODULE_INIT, EVP_R_UNKNOWN_OPTION);
10790792Sgshapiro            ERR_add_error_data(4, "name=", oval->name,
10890792Sgshapiro                               ", value=", oval->value);
10990792Sgshapiro        }
11090792Sgshapiro
11190792Sgshapiro    }
11290792Sgshapiro    return 1;
11390792Sgshapiro}
11490792Sgshapiro
11590792Sgshapirovoid EVP_add_alg_module(void)
11690792Sgshapiro{
11790792Sgshapiro    CONF_module_add("alg_section", alg_module_init, 0);
11890792Sgshapiro}
11990792Sgshapiro