Jean-Paul Calderone | 897bc25 | 2008-02-18 20:50:23 -0500 | [diff] [blame] | 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
| 2 | <html> |
| 3 | <head> |
| 4 | <title>3.3.1 Context objects </title> |
| 5 | <META NAME="description" CONTENT="3.3.1 Context objects "> |
| 6 | <META NAME="keywords" CONTENT="pyOpenSSL"> |
| 7 | <META NAME="resource-type" CONTENT="document"> |
| 8 | <META NAME="distribution" CONTENT="global"> |
| 9 | <link rel="STYLESHEET" href="pyOpenSSL.css"> |
| 10 | <LINK REL="next" href="openssl-connection.html"> |
| 11 | <LINK REL="previous" href="openssl-ssl.html"> |
| 12 | <LINK REL="up" href="openssl-ssl.html"> |
| 13 | <LINK REL="next" href="openssl-connection.html"> |
| 14 | </head> |
| 15 | <body> |
| 16 | <DIV CLASS="navigation"> |
| 17 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> |
| 18 | <tr> |
| 19 | <td><A href="openssl-ssl.html"><img src="previous.gif" |
| 20 | border="0" height="32" |
| 21 | alt="Previous Page" width="32"></A></td> |
| 22 | <td><A href="openssl-ssl.html"><img src="up.gif" |
| 23 | border="0" height="32" |
| 24 | alt="Up One Level" width="32"></A></td> |
| 25 | <td><A href="openssl-connection.html"><img src="next.gif" |
| 26 | border="0" height="32" |
| 27 | alt="Next Page" width="32"></A></td> |
| 28 | <td align="center" width="100%">Python OpenSSL Manual</td> |
| 29 | <td><A href="contents.html"><img src="contents.gif" |
| 30 | border="0" height="32" |
| 31 | alt="Contents" width="32"></A></td> |
| 32 | <td><img src="blank.gif" |
| 33 | border="0" height="32" |
| 34 | alt="" width="32"></td> |
| 35 | <td><img src="blank.gif" |
| 36 | border="0" height="32" |
| 37 | alt="" width="32"></td> |
| 38 | </tr></table> |
| 39 | <b class="navlabel">Previous:</b> <a class="sectref" href="openssl-ssl.html">3.3 SSL </A> |
| 40 | <b class="navlabel">Up:</b> <a class="sectref" href="openssl-ssl.html">3.3 SSL </A> |
| 41 | <b class="navlabel">Next:</b> <a class="sectref" href="openssl-connection.html">3.3.2 Connection objects</A> |
| 42 | <br><hr> |
| 43 | </DIV> |
| 44 | <!--End of Navigation Panel--> |
| 45 | |
| 46 | <H3><A NAME="SECTION000431000000000000000"> </A> |
| 47 | <BR> |
| 48 | 3.3.1 Context objects |
| 49 | </H3> |
| 50 | <P> |
| 51 | <EM><EM><EM>Context objects have the following methods: |
| 52 | </EM></EM></EM> |
| 53 | <P> |
| 54 | <dl><dt><b><a name='l2h-114'><tt class='method'>check_privatekey</tt></a></b>() |
| 55 | <dd> |
| 56 | Check if the private key (loaded with <tt class="method">use_privatekey<big>[</big>_file<big>]</big></tt>) |
| 57 | matches the certificate (loaded with <tt class="method">use_certificate<big>[</big>_file<big>]</big></tt>). |
| 58 | Returns true if they match, false otherwise. |
| 59 | </dl> |
| 60 | <P> |
| 61 | <dl><dt><b><a name='l2h-115'><tt class='method'>get_app_data</tt></a></b>() |
| 62 | <dd> |
| 63 | Retrieve application data as set by <tt class="method">set_app_data</tt>. |
| 64 | </dl> |
| 65 | <P> |
| 66 | <dl><dt><b><a name='l2h-116'><tt class='method'>get_cert_store</tt></a></b>() |
| 67 | <dd> |
| 68 | Retrieve the certificate store (a X509Store object) that the context uses. |
| 69 | This can be used to add "trusted" certificates without using the. |
| 70 | <tt class="method">load_verify_locations()</tt> method. |
| 71 | </dl> |
| 72 | <P> |
| 73 | <dl><dt><b><a name='l2h-117'><tt class='method'>get_timeout</tt></a></b>() |
| 74 | <dd> |
| 75 | Retrieve session timeout, as set by <tt class="method">set_timeout</tt>. The default is 300 |
| 76 | seconds. |
| 77 | </dl> |
| 78 | <P> |
| 79 | <dl><dt><b><a name='l2h-118'><tt class='method'>get_verify_depth</tt></a></b>() |
| 80 | <dd> |
| 81 | Retrieve the Context object's verify depth, as set by |
| 82 | <tt class="method">set_verify_depth</tt>. |
| 83 | </dl> |
| 84 | <P> |
| 85 | <dl><dt><b><a name='l2h-119'><tt class='method'>get_verify_mode</tt></a></b>() |
| 86 | <dd> |
| 87 | Retrieve the Context object's verify mode, as set by <tt class="method">set_verify_mode</tt>. |
| 88 | </dl> |
| 89 | <P> |
| 90 | <dl><dt><b><a name='l2h-120'><tt class='method'>load_client_ca</tt></a></b>(<var>pemfile</var>) |
| 91 | <dd> |
| 92 | Read a file with PEM-formatted certificates that will be sent to the client |
| 93 | when requesting a client certificate. |
| 94 | </dl> |
| 95 | <P> |
| 96 | <dl><dt><b><a name='l2h-121'><tt class='method'>load_verify_locations</tt></a></b>(<var>pemfile</var>) |
| 97 | <dd> |
| 98 | Specify where CA certificates for verification purposes are located. These are |
| 99 | trusted certificates. Note that the certificates have to be in PEM format. |
| 100 | </dl> |
| 101 | <P> |
| 102 | <dl><dt><b><a name='l2h-122'><tt class='method'>load_tmp_dh</tt></a></b>(<var>dhfile</var>) |
| 103 | <dd> |
| 104 | Load parameters for Ephemeral Diffie-Hellman from <var>dhfile</var>. |
| 105 | </dl> |
| 106 | <P> |
| 107 | <dl><dt><b><a name='l2h-123'><tt class='method'>set_app_data</tt></a></b>(<var>data</var>) |
| 108 | <dd> |
| 109 | Associate <var>data</var> with this Context object. <var>data</var> can be retrieved |
| 110 | later using the <tt class="method">get_app_data</tt> method. |
| 111 | </dl> |
| 112 | <P> |
| 113 | <dl><dt><b><a name='l2h-124'><tt class='method'>set_cipher_list</tt></a></b>(<var>ciphers</var>) |
| 114 | <dd> |
| 115 | Set the list of ciphers to be used in this context. See the OpenSSL manual for |
| 116 | more information (e.g. ciphers(1)) |
| 117 | </dl> |
| 118 | <P> |
| 119 | <dl><dt><b><a name='l2h-125'><tt class='method'>set_info_callback</tt></a></b>(<var>callback</var>) |
| 120 | <dd> |
| 121 | Set the information callback to <var>callback</var>. This function will be called |
| 122 | from time to time during SSL handshakes. |
Jean-Paul Calderone | 420bf21 | 2008-02-19 21:19:30 -0500 | [diff] [blame] | 123 | <var>callback</var> should take three arguments: a Connection object and two |
Jean-Paul Calderone | 897bc25 | 2008-02-18 20:50:23 -0500 | [diff] [blame] | 124 | integers. The first integer specifies where in the SSL handshake the function |
| 125 | was called, and the other the return code from a (possibly failed) internal |
| 126 | function call. |
| 127 | </dl> |
| 128 | <P> |
| 129 | <dl><dt><b><a name='l2h-126'><tt class='method'>set_options</tt></a></b>(<var>options</var>) |
| 130 | <dd> |
| 131 | Add SSL options. Options you have set before are not cleared! |
Jean-Paul Calderone | 420bf21 | 2008-02-19 21:19:30 -0500 | [diff] [blame] | 132 | This method should be used with the <tt class="constant">OP_*</tt> constants. |
Jean-Paul Calderone | 897bc25 | 2008-02-18 20:50:23 -0500 | [diff] [blame] | 133 | </dl> |
| 134 | <P> |
| 135 | <dl><dt><b><a name='l2h-127'><tt class='method'>set_passwd_cb</tt></a></b>(<var>callback</var><big>[</big><var>, userdata</var><big>]</big>) |
| 136 | <dd> |
| 137 | Set the passphrase callback to <var>callback</var>. This function will be called |
| 138 | when a private key with a passphrase is loaded. |
Jean-Paul Calderone | 420bf21 | 2008-02-19 21:19:30 -0500 | [diff] [blame] | 139 | <var>callback</var> should take a boolean argument <var>repeat</var> and an arbitrary |
Jean-Paul Calderone | 897bc25 | 2008-02-18 20:50:23 -0500 | [diff] [blame] | 140 | argument <var>data</var> and return the passphrase entered by the user. If |
| 141 | <var>repeat</var> is true then <var>callback</var> should ask for the passphrase twice |
| 142 | and make sure that the two entries are equal. The <var>data</var> argument is the |
| 143 | <var>userdata</var> variable passed to the <tt class="method">set_passwd_cb</tt> method. If an |
| 144 | error occurs, <var>callback</var> should return a false value (e.g. an empty |
| 145 | string). |
| 146 | </dl> |
| 147 | <P> |
| 148 | <dl><dt><b><a name='l2h-128'><tt class='method'>set_session_id</tt></a></b>(<var>name</var>) |
| 149 | <dd> |
| 150 | Set the context <var>name</var> within which a session can be reused for this |
| 151 | Context object. This is needed when doing session resumption, because there is |
| 152 | no way for a stored session to know which Context object it is associated with. |
| 153 | <var>name</var> may be any binary data. |
| 154 | </dl> |
| 155 | <P> |
| 156 | <dl><dt><b><a name='l2h-129'><tt class='method'>set_timeout</tt></a></b>(<var>timeout</var>) |
| 157 | <dd> |
| 158 | Set the timeout for newly created sessions for this Context object to |
| 159 | <var>timeout</var>. <var>timeout</var> must be given in (whole) seconds. The default |
| 160 | value is 300 seconds. See the OpenSSL manual for more information (e.g. |
| 161 | SSL_CTX_set_timeout(3)). |
| 162 | </dl> |
| 163 | <P> |
| 164 | <dl><dt><b><a name='l2h-130'><tt class='method'>set_verify</tt></a></b>(<var>mode, callback</var>) |
| 165 | <dd> |
| 166 | Set the verification flags for this Context object to <var>mode</var> and specify |
| 167 | that <var>callback</var> should be used for verification callbacks. <var>mode</var> |
| 168 | should be one of <tt class="constant">VERIFY_NONE</tt> and <tt class="constant">VERIFY_PEER</tt>. If |
| 169 | <tt class="constant">VERIFY_PEER</tt> is used, <var>mode</var> can be OR:ed with |
| 170 | <tt class="constant">VERIFY_FAIL_IF_NO_PEER_CERT</tt> and <tt class="constant">VERIFY_CLIENT_ONCE</tt> to |
| 171 | further control the behaviour. |
Jean-Paul Calderone | 420bf21 | 2008-02-19 21:19:30 -0500 | [diff] [blame] | 172 | <var>callback</var> should take five arguments: A Connection object, an X509 object, |
Jean-Paul Calderone | 897bc25 | 2008-02-18 20:50:23 -0500 | [diff] [blame] | 173 | and three integer variables, which are in turn potential error number, error |
| 174 | depth and return code. <var>callback</var> should return true if verification passes |
| 175 | and false otherwise. |
| 176 | </dl> |
| 177 | <P> |
| 178 | <dl><dt><b><a name='l2h-131'><tt class='method'>set_verify_depth</tt></a></b>(<var>depth</var>) |
| 179 | <dd> |
| 180 | Set the maximum depth for the certificate chain verification that shall be |
| 181 | allowed for this Context object. |
| 182 | </dl> |
| 183 | <P> |
| 184 | <dl><dt><b><a name='l2h-132'><tt class='method'>use_certificate</tt></a></b>(<var>cert</var>) |
| 185 | <dd> |
| 186 | Use the certificate <var>cert</var> which has to be a X509 object. |
| 187 | </dl> |
| 188 | <P> |
Jean-Paul Calderone | 87b4060 | 2008-02-19 21:13:25 -0500 | [diff] [blame] | 189 | <dl><dt><b><a name='l2h-133'><tt class='method'>add_extra_chain_cert</tt></a></b>(<var>cert</var>) |
| 190 | <dd> |
| 191 | Adds the certificate <var>cert</var>, which has to be a X509 object, to the |
| 192 | certificate chain presented together with the certificate. |
| 193 | </dl> |
| 194 | <P> |
| 195 | <dl><dt><b><a name='l2h-134'><tt class='method'>use_certificate_chain_file</tt></a></b>(<var>file</var>) |
Jean-Paul Calderone | 897bc25 | 2008-02-18 20:50:23 -0500 | [diff] [blame] | 196 | <dd> |
| 197 | Load a certificate chain from <var>file</var> which must be PEM encoded. |
| 198 | </dl> |
| 199 | <P> |
Jean-Paul Calderone | 87b4060 | 2008-02-19 21:13:25 -0500 | [diff] [blame] | 200 | <dl><dt><b><a name='l2h-135'><tt class='method'>use_privatekey</tt></a></b>(<var>pkey</var>) |
Jean-Paul Calderone | 897bc25 | 2008-02-18 20:50:23 -0500 | [diff] [blame] | 201 | <dd> |
| 202 | Use the private key <var>pkey</var> which has to be a PKey object. |
| 203 | </dl> |
| 204 | <P> |
Jean-Paul Calderone | 87b4060 | 2008-02-19 21:13:25 -0500 | [diff] [blame] | 205 | <dl><dt><b><a name='l2h-136'><tt class='method'>use_certificate_file</tt></a></b>(<var>file</var><big>[</big><var>, format</var><big>]</big>) |
Jean-Paul Calderone | 897bc25 | 2008-02-18 20:50:23 -0500 | [diff] [blame] | 206 | <dd> |
| 207 | Load the first certificate found in <var>file</var>. The certificate must be in the |
| 208 | format specified by <var>format</var>, which is either <tt class="constant">FILETYPE_PEM</tt> or |
| 209 | <tt class="constant">FILETYPE_ASN1</tt>. The default is <tt class="constant">FILETYPE_PEM</tt>. |
| 210 | </dl> |
| 211 | <P> |
Jean-Paul Calderone | 87b4060 | 2008-02-19 21:13:25 -0500 | [diff] [blame] | 212 | <dl><dt><b><a name='l2h-137'><tt class='method'>use_privatekey_file</tt></a></b>(<var>file</var><big>[</big><var>, format</var><big>]</big>) |
Jean-Paul Calderone | 897bc25 | 2008-02-18 20:50:23 -0500 | [diff] [blame] | 213 | <dd> |
| 214 | Load the first private key found in <var>file</var>. The private key must be in the |
| 215 | format specified by <var>format</var>, which is either <tt class="constant">FILETYPE_PEM</tt> or |
| 216 | <tt class="constant">FILETYPE_ASN1</tt>. The default is <tt class="constant">FILETYPE_PEM</tt>. |
| 217 | </dl> |
| 218 | <P> |
| 219 | |
| 220 | <DIV CLASS="navigation"> |
| 221 | <p><hr> |
| 222 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> |
| 223 | <tr> |
| 224 | <td><A href="openssl-ssl.html"><img src="previous.gif" |
| 225 | border="0" height="32" |
| 226 | alt="Previous Page" width="32"></A></td> |
| 227 | <td><A href="openssl-ssl.html"><img src="up.gif" |
| 228 | border="0" height="32" |
| 229 | alt="Up One Level" width="32"></A></td> |
| 230 | <td><A href="openssl-connection.html"><img src="next.gif" |
| 231 | border="0" height="32" |
| 232 | alt="Next Page" width="32"></A></td> |
| 233 | <td align="center" width="100%">Python OpenSSL Manual</td> |
| 234 | <td><A href="contents.html"><img src="contents.gif" |
| 235 | border="0" height="32" |
| 236 | alt="Contents" width="32"></A></td> |
| 237 | <td><img src="blank.gif" |
| 238 | border="0" height="32" |
| 239 | alt="" width="32"></td> |
| 240 | <td><img src="blank.gif" |
| 241 | border="0" height="32" |
| 242 | alt="" width="32"></td> |
| 243 | </tr></table> |
| 244 | <b class="navlabel">Previous:</b> <a class="sectref" href="openssl-ssl.html">3.3 SSL </A> |
| 245 | <b class="navlabel">Up:</b> <a class="sectref" href="openssl-ssl.html">3.3 SSL </A> |
| 246 | <b class="navlabel">Next:</b> <a class="sectref" href="openssl-connection.html">3.3.2 Connection objects</A> |
| 247 | <hr> |
| 248 | <span class="release-info">Release 0.6.</span> |
| 249 | </DIV> |
| 250 | <!--End of Navigation Panel--> |
| 251 | |
| 252 | </BODY> |
| 253 | </HTML> |