summaryrefslogtreecommitdiff
path: root/doc/html/openssl-connection.html
blob: d3eaf71e4219a815c020e5d94716b444b165f4b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>3.3.2 Connection objects </title>
<META NAME="description" CONTENT="3.3.2 Connection objects ">
<META NAME="keywords" CONTENT="pyOpenSSL">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<link rel="STYLESHEET" href="pyOpenSSL.css">
<LINK REL="previous" href="openssl-context.html">
<LINK REL="up" href="openssl-ssl.html">
<LINK REL="next" href="internals.html">
</head>
<body>
<DIV CLASS="navigation">
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A href="openssl-context.html"><img src="previous.gif"
  border="0" height="32"
  alt="Previous Page" width="32"></A></td>
<td><A href="openssl-ssl.html"><img src="up.gif"
  border="0" height="32"
  alt="Up One Level" width="32"></A></td>
<td><A href="internals.html"><img src="next.gif"
  border="0" height="32"
  alt="Next Page" width="32"></A></td>
<td align="center" width="100%">Python OpenSSL Manual</td>
<td><A href="contents.html"><img src="contents.gif"
  border="0" height="32"
  alt="Contents" width="32"></A></td>
<td><img src="blank.gif"
  border="0" height="32"
  alt="" width="32"></td>
<td><img src="blank.gif"
  border="0" height="32"
  alt="" width="32"></td>
</tr></table>
<b class="navlabel">Previous:</b> <a class="sectref" href="openssl-context.html">3.3.1 Context objects</A>
<b class="navlabel">Up:</b> <a class="sectref" href="openssl-ssl.html">3.3 SSL  </A>
<b class="navlabel">Next:</b> <a class="sectref" href="internals.html">4 Internals</A>
<br><hr>
</DIV>
<!--End of Navigation Panel-->

<H3><A NAME="SECTION000432000000000000000">&nbsp;</A>
<BR>
3.3.2 Connection objects 
</H3>

<P>
Connection objects have the following methods:

<P>
<dl><dt><b><a name='l2h-179'><tt class='method'>accept</tt></a></b>()
<dd>
Call the <tt class="method">accept</tt> method of the underlying socket and set up SSL on the
returned socket, using the Context object supplied to this Connection object at
creation. Returns a pair <code>(<var>conn</var>, <var>address</var>)</code>. where <var>conn</var>
is the new Connection object created, and <var>address</var> is as returned by the
socket's <tt class="method">accept</tt>.
</dl>

<P>
<dl><dt><b><a name='l2h-180'><tt class='method'>bind</tt></a></b>(<var>address</var>)
<dd>
Call the <tt class="method">bind</tt> method of the underlying socket.
</dl>

<P>
<dl><dt><b><a name='l2h-181'><tt class='method'>close</tt></a></b>()
<dd>
Call the <tt class="method">close</tt> method of the underlying socket. Note: If you want
correct SSL closure, you need to call the <tt class="method">shutdown</tt> method first.
</dl>

<P>
<dl><dt><b><a name='l2h-182'><tt class='method'>connect</tt></a></b>(<var>address</var>)
<dd>
Call the <tt class="method">connect</tt> method of the underlying socket and set up SSL on the
socket, using the Context object supplied to this Connection object at
creation.
</dl>

<P>
<dl><dt><b><a name='l2h-183'><tt class='method'>connect_ex</tt></a></b>(<var>address</var>)
<dd>
Call the <tt class="method">connect_ex</tt> method of the underlying socket and set up SSL on
the socket, using the Context object supplied to this Connection object at
creation. Note that if the <tt class="method">connect_ex</tt> method of the socket doesn't
return 0, SSL won't be initialized.
</dl>

<P>
<dl><dt><b><a name='l2h-184'><tt class='method'>do_handshake</tt></a></b>()
<dd>
Perform an SSL handshake (usually called after <tt class="method">renegotiate</tt> or one of
<tt class="method">set_accept_state</tt> or <tt class="method">set_accept_state</tt>). This can raise the
same exceptions as <tt class="method">send</tt> and <tt class="method">recv</tt>.
</dl>

<P>
<dl><dt><b><a name='l2h-185'><tt class='method'>fileno</tt></a></b>()
<dd>
Retrieve the file descriptor number for the underlying socket.
</dl>

<P>
<dl><dt><b><a name='l2h-186'><tt class='method'>listen</tt></a></b>(<var>backlog</var>)
<dd>
Call the <tt class="method">listen</tt> method of the underlying socket.
</dl>

