OSSL_ENCODER_CTX_new_by_EVP_PKEY.pod 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. =pod
  2. =head1 NAME
  3. OSSL_ENCODER_CTX_new_by_EVP_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_by_EVP_PKEY(const EVP_PKEY *pkey,
  14. const char *output_type, int selection,
  15. OPENSSL_CTX *libctx, const char *propquery);
  16. int OSSL_ENCODER_CTX_set_cipher(OSSL_ENCODER_CTX *ctx,
  17. const char *cipher_name,
  18. const char *propquery);
  19. int OSSL_ENCODER_CTX_set_passphrase(OSSL_ENCODER_CTX *ctx,
  20. const unsigned char *kstr,
  21. size_t klen);
  22. int OSSL_ENCODER_CTX_set_pem_password_cb(OSSL_ENCODER_CTX *ctx,
  23. pem_password_cb *cb, void *cbarg);
  24. int OSSL_ENCODER_CTX_set_passphrase_ui(OSSL_ENCODER_CTX *ctx,
  25. const UI_METHOD *ui_method,
  26. void *ui_data);
  27. int OSSL_ENCODER_CTX_set_passphrase_cb(OSSL_ENCODER_CTX *ctx,
  28. OSSL_PASSPHRASE_CALLBACK *cb,
  29. void *cbarg);
  30. =head1 DESCRIPTION
  31. OSSL_ENCODER_CTX_new_by_EVP_PKEY() is a utility function that creates a
  32. B<OSSL_ENCODER_CTX>, finds all applicable encoder implementations and sets
  33. them up, so almost all the caller has to do next is call functions like
  34. L<OSSL_ENCODER_to_bio(3)>.
  35. Internally, OSSL_ENCODER_CTX_new_by_EVP_PKEY() uses the names from the
  36. L<EVP_KEYMGMT(3)> implementation associated with I<pkey> to build a list of
  37. applicable encoder implementations that are used to process the I<pkey> into
  38. the encoding named by I<output_type>. All these implementations are
  39. implicitly fetched using I<libctx> and I<propquery>.
  40. If no suitable encoder implementation is found,
  41. OSSL_ENCODER_CTX_new_by_EVP_PKEY() still creates a B<OSSL_ENCODER_CTX>, but
  42. with no associated encoder (L<OSSL_ENCODER_CTX_get_num_encoders(3)> returns
  43. zero). This helps the caller to distinguish between an error when creating
  44. the B<OSSL_ENCODER_CTX> and missing encoder implementation, and allows it to
  45. act accordingly.
  46. OSSL_ENCODER_CTX_set_cipher() tells the implementation what cipher
  47. should be used to encrypt encoded keys. The cipher is given by
  48. name I<cipher_name>. The interpretation of that I<cipher_name> is
  49. implementation dependent. The implementation may implement the cipher
  50. directly itself or by other implementations, or it may choose to fetch
  51. it. If the implementation supports fetching the cipher, then it may
  52. use I<propquery> as properties to be queried for when fetching.
  53. I<cipher_name> may also be NULL, which will result in unencrypted
  54. encoding.
  55. OSSL_ENCODER_CTX_set_passphrase() gives the implementation a
  56. pass phrase to use when encrypting the encoded private key.
  57. Alternatively, a pass phrase callback may be specified with the
  58. following functions.
  59. OSSL_ENCODER_CTX_set_pem_password_cb(), OSSL_ENCODER_CTX_set_passphrase_ui()
  60. and OSSL_ENCODER_CTX_set_passphrase_cb() sets up a callback method that the
  61. implementation can use to prompt for a pass phrase, giving the caller the
  62. choice of prefered pass phrase callback form. These are called indirectly,
  63. through an internal B<OSSL_PASSPHRASE_CALLBACK> function.
  64. =head1 RETURN VALUES
  65. OSSL_ENCODER_CTX_new_by_EVP_PKEY() returns a pointer to a
  66. B<OSSL_ENCODER_CTX>, or NULL if it couldn't be created.
  67. OSSL_ENCODER_CTX_set_cipher(), OSSL_ENCODER_CTX_set_passphrase(),
  68. OSSL_ENCODER_CTX_set_pem_password_cb(), OSSL_ENCODER_CTX_set_passphrase_ui()
  69. and OSSL_ENCODER_CTX_set_passphrase_cb() all return 1 on success, or 0 on
  70. failure.
  71. =head1 NOTES
  72. Parts of the function names are made to match already existing OpenSSL
  73. names.
  74. B<EVP_PKEY> in OSSL_ENCODER_CTX_new_by_EVP_PKEY() matches the type name,
  75. thus making for the naming pattern B<OSSL_ENCODER_CTX_new_by_I<TYPE>>() when
  76. new types are handled.
  77. =head1 SEE ALSO
  78. L<provider(7)>, L<OSSL_ENCODER(3)>, L<OSSL_ENCODER_CTX(3)>
  79. =head1 HISTORY
  80. The functions described here were added in OpenSSL 3.0.
  81. =head1 COPYRIGHT
  82. Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved.
  83. Licensed under the Apache License 2.0 (the "License"). You may not use
  84. this file except in compliance with the License. You can obtain a copy
  85. in the file LICENSE in the source distribution or at
  86. L<https://www.openssl.org/source/license.html>.
  87. =cut