2015-01-22 11:40:55 +08:00
|
|
|
/*
|
2016-05-18 02:24:46 +08:00
|
|
|
* Copyright 2002-2016 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"
|
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
|
|
|
|
2017-11-12 05:23:12 +08:00
|
|
|
#ifdef _WIN32
|
|
|
|
# define strdup _strdup
|
|
|
|
#endif
|
|
|
|
|
2015-01-22 11:40:55 +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()
|
2002-02-23 09:00:44 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
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);
|
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
|
|
|
|
2019-01-01 15:53:24 +08:00
|
|
|
int openssl_config_int(const OPENSSL_INIT_SETTINGS *settings)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
2019-05-28 20:29:59 +08:00
|
|
|
int ret = 0;
|
2019-01-01 15:53:24 +08:00
|
|
|
const char *filename;
|
|
|
|
const char *appname;
|
|
|
|
unsigned long flags;
|
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
if (openssl_configured)
|
2019-01-01 15:53:24 +08:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
filename = settings ? settings->filename : NULL;
|
|
|
|
appname = settings ? settings->appname : NULL;
|
|
|
|
flags = settings ? settings->flags : DEFAULT_CONF_MFLAGS;
|
|
|
|
|
|
|
|
#ifdef OPENSSL_INIT_DEBUG
|
|
|
|
fprintf(stderr, "OPENSSL_INIT: openssl_config_int(%s, %s, %lu)\n",
|
|
|
|
filename, appname, flags);
|
|
|
|
#endif
|
2002-02-23 09:00:44 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
OPENSSL_load_builtin_modules();
|
2003-01-31 01:39:26 +08:00
|
|
|
#ifndef OPENSSL_NO_ENGINE
|
2015-01-22 11:40:55 +08:00
|
|
|
/* Need to load ENGINEs */
|
|
|
|
ENGINE_load_builtin_engines();
|
2003-01-31 01:39:26 +08:00
|
|
|
#endif
|
2015-01-22 11:40:55 +08:00
|
|
|
ERR_clear_error();
|
2015-09-12 02:56:32 +08:00
|
|
|
#ifndef OPENSSL_SYS_UEFI
|
2019-01-01 15:53:24 +08:00
|
|
|
ret = CONF_modules_load_file(filename, appname, flags);
|
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;
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
2002-02-23 09:00:44 +08:00
|
|
|
|
2016-04-12 19:20:16 +08:00
|
|
|
void openssl_no_config_int(void)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
|
|
|
openssl_configured = 1;
|
|
|
|
}
|