5 provider-serializer - The SERIALIZER library E<lt>-E<gt> provider functions
11 Future development will also include deserializing functions.
15 #include <openssl/core_numbers.h>
18 * None of these are actual functions, but are displayed like this for
19 * the function signatures for functions that are offered as function
20 * pointers in OSSL_DISPATCH arrays.
23 /* Functions to construct / destruct / manipulate the serializer context */
24 void *OP_serializer_newctx(void *provctx);
25 void OP_serializer_freectx(void *ctx);
26 int OP_serializer_set_ctx_params(void *ctx, const OSSL_PARAM params[]);
27 const OSSL_PARAM *OP_serializer_settable_ctx_params(void)
29 /* Functions to serialize object data */
30 int OP_serializer_serialize_data(void *ctx, const OSSL_PARAM *data,
32 OSSL_PASSPHRASE_CALLBACK *cb,
34 int OP_serializer_serialize_object(void *ctx, void *obj, OSSL_CORE_BIO *out,
35 OSSL_PASSPHRASE_CALLBACK *cb,
40 The SERIALIZER is a generic method to serialize any set of object data
41 in L<OSSL_PARAM(3)> array form, or any provider side object into
42 serialized form, and write it to the given OSSL_CORE_BIO. If the caller wants
43 to get the serialized stream to memory, it should provide a
46 The serializer doesn't need to know more about the B<OSSL_CORE_BIO> pointer than
47 being able to pass it to the appropriate BIO upcalls (see
48 L<provider-base(7)/Core functions>).
50 The serialization using the L<OSSL_PARAM(3)> array form allows a
51 serializer to be used for data that's been exported from another
52 provider, and thereby allow them to exist independently of each
55 The serialization using a provider side object can only be safely used
56 with provider data coming from the same provider, for example keys
57 with the L<KEYMGMT|provider-keymgmt(7)> provider.
59 All "functions" mentioned here are passed as function pointers between
60 F<libcrypto> and the provider in B<OSSL_DISPATCH> arrays via
61 B<OSSL_ALGORITHM> arrays that are returned by the provider's
62 provider_query_operation() function
63 (see L<provider-base(7)/Provider Functions>).
65 All these "functions" have a corresponding function type definition
66 named B<OSSL_{name}_fn>, and a helper function to retrieve the
67 function pointer from a B<OSSL_DISPATCH> element named
69 For example, the "function" OP_serializer_serialize_data() has these:
72 (OSSL_OP_serializer_serialize_data_fn)(void *provctx,
73 const OSSL_PARAM params[],
75 static ossl_inline OSSL_OP_serializer_serialize_data_fn
76 OSSL_get_OP_serializer_serialize_data(const OSSL_DISPATCH *opf);
78 B<OSSL_DISPATCH> arrays are indexed by numbers that are provided as
79 macros in L<openssl-core_numbers.h(7)>, as follows:
81 OP_serializer_newctx OSSL_FUNC_SERIALIZER_NEWCTX
82 OP_serializer_freectx OSSL_FUNC_SERIALIZER_FREECTX
83 OP_serializer_set_ctx_params OSSL_FUNC_SERIALIZER_SET_CTX_PARAMS
84 OP_serializer_settable_ctx_params OSSL_FUNC_SERIALIZER_SETTABLE_CTX_PARAMS
86 OP_serializer_serialize_data OSSL_FUNC_SERIALIZER_SERIALIZE_DATA
87 OP_serializer_serialize_object OSSL_FUNC_SERIALIZER_SERIALIZE_OBJECT
89 =head2 Names and properties
91 The name of an implementation should match the type of object it
92 handles. For example, an implementation that serializes an RSA key
93 should be named accordingly.
95 To be able to specify exactly what serialization format and what type
96 of data a serializer implementation is expected to handle, two
97 additional properties may be given:
103 This property is used to specify what kind of output format the
104 implementation produces. Currently known formats are:
110 An implementation with that format property value outputs human
111 readable text, making that implementation suitable for C<-text> output
112 in diverse L<openssl(1)> commands.
116 An implementation with that format property value outputs PEM
121 An implementation with that format property value outputs DER
128 With objects that have multiple purposes, this can be used to specify
129 the purpose type. The currently known use cases are asymmetric keys
130 and key parameters, where the type can be one of:
136 An implementation with that format property value outputs a private
141 An implementation with that format property value outputs a public
146 An implementation with that format property value outputs key
153 The possible values of both these properties is open ended. A
154 provider may very well specify other formats that libcrypto doesn't
157 =head2 Context functions
159 OP_serializer_newctx() returns a context to be used with the rest of
162 OP_serializer_freectx() frees the given I<ctx>, if it was created by
163 OP_serializer_newctx().
165 OP_serializer_set_ctx_params() sets context data according to
166 parameters from I<params> that it recognises. Unrecognised parameters
169 OP_serializer_settable_ctx_params() returns a constant B<OSSL_PARAM>
170 array describing the parameters that OP_serializer_set_ctx_params()
173 See L<OSSL_PARAM(3)> for further details on the parameters structure used
174 by OP_serializer_set_ctx_params() and OP_serializer_settable_ctx_params().
176 =head2 Serializing functions
178 =for comment There will be a "Deserializing functions" title as well
180 OP_serializer_serialize_data() should take an array of B<OSSL_PARAM>,
181 I<data>, and if it contains the data necessary for the object type
182 that the implementation handles, it should output the object in
183 serialized form to the B<OSSL_CORE_BIO>.
185 OP_serializer_serialize_object() should take a pointer to an object
186 that it knows intimately, and output that object in serialized form to
187 the B<OSSL_CORE_BIO>. The caller I<must> ensure that this function is called
188 with a pointer that the provider of this function is familiar with.
189 It is not suitable to use with object pointers coming from other
192 Both serialization functions also take an B<OSSL_PASSPHRASE_CALLBACK>
193 function pointer along with a pointer to application data I<cbarg>,
194 which should be used when a pass phrase prompt is needed.
196 =head2 Serializer parameters
198 Parameters currently recognised by built-in serializers are as
203 =item "cipher" (B<OSSL_SERIALIZER_PARAM_CIPHER>) <UTF8 string>
205 The name of the encryption cipher to be used when generating encrypted
206 serialization. This is used when serializing private keys, as well as
207 other objects that need protection.
209 If this name is invalid for the serialization implementation, the
210 implementation should refuse to perform the serialization, i.e.
211 OP_serializer_serialize_data() and OP_serializer_serialize_object()
212 should return an error.
214 =item "properties" (B<OSSL_SERIALIZER_PARAM_PROPERTIES>) <UTF8 string>
216 The properties to be queried when trying to fetch the algorithm given
217 with the "cipher" parameter.
218 This must be given together with the "cipher" parameter to be
221 The serialization implementation isn't obligated to use this value.
222 However, it is recommended that implementations that do not handle
223 property strings return an error on receiving this parameter unless
224 its value NULL or the empty string.
226 =item "passphrase" (B<OSSL_SERIALIZER_PARAM_PASS>) <octet string>
228 A pass phrase provided by the application. When this is given, the
229 built-in serializers will not attempt to use the passphrase callback.
233 Parameters currently recognised by the built-in pass phrase callback:
237 =item "info" (B<OSSL_PASSPHRASE_PARAM_INFO>) <UTF8 string>
239 A string of information that will become part of the pass phrase
240 prompt. This could be used to give the user information on what kind
241 of object it's being prompted for.
247 OP_serializer_newctx() returns a pointer to a context, or NULL on
250 OP_serializer_set_ctx_params() returns 1, unless a recognised
251 parameters was invalid or caused an error, for which 0 is returned.
253 OP_serializer_settable_ctx_params() returns a pointer to an array of
254 constant B<OSSL_PARAM> elements.
256 OP_serializer_serialize_data() and OP_serializer_serialize_object()
257 return 1 on success, or 0 on failure.
265 The SERIALIZER interface was introduced in OpenSSL 3.0.
269 Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved.
271 Licensed under the Apache License 2.0 (the "License"). You may not use
272 this file except in compliance with the License. You can obtain a copy
273 in the file LICENSE in the source distribution or at
274 L<https://www.openssl.org/source/license.html>.