| 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. | 
|  | 123 | </EM></EM></EM> | 
|  | 124 | <P> | 
|  | 125 | <EM><EM><EM><var>callback</var> should take three arguments: a Connection object and two | 
|  | 126 | integers. The first integer specifies where in the SSL handshake the function | 
|  | 127 | was called, and the other the return code from a (possibly failed) internal | 
|  | 128 | function call. | 
|  | 129 | </dl> | 
|  | 130 | <P> | 
|  | 131 | <dl><dt><b><a name='l2h-126'><tt class='method'>set_options</tt></a></b>(<var>options</var>) | 
|  | 132 | <dd> | 
|  | 133 | Add SSL options. Options you have set before are not cleared! | 
|  | 134 | </EM></EM></EM> | 
|  | 135 | <P> | 
|  | 136 | <EM><EM><EM>This method should be used with the <tt class="constant">OP_*</tt> constants. | 
|  | 137 | </dl> | 
|  | 138 | <P> | 
|  | 139 | <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>) | 
|  | 140 | <dd> | 
|  | 141 | Set the passphrase callback to <var>callback</var>. This function will be called | 
|  | 142 | when a private key with a passphrase is loaded. | 
|  | 143 | </EM></EM></EM> | 
|  | 144 | <P> | 
|  | 145 | <EM><EM><EM><var>callback</var> should take a boolean argument <var>repeat</var> and an arbitrary | 
|  | 146 | argument <var>data</var> and return the passphrase entered by the user. If | 
|  | 147 | <var>repeat</var> is true then <var>callback</var> should ask for the passphrase twice | 
|  | 148 | and make sure that the two entries are equal. The <var>data</var> argument is the | 
|  | 149 | <var>userdata</var> variable passed to the <tt class="method">set_passwd_cb</tt> method. If an | 
|  | 150 | error occurs, <var>callback</var> should return a false value (e.g. an empty | 
|  | 151 | string). | 
|  | 152 | </dl> | 
|  | 153 | <P> | 
|  | 154 | <dl><dt><b><a name='l2h-128'><tt class='method'>set_session_id</tt></a></b>(<var>name</var>) | 
|  | 155 | <dd> | 
|  | 156 | Set the context <var>name</var> within which a session can be reused for this | 
|  | 157 | Context object. This is needed when doing session resumption, because there is | 
|  | 158 | no way for a stored session to know which Context object it is associated with. | 
|  | 159 | <var>name</var> may be any binary data. | 
|  | 160 | </dl> | 
|  | 161 | <P> | 
|  | 162 | <dl><dt><b><a name='l2h-129'><tt class='method'>set_timeout</tt></a></b>(<var>timeout</var>) | 
|  | 163 | <dd> | 
|  | 164 | Set the timeout for newly created sessions for this Context object to | 
|  | 165 | <var>timeout</var>. <var>timeout</var> must be given in (whole) seconds. The default | 
|  | 166 | value is 300 seconds. See the OpenSSL manual for more information (e.g. | 
|  | 167 | SSL_CTX_set_timeout(3)). | 
|  | 168 | </dl> | 
|  | 169 | <P> | 
|  | 170 | <dl><dt><b><a name='l2h-130'><tt class='method'>set_verify</tt></a></b>(<var>mode, callback</var>) | 
|  | 171 | <dd> | 
|  | 172 | Set the verification flags for this Context object to <var>mode</var> and specify | 
|  | 173 | that <var>callback</var> should be used for verification callbacks. <var>mode</var> | 
|  | 174 | should be one of <tt class="constant">VERIFY_NONE</tt> and <tt class="constant">VERIFY_PEER</tt>. If | 
|  | 175 | <tt class="constant">VERIFY_PEER</tt> is used, <var>mode</var> can be OR:ed with | 
|  | 176 | <tt class="constant">VERIFY_FAIL_IF_NO_PEER_CERT</tt> and <tt class="constant">VERIFY_CLIENT_ONCE</tt> to | 
|  | 177 | further control the behaviour. | 
|  | 178 | </EM></EM></EM> | 
|  | 179 | <P> | 
|  | 180 | <EM><EM><EM><var>callback</var> should take five arguments: A Connection object, an X509 object, | 
|  | 181 | and three integer variables, which are in turn potential error number, error | 
|  | 182 | depth and return code. <var>callback</var> should return true if verification passes | 
|  | 183 | and false otherwise. | 
|  | 184 | </dl> | 
|  | 185 | <P> | 
|  | 186 | <dl><dt><b><a name='l2h-131'><tt class='method'>set_verify_depth</tt></a></b>(<var>depth</var>) | 
|  | 187 | <dd> | 
|  | 188 | Set the maximum depth for the certificate chain verification that shall be | 
|  | 189 | allowed for this Context object. | 
|  | 190 | </dl> | 
|  | 191 | <P> | 
|  | 192 | <dl><dt><b><a name='l2h-132'><tt class='method'>use_certificate</tt></a></b>(<var>cert</var>) | 
|  | 193 | <dd> | 
|  | 194 | Use the certificate <var>cert</var> which has to be a X509 object. | 
|  | 195 | </dl> | 
|  | 196 | <P> | 
|  | 197 | <dl><dt><b><a name='l2h-133'><tt class='method'>use_certificate_chain_file</tt></a></b>(<var>file</var>) | 
|  | 198 | <dd> | 
|  | 199 | Load a certificate chain from <var>file</var> which must be PEM encoded. | 
|  | 200 | </dl> | 
|  | 201 | <P> | 
|  | 202 | <dl><dt><b><a name='l2h-134'><tt class='method'>use_privatekey</tt></a></b>(<var>pkey</var>) | 
|  | 203 | <dd> | 
|  | 204 | Use the private key <var>pkey</var> which has to be a PKey object. | 
|  | 205 | </dl> | 
|  | 206 | <P> | 
|  | 207 | <dl><dt><b><a name='l2h-135'><tt class='method'>use_certificate_file</tt></a></b>(<var>file</var><big>[</big><var>, format</var><big>]</big>) | 
|  | 208 | <dd> | 
|  | 209 | Load the first certificate found in <var>file</var>. The certificate must be in the | 
|  | 210 | format specified by <var>format</var>, which is either <tt class="constant">FILETYPE_PEM</tt> or | 
|  | 211 | <tt class="constant">FILETYPE_ASN1</tt>. The default is <tt class="constant">FILETYPE_PEM</tt>. | 
|  | 212 | </dl> | 
|  | 213 | <P> | 
|  | 214 | <dl><dt><b><a name='l2h-136'><tt class='method'>use_privatekey_file</tt></a></b>(<var>file</var><big>[</big><var>, format</var><big>]</big>) | 
|  | 215 | <dd> | 
|  | 216 | Load the first private key found in <var>file</var>. The private key must be in the | 
|  | 217 | format specified by <var>format</var>, which is either <tt class="constant">FILETYPE_PEM</tt> or | 
|  | 218 | <tt class="constant">FILETYPE_ASN1</tt>. The default is <tt class="constant">FILETYPE_PEM</tt>. | 
|  | 219 | </dl> | 
|  | 220 | <P> | 
|  | 221 |  | 
|  | 222 | <DIV CLASS="navigation"> | 
|  | 223 | <p><hr> | 
|  | 224 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | 
|  | 225 | <tr> | 
|  | 226 | <td><A href="openssl-ssl.html"><img src="previous.gif" | 
|  | 227 | border="0" height="32" | 
|  | 228 | alt="Previous Page" width="32"></A></td> | 
|  | 229 | <td><A href="openssl-ssl.html"><img src="up.gif" | 
|  | 230 | border="0" height="32" | 
|  | 231 | alt="Up One Level" width="32"></A></td> | 
|  | 232 | <td><A href="openssl-connection.html"><img src="next.gif" | 
|  | 233 | border="0" height="32" | 
|  | 234 | alt="Next Page" width="32"></A></td> | 
|  | 235 | <td align="center" width="100%">Python OpenSSL Manual</td> | 
|  | 236 | <td><A href="contents.html"><img src="contents.gif" | 
|  | 237 | border="0" height="32" | 
|  | 238 | alt="Contents" width="32"></A></td> | 
|  | 239 | <td><img src="blank.gif" | 
|  | 240 | border="0" height="32" | 
|  | 241 | alt="" width="32"></td> | 
|  | 242 | <td><img src="blank.gif" | 
|  | 243 | border="0" height="32" | 
|  | 244 | alt="" width="32"></td> | 
|  | 245 | </tr></table> | 
|  | 246 | <b class="navlabel">Previous:</b> <a class="sectref" href="openssl-ssl.html">3.3 SSL  </A> | 
|  | 247 | <b class="navlabel">Up:</b> <a class="sectref" href="openssl-ssl.html">3.3 SSL  </A> | 
|  | 248 | <b class="navlabel">Next:</b> <a class="sectref" href="openssl-connection.html">3.3.2 Connection objects</A> | 
|  | 249 | <hr> | 
|  | 250 | <span class="release-info">Release 0.6.</span> | 
|  | 251 | </DIV> | 
|  | 252 | <!--End of Navigation Panel--> | 
|  | 253 |  | 
|  | 254 | </BODY> | 
|  | 255 | </HTML> |