diff options
author | Richard Levitte <levitte@openssl.org> | 2019-11-18 01:29:06 +0100 |
---|---|---|
committer | Richard Levitte <levitte@openssl.org> | 2019-11-29 20:54:48 +0100 |
commit | 0d003c52d3dcf4b076bb01a6767cdd5ace2d79f6 (patch) | |
tree | c04a81334735f506d3c94a3591e224683feb78ad /doc | |
parent | 36fa4d8a0df9dc168047fadd0365966c7116b31d (diff) |
SERIALIZER: New API for serialization of objects through providers
Serialization is needed to be able to take a provider object (such as
the provider side key data) and output it in PEM form, DER form, text
form (for display), and possibly other future forms (XML? JSON? JWK?)
The idea is that a serializer should be able to handle objects it has
intimate knowledge of, as well as object data in OSSL_PARAM form. The
latter will allow libcrypto to serialize some object with a different
provider than the one holding the data, if exporting of that data is
allowed and there is a serializer that can handle it.
We will provide serializers for the types of objects we know about,
which should be useful together with any other provider that provides
implementations of the same type of object.
Serializers are selected by method name and a couple of additional
properties:
- format used to tell what format the output should be in.
Possibilities could include "format=text",
"format=pem", "format=der", "format=pem-pkcs1"
(traditional), "format=der-pkcs1" (traditional)
- type used to tell exactly what type of data should be
output, for example "type=public" (the public part of
a key), "type=private" (the private part of a key),
"type=domainparams" (domain parameters).
This also adds a passphrase callback function type,
OSSL_PASSPHRASE_CALLBACK, which is a bit like OSSL_CALLBACK, but it
takes a few extra arguments to place the result in.
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/10394)
Diffstat (limited to 'doc')
-rw-r--r-- | doc/man3/OSSL_SERIALIZER.pod | 128 | ||||
-rw-r--r-- | doc/man3/OSSL_SERIALIZER_CTX.pod | 94 | ||||
-rw-r--r-- | doc/man7/openssl-core.h.pod | 23 | ||||
-rw-r--r-- | doc/man7/provider-serializer.pod | 227 | ||||
-rw-r--r-- | doc/man7/provider.pod | 8 |
5 files changed, 479 insertions, 1 deletions
diff --git a/doc/man3/OSSL_SERIALIZER.pod b/doc/man3/OSSL_SERIALIZER.pod new file mode 100644 index 0000000000..34767734f7 --- /dev/null +++ b/doc/man3/OSSL_SERIALIZER.pod @@ -0,0 +1,128 @@ +=pod + +=head1 NAME + +OSSL_SERIALIZER, +OSSL_SERIALIZER_fetch, +OSSL_SERIALIZER_up_ref, +OSSL_SERIALIZER_free, +OSSL_SERIALIZER_provider, +OSSL_SERIALIZER_properties, +OSSL_SERIALIZER_is_a, +OSSL_SERIALIZER_number, +OSSL_SERIALIZER_do_all_provided, +OSSL_SERIALIZER_names_do_all +- Serializer method routines + +=head1 SYNOPSIS + + #include <openssl/serializer.h> + + typedef struct ossl_serializer_st OSSL_SERIALIZER; + + OSSL_SERIALIZER *OSSL_SERIALIZER_fetch(OPENSSL_CTX *ctx, const char *name, + const char *properties); + int OSSL_SERIALIZER_up_ref(OSSL_SERIALIZER *serializer); + void OSSL_SERIALIZER_free(OSSL_SERIALIZER *serializer); + const OSSL_PROVIDER *OSSL_SERIALIZER_provider(const OSSL_SERIALIZER + *serializer); + const char *OSSL_SERIALIZER_properties(const OSSL_SERIALIZER *ser); + int OSSL_SERIALIZER_is_a(const OSSL_SERIALIZER *serializer, + const char *name); + int OSSL_SERIALIZER_number(const OSSL_SERIALIZER *serializer); + void OSSL_SERIALIZER_do_all_provided(OPENSSL_CTX *libctx, + void (*fn)(OSSL_SERIALIZER *serializer, + void *arg), + void *arg); + void OSSL_SERIALIZER_names_do_all(const OSSL_SERIALIZER *serializer, + void (*fn)(const char *name, void *data), + void *data); + +=head1 DESCRIPTION + +=for comment Future development should also talk about deserialization + +B<OSSL_SERIALIZER> is a method for serializers, which know how to +serialize an object of some kind to a serialized form, such as PEM, +DER, or even human readable text. + +OSSL_SERIALIZER_fetch() looks for an algorithm within the provider that +has been loaded into the B<OPENSSL_CTX> given by I<ctx>, having the +name given by I<name> and the properties given by I<properties>. +The I<name> determines what type of object the fetched serializer +method is expected to be able to serialize, and the properties are +used to determine the expected output type. +For known properties and the values they may have, please have a look +in L<provider-serializer(7)/Names and properties>. + +OSSL_SERIALIZER_up_ref() increments the reference count for the given +I<serializer>. + +OSSL_SERIALIZER_free() decrements the reference count for the given +I<serializer>, and when the count reaches zero, frees it. + +OSSL_SERIALIZER_provider() returns the provider of the given +I<serializer>. + +OSSL_SERIALIZER_provider() returns the property definition associated +with the given I<serializer>. + +OSSL_SERIALIZER_is_a() checks if I<serializer> is an implementation of an +algorithm that's identifiable with I<name>. + +OSSL_SERIALIZER_number() returns the internal dynamic number assigned to +the given I<serializer>. + +OSSL_SERIALIZER_names_do_all() traverses all names for the given +I<serializer>, and calls I<fn> with each name and I<data>. + +OSSL_SERIALIZER_do_all_provided() traverses all serializer +implementations by all activated providers in the library context +I<libctx>, and for each of the implementations, calls I<fn> with the +implementation method and I<data> as arguments. + +=head1 NOTES + +OSSL_SERIALIZER_fetch() may be called implicitly by other fetching +functions, using the same library context and properties. +Any other API that uses keys will typically do this. + +=head1 RETURN VALUES + +OSSL_SERIALIZER_fetch() returns a pointer to the key management +implementation represented by an OSSL_SERIALIZER object, or NULL on +error. + +OSSL_SERIALIZER_up_ref() returns 1 on success, or 0 on error. + +OSSL_SERIALIZER_free() doesn't return any value. + +OSSL_SERIALIZER_provider() returns a pointer to a provider object, or +NULL on error. + +OSSL_SERIALIZER_properties() returns a pointer to a property +definition string, or NULL on error. + +OSSL_SERIALIZER_is_a() returns 1 of I<serializer> was identifiable, +otherwise 0. + +OSSL_SERIALIZER_number() returns an integer. + +=head1 SEE ALSO + +L<provider(7)>, L<OSSL_SERIALIZER_CTX(3)>, L<OPENSSL_CTX(3)> + +=head1 HISTORY + +The functions described here were added in OpenSSL 3.0. + +=head1 COPYRIGHT + +Copyright 2019 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 +L<https://www.openssl.org/source/license.html>. + +=cut diff --git a/doc/man3/OSSL_SERIALIZER_CTX.pod b/doc/man3/OSSL_SERIALIZER_CTX.pod new file mode 100644 index 0000000000..d446b842d0 --- /dev/null +++ b/doc/man3/OSSL_SERIALIZER_CTX.pod @@ -0,0 +1,94 @@ +=pod + +=head1 NAME + +OSSL_SERIALIZER_CTX, +OSSL_SERIALIZER_CTX_new, +OSSL_SERIALIZER_CTX_get_serializer, +OSSL_SERIALIZER_settable_ctx_params, +OSSL_SERIALIZER_CTX_set_params, +OSSL_SERIALIZER_CTX_free +- Serializer context routines + +=head1 SYNOPSIS + + #include <openssl/serializer.h> + + typedef struct ossl_serializer_ctx_st OSSL_SERIALIZER_CTX; + + OSSL_SERIALIZER_CTX *OSSL_SERIALIZER_CTX_new(OSSL_SERIALIZER *ser); + const OSSL_SERIALIZER * + OSSL_SERIALIZER_CTX_get_serializer(OSSL_SERIALIZER_CTX *ctx); + const OSSL_PARAM *OSSL_SERIALIZER_settable_ctx_params(OSSL_SERIALIZER *ser); + int OSSL_SERIALIZER_CTX_set_params(OSSL_SERIALIZER_CTX *ctx, + const OSSL_PARAM params[]); + void OSSL_SERIALIZER_CTX_free(OSSL_SERIALIZER_CTX *ctx); + +=head1 DESCRIPTION + +B<OSSL_SERIALIZER_CTX> is a context with which B<OSSL_SERIALIZER> +operations are performed. The context typically holds values, both +internal and supplied by the application, which are useful for the +implementations supplied by providers. + +OSSL_SERIALIZER_CTX_new() creates a B<OSSL_SERIALIZER_CTX> associated +with the serializer I<ser>. NULL is a valid I<ser>, the context will +be created anyway, it's just not very useful. This is intentional, to +distinguish between errors in allocating the context or assigning it +values on one hand, and the lack of serializer support on the other. + +=begin comment + +The above distinction makes it possible for other routines to sense if +they need to report an error or fall back on other methods to +serialize. + +=end comment + +OSSL_SERIALIZER_CTX_get_serializer() gets the serializer method +currently associated with the context I<ctx>. + +OSSL_SERIALIZER_settable_ctx_params() returns an L<OSSL_PARAM(3)> +array of parameter descriptors. + +OSSL_SERIALIZER_CTX_set_params() attempts to set parameters specified +with an L<OSSL_PARAM(3)> array I<params>. Parameters that the +implementation doesn't recognise should be ignored. + +OSSL_SERIALIZER_CTX_free() frees the given context I<ctx>. + +=head1 RETURN VALUES + +OSSL_SERIALIZER_CTX_new() returns a pointer to a +B<OSSL_SERIALIZER_CTX>, or NULL if the context structure couldn't be +allocated. + +OSSL_SERIALIZER_CTX_get_serializer() returns a pointer to the +serializer method associated with I<ctx>. NULL is a valid return +value and signifies that there is no associated serializer method. + +OSSL_SERIALIZER_settable_ctx_params() returns an L<OSSL_PARAM(3)> +array, or NULL if none is available. + +OSSL_SERIALIZER_CTX_set_params() returns 1 if all recognised +parameters were valid, or 0 if one of them was invalid or caused some +other failure in the implementation. + +=head1 SEE ALSO + +L<provider(7)>, L<OSSL_SERIALIZER(3)> + +=head1 HISTORY + +The functions described here were added in OpenSSL 3.0. + +=head1 COPYRIGHT + +Copyright 2019 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 +L<https://www.openssl.org/source/license.html>. + +=cut diff --git a/doc/man7/openssl-core.h.pod b/doc/man7/openssl-core.h.pod index b5323e9d21..28307a97d4 100644 --- a/doc/man7/openssl-core.h.pod +++ b/doc/man7/openssl-core.h.pod @@ -76,7 +76,7 @@ B<OSSL_PARAM> is further described in L<OSSL_PARAM(3)> =item B<OSSL_CALLBACK> -This is a function type for a generic callback function: +This is a function type for a generic feedback callback function: typedef int (OSSL_CALLBACK)(const OSSL_PARAM params[], void *arg); @@ -86,6 +86,27 @@ expected to build an B<OSSL_PARAM> array of data it wants or is expected to pass back, and pass that as I<params>, as well as the caller data pointer it received, as I<arg>. +=item B<OSSL_PASSPHRASE_CALLBACK> + +This is a function type for a generic pass phrase callback function: + + typedef int (OSSL_PASSPHRASE_CALLBACK)(char *pass, size_t pass_size, + size_t *pass_len, + const OSSL_PARAM params[], + void *arg); + +This callback can be used to prompt the user for a passphrase. When +calling it, a buffer to store the pass phrase needs to be given with +I<pass>, and its size with I<pass_size>. The length of the prompted +pass phrase will be given back in I<*pass_len>. + +Additional parameters can be passed with the B<OSSL_PARAM> array +I<params>. + +A function that takes a pointer of this type should also take a +pointer to caller data, which should be passed as I<arg> to this +callback. + =back =head1 SEE ALSO diff --git a/doc/man7/provider-serializer.pod b/doc/man7/provider-serializer.pod new file mode 100644 index 0000000000..e43e293d60 --- /dev/null +++ b/doc/man7/provider-serializer.pod @@ -0,0 +1,227 @@ +=pod + +=head1 NAME + +provider-serializer - The SERIALIZER library E<lt>-E<gt> provider functions + +=head1 SYNOPSIS + +=begin comment + +Future development will also include deserializing functions. + +=end comment + + #include <openssl/core_numbers.h> + + /* + * None of these are actual functions, but are displayed like this for + * the function signatures for functions that are offered as function + * pointers in OSSL_DISPATCH arrays. + */ + + /* Functions to construct / destruct / manipulate the serializer context */ + void *OP_serializer_newctx(void *provctx); + void OP_serializer_freectx(void *ctx); + int OP_serializer_set_ctx_params(void *ctx, const OSSL_PARAM params[]); + const OSSL_PARAM *OP_serializer_settable_ctx_params(void) + + /* Functions to serialize object data */ + int OP_serializer_serialize_data(void *ctx, const OSSL_PARAM *data, + BIO *out, + OSSL_PASSPHRASE_CALLBACK *cb, + void *cbarg); + int OP_serializer_serialize_object(void *ctx, void *obj, BIO *out, + OSSL_PASSPHRASE_CALLBACK *cb, + void *cbarg); + +=head1 DESCRIPTION + +The SERIALIZER is a generic method to serialize any set of object data +in L<OSSL_PARAM(3)> array form, or any provider side object into +serialized form, and write it to the given BIO. If the caller wants +to get the serialized stream to memory, it should provide a +L<BIO_s_membuf(3)>. + +The serializer doesn't need to know more about the B<BIO> pointer than +being able to pass it to the appropriate BIO upcalls (see +L<provider-base(7)/Core functions>). + +The serialization using the L<OSSL_PARAM(3)> array form allows a +serializer to be used for data that's been exported from another +provider, and thereby allow them to exist independently of each +other. + +The serialization using a provider side object can only be safely used +with provider data coming from the same provider, for example keys +with the L<KEYMGMT|provider-keymgmt(7)> provider. + +All "functions" mentioned here are passed as function pointers between +F<libcrypto> and the provider in B<OSSL_DISPATCH> arrays via +B<OSSL_ALGORITHM> arrays that are returned by the provider's +provider_query_operation() function +(see L<provider-base(7)/Provider Functions>). + +All these "functions" have a corresponding function type definition +named B<OSSL_{name}_fn>, and a helper function to retrieve the +function pointer from a B<OSSL_DISPATCH> element named +B<OSSL_get_{name}>. +For example, the "function" OP_serializer_serialize_data() has these: + + typedef int + (OSSL_OP_serializer_serialize_data_fn)(void *provctx, + const OSSL_PARAM params[], + BIO *out); + static ossl_inline OSSL_OP_serializer_serialize_data_fn + OSSL_get_OP_serializer_serialize_data(const OSSL_DISPATCH *opf); + +B<OSSL_DISPATCH> arrays are indexed by numbers that are provided as +macros in L<openssl-core_numbers.h(7)>, as follows: + + OP_serializer_newctx OSSL_FUNC_SERIALIZER_NEWCTX + OP_serializer_freectx OSSL_FUNC_SERIALIZER_FREECTX + OP_serializer_set_ctx_params OSSL_FUNC_SERIALIZER_SET_CTX_PARAMS + OP_serializer_settable_ctx_params OSSL_FUNC_SERIALIZER_SETTABLE_CTX_PARAMS + + OP_serializer_serialize_data OSSL_FUNC_SERIALIZER_SERIALIZE_DATA + OP_serializer_serialize_object OSSL_FUNC_SERIALIZER_SERIALIZE_OBJECT + +=head2 Names and properties + +The name of an implementation should match the type of object it +handles. For example, an implementation that serializes an RSA key +should be named accordingly. + +To be able to specify exactly what serialization format and what type +of data a serializer implementation is expected to handle, two +additional properties may be given: + +=over 4 + +=item format + +This property is used to specify what kind of output format the +implementation produces. Currently known formats are: + +=over 4 + +=item text + +An implementation with that format property value outputs human +readable text, making that implementation suitable for C<-text> output +in diverse L<openssl(1)> commands. + +=item pem + +An implementation with that format property value outputs PEM +formatted data. + +=item der + +An implementation with that format property value outputs DER +formatted data. + +=back + +=item type + +With objects that have multiple purposes, this can be used to specify +the purpose type. The currently known use cases are asymmetric keys +and domain parameters, where the type can be one of: + +=over 4 + +=item private + +An implementation with that format property value outputs a private +key. + +=item public + +An implementation with that format property value outputs a public +key. + +=item domainparams + +An implementation with that format property value outputs domain +parameters. + +=back + +=back + +The possible values of both these properties is open ended. A +provider may very well specify other formats that libcrypto doesn't +know anything about. + +=head2 Context functions + +OP_serializer_newctx() returns a context to be used with the rest of +the functions. + +OP_serializer_freectx() frees the given I<ctx>, if it was created by +OP_serializer_newctx(). + +OP_serializer_set_ctx_params() sets context data according to +parameters from I<params> that it recognises. Unrecognised parameters +should be ignored. + +OP_serializer_settable_ctx_params() returns a constant B<OSSL_PARAM> +array describing the parameters that OP_serializer_set_ctx_params() +can handle. + +See L<OSSL_PARAM(3)> for further details on the parameters structure used +by OP_serializer_set_ctx_params() and OP_serializer_settable_ctx_params(). + +=head2 Serializing functions + +=for comment There will be a "Deserializing functions" title as well + +OP_serializer_serialize_data() should take an array of B<OSSL_PARAM>, +I<data>, and if it contains the data necessary for the object type +that the implementation handles, it should output the object in +serialized form to the B<BIO>. + +OP_serializer_serialize_object() should take a pointer to an object +that it knows intimately, and output that object in serialized form to +the B<BIO>. The caller I<must> ensure that this function is called +with a pointer that the provider of this function is familiar with. +It is not suitable to use with object pointers coming from other +providers. + +Both serialization functions also take an B<OSSL_PASSPHRASE_CALLBACK> +function pointer along with a pointer to application data I<cbarg>, +which should be used when a pass phrase prompt is needed. + +=head1 RETURN VALUES + +OP_serializer_newctx() returns a pointer to a context, or NULL on +failure. + +OP_serializer_set_ctx_params() returns 1, unless a recognised +parameters was invalid or caused an error, for which 0 is returned. + +OP_serializer_settable_ctx_params() returns a pointer to an array of +constant B<OSSL_PARAM> elements. + +OP_serializer_serialize_data() and OP_serializer_serialize_object() +return 1 on success, or 0 on failure. + +=head1 SEE ALSO + +L<provider(7)> + +=head1 HISTORY + +The SERIALIZER interface was introduced in OpenSSL 3.0. + +=head1 COPYRIGHT + +Copyright 2019 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 +L<https://www.openssl.org/source/license.html>. + +=cut diff --git a/doc/man7/provider.pod b/doc/man7/provider.pod index c3405b6f22..b6c5e49f50 100644 --- a/doc/man7/provider.pod +++ b/doc/man7/provider.pod @@ -147,6 +147,14 @@ The number for this operation is B<OSSL_OP_KEYEXCH>. The functions the provider can offer are described in L<provider-keyexch(7)> +=item Serialization + +In the OpenSSL libraries, the corresponding method object is +B<OSSL_SERIALIZER>. +The number for this operation is B<OSSL_OP_SERIALIZER>. +The functions the provider can offer are described in +L<provider-serializer(7)> + =back =head2 Fetching algorithms |