SSL_CTX_set_default_passwd_cb.pod 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. =pod
  2. =head1 NAME
  3. SSL_CTX_set_default_passwd_cb, SSL_CTX_set_default_passwd_cb_userdata,
  4. SSL_CTX_get_default_passwd_cb, SSL_CTX_get_default_passwd_cb_userdata,
  5. SSL_set_default_passwd_cb, SSL_set_default_passwd_cb_userdata,
  6. SSL_get_default_passwd_cb, SSL_get_default_passwd_cb_userdata - set or
  7. get passwd callback for encrypted PEM file handling
  8. =head1 SYNOPSIS
  9. #include <openssl/ssl.h>
  10. void SSL_CTX_set_default_passwd_cb(SSL_CTX *ctx, pem_password_cb *cb);
  11. void SSL_CTX_set_default_passwd_cb_userdata(SSL_CTX *ctx, void *u);
  12. pem_password_cb *SSL_CTX_get_default_passwd_cb(SSL_CTX *ctx);
  13. void *SSL_CTX_get_default_passwd_cb_userdata(SSL_CTX *ctx);
  14. void SSL_set_default_passwd_cb(SSL *s, pem_password_cb *cb);
  15. void SSL_set_default_passwd_cb_userdata(SSL *s, void *u);
  16. pem_password_cb *SSL_get_default_passwd_cb(SSL *s);
  17. void *SSL_get_default_passwd_cb_userdata(SSL *s);
  18. =head1 DESCRIPTION
  19. SSL_CTX_set_default_passwd_cb() sets the default password callback called
  20. when loading/storing a PEM certificate with encryption.
  21. SSL_CTX_set_default_passwd_cb_userdata() sets a pointer to userdata, B<u>,
  22. which will be provided to the password callback on invocation.
  23. SSL_CTX_get_default_passwd_cb() returns a function pointer to the password
  24. callback currently set in B<ctx>. If no callback was explicitly set, the
  25. NULL pointer is returned.
  26. SSL_CTX_get_default_passwd_cb_userdata() returns a pointer to the userdata
  27. currently set in B<ctx>. If no userdata was explicitly set, the NULL pointer
  28. is returned.
  29. SSL_set_default_passwd_cb(), SSL_set_default_passwd_cb_userdata(),
  30. SSL_get_default_passwd_cb() and SSL_get_default_passwd_cb_userdata() perform
  31. the same function as their SSL_CTX counterparts, but using an SSL object.
  32. The password callback, which must be provided by the application, hands back the
  33. password to be used during decryption.
  34. On invocation a pointer to userdata
  35. is provided. The function must store the password into the provided buffer
  36. B<buf> which is of size B<size>. The actual length of the password must
  37. be returned to the calling function. B<rwflag> indicates whether the
  38. callback is used for reading/decryption (rwflag=0) or writing/encryption
  39. (rwflag=1).
  40. For more details, see L<pem_password_cb(3)>.
  41. =head1 NOTES
  42. When loading or storing private keys, a password might be supplied to
  43. protect the private key. The way this password can be supplied may depend
  44. on the application. If only one private key is handled, it can be practical
  45. to have the callback handle the password dialog interactively. If several
  46. keys have to be handled, it can be practical to ask for the password once,
  47. then keep it in memory and use it several times. In the last case, the
  48. password could be stored into the userdata storage and the
  49. callback only returns the password already stored.
  50. When asking for the password interactively, the callback can use
  51. B<rwflag> to check, whether an item shall be encrypted (rwflag=1).
  52. In this case the password dialog may ask for the same password twice
  53. for comparison in order to catch typos, that would make decryption
  54. impossible.
  55. Other items in PEM formatting (certificates) can also be encrypted, it is
  56. however not usual, as certificate information is considered public.
  57. =head1 RETURN VALUES
  58. These functions do not provide diagnostic information.
  59. =head1 EXAMPLES
  60. The following example returns the password provided as userdata to the
  61. calling function. The password is considered to be a '\0' terminated
  62. string. If the password does not fit into the buffer, the password is
  63. truncated.
  64. int my_cb(char *buf, int size, int rwflag, void *u)
  65. {
  66. strncpy(buf, (char *)u, size);
  67. buf[size - 1] = '\0';
  68. return strlen(buf);
  69. }
  70. =head1 HISTORY
  71. SSL_CTX_get_default_passwd_cb(), SSL_CTX_get_default_passwd_cb_userdata(),
  72. SSL_set_default_passwd_cb() and SSL_set_default_passwd_cb_userdata() were
  73. first added to OpenSSL 1.1.0
  74. =head1 SEE ALSO
  75. L<ssl(7)>,
  76. L<SSL_CTX_use_certificate(3)>
  77. =head1 COPYRIGHT
  78. Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved.
  79. Licensed under the OpenSSL license (the "License"). You may not use
  80. this file except in compliance with the License. You can obtain a copy
  81. in the file LICENSE in the source distribution or at
  82. L<https://www.openssl.org/source/license.html>.
  83. =cut