openssl/crypto/store/store_local.h
Richard Levitte 34b80d0622 STORE: Modify to support loading with provider based loaders
This adds the needed code to make the OSSL_STORE API functions handle
provided STORE implementations.

This also modifies OSSL_STORE_attach() for have the URI, the
library context and the properties in the same order as
OSSL_STORE_open_with_libctx().

The most notable change, though, is how this creates a division of
labor between libcrypto and any storemgmt implementation that wants to
pass X.509, X.509 CRL, etc structures back to libcrypto.  Since those
structures aren't directly supported in the libcrypto <-> provider
interface (asymmetric keys being the only exception so far), we resort
to a libcrypto object callback that can handle passed data in DER form
and does its part of figuring out what the DER content actually is.

This also adds the internal x509_crl_set0_libctx(), which works just
like x509_set0_libctx(), but for X509_CRL.

Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/12512)
2020-08-24 10:02:26 +02:00

204 lines
5.9 KiB
C

/*
* Copyright 2016-2020 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (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
*/
#include <openssl/core_dispatch.h>
#include "internal/thread_once.h"
#include "internal/refcount.h"
#include <openssl/dsa.h>
#include <openssl/engine.h>
#include <openssl/evp.h>
#include <openssl/lhash.h>
#include <openssl/x509.h>
#include <openssl/store.h>
#include "internal/passphrase.h"
/*-
* OSSL_STORE_INFO stuff
* ---------------------
*/
struct ossl_store_info_st {
int type;
union {
void *data; /* used internally as generic pointer */
struct {
BUF_MEM *blob;
char *pem_name;
} embedded; /* when type == OSSL_STORE_INFO_EMBEDDED */
struct {
char *name;
char *desc;
} name; /* when type == OSSL_STORE_INFO_NAME */
EVP_PKEY *params; /* when type == OSSL_STORE_INFO_PARAMS */
EVP_PKEY *pubkey; /* when type == OSSL_STORE_INFO_PUBKEY */
EVP_PKEY *pkey; /* when type == OSSL_STORE_INFO_PKEY */
X509 *x509; /* when type == OSSL_STORE_INFO_CERT */
X509_CRL *crl; /* when type == OSSL_STORE_INFO_CRL */
} _;
};
DEFINE_STACK_OF(OSSL_STORE_INFO)
/*
* EMBEDDED is a special type of OSSL_STORE_INFO, specially for the file
* handlers. It should never reach a calling application or any engine.
* However, it can be used by a FILE_HANDLER's try_decode function to signal
* that it has decoded the incoming blob into a new blob, and that the
* attempted decoding should be immediately restarted with the new blob, using
* the new PEM name.
*/
/*
* Because this is an internal type, we don't make it public.
*/
#define OSSL_STORE_INFO_EMBEDDED -1
OSSL_STORE_INFO *ossl_store_info_new_EMBEDDED(const char *new_pem_name,
BUF_MEM *embedded);
BUF_MEM *ossl_store_info_get0_EMBEDDED_buffer(OSSL_STORE_INFO *info);
char *ossl_store_info_get0_EMBEDDED_pem_name(OSSL_STORE_INFO *info);
/*-
* OSSL_STORE_SEARCH stuff
* -----------------------
*/
struct ossl_store_search_st {
int search_type;
/*
* Used by OSSL_STORE_SEARCH_BY_NAME and
* OSSL_STORE_SEARCH_BY_ISSUER_SERIAL
*/
X509_NAME *name; /* TODO constify this; leads to API incompatibility */
/* Used by OSSL_STORE_SEARCH_BY_ISSUER_SERIAL */
const ASN1_INTEGER *serial;
/* Used by OSSL_STORE_SEARCH_BY_KEY_FINGERPRINT */
const EVP_MD *digest;
/*
* Used by OSSL_STORE_SEARCH_BY_KEY_FINGERPRINT and
* OSSL_STORE_SEARCH_BY_ALIAS
*/
const unsigned char *string;
size_t stringlength;
};
/*-
* OSSL_STORE_LOADER stuff
* -----------------------
*/
int ossl_store_register_loader_int(OSSL_STORE_LOADER *loader);
OSSL_STORE_LOADER *ossl_store_unregister_loader_int(const char *scheme);
/* loader stuff */
struct ossl_store_loader_st {
/* Legacy stuff */
const char *scheme;
ENGINE *engine;
OSSL_STORE_open_fn open;
OSSL_STORE_attach_fn attach;
OSSL_STORE_ctrl_fn ctrl;
OSSL_STORE_expect_fn expect;
OSSL_STORE_find_fn find;
OSSL_STORE_load_fn load;
OSSL_STORE_eof_fn eof;
OSSL_STORE_error_fn error;
OSSL_STORE_close_fn close;
OSSL_STORE_open_with_libctx_fn open_with_libctx;
/* Provider stuff */
OSSL_PROVIDER *prov;
int scheme_id;
const char *propdef;
CRYPTO_REF_COUNT refcnt;
CRYPTO_RWLOCK *lock;
OSSL_FUNC_store_open_fn *p_open;
OSSL_FUNC_store_attach_fn *p_attach;
OSSL_FUNC_store_settable_ctx_params_fn *p_settable_ctx_params;
OSSL_FUNC_store_set_ctx_params_fn *p_set_ctx_params;
OSSL_FUNC_store_load_fn *p_load;
OSSL_FUNC_store_eof_fn *p_eof;
OSSL_FUNC_store_close_fn *p_close;
OSSL_FUNC_store_export_object_fn *p_export_object;
};
DEFINE_LHASH_OF(OSSL_STORE_LOADER);
const OSSL_STORE_LOADER *ossl_store_get0_loader_int(const char *scheme);
void ossl_store_destroy_loaders_int(void);
/*-
* OSSL_STORE_CTX stuff
* ---------------------
*/
struct ossl_store_ctx_st {
const OSSL_STORE_LOADER *loader; /* legacy */
OSSL_STORE_LOADER *fetched_loader;
OSSL_STORE_LOADER_CTX *loader_ctx;
OSSL_STORE_post_process_info_fn post_process;
void *post_process_data;
int expected_type;
char *properties;
/* 0 before the first STORE_load(), 1 otherwise */
int loading;
/* 1 on load error, only valid for fetched loaders */
int error_flag;
/*
* Cache of stuff, to be able to return the contents of a PKCS#12
* blob, one object at a time.
*/
STACK_OF(OSSL_STORE_INFO) *cached_info;
struct ossl_passphrase_data_st pwdata;
};
/*-
* OSSL_STORE init stuff
* ---------------------
*/
int ossl_store_init_once(void);
int ossl_store_file_loader_init(void);
/*-
* 'file' scheme stuff
* -------------------
*/
OSSL_STORE_LOADER_CTX *ossl_store_file_attach_pem_bio_int(BIO *bp);
int ossl_store_file_detach_pem_bio_int(OSSL_STORE_LOADER_CTX *ctx);
/*-
* Provider stuff
* -------------------
*/
OSSL_STORE_LOADER *ossl_store_loader_fetch(OPENSSL_CTX *libctx,
const char *scheme,
const char *properties);
OSSL_STORE_LOADER *ossl_store_loader_fetch_by_number(OPENSSL_CTX *libctx,
int scheme_id,
const char *properties);
/* Standard function to handle the result from OSSL_FUNC_store_load() */
struct ossl_load_result_data_st {
OSSL_STORE_INFO *v; /* To be filled in */
OSSL_STORE_CTX *ctx;
};
OSSL_CALLBACK ossl_store_handle_load_result;