84 int tls_set_ca_certificate_info(SSL_CTX *ctx,
const char *CAfile,
92 #define CA_PATH_FMT "%s%s%s"
93 #define CA_PATH_ARGS(var, nextvar) \
94 var ? #var "=\"" : "", \
96 var ? (nextvar ? "\", " : "\"") : ""
98 if (CAfile || CApath) {
99 if (!SSL_CTX_load_verify_locations(ctx, CAfile, CApath)) {
100 msg_info(
"cannot load Certification Authority data, "
101 CA_PATH_FMT CA_PATH_FMT
": disabling TLS support",
102 CA_PATH_ARGS(CAfile, CApath),
103 CA_PATH_ARGS(CApath, 0));
108 msg_info(
"cannot set default OpenSSL certificate verification "
109 "paths: disabling TLS support");
119 static int set_cert_stuff(SSL_CTX *ctx,
const char *cert_type,
120 const char *cert_file,
121 const char *key_file)
131 if (SSL_CTX_use_certificate_chain_file(ctx, cert_file) <= 0) {
132 msg_warn(
"cannot get %s certificate from file \"%s\": "
133 "disabling TLS support", cert_type, cert_file);
137 if (SSL_CTX_use_PrivateKey_file(ctx, key_file, SSL_FILETYPE_PEM) <= 0) {
138 msg_warn(
"cannot get %s private key from file \"%s\": "
139 "disabling TLS support", cert_type, key_file);
147 if (!SSL_CTX_check_private_key(ctx)) {
148 msg_warn(
"%s private key in %s does not match public key in %s: "
149 "disabling TLS support", cert_type, key_file, cert_file);
157 int tls_set_my_certificate_key_info(SSL_CTX *ctx,
158 const char *cert_file,
159 const char *key_file,
160 const char *dcert_file,
161 const char *dkey_file,
162 const char *eccert_file,
163 const char *eckey_file)
170 if (*cert_file && !set_cert_stuff(ctx,
"RSA", cert_file, key_file))
172 if (*dcert_file && !set_cert_stuff(ctx,
"DSA", dcert_file, dkey_file))
174 #if OPENSSL_VERSION_NUMBER >= 0x1000000fL && !defined(OPENSSL_NO_ECDH)
175 if (*eccert_file && !set_cert_stuff(ctx,
"ECDSA", eccert_file, eckey_file))
179 msg_warn(
"ECDSA not supported. Ignoring ECDSA certificate file \"%s\"",
void msg_warn(const char *fmt,...)
bool var_tls_append_def_CA
void msg_info(const char *fmt,...)