2015-03-14 09:36:30 +08:00
|
|
|
/*
|
2020-08-06 20:22:30 +08:00
|
|
|
* Copyright 2015-2020 The OpenSSL Project Authors. All Rights Reserved.
|
2015-03-14 09:36:30 +08:00
|
|
|
*
|
2018-12-06 20:08:51 +08:00
|
|
|
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
2016-05-18 02:18:30 +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
|
2015-03-14 09:36:30 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <openssl/conf.h>
|
|
|
|
#include <openssl/ssl.h>
|
2019-09-28 06:45:40 +08:00
|
|
|
#include "ssl_local.h"
|
2018-03-31 02:19:56 +08:00
|
|
|
#include "internal/sslconf.h"
|
2015-03-14 09:36:30 +08:00
|
|
|
|
|
|
|
/* SSL library configuration module. */
|
|
|
|
|
|
|
|
void SSL_add_ssl_module(void)
|
|
|
|
{
|
2018-03-31 02:19:56 +08:00
|
|
|
/* Do nothing. This will be added automatically by libcrypto */
|
2015-03-14 09:36:30 +08:00
|
|
|
}
|
|
|
|
|
2018-03-19 22:01:39 +08:00
|
|
|
static int ssl_do_config(SSL *s, SSL_CTX *ctx, const char *name, int system)
|
2015-03-14 09:36:30 +08:00
|
|
|
{
|
|
|
|
SSL_CONF_CTX *cctx = NULL;
|
2018-03-31 02:19:56 +08:00
|
|
|
size_t i, idx, cmd_count;
|
2023-12-14 23:26:21 +08:00
|
|
|
int err = 1;
|
2015-03-14 09:36:30 +08:00
|
|
|
unsigned int flags;
|
|
|
|
const SSL_METHOD *meth;
|
2018-03-31 02:19:56 +08:00
|
|
|
const SSL_CONF_CMD *cmds;
|
2020-10-15 17:55:50 +08:00
|
|
|
OSSL_LIB_CTX *prev_libctx = NULL;
|
|
|
|
OSSL_LIB_CTX *libctx = NULL;
|
2018-03-19 22:01:39 +08:00
|
|
|
|
2015-03-14 09:36:30 +08:00
|
|
|
if (s == NULL && ctx == NULL) {
|
2020-11-04 19:18:33 +08:00
|
|
|
ERR_raise(ERR_LIB_SSL, ERR_R_PASSED_NULL_PARAMETER);
|
2015-03-14 09:36:30 +08:00
|
|
|
goto err;
|
|
|
|
}
|
2018-03-19 22:01:39 +08:00
|
|
|
|
|
|
|
if (name == NULL && system)
|
|
|
|
name = "system_default";
|
2018-03-31 02:19:56 +08:00
|
|
|
if (!conf_ssl_name_find(name, &idx)) {
|
2020-11-04 21:39:57 +08:00
|
|
|
if (!system)
|
|
|
|
ERR_raise_data(ERR_LIB_SSL, SSL_R_INVALID_CONFIGURATION_NAME,
|
|
|
|
"name=%s", name);
|
2015-03-14 09:36:30 +08:00
|
|
|
goto err;
|
|
|
|
}
|
2018-03-31 02:19:56 +08:00
|
|
|
cmds = conf_ssl_get(idx, &name, &cmd_count);
|
2015-03-14 09:36:30 +08:00
|
|
|
cctx = SSL_CONF_CTX_new();
|
|
|
|
if (cctx == NULL)
|
|
|
|
goto err;
|
|
|
|
flags = SSL_CONF_FLAG_FILE;
|
2018-03-19 22:01:39 +08:00
|
|
|
if (!system)
|
|
|
|
flags |= SSL_CONF_FLAG_CERTIFICATE | SSL_CONF_FLAG_REQUIRE_PRIVATE;
|
2015-03-14 09:36:30 +08:00
|
|
|
if (s != NULL) {
|
|
|
|
meth = s->method;
|
|
|
|
SSL_CONF_CTX_set_ssl(cctx, s);
|
2020-07-24 20:53:27 +08:00
|
|
|
libctx = s->ctx->libctx;
|
2015-03-14 09:36:30 +08:00
|
|
|
} else {
|
|
|
|
meth = ctx->method;
|
|
|
|
SSL_CONF_CTX_set_ssl_ctx(cctx, ctx);
|
2020-07-24 20:53:27 +08:00
|
|
|
libctx = ctx->libctx;
|
2015-03-14 09:36:30 +08:00
|
|
|
}
|
|
|
|
if (meth->ssl_accept != ssl_undefined_function)
|
2016-08-06 01:03:17 +08:00
|
|
|
flags |= SSL_CONF_FLAG_SERVER;
|
2015-03-14 09:36:30 +08:00
|
|
|
if (meth->ssl_connect != ssl_undefined_function)
|
2016-08-06 01:03:17 +08:00
|
|
|
flags |= SSL_CONF_FLAG_CLIENT;
|
2015-03-14 09:36:30 +08:00
|
|
|
SSL_CONF_CTX_set_flags(cctx, flags);
|
2020-10-15 17:55:50 +08:00
|
|
|
prev_libctx = OSSL_LIB_CTX_set0_default(libctx);
|
2023-12-14 23:26:21 +08:00
|
|
|
err = 0;
|
2018-03-31 02:19:56 +08:00
|
|
|
for (i = 0; i < cmd_count; i++) {
|
|
|
|
char *cmdstr, *arg;
|
2023-12-14 23:26:21 +08:00
|
|
|
int rv;
|
2018-03-31 02:19:56 +08:00
|
|
|
|
|
|
|
conf_ssl_get_cmd(cmds, i, &cmdstr, &arg);
|
|
|
|
rv = SSL_CONF_cmd(cctx, cmdstr, arg);
|
2023-12-15 01:33:57 +08:00
|
|
|
if (rv <= 0)
|
2023-12-14 23:26:21 +08:00
|
|
|
++err;
|
2015-03-14 09:36:30 +08:00
|
|
|
}
|
2023-12-14 23:26:21 +08:00
|
|
|
if (!SSL_CONF_CTX_finish(cctx))
|
|
|
|
++err;
|
2016-08-06 01:03:17 +08:00
|
|
|
err:
|
2020-10-15 17:55:50 +08:00
|
|
|
OSSL_LIB_CTX_set0_default(prev_libctx);
|
2015-03-14 09:36:30 +08:00
|
|
|
SSL_CONF_CTX_free(cctx);
|
2023-12-14 23:26:21 +08:00
|
|
|
return err == 0;
|
2015-03-14 09:36:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int SSL_config(SSL *s, const char *name)
|
|
|
|
{
|
2018-03-19 22:01:39 +08:00
|
|
|
return ssl_do_config(s, NULL, name, 0);
|
2015-03-14 09:36:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int SSL_CTX_config(SSL_CTX *ctx, const char *name)
|
|
|
|
{
|
2018-03-19 22:01:39 +08:00
|
|
|
return ssl_do_config(NULL, ctx, name, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ssl_ctx_system_config(SSL_CTX *ctx)
|
|
|
|
{
|
|
|
|
ssl_do_config(NULL, ctx, NULL, 1);
|
2015-03-14 09:36:30 +08:00
|
|
|
}
|