2008-11-06 02:39:08 +08:00
|
|
|
/*
|
2024-09-05 15:35:49 +08:00
|
|
|
* Copyright 2002-2024 The OpenSSL Project Authors. All Rights Reserved.
|
2002-02-23 09:00:44 +08:00
|
|
|
*
|
2018-12-06 20:34:05 +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
|
2002-02-23 09:00:44 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <openssl/crypto.h>
|
2015-05-14 22:56:48 +08:00
|
|
|
#include "internal/cryptlib.h"
|
2017-08-22 20:35:43 +08:00
|
|
|
#include "internal/conf.h"
|
2021-05-26 00:57:06 +08:00
|
|
|
#include "conf_local.h"
|
2002-02-23 09:00:44 +08:00
|
|
|
#include <openssl/x509.h>
|
|
|
|
#include <openssl/asn1.h>
|
2016-03-19 02:30:20 +08:00
|
|
|
#include <openssl/engine.h>
|
2002-02-23 09:00:44 +08:00
|
|
|
|
2020-11-20 07:39:12 +08:00
|
|
|
#if defined(_WIN32) && !defined(__BORLANDC__)
|
2017-11-12 05:23:12 +08:00
|
|
|
# define strdup _strdup
|
|
|
|
#endif
|
|
|
|
|
2002-02-23 09:00:44 +08:00
|
|
|
/*
|
|
|
|
* This is the automatic configuration loader: it is called automatically by
|
|
|
|
* OpenSSL when any of a number of standard initialisation functions are
|
|
|
|
* called, unless this is overridden by calling OPENSSL_no_config()
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int openssl_configured = 0;
|
|
|
|
|
2019-11-06 00:34:09 +08:00
|
|
|
#ifndef OPENSSL_NO_DEPRECATED_1_1_0
|
2016-06-13 09:49:40 +08:00
|
|
|
void OPENSSL_config(const char *appname)
|
2016-02-09 00:43:03 +08:00
|
|
|
{
|
2016-02-10 22:55:48 +08:00
|
|
|
OPENSSL_INIT_SETTINGS settings;
|
2016-02-10 05:01:25 +08:00
|
|
|
|
2016-02-10 22:55:48 +08:00
|
|
|
memset(&settings, 0, sizeof(settings));
|
2016-06-13 09:49:40 +08:00
|
|
|
if (appname != NULL)
|
|
|
|
settings.appname = strdup(appname);
|
2019-03-20 17:18:13 +08:00
|
|
|
settings.flags = DEFAULT_CONF_MFLAGS;
|
2016-02-10 22:55:48 +08:00
|
|
|
OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CONFIG, &settings);
|
2024-06-25 22:53:32 +08:00
|
|
|
|
|
|
|
free(settings.appname);
|
2016-02-09 00:43:03 +08:00
|
|
|
}
|
2016-02-15 04:25:54 +08:00
|
|
|
#endif
|
2016-02-09 00:43:03 +08:00
|
|
|
|
2021-03-09 09:36:36 +08:00
|
|
|
int ossl_config_int(const OPENSSL_INIT_SETTINGS *settings)
|
2002-02-23 09:00:44 +08:00
|
|
|
{
|
2019-05-28 20:29:59 +08:00
|
|
|
int ret = 0;
|
2022-09-07 14:31:31 +08:00
|
|
|
#if defined(OPENSSL_INIT_DEBUG) || !defined(OPENSSL_SYS_UEFI)
|
2019-01-01 15:53:24 +08:00
|
|
|
const char *filename;
|
|
|
|
const char *appname;
|
|
|
|
unsigned long flags;
|
2022-09-07 14:31:31 +08:00
|
|
|
#endif
|
2019-01-01 15:53:24 +08:00
|
|
|
|
2002-02-23 09:00:44 +08:00
|
|
|
if (openssl_configured)
|
2019-01-01 15:53:24 +08:00
|
|
|
return 1;
|
|
|
|
|
2022-09-07 14:31:31 +08:00
|
|
|
#if defined(OPENSSL_INIT_DEBUG) || !defined(OPENSSL_SYS_UEFI)
|
2019-01-01 15:53:24 +08:00
|
|
|
filename = settings ? settings->filename : NULL;
|
|
|
|
appname = settings ? settings->appname : NULL;
|
|
|
|
flags = settings ? settings->flags : DEFAULT_CONF_MFLAGS;
|
2022-09-07 14:31:31 +08:00
|
|
|
#endif
|
2019-01-01 15:53:24 +08:00
|
|
|
|
|
|
|
#ifdef OPENSSL_INIT_DEBUG
|
2021-03-09 09:36:36 +08:00
|
|
|
fprintf(stderr, "OPENSSL_INIT: ossl_config_int(%s, %s, %lu)\n",
|
2019-01-01 15:53:24 +08:00
|
|
|
filename, appname, flags);
|
|
|
|
#endif
|
2002-02-23 09:00:44 +08:00
|
|
|
|
2015-09-12 02:56:32 +08:00
|
|
|
#ifndef OPENSSL_SYS_UEFI
|
2023-08-30 14:41:43 +08:00
|
|
|
ret = CONF_modules_load_file_ex(OSSL_LIB_CTX_get0_global_default(),
|
|
|
|
filename, appname, flags);
|
2023-06-27 22:33:24 +08:00
|
|
|
#else
|
|
|
|
ret = 1;
|
2015-09-12 02:56:32 +08:00
|
|
|
#endif
|
2015-11-04 22:00:12 +08:00
|
|
|
openssl_configured = 1;
|
2019-01-01 15:53:24 +08:00
|
|
|
return ret;
|
2002-02-23 09:00:44 +08:00
|
|
|
}
|
|
|
|
|
2021-03-09 09:36:36 +08:00
|
|
|
void ossl_no_config_int(void)
|
2002-02-23 09:00:44 +08:00
|
|
|
{
|
|
|
|
openssl_configured = 1;
|
|
|
|
}
|