summaryrefslogtreecommitdiffstats
path: root/crypto/store
diff options
context:
space:
mode:
authorRichard Levitte <levitte@openssl.org>2017-02-11 02:27:31 +0100
committerRichard Levitte <levitte@openssl.org>2018-02-23 07:40:42 +0100
commit6541d9e2646d693b3879ce438a2e9b8d290907fc (patch)
treea0a17740c7769ef6eb247999df4d7bf9c71bdf9c /crypto/store
parent072bfcc90b6f7c206e39339da519567c4460250c (diff)
STORE 'file' scheme loader: Add info type expectation
Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from https://github.com/openssl/openssl/pull/2688)
Diffstat (limited to 'crypto/store')
-rw-r--r--crypto/store/loader_file.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/crypto/store/loader_file.c b/crypto/store/loader_file.c
index 048cbd3a69..7232b9858a 100644
--- a/crypto/store/loader_file.c
+++ b/crypto/store/loader_file.c
@@ -721,6 +721,9 @@ struct ossl_store_loader_ctx_st {
int last_errno;
} dir;
} _;
+
+ /* Expected object type. May be unspecified */
+ int expected_type;
};
static void OSSL_STORE_LOADER_CTX_free(OSSL_STORE_LOADER_CTX *ctx)
@@ -908,6 +911,12 @@ static int file_ctrl(OSSL_STORE_LOADER_CTX *ctx, int cmd, va_list args)
return ret;
}
+static int file_expect(OSSL_STORE_LOADER_CTX *ctx, int expected)
+{
+ ctx->expected_type = expected;
+ return 1;
+}
+
/* Internal function to decode an already opened PEM file */
OSSL_STORE_LOADER_CTX *ossl_store_file_attach_pem_bio_int(BIO *bp)
{
@@ -1181,6 +1190,7 @@ static OSSL_STORE_INFO *file_load(OSSL_STORE_LOADER_CTX *ctx,
} else {
int matchcount = -1;
+ again:
result = file_load_try_repeat(ctx, ui_method, ui_data);
if (result != NULL)
return result;
@@ -1251,6 +1261,13 @@ static OSSL_STORE_INFO *file_load(OSSL_STORE_LOADER_CTX *ctx,
/* We bail out on ambiguity */
if (matchcount > 1)
return NULL;
+
+ if (result != NULL
+ && ctx->expected_type != 0
+ && ctx->expected_type != OSSL_STORE_INFO_get_type(result)) {
+ OSSL_STORE_INFO_free(result);
+ goto again;
+ }
}
return result;
@@ -1295,7 +1312,7 @@ static OSSL_STORE_LOADER file_loader =
NULL,
file_open,
file_ctrl,
- NULL,
+ file_expect,
file_load,
file_eof,
file_error,