GH721: Duplicated flags in doc
[openssl.git] / doc / ssl / SSL_CTX_set_default_passwd_cb.pod
1 =pod
2
3 =head1 NAME
4
5 SSL_CTX_set_default_passwd_cb, SSL_CTX_set_default_passwd_cb_userdata,
6 SSL_set_default_passwd_cb, SSL_set_default_passwd_cb_userdata - set passwd
7 callback for encrypted PEM file handling
8
9 =head1 SYNOPSIS
10
11  #include <openssl/ssl.h>
12
13  void SSL_CTX_set_default_passwd_cb(SSL_CTX *ctx, pem_password_cb *cb);
14  void SSL_CTX_set_default_passwd_cb_userdata(SSL_CTX *ctx, void *u);
15  void SSL_set_default_passwd_cb(SSL *s, pem_password_cb *cb);
16  void SSL_set_default_passwd_cb_userdata(SSL *s, void *u);
17
18  int pem_passwd_cb(char *buf, int size, int rwflag, void *userdata);
19
20 =head1 DESCRIPTION
21
22 SSL_CTX_set_default_passwd_cb() sets the default password callback called
23 when loading/storing a PEM certificate with encryption.
24
25 SSL_CTX_set_default_passwd_cb_userdata() sets a pointer to B<userdata> which
26 will be provided to the password callback on invocation.
27
28 SSL_set_default_passwd_cb() and SSL_set_default_passwd_cb_userdata() perform the
29 same function as their SSL_CTX counterparts, but using an SSL object.
30
31 The pem_passwd_cb(), which must be provided by the application, hands back the
32 password to be used during decryption. On invocation a pointer to B<userdata>
33 is provided. The pem_passwd_cb must write the password into the provided buffer
34 B<buf> which is of size B<size>. The actual length of the password must
35 be returned to the calling function. B<rwflag> indicates whether the
36 callback is used for reading/decryption (rwflag=0) or writing/encryption
37 (rwflag=1).
38
39 =head1 NOTES
40
41 When loading or storing private keys, a password might be supplied to
42 protect the private key. The way this password can be supplied may depend
43 on the application. If only one private key is handled, it can be practical
44 to have pem_passwd_cb() handle the password dialog interactively. If several
45 keys have to be handled, it can be practical to ask for the password once,
46 then keep it in memory and use it several times. In the last case, the
47 password could be stored into the B<userdata> storage and the
48 pem_passwd_cb() only returns the password already stored.
49
50 When asking for the password interactively, pem_passwd_cb() 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
56 Other items in PEM formatting (certificates) can also be encrypted, it is
57 however not usual, as certificate information is considered public.
58
59 =head1 RETURN VALUES
60
61 These functions do not provide diagnostic information.
62
63 =head1 EXAMPLES
64
65 The following example returns the password provided as B<userdata> to the
66 calling function. The password is considered to be a '\0' terminated
67 string. If the password does not fit into the buffer, the password is
68 truncated.
69
70  int pem_passwd_cb(char *buf, int size, int rwflag, void *password)
71  {
72   strncpy(buf, (char *)(password), size);
73   buf[size - 1] = '\0';
74   return(strlen(buf));
75  }
76
77 =head1 SEE ALSO
78
79 L<ssl(3)>,
80 L<SSL_CTX_use_certificate(3)>
81
82 =cut