OSSL_SERIALIZER_CTX_new_by_EVP_PKEY.pod 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. =pod
  2. =head1 NAME
  3. OSSL_SERIALIZER_CTX_new_by_EVP_PKEY,
  4. OSSL_SERIALIZER_CTX_set_cipher,
  5. OSSL_SERIALIZER_CTX_set_passphrase,
  6. OSSL_SERIALIZER_CTX_set_passphrase_cb,
  7. OSSL_SERIALIZER_CTX_set_passphrase_ui,
  8. OSSL_SERIALIZER_PUBKEY_TO_PEM_PQ,
  9. OSSL_SERIALIZER_PrivateKey_TO_PEM_PQ,
  10. OSSL_SERIALIZER_Parameters_TO_PEM_PQ,
  11. OSSL_SERIALIZER_PUBKEY_TO_DER_PQ,
  12. OSSL_SERIALIZER_PrivateKey_TO_DER_PQ,
  13. OSSL_SERIALIZER_Parameters_TO_DER_PQ,
  14. OSSL_SERIALIZER_PUBKEY_TO_TEXT_PQ,
  15. OSSL_SERIALIZER_PrivateKey_TO_TEXT_PQ,
  16. OSSL_SERIALIZER_Parameters_TO_TEXT_PQ
  17. - Serializer routines to serialize EVP_PKEYs
  18. =head1 SYNOPSIS
  19. #include <openssl/serializer.h>
  20. OSSL_SERIALIZER_CTX *OSSL_SERIALIZER_CTX_new_by_EVP_PKEY(const EVP_PKEY *pkey,
  21. const char *propquery);
  22. int OSSL_SERIALIZER_CTX_set_cipher(OSSL_SERIALIZER_CTX *ctx,
  23. const char *cipher_name,
  24. const char *propquery);
  25. int OSSL_SERIALIZER_CTX_set_passphrase(OSSL_SERIALIZER_CTX *ctx,
  26. const unsigned char *kstr,
  27. size_t klen);
  28. int OSSL_SERIALIZER_CTX_set_passphrase_cb(OSSL_SERIALIZER_CTX *ctx, int enc,
  29. pem_password_cb *cb, void *cbarg);
  30. int OSSL_SERIALIZER_CTX_set_passphrase_ui(OSSL_SERIALIZER_CTX *ctx,
  31. const UI_METHOD *ui_method,
  32. void *ui_data);
  33. #define OSSL_SERIALIZER_PUBKEY_TO_PEM_PQ "format=pem,type=public"
  34. #define OSSL_SERIALIZER_PrivateKey_TO_PEM_PQ "format=pem,type=private"
  35. #define OSSL_SERIALIZER_Parameters_TO_PEM_PQ "format=pem,type=parameters"
  36. #define OSSL_SERIALIZER_PUBKEY_TO_DER_PQ "format=der,type=public"
  37. #define OSSL_SERIALIZER_PrivateKey_TO_DER_PQ "format=der,type=private"
  38. #define OSSL_SERIALIZER_Parameters_TO_DER_PQ "format=der,type=parameters"
  39. #define OSSL_SERIALIZER_PUBKEY_TO_TEXT_PQ "format=text,type=public"
  40. #define OSSL_SERIALIZER_PrivateKey_TO_TEXT_PQ "format=text,type=private"
  41. #define OSSL_SERIALIZER_Parameters_TO_TEXT_PQ "format=text,type=parameters"
  42. =head1 DESCRIPTION
  43. OSSL_SERIALIZER_CTX_new_by_EVP_PKEY() creates a B<OSSL_SERIALIZER_CTX>
  44. with a suitable attached output routine for B<EVP_PKEY>s. It will
  45. search for a serializer implementation that matches the algorithm of
  46. the B<EVP_PKEY> and the property query given with I<propquery>. It
  47. will prefer to find a serializer from the same provider as the key
  48. data of the B<EVP_PKEY> itself, but failing that, it will choose the
  49. first serializer that supplies a generic serializing function.
  50. If no suitable serializer was found, OSSL_SERIALIZER_CTX_new_by_EVP_PKEY()
  51. still creates a B<OSSL_SERIALIZER_CTX>, but with no associated
  52. serializer (L<OSSL_SERIALIZER_CTX_get_serializer(3)> returns NULL).
  53. This helps the caller distinguish between an error when creating
  54. the B<OSSL_SERIALIZER_CTX>, and the lack the serializer support and
  55. act accordingly.
  56. OSSL_SERIALIZER_CTX_set_cipher() tells the implementation what cipher
  57. should be used to encrypt serialized keys. The cipher is given by
  58. name I<cipher_name>. The interpretation of that I<cipher_name> is
  59. implementation dependent. The implementation may implement the digest
  60. directly itself or by other implementations, or it may choose to fetch
  61. it. If the implementation supports fetching the cipher, then it may
  62. use I<propquery> as properties to be queried for when fetching.
  63. I<cipher_name> may also be NULL, which will result in unencrypted
  64. serialization.
  65. OSSL_SERIALIZER_CTX_set_passphrase() gives the implementation a
  66. pass phrase to use when encrypting the serialized private key.
  67. Alternatively, a pass phrase callback may be specified with the
  68. following functions.
  69. OSSL_SERIALIZER_CTX_set_passphrase_cb() and
  70. OSSL_SERIALIZER_CTX_set_passphrase_ui() sets up a callback method that
  71. the implementation can use to prompt for a pass phrase.
  72. =for comment Note that the callback method is called indirectly,
  73. through an internal B<OSSL_PASSPHRASE_CALLBACK> function.
  74. The macros B<OSSL_SERIALIZER_PUBKEY_TO_PEM_PQ>,
  75. B<OSSL_SERIALIZER_PrivateKey_TO_PEM_PQ>,
  76. B<OSSL_SERIALIZER_Parameters_TO_PEM_PQ>,
  77. B<OSSL_SERIALIZER_PUBKEY_TO_DER_PQ>,
  78. B<OSSL_SERIALIZER_PrivateKey_TO_DER_PQ>,
  79. B<OSSL_SERIALIZER_Parameters_TO_DER_PQ>,
  80. B<OSSL_SERIALIZER_PUBKEY_TO_TEXT_PQ>,
  81. B<OSSL_SERIALIZER_PrivateKey_TO_TEXT_PQ>,
  82. B<OSSL_SERIALIZER_Parameters_TO_TEXT_PQ> are convenience macros with
  83. property queries to serialize the B<EVP_PKEY> as a public key, private
  84. key or parameters to B<PEM>, to B<DER>, or to text.
  85. =head1 RETURN VALUES
  86. OSSL_SERIALIZER_CTX_new_by_EVP_PKEY() returns a pointer to a
  87. B<OSSL_SERIALIZER_CTX>, or NULL if it couldn't be created.
  88. OSSL_SERIALIZER_CTX_set_cipher(),
  89. OSSL_SERIALIZER_CTX_set_passphrase(),
  90. OSSL_SERIALIZER_CTX_set_passphrase_cb(), and
  91. OSSL_SERIALIZER_CTX_set_passphrase_ui() all return 1 on success, or 0
  92. on failure.
  93. =head1 NOTES
  94. Parts of the function and macro names are made to match already
  95. existing OpenSSL names.
  96. B<EVP_PKEY> in OSSL_SERIALIZER_CTX_new_by_EVP_PKEY() matches the type
  97. name, thus making for the naming pattern
  98. B<OSSL_SERIALIZER_CTX_new_by_I<TYPE>>() when new types are handled.
  99. B<PUBKEY>, B<PrivateKey> and B<Parameters> in the macro names match
  100. the B<I<TYPE>> part of B<PEM_write_bio_I<TYPE>> functions as well
  101. as B<i2d_I<TYPE>_bio> functions.
  102. =head1 SEE ALSO
  103. L<provider(7)>, L<OSSL_SERIALIZER(3)>, L<OSSL_SERIALIZER_CTX(3)>
  104. =head1 HISTORY
  105. The functions described here were added in OpenSSL 3.0.
  106. =head1 COPYRIGHT
  107. Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved.
  108. Licensed under the Apache License 2.0 (the "License"). You may not use
  109. this file except in compliance with the License. You can obtain a copy
  110. in the file LICENSE in the source distribution or at
  111. L<https://www.openssl.org/source/license.html>.
  112. =cut