1PROVIDER-DECODER(7ossl) OpenSSL PROVIDER-DECODER(7ossl)
2
3
4
6 provider-decoder - The OSSL_DECODER library <-> provider functions
7
9 #include <openssl/core_dispatch.h>
10
11 /*
12 * None of these are actual functions, but are displayed like this for
13 * the function signatures for functions that are offered as function
14 * pointers in OSSL_DISPATCH arrays.
15 */
16
17 /* Decoder parameter accessor and descriptor */
18 const OSSL_PARAM *OSSL_FUNC_decoder_gettable_params(void *provctx);
19 int OSSL_FUNC_decoder_get_params(OSSL_PARAM params[]);
20
21 /* Functions to construct / destruct / manipulate the decoder context */
22 void *OSSL_FUNC_decoder_newctx(void *provctx);
23 void OSSL_FUNC_decoder_freectx(void *ctx);
24 const OSSL_PARAM *OSSL_FUNC_decoder_settable_ctx_params(void *provctx);
25 int OSSL_FUNC_decoder_set_ctx_params(void *ctx, const OSSL_PARAM params[]);
26
27 /* Functions to check selection support */
28 int OSSL_FUNC_decoder_does_selection(void *provctx, int selection);
29
30 /* Functions to decode object data */
31 int OSSL_FUNC_decoder_decode(void *ctx, OSSL_CORE_BIO *in,
32 int selection,
33 OSSL_CALLBACK *data_cb, void *data_cbarg,
34 OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg);
35
36 /* Functions to export a decoded object */
37 void *OSSL_FUNC_decoder_export_object(void *ctx,
38 const void *objref, size_t objref_sz,
39 OSSL_CALLBACK *export_cb,
40 void *export_cbarg);
41
43 The term "decode" is used throughout this manual. This includes but is
44 not limited to deserialization as individual decoders can also do
45 decoding into intermediate data formats.
46
47 The DECODER operation is a generic method to create a provider-native
48 object reference or intermediate decoded data from an encoded form read
49 from the given OSSL_CORE_BIO. If the caller wants to decode data from
50 memory, it should provide a BIO_s_mem(3) BIO. The decoded data or
51 object reference is passed along with eventual metadata to the
52 metadata_cb as OSSL_PARAM parameters.
53
54 The decoder doesn't need to know more about the OSSL_CORE_BIO pointer
55 than being able to pass it to the appropriate BIO upcalls (see "Core
56 functions" in provider-base(7)).
57
58 The DECODER implementation may be part of a chain, where data is passed
59 from one to the next. For example, there may be an implementation to
60 decode an object from PEM to DER, and another one that decodes DER to a
61 provider-native object.
62
63 The last decoding step in the decoding chain is usually supposed to
64 create a provider-native object referenced by an object reference. To
65 import that object into a different provider the
66 OSSL_FUNC_decoder_export_object() can be called as the final step of
67 the decoding process.
68
69 All "functions" mentioned here are passed as function pointers between
70 libcrypto and the provider in OSSL_DISPATCH arrays via OSSL_ALGORITHM
71 arrays that are returned by the provider's provider_query_operation()
72 function (see "Provider Functions" in provider-base(7)).
73
74 All these "functions" have a corresponding function type definition
75 named OSSL_FUNC_{name}_fn, and a helper function to retrieve the
76 function pointer from an OSSL_DISPATCH element named OSSL_FUNC_{name}.
77 For example, the "function" OSSL_FUNC_decoder_decode() has these:
78
79 typedef int
80 (OSSL_FUNC_decoder_decode_fn)(void *ctx, OSSL_CORE_BIO *in,
81 int selection,
82 OSSL_CALLBACK *data_cb, void *data_cbarg,
83 OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg);
84 static ossl_inline OSSL_FUNC_decoder_decode_fn
85 OSSL_FUNC_decoder_decode(const OSSL_DISPATCH *opf);
86
87 OSSL_DISPATCH arrays are indexed by numbers that are provided as macros
88 in openssl-core_dispatch.h(7), as follows:
89
90 OSSL_FUNC_decoder_get_params OSSL_FUNC_DECODER_GET_PARAMS
91 OSSL_FUNC_decoder_gettable_params OSSL_FUNC_DECODER_GETTABLE_PARAMS
92
93 OSSL_FUNC_decoder_newctx OSSL_FUNC_DECODER_NEWCTX
94 OSSL_FUNC_decoder_freectx OSSL_FUNC_DECODER_FREECTX
95 OSSL_FUNC_decoder_set_ctx_params OSSL_FUNC_DECODER_SET_CTX_PARAMS
96 OSSL_FUNC_decoder_settable_ctx_params OSSL_FUNC_DECODER_SETTABLE_CTX_PARAMS
97
98 OSSL_FUNC_decoder_does_selection OSSL_FUNC_DECODER_DOES_SELECTION
99
100 OSSL_FUNC_decoder_decode OSSL_FUNC_DECODER_DECODE
101
102 OSSL_FUNC_decoder_export_object OSSL_FUNC_DECODER_EXPORT_OBJECT
103
104 Names and properties
105 The name of an implementation should match the target type of object it
106 decodes. For example, an implementation that decodes an RSA key should
107 be named "RSA". Likewise, an implementation that decodes DER data from
108 PEM input should be named "DER".
109
110 Properties can be used to further specify details about an
111 implementation:
112
113 input
114 This property is used to specify what format of input the
115 implementation can decode.
116
117 This property is mandatory.
118
119 OpenSSL providers recognize the following input types:
120
121 pem An implementation with that input type decodes PEM formatted
122 data.
123
124 der An implementation with that input type decodes DER formatted
125 data.
126
127 msblob
128 An implementation with that input type decodes MSBLOB formatted
129 data.
130
131 pvk An implementation with that input type decodes PVK formatted
132 data.
133
134 structure
135 This property is used to specify the structure that the decoded
136 data is expected to have.
137
138 This property is optional.
139
140 Structures currently recognised by built-in decoders:
141
142 "type-specific"
143 Type specific structure.
144
145 "pkcs8"
146 Structure according to the PKCS#8 specification.
147
148 "SubjectPublicKeyInfo"
149 Encoding of public keys according to the Subject Public Key
150 Info of RFC 5280.
151
152 The possible values of both these properties is open ended. A provider
153 may very well specify input types and structures that libcrypto doesn't
154 know anything about.
155
156 Subset selections
157 Sometimes, an object has more than one subset of data that is
158 interesting to treat separately or together. It's possible to specify
159 what subsets are to be decoded, with a set of bits selection that are
160 passed in an int.
161
162 This set of bits depend entirely on what kind of provider-side object
163 is to be decoded. For example, those bits are assumed to be the same
164 as those used with provider-keymgmt(7) (see "Key Objects" in
165 provider-keymgmt(7)) when the object is an asymmetric keypair - e.g.,
166 OSSL_KEYMGMT_SELECT_PRIVATE_KEY if the object to be decoded is supposed
167 to contain private key components.
168
169 OSSL_FUNC_decoder_does_selection() should tell if a particular
170 implementation supports any of the combinations given by selection.
171
172 Context functions
173 OSSL_FUNC_decoder_newctx() returns a context to be used with the rest
174 of the functions.
175
176 OSSL_FUNC_decoder_freectx() frees the given ctx as created by
177 OSSL_FUNC_decoder_newctx().
178
179 OSSL_FUNC_decoder_set_ctx_params() sets context data according to
180 parameters from params that it recognises. Unrecognised parameters
181 should be ignored. Passing NULL for params should return true.
182
183 OSSL_FUNC_decoder_settable_ctx_params() returns a constant OSSL_PARAM
184 array describing the parameters that OSSL_FUNC_decoder_set_ctx_params()
185 can handle.
186
187 See OSSL_PARAM(3) for further details on the parameters structure used
188 by OSSL_FUNC_decoder_set_ctx_params() and
189 OSSL_FUNC_decoder_settable_ctx_params().
190
191 Export function
192 When a provider-native object is created by a decoder it would be
193 unsuitable for direct use with a foreign provider. The export function
194 allows for exporting the object into that foreign provider if the
195 foreign provider supports the type of the object and provides an import
196 function.
197
198 OSSL_FUNC_decoder_export_object() should export the object of size
199 objref_sz referenced by objref as an OSSL_PARAM array and pass that
200 into the export_cb as well as the given export_cbarg.
201
202 Decoding functions
203 OSSL_FUNC_decoder_decode() should decode the data as read from the
204 OSSL_CORE_BIO in to produce decoded data or an object to be passed as
205 reference in an OSSL_PARAM array along with possible other metadata
206 that was decoded from the input. This OSSL_PARAM array is then passed
207 to the data_cb callback. The selection bits, if relevant, should
208 determine what the input data should contain. The decoding functions
209 also take an OSSL_PASSPHRASE_CALLBACK function pointer along with a
210 pointer to application data cbarg, which should be used when a pass
211 phrase prompt is needed.
212
213 It's important to understand that the return value from this function
214 is interpreted as follows:
215
216 True (1)
217 This means "carry on the decoding process", and is meaningful even
218 though this function couldn't decode the input into anything,
219 because there may be another decoder implementation that can decode
220 it into something.
221
222 The data_cb callback should never be called when this function
223 can't decode the input into anything.
224
225 False (0)
226 This means "stop the decoding process", and is meaningful when the
227 input could be decoded into some sort of object that this function
228 understands, but further treatment of that object results into
229 errors that won't be possible for some other decoder implementation
230 to get a different result.
231
232 The conditions to stop the decoding process are at the discretion of
233 the implementation.
234
235 Decoder operation parameters
236 There are currently no operation parameters currently recognised by the
237 built-in decoders.
238
239 Parameters currently recognised by the built-in pass phrase callback:
240
241 "info" (OSSL_PASSPHRASE_PARAM_INFO) <UTF8 string>
242 A string of information that will become part of the pass phrase
243 prompt. This could be used to give the user information on what
244 kind of object it's being prompted for.
245
247 OSSL_FUNC_decoder_newctx() returns a pointer to a context, or NULL on
248 failure.
249
250 OSSL_FUNC_decoder_set_ctx_params() returns 1, unless a recognised
251 parameter was invalid or caused an error, for which 0 is returned.
252
253 OSSL_FUNC_decoder_settable_ctx_params() returns a pointer to an array
254 of constant OSSL_PARAM elements.
255
256 OSSL_FUNC_decoder_does_selection() returns 1 if the decoder
257 implementation supports any of the selection bits, otherwise 0.
258
259 OSSL_FUNC_decoder_decode() returns 1 to signal that the decoding
260 process should continue, or 0 to signal that it should stop.
261
263 provider(7)
264
266 The DECODER interface was introduced in OpenSSL 3.0.
267
269 Copyright 2019-2021 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 <https://www.openssl.org/source/license.html>.
275
276
277
2783.0.5 2022-11-01 PROVIDER-DECODER(7ossl)