OSSL_ENCODER_CTX_new_for_pkey.pod 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. =pod
  2. =head1 NAME
  3. OSSL_ENCODER_CTX_new_for_pkey,
  4. OSSL_ENCODER_CTX_set_cipher,
  5. OSSL_ENCODER_CTX_set_passphrase,
  6. OSSL_ENCODER_CTX_set_pem_password_cb,
  7. OSSL_ENCODER_CTX_set_passphrase_cb,
  8. OSSL_ENCODER_CTX_set_passphrase_ui
  9. - Encoder routines to encode EVP_PKEYs
  10. =head1 SYNOPSIS
  11. #include <openssl/encoder.h>
  12. OSSL_ENCODER_CTX *
  13. OSSL_ENCODER_CTX_new_for_pkey(const EVP_PKEY *pkey, int selection,
  14. const char *output_type,
  15. const char *output_structure,
  16. const char *propquery);
  17. int OSSL_ENCODER_CTX_set_cipher(OSSL_ENCODER_CTX *ctx,
  18. const char *cipher_name,
  19. const char *propquery);
  20. int OSSL_ENCODER_CTX_set_passphrase(OSSL_ENCODER_CTX *ctx,
  21. const unsigned char *kstr,
  22. size_t klen);
  23. int OSSL_ENCODER_CTX_set_pem_password_cb(OSSL_ENCODER_CTX *ctx,
  24. pem_password_cb *cb, void *cbarg);
  25. int OSSL_ENCODER_CTX_set_passphrase_ui(OSSL_ENCODER_CTX *ctx,
  26. const UI_METHOD *ui_method,
  27. void *ui_data);
  28. int OSSL_ENCODER_CTX_set_passphrase_cb(OSSL_ENCODER_CTX *ctx,
  29. OSSL_PASSPHRASE_CALLBACK *cb,
  30. void *cbarg);
  31. =head1 DESCRIPTION
  32. OSSL_ENCODER_CTX_new_for_pkey() is a utility function that creates a
  33. B<OSSL_ENCODER_CTX>, finds all applicable encoder implementations and sets
  34. them up, so almost all the caller has to do next is call functions like
  35. L<OSSL_ENCODER_to_bio(3)>. I<output_type> determines the final output
  36. encoding, and I<selection> can be used to select what parts of the I<pkey>
  37. should be included in the output. I<output_type> is further discussed in
  38. L</Output types> below, and I<selection> is further described in
  39. L</Selections>.
  40. Internally, OSSL_ENCODER_CTX_new_for_pkey() uses the names from the
  41. L<EVP_KEYMGMT(3)> implementation associated with I<pkey> to build a list of
  42. applicable encoder implementations that are used to process the I<pkey> into
  43. the encoding named by I<output_type>, with the outermost structure named by
  44. I<output_structure> if that's relevant. All these implementations are
  45. implicitly fetched, with I<propquery> for finer selection.
  46. If no suitable encoder implementation is found,
  47. OSSL_ENCODER_CTX_new_for_pkey() still creates a B<OSSL_ENCODER_CTX>, but
  48. with no associated encoder (L<OSSL_ENCODER_CTX_get_num_encoders(3)> returns
  49. zero). This helps the caller to distinguish between an error when creating
  50. the B<OSSL_ENCODER_CTX> and missing encoder implementation, and allows it to
  51. act accordingly.
  52. OSSL_ENCODER_CTX_set_cipher() tells the implementation what cipher
  53. should be used to encrypt encoded keys. The cipher is given by
  54. name I<cipher_name>. The interpretation of that I<cipher_name> is
  55. implementation dependent. The implementation may implement the cipher
  56. directly itself or by other implementations, or it may choose to fetch
  57. it. If the implementation supports fetching the cipher, then it may
  58. use I<propquery> as properties to be queried for when fetching.
  59. I<cipher_name> may also be NULL, which will result in unencrypted
  60. encoding.
  61. OSSL_ENCODER_CTX_set_passphrase() gives the implementation a
  62. pass phrase to use when encrypting the encoded private key.
  63. Alternatively, a pass phrase callback may be specified with the
  64. following functions.
  65. OSSL_ENCODER_CTX_set_pem_password_cb(), OSSL_ENCODER_CTX_set_passphrase_ui()
  66. and OSSL_ENCODER_CTX_set_passphrase_cb() sets up a callback method that the
  67. implementation can use to prompt for a pass phrase, giving the caller the
  68. choice of preferred pass phrase callback form. These are called indirectly,
  69. through an internal B<OSSL_PASSPHRASE_CALLBACK> function.
  70. =head2 Output types
  71. The possible B<EVP_PKEY> output types depends on the available
  72. implementations.
  73. OpenSSL has built in implementations for the following output types:
  74. =over 4
  75. =item C<TEXT>
  76. The output is a human readable description of the key.
  77. L<EVP_PKEY_print_private(3)>, L<EVP_PKEY_print_public(3)> and
  78. L<EVP_PKEY_print_params(3)> use this for their output.
  79. =item C<DER>
  80. The output is the DER encoding of the I<selection> of the I<pkey>.
  81. =item C<PEM>
  82. The output is the I<selection> of the I<pkey> in PEM format.
  83. =back
  84. =head2 Selections
  85. I<selection> can be any one of the values described in
  86. L<EVP_PKEY_fromdata(3)/Selections>.
  87. These are only 'hints' since the encoder implementations are free to
  88. determine what makes sense to include in the output, and this may depend on
  89. the desired output. For example, an EC key in a PKCS#8 structure doesn't
  90. usually include the public key.
  91. =head1 RETURN VALUES
  92. OSSL_ENCODER_CTX_new_for_pkey() returns a pointer to an B<OSSL_ENCODER_CTX>,
  93. or NULL if it couldn't be created.
  94. OSSL_ENCODER_CTX_set_cipher(), OSSL_ENCODER_CTX_set_passphrase(),
  95. OSSL_ENCODER_CTX_set_pem_password_cb(), OSSL_ENCODER_CTX_set_passphrase_ui()
  96. and OSSL_ENCODER_CTX_set_passphrase_cb() all return 1 on success, or 0 on
  97. failure.
  98. =head1 SEE ALSO
  99. L<provider(7)>, L<OSSL_ENCODER(3)>, L<OSSL_ENCODER_CTX(3)>
  100. =head1 HISTORY
  101. The functions described here were added in OpenSSL 3.0.
  102. =head1 COPYRIGHT
  103. Copyright 2019-2022 The OpenSSL Project Authors. All Rights Reserved.
  104. Licensed under the Apache License 2.0 (the "License"). You may not use
  105. this file except in compliance with the License. You can obtain a copy
  106. in the file LICENSE in the source distribution or at
  107. L<https://www.openssl.org/source/license.html>.
  108. =cut