8eba0e3e30169cf4a59c011424260bfc864c0173
[openssl.git] / doc / man7 / provider-serializer.pod
1 =pod
2
3 =head1 NAME
4
5 provider-serializer - The SERIALIZER library E<lt>-E<gt> provider functions
6
7 =head1 SYNOPSIS
8
9 =begin comment
10
11 Future development will also include deserializing functions.
12
13 =end comment
14
15  #include <openssl/core_dispatch.h>
16
17  /*
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.
21   */
22
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)
28
29  /* Functions to serialize object data */
30  int OP_serializer_serialize_data(void *ctx, const OSSL_PARAM *data,
31                                   OSSL_CORE_BIO *out,
32                                   OSSL_PASSPHRASE_CALLBACK *cb,
33                                   void *cbarg);
34  int OP_serializer_serialize_object(void *ctx, void *obj, OSSL_CORE_BIO *out,
35                                     OSSL_PASSPHRASE_CALLBACK *cb,
36                                     void *cbarg);
37
38 =head1 DESCRIPTION
39
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
44 L<BIO_s_membuf(3)>.
45
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>).
49
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
53 other.
54
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.
58
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>).
64
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
68 B<OSSL_get_{name}>.
69 For example, the "function" OP_serializer_serialize_data() has these:
70
71  typedef int
72      (OSSL_OP_serializer_serialize_data_fn)(void *provctx,
73                                             const OSSL_PARAM params[],
74                                             OSSL_CORE_BIO *out);
75  static ossl_inline OSSL_OP_serializer_serialize_data_fn
76      OSSL_get_OP_serializer_serialize_data(const OSSL_DISPATCH *opf);
77
78 B<OSSL_DISPATCH> arrays are indexed by numbers that are provided as
79 macros in L<openssl-core_dispatch.h(7)>, as follows:
80
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
85
86  OP_serializer_serialize_data      OSSL_FUNC_SERIALIZER_SERIALIZE_DATA
87  OP_serializer_serialize_object    OSSL_FUNC_SERIALIZER_SERIALIZE_OBJECT
88
89 =head2 Names and properties
90
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.
94
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:
98
99 =over 4
100
101 =item format
102
103 This property is used to specify what kind of output format the
104 implementation produces.  Currently known formats are:
105
106 =over 4
107
108 =item text
109
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.
113
114 =item pem
115
116 An implementation with that format property value outputs PEM
117 formatted data.
118
119 =item der
120
121 An implementation with that format property value outputs DER
122 formatted data.
123
124 =back
125
126 =item type
127
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:
131
132 =over 4
133
134 =item private
135
136 An implementation with that format property value outputs a private
137 key.
138
139 =item public
140
141 An implementation with that format property value outputs a public
142 key.
143
144 =item parameters
145
146 An implementation with that format property value outputs key
147 parameters.
148
149 =back
150
151 =back
152
153 The possible values of both these properties is open ended.  A
154 provider may very well specify other formats that libcrypto doesn't
155 know anything about.
156
157 =head2 Context functions
158
159 OP_serializer_newctx() returns a context to be used with the rest of
160 the functions.
161
162 OP_serializer_freectx() frees the given I<ctx>, if it was created by
163 OP_serializer_newctx().
164
165 OP_serializer_set_ctx_params() sets context data according to
166 parameters from I<params> that it recognises.  Unrecognised parameters
167 should be ignored.
168
169 OP_serializer_settable_ctx_params() returns a constant B<OSSL_PARAM>
170 array describing the parameters that OP_serializer_set_ctx_params()
171 can handle.
172
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().
175
176 =head2 Serializing functions
177
178 =for comment There will be a "Deserializing functions" title as well
179
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>.
184
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
190 providers.
191
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.
195
196 =head2 Serializer parameters
197
198 Parameters currently recognised by built-in serializers are as
199 follows:
200
201 =over 4
202
203 =item "cipher" (B<OSSL_SERIALIZER_PARAM_CIPHER>) <UTF8 string>
204
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.
208
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.
213
214 =item "properties" (B<OSSL_SERIALIZER_PARAM_PROPERTIES>) <UTF8 string>
215
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
219 considered valid.
220
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.
225
226 =item "passphrase" (B<OSSL_SERIALIZER_PARAM_PASS>) <octet string>
227
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.
230
231 =back
232
233 Parameters currently recognised by the built-in pass phrase callback:
234
235 =over 4
236
237 =item "info" (B<OSSL_PASSPHRASE_PARAM_INFO>) <UTF8 string>
238
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.
242
243 =back
244
245 =head1 RETURN VALUES
246
247 OP_serializer_newctx() returns a pointer to a context, or NULL on
248 failure.
249
250 OP_serializer_set_ctx_params() returns 1, unless a recognised
251 parameters was invalid or caused an error, for which 0 is returned.
252
253 OP_serializer_settable_ctx_params() returns a pointer to an array of
254 constant B<OSSL_PARAM> elements.
255
256 OP_serializer_serialize_data() and OP_serializer_serialize_object()
257 return 1 on success, or 0 on failure.
258
259 =head1 SEE ALSO
260
261 L<provider(7)>
262
263 =head1 HISTORY
264
265 The SERIALIZER interface was introduced in OpenSSL 3.0.
266
267 =head1 COPYRIGHT
268
269 Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved.
270
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>.
275
276 =cut