2015-01-22 03:40:55 +00:00
|
|
|
/*
|
2018-05-01 12:34:30 +00:00
|
|
|
* Copyright 2004-2018 The OpenSSL Project Authors. All Rights Reserved.
|
2004-09-06 18:43:01 +00:00
|
|
|
*
|
2016-05-17 18:52:22 +00:00
|
|
|
* Licensed under the OpenSSL license (the "License"). You may not use
|
|
|
|
* 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
|
2004-09-06 18:43:01 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2015-05-14 14:56:48 +00:00
|
|
|
#include "internal/cryptlib.h"
|
2004-09-06 18:43:01 +00:00
|
|
|
#include <openssl/crypto.h>
|
|
|
|
#include <openssl/buffer.h>
|
|
|
|
#include <openssl/x509.h>
|
|
|
|
#include <openssl/x509v3.h>
|
2016-06-05 19:51:35 +00:00
|
|
|
#include "internal/x509_int.h"
|
2004-09-06 18:43:01 +00:00
|
|
|
|
2014-05-24 22:48:29 +00:00
|
|
|
#include "x509_lcl.h"
|
2013-12-11 14:28:57 +00:00
|
|
|
|
2004-09-06 18:43:01 +00:00
|
|
|
/* X509_VERIFY_PARAM functions */
|
|
|
|
|
2014-06-22 05:38:57 +00:00
|
|
|
#define SET_HOST 0
|
|
|
|
#define ADD_HOST 1
|
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
static char *str_copy(const char *s)
|
|
|
|
{
|
|
|
|
return OPENSSL_strdup(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void str_free(char *s)
|
|
|
|
{
|
|
|
|
OPENSSL_free(s);
|
|
|
|
}
|
2014-06-22 05:38:57 +00:00
|
|
|
|
2015-05-02 16:44:08 +00:00
|
|
|
static int int_x509_param_set_hosts(X509_VERIFY_PARAM *vpm, int mode,
|
2015-01-22 03:40:55 +00:00
|
|
|
const char *name, size_t namelen)
|
|
|
|
{
|
|
|
|
char *copy;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Refuse names with embedded NUL bytes, except perhaps as final byte.
|
|
|
|
* XXX: Do we need to push an error onto the error stack?
|
|
|
|
*/
|
2016-01-16 17:57:24 +00:00
|
|
|
if (namelen == 0 || name == NULL)
|
2015-01-22 03:40:55 +00:00
|
|
|
namelen = name ? strlen(name) : 0;
|
|
|
|
else if (name && memchr(name, '\0', namelen > 1 ? namelen - 1 : namelen))
|
|
|
|
return 0;
|
2016-01-16 17:57:24 +00:00
|
|
|
if (namelen > 0 && name[namelen - 1] == '\0')
|
2015-01-22 03:40:55 +00:00
|
|
|
--namelen;
|
|
|
|
|
2015-05-01 18:37:16 +00:00
|
|
|
if (mode == SET_HOST) {
|
2015-05-02 16:44:08 +00:00
|
|
|
sk_OPENSSL_STRING_pop_free(vpm->hosts, str_free);
|
|
|
|
vpm->hosts = NULL;
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
|
|
|
if (name == NULL || namelen == 0)
|
|
|
|
return 1;
|
|
|
|
|
Rename some BUF_xxx to OPENSSL_xxx
Rename BUF_{strdup,strlcat,strlcpy,memdup,strndup,strnlen}
to OPENSSL_{strdup,strlcat,strlcpy,memdup,strndup,strnlen}
Add #define's for the old names.
Add CRYPTO_{memdup,strndup}, called by OPENSSL_{memdup,strndup} macros.
Reviewed-by: Tim Hudson <tjh@openssl.org>
2015-12-16 21:12:24 +00:00
|
|
|
copy = OPENSSL_strndup(name, namelen);
|
2015-01-22 03:40:55 +00:00
|
|
|
if (copy == NULL)
|
|
|
|
return 0;
|
|
|
|
|
2015-05-02 16:44:08 +00:00
|
|
|
if (vpm->hosts == NULL &&
|
|
|
|
(vpm->hosts = sk_OPENSSL_STRING_new_null()) == NULL) {
|
2015-01-22 03:40:55 +00:00
|
|
|
OPENSSL_free(copy);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-05-02 16:44:08 +00:00
|
|
|
if (!sk_OPENSSL_STRING_push(vpm->hosts, copy)) {
|
2015-01-22 03:40:55 +00:00
|
|
|
OPENSSL_free(copy);
|
2015-05-02 16:44:08 +00:00
|
|
|
if (sk_OPENSSL_STRING_num(vpm->hosts) == 0) {
|
|
|
|
sk_OPENSSL_STRING_free(vpm->hosts);
|
|
|
|
vpm->hosts = NULL;
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
2014-06-22 05:38:57 +00:00
|
|
|
|
2004-09-06 18:43:01 +00:00
|
|
|
|
|
|
|
X509_VERIFY_PARAM *X509_VERIFY_PARAM_new(void)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
|
|
|
X509_VERIFY_PARAM *param;
|
2015-04-30 21:33:59 +00:00
|
|
|
|
2015-08-25 17:25:58 +00:00
|
|
|
param = OPENSSL_zalloc(sizeof(*param));
|
2018-04-24 16:41:45 +00:00
|
|
|
if (param == NULL) {
|
|
|
|
X509err(X509_F_X509_VERIFY_PARAM_NEW, ERR_R_MALLOC_FAILURE);
|
2015-01-22 03:40:55 +00:00
|
|
|
return NULL;
|
2018-04-24 16:41:45 +00:00
|
|
|
}
|
2016-09-15 19:42:53 +00:00
|
|
|
param->trust = X509_TRUST_DEFAULT;
|
2018-04-24 16:41:45 +00:00
|
|
|
/* param->inh_flags = X509_VP_FLAG_DEFAULT; */
|
2016-09-15 19:42:53 +00:00
|
|
|
param->depth = -1;
|
|
|
|
param->auth_level = -1; /* -1 means unset, 0 is explicit */
|
2015-01-22 03:40:55 +00:00
|
|
|
return param;
|
|
|
|
}
|
2004-09-06 18:43:01 +00:00
|
|
|
|
|
|
|
void X509_VERIFY_PARAM_free(X509_VERIFY_PARAM *param)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
2016-09-15 19:42:53 +00:00
|
|
|
if (param == NULL)
|
2015-04-11 15:08:38 +00:00
|
|
|
return;
|
2016-09-15 19:42:53 +00:00
|
|
|
sk_ASN1_OBJECT_pop_free(param->policies, ASN1_OBJECT_free);
|
|
|
|
sk_OPENSSL_STRING_pop_free(param->hosts, str_free);
|
|
|
|
OPENSSL_free(param->peername);
|
|
|
|
OPENSSL_free(param->email);
|
|
|
|
OPENSSL_free(param->ip);
|
2015-01-22 03:40:55 +00:00
|
|
|
OPENSSL_free(param);
|
|
|
|
}
|
2004-09-06 18:43:01 +00:00
|
|
|
|
2014-12-28 02:48:40 +00:00
|
|
|
/*-
|
|
|
|
* This function determines how parameters are "inherited" from one structure
|
2004-09-06 18:43:01 +00:00
|
|
|
* to another. There are several different ways this can happen.
|
|
|
|
*
|
|
|
|
* 1. If a child structure needs to have its values initialized from a parent
|
|
|
|
* they are simply copied across. For example SSL_CTX copied to SSL.
|
|
|
|
* 2. If the structure should take on values only if they are currently unset.
|
|
|
|
* For example the values in an SSL structure will take appropriate value
|
|
|
|
* for SSL servers or clients but only if the application has not set new
|
|
|
|
* ones.
|
|
|
|
*
|
2015-01-22 03:40:55 +00:00
|
|
|
* The "inh_flags" field determines how this function behaves.
|
2004-09-06 18:43:01 +00:00
|
|
|
*
|
|
|
|
* Normally any values which are set in the default are not copied from the
|
|
|
|
* destination and verify flags are ORed together.
|
|
|
|
*
|
|
|
|
* If X509_VP_FLAG_DEFAULT is set then anything set in the source is copied
|
|
|
|
* to the destination. Effectively the values in "to" become default values
|
|
|
|
* which will be used only if nothing new is set in "from".
|
|
|
|
*
|
|
|
|
* If X509_VP_FLAG_OVERWRITE is set then all value are copied across whether
|
|
|
|
* they are set or not. Flags is still Ored though.
|
|
|
|
*
|
|
|
|
* If X509_VP_FLAG_RESET_FLAGS is set then the flags value is copied instead
|
|
|
|
* of ORed.
|
|
|
|
*
|
|
|
|
* If X509_VP_FLAG_LOCKED is set then no values are copied.
|
|
|
|
*
|
|
|
|
* If X509_VP_FLAG_ONCE is set then the current inh_flags setting is zeroed
|
|
|
|
* after the next call.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Macro to test if a field should be copied from src to dest */
|
|
|
|
|
|
|
|
#define test_x509_verify_param_copy(field, def) \
|
2015-01-22 03:40:55 +00:00
|
|
|
(to_overwrite || \
|
|
|
|
((src->field != def) && (to_default || (dest->field == def))))
|
2004-09-06 18:43:01 +00:00
|
|
|
|
|
|
|
/* Macro to test and copy a field if necessary */
|
|
|
|
|
|
|
|
#define x509_verify_param_copy(field, def) \
|
2015-01-22 03:40:55 +00:00
|
|
|
if (test_x509_verify_param_copy(field, def)) \
|
|
|
|
dest->field = src->field
|
2004-09-06 18:43:01 +00:00
|
|
|
|
|
|
|
int X509_VERIFY_PARAM_inherit(X509_VERIFY_PARAM *dest,
|
2015-01-22 03:40:55 +00:00
|
|
|
const X509_VERIFY_PARAM *src)
|
|
|
|
{
|
|
|
|
unsigned long inh_flags;
|
|
|
|
int to_default, to_overwrite;
|
|
|
|
if (!src)
|
|
|
|
return 1;
|
|
|
|
inh_flags = dest->inh_flags | src->inh_flags;
|
|
|
|
|
|
|
|
if (inh_flags & X509_VP_FLAG_ONCE)
|
|
|
|
dest->inh_flags = 0;
|
|
|
|
|
|
|
|
if (inh_flags & X509_VP_FLAG_LOCKED)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
if (inh_flags & X509_VP_FLAG_DEFAULT)
|
|
|
|
to_default = 1;
|
|
|
|
else
|
|
|
|
to_default = 0;
|
|
|
|
|
|
|
|
if (inh_flags & X509_VP_FLAG_OVERWRITE)
|
|
|
|
to_overwrite = 1;
|
|
|
|
else
|
|
|
|
to_overwrite = 0;
|
|
|
|
|
|
|
|
x509_verify_param_copy(purpose, 0);
|
2016-01-28 08:01:45 +00:00
|
|
|
x509_verify_param_copy(trust, X509_TRUST_DEFAULT);
|
2015-01-22 03:40:55 +00:00
|
|
|
x509_verify_param_copy(depth, -1);
|
2016-03-19 02:09:41 +00:00
|
|
|
x509_verify_param_copy(auth_level, -1);
|
2015-01-22 03:40:55 +00:00
|
|
|
|
|
|
|
/* If overwrite or check time not set, copy across */
|
|
|
|
|
|
|
|
if (to_overwrite || !(dest->flags & X509_V_FLAG_USE_CHECK_TIME)) {
|
|
|
|
dest->check_time = src->check_time;
|
|
|
|
dest->flags &= ~X509_V_FLAG_USE_CHECK_TIME;
|
|
|
|
/* Don't need to copy flag: that is done below */
|
|
|
|
}
|
|
|
|
|
|
|
|
if (inh_flags & X509_VP_FLAG_RESET_FLAGS)
|
|
|
|
dest->flags = 0;
|
|
|
|
|
|
|
|
dest->flags |= src->flags;
|
|
|
|
|
|
|
|
if (test_x509_verify_param_copy(policies, NULL)) {
|
|
|
|
if (!X509_VERIFY_PARAM_set1_policies(dest, src->policies))
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Copy the host flags if and only if we're copying the host list */
|
2015-05-02 16:44:08 +00:00
|
|
|
if (test_x509_verify_param_copy(hosts, NULL)) {
|
|
|
|
sk_OPENSSL_STRING_pop_free(dest->hosts, str_free);
|
|
|
|
dest->hosts = NULL;
|
|
|
|
if (src->hosts) {
|
|
|
|
dest->hosts =
|
|
|
|
sk_OPENSSL_STRING_deep_copy(src->hosts, str_copy, str_free);
|
|
|
|
if (dest->hosts == NULL)
|
2015-01-22 03:40:55 +00:00
|
|
|
return 0;
|
2015-05-02 16:44:08 +00:00
|
|
|
dest->hostflags = src->hostflags;
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-02 16:44:08 +00:00
|
|
|
if (test_x509_verify_param_copy(email, NULL)) {
|
|
|
|
if (!X509_VERIFY_PARAM_set1_email(dest, src->email, src->emaillen))
|
2015-01-22 03:40:55 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-05-02 16:44:08 +00:00
|
|
|
if (test_x509_verify_param_copy(ip, NULL)) {
|
|
|
|
if (!X509_VERIFY_PARAM_set1_ip(dest, src->ip, src->iplen))
|
2015-01-22 03:40:55 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
2004-09-06 18:43:01 +00:00
|
|
|
|
|
|
|
int X509_VERIFY_PARAM_set1(X509_VERIFY_PARAM *to,
|
2015-01-22 03:40:55 +00:00
|
|
|
const X509_VERIFY_PARAM *from)
|
|
|
|
{
|
|
|
|
unsigned long save_flags = to->inh_flags;
|
|
|
|
int ret;
|
|
|
|
to->inh_flags |= X509_VP_FLAG_DEFAULT;
|
|
|
|
ret = X509_VERIFY_PARAM_inherit(to, from);
|
|
|
|
to->inh_flags = save_flags;
|
|
|
|
return ret;
|
|
|
|
}
|
2004-09-06 18:43:01 +00:00
|
|
|
|
2014-07-07 09:11:38 +00:00
|
|
|
static int int_x509_param_set1(char **pdest, size_t *pdestlen,
|
2015-01-22 03:40:55 +00:00
|
|
|
const char *src, size_t srclen)
|
|
|
|
{
|
|
|
|
void *tmp;
|
|
|
|
if (src) {
|
2016-05-26 20:38:31 +00:00
|
|
|
if (srclen == 0)
|
2015-01-22 03:40:55 +00:00
|
|
|
srclen = strlen(src);
|
2016-05-26 20:38:31 +00:00
|
|
|
|
|
|
|
tmp = OPENSSL_memdup(src, srclen);
|
|
|
|
if (tmp == NULL)
|
2015-01-22 03:40:55 +00:00
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
tmp = NULL;
|
|
|
|
srclen = 0;
|
|
|
|
}
|
2015-05-01 14:02:07 +00:00
|
|
|
OPENSSL_free(*pdest);
|
2015-01-22 03:40:55 +00:00
|
|
|
*pdest = tmp;
|
2016-05-26 20:38:31 +00:00
|
|
|
if (pdestlen != NULL)
|
2015-01-22 03:40:55 +00:00
|
|
|
*pdestlen = srclen;
|
|
|
|
return 1;
|
|
|
|
}
|
2012-12-05 18:35:20 +00:00
|
|
|
|
2004-09-06 18:43:01 +00:00
|
|
|
int X509_VERIFY_PARAM_set1_name(X509_VERIFY_PARAM *param, const char *name)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
2015-05-01 14:02:07 +00:00
|
|
|
OPENSSL_free(param->name);
|
Rename some BUF_xxx to OPENSSL_xxx
Rename BUF_{strdup,strlcat,strlcpy,memdup,strndup,strnlen}
to OPENSSL_{strdup,strlcat,strlcpy,memdup,strndup,strnlen}
Add #define's for the old names.
Add CRYPTO_{memdup,strndup}, called by OPENSSL_{memdup,strndup} macros.
Reviewed-by: Tim Hudson <tjh@openssl.org>
2015-12-16 21:12:24 +00:00
|
|
|
param->name = OPENSSL_strdup(name);
|
2015-01-22 03:40:55 +00:00
|
|
|
if (param->name)
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
2004-09-06 18:43:01 +00:00
|
|
|
|
|
|
|
int X509_VERIFY_PARAM_set_flags(X509_VERIFY_PARAM *param, unsigned long flags)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
|
|
|
param->flags |= flags;
|
|
|
|
if (flags & X509_V_FLAG_POLICY_MASK)
|
|
|
|
param->flags |= X509_V_FLAG_POLICY_CHECK;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int X509_VERIFY_PARAM_clear_flags(X509_VERIFY_PARAM *param,
|
|
|
|
unsigned long flags)
|
|
|
|
{
|
|
|
|
param->flags &= ~flags;
|
|
|
|
return 1;
|
|
|
|
}
|
2005-09-02 22:49:54 +00:00
|
|
|
|
2016-09-21 14:37:03 +00:00
|
|
|
unsigned long X509_VERIFY_PARAM_get_flags(X509_VERIFY_PARAM *param)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
|
|
|
return param->flags;
|
|
|
|
}
|
2005-09-02 22:49:54 +00:00
|
|
|
|
2016-12-13 16:52:22 +00:00
|
|
|
uint32_t X509_VERIFY_PARAM_get_inh_flags(const X509_VERIFY_PARAM *param)
|
|
|
|
{
|
|
|
|
return param->inh_flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
int X509_VERIFY_PARAM_set_inh_flags(X509_VERIFY_PARAM *param, uint32_t flags)
|
|
|
|
{
|
|
|
|
param->inh_flags = flags;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2004-09-06 18:43:01 +00:00
|
|
|
int X509_VERIFY_PARAM_set_purpose(X509_VERIFY_PARAM *param, int purpose)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
|
|
|
return X509_PURPOSE_set(¶m->purpose, purpose);
|
|
|
|
}
|
2004-09-06 18:43:01 +00:00
|
|
|
|
|
|
|
int X509_VERIFY_PARAM_set_trust(X509_VERIFY_PARAM *param, int trust)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
|
|
|
return X509_TRUST_set(¶m->trust, trust);
|
|
|
|
}
|
2004-09-06 18:43:01 +00:00
|
|
|
|
|
|
|
void X509_VERIFY_PARAM_set_depth(X509_VERIFY_PARAM *param, int depth)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
|
|
|
param->depth = depth;
|
|
|
|
}
|
2004-09-06 18:43:01 +00:00
|
|
|
|
2016-03-19 02:09:41 +00:00
|
|
|
void X509_VERIFY_PARAM_set_auth_level(X509_VERIFY_PARAM *param, int auth_level)
|
|
|
|
{
|
|
|
|
param->auth_level = auth_level;
|
|
|
|
}
|
|
|
|
|
2017-01-10 21:18:33 +00:00
|
|
|
time_t X509_VERIFY_PARAM_get_time(const X509_VERIFY_PARAM *param)
|
|
|
|
{
|
|
|
|
return param->check_time;
|
|
|
|
}
|
|
|
|
|
2004-09-06 18:43:01 +00:00
|
|
|
void X509_VERIFY_PARAM_set_time(X509_VERIFY_PARAM *param, time_t t)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
|
|
|
param->check_time = t;
|
|
|
|
param->flags |= X509_V_FLAG_USE_CHECK_TIME;
|
|
|
|
}
|
|
|
|
|
|
|
|
int X509_VERIFY_PARAM_add0_policy(X509_VERIFY_PARAM *param,
|
|
|
|
ASN1_OBJECT *policy)
|
|
|
|
{
|
|
|
|
if (!param->policies) {
|
|
|
|
param->policies = sk_ASN1_OBJECT_new_null();
|
|
|
|
if (!param->policies)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (!sk_ASN1_OBJECT_push(param->policies, policy))
|
|
|
|
return 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int X509_VERIFY_PARAM_set1_policies(X509_VERIFY_PARAM *param,
|
|
|
|
STACK_OF(ASN1_OBJECT) *policies)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
ASN1_OBJECT *oid, *doid;
|
2015-04-30 15:30:03 +00:00
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
if (!param)
|
|
|
|
return 0;
|
2015-04-30 15:30:03 +00:00
|
|
|
sk_ASN1_OBJECT_pop_free(param->policies, ASN1_OBJECT_free);
|
2015-01-22 03:40:55 +00:00
|
|
|
|
|
|
|
if (!policies) {
|
|
|
|
param->policies = NULL;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
param->policies = sk_ASN1_OBJECT_new_null();
|
|
|
|
if (!param->policies)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
for (i = 0; i < sk_ASN1_OBJECT_num(policies); i++) {
|
|
|
|
oid = sk_ASN1_OBJECT_value(policies, i);
|
|
|
|
doid = OBJ_dup(oid);
|
|
|
|
if (!doid)
|
|
|
|
return 0;
|
|
|
|
if (!sk_ASN1_OBJECT_push(param->policies, doid)) {
|
|
|
|
ASN1_OBJECT_free(doid);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
param->flags |= X509_V_FLAG_POLICY_CHECK;
|
|
|
|
return 1;
|
|
|
|
}
|
2004-09-06 18:43:01 +00:00
|
|
|
|
2012-12-05 18:35:20 +00:00
|
|
|
int X509_VERIFY_PARAM_set1_host(X509_VERIFY_PARAM *param,
|
2015-01-22 03:40:55 +00:00
|
|
|
const char *name, size_t namelen)
|
|
|
|
{
|
2015-05-02 16:44:08 +00:00
|
|
|
return int_x509_param_set_hosts(param, SET_HOST, name, namelen);
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
2014-06-22 05:38:57 +00:00
|
|
|
|
|
|
|
int X509_VERIFY_PARAM_add1_host(X509_VERIFY_PARAM *param,
|
2015-01-22 03:40:55 +00:00
|
|
|
const char *name, size_t namelen)
|
|
|
|
{
|
2015-05-02 16:44:08 +00:00
|
|
|
return int_x509_param_set_hosts(param, ADD_HOST, name, namelen);
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
2012-12-05 18:35:20 +00:00
|
|
|
|
2014-05-21 09:57:44 +00:00
|
|
|
void X509_VERIFY_PARAM_set_hostflags(X509_VERIFY_PARAM *param,
|
2015-01-22 03:40:55 +00:00
|
|
|
unsigned int flags)
|
|
|
|
{
|
2015-05-02 16:44:08 +00:00
|
|
|
param->hostflags = flags;
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
2014-05-21 09:57:44 +00:00
|
|
|
|
2018-05-02 10:32:39 +00:00
|
|
|
unsigned int X509_VERIFY_PARAM_get_hostflags(const X509_VERIFY_PARAM *param)
|
2018-04-30 14:59:51 +00:00
|
|
|
{
|
|
|
|
return param->hostflags;
|
|
|
|
}
|
|
|
|
|
2016-09-21 14:37:03 +00:00
|
|
|
char *X509_VERIFY_PARAM_get0_peername(X509_VERIFY_PARAM *param)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
2015-05-02 16:44:08 +00:00
|
|
|
return param->peername;
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
2014-07-05 15:44:30 +00:00
|
|
|
|
2015-12-29 18:28:28 +00:00
|
|
|
/*
|
|
|
|
* Move peername from one param structure to another, freeing any name present
|
|
|
|
* at the target. If the source is a NULL parameter structure, free and zero
|
|
|
|
* the target peername.
|
|
|
|
*/
|
|
|
|
void X509_VERIFY_PARAM_move_peername(X509_VERIFY_PARAM *to,
|
|
|
|
X509_VERIFY_PARAM *from)
|
|
|
|
{
|
|
|
|
char *peername = (from != NULL) ? from->peername : NULL;
|
|
|
|
|
|
|
|
if (to->peername != peername) {
|
|
|
|
OPENSSL_free(to->peername);
|
|
|
|
to->peername = peername;
|
|
|
|
}
|
|
|
|
if (from)
|
|
|
|
from->peername = NULL;
|
|
|
|
}
|
|
|
|
|
2012-12-05 18:35:20 +00:00
|
|
|
int X509_VERIFY_PARAM_set1_email(X509_VERIFY_PARAM *param,
|
2015-01-22 03:40:55 +00:00
|
|
|
const char *email, size_t emaillen)
|
|
|
|
{
|
2015-05-02 16:44:08 +00:00
|
|
|
return int_x509_param_set1(¶m->email, ¶m->emaillen,
|
2015-01-22 03:40:55 +00:00
|
|
|
email, emaillen);
|
|
|
|
}
|
2012-12-05 18:35:20 +00:00
|
|
|
|
|
|
|
int X509_VERIFY_PARAM_set1_ip(X509_VERIFY_PARAM *param,
|
2015-01-22 03:40:55 +00:00
|
|
|
const unsigned char *ip, size_t iplen)
|
|
|
|
{
|
|
|
|
if (iplen != 0 && iplen != 4 && iplen != 16)
|
|
|
|
return 0;
|
2015-05-02 16:44:08 +00:00
|
|
|
return int_x509_param_set1((char **)¶m->ip, ¶m->iplen,
|
2015-01-22 03:40:55 +00:00
|
|
|
(char *)ip, iplen);
|
|
|
|
}
|
2012-12-05 18:35:20 +00:00
|
|
|
|
|
|
|
int X509_VERIFY_PARAM_set1_ip_asc(X509_VERIFY_PARAM *param, const char *ipasc)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
|
|
|
unsigned char ipout[16];
|
|
|
|
size_t iplen;
|
2014-07-07 09:11:38 +00:00
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
iplen = (size_t)a2i_ipadd(ipout, ipasc);
|
|
|
|
if (iplen == 0)
|
|
|
|
return 0;
|
|
|
|
return X509_VERIFY_PARAM_set1_ip(param, ipout, iplen);
|
|
|
|
}
|
2012-12-05 18:35:20 +00:00
|
|
|
|
2004-09-06 18:43:01 +00:00
|
|
|
int X509_VERIFY_PARAM_get_depth(const X509_VERIFY_PARAM *param)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
|
|
|
return param->depth;
|
|
|
|
}
|
2004-09-06 18:43:01 +00:00
|
|
|
|
2016-03-19 02:09:41 +00:00
|
|
|
int X509_VERIFY_PARAM_get_auth_level(const X509_VERIFY_PARAM *param)
|
|
|
|
{
|
|
|
|
return param->auth_level;
|
|
|
|
}
|
|
|
|
|
2010-02-25 00:08:23 +00:00
|
|
|
const char *X509_VERIFY_PARAM_get0_name(const X509_VERIFY_PARAM *param)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
|
|
|
return param->name;
|
|
|
|
}
|
2010-02-25 00:08:23 +00:00
|
|
|
|
2015-05-02 16:44:08 +00:00
|
|
|
#define vpm_empty_id NULL, 0U, NULL, NULL, 0, NULL, 0
|
2013-12-11 14:28:57 +00:00
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
/*
|
|
|
|
* Default verify parameters: these are used for various applications and can
|
|
|
|
* be overridden by the user specified table. NB: the 'name' field *must* be
|
|
|
|
* in alphabetical order because it will be searched using OBJ_search.
|
2004-09-06 18:43:01 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
static const X509_VERIFY_PARAM default_table[] = {
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
|
|
|
"default", /* X509 default parameters */
|
|
|
|
0, /* Check time */
|
|
|
|
0, /* internal flags */
|
2016-01-28 08:01:45 +00:00
|
|
|
X509_V_FLAG_TRUSTED_FIRST, /* flags */
|
2015-01-22 03:40:55 +00:00
|
|
|
0, /* purpose */
|
|
|
|
0, /* trust */
|
|
|
|
100, /* depth */
|
2016-03-19 02:09:41 +00:00
|
|
|
-1, /* auth_level */
|
2015-01-22 03:40:55 +00:00
|
|
|
NULL, /* policies */
|
|
|
|
vpm_empty_id},
|
|
|
|
{
|
|
|
|
"pkcs7", /* S/MIME sign parameters */
|
|
|
|
0, /* Check time */
|
|
|
|
0, /* internal flags */
|
|
|
|
0, /* flags */
|
|
|
|
X509_PURPOSE_SMIME_SIGN, /* purpose */
|
|
|
|
X509_TRUST_EMAIL, /* trust */
|
|
|
|
-1, /* depth */
|
2016-03-19 02:09:41 +00:00
|
|
|
-1, /* auth_level */
|
2015-01-22 03:40:55 +00:00
|
|
|
NULL, /* policies */
|
|
|
|
vpm_empty_id},
|
|
|
|
{
|
|
|
|
"smime_sign", /* S/MIME sign parameters */
|
|
|
|
0, /* Check time */
|
|
|
|
0, /* internal flags */
|
|
|
|
0, /* flags */
|
|
|
|
X509_PURPOSE_SMIME_SIGN, /* purpose */
|
|
|
|
X509_TRUST_EMAIL, /* trust */
|
|
|
|
-1, /* depth */
|
2016-03-19 02:09:41 +00:00
|
|
|
-1, /* auth_level */
|
2015-01-22 03:40:55 +00:00
|
|
|
NULL, /* policies */
|
|
|
|
vpm_empty_id},
|
|
|
|
{
|
|
|
|
"ssl_client", /* SSL/TLS client parameters */
|
|
|
|
0, /* Check time */
|
|
|
|
0, /* internal flags */
|
|
|
|
0, /* flags */
|
|
|
|
X509_PURPOSE_SSL_CLIENT, /* purpose */
|
|
|
|
X509_TRUST_SSL_CLIENT, /* trust */
|
|
|
|
-1, /* depth */
|
2016-03-19 02:09:41 +00:00
|
|
|
-1, /* auth_level */
|
2015-01-22 03:40:55 +00:00
|
|
|
NULL, /* policies */
|
|
|
|
vpm_empty_id},
|
|
|
|
{
|
|
|
|
"ssl_server", /* SSL/TLS server parameters */
|
|
|
|
0, /* Check time */
|
|
|
|
0, /* internal flags */
|
|
|
|
0, /* flags */
|
|
|
|
X509_PURPOSE_SSL_SERVER, /* purpose */
|
|
|
|
X509_TRUST_SSL_SERVER, /* trust */
|
|
|
|
-1, /* depth */
|
2016-03-19 02:09:41 +00:00
|
|
|
-1, /* auth_level */
|
2015-01-22 03:40:55 +00:00
|
|
|
NULL, /* policies */
|
|
|
|
vpm_empty_id}
|
|
|
|
};
|
2004-09-06 18:43:01 +00:00
|
|
|
|
|
|
|
static STACK_OF(X509_VERIFY_PARAM) *param_table = NULL;
|
|
|
|
|
2008-10-12 14:32:47 +00:00
|
|
|
static int table_cmp(const X509_VERIFY_PARAM *a, const X509_VERIFY_PARAM *b)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
|
|
|
return strcmp(a->name, b->name);
|
|
|
|
}
|
2008-10-12 14:32:47 +00:00
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
DECLARE_OBJ_BSEARCH_CMP_FN(X509_VERIFY_PARAM, X509_VERIFY_PARAM, table);
|
|
|
|
IMPLEMENT_OBJ_BSEARCH_CMP_FN(X509_VERIFY_PARAM, X509_VERIFY_PARAM, table);
|
2008-10-12 14:32:47 +00:00
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
static int param_cmp(const X509_VERIFY_PARAM *const *a,
|
|
|
|
const X509_VERIFY_PARAM *const *b)
|
|
|
|
{
|
|
|
|
return strcmp((*a)->name, (*b)->name);
|
|
|
|
}
|
2004-09-06 18:43:01 +00:00
|
|
|
|
|
|
|
int X509_VERIFY_PARAM_add0_table(X509_VERIFY_PARAM *param)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
|
|
|
int idx;
|
|
|
|
X509_VERIFY_PARAM *ptmp;
|
2015-10-30 11:12:26 +00:00
|
|
|
if (param_table == NULL) {
|
2015-01-22 03:40:55 +00:00
|
|
|
param_table = sk_X509_VERIFY_PARAM_new(param_cmp);
|
2015-10-30 11:12:26 +00:00
|
|
|
if (param_table == NULL)
|
2015-01-22 03:40:55 +00:00
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
idx = sk_X509_VERIFY_PARAM_find(param_table, param);
|
2018-08-05 14:50:41 +00:00
|
|
|
if (idx >= 0) {
|
|
|
|
ptmp = sk_X509_VERIFY_PARAM_delete(param_table, idx);
|
2015-01-22 03:40:55 +00:00
|
|
|
X509_VERIFY_PARAM_free(ptmp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!sk_X509_VERIFY_PARAM_push(param_table, param))
|
|
|
|
return 0;
|
|
|
|
return 1;
|
|
|
|
}
|
2004-09-06 18:43:01 +00:00
|
|
|
|
2010-02-25 00:08:23 +00:00
|
|
|
int X509_VERIFY_PARAM_get_count(void)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
2015-05-02 17:30:00 +00:00
|
|
|
int num = OSSL_NELEM(default_table);
|
2015-01-22 03:40:55 +00:00
|
|
|
if (param_table)
|
|
|
|
num += sk_X509_VERIFY_PARAM_num(param_table);
|
|
|
|
return num;
|
|
|
|
}
|
2010-02-25 00:08:23 +00:00
|
|
|
|
|
|
|
const X509_VERIFY_PARAM *X509_VERIFY_PARAM_get0(int id)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
2015-05-02 17:30:00 +00:00
|
|
|
int num = OSSL_NELEM(default_table);
|
2015-01-22 03:40:55 +00:00
|
|
|
if (id < num)
|
|
|
|
return default_table + id;
|
|
|
|
return sk_X509_VERIFY_PARAM_value(param_table, id - num);
|
|
|
|
}
|
2010-02-25 00:08:23 +00:00
|
|
|
|
2004-09-06 18:43:01 +00:00
|
|
|
const X509_VERIFY_PARAM *X509_VERIFY_PARAM_lookup(const char *name)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
|
|
|
int idx;
|
|
|
|
X509_VERIFY_PARAM pm;
|
|
|
|
|
|
|
|
pm.name = (char *)name;
|
2018-08-05 14:50:41 +00:00
|
|
|
if (param_table != NULL) {
|
2015-01-22 03:40:55 +00:00
|
|
|
idx = sk_X509_VERIFY_PARAM_find(param_table, &pm);
|
2018-08-05 14:50:41 +00:00
|
|
|
if (idx >= 0)
|
2015-01-22 03:40:55 +00:00
|
|
|
return sk_X509_VERIFY_PARAM_value(param_table, idx);
|
|
|
|
}
|
2015-05-02 17:30:00 +00:00
|
|
|
return OBJ_bsearch_table(&pm, default_table, OSSL_NELEM(default_table));
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
2004-09-06 18:43:01 +00:00
|
|
|
|
|
|
|
void X509_VERIFY_PARAM_table_cleanup(void)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
2015-04-30 21:33:59 +00:00
|
|
|
sk_X509_VERIFY_PARAM_pop_free(param_table, X509_VERIFY_PARAM_free);
|
2015-01-22 03:40:55 +00:00
|
|
|
param_table = NULL;
|
|
|
|
}
|