<P>
<dl><dt><b><a name='l2h-187'><tt class='method'>get_app_data</tt></a></b>()
<dd>
Retrieve application data as set by <tt class="method">set_app_data</tt>.
</dl>

<P>
<dl><dt><b><a name='l2h-188'><tt class='method'>get_cipher_list</tt></a></b>()
<dd>
Retrieve the list of ciphers used by the Connection object. WARNING: This API
has changed. It used to take an optional parameter and just return a string,
but not it returns the entire list in one go.
</dl>

<P>
<dl><dt><b><a name='l2h-189'><tt class='method'>get_client_ca_list</tt></a></b>()
<dd>
Retrieve the list of preferred client certificate issuers sent by the server
as <tt class="class">OpenSSL.crypto.X509Name</tt> objects.

<P>
If this is a client <tt class="class">Connection</tt>, the list will be empty until the
connection with the server is established.

<P>
If this is a server <tt class="class">Connection</tt>, return the list of certificate
authorities that will be sent or has been sent to the client, as controlled
by this <tt class="class">Connection</tt>'s <tt class="class">Context</tt>.

<P>

<span class='versionnote'>New in version 0.10.</span>

</dl>

<P>
<dl><dt><b><a name='l2h-190'><tt class='method'>get_context</tt></a></b>()
<dd>
Retrieve the Context object associated with this Connection.
</dl>

<P>
<dl><dt><b><a name='l2h-191'><tt class='method'>get_peer_certificate</tt></a></b>()
<dd>
Retrieve the other side's certificate (if any)
</dl>

<P>
<dl><dt><b><a name='l2h-192'><tt class='method'>getpeername</tt></a></b>()
<dd>
Call the <tt class="method">getpeername</tt> method of the underlying socket.
</dl>

<P>
<dl><dt><b><a name='l2h-193'><tt class='method'>getsockname</tt></a></b>()
<dd>
Call the <tt class="method">getsockname</tt> method of the underlying socket.
</dl>

<P>
<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>)
<dd>
Call the <tt class="method">getsockopt</tt> method of the underlying socket.
</dl>

<P>
<dl><dt><b><a name='l2h-195'><tt class='method'>pending</tt></a></b>()
<dd>
Retrieve the number of bytes that can be safely read from the SSL buffer
(<i>not</i> the underlying transport buffer).
</dl>

<P>
<dl><dt><b><a name='l2h-196'><tt class='method'>recv</tt></a></b>(<var>bufsize</var>)
<dd>
Receive data from the Connection. The return value is a string representing the
data received. The maximum amount of data to be received at once, is specified
by <var>bufsize</var>.
</dl>

<P>
<dl><dt><b><a name='l2h-197'><tt class='method'>bio_write</tt></a></b>(<var>bytes</var>)
<dd>
If the Connection was created with a memory BIO, this method can be used to add
bytes to the read end of that memory BIO.  The Connection can then read the
bytes (for example, in response to a call to <tt class="method">recv</tt>).
</dl>

<P>
<dl><dt><b><a name='l2h-198'><tt class='method'>renegotiate</tt></a></b>()
<dd>
Renegotiate the SSL session. Call this if you wish to change cipher suites or
anything like that.
</dl>

<P>
<dl><dt><b><a name='l2h-199'><tt class='method'>send</tt></a></b>(<var>string</var>)
<dd>
Send the <var>string</var> data to the Connection.
</dl>

<P>
<dl><dt><b><a name='l2h-200'><tt class='method'>bio_read</tt></a></b>(<var>bufsize</var>)
<dd>
If the Connection was created with a memory BIO, this method can be used to
read bytes from the write end of that memory BIO.  Many Connection methods will
add bytes which must be read in this manner or the buffer will eventually fill
up and the Connection will be able to take no further actions.
</dl>

<P>
<dl><dt><b><a name='l2h-201'><tt class='method'>sendall</tt></a></b>(<var>string</var>)
<dd>
Send all of the <var>string</var> data to the Connection. This calls <tt class="method">send</tt>
repeatedly until all data is sent. If an error occurs, it's impossible to tell
how much data has been sent.
</dl>

<P>
<dl><dt><b><a name='l2h-202'><tt class='method'>set_accept_state</tt></a></b>()
<dd>
Set the connection to work in server mode. The handshake will be handled
automatically by read/write.
</dl>

<P>
<dl><dt><b><a name='l2h-203'><tt class='method'>set_app_data</tt></a></b>(<var>data</var>)
<dd>
Associate <var>data</var> with this Connection object. <var>data</var> can be retrieved
later using the <tt class="method">get_app_data</tt> method.
</dl>

