|
@@ -17,7 +17,6 @@ typedef struct cached_store_st {
|
|
char *uri;
|
|
char *uri;
|
|
OSSL_LIB_CTX *libctx;
|
|
OSSL_LIB_CTX *libctx;
|
|
char *propq;
|
|
char *propq;
|
|
- OSSL_STORE_CTX *ctx;
|
|
|
|
} CACHED_STORE;
|
|
} CACHED_STORE;
|
|
|
|
|
|
DEFINE_STACK_OF(CACHED_STORE)
|
|
DEFINE_STACK_OF(CACHED_STORE)
|
|
@@ -27,14 +26,12 @@ static int cache_objects(X509_LOOKUP *lctx, CACHED_STORE *store,
|
|
const OSSL_STORE_SEARCH *criterion, int depth)
|
|
const OSSL_STORE_SEARCH *criterion, int depth)
|
|
{
|
|
{
|
|
int ok = 0;
|
|
int ok = 0;
|
|
- OSSL_STORE_CTX *ctx = store->ctx;
|
|
|
|
|
|
+ OSSL_STORE_CTX *ctx;
|
|
X509_STORE *xstore = X509_LOOKUP_get_store(lctx);
|
|
X509_STORE *xstore = X509_LOOKUP_get_store(lctx);
|
|
|
|
|
|
- if (ctx == NULL
|
|
|
|
- && (ctx = OSSL_STORE_open_ex(store->uri, store->libctx, store->propq,
|
|
|
|
- NULL, NULL, NULL, NULL, NULL)) == NULL)
|
|
|
|
|
|
+ if ((ctx = OSSL_STORE_open_ex(store->uri, store->libctx, store->propq,
|
|
|
|
+ NULL, NULL, NULL, NULL, NULL)) == NULL)
|
|
return 0;
|
|
return 0;
|
|
- store->ctx = ctx;
|
|
|
|
|
|
|
|
/*
|
|
/*
|
|
* We try to set the criterion, but don't care if it was valid or not.
|
|
* We try to set the criterion, but don't care if it was valid or not.
|
|
@@ -79,7 +76,6 @@ static int cache_objects(X509_LOOKUP *lctx, CACHED_STORE *store,
|
|
substore.uri = (char *)OSSL_STORE_INFO_get0_NAME(info);
|
|
substore.uri = (char *)OSSL_STORE_INFO_get0_NAME(info);
|
|
substore.libctx = store->libctx;
|
|
substore.libctx = store->libctx;
|
|
substore.propq = store->propq;
|
|
substore.propq = store->propq;
|
|
- substore.ctx = NULL;
|
|
|
|
ok = cache_objects(lctx, &substore, criterion, depth - 1);
|
|
ok = cache_objects(lctx, &substore, criterion, depth - 1);
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
@@ -105,7 +101,6 @@ static int cache_objects(X509_LOOKUP *lctx, CACHED_STORE *store,
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
OSSL_STORE_close(ctx);
|
|
OSSL_STORE_close(ctx);
|
|
- store->ctx = NULL;
|
|
|
|
|
|
|
|
return ok;
|
|
return ok;
|
|
}
|
|
}
|
|
@@ -114,7 +109,6 @@ static int cache_objects(X509_LOOKUP *lctx, CACHED_STORE *store,
|
|
static void free_store(CACHED_STORE *store)
|
|
static void free_store(CACHED_STORE *store)
|
|
{
|
|
{
|
|
if (store != NULL) {
|
|
if (store != NULL) {
|
|
- OSSL_STORE_close(store->ctx);
|
|
|
|
OPENSSL_free(store->uri);
|
|
OPENSSL_free(store->uri);
|
|
OPENSSL_free(store->propq);
|
|
OPENSSL_free(store->propq);
|
|
OPENSSL_free(store);
|
|
OPENSSL_free(store);
|
|
@@ -149,6 +143,7 @@ static int by_store_ctrl_ex(X509_LOOKUP *ctx, int cmd, const char *argp,
|
|
{
|
|
{
|
|
STACK_OF(CACHED_STORE) *stores = X509_LOOKUP_get_method_data(ctx);
|
|
STACK_OF(CACHED_STORE) *stores = X509_LOOKUP_get_method_data(ctx);
|
|
CACHED_STORE *store = OPENSSL_zalloc(sizeof(*store));
|
|
CACHED_STORE *store = OPENSSL_zalloc(sizeof(*store));
|
|
|
|
+ OSSL_STORE_CTX *sctx;
|
|
|
|
|
|
if (store == NULL) {
|
|
if (store == NULL) {
|
|
return 0;
|
|
return 0;
|
|
@@ -158,14 +153,20 @@ static int by_store_ctrl_ex(X509_LOOKUP *ctx, int cmd, const char *argp,
|
|
store->libctx = libctx;
|
|
store->libctx = libctx;
|
|
if (propq != NULL)
|
|
if (propq != NULL)
|
|
store->propq = OPENSSL_strdup(propq);
|
|
store->propq = OPENSSL_strdup(propq);
|
|
- store->ctx = OSSL_STORE_open_ex(argp, libctx, propq, NULL, NULL,
|
|
|
|
- NULL, NULL, NULL);
|
|
|
|
- if (store->ctx == NULL
|
|
|
|
|
|
+ /*
|
|
|
|
+ * We open this to check for errors now - so we can report those
|
|
|
|
+ * errors early.
|
|
|
|
+ */
|
|
|
|
+ sctx = OSSL_STORE_open_ex(argp, libctx, propq, NULL, NULL,
|
|
|
|
+ NULL, NULL, NULL);
|
|
|
|
+ if (sctx == NULL
|
|
|| (propq != NULL && store->propq == NULL)
|
|
|| (propq != NULL && store->propq == NULL)
|
|
|| store->uri == NULL) {
|
|
|| store->uri == NULL) {
|
|
|
|
+ OSSL_STORE_close(sctx);
|
|
free_store(store);
|
|
free_store(store);
|
|
return use_default;
|
|
return use_default;
|
|
}
|
|
}
|
|
|
|
+ OSSL_STORE_close(sctx);
|
|
|
|
|
|
if (stores == NULL) {
|
|
if (stores == NULL) {
|
|
stores = sk_CACHED_STORE_new_null();
|
|
stores = sk_CACHED_STORE_new_null();
|
|
@@ -185,7 +186,6 @@ static int by_store_ctrl_ex(X509_LOOKUP *ctx, int cmd, const char *argp,
|
|
store.uri = (char *)argp;
|
|
store.uri = (char *)argp;
|
|
store.libctx = libctx;
|
|
store.libctx = libctx;
|
|
store.propq = (char *)propq;
|
|
store.propq = (char *)propq;
|
|
- store.ctx = NULL;
|
|
|
|
return cache_objects(ctx, &store, NULL, 0);
|
|
return cache_objects(ctx, &store, NULL, 0);
|
|
}
|
|
}
|
|
default:
|
|
default:
|
|
@@ -231,8 +231,14 @@ static int by_store_subject(X509_LOOKUP *ctx, X509_LOOKUP_TYPE type,
|
|
|
|
|
|
OSSL_STORE_SEARCH_free(criterion);
|
|
OSSL_STORE_SEARCH_free(criterion);
|
|
|
|
|
|
- if (ok)
|
|
|
|
|
|
+ if (ok) {
|
|
|
|
+ X509_STORE *store = X509_LOOKUP_get_store(ctx);
|
|
|
|
+
|
|
|
|
+ if (!ossl_x509_store_read_lock(store))
|
|
|
|
+ return 0;
|
|
tmp = X509_OBJECT_retrieve_by_subject(store_objects, type, name);
|
|
tmp = X509_OBJECT_retrieve_by_subject(store_objects, type, name);
|
|
|
|
+ X509_STORE_unlock(store);
|
|
|
|
+ }
|
|
|
|
|
|
ok = 0;
|
|
ok = 0;
|
|
if (tmp != NULL) {
|
|
if (tmp != NULL) {
|