
#use wml::openssl-macros area=docs page=SSL_CTX_set_default_passwd_cb

<title>Documents, SSL_CTX_set_default_passwd_cb(3)</title>

<h1>SSL_CTX_set_default_passwd_cb(3)</h1>

#use wml::imp::generic

{:
## What's this? [[s|(<STRONG>[^<].+?)</A>(</STRONG><DD>)|$1$2|sg]]
[[s|<P>\s+<P>|<P>|sg]]
[[s|<P>\s+</|</|sg]]
[[s|<DD>\s*<DT>|<DD>&nbsp;<DT>|sg]]
[[s|<DD>\s*</DL>|<DD>&nbsp;</DL>|sg]]
[[s|\[|&#91;|sg]]
[[s|\]|&#93;|sg]]

<!-- INDEX BEGIN -->

<UL>

	<LI><A HREF="#NAME">NAME</A>
	<LI><A HREF="#SYNOPSIS">SYNOPSIS</A>
	<LI><A HREF="#DESCRIPTION">DESCRIPTION</A>
	<LI><A HREF="#NOTES">NOTES</A>
	<LI><A HREF="#RETURN_VALUES">RETURN VALUES</A>
	<LI><A HREF="#EXAMPLES">EXAMPLES</A>
	<LI><A HREF="#SEE_ALSO">SEE ALSO</A>
</UL>
<!-- INDEX END -->

<HR>
<P>
<HR>
<H1><A NAME="NAME">NAME</A></H1>
<P>
SSL_CTX_set_default_passwd_cb, SSL_CTX_set_default_passwd_cb_userdata - set
passwd callback for encrypted PEM file handling

</P>
<P>
<HR>
<H1><A NAME="SYNOPSIS">SYNOPSIS</A></H1>
<PRE> #include &lt;openssl/ssl.h&gt;
</PRE>
<PRE> void SSL_CTX_set_default_passwd_cb(SSL_CTX *ctx, pem_password_cb *cb);
 void SSL_CTX_set_default_passwd_cb_userdata(SSL_CTX *ctx, void *u);
</PRE>
<PRE> int pem_passwd_cb(char *buf, int size, int rwflag, void *userdata);
</PRE>
<P>
<HR>
<H1><A NAME="DESCRIPTION">DESCRIPTION</A></H1>
<P>
<CODE>SSL_CTX_set_default_passwd_cb()</CODE> sets the default password
callback called when loading/storing a PEM certificate with encryption.

</P>
<P>
<CODE>SSL_CTX_set_default_passwd_cb_userdata()</CODE> sets a pointer to <STRONG>userdata</STRONG> which will be provided to the password callback on invocation.

</P>
<P>
The <CODE>pem_passwd_cb(),</CODE> which must be provided by the
application, hands back the password to be used during decryption. On
invocation a pointer to <STRONG>userdata</STRONG>
is provided. The pem_passwd_cb must write the password into the provided
buffer
<STRONG>buf</STRONG> which is of size <STRONG>size</STRONG>. The actual length of the password must be returned to the calling
function. <STRONG>rwflag</STRONG> indicates whether the callback is used for reading/decryption (rwflag=0) or
writing/encryption (rwflag=1).

</P>
<P>
<HR>
<H1><A NAME="NOTES">NOTES</A></H1>
<P>
When loading or storing private keys, a password might be supplied to
protect the private key. The way this password can be supplied may depend
on the application. If only one private key is handled, it can be practical
to have <CODE>pem_passwd_cb()</CODE> handle the password dialog
interactively. If several keys have to be handled, it can be practical to
ask for the password once, then keep it in memory and use it several times.
In the last case, the password could be stored into the <STRONG>userdata</STRONG> storage and the <CODE>pem_passwd_cb()</CODE> only returns the password
already stored.

</P>
<P>
When asking for the password interactively, <CODE>pem_passwd_cb()</CODE>
can use
<STRONG>rwflag</STRONG> to check, whether an item shall be encrypted (rwflag=1). In this case the
password dialog may ask for the same password twice for comparison in order
to catch typos, that would make decryption impossible.

</P>
<P>
Other items in PEM formatting (certificates) can also be encrypted, it is
however not usual, as certificate information is considered public.

</P>
<P>
<HR>
<H1><A NAME="RETURN_VALUES">RETURN VALUES</A></H1>
<P>
<CODE>SSL_CTX_set_default_passwd_cb()</CODE> and
<CODE>SSL_CTX_set_default_passwd_cb_userdata()</CODE> do not provide
diagnostic information.

</P>
<P>
<HR>
<H1><A NAME="EXAMPLES">EXAMPLES</A></H1>
<P>
The following example returns the password provided as <STRONG>userdata</STRONG> to the calling function. The password is considered to be a '\0' terminated
string. If the password does not fit into the buffer, the password is
truncated.

</P>
<PRE> int pem_passwd_cb(char *buf, int size, int rwflag, void *password)
 {
  strncpy(buf, (char *)(password), size);
  buf[size - 1] = '\0';
  return(strlen(buf));
 }
</PRE>
<P>
<HR>
<H1><A NAME="SEE_ALSO">SEE ALSO</A></H1>
<P>
<A HREF="../ssl/ssl.html#">ssl(3)</A>,
<A HREF="../ssl/SSL_CTX_use_certificate.html#">SSL_CTX_use_certificate(3)</A>



</P>
:}