<P>
<dl><dt><b><a name='l2h-204'><tt class='method'>set_connect_state</tt></a></b>()
<dd>
Set the connection to work in client mode. The handshake will be handled
automatically by read/write.
</dl>

<P>
<dl><dt><b><a name='l2h-205'><tt class='method'>setblocking</tt></a></b>(<var>flag</var>)
<dd>
Call the <tt class="method">setblocking</tt> method of the underlying socket.
</dl>

<P>
<dl><dt><b><a name='l2h-206'><tt class='method'>setsockopt</tt></a></b>(<var>level, optname, value</var>)
<dd>
Call the <tt class="method">setsockopt</tt> method of the underlying socket.
</dl>

<P>
<dl><dt><b><a name='l2h-207'><tt class='method'>shutdown</tt></a></b>()
<dd>
Send the shutdown message to the Connection. Returns true if the shutdown
message exchange is completed and false otherwise (in which case you call
<tt class="method">recv()</tt> or <tt class="method">send()</tt> when the connection becomes
readable/writeable.
</dl>

<P>
<dl><dt><b><a name='l2h-208'><tt class='method'>get_shutdown</tt></a></b>()
<dd>
Get the shutdown state of the Connection.  Returns a bitvector of either or
both of <var>SENT_SHUTDOWN</var> and <var>RECEIVED_SHUTDOWN</var>.
</dl>

<P>
<dl><dt><b><a name='l2h-209'><tt class='method'>set_shutdown</tt></a></b>(<var>state</var>)
<dd>
Set the shutdown state of the Connection.  <var>state</var> is a bitvector of
either or both of <var>SENT_SHUTDOWN</var> and <var>RECEIVED_SHUTDOWN</var>.
</dl>

<P>
<dl><dt><b><a name='l2h-210'><tt class='method'>sock_shutdown</tt></a></b>(<var>how</var>)
<dd>
Call the <tt class="method">shutdown</tt> method of the underlying socket.
</dl>

<P>
<dl><dt><b><a name='l2h-211'><tt class='method'>bio_shutdown</tt></a></b>()
<dd>
If the Connection was created with a memory BIO, this method can be used to
indicate that ``end of file'' has been reached on the read end of that memory
BIO.
</dl>

<P>
<dl><dt><b><a name='l2h-212'><tt class='method'>state_string</tt></a></b>()
<dd>
Retrieve a verbose string detailing the state of the Connection.
</dl>

<P>
<dl><dt><b><a name='l2h-213'><tt class='method'>client_random</tt></a></b>()
<dd>
Retrieve the random value used with the client hello message.
</dl>

<P>
<dl><dt><b><a name='l2h-214'><tt class='method'>server_random</tt></a></b>()
<dd>
Retrieve the random value used with the server hello message.
</dl>

<P>
<dl><dt><b><a name='l2h-215'><tt class='method'>master_key</tt></a></b>()
<dd>
Retrieve the value of the master key for this session.
</dl>

<P>
<dl><dt><b><a name='l2h-216'><tt class='method'>want_read</tt></a></b>()
<dd>
Checks if more data has to be read from the transport layer to complete an
operation.
</dl>

<P>
<dl><dt><b><a name='l2h-217'><tt class='method'>want_write</tt></a></b>()
<dd>
Checks if there is data to write to the transport layer to complete an
operation.
</dl>

<P>

<DIV CLASS="navigation">
<p><hr>
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A href="openssl-context.html"><img src="previous.gif"
  border="0" height="32"
  alt="Previous Page" width="32"></A></td>
<td><A href="openssl-ssl.html"><img src="up.gif"
  border="0" height="32"
  alt="Up One Level" width="32"></A></td>
<td><A href="internals.html"><img src="next.gif"
  border="0" height="32"
  alt="Next Page" width="32"></A></td>
<td align="center" width="100%">Python OpenSSL Manual</td>
<td><A href="contents.html"><img src="contents.gif"
  border="0" height="32"
  alt="Contents" width="32"></A></td>
<td><img src="blank.gif"
  border="0" height="32"
  alt="" width="32"></td>
<td><img src="blank.gif"
  border="0" height="32"
  alt="" width="32"></td>
</tr></table>
<b class="navlabel">Previous:</b> <a class="sectref" href="openssl-context.html">3.3.1 Context objects</A>
<b class="navlabel">Up:</b> <a class="sectref" href="openssl-ssl.html">3.3 SSL  </A>
<b class="navlabel">Next:</b> <a class="sectref" href="internals.html">4 Internals</A>
<hr>
<span class="release-info">Release 0.11.</span>
</DIV>
<!--End of Navigation Panel-->

</BODY>
</HTML>