blob: 872cd5a32b8e28224742ebdf75651fa8fee367ed [file] [log] [blame]
Jonathan Ballet6381da32011-07-20 16:43:38 +09001.. _openssl-ssl:
2
3:py:mod:`SSL` --- An interface to the SSL-specific parts of OpenSSL
4===================================================================
5
Jonathan Balletc9e066c2011-07-17 22:56:05 +09006.. py:module:: OpenSSL.SSL
Jonathan Ballet6381da32011-07-20 16:43:38 +09007 :synopsis: An interface to the SSL-specific parts of OpenSSL
Jonathan Balletc9e066c2011-07-17 22:56:05 +09008
Jonathan Balletc9e066c2011-07-17 22:56:05 +09009
10This module handles things specific to SSL. There are two objects defined:
11Context, Connection.
12
13.. py:data:: SSLv2_METHOD
Jonathan Ballet6381da32011-07-20 16:43:38 +090014 SSLv3_METHOD
15 SSLv23_METHOD
16 TLSv1_METHOD
Jonathan Balletc9e066c2011-07-17 22:56:05 +090017
18 These constants represent the different SSL methods to use when creating a
19 context object.
20
21
22.. py:data:: VERIFY_NONE
Jonathan Ballet6381da32011-07-20 16:43:38 +090023 VERIFY_PEER
24 VERIFY_FAIL_IF_NO_PEER_CERT
Jonathan Balletc9e066c2011-07-17 22:56:05 +090025
26 These constants represent the verification mode used by the Context
27 object's :py:meth:`set_verify` method.
28
29
30.. py:data:: FILETYPE_PEM
Jonathan Ballet6381da32011-07-20 16:43:38 +090031 FILETYPE_ASN1
Jonathan Balletc9e066c2011-07-17 22:56:05 +090032
33 File type constants used with the :py:meth:`use_certificate_file` and
34 :py:meth:`use_privatekey_file` methods of Context objects.
35
36
37.. py:data:: OP_SINGLE_DH_USE
Jonathan Ballet6381da32011-07-20 16:43:38 +090038 OP_EPHEMERAL_RSA
39 OP_NO_SSLv2
40 OP_NO_SSLv3
41 OP_NO_TLSv1
Jean-Paul Calderone21641542011-09-11 09:18:14 -040042 OP_NO_TICKET
43 OP_NO_COMPRESSION
Jonathan Balletc9e066c2011-07-17 22:56:05 +090044
45 Constants used with :py:meth:`set_options` of Context objects.
46
47 :py:const:`OP_SINGLE_DH_USE` means to always create a new key when using
48 ephemeral Diffie-Hellman. :py:const:`OP_EPHEMERAL_RSA` means to always use
49 ephemeral RSA keys when doing RSA operations. :py:const:`OP_NO_SSLv2`,
50 :py:const:`OP_NO_SSLv3` and :py:const:`OP_NO_TLSv1` means to disable those
51 specific protocols. This is interesting if you're using e.g.
52 :py:const:`SSLv23_METHOD` to get an SSLv2-compatible handshake, but don't want
53 to use SSLv2.
54
55
Jean-Paul Calderone21641542011-09-11 09:18:14 -040056.. py:data:: MODE_NO_COMPRESSION
57
58 Constant used with :py:meth:`set_mode` of Context objects to disable
59 automatic compression of application traffic.
60
61
Jonathan Balletc9e066c2011-07-17 22:56:05 +090062.. py:data:: SSLEAY_VERSION
Jonathan Ballet6381da32011-07-20 16:43:38 +090063 SSLEAY_CFLAGS
64 SSLEAY_BUILT_ON
65 SSLEAY_PLATFORM
66 SSLEAY_DIR
Jonathan Balletc9e066c2011-07-17 22:56:05 +090067
68 Constants used with :py:meth:`SSLeay_version` to specify what OpenSSL version
69 information to retrieve. See the man page for the :py:func:`SSLeay_version` C
70 API for details.
71
Jean-Paul Calderone8e8f90c2012-02-08 13:16:26 -050072.. py:data:: SESS_CACHE_OFF
73 SESS_CACHE_CLIENT
74 SESS_CACHE_SERVER
75 SESS_CACHE_BOTH
76 SESS_CACHE_NO_AUTO_CLEAR
77 SESS_CACHE_NO_INTERNAL_LOOKUP
78 SESS_CACHE_NO_INTERNAL_STORE
79 SESS_CACHE_NO_INTERNAL
80
81 Constants used with :py:meth:`Context.set_session_cache_mode` to specify
82 the behavior of the session cache and potential session reuse. See the man
83 page for the :py:func:`SSL_CTX_set_session_cache_mode` C API for details.
84
85 .. versionadded:: 0.14
Jonathan Balletc9e066c2011-07-17 22:56:05 +090086
87.. py:data:: OPENSSL_VERSION_NUMBER
88
89 An integer giving the version number of the OpenSSL library used to build this
90 version of pyOpenSSL. See the man page for the :py:func:`SSLeay_version` C API
91 for details.
92
93
94.. py:function:: SSLeay_version(type)
95
96 Retrieve a string describing some aspect of the underlying OpenSSL version. The
97 type passed in should be one of the :py:const:`SSLEAY_*` constants defined in
98 this module.
99
100
101.. py:data:: ContextType
102
103 See :py:class:`Context`.
104
105
106.. py:class:: Context(method)
107
108 A class representing SSL contexts. Contexts define the parameters of one or
109 more SSL connections.
110
111 *method* should be :py:const:`SSLv2_METHOD`, :py:const:`SSLv3_METHOD`,
112 :py:const:`SSLv23_METHOD` or :py:const:`TLSv1_METHOD`.
113
114
Jean-Paul Calderone6c896fe2012-02-16 08:10:04 -0500115.. py:class:: Session()
116
117 A class representing an SSL session. A session defines certain connection
118 parameters which may be re-used to speed up the setup of subsequent
119 connections.
120
121 .. versionadded:: 0.14
122
123
Jonathan Balletc9e066c2011-07-17 22:56:05 +0900124.. py:data:: ConnectionType
125
126 See :py:class:`Connection`.
127
128
129.. py:class:: Connection(context, socket)
130
131 A class representing SSL connections.
132
133 *context* should be an instance of :py:class:`Context` and *socket*
134 should be a socket [#connection-context-socket]_ object. *socket* may be
135 *None*; in this case, the Connection is created with a memory BIO: see
136 the :py:meth:`bio_read`, :py:meth:`bio_write`, and :py:meth:`bio_shutdown`
137 methods.
138
139.. py:exception:: Error
140
141 This exception is used as a base class for the other SSL-related
142 exceptions, but may also be raised directly.
143
144 Whenever this exception is raised directly, it has a list of error messages
145 from the OpenSSL error queue, where each item is a tuple *(lib, function,
146 reason)*. Here *lib*, *function* and *reason* are all strings, describing
147 where and what the problem is. See :manpage:`err(3)` for more information.
148
149
150.. py:exception:: ZeroReturnError
151
152 This exception matches the error return code
153 :py:data:`SSL_ERROR_ZERO_RETURN`, and is raised when the SSL Connection has
154 been closed. In SSL 3.0 and TLS 1.0, this only occurs if a closure alert has
155 occurred in the protocol, i.e. the connection has been closed cleanly. Note
156 that this does not necessarily mean that the transport layer (e.g. a socket)
157 has been closed.
158
159 It may seem a little strange that this is an exception, but it does match an
160 :py:data:`SSL_ERROR` code, and is very convenient.
161
162
163.. py:exception:: WantReadError
164
165 The operation did not complete; the same I/O method should be called again
166 later, with the same arguments. Any I/O method can lead to this since new
167 handshakes can occur at any time.
168
169 The wanted read is for **dirty** data sent over the network, not the
170 **clean** data inside the tunnel. For a socket based SSL connection,
171 **read** means data coming at us over the network. Until that read
172 succeeds, the attempted :py:meth:`OpenSSL.SSL.Connection.recv`,
173 :py:meth:`OpenSSL.SSL.Connection.send`, or
174 :py:meth:`OpenSSL.SSL.Connection.do_handshake` is prevented or incomplete. You
175 probably want to :py:meth:`select()` on the socket before trying again.
176
177
178.. py:exception:: WantWriteError
179
180 See :py:exc:`WantReadError`. The socket send buffer may be too full to
181 write more data.
182
183
184.. py:exception:: WantX509LookupError
185
186 The operation did not complete because an application callback has asked to be
187 called again. The I/O method should be called again later, with the same
188 arguments.
189
190 .. note:: This won't occur in this version, as there are no such
191 callbacks in this version.
192
193
194.. py:exception:: SysCallError
195
196 The :py:exc:`SysCallError` occurs when there's an I/O error and OpenSSL's
197 error queue does not contain any information. This can mean two things: An
198 error in the transport protocol, or an end of file that violates the protocol.
199 The parameter to the exception is always a pair *(errnum,
200 errstr)*.
201
202
203
204.. _openssl-context:
205
206Context objects
207---------------
208
209Context objects have the following methods:
210
211.. :py:class:: OpenSSL.SSL.Context
212
213.. py:method:: Context.check_privatekey()
214
215 Check if the private key (loaded with :py:meth:`use_privatekey`) matches the
216 certificate (loaded with :py:meth:`use_certificate`). Returns
217 :py:data:`None` if they match, raises :py:exc:`Error` otherwise.
218
219
220.. py:method:: Context.get_app_data()
221
222 Retrieve application data as set by :py:meth:`set_app_data`.
223
224
225.. py:method:: Context.get_cert_store()
226
227 Retrieve the certificate store (a X509Store object) that the context uses.
228 This can be used to add "trusted" certificates without using the.
229 :py:meth:`load_verify_locations` method.
230
231
232.. py:method:: Context.get_timeout()
233
234 Retrieve session timeout, as set by :py:meth:`set_timeout`. The default is 300
235 seconds.
236
237
238.. py:method:: Context.get_verify_depth()
239
240 Retrieve the Context object's verify depth, as set by
241 :py:meth:`set_verify_depth`.
242
243
244.. py:method:: Context.get_verify_mode()
245
246 Retrieve the Context object's verify mode, as set by :py:meth:`set_verify`.
247
248
249.. py:method:: Context.load_client_ca(pemfile)
250
251 Read a file with PEM-formatted certificates that will be sent to the client
252 when requesting a client certificate.
253
254
255.. py:method:: Context.set_client_ca_list(certificate_authorities)
256
257 Replace the current list of preferred certificate signers that would be
258 sent to the client when requesting a client certificate with the
259 *certificate_authorities* sequence of :py:class:`OpenSSL.crypto.X509Name`'s.
260
261 .. versionadded:: 0.10
262
263
264.. py:method:: Context.add_client_ca(certificate_authority)
265
266 Extract a :py:class:`OpenSSL.crypto.X509Name` from the *certificate_authority*
267 :py:class:`OpenSSL.crypto.X509` certificate and add it to the list of preferred
268 certificate signers sent to the client when requesting a client certificate.
269
270 .. versionadded:: 0.10
271
272
273.. py:method:: Context.load_verify_locations(pemfile, capath)
274
275 Specify where CA certificates for verification purposes are located. These
276 are trusted certificates. Note that the certificates have to be in PEM
277 format. If capath is passed, it must be a directory prepared using the
Jonathan Ballet6381da32011-07-20 16:43:38 +0900278 ``c_rehash`` tool included with OpenSSL. Either, but not both, of
Jonathan Balletc9e066c2011-07-17 22:56:05 +0900279 *pemfile* or *capath* may be :py:data:`None`.
280
281
282.. py:method:: Context.set_default_verify_paths()
283
284 Specify that the platform provided CA certificates are to be used for
285 verification purposes. This method may not work properly on OS X.
286
287
288.. py:method:: Context.load_tmp_dh(dhfile)
289
290 Load parameters for Ephemeral Diffie-Hellman from *dhfile*.
291
292
293.. py:method:: Context.set_app_data(data)
294
295 Associate *data* with this Context object. *data* can be retrieved
296 later using the :py:meth:`get_app_data` method.
297
298
299.. py:method:: Context.set_cipher_list(ciphers)
300
301 Set the list of ciphers to be used in this context. See the OpenSSL manual for
302 more information (e.g. :manpage:`ciphers(1)`)
303
304
305.. py:method:: Context.set_info_callback(callback)
306
307 Set the information callback to *callback*. This function will be called
308 from time to time during SSL handshakes.
309
Jonathan Ballet6381da32011-07-20 16:43:38 +0900310 *callback* should take three arguments: a Connection object and two integers.
311 The first integer specifies where in the SSL handshake the function was
312 called, and the other the return code from a (possibly failed) internal
Jonathan Balletc9e066c2011-07-17 22:56:05 +0900313 function call.
314
315
316.. py:method:: Context.set_options(options)
317
318 Add SSL options. Options you have set before are not cleared!
319 This method should be used with the :py:const:`OP_*` constants.
320
321
Jean-Paul Calderone21641542011-09-11 09:18:14 -0400322.. py:method:: Context.set_mode(mode)
323
324 Add SSL mode. Modes you have set before are not cleared! This method should
325 be used with the :py:const:`MODE_*` constants.
326
327
Jonathan Balletc9e066c2011-07-17 22:56:05 +0900328.. py:method:: Context.set_passwd_cb(callback[, userdata])
329
330 Set the passphrase callback to *callback*. This function will be called
331 when a private key with a passphrase is loaded. *callback* must accept
332 three positional arguments. First, an integer giving the maximum length of
333 the passphrase it may return. If the returned passphrase is longer than
334 this, it will be truncated. Second, a boolean value which will be true if
335 the user should be prompted for the passphrase twice and the callback should
336 verify that the two values supplied are equal. Third, the value given as the
337 *userdata* parameter to :py:meth:`set_passwd_cb`. If an error occurs,
338 *callback* should return a false value (e.g. an empty string).
339
340
Jean-Paul Calderone8e8f90c2012-02-08 13:16:26 -0500341.. py:method:: Context.set_session_cache_mode(mode)
342
343 Set the behavior of the session cache used by all connections using this
344 Context. The previously set mode is returned. See :py:const:`SESS_CACHE_*`
345 for details about particular modes.
346
347 .. versionadded:: 0.14
348
349
350.. py:method:: Context.get_session_cache_mode()
351
352 Get the current session cache mode.
353
354 .. versionadded:: 0.14
355
356
Jonathan Balletc9e066c2011-07-17 22:56:05 +0900357.. py:method:: Context.set_session_id(name)
358
359 Set the context *name* within which a session can be reused for this
360 Context object. This is needed when doing session resumption, because there is
361 no way for a stored session to know which Context object it is associated with.
362 *name* may be any binary data.
363
364
365.. py:method:: Context.set_timeout(timeout)
366
367 Set the timeout for newly created sessions for this Context object to
368 *timeout*. *timeout* must be given in (whole) seconds. The default
369 value is 300 seconds. See the OpenSSL manual for more information (e.g.
370 :manpage:`SSL_CTX_set_timeout(3)`).
371
372
373.. py:method:: Context.set_verify(mode, callback)
374
375 Set the verification flags for this Context object to *mode* and specify
376 that *callback* should be used for verification callbacks. *mode* should be
377 one of :py:const:`VERIFY_NONE` and :py:const:`VERIFY_PEER`. If
378 :py:const:`VERIFY_PEER` is used, *mode* can be OR:ed with
379 :py:const:`VERIFY_FAIL_IF_NO_PEER_CERT` and :py:const:`VERIFY_CLIENT_ONCE`
380 to further control the behaviour.
381
382 *callback* should take five arguments: A Connection object, an X509 object,
383 and three integer variables, which are in turn potential error number, error
384 depth and return code. *callback* should return true if verification passes
385 and false otherwise.
386
387
388.. py:method:: Context.set_verify_depth(depth)
389
390 Set the maximum depth for the certificate chain verification that shall be
391 allowed for this Context object.
392
393
394.. py:method:: Context.use_certificate(cert)
395
396 Use the certificate *cert* which has to be a X509 object.
397
398
399.. py:method:: Context.add_extra_chain_cert(cert)
400
401 Adds the certificate *cert*, which has to be a X509 object, to the
402 certificate chain presented together with the certificate.
403
404
405.. py:method:: Context.use_certificate_chain_file(file)
406
407 Load a certificate chain from *file* which must be PEM encoded.
408
409
410.. py:method:: Context.use_privatekey(pkey)
411
412 Use the private key *pkey* which has to be a PKey object.
413
414
415.. py:method:: Context.use_certificate_file(file[, format])
416
417 Load the first certificate found in *file*. The certificate must be in the
418 format specified by *format*, which is either :py:const:`FILETYPE_PEM` or
419 :py:const:`FILETYPE_ASN1`. The default is :py:const:`FILETYPE_PEM`.
420
421
422.. py:method:: Context.use_privatekey_file(file[, format])
423
424 Load the first private key found in *file*. The private key must be in the
425 format specified by *format*, which is either :py:const:`FILETYPE_PEM` or
426 :py:const:`FILETYPE_ASN1`. The default is :py:const:`FILETYPE_PEM`.
427
428
429.. py:method:: Context.set_tlsext_servername_callback(callback)
430
431 Specify a one-argument callable to use as the TLS extension server name
Jonathan Ballet6381da32011-07-20 16:43:38 +0900432 callback. When a connection using the server name extension is made using
433 this context, the callback will be invoked with the :py:class:`Connection`
434 instance.
Jonathan Balletc9e066c2011-07-17 22:56:05 +0900435
436 .. versionadded:: 0.13
437
438
Jean-Paul Calderone6c896fe2012-02-16 08:10:04 -0500439.. _openssl-session:
440
441Session objects
442---------------
443
444Session objects have no methods.
445
446
Jonathan Balletc9e066c2011-07-17 22:56:05 +0900447.. _openssl-connection:
448
449Connection objects
450------------------
451
452Connection objects have the following methods:
453
454.. py:method:: Connection.accept()
455
456 Call the :py:meth:`accept` method of the underlying socket and set up SSL on the
457 returned socket, using the Context object supplied to this Connection object at
458 creation. Returns a pair *(conn, address)*. where *conn* is the new
459 Connection object created, and *address* is as returned by the socket's
460 :py:meth:`accept`.
461
462
463.. py:method:: Connection.bind(address)
464
465 Call the :py:meth:`bind` method of the underlying socket.
466
467
468.. py:method:: Connection.close()
469
470 Call the :py:meth:`close` method of the underlying socket. Note: If you want
471 correct SSL closure, you need to call the :py:meth:`shutdown` method first.
472
473
474.. py:method:: Connection.connect(address)
475
476 Call the :py:meth:`connect` method of the underlying socket and set up SSL on the
477 socket, using the Context object supplied to this Connection object at
478 creation.
479
480
481.. py:method:: Connection.connect_ex(address)
482
483 Call the :py:meth:`connect_ex` method of the underlying socket and set up SSL on
484 the socket, using the Context object supplied to this Connection object at
485 creation. Note that if the :py:meth:`connect_ex` method of the socket doesn't
486 return 0, SSL won't be initialized.
487
488
489.. py:method:: Connection.do_handshake()
490
491 Perform an SSL handshake (usually called after :py:meth:`renegotiate` or one of
492 :py:meth:`set_accept_state` or :py:meth:`set_accept_state`). This can raise the
493 same exceptions as :py:meth:`send` and :py:meth:`recv`.
494
495
496.. py:method:: Connection.fileno()
497
498 Retrieve the file descriptor number for the underlying socket.
499
500
501.. py:method:: Connection.listen(backlog)
502
503 Call the :py:meth:`listen` method of the underlying socket.
504
505
506.. py:method:: Connection.get_app_data()
507
508 Retrieve application data as set by :py:meth:`set_app_data`.
509
510
511.. py:method:: Connection.get_cipher_list()
512
513 Retrieve the list of ciphers used by the Connection object. WARNING: This API
514 has changed. It used to take an optional parameter and just return a string,
515 but not it returns the entire list in one go.
516
517
518.. py:method:: Connection.get_client_ca_list()
519
520 Retrieve the list of preferred client certificate issuers sent by the server
521 as :py:class:`OpenSSL.crypto.X509Name` objects.
522
523 If this is a client :py:class:`Connection`, the list will be empty until the
524 connection with the server is established.
525
526 If this is a server :py:class:`Connection`, return the list of certificate
527 authorities that will be sent or has been sent to the client, as controlled
528 by this :py:class:`Connection`'s :py:class:`Context`.
529
530 .. versionadded:: 0.10
531
532
533.. py:method:: Connection.get_context()
534
535 Retrieve the Context object associated with this Connection.
536
537
538.. py:method:: Connection.set_context(context)
539
540 Specify a replacement Context object for this Connection.
541
542
543.. py:method:: Connection.get_peer_certificate()
544
545 Retrieve the other side's certificate (if any)
546
547
548.. py:method:: Connection.get_peer_cert_chain()
549
550 Retrieve the tuple of the other side's certificate chain (if any)
551
552
553.. py:method:: Connection.getpeername()
554
555 Call the :py:meth:`getpeername` method of the underlying socket.
556
557
558.. py:method:: Connection.getsockname()
559
560 Call the :py:meth:`getsockname` method of the underlying socket.
561
562
563.. py:method:: Connection.getsockopt(level, optname[, buflen])
564
565 Call the :py:meth:`getsockopt` method of the underlying socket.
566
567
568.. py:method:: Connection.pending()
569
570 Retrieve the number of bytes that can be safely read from the SSL buffer
571 (**not** the underlying transport buffer).
572
573
574.. py:method:: Connection.recv(bufsize)
575
576 Receive data from the Connection. The return value is a string representing the
577 data received. The maximum amount of data to be received at once, is specified
578 by *bufsize*.
579
580
581.. py:method:: Connection.bio_write(bytes)
582
583 If the Connection was created with a memory BIO, this method can be used to add
584 bytes to the read end of that memory BIO. The Connection can then read the
585 bytes (for example, in response to a call to :py:meth:`recv`).
586
587
588.. py:method:: Connection.renegotiate()
589
590 Renegotiate the SSL session. Call this if you wish to change cipher suites or
591 anything like that.
592
593
594.. py:method:: Connection.send(string)
595
596 Send the *string* data to the Connection.
597
598
599.. py:method:: Connection.bio_read(bufsize)
600
601 If the Connection was created with a memory BIO, this method can be used to
602 read bytes from the write end of that memory BIO. Many Connection methods will
603 add bytes which must be read in this manner or the buffer will eventually fill
604 up and the Connection will be able to take no further actions.
605
606
607.. py:method:: Connection.sendall(string)
608
609 Send all of the *string* data to the Connection. This calls :py:meth:`send`
610 repeatedly until all data is sent. If an error occurs, it's impossible to tell
611 how much data has been sent.
612
613
614.. py:method:: Connection.set_accept_state()
615
616 Set the connection to work in server mode. The handshake will be handled
617 automatically by read/write.
618
619
620.. py:method:: Connection.set_app_data(data)
621
622 Associate *data* with this Connection object. *data* can be retrieved
623 later using the :py:meth:`get_app_data` method.
624
625
626.. py:method:: Connection.set_connect_state()
627
628 Set the connection to work in client mode. The handshake will be handled
629 automatically by read/write.
630
631
632.. py:method:: Connection.setblocking(flag)
633
634 Call the :py:meth:`setblocking` method of the underlying socket.
635
636
637.. py:method:: Connection.setsockopt(level, optname, value)
638
639 Call the :py:meth:`setsockopt` method of the underlying socket.
640
641
642.. py:method:: Connection.shutdown()
643
644 Send the shutdown message to the Connection. Returns true if the shutdown
645 message exchange is completed and false otherwise (in which case you call
646 :py:meth:`recv` or :py:meth:`send` when the connection becomes
647 readable/writeable.
648
649
650.. py:method:: Connection.get_shutdown()
651
652 Get the shutdown state of the Connection. Returns a bitvector of either or
653 both of *SENT_SHUTDOWN* and *RECEIVED_SHUTDOWN*.
654
655
656.. py:method:: Connection.set_shutdown(state)
657
658 Set the shutdown state of the Connection. *state* is a bitvector of
659 either or both of *SENT_SHUTDOWN* and *RECEIVED_SHUTDOWN*.
660
661
662.. py:method:: Connection.sock_shutdown(how)
663
664 Call the :py:meth:`shutdown` method of the underlying socket.
665
666
667.. py:method:: Connection.bio_shutdown()
668
669 If the Connection was created with a memory BIO, this method can be used to
670 indicate that *end of file* has been reached on the read end of that memory
671 BIO.
672
673
674.. py:method:: Connection.state_string()
675
676 Retrieve a verbose string detailing the state of the Connection.
677
678
679.. py:method:: Connection.client_random()
680
681 Retrieve the random value used with the client hello message.
682
683
684.. py:method:: Connection.server_random()
685
686 Retrieve the random value used with the server hello message.
687
688
689.. py:method:: Connection.master_key()
690
691 Retrieve the value of the master key for this session.
692
693
694.. py:method:: Connection.want_read()
695
696 Checks if more data has to be read from the transport layer to complete an
697 operation.
698
699
700.. py:method:: Connection.want_write()
701
702 Checks if there is data to write to the transport layer to complete an
703 operation.
704
705
706.. py:method:: Connection.set_tlsext_host_name(name)
707
708 Specify the byte string to send as the server name in the client hello message.
709
710 .. versionadded:: 0.13
711
712
713.. py:method:: Connection.get_servername()
714
715 Get the value of the server name received in the client hello message.
716
717 .. versionadded:: 0.13
718
719
Jean-Paul Calderone6c896fe2012-02-16 08:10:04 -0500720.. py:method:: Connection.get_session()
721
722 Get a :py:class:`Session` instance representing the SSL session in use by
723 the connection, or :py:obj:`None` if there is no session.
724
725 .. versionadded:: 0.14
726
727
728.. py:method:: Connection.set_session(session)
729
730 Set a new SSL session (using a :py:class:`Session` instance) to be used by
731 the connection.
732
733 .. versionadded:: 0.14
734
735
Jonathan Ballet6381da32011-07-20 16:43:38 +0900736.. Rubric:: Footnotes
737
Jonathan Balletc9e066c2011-07-17 22:56:05 +0900738.. [#connection-context-socket] Actually, all that is required is an object that
739 **behaves** like a socket, you could even use files, even though it'd be
740 tricky to get the handshakes right!