51
51
Connection objects have the following methods:
54
<dl><dt><b><a name='l2h-175'><tt class='method'>accept</tt></a></b>()
54
<dl><dt><b><a name='l2h-179'><tt class='method'>accept</tt></a></b>()
56
56
Call the <tt class="method">accept</tt> method of the underlying socket and set up SSL on the
57
57
returned socket, using the Context object supplied to this Connection object at
64
<dl><dt><b><a name='l2h-176'><tt class='method'>bind</tt></a></b>(<var>address</var>)
64
<dl><dt><b><a name='l2h-180'><tt class='method'>bind</tt></a></b>(<var>address</var>)
66
66
Call the <tt class="method">bind</tt> method of the underlying socket.
70
<dl><dt><b><a name='l2h-177'><tt class='method'>close</tt></a></b>()
70
<dl><dt><b><a name='l2h-181'><tt class='method'>close</tt></a></b>()
72
72
Call the <tt class="method">close</tt> method of the underlying socket. Note: If you want
73
73
correct SSL closure, you need to call the <tt class="method">shutdown</tt> method first.
77
<dl><dt><b><a name='l2h-178'><tt class='method'>connect</tt></a></b>(<var>address</var>)
77
<dl><dt><b><a name='l2h-182'><tt class='method'>connect</tt></a></b>(<var>address</var>)
79
79
Call the <tt class="method">connect</tt> method of the underlying socket and set up SSL on the
80
80
socket, using the Context object supplied to this Connection object at
85
<dl><dt><b><a name='l2h-179'><tt class='method'>connect_ex</tt></a></b>(<var>address</var>)
85
<dl><dt><b><a name='l2h-183'><tt class='method'>connect_ex</tt></a></b>(<var>address</var>)
87
87
Call the <tt class="method">connect_ex</tt> method of the underlying socket and set up SSL on
88
88
the socket, using the Context object supplied to this Connection object at
94
<dl><dt><b><a name='l2h-180'><tt class='method'>do_handshake</tt></a></b>()
94
<dl><dt><b><a name='l2h-184'><tt class='method'>do_handshake</tt></a></b>()
96
96
Perform an SSL handshake (usually called after <tt class="method">renegotiate</tt> or one of
97
97
<tt class="method">set_accept_state</tt> or <tt class="method">set_accept_state</tt>). This can raise the
102
<dl><dt><b><a name='l2h-181'><tt class='method'>fileno</tt></a></b>()
102
<dl><dt><b><a name='l2h-185'><tt class='method'>fileno</tt></a></b>()
104
104
Retrieve the file descriptor number for the underlying socket.
108
<dl><dt><b><a name='l2h-182'><tt class='method'>listen</tt></a></b>(<var>backlog</var>)
108
<dl><dt><b><a name='l2h-186'><tt class='method'>listen</tt></a></b>(<var>backlog</var>)
110
110
Call the <tt class="method">listen</tt> method of the underlying socket.
114
<dl><dt><b><a name='l2h-183'><tt class='method'>get_app_data</tt></a></b>()
114
<dl><dt><b><a name='l2h-187'><tt class='method'>get_app_data</tt></a></b>()
116
116
Retrieve application data as set by <tt class="method">set_app_data</tt>.
120
<dl><dt><b><a name='l2h-184'><tt class='method'>get_cipher_list</tt></a></b>()
120
<dl><dt><b><a name='l2h-188'><tt class='method'>get_cipher_list</tt></a></b>()
122
122
Retrieve the list of ciphers used by the Connection object. WARNING: This API
123
123
has changed. It used to take an optional parameter and just return a string,
128
<dl><dt><b><a name='l2h-185'><tt class='method'>get_client_ca_list</tt></a></b>()
128
<dl><dt><b><a name='l2h-189'><tt class='method'>get_client_ca_list</tt></a></b>()
130
130
Retrieve the list of preferred client certificate issuers sent by the server
131
131
as <tt class="class">OpenSSL.crypto.X509Name</tt> objects.
149
<dl><dt><b><a name='l2h-186'><tt class='method'>get_context</tt></a></b>()
149
<dl><dt><b><a name='l2h-190'><tt class='method'>get_context</tt></a></b>()
151
151
Retrieve the Context object associated with this Connection.
155
<dl><dt><b><a name='l2h-187'><tt class='method'>get_peer_certificate</tt></a></b>()
155
<dl><dt><b><a name='l2h-191'><tt class='method'>get_peer_certificate</tt></a></b>()
157
157
Retrieve the other side's certificate (if any)
161
<dl><dt><b><a name='l2h-188'><tt class='method'>getpeername</tt></a></b>()
161
<dl><dt><b><a name='l2h-192'><tt class='method'>getpeername</tt></a></b>()
163
163
Call the <tt class="method">getpeername</tt> method of the underlying socket.
167
<dl><dt><b><a name='l2h-189'><tt class='method'>getsockname</tt></a></b>()
167
<dl><dt><b><a name='l2h-193'><tt class='method'>getsockname</tt></a></b>()
169
169
Call the <tt class="method">getsockname</tt> method of the underlying socket.
173
<dl><dt><b><a name='l2h-190'><tt class='method'>getsockopt</tt></a></b>(<var>level, optname</var><big>[</big><var>, buflen</var><big>]</big>)
173
<dl><dt><b><a name='l2h-194'><tt class='method'>getsockopt</tt></a></b>(<var>level, optname</var><big>[</big><var>, buflen</var><big>]</big>)
175
175
Call the <tt class="method">getsockopt</tt> method of the underlying socket.
179
<dl><dt><b><a name='l2h-191'><tt class='method'>pending</tt></a></b>()
179
<dl><dt><b><a name='l2h-195'><tt class='method'>pending</tt></a></b>()
181
181
Retrieve the number of bytes that can be safely read from the SSL buffer
182
182
(<i>not</i> the underlying transport buffer).
186
<dl><dt><b><a name='l2h-192'><tt class='method'>recv</tt></a></b>(<var>bufsize</var>)
186
<dl><dt><b><a name='l2h-196'><tt class='method'>recv</tt></a></b>(<var>bufsize</var>)
188
188
Receive data from the Connection. The return value is a string representing the
189
189
data received. The maximum amount of data to be received at once, is specified
194
<dl><dt><b><a name='l2h-193'><tt class='method'>bio_write</tt></a></b>(<var>bytes</var>)
194
<dl><dt><b><a name='l2h-197'><tt class='method'>bio_write</tt></a></b>(<var>bytes</var>)
196
196
If the Connection was created with a memory BIO, this method can be used to add
197
197
bytes to the read end of that memory BIO. The Connection can then read the
202
<dl><dt><b><a name='l2h-194'><tt class='method'>renegotiate</tt></a></b>()
202
<dl><dt><b><a name='l2h-198'><tt class='method'>renegotiate</tt></a></b>()
204
204
Renegotiate the SSL session. Call this if you wish to change cipher suites or
205
205
anything like that.
209
<dl><dt><b><a name='l2h-195'><tt class='method'>send</tt></a></b>(<var>string</var>)
209
<dl><dt><b><a name='l2h-199'><tt class='method'>send</tt></a></b>(<var>string</var>)
211
211
Send the <var>string</var> data to the Connection.
215
<dl><dt><b><a name='l2h-196'><tt class='method'>bio_read</tt></a></b>(<var>bufsize</var>)
215
<dl><dt><b><a name='l2h-200'><tt class='method'>bio_read</tt></a></b>(<var>bufsize</var>)
217
217
If the Connection was created with a memory BIO, this method can be used to
218
218
read bytes from the write end of that memory BIO. Many Connection methods will
224
<dl><dt><b><a name='l2h-197'><tt class='method'>sendall</tt></a></b>(<var>string</var>)
224
<dl><dt><b><a name='l2h-201'><tt class='method'>sendall</tt></a></b>(<var>string</var>)
226
226
Send all of the <var>string</var> data to the Connection. This calls <tt class="method">send</tt>
227
227
repeatedly until all data is sent. If an error occurs, it's impossible to tell
232
<dl><dt><b><a name='l2h-198'><tt class='method'>set_accept_state</tt></a></b>()
232
<dl><dt><b><a name='l2h-202'><tt class='method'>set_accept_state</tt></a></b>()
234
234
Set the connection to work in server mode. The handshake will be handled
235
235
automatically by read/write.
239
<dl><dt><b><a name='l2h-199'><tt class='method'>set_app_data</tt></a></b>(<var>data</var>)
239
<dl><dt><b><a name='l2h-203'><tt class='method'>set_app_data</tt></a></b>(<var>data</var>)
241
241
Associate <var>data</var> with this Connection object. <var>data</var> can be retrieved
242
242
later using the <tt class="method">get_app_data</tt> method.
246
<dl><dt><b><a name='l2h-200'><tt class='method'>set_connect_state</tt></a></b>()
246
<dl><dt><b><a name='l2h-204'><tt class='method'>set_connect_state</tt></a></b>()
248
248
Set the connection to work in client mode. The handshake will be handled
249
249
automatically by read/write.
253
<dl><dt><b><a name='l2h-201'><tt class='method'>setblocking</tt></a></b>(<var>flag</var>)
253
<dl><dt><b><a name='l2h-205'><tt class='method'>setblocking</tt></a></b>(<var>flag</var>)
255
255
Call the <tt class="method">setblocking</tt> method of the underlying socket.
259
<dl><dt><b><a name='l2h-202'><tt class='method'>setsockopt</tt></a></b>(<var>level, optname, value</var>)
259
<dl><dt><b><a name='l2h-206'><tt class='method'>setsockopt</tt></a></b>(<var>level, optname, value</var>)
261
261
Call the <tt class="method">setsockopt</tt> method of the underlying socket.
265
<dl><dt><b><a name='l2h-203'><tt class='method'>shutdown</tt></a></b>()
265
<dl><dt><b><a name='l2h-207'><tt class='method'>shutdown</tt></a></b>()
267
267
Send the shutdown message to the Connection. Returns true if the shutdown
268
268
message exchange is completed and false otherwise (in which case you call
274
<dl><dt><b><a name='l2h-204'><tt class='method'>get_shutdown</tt></a></b>()
274
<dl><dt><b><a name='l2h-208'><tt class='method'>get_shutdown</tt></a></b>()
276
276
Get the shutdown state of the Connection. Returns a bitvector of either or
277
277
both of <var>SENT_SHUTDOWN</var> and <var>RECEIVED_SHUTDOWN</var>.
281
<dl><dt><b><a name='l2h-205'><tt class='method'>set_shutdown</tt></a></b>(<var>state</var>)
281
<dl><dt><b><a name='l2h-209'><tt class='method'>set_shutdown</tt></a></b>(<var>state</var>)
283
283
Set the shutdown state of the Connection. <var>state</var> is a bitvector of
284
284
either or both of <var>SENT_SHUTDOWN</var> and <var>RECEIVED_SHUTDOWN</var>.
288
<dl><dt><b><a name='l2h-206'><tt class='method'>sock_shutdown</tt></a></b>(<var>how</var>)
288
<dl><dt><b><a name='l2h-210'><tt class='method'>sock_shutdown</tt></a></b>(<var>how</var>)
290
290
Call the <tt class="method">shutdown</tt> method of the underlying socket.
294
<dl><dt><b><a name='l2h-207'><tt class='method'>bio_shutdown</tt></a></b>()
294
<dl><dt><b><a name='l2h-211'><tt class='method'>bio_shutdown</tt></a></b>()
296
296
If the Connection was created with a memory BIO, this method can be used to
297
297
indicate that ``end of file'' has been reached on the read end of that memory
302
<dl><dt><b><a name='l2h-208'><tt class='method'>state_string</tt></a></b>()
302
<dl><dt><b><a name='l2h-212'><tt class='method'>state_string</tt></a></b>()
304
304
Retrieve a verbose string detailing the state of the Connection.
308
<dl><dt><b><a name='l2h-209'><tt class='method'>client_random</tt></a></b>()
308
<dl><dt><b><a name='l2h-213'><tt class='method'>client_random</tt></a></b>()
310
310
Retrieve the random value used with the client hello message.
314
<dl><dt><b><a name='l2h-210'><tt class='method'>server_random</tt></a></b>()
314
<dl><dt><b><a name='l2h-214'><tt class='method'>server_random</tt></a></b>()
316
316
Retrieve the random value used with the server hello message.
320
<dl><dt><b><a name='l2h-211'><tt class='method'>master_key</tt></a></b>()
320
<dl><dt><b><a name='l2h-215'><tt class='method'>master_key</tt></a></b>()
322
322
Retrieve the value of the master key for this session.
326
<dl><dt><b><a name='l2h-212'><tt class='method'>want_read</tt></a></b>()
326
<dl><dt><b><a name='l2h-216'><tt class='method'>want_read</tt></a></b>()
328
328
Checks if more data has to be read from the transport layer to complete an
333
<dl><dt><b><a name='l2h-213'><tt class='method'>want_write</tt></a></b>()
333
<dl><dt><b><a name='l2h-217'><tt class='method'>want_write</tt></a></b>()
335
335
Checks if there is data to write to the transport layer to complete an