2015-03-14 01:36:30 +00:00
|
|
|
/*
|
2018-03-20 13:00:17 +00:00
|
|
|
* Copyright 2015-2018 The OpenSSL Project Authors. All Rights Reserved.
|
2015-03-14 01:36:30 +00:00
|
|
|
*
|
2018-12-06 12:08:51 +00:00
|
|
|
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
2016-05-17 18:18:30 +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
|
2015-03-14 01:36:30 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <openssl/conf.h>
|
|
|
|
#include <openssl/ssl.h>
|
|
|
|
#include "ssl_locl.h"
|
2018-03-30 18:19:56 +00:00
|
|
|
#include "internal/sslconf.h"
|
2015-03-14 01:36:30 +00:00
|
|
|
|
|
|
|
/* SSL library configuration module. */
|
|
|
|
|
|
|
|
void SSL_add_ssl_module(void)
|
|
|
|
{
|
2018-03-30 18:19:56 +00:00
|
|
|
/* Do nothing. This will be added automatically by libcrypto */
|
2015-03-14 01:36:30 +00:00
|
|
|
}
|
|
|
|
|
2018-03-19 14:01:39 +00:00
|
|
|
static int ssl_do_config(SSL *s, SSL_CTX *ctx, const char *name, int system)
|
2015-03-14 01:36:30 +00:00
|
|
|
{
|
|
|
|
SSL_CONF_CTX *cctx = NULL;
|
2018-03-30 18:19:56 +00:00
|
|
|
size_t i, idx, cmd_count;
|
2015-03-14 01:36:30 +00:00
|
|
|
int rv = 0;
|
|
|
|
unsigned int flags;
|
|
|
|
const SSL_METHOD *meth;
|
2018-03-30 18:19:56 +00:00
|
|
|
const SSL_CONF_CMD *cmds;
|
2018-03-19 14:01:39 +00:00
|
|
|
|
2015-03-14 01:36:30 +00:00
|
|
|
if (s == NULL && ctx == NULL) {
|
|
|
|
SSLerr(SSL_F_SSL_DO_CONFIG, ERR_R_PASSED_NULL_PARAMETER);
|
|
|
|
goto err;
|
|
|
|
}
|
2018-03-19 14:01:39 +00:00
|
|
|
|
|
|
|
if (name == NULL && system)
|
|
|
|
name = "system_default";
|
2018-03-30 18:19:56 +00:00
|
|
|
if (!conf_ssl_name_find(name, &idx)) {
|
2018-03-19 14:01:39 +00:00
|
|
|
if (!system) {
|
|
|
|
SSLerr(SSL_F_SSL_DO_CONFIG, SSL_R_INVALID_CONFIGURATION_NAME);
|
|
|
|
ERR_add_error_data(2, "name=", name);
|
|
|
|
}
|
2015-03-14 01:36:30 +00:00
|
|
|
goto err;
|
|
|
|
}
|
2018-03-30 18:19:56 +00:00
|
|
|
cmds = conf_ssl_get(idx, &name, &cmd_count);
|
2015-03-14 01:36:30 +00:00
|
|
|
cctx = SSL_CONF_CTX_new();
|
|
|
|
if (cctx == NULL)
|
|
|
|
goto err;
|
|
|
|
flags = SSL_CONF_FLAG_FILE;
|
2018-03-19 14:01:39 +00:00
|
|
|
if (!system)
|
|
|
|
flags |= SSL_CONF_FLAG_CERTIFICATE | SSL_CONF_FLAG_REQUIRE_PRIVATE;
|
2015-03-14 01:36:30 +00:00
|
|
|
if (s != NULL) {
|
|
|
|
meth = s->method;
|
|
|
|
SSL_CONF_CTX_set_ssl(cctx, s);
|
|
|
|
} else {
|
|
|
|
meth = ctx->method;
|
|
|
|
SSL_CONF_CTX_set_ssl_ctx(cctx, ctx);
|
|
|
|
}
|
|
|
|
if (meth->ssl_accept != ssl_undefined_function)
|
2016-08-05 17:03:17 +00:00
|
|
|
flags |= SSL_CONF_FLAG_SERVER;
|
2015-03-14 01:36:30 +00:00
|
|
|
if (meth->ssl_connect != ssl_undefined_function)
|
2016-08-05 17:03:17 +00:00
|
|
|
flags |= SSL_CONF_FLAG_CLIENT;
|
2015-03-14 01:36:30 +00:00
|
|
|
SSL_CONF_CTX_set_flags(cctx, flags);
|
2018-03-30 18:19:56 +00:00
|
|
|
for (i = 0; i < cmd_count; i++) {
|
|
|
|
char *cmdstr, *arg;
|
|
|
|
|
|
|
|
conf_ssl_get_cmd(cmds, i, &cmdstr, &arg);
|
|
|
|
rv = SSL_CONF_cmd(cctx, cmdstr, arg);
|
2015-03-14 01:36:30 +00:00
|
|
|
if (rv <= 0) {
|
|
|
|
if (rv == -2)
|
|
|
|
SSLerr(SSL_F_SSL_DO_CONFIG, SSL_R_UNKNOWN_COMMAND);
|
2016-06-28 20:51:27 +00:00
|
|
|
else
|
2015-03-14 01:36:30 +00:00
|
|
|
SSLerr(SSL_F_SSL_DO_CONFIG, SSL_R_BAD_VALUE);
|
2018-03-30 18:19:56 +00:00
|
|
|
ERR_add_error_data(6, "section=", name, ", cmd=", cmdstr,
|
|
|
|
", arg=", arg);
|
2015-03-14 01:36:30 +00:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rv = SSL_CONF_CTX_finish(cctx);
|
2016-08-05 17:03:17 +00:00
|
|
|
err:
|
2015-03-14 01:36:30 +00:00
|
|
|
SSL_CONF_CTX_free(cctx);
|
|
|
|
return rv <= 0 ? 0 : 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int SSL_config(SSL *s, const char *name)
|
|
|
|
{
|
2018-03-19 14:01:39 +00:00
|
|
|
return ssl_do_config(s, NULL, name, 0);
|
2015-03-14 01:36:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int SSL_CTX_config(SSL_CTX *ctx, const char *name)
|
|
|
|
{
|
2018-03-19 14:01:39 +00: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 01:36:30 +00:00
|
|
|
}
|