2016-05-18 02:20:24 +08:00
|
|
|
/*
|
2021-02-18 22:57:13 +08:00
|
|
|
* Copyright 2015-2021 The OpenSSL Project Authors. All Rights Reserved.
|
2015-12-30 03:12:36 +08:00
|
|
|
*
|
2018-12-06 20:05:25 +08:00
|
|
|
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
2016-05-18 02:20:24 +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-12-30 03:12:36 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include <openssl/crypto.h>
|
|
|
|
#include <openssl/evp.h>
|
|
|
|
#include <openssl/x509.h>
|
|
|
|
#include <openssl/ssl.h>
|
|
|
|
#include <openssl/err.h>
|
|
|
|
#include <openssl/conf.h>
|
|
|
|
#ifndef OPENSSL_NO_ENGINE
|
2021-03-05 04:18:45 +08:00
|
|
|
# include <openssl/engine.h>
|
2015-12-30 03:12:36 +08:00
|
|
|
#endif
|
2017-05-02 20:32:26 +08:00
|
|
|
#include "testutil.h"
|
2015-12-30 03:12:36 +08:00
|
|
|
|
2017-08-22 20:35:43 +08:00
|
|
|
#include "internal/nelem.h"
|
2015-12-30 03:12:36 +08:00
|
|
|
|
2016-02-14 20:02:15 +08:00
|
|
|
#define _UC(c) ((unsigned char)(c))
|
|
|
|
|
2017-05-02 20:32:26 +08:00
|
|
|
static const char *basedomain;
|
|
|
|
static const char *CAfile;
|
|
|
|
static const char *tlsafile;
|
2015-12-30 03:12:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Forward declaration, of function that uses internal interfaces, from headers
|
|
|
|
* included at the end of this module.
|
|
|
|
*/
|
|
|
|
static void store_ctx_dane_init(X509_STORE_CTX *, SSL *);
|
|
|
|
|
|
|
|
static int saved_errno;
|
|
|
|
|
|
|
|
static void save_errno(void)
|
|
|
|
{
|
|
|
|
saved_errno = errno;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int restore_errno(void)
|
|
|
|
{
|
|
|
|
int ret = errno;
|
|
|
|
errno = saved_errno;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int verify_chain(SSL *ssl, STACK_OF(X509) *chain)
|
|
|
|
{
|
2017-05-02 20:32:26 +08:00
|
|
|
X509_STORE_CTX *store_ctx = NULL;
|
|
|
|
SSL_CTX *ssl_ctx = NULL;
|
|
|
|
X509_STORE *store = NULL;
|
|
|
|
int ret = 0;
|
2015-12-30 03:12:36 +08:00
|
|
|
int store_ctx_idx = SSL_get_ex_data_X509_STORE_CTX_idx();
|
|
|
|
|
2017-05-02 20:32:26 +08:00
|
|
|
if (!TEST_ptr(store_ctx = X509_STORE_CTX_new())
|
|
|
|
|| !TEST_ptr(ssl_ctx = SSL_get_SSL_CTX(ssl))
|
|
|
|
|| !TEST_ptr(store = SSL_CTX_get_cert_store(ssl_ctx))
|
2021-01-28 07:28:25 +08:00
|
|
|
|| !TEST_true(X509_STORE_CTX_init(store_ctx, store, NULL, chain))
|
2017-05-02 20:32:26 +08:00
|
|
|
|| !TEST_true(X509_STORE_CTX_set_ex_data(store_ctx, store_ctx_idx,
|
|
|
|
ssl)))
|
2016-02-14 17:42:29 +08:00
|
|
|
goto end;
|
2015-12-30 03:12:36 +08:00
|
|
|
|
2021-03-05 04:18:45 +08:00
|
|
|
X509_STORE_CTX_set_default(store_ctx, SSL_is_server(ssl)
|
|
|
|
? "ssl_client" : "ssl_server");
|
2015-12-30 03:12:36 +08:00
|
|
|
X509_VERIFY_PARAM_set1(X509_STORE_CTX_get0_param(store_ctx),
|
2021-03-05 04:18:45 +08:00
|
|
|
SSL_get0_param(ssl));
|
2015-12-30 03:12:36 +08:00
|
|
|
store_ctx_dane_init(store_ctx, ssl);
|
|
|
|
|
2017-05-02 20:32:26 +08:00
|
|
|
if (SSL_get_verify_callback(ssl) != NULL)
|
2016-05-04 04:40:33 +08:00
|
|
|
X509_STORE_CTX_set_verify_cb(store_ctx, SSL_get_verify_callback(ssl));
|
2015-12-30 03:12:36 +08:00
|
|
|
|
2017-05-02 20:32:26 +08:00
|
|
|
/* Mask "internal failures" (-1) from our return value. */
|
2021-01-28 07:28:25 +08:00
|
|
|
if (!TEST_int_ge(ret = X509_STORE_CTX_verify(store_ctx), 0))
|
2017-05-02 20:32:26 +08:00
|
|
|
ret = 0;
|
2015-12-30 03:12:36 +08:00
|
|
|
|
|
|
|
SSL_set_verify_result(ssl, X509_STORE_CTX_get_error(store_ctx));
|
2017-05-02 20:32:26 +08:00
|
|
|
|
2016-02-14 17:42:29 +08:00
|
|
|
end:
|
2015-12-30 03:12:36 +08:00
|
|
|
X509_STORE_CTX_free(store_ctx);
|
2017-05-02 20:32:26 +08:00
|
|
|
return ret;
|
2015-12-30 03:12:36 +08:00
|
|
|
}
|
|
|
|
|
2016-04-06 17:31:31 +08:00
|
|
|
static STACK_OF(X509) *load_chain(BIO *fp, int nelem)
|
2015-12-30 03:12:36 +08:00
|
|
|
{
|
|
|
|
int count;
|
|
|
|
char *name = 0;
|
|
|
|
char *header = 0;
|
|
|
|
unsigned char *data = 0;
|
|
|
|
long len;
|
2021-03-05 04:18:45 +08:00
|
|
|
char *errtype = 0; /* if error: cert or pkey? */
|
2015-12-30 03:12:36 +08:00
|
|
|
STACK_OF(X509) *chain;
|
|
|
|
typedef X509 *(*d2i_X509_t)(X509 **, const unsigned char **, long);
|
|
|
|
|
2017-05-02 20:32:26 +08:00
|
|
|
if (!TEST_ptr(chain = sk_X509_new_null()))
|
|
|
|
goto err;
|
2015-12-30 03:12:36 +08:00
|
|
|
|
|
|
|
for (count = 0;
|
2016-05-04 04:40:33 +08:00
|
|
|
count < nelem && errtype == 0
|
2017-05-02 20:32:26 +08:00
|
|
|
&& PEM_read_bio(fp, &name, &header, &data, &len) == 1;
|
2016-05-04 04:40:33 +08:00
|
|
|
++count) {
|
|
|
|
if (strcmp(name, PEM_STRING_X509) == 0
|
2021-03-05 04:18:45 +08:00
|
|
|
|| strcmp(name, PEM_STRING_X509_TRUSTED) == 0
|
|
|
|
|| strcmp(name, PEM_STRING_X509_OLD) == 0) {
|
2017-05-02 20:32:26 +08:00
|
|
|
d2i_X509_t d = strcmp(name, PEM_STRING_X509_TRUSTED) != 0
|
|
|
|
? d2i_X509_AUX : d2i_X509;
|
|
|
|
X509 *cert;
|
|
|
|
const unsigned char *p = data;
|
|
|
|
|
|
|
|
if (!TEST_ptr(cert = d(0, &p, len))
|
|
|
|
|| !TEST_long_eq(p - data, len)) {
|
|
|
|
TEST_info("Certificate parsing error");
|
2016-05-04 04:40:33 +08:00
|
|
|
goto err;
|
|
|
|
}
|
2017-05-02 20:32:26 +08:00
|
|
|
|
|
|
|
if (!TEST_true(sk_X509_push(chain, cert)))
|
|
|
|
goto err;
|
2016-05-04 04:40:33 +08:00
|
|
|
} else {
|
2017-05-02 20:32:26 +08:00
|
|
|
TEST_info("Unknown chain file object %s", name);
|
2016-05-04 04:40:33 +08:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
OPENSSL_free(name);
|
|
|
|
OPENSSL_free(header);
|
|
|
|
OPENSSL_free(data);
|
2017-07-06 07:10:28 +08:00
|
|
|
name = header = NULL;
|
|
|
|
data = NULL;
|
2015-12-30 03:12:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (count == nelem) {
|
|
|
|
ERR_clear_error();
|
|
|
|
return chain;
|
|
|
|
}
|
|
|
|
|
|
|
|
err:
|
2017-05-02 20:32:26 +08:00
|
|
|
OPENSSL_free(name);
|
|
|
|
OPENSSL_free(header);
|
|
|
|
OPENSSL_free(data);
|
2021-12-18 23:15:49 +08:00
|
|
|
OSSL_STACK_OF_X509_free(chain);
|
2015-12-30 03:12:36 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-04-06 17:31:31 +08:00
|
|
|
static char *read_to_eol(BIO *f)
|
2015-12-30 03:12:36 +08:00
|
|
|
{
|
2021-08-31 03:09:43 +08:00
|
|
|
static char buf[4096];
|
2015-12-30 03:12:36 +08:00
|
|
|
int n;
|
|
|
|
|
2021-11-14 16:55:45 +08:00
|
|
|
if (BIO_gets(f, buf, sizeof(buf)) <= 0)
|
2015-12-30 03:12:36 +08:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
n = strlen(buf);
|
2017-05-02 20:32:26 +08:00
|
|
|
if (buf[n - 1] != '\n') {
|
|
|
|
if (n + 1 == sizeof(buf))
|
|
|
|
TEST_error("input too long");
|
|
|
|
else
|
|
|
|
TEST_error("EOF before newline");
|
2015-12-30 03:12:36 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Trim trailing whitespace */
|
2017-05-02 20:32:26 +08:00
|
|
|
while (n > 0 && isspace(_UC(buf[n - 1])))
|
2015-12-30 03:12:36 +08:00
|
|
|
buf[--n] = '\0';
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Hex decoder that tolerates optional whitespace
|
|
|
|
*/
|
|
|
|
static ossl_ssize_t hexdecode(const char *in, void *result)
|
|
|
|
{
|
|
|
|
unsigned char **out = (unsigned char **)result;
|
2017-05-02 20:32:26 +08:00
|
|
|
unsigned char *ret;
|
|
|
|
unsigned char *cp;
|
2015-12-30 03:12:36 +08:00
|
|
|
uint8_t byte;
|
|
|
|
int nibble = 0;
|
|
|
|
|
2017-05-02 20:32:26 +08:00
|
|
|
if (!TEST_ptr(ret = OPENSSL_malloc(strlen(in) / 2)))
|
2015-12-30 03:12:36 +08:00
|
|
|
return -1;
|
2017-05-02 20:32:26 +08:00
|
|
|
cp = ret;
|
2015-12-30 03:12:36 +08:00
|
|
|
|
|
|
|
for (byte = 0; *in; ++in) {
|
2016-05-13 03:52:58 +08:00
|
|
|
int x;
|
2015-12-30 03:12:36 +08:00
|
|
|
|
2016-02-14 20:02:15 +08:00
|
|
|
if (isspace(_UC(*in)))
|
2015-12-30 03:12:36 +08:00
|
|
|
continue;
|
2016-05-13 03:52:58 +08:00
|
|
|
x = OPENSSL_hexchar2int(*in);
|
|
|
|
if (x < 0) {
|
2015-12-30 03:12:36 +08:00
|
|
|
OPENSSL_free(ret);
|
|
|
|
return 0;
|
|
|
|
}
|
2016-05-13 03:52:58 +08:00
|
|
|
byte |= (char)x;
|
2015-12-30 03:12:36 +08:00
|
|
|
if ((nibble ^= 1) == 0) {
|
|
|
|
*cp++ = byte;
|
|
|
|
byte = 0;
|
|
|
|
} else {
|
|
|
|
byte <<= 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (nibble != 0) {
|
|
|
|
OPENSSL_free(ret);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return cp - (*out = ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ossl_ssize_t checked_uint8(const char *in, void *out)
|
|
|
|
{
|
|
|
|
uint8_t *result = (uint8_t *)out;
|
|
|
|
const char *cp = in;
|
|
|
|
char *endp;
|
|
|
|
long v;
|
|
|
|
int e;
|
|
|
|
|
|
|
|
save_errno();
|
|
|
|
v = strtol(cp, &endp, 10);
|
|
|
|
e = restore_errno();
|
|
|
|
|
|
|
|
if (((v == LONG_MIN || v == LONG_MAX) && e == ERANGE) ||
|
2016-02-14 20:02:15 +08:00
|
|
|
endp == cp || !isspace(_UC(*endp)) ||
|
2015-12-30 03:12:36 +08:00
|
|
|
v != (*(uint8_t *)result = (uint8_t) v)) {
|
|
|
|
return -1;
|
|
|
|
}
|
2016-02-14 20:02:15 +08:00
|
|
|
for (cp = endp; isspace(_UC(*cp)); ++cp)
|
2015-12-30 03:12:36 +08:00
|
|
|
continue;
|
|
|
|
return cp - in;
|
|
|
|
}
|
|
|
|
|
2016-01-08 04:06:38 +08:00
|
|
|
struct tlsa_field {
|
|
|
|
void *var;
|
|
|
|
const char *name;
|
|
|
|
ossl_ssize_t (*parser)(const char *, void *);
|
|
|
|
};
|
|
|
|
|
2015-12-30 03:12:36 +08:00
|
|
|
static int tlsa_import_rr(SSL *ssl, const char *rrdata)
|
|
|
|
{
|
2016-01-08 04:06:38 +08:00
|
|
|
static uint8_t usage;
|
|
|
|
static uint8_t selector;
|
|
|
|
static uint8_t mtype;
|
|
|
|
static unsigned char *data = NULL;
|
|
|
|
static struct tlsa_field tlsa_fields[] = {
|
2015-12-30 03:12:36 +08:00
|
|
|
{ &usage, "usage", checked_uint8 },
|
|
|
|
{ &selector, "selector", checked_uint8 },
|
|
|
|
{ &mtype, "mtype", checked_uint8 },
|
|
|
|
{ &data, "data", hexdecode },
|
|
|
|
{ NULL, }
|
|
|
|
};
|
2016-01-08 04:06:38 +08:00
|
|
|
int ret;
|
2015-12-30 03:12:36 +08:00
|
|
|
struct tlsa_field *f;
|
2016-01-08 04:06:38 +08:00
|
|
|
const char *cp = rrdata;
|
|
|
|
ossl_ssize_t len = 0;
|
2015-12-30 03:12:36 +08:00
|
|
|
|
|
|
|
for (f = tlsa_fields; f->var; ++f) {
|
|
|
|
if ((len = f->parser(cp += len, f->var)) <= 0) {
|
2017-05-02 20:32:26 +08:00
|
|
|
TEST_info("bad TLSA %s field in: %s", f->name, rrdata);
|
2015-12-30 03:12:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2017-05-02 20:32:26 +08:00
|
|
|
|
2015-12-30 03:12:36 +08:00
|
|
|
ret = SSL_dane_tlsa_add(ssl, usage, selector, mtype, data, len);
|
|
|
|
OPENSSL_free(data);
|
|
|
|
if (ret == 0) {
|
2017-05-02 20:32:26 +08:00
|
|
|
TEST_info("unusable TLSA rrdata: %s", rrdata);
|
2015-12-30 03:12:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (ret < 0) {
|
2017-05-02 20:32:26 +08:00
|
|
|
TEST_info("error loading TLSA rrdata: %s", rrdata);
|
2015-12-30 03:12:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2017-05-02 20:32:26 +08:00
|
|
|
|
2015-12-30 03:12:36 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int allws(const char *cp)
|
|
|
|
{
|
|
|
|
while (*cp)
|
2016-02-14 20:02:15 +08:00
|
|
|
if (!isspace(_UC(*cp++)))
|
2015-12-30 03:12:36 +08:00
|
|
|
return 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2017-03-15 00:36:07 +08:00
|
|
|
static int test_tlsafile(SSL_CTX *ctx, const char *base_name,
|
2016-04-06 17:31:31 +08:00
|
|
|
BIO *f, const char *path)
|
2015-12-30 03:12:36 +08:00
|
|
|
{
|
|
|
|
char *line;
|
|
|
|
int testno = 0;
|
|
|
|
int ret = 1;
|
|
|
|
SSL *ssl;
|
|
|
|
|
|
|
|
while (ret > 0 && (line = read_to_eol(f)) != NULL) {
|
|
|
|
STACK_OF(X509) *chain;
|
|
|
|
int ntlsa;
|
|
|
|
int ncert;
|
2016-07-11 08:36:02 +08:00
|
|
|
int noncheck;
|
2015-12-30 03:12:36 +08:00
|
|
|
int want;
|
|
|
|
int want_depth;
|
|
|
|
int off;
|
|
|
|
int i;
|
|
|
|
int ok;
|
|
|
|
int err;
|
|
|
|
int mdpth;
|
|
|
|
|
|
|
|
if (*line == '\0' || *line == '#')
|
|
|
|
continue;
|
|
|
|
|
|
|
|
++testno;
|
2016-07-11 08:36:02 +08:00
|
|
|
if (sscanf(line, "%d %d %d %d %d%n",
|
|
|
|
&ntlsa, &ncert, &noncheck, &want, &want_depth, &off) != 5
|
2015-12-30 03:12:36 +08:00
|
|
|
|| !allws(line + off)) {
|
2017-05-02 20:32:26 +08:00
|
|
|
TEST_error("Malformed line for test %d", testno);
|
2015-12-30 03:12:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-05-02 20:32:26 +08:00
|
|
|
if (!TEST_ptr(ssl = SSL_new(ctx)))
|
|
|
|
return 0;
|
2015-12-30 03:12:36 +08:00
|
|
|
SSL_set_connect_state(ssl);
|
2017-03-15 00:36:07 +08:00
|
|
|
if (SSL_dane_enable(ssl, base_name) <= 0) {
|
2015-12-30 03:12:36 +08:00
|
|
|
SSL_free(ssl);
|
2017-05-02 20:32:26 +08:00
|
|
|
return 0;
|
2015-12-30 03:12:36 +08:00
|
|
|
}
|
2016-07-11 08:36:02 +08:00
|
|
|
if (noncheck)
|
|
|
|
SSL_dane_set_flags(ssl, DANE_FLAG_NO_DANE_EE_NAMECHECKS);
|
2015-12-30 03:12:36 +08:00
|
|
|
|
|
|
|
for (i = 0; i < ntlsa; ++i) {
|
|
|
|
if ((line = read_to_eol(f)) == NULL || !tlsa_import_rr(ssl, line)) {
|
|
|
|
SSL_free(ssl);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Don't report old news */
|
|
|
|
ERR_clear_error();
|
2017-05-02 20:32:26 +08:00
|
|
|
if (!TEST_ptr(chain = load_chain(f, ncert))) {
|
2015-12-30 03:12:36 +08:00
|
|
|
SSL_free(ssl);
|
2017-05-02 20:32:26 +08:00
|
|
|
return 0;
|
2015-12-30 03:12:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ok = verify_chain(ssl, chain);
|
2021-12-18 23:15:49 +08:00
|
|
|
OSSL_STACK_OF_X509_free(chain);
|
2015-12-30 03:12:36 +08:00
|
|
|
err = SSL_get_verify_result(ssl);
|
Suppress DANE TLSA reflection when verification fails
As documented both SSL_get0_dane_authority() and SSL_get0_dane_tlsa()
are expected to return a negative match depth and nothing else when
verification fails. However, this only happened when verification
failed during chain construction. Errors in verification of the
constructed chain did not have the intended effect on these functions.
This commit updates the functions to check for verify_result ==
X509_V_OK, and no longer erases any accumulated match information
when chain construction fails. Sophisticated developers can, with
care, use SSL_set_verify_result(ssl, X509_V_OK) to "peek" at TLSA
info even when verification fail. They must of course first check
and save the real error, and restore the original error as quickly
as possible. Hiding by default seems to be the safer interface.
Introduced X509_V_ERR_DANE_NO_MATCH code to signal failure to find
matching TLSA records. Previously reported via X509_V_ERR_CERT_UNTRUSTED.
This also changes the "-brief" output from s_client to include
verification results and TLSA match information.
Mentioned session resumption in code example in SSL_CTX_dane_enable(3).
Also mentioned that depths returned are relative to the verified chain
which is now available via SSL_get0_verified_chain(3).
Added a few more test-cases to danetest, that exercise the new
code.
Resolved thread safety issue in use of static buffer in
X509_verify_cert_error_string().
Fixed long-stating issue in apps/s_cb.c which always sets verify_error
to either X509_V_OK or "chain to long", code elsewhere (e.g.
s_time.c), seems to expect the actual error. [ The new chain
construction code is expected to correctly generate "chain
too long" errors, so at some point we need to drop the
work-arounds, once SSL_set_verify_depth() is also fixed to
propagate the depth to X509_STORE_CTX reliably. ]
Reviewed-by: Rich Salz <rsalz@openssl.org>
2016-02-08 08:07:57 +08:00
|
|
|
/*
|
|
|
|
* Peek under the hood, normally TLSA match data is hidden when
|
|
|
|
* verification fails, we can obtain any suppressed data by setting the
|
|
|
|
* verification result to X509_V_OK before looking.
|
|
|
|
*/
|
|
|
|
SSL_set_verify_result(ssl, X509_V_OK);
|
2015-12-30 03:12:36 +08:00
|
|
|
mdpth = SSL_get0_dane_authority(ssl, NULL, NULL);
|
Suppress DANE TLSA reflection when verification fails
As documented both SSL_get0_dane_authority() and SSL_get0_dane_tlsa()
are expected to return a negative match depth and nothing else when
verification fails. However, this only happened when verification
failed during chain construction. Errors in verification of the
constructed chain did not have the intended effect on these functions.
This commit updates the functions to check for verify_result ==
X509_V_OK, and no longer erases any accumulated match information
when chain construction fails. Sophisticated developers can, with
care, use SSL_set_verify_result(ssl, X509_V_OK) to "peek" at TLSA
info even when verification fail. They must of course first check
and save the real error, and restore the original error as quickly
as possible. Hiding by default seems to be the safer interface.
Introduced X509_V_ERR_DANE_NO_MATCH code to signal failure to find
matching TLSA records. Previously reported via X509_V_ERR_CERT_UNTRUSTED.
This also changes the "-brief" output from s_client to include
verification results and TLSA match information.
Mentioned session resumption in code example in SSL_CTX_dane_enable(3).
Also mentioned that depths returned are relative to the verified chain
which is now available via SSL_get0_verified_chain(3).
Added a few more test-cases to danetest, that exercise the new
code.
Resolved thread safety issue in use of static buffer in
X509_verify_cert_error_string().
Fixed long-stating issue in apps/s_cb.c which always sets verify_error
to either X509_V_OK or "chain to long", code elsewhere (e.g.
s_time.c), seems to expect the actual error. [ The new chain
construction code is expected to correctly generate "chain
too long" errors, so at some point we need to drop the
work-arounds, once SSL_set_verify_depth() is also fixed to
propagate the depth to X509_STORE_CTX reliably. ]
Reviewed-by: Rich Salz <rsalz@openssl.org>
2016-02-08 08:07:57 +08:00
|
|
|
/* Not needed any more, but lead by example and put the error back. */
|
|
|
|
SSL_set_verify_result(ssl, err);
|
2015-12-30 03:12:36 +08:00
|
|
|
SSL_free(ssl);
|
|
|
|
|
2017-05-02 20:32:26 +08:00
|
|
|
if (!TEST_int_eq(err, want)) {
|
|
|
|
if (want == X509_V_OK)
|
|
|
|
TEST_info("Verification failure in test %d: %d=%s",
|
|
|
|
testno, err, X509_verify_cert_error_string(err));
|
|
|
|
else
|
|
|
|
TEST_info("Unexpected error in test %d", testno);
|
2015-12-30 03:12:36 +08:00
|
|
|
ret = 0;
|
|
|
|
continue;
|
|
|
|
}
|
2017-05-02 20:32:26 +08:00
|
|
|
if (!TEST_false(want == 0 && ok == 0)) {
|
|
|
|
TEST_info("Verification failure in test %d: ok=0", testno);
|
2015-12-30 03:12:36 +08:00
|
|
|
ret = 0;
|
|
|
|
continue;
|
|
|
|
}
|
2017-05-02 20:32:26 +08:00
|
|
|
if (!TEST_int_eq(mdpth, want_depth)) {
|
|
|
|
TEST_info("In test test %d", testno);
|
2015-12-30 03:12:36 +08:00
|
|
|
ret = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ERR_clear_error();
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-08-16 05:39:03 +08:00
|
|
|
static int run_tlsatest(void)
|
2015-12-30 03:12:36 +08:00
|
|
|
{
|
|
|
|
SSL_CTX *ctx = NULL;
|
2017-05-02 20:32:26 +08:00
|
|
|
BIO *f = NULL;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
if (!TEST_ptr(f = BIO_new_file(tlsafile, "r"))
|
|
|
|
|| !TEST_ptr(ctx = SSL_CTX_new(TLS_client_method()))
|
|
|
|
|| !TEST_int_gt(SSL_CTX_dane_enable(ctx), 0)
|
2019-03-08 08:09:44 +08:00
|
|
|
|| !TEST_true(SSL_CTX_load_verify_file(ctx, CAfile))
|
2021-03-05 04:18:45 +08:00
|
|
|
|| !TEST_int_gt(SSL_CTX_dane_mtype_set(ctx, EVP_sha512(), 2, 1), 0)
|
|
|
|
|| !TEST_int_gt(SSL_CTX_dane_mtype_set(ctx, EVP_sha256(), 1, 2), 0)
|
2017-05-02 20:32:26 +08:00
|
|
|
|| !TEST_int_gt(test_tlsafile(ctx, basedomain, f, tlsafile), 0))
|
|
|
|
goto end;
|
|
|
|
ret = 1;
|
|
|
|
|
|
|
|
end:
|
|
|
|
BIO_free(f);
|
|
|
|
SSL_CTX_free(ctx);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-08-16 10:36:01 +08:00
|
|
|
OPT_TEST_DECLARE_USAGE("basedomain CAfile tlsafile\n")
|
|
|
|
|
2017-07-18 09:48:27 +08:00
|
|
|
int setup_tests(void)
|
2017-05-02 20:32:26 +08:00
|
|
|
{
|
2020-01-30 23:30:17 +08:00
|
|
|
if (!test_skip_common_options()) {
|
|
|
|
TEST_error("Error parsing test options\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-07-18 09:48:27 +08:00
|
|
|
if (!TEST_ptr(basedomain = test_get_argument(0))
|
|
|
|
|| !TEST_ptr(CAfile = test_get_argument(1))
|
2018-08-16 10:36:01 +08:00
|
|
|
|| !TEST_ptr(tlsafile = test_get_argument(2)))
|
2017-05-02 20:32:26 +08:00
|
|
|
return 0;
|
2015-12-30 03:12:36 +08:00
|
|
|
|
2017-05-02 20:32:26 +08:00
|
|
|
ADD_TEST(run_tlsatest);
|
2017-07-18 09:48:27 +08:00
|
|
|
return 1;
|
2015-12-30 03:12:36 +08:00
|
|
|
}
|
|
|
|
|
2017-08-22 20:35:43 +08:00
|
|
|
#include "internal/dane.h"
|
2015-12-30 03:12:36 +08:00
|
|
|
|
|
|
|
static void store_ctx_dane_init(X509_STORE_CTX *store_ctx, SSL *ssl)
|
|
|
|
{
|
|
|
|
X509_STORE_CTX_set0_dane(store_ctx, SSL_get0_dane(ssl));
|
|
|
|
}
|