provider-decoder.pod 11 KB

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