/* Copyright (c) 2009-2018 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "net.h"
#include "str.h"
#include "iostream-openssl.h"
/* openssl_min_protocol_to_options() scans this array for name and returns
version and opt. opt is used with SSL_set_options() and version is used with
SSL_set_min_proto_version(). Using either method should enable the same
SSL protocol versions. */
static const struct {
const char *name;
int version;
long opt;
} protocol_versions[] = {
{ SSL_TXT_SSLV3, SSL3_VERSION, 0 },
};
int *version_r)
{
unsigned i = 0;
for (; i < N_ELEMENTS(protocol_versions); i++) {
break;
}
if (i >= N_ELEMENTS(protocol_versions))
return -1;
return 0;
}
{
const char *cstr;
unsigned int len;
/* NULs in the name - could be some MITM attack.
never allow. */
return "";
}
return cstr;
}
{
return "";
}
{
return 0;
} else
return -1;
return 0;
}
{
int cn_idx;
return "";
if (cn_idx == -1)
return "";
return asn1_string_to_c(str);
}
{
const char *p;
return TRUE;
/* check for *.example.com wildcard */
return FALSE;
}
const char **reason_r)
{
const char *dnsname;
unsigned int i, count;
bool ret;
/* verify against SubjectAltNames */
/* try to convert verify_name to IP */
else
for (i = 0; i < count; i++) {
"Matches DNS name in SubjectAltNames: %s", dnsname);
break;
}
break;
}
}
}
/* verify against CommonName only when there wasn't any DNS
SubjectAltNames */
if (dns_names) {
} else {
"Matches to CommonName: %s", cname);
} else {
"No match to CommonName=%s or %u SubjectAltNames",
}
}
return ret;
}
{
const char *ret;
char *buf;
if ((flags & ERR_TXT_STRING) != 0)
return ret;
}
const char *openssl_iostream_error(void)
{
unsigned long err;
int flags;
if (ERR_peek_error() == 0)
break;
else
}
if (err == 0) {
if (errno != 0)
else
final_error = "Unknown error";
} else {
}
return final_error;
else {
}
}
const char *openssl_iostream_key_load_error(void)
{
return "Key is for a different cert than ssl_cert";
else
return openssl_iostream_error();
}
{
}
const char *
{
unsigned long err;
err = ERR_peek_error();
return openssl_iostream_error();
else if (is_pem_key(cert)) {
return "The file contains a private key "
"(you've mixed ssl_cert and ssl_key settings)";
return t_strdup_printf("There is no valid PEM certificate. "
} else {
return "There is no valid PEM certificate.";
}
}
void openssl_iostream_clear_errors(void)
{
while (ERR_get_error() != 0)
;
}