2016-05-17 18:52:22 +00:00
|
|
|
/*
|
2018-05-01 12:34:30 +00:00
|
|
|
* Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
|
1998-12-21 10:52:47 +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
|
1998-12-21 10:52:47 +00:00
|
|
|
*/
|
|
|
|
|
2017-08-23 23:05:07 +00:00
|
|
|
#include "e_os.h"
|
|
|
|
#include "internal/cryptlib.h"
|
1998-12-21 10:52:47 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <errno.h>
|
2017-08-25 12:51:45 +00:00
|
|
|
#include <sys/types.h>
|
1998-12-21 10:52:47 +00:00
|
|
|
|
2005-11-03 16:22:40 +00:00
|
|
|
#ifndef OPENSSL_NO_POSIX_IO
|
1999-09-11 17:54:18 +00:00
|
|
|
# include <sys/stat.h>
|
|
|
|
#endif
|
|
|
|
|
1999-04-23 22:13:45 +00:00
|
|
|
#include <openssl/x509.h>
|
2015-08-31 20:30:13 +00:00
|
|
|
#include "internal/x509_int.h"
|
2016-01-06 02:54:18 +00:00
|
|
|
#include "x509_lcl.h"
|
1998-12-21 10:52:47 +00:00
|
|
|
|
2016-01-06 02:54:18 +00:00
|
|
|
struct lookup_dir_hashes_st {
|
2015-01-22 03:40:55 +00:00
|
|
|
unsigned long hash;
|
|
|
|
int suffix;
|
2016-01-06 02:54:18 +00:00
|
|
|
};
|
2006-09-17 17:16:28 +00:00
|
|
|
|
2016-01-06 02:54:18 +00:00
|
|
|
struct lookup_dir_entry_st {
|
2015-01-22 03:40:55 +00:00
|
|
|
char *dir;
|
|
|
|
int dir_type;
|
|
|
|
STACK_OF(BY_DIR_HASH) *hashes;
|
2016-01-06 02:54:18 +00:00
|
|
|
};
|
2006-09-17 17:16:28 +00:00
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
typedef struct lookup_dir_st {
|
|
|
|
BUF_MEM *buffer;
|
|
|
|
STACK_OF(BY_DIR_ENTRY) *dirs;
|
2016-03-09 09:52:39 +00:00
|
|
|
CRYPTO_RWLOCK *lock;
|
2015-01-22 03:40:55 +00:00
|
|
|
} BY_DIR;
|
1998-12-21 10:52:47 +00:00
|
|
|
|
1999-05-09 10:12:10 +00:00
|
|
|
static int dir_ctrl(X509_LOOKUP *ctx, int cmd, const char *argp, long argl,
|
2015-01-22 03:40:55 +00:00
|
|
|
char **ret);
|
1998-12-21 10:52:47 +00:00
|
|
|
static int new_dir(X509_LOOKUP *lu);
|
|
|
|
static void free_dir(X509_LOOKUP *lu);
|
2015-01-22 03:40:55 +00:00
|
|
|
static int add_cert_dir(BY_DIR *ctx, const char *dir, int type);
|
2016-07-25 15:46:05 +00:00
|
|
|
static int get_cert_by_subject(X509_LOOKUP *xl, X509_LOOKUP_TYPE type,
|
|
|
|
X509_NAME *name, X509_OBJECT *ret);
|
2015-09-05 12:32:58 +00:00
|
|
|
static X509_LOOKUP_METHOD x509_dir_lookup = {
|
2015-01-22 03:40:55 +00:00
|
|
|
"Load certs from files in a directory",
|
2018-03-28 20:32:31 +00:00
|
|
|
new_dir, /* new_item */
|
2015-01-22 03:40:55 +00:00
|
|
|
free_dir, /* free */
|
|
|
|
NULL, /* init */
|
|
|
|
NULL, /* shutdown */
|
|
|
|
dir_ctrl, /* ctrl */
|
|
|
|
get_cert_by_subject, /* get_by_subject */
|
|
|
|
NULL, /* get_by_issuer_serial */
|
|
|
|
NULL, /* get_by_fingerprint */
|
|
|
|
NULL, /* get_by_alias */
|
|
|
|
};
|
1998-12-21 10:52:47 +00:00
|
|
|
|
1999-04-19 21:31:43 +00:00
|
|
|
X509_LOOKUP_METHOD *X509_LOOKUP_hash_dir(void)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
2017-10-17 14:04:09 +00:00
|
|
|
return &x509_dir_lookup;
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
1998-12-21 10:52:47 +00:00
|
|
|
|
1999-05-09 10:12:10 +00:00
|
|
|
static int dir_ctrl(X509_LOOKUP *ctx, int cmd, const char *argp, long argl,
|
2015-01-22 03:40:55 +00:00
|
|
|
char **retp)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
2018-03-28 20:32:31 +00:00
|
|
|
BY_DIR *ld = (BY_DIR *)ctx->method_data;
|
2015-01-22 03:40:55 +00:00
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case X509_L_ADD_DIR:
|
|
|
|
if (argl == X509_FILETYPE_DEFAULT) {
|
2018-03-28 20:32:31 +00:00
|
|
|
const char *dir = getenv(X509_get_default_cert_dir_env());
|
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
if (dir)
|
|
|
|
ret = add_cert_dir(ld, dir, X509_FILETYPE_PEM);
|
|
|
|
else
|
|
|
|
ret = add_cert_dir(ld, X509_get_default_cert_dir(),
|
|
|
|
X509_FILETYPE_PEM);
|
|
|
|
if (!ret) {
|
|
|
|
X509err(X509_F_DIR_CTRL, X509_R_LOADING_CERT_DIR);
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
ret = add_cert_dir(ld, argp, (int)argl);
|
|
|
|
break;
|
|
|
|
}
|
2017-10-17 14:04:09 +00:00
|
|
|
return ret;
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
1998-12-21 10:52:47 +00:00
|
|
|
|
1999-04-19 21:31:43 +00:00
|
|
|
static int new_dir(X509_LOOKUP *lu)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
2018-03-28 20:32:31 +00:00
|
|
|
BY_DIR *a = OPENSSL_malloc(sizeof(*a));
|
2015-01-22 03:40:55 +00:00
|
|
|
|
2018-03-28 20:32:31 +00:00
|
|
|
if (a == NULL) {
|
|
|
|
X509err(X509_F_NEW_DIR, ERR_R_MALLOC_FAILURE);
|
2016-03-09 09:52:39 +00:00
|
|
|
return 0;
|
2018-03-28 20:32:31 +00:00
|
|
|
}
|
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
if ((a->buffer = BUF_MEM_new()) == NULL) {
|
2018-03-28 20:32:31 +00:00
|
|
|
X509err(X509_F_NEW_DIR, ERR_R_MALLOC_FAILURE);
|
|
|
|
goto err;
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
|
|
|
a->dirs = NULL;
|
2016-03-09 09:52:39 +00:00
|
|
|
a->lock = CRYPTO_THREAD_lock_new();
|
|
|
|
if (a->lock == NULL) {
|
|
|
|
BUF_MEM_free(a->buffer);
|
2018-03-28 20:32:31 +00:00
|
|
|
X509err(X509_F_NEW_DIR, ERR_R_MALLOC_FAILURE);
|
|
|
|
goto err;
|
2016-03-09 09:52:39 +00:00
|
|
|
}
|
2018-02-09 18:23:18 +00:00
|
|
|
lu->method_data = a;
|
2016-03-09 09:52:39 +00:00
|
|
|
return 1;
|
2018-03-28 20:32:31 +00:00
|
|
|
|
|
|
|
err:
|
|
|
|
OPENSSL_free(a);
|
|
|
|
return 0;
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
1998-12-21 10:52:47 +00:00
|
|
|
|
2006-09-17 17:16:28 +00:00
|
|
|
static void by_dir_hash_free(BY_DIR_HASH *hash)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
|
|
|
OPENSSL_free(hash);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int by_dir_hash_cmp(const BY_DIR_HASH *const *a,
|
|
|
|
const BY_DIR_HASH *const *b)
|
|
|
|
{
|
|
|
|
if ((*a)->hash > (*b)->hash)
|
|
|
|
return 1;
|
|
|
|
if ((*a)->hash < (*b)->hash)
|
|
|
|
return -1;
|
|
|
|
return 0;
|
|
|
|
}
|
2006-09-17 17:16:28 +00:00
|
|
|
|
|
|
|
static void by_dir_entry_free(BY_DIR_ENTRY *ent)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
2015-05-01 14:02:07 +00:00
|
|
|
OPENSSL_free(ent->dir);
|
2015-05-01 18:37:16 +00:00
|
|
|
sk_BY_DIR_HASH_pop_free(ent->hashes, by_dir_hash_free);
|
2015-01-22 03:40:55 +00:00
|
|
|
OPENSSL_free(ent);
|
|
|
|
}
|
2006-09-17 17:16:28 +00:00
|
|
|
|
1999-04-19 21:31:43 +00:00
|
|
|
static void free_dir(X509_LOOKUP *lu)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
2018-03-28 20:32:31 +00:00
|
|
|
BY_DIR *a = (BY_DIR *)lu->method_data;
|
1998-12-21 10:52:47 +00:00
|
|
|
|
2015-05-01 18:37:16 +00:00
|
|
|
sk_BY_DIR_ENTRY_pop_free(a->dirs, by_dir_entry_free);
|
|
|
|
BUF_MEM_free(a->buffer);
|
2016-03-09 09:52:39 +00:00
|
|
|
CRYPTO_THREAD_lock_free(a->lock);
|
2015-01-22 03:40:55 +00:00
|
|
|
OPENSSL_free(a);
|
|
|
|
}
|
1998-12-21 10:52:47 +00:00
|
|
|
|
1999-04-19 21:31:43 +00:00
|
|
|
static int add_cert_dir(BY_DIR *ctx, const char *dir, int type)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
2017-09-14 23:05:43 +00:00
|
|
|
int j;
|
|
|
|
size_t len;
|
2017-09-11 23:13:12 +00:00
|
|
|
const char *s, *ss, *p;
|
2015-01-22 03:40:55 +00:00
|
|
|
|
|
|
|
if (dir == NULL || !*dir) {
|
|
|
|
X509err(X509_F_ADD_CERT_DIR, X509_R_INVALID_DIRECTORY);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
s = dir;
|
|
|
|
p = s;
|
|
|
|
do {
|
|
|
|
if ((*p == LIST_SEPARATOR_CHAR) || (*p == '\0')) {
|
|
|
|
BY_DIR_ENTRY *ent;
|
2018-03-28 20:32:31 +00:00
|
|
|
|
2017-09-11 23:13:12 +00:00
|
|
|
ss = s;
|
2015-01-22 03:40:55 +00:00
|
|
|
s = p + 1;
|
2017-09-14 23:05:43 +00:00
|
|
|
len = p - ss;
|
2015-01-22 03:40:55 +00:00
|
|
|
if (len == 0)
|
|
|
|
continue;
|
|
|
|
for (j = 0; j < sk_BY_DIR_ENTRY_num(ctx->dirs); j++) {
|
|
|
|
ent = sk_BY_DIR_ENTRY_value(ctx->dirs, j);
|
2017-09-14 21:52:32 +00:00
|
|
|
if (strlen(ent->dir) == len && strncmp(ent->dir, ss, len) == 0)
|
2015-01-22 03:40:55 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (j < sk_BY_DIR_ENTRY_num(ctx->dirs))
|
|
|
|
continue;
|
|
|
|
if (ctx->dirs == NULL) {
|
|
|
|
ctx->dirs = sk_BY_DIR_ENTRY_new_null();
|
|
|
|
if (!ctx->dirs) {
|
|
|
|
X509err(X509_F_ADD_CERT_DIR, ERR_R_MALLOC_FAILURE);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2015-05-02 03:10:31 +00:00
|
|
|
ent = OPENSSL_malloc(sizeof(*ent));
|
2018-03-28 20:32:31 +00:00
|
|
|
if (ent == NULL) {
|
|
|
|
X509err(X509_F_ADD_CERT_DIR, ERR_R_MALLOC_FAILURE);
|
2015-01-22 03:40:55 +00:00
|
|
|
return 0;
|
2018-03-28 20:32:31 +00:00
|
|
|
}
|
2015-01-22 03:40:55 +00:00
|
|
|
ent->dir_type = type;
|
|
|
|
ent->hashes = sk_BY_DIR_HASH_new(by_dir_hash_cmp);
|
2017-09-14 21:52:32 +00:00
|
|
|
ent->dir = OPENSSL_strndup(ss, len);
|
2015-10-30 11:12:26 +00:00
|
|
|
if (ent->dir == NULL || ent->hashes == NULL) {
|
2015-01-22 03:40:55 +00:00
|
|
|
by_dir_entry_free(ent);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (!sk_BY_DIR_ENTRY_push(ctx->dirs, ent)) {
|
|
|
|
by_dir_entry_free(ent);
|
2018-03-28 20:32:31 +00:00
|
|
|
X509err(X509_F_ADD_CERT_DIR, ERR_R_MALLOC_FAILURE);
|
2015-01-22 03:40:55 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} while (*p++ != '\0');
|
|
|
|
return 1;
|
|
|
|
}
|
1998-12-21 10:52:47 +00:00
|
|
|
|
2015-05-26 19:42:01 +00:00
|
|
|
static int get_cert_by_subject(X509_LOOKUP *xl, X509_LOOKUP_TYPE type,
|
|
|
|
X509_NAME *name, X509_OBJECT *ret)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
|
|
|
BY_DIR *ctx;
|
|
|
|
union {
|
2015-09-16 17:40:26 +00:00
|
|
|
X509 st_x509;
|
2015-09-15 23:24:43 +00:00
|
|
|
X509_CRL crl;
|
2015-01-22 03:40:55 +00:00
|
|
|
} data;
|
|
|
|
int ok = 0;
|
|
|
|
int i, j, k;
|
|
|
|
unsigned long h;
|
|
|
|
BUF_MEM *b = NULL;
|
|
|
|
X509_OBJECT stmp, *tmp;
|
|
|
|
const char *postfix = "";
|
|
|
|
|
|
|
|
if (name == NULL)
|
2017-10-17 14:04:09 +00:00
|
|
|
return 0;
|
2015-01-22 03:40:55 +00:00
|
|
|
|
|
|
|
stmp.type = type;
|
|
|
|
if (type == X509_LU_X509) {
|
2015-09-16 17:40:26 +00:00
|
|
|
data.st_x509.cert_info.subject = name;
|
|
|
|
stmp.data.x509 = &data.st_x509;
|
2015-01-22 03:40:55 +00:00
|
|
|
postfix = "";
|
|
|
|
} else if (type == X509_LU_CRL) {
|
2015-09-15 23:24:43 +00:00
|
|
|
data.crl.crl.issuer = name;
|
|
|
|
stmp.data.crl = &data.crl;
|
2015-01-22 03:40:55 +00:00
|
|
|
postfix = "r";
|
|
|
|
} else {
|
|
|
|
X509err(X509_F_GET_CERT_BY_SUBJECT, X509_R_WRONG_LOOKUP_TYPE);
|
|
|
|
goto finish;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((b = BUF_MEM_new()) == NULL) {
|
|
|
|
X509err(X509_F_GET_CERT_BY_SUBJECT, ERR_R_BUF_LIB);
|
|
|
|
goto finish;
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx = (BY_DIR *)xl->method_data;
|
|
|
|
|
|
|
|
h = X509_NAME_hash(name);
|
|
|
|
for (i = 0; i < sk_BY_DIR_ENTRY_num(ctx->dirs); i++) {
|
|
|
|
BY_DIR_ENTRY *ent;
|
|
|
|
int idx;
|
|
|
|
BY_DIR_HASH htmp, *hent;
|
2018-03-28 20:32:31 +00:00
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
ent = sk_BY_DIR_ENTRY_value(ctx->dirs, i);
|
|
|
|
j = strlen(ent->dir) + 1 + 8 + 6 + 1 + 1;
|
|
|
|
if (!BUF_MEM_grow(b, j)) {
|
|
|
|
X509err(X509_F_GET_CERT_BY_SUBJECT, ERR_R_MALLOC_FAILURE);
|
|
|
|
goto finish;
|
|
|
|
}
|
|
|
|
if (type == X509_LU_CRL && ent->hashes) {
|
|
|
|
htmp.hash = h;
|
2016-03-09 09:52:39 +00:00
|
|
|
CRYPTO_THREAD_read_lock(ctx->lock);
|
2015-01-22 03:40:55 +00:00
|
|
|
idx = sk_BY_DIR_HASH_find(ent->hashes, &htmp);
|
|
|
|
if (idx >= 0) {
|
|
|
|
hent = sk_BY_DIR_HASH_value(ent->hashes, idx);
|
|
|
|
k = hent->suffix;
|
|
|
|
} else {
|
|
|
|
hent = NULL;
|
|
|
|
k = 0;
|
|
|
|
}
|
2016-03-09 09:52:39 +00:00
|
|
|
CRYPTO_THREAD_unlock(ctx->lock);
|
2015-01-22 03:40:55 +00:00
|
|
|
} else {
|
|
|
|
k = 0;
|
|
|
|
hent = NULL;
|
|
|
|
}
|
|
|
|
for (;;) {
|
|
|
|
char c = '/';
|
Adding a slash between the directoryt and the file is a problem with
VMS. The C RTL can handle it well if the "directory" is a logical
name with no colon, therefore ending being 'logname/file'. However,
if the given logical names actually has a colon, or if you use a full
VMS-syntax directory, you end up with 'logname:/file' or
'dev:[dir1.dir2]/file', and that isn't handled in any good way.
So, on VMS, we need to check if the directory string ends with a
separator (one of ':', ']' or '>' (< and > can be used instead [ and
])), and handle that by not inserting anything between the directory
spec and the file name. In all other cases, it's assumed the
directory spec is a logical name, so we need to place a colon between
it and the file.
Notified by Kevin Greaney <kevin.greaney@hp.com>.
2004-01-10 18:04:38 +00:00
|
|
|
#ifdef OPENSSL_SYS_VMS
|
2015-01-22 03:40:55 +00:00
|
|
|
c = ent->dir[strlen(ent->dir) - 1];
|
|
|
|
if (c != ':' && c != '>' && c != ']') {
|
|
|
|
/*
|
|
|
|
* If no separator is present, we assume the directory
|
|
|
|
* specifier is a logical name, and add a colon. We really
|
|
|
|
* should use better VMS routines for merging things like
|
|
|
|
* this, but this will do for now... -- Richard Levitte
|
|
|
|
*/
|
|
|
|
c = ':';
|
|
|
|
} else {
|
|
|
|
c = '\0';
|
|
|
|
}
|
Adding a slash between the directoryt and the file is a problem with
VMS. The C RTL can handle it well if the "directory" is a logical
name with no colon, therefore ending being 'logname/file'. However,
if the given logical names actually has a colon, or if you use a full
VMS-syntax directory, you end up with 'logname:/file' or
'dev:[dir1.dir2]/file', and that isn't handled in any good way.
So, on VMS, we need to check if the directory string ends with a
separator (one of ':', ']' or '>' (< and > can be used instead [ and
])), and handle that by not inserting anything between the directory
spec and the file name. In all other cases, it's assumed the
directory spec is a logical name, so we need to place a colon between
it and the file.
Notified by Kevin Greaney <kevin.greaney@hp.com>.
2004-01-10 18:04:38 +00:00
|
|
|
#endif
|
2015-01-22 03:40:55 +00:00
|
|
|
if (c == '\0') {
|
|
|
|
/*
|
|
|
|
* This is special. When c == '\0', no directory separator
|
|
|
|
* should be added.
|
|
|
|
*/
|
|
|
|
BIO_snprintf(b->data, b->max,
|
|
|
|
"%s%08lx.%s%d", ent->dir, h, postfix, k);
|
|
|
|
} else {
|
2017-07-06 04:56:20 +00:00
|
|
|
BIO_snprintf(b->data, b->max,
|
|
|
|
"%s%c%08lx.%s%d", ent->dir, c, h, postfix, k);
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
2005-11-03 16:22:40 +00:00
|
|
|
#ifndef OPENSSL_NO_POSIX_IO
|
2015-01-22 03:40:55 +00:00
|
|
|
# ifdef _WIN32
|
|
|
|
# define stat _stat
|
|
|
|
# endif
|
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
if (stat(b->data, &st) < 0)
|
|
|
|
break;
|
|
|
|
}
|
2005-11-03 16:22:40 +00:00
|
|
|
#endif
|
2015-01-22 03:40:55 +00:00
|
|
|
/* found one. */
|
|
|
|
if (type == X509_LU_X509) {
|
|
|
|
if ((X509_load_cert_file(xl, b->data, ent->dir_type)) == 0)
|
|
|
|
break;
|
|
|
|
} else if (type == X509_LU_CRL) {
|
|
|
|
if ((X509_load_crl_file(xl, b->data, ent->dir_type)) == 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* else case will caught higher up */
|
|
|
|
k++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* we have added it to the cache so now pull it out again
|
|
|
|
*/
|
2016-03-09 09:52:39 +00:00
|
|
|
CRYPTO_THREAD_write_lock(ctx->lock);
|
2015-01-22 03:40:55 +00:00
|
|
|
j = sk_X509_OBJECT_find(xl->store_ctx->objs, &stmp);
|
|
|
|
if (j != -1)
|
|
|
|
tmp = sk_X509_OBJECT_value(xl->store_ctx->objs, j);
|
|
|
|
else
|
|
|
|
tmp = NULL;
|
2016-03-09 09:52:39 +00:00
|
|
|
CRYPTO_THREAD_unlock(ctx->lock);
|
2015-01-22 03:40:55 +00:00
|
|
|
|
|
|
|
/* If a CRL, update the last file suffix added for this */
|
|
|
|
|
|
|
|
if (type == X509_LU_CRL) {
|
2016-03-09 09:52:39 +00:00
|
|
|
CRYPTO_THREAD_write_lock(ctx->lock);
|
2015-01-22 03:40:55 +00:00
|
|
|
/*
|
|
|
|
* Look for entry again in case another thread added an entry
|
|
|
|
* first.
|
|
|
|
*/
|
|
|
|
if (!hent) {
|
|
|
|
htmp.hash = h;
|
|
|
|
idx = sk_BY_DIR_HASH_find(ent->hashes, &htmp);
|
|
|
|
if (idx >= 0)
|
|
|
|
hent = sk_BY_DIR_HASH_value(ent->hashes, idx);
|
|
|
|
}
|
2018-03-28 20:32:31 +00:00
|
|
|
if (hent == NULL) {
|
2015-05-02 03:10:31 +00:00
|
|
|
hent = OPENSSL_malloc(sizeof(*hent));
|
2015-01-22 03:40:55 +00:00
|
|
|
if (hent == NULL) {
|
2016-03-09 09:52:39 +00:00
|
|
|
CRYPTO_THREAD_unlock(ctx->lock);
|
2015-01-22 03:40:55 +00:00
|
|
|
X509err(X509_F_GET_CERT_BY_SUBJECT, ERR_R_MALLOC_FAILURE);
|
|
|
|
ok = 0;
|
|
|
|
goto finish;
|
|
|
|
}
|
|
|
|
hent->hash = h;
|
|
|
|
hent->suffix = k;
|
|
|
|
if (!sk_BY_DIR_HASH_push(ent->hashes, hent)) {
|
2016-03-09 09:52:39 +00:00
|
|
|
CRYPTO_THREAD_unlock(ctx->lock);
|
2015-01-22 03:40:55 +00:00
|
|
|
OPENSSL_free(hent);
|
2018-03-28 20:32:31 +00:00
|
|
|
X509err(X509_F_GET_CERT_BY_SUBJECT, ERR_R_MALLOC_FAILURE);
|
2015-01-22 03:40:55 +00:00
|
|
|
ok = 0;
|
|
|
|
goto finish;
|
|
|
|
}
|
2016-03-09 09:52:39 +00:00
|
|
|
} else if (hent->suffix < k) {
|
2015-01-22 03:40:55 +00:00
|
|
|
hent->suffix = k;
|
2016-03-09 09:52:39 +00:00
|
|
|
}
|
2015-01-22 03:40:55 +00:00
|
|
|
|
2016-03-09 09:52:39 +00:00
|
|
|
CRYPTO_THREAD_unlock(ctx->lock);
|
2015-01-22 03:40:55 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tmp != NULL) {
|
|
|
|
ok = 1;
|
|
|
|
ret->type = tmp->type;
|
|
|
|
memcpy(&ret->data, &tmp->data, sizeof(ret->data));
|
2017-04-20 19:33:42 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Clear any errors that might have been raised processing empty
|
|
|
|
* or malformed files.
|
|
|
|
*/
|
|
|
|
ERR_clear_error();
|
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
goto finish;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
finish:
|
2015-05-01 18:37:16 +00:00
|
|
|
BUF_MEM_free(b);
|
2017-10-17 14:04:09 +00:00
|
|
|
return ok;
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|