provider-decoder.7ossl 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. .\" -*- mode: troff; coding: utf-8 -*-
  2. .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43)
  3. .\"
  4. .\" Standard preamble:
  5. .\" ========================================================================
  6. .de Sp \" Vertical space (when we can't use .PP)
  7. .if t .sp .5v
  8. .if n .sp
  9. ..
  10. .de Vb \" Begin verbatim text
  11. .ft CW
  12. .nf
  13. .ne \\$1
  14. ..
  15. .de Ve \" End verbatim text
  16. .ft R
  17. .fi
  18. ..
  19. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
  20. .ie n \{\
  21. . ds C` ""
  22. . ds C' ""
  23. 'br\}
  24. .el\{\
  25. . ds C`
  26. . ds C'
  27. 'br\}
  28. .\"
  29. .\" Escape single quotes in literal strings from groff's Unicode transform.
  30. .ie \n(.g .ds Aq \(aq
  31. .el .ds Aq '
  32. .\"
  33. .\" If the F register is >0, we'll generate index entries on stderr for
  34. .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
  35. .\" entries marked with X<> in POD. Of course, you'll have to process the
  36. .\" output yourself in some meaningful fashion.
  37. .\"
  38. .\" Avoid warning from groff about undefined register 'F'.
  39. .de IX
  40. ..
  41. .nr rF 0
  42. .if \n(.g .if rF .nr rF 1
  43. .if (\n(rF:(\n(.g==0)) \{\
  44. . if \nF \{\
  45. . de IX
  46. . tm Index:\\$1\t\\n%\t"\\$2"
  47. ..
  48. . if !\nF==2 \{\
  49. . nr % 0
  50. . nr F 2
  51. . \}
  52. . \}
  53. .\}
  54. .rr rF
  55. .\" ========================================================================
  56. .\"
  57. .IX Title "PROVIDER-DECODER 7ossl"
  58. .TH PROVIDER-DECODER 7ossl 2025-01-17 3.4.0 OpenSSL
  59. .\" For nroff, turn off justification. Always turn off hyphenation; it makes
  60. .\" way too many mistakes in technical documents.
  61. .if n .ad l
  62. .nh
  63. .SH NAME
  64. provider\-decoder \- The OSSL_DECODER library <\-> provider functions
  65. .SH SYNOPSIS
  66. .IX Header "SYNOPSIS"
  67. .Vb 1
  68. \& #include <openssl/core_dispatch.h>
  69. \&
  70. \& /*
  71. \& * None of these are actual functions, but are displayed like this for
  72. \& * the function signatures for functions that are offered as function
  73. \& * pointers in OSSL_DISPATCH arrays.
  74. \& */
  75. \&
  76. \& /* Decoder parameter accessor and descriptor */
  77. \& const OSSL_PARAM *OSSL_FUNC_decoder_gettable_params(void *provctx);
  78. \& int OSSL_FUNC_decoder_get_params(OSSL_PARAM params[]);
  79. \&
  80. \& /* Functions to construct / destruct / manipulate the decoder context */
  81. \& void *OSSL_FUNC_decoder_newctx(void *provctx);
  82. \& void OSSL_FUNC_decoder_freectx(void *ctx);
  83. \& const OSSL_PARAM *OSSL_FUNC_decoder_settable_ctx_params(void *provctx);
  84. \& int OSSL_FUNC_decoder_set_ctx_params(void *ctx, const OSSL_PARAM params[]);
  85. \&
  86. \& /* Functions to check selection support */
  87. \& int OSSL_FUNC_decoder_does_selection(void *provctx, int selection);
  88. \&
  89. \& /* Functions to decode object data */
  90. \& int OSSL_FUNC_decoder_decode(void *ctx, OSSL_CORE_BIO *in,
  91. \& int selection,
  92. \& OSSL_CALLBACK *data_cb, void *data_cbarg,
  93. \& OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg);
  94. \&
  95. \& /* Functions to export a decoded object */
  96. \& int OSSL_FUNC_decoder_export_object(void *ctx,
  97. \& const void *objref, size_t objref_sz,
  98. \& OSSL_CALLBACK *export_cb,
  99. \& void *export_cbarg);
  100. .Ve
  101. .SH DESCRIPTION
  102. .IX Header "DESCRIPTION"
  103. \&\fIThe term "decode" is used throughout this manual. This includes but is
  104. not limited to deserialization as individual decoders can also do
  105. decoding into intermediate data formats.\fR
  106. .PP
  107. The DECODER operation is a generic method to create a provider-native
  108. object reference or intermediate decoded data from an encoded form
  109. read from the given \fBOSSL_CORE_BIO\fR. If the caller wants to decode
  110. data from memory, it should provide a \fBBIO_s_mem\fR\|(3) \fBBIO\fR. The decoded
  111. data or object reference is passed along with eventual metadata
  112. to the \fImetadata_cb\fR as \fBOSSL_PARAM\fR\|(3) parameters.
  113. .PP
  114. The decoder doesn't need to know more about the \fBOSSL_CORE_BIO\fR
  115. pointer than being able to pass it to the appropriate BIO upcalls (see
  116. "Core functions" in \fBprovider\-base\fR\|(7)).
  117. .PP
  118. The DECODER implementation may be part of a chain, where data is
  119. passed from one to the next. For example, there may be an
  120. implementation to decode an object from PEM to DER, and another one
  121. that decodes DER to a provider-native object.
  122. .PP
  123. The last decoding step in the decoding chain is usually supposed to create
  124. a provider-native object referenced by an object reference. To import
  125. that object into a different provider the \fBOSSL_FUNC_decoder_export_object()\fR
  126. can be called as the final step of the decoding process.
  127. .PP
  128. All "functions" mentioned here are passed as function pointers between
  129. \&\fIlibcrypto\fR and the provider in \fBOSSL_DISPATCH\fR\|(3) arrays via
  130. \&\fBOSSL_ALGORITHM\fR\|(3) arrays that are returned by the provider's
  131. \&\fBprovider_query_operation()\fR function
  132. (see "Provider Functions" in \fBprovider\-base\fR\|(7)).
  133. .PP
  134. All these "functions" have a corresponding function type definition
  135. named \fBOSSL_FUNC_{name}_fn\fR, and a helper function to retrieve the
  136. function pointer from an \fBOSSL_DISPATCH\fR\|(3) element named
  137. \&\fBOSSL_FUNC_{name}\fR.
  138. For example, the "function" \fBOSSL_FUNC_decoder_decode()\fR has these:
  139. .PP
  140. .Vb 7
  141. \& typedef int
  142. \& (OSSL_FUNC_decoder_decode_fn)(void *ctx, OSSL_CORE_BIO *in,
  143. \& int selection,
  144. \& OSSL_CALLBACK *data_cb, void *data_cbarg,
  145. \& OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg);
  146. \& static ossl_inline OSSL_FUNC_decoder_decode_fn*
  147. \& OSSL_FUNC_decoder_decode(const OSSL_DISPATCH *opf);
  148. .Ve
  149. .PP
  150. \&\fBOSSL_DISPATCH\fR\|(3) arrays are indexed by numbers that are provided as
  151. macros in \fBopenssl\-core_dispatch.h\fR\|(7), as follows:
  152. .PP
  153. .Vb 2
  154. \& OSSL_FUNC_decoder_get_params OSSL_FUNC_DECODER_GET_PARAMS
  155. \& OSSL_FUNC_decoder_gettable_params OSSL_FUNC_DECODER_GETTABLE_PARAMS
  156. \&
  157. \& OSSL_FUNC_decoder_newctx OSSL_FUNC_DECODER_NEWCTX
  158. \& OSSL_FUNC_decoder_freectx OSSL_FUNC_DECODER_FREECTX
  159. \& OSSL_FUNC_decoder_set_ctx_params OSSL_FUNC_DECODER_SET_CTX_PARAMS
  160. \& OSSL_FUNC_decoder_settable_ctx_params OSSL_FUNC_DECODER_SETTABLE_CTX_PARAMS
  161. \&
  162. \& OSSL_FUNC_decoder_does_selection OSSL_FUNC_DECODER_DOES_SELECTION
  163. \&
  164. \& OSSL_FUNC_decoder_decode OSSL_FUNC_DECODER_DECODE
  165. \&
  166. \& OSSL_FUNC_decoder_export_object OSSL_FUNC_DECODER_EXPORT_OBJECT
  167. .Ve
  168. .SS "Names and properties"
  169. .IX Subsection "Names and properties"
  170. The name of an implementation should match the target type of object
  171. it decodes. For example, an implementation that decodes an RSA key
  172. should be named "RSA". Likewise, an implementation that decodes DER data
  173. from PEM input should be named "DER".
  174. .PP
  175. Properties can be used to further specify details about an implementation:
  176. .IP input 4
  177. .IX Item "input"
  178. This property is used to specify what format of input the implementation
  179. can decode.
  180. .Sp
  181. This property is \fImandatory\fR.
  182. .Sp
  183. OpenSSL providers recognize the following input types:
  184. .RS 4
  185. .IP pem 4
  186. .IX Item "pem"
  187. An implementation with that input type decodes PEM formatted data.
  188. .IP der 4
  189. .IX Item "der"
  190. An implementation with that input type decodes DER formatted data.
  191. .IP msblob 4
  192. .IX Item "msblob"
  193. An implementation with that input type decodes MSBLOB formatted data.
  194. .IP pvk 4
  195. .IX Item "pvk"
  196. An implementation with that input type decodes PVK formatted data.
  197. .RE
  198. .RS 4
  199. .RE
  200. .IP structure 4
  201. .IX Item "structure"
  202. This property is used to specify the structure that the decoded data is
  203. expected to have.
  204. .Sp
  205. This property is \fIoptional\fR.
  206. .Sp
  207. Structures currently recognised by built-in decoders:
  208. .RS 4
  209. .IP """type-specific""" 4
  210. .IX Item """type-specific"""
  211. Type specific structure.
  212. .IP """pkcs8""" 4
  213. .IX Item """pkcs8"""
  214. Structure according to the PKCS#8 specification.
  215. .IP """SubjectPublicKeyInfo""" 4
  216. .IX Item """SubjectPublicKeyInfo"""
  217. Encoding of public keys according to the Subject Public Key Info of RFC 5280.
  218. .RE
  219. .RS 4
  220. .RE
  221. .PP
  222. The possible values of both these properties is open ended. A provider may
  223. very well specify input types and structures that libcrypto doesn't know
  224. anything about.
  225. .SS "Subset selections"
  226. .IX Subsection "Subset selections"
  227. Sometimes, an object has more than one subset of data that is interesting to
  228. treat separately or together. It's possible to specify what subsets are to
  229. be decoded, with a set of bits \fIselection\fR that are passed in an \fBint\fR.
  230. .PP
  231. This set of bits depend entirely on what kind of provider-side object is
  232. to be decoded. For example, those bits are assumed to be the same as those
  233. used with \fBprovider\-keymgmt\fR\|(7) (see "Key Objects" in \fBprovider\-keymgmt\fR\|(7)) when
  234. the object is an asymmetric keypair \- e.g., \fBOSSL_KEYMGMT_SELECT_PRIVATE_KEY\fR
  235. if the object to be decoded is supposed to contain private key components.
  236. .PP
  237. \&\fBOSSL_FUNC_decoder_does_selection()\fR should tell if a particular implementation
  238. supports any of the combinations given by \fIselection\fR.
  239. .SS "Context functions"
  240. .IX Subsection "Context functions"
  241. \&\fBOSSL_FUNC_decoder_newctx()\fR returns a context to be used with the rest of
  242. the functions.
  243. .PP
  244. \&\fBOSSL_FUNC_decoder_freectx()\fR frees the given \fIctx\fR as created by
  245. \&\fBOSSL_FUNC_decoder_newctx()\fR.
  246. .PP
  247. \&\fBOSSL_FUNC_decoder_set_ctx_params()\fR sets context data according to parameters
  248. from \fIparams\fR that it recognises. Unrecognised parameters should be
  249. ignored.
  250. Passing NULL for \fIparams\fR should return true.
  251. .PP
  252. \&\fBOSSL_FUNC_decoder_settable_ctx_params()\fR returns a constant \fBOSSL_PARAM\fR\|(3)
  253. array describing the parameters that \fBOSSL_FUNC_decoder_set_ctx_params()\fR
  254. can handle.
  255. .PP
  256. See \fBOSSL_PARAM\fR\|(3) for further details on the parameters structure used by
  257. \&\fBOSSL_FUNC_decoder_set_ctx_params()\fR and \fBOSSL_FUNC_decoder_settable_ctx_params()\fR.
  258. .SS "Export function"
  259. .IX Subsection "Export function"
  260. When a provider-native object is created by a decoder it would be unsuitable
  261. for direct use with a foreign provider. The export function allows for
  262. exporting the object into that foreign provider if the foreign provider
  263. supports the type of the object and provides an import function.
  264. .PP
  265. \&\fBOSSL_FUNC_decoder_export_object()\fR should export the object of size \fIobjref_sz\fR
  266. referenced by \fIobjref\fR as an \fBOSSL_PARAM\fR\|(3) array and pass that into the
  267. \&\fIexport_cb\fR as well as the given \fIexport_cbarg\fR.
  268. .SS "Decoding functions"
  269. .IX Subsection "Decoding functions"
  270. \&\fBOSSL_FUNC_decoder_decode()\fR should decode the data as read from
  271. the \fBOSSL_CORE_BIO\fR \fIin\fR to produce decoded data or an object to be
  272. passed as reference in an \fBOSSL_PARAM\fR\|(3) array along with possible other
  273. metadata that was decoded from the input. This \fBOSSL_PARAM\fR\|(3) array is
  274. then passed to the \fIdata_cb\fR callback. The \fIselection\fR bits,
  275. if relevant, should determine what the input data should contain.
  276. The decoding functions also take an \fBOSSL_PASSPHRASE_CALLBACK\fR\|(3) function
  277. pointer along with a pointer to application data \fIcbarg\fR, which should be
  278. used when a pass phrase prompt is needed.
  279. .PP
  280. It's important to understand that the return value from this function is
  281. interpreted as follows:
  282. .IP "True (1)" 4
  283. .IX Item "True (1)"
  284. This means "carry on the decoding process", and is meaningful even though
  285. this function couldn't decode the input into anything, because there may be
  286. another decoder implementation that can decode it into something.
  287. .Sp
  288. The \fIdata_cb\fR callback should never be called when this function can't
  289. decode the input into anything.
  290. .IP "False (0)" 4
  291. .IX Item "False (0)"
  292. This means "stop the decoding process", and is meaningful when the input
  293. could be decoded into some sort of object that this function understands,
  294. but further treatment of that object results into errors that won't be
  295. possible for some other decoder implementation to get a different result.
  296. .PP
  297. The conditions to stop the decoding process are at the discretion of the
  298. implementation.
  299. .SS "Decoder operation parameters"
  300. .IX Subsection "Decoder operation parameters"
  301. There are currently no operation parameters currently recognised by the
  302. built-in decoders.
  303. .PP
  304. Parameters currently recognised by the built-in pass phrase callback:
  305. .IP """info"" (\fBOSSL_PASSPHRASE_PARAM_INFO\fR) <UTF8 string>" 4
  306. .IX Item """info"" (OSSL_PASSPHRASE_PARAM_INFO) <UTF8 string>"
  307. A string of information that will become part of the pass phrase
  308. prompt. This could be used to give the user information on what kind
  309. of object it's being prompted for.
  310. .SH "RETURN VALUES"
  311. .IX Header "RETURN VALUES"
  312. \&\fBOSSL_FUNC_decoder_newctx()\fR returns a pointer to a context, or NULL on
  313. failure.
  314. .PP
  315. \&\fBOSSL_FUNC_decoder_set_ctx_params()\fR returns 1, unless a recognised
  316. parameter was invalid or caused an error, for which 0 is returned.
  317. .PP
  318. \&\fBOSSL_FUNC_decoder_settable_ctx_params()\fR returns a pointer to an array of
  319. constant \fBOSSL_PARAM\fR\|(3) elements.
  320. .PP
  321. \&\fBOSSL_FUNC_decoder_does_selection()\fR returns 1 if the decoder implementation
  322. supports any of the \fIselection\fR bits, otherwise 0.
  323. .PP
  324. \&\fBOSSL_FUNC_decoder_decode()\fR returns 1 to signal that the decoding process
  325. should continue, or 0 to signal that it should stop.
  326. .SH "SEE ALSO"
  327. .IX Header "SEE ALSO"
  328. \&\fBprovider\fR\|(7)
  329. .SH HISTORY
  330. .IX Header "HISTORY"
  331. The DECODER interface was introduced in OpenSSL 3.0.
  332. .SH COPYRIGHT
  333. .IX Header "COPYRIGHT"
  334. Copyright 2019\-2023 The OpenSSL Project Authors. All Rights Reserved.
  335. .PP
  336. Licensed under the Apache License 2.0 (the "License"). You may not use
  337. this file except in compliance with the License. You can obtain a copy
  338. in the file LICENSE in the source distribution or at
  339. <https://www.openssl.org/source/license.html>.