provider-serializer.pod 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. =pod
  2. =head1 NAME
  3. provider-serializer - The SERIALIZER library E<lt>-E<gt> provider functions
  4. =head1 SYNOPSIS
  5. =begin comment
  6. Future development will also include deserializing functions.
  7. =end comment
  8. #include <openssl/core_dispatch.h>
  9. /*
  10. * None of these are actual functions, but are displayed like this for
  11. * the function signatures for functions that are offered as function
  12. * pointers in OSSL_DISPATCH arrays.
  13. */
  14. /* Functions to construct / destruct / manipulate the serializer context */
  15. void *OSSL_FUNC_serializer_newctx(void *provctx);
  16. void OSSL_FUNC_serializer_freectx(void *ctx);
  17. int OSSL_FUNC_serializer_set_ctx_params(void *ctx, const OSSL_PARAM params[]);
  18. const OSSL_PARAM *OSSL_FUNC_serializer_settable_ctx_params(void)
  19. /* Functions to serialize object data */
  20. int OSSL_FUNC_serializer_serialize_data(void *ctx, const OSSL_PARAM *data,
  21. OSSL_CORE_BIO *out,
  22. OSSL_PASSPHRASE_CALLBACK *cb,
  23. void *cbarg);
  24. int OSSL_FUNC_serializer_serialize_object(void *ctx, void *obj, OSSL_CORE_BIO *out,
  25. OSSL_PASSPHRASE_CALLBACK *cb,
  26. void *cbarg);
  27. =head1 DESCRIPTION
  28. The SERIALIZER is a generic method to serialize any set of object data
  29. in L<OSSL_PARAM(3)> array form, or any provider side object into
  30. serialized form, and write it to the given OSSL_CORE_BIO. If the caller wants
  31. to get the serialized stream to memory, it should provide a
  32. L<BIO_s_membuf(3)>.
  33. The serializer doesn't need to know more about the B<OSSL_CORE_BIO> pointer than
  34. being able to pass it to the appropriate BIO upcalls (see
  35. L<provider-base(7)/Core functions>).
  36. The serialization using the L<OSSL_PARAM(3)> array form allows a
  37. serializer to be used for data that's been exported from another
  38. provider, and thereby allow them to exist independently of each
  39. other.
  40. The serialization using a provider side object can only be safely used
  41. with provider data coming from the same provider, for example keys
  42. with the L<KEYMGMT|provider-keymgmt(7)> provider.
  43. All "functions" mentioned here are passed as function pointers between
  44. F<libcrypto> and the provider in B<OSSL_DISPATCH> arrays via
  45. B<OSSL_ALGORITHM> arrays that are returned by the provider's
  46. provider_query_operation() function
  47. (see L<provider-base(7)/Provider Functions>).
  48. All these "functions" have a corresponding function type definition
  49. named B<OSSL_{name}_fn>, and a helper function to retrieve the
  50. function pointer from a B<OSSL_DISPATCH> element named
  51. B<OSSL_FUNC_{name}>.
  52. For example, the "function" OSSL_FUNC_serializer_serialize_data() has these:
  53. typedef int
  54. (OSSL_FUNC_serializer_serialize_data_fn)(void *provctx,
  55. const OSSL_PARAM params[],
  56. OSSL_CORE_BIO *out);
  57. static ossl_inline OSSL_FUNC_serializer_serialize_data_fn
  58. OSSL_FUNC_serializer_serialize_data(const OSSL_DISPATCH *opf);
  59. B<OSSL_DISPATCH> arrays are indexed by numbers that are provided as
  60. macros in L<openssl-core_dispatch.h(7)>, as follows:
  61. OSSL_FUNC_serializer_newctx OSSL_FUNC_SERIALIZER_NEWCTX
  62. OSSL_FUNC_serializer_freectx OSSL_FUNC_SERIALIZER_FREECTX
  63. OSSL_FUNC_serializer_set_ctx_params OSSL_FUNC_SERIALIZER_SET_CTX_PARAMS
  64. OSSL_FUNC_serializer_settable_ctx_params OSSL_FUNC_SERIALIZER_SETTABLE_CTX_PARAMS
  65. OSSL_FUNC_serializer_serialize_data OSSL_FUNC_SERIALIZER_SERIALIZE_DATA
  66. OSSL_FUNC_serializer_serialize_object OSSL_FUNC_SERIALIZER_SERIALIZE_OBJECT
  67. =head2 Names and properties
  68. The name of an implementation should match the type of object it
  69. handles. For example, an implementation that serializes an RSA key
  70. should be named accordingly.
  71. To be able to specify exactly what serialization format and what type
  72. of data a serializer implementation is expected to handle, two
  73. additional properties may be given:
  74. =over 4
  75. =item format
  76. This property is used to specify what kind of output format the
  77. implementation produces. Currently known formats are:
  78. =over 4
  79. =item text
  80. An implementation with that format property value outputs human
  81. readable text, making that implementation suitable for C<-text> output
  82. in diverse L<openssl(1)> commands.
  83. =item pem
  84. An implementation with that format property value outputs PEM
  85. formatted data.
  86. =item der
  87. An implementation with that format property value outputs DER
  88. formatted data.
  89. =back
  90. =item type
  91. With objects that have multiple purposes, this can be used to specify
  92. the purpose type. The currently known use cases are asymmetric keys
  93. and key parameters, where the type can be one of:
  94. =over 4
  95. =item private
  96. An implementation with that format property value outputs a private
  97. key.
  98. =item public
  99. An implementation with that format property value outputs a public
  100. key.
  101. =item parameters
  102. An implementation with that format property value outputs key
  103. parameters.
  104. =back
  105. =back
  106. The possible values of both these properties is open ended. A
  107. provider may very well specify other formats that libcrypto doesn't
  108. know anything about.
  109. =head2 Context functions
  110. OSSL_FUNC_serializer_newctx() returns a context to be used with the rest of
  111. the functions.
  112. OSSL_FUNC_serializer_freectx() frees the given I<ctx>, if it was created by
  113. OSSL_FUNC_serializer_newctx().
  114. OSSL_FUNC_serializer_set_ctx_params() sets context data according to
  115. parameters from I<params> that it recognises. Unrecognised parameters
  116. should be ignored.
  117. OSSL_FUNC_serializer_settable_ctx_params() returns a constant B<OSSL_PARAM>
  118. array describing the parameters that OSSL_FUNC_serializer_set_ctx_params()
  119. can handle.
  120. See L<OSSL_PARAM(3)> for further details on the parameters structure used
  121. by OSSL_FUNC_serializer_set_ctx_params() and OSSL_FUNC_serializer_settable_ctx_params().
  122. =head2 Serializing functions
  123. =for comment There will be a "Deserializing functions" title as well
  124. OSSL_FUNC_serializer_serialize_data() should take an array of B<OSSL_PARAM>,
  125. I<data>, and if it contains the data necessary for the object type
  126. that the implementation handles, it should output the object in
  127. serialized form to the B<OSSL_CORE_BIO>.
  128. OSSL_FUNC_serializer_serialize_object() should take a pointer to an object
  129. that it knows intimately, and output that object in serialized form to
  130. the B<OSSL_CORE_BIO>. The caller I<must> ensure that this function is called
  131. with a pointer that the provider of this function is familiar with.
  132. It is not suitable to use with object pointers coming from other
  133. providers.
  134. Both serialization functions also take an B<OSSL_PASSPHRASE_CALLBACK>
  135. function pointer along with a pointer to application data I<cbarg>,
  136. which should be used when a pass phrase prompt is needed.
  137. =head2 Serializer parameters
  138. Parameters currently recognised by built-in serializers are as
  139. follows:
  140. =over 4
  141. =item "cipher" (B<OSSL_SERIALIZER_PARAM_CIPHER>) <UTF8 string>
  142. The name of the encryption cipher to be used when generating encrypted
  143. serialization. This is used when serializing private keys, as well as
  144. other objects that need protection.
  145. If this name is invalid for the serialization implementation, the
  146. implementation should refuse to perform the serialization, i.e.
  147. OSSL_FUNC_serializer_serialize_data() and OSSL_FUNC_serializer_serialize_object()
  148. should return an error.
  149. =item "properties" (B<OSSL_SERIALIZER_PARAM_PROPERTIES>) <UTF8 string>
  150. The properties to be queried when trying to fetch the algorithm given
  151. with the "cipher" parameter.
  152. This must be given together with the "cipher" parameter to be
  153. considered valid.
  154. The serialization implementation isn't obligated to use this value.
  155. However, it is recommended that implementations that do not handle
  156. property strings return an error on receiving this parameter unless
  157. its value NULL or the empty string.
  158. =item "passphrase" (B<OSSL_SERIALIZER_PARAM_PASS>) <octet string>
  159. A pass phrase provided by the application. When this is given, the
  160. built-in serializers will not attempt to use the passphrase callback.
  161. =back
  162. Parameters currently recognised by the built-in pass phrase callback:
  163. =over 4
  164. =item "info" (B<OSSL_PASSPHRASE_PARAM_INFO>) <UTF8 string>
  165. A string of information that will become part of the pass phrase
  166. prompt. This could be used to give the user information on what kind
  167. of object it's being prompted for.
  168. =back
  169. =head1 RETURN VALUES
  170. OSSL_FUNC_serializer_newctx() returns a pointer to a context, or NULL on
  171. failure.
  172. OSSL_FUNC_serializer_set_ctx_params() returns 1, unless a recognised
  173. parameters was invalid or caused an error, for which 0 is returned.
  174. OSSL_FUNC_serializer_settable_ctx_params() returns a pointer to an array of
  175. constant B<OSSL_PARAM> elements.
  176. OSSL_FUNC_serializer_serialize_data() and OSSL_FUNC_serializer_serialize_object()
  177. return 1 on success, or 0 on failure.
  178. =head1 SEE ALSO
  179. L<provider(7)>
  180. =head1 HISTORY
  181. The SERIALIZER interface was introduced in OpenSSL 3.0.
  182. =head1 COPYRIGHT
  183. Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved.
  184. Licensed under the Apache License 2.0 (the "License"). You may not use
  185. this file except in compliance with the License. You can obtain a copy
  186. in the file LICENSE in the source distribution or at
  187. L<https://www.openssl.org/source/license.html>.
  188. =cut