SSL_CTX_set_default_passwd_cb.pod 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. =pod
  2. =head1 NAME
  3. SSL_CTX_set_default_passwd_cb, SSL_CTX_set_default_passwd_cb_userdata - set passwd callback for encrypted PEM file handling
  4. =head1 SYNOPSIS
  5. #include <openssl/ssl.h>
  6. void SSL_CTX_set_default_passwd_cb(SSL_CTX *ctx, pem_password_cb *cb);
  7. void SSL_CTX_set_default_passwd_cb_userdata(SSL_CTX *ctx, void *u);
  8. int pem_passwd_cb(char *buf, int size, int rwflag, void *userdata);
  9. =head1 DESCRIPTION
  10. SSL_CTX_set_default_passwd_cb() sets the default password callback called
  11. when loading/storing a PEM certificate with encryption.
  12. SSL_CTX_set_default_passwd_cb_userdata() sets a pointer to B<userdata> which
  13. will be provided to the password callback on invocation.
  14. The pem_passwd_cb(), which must be provided by the application, hands back the
  15. password to be used during decryption. On invocation a pointer to B<userdata>
  16. is provided. The pem_passwd_cb must write the password into the provided buffer
  17. B<buf> which is of size B<size>. The actual length of the password must
  18. be returned to the calling function. B<rwflag> indicates whether the
  19. callback is used for reading/decryption (rwflag=0) or writing/encryption
  20. (rwflag=1).
  21. =head1 NOTES
  22. When loading or storing private keys, a password might be supplied to
  23. protect the private key. The way this password can be supplied may depend
  24. on the application. If only one private key is handled, it can be practical
  25. to have pem_passwd_cb() handle the password dialog interactively. If several
  26. keys have to be handled, it can be practical to ask for the password once,
  27. then keep it in memory and use it several times. In the last case, the
  28. password could be stored into the B<userdata> storage and the
  29. pem_passwd_cb() only returns the password already stored.
  30. When asking for the password interactively, pem_passwd_cb() can use
  31. B<rwflag> to check, whether an item shall be encrypted (rwflag=1).
  32. In this case the password dialog may ask for the same password twice
  33. for comparison in order to catch typos, that would make decryption
  34. impossible.
  35. Other items in PEM formatting (certificates) can also be encrypted, it is
  36. however not usual, as certificate information is considered public.
  37. =head1 RETURN VALUES
  38. SSL_CTX_set_default_passwd_cb() and SSL_CTX_set_default_passwd_cb_userdata()
  39. do not provide diagnostic information.
  40. =head1 EXAMPLES
  41. The following example returns the password provided as B<userdata> to the
  42. calling function. The password is considered to be a '\0' terminated
  43. string. If the password does not fit into the buffer, the password is
  44. truncated.
  45. int pem_passwd_cb(char *buf, int size, int rwflag, void *password)
  46. {
  47. strncpy(buf, (char *)(password), size);
  48. buf[size - 1] = '\0';
  49. return(strlen(buf));
  50. }
  51. =head1 SEE ALSO
  52. L<ssl(3)|ssl(3)>,
  53. L<SSL_CTX_use_certificate(3)|SSL_CTX_use_certificate(3)>
  54. =cut