OSSL_SERIALIZER_CTX_new_by_EVP_PKEY.pod 5.3 KB

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