Linux server.nvwebsoft.co.in 3.10.0-1160.114.2.el7.x86_64 #1 SMP Wed Mar 20 15:54:52 UTC 2024 x86_64
Apache
: 162.240.12.249 | : 3.15.202.169
202 Domain
8.1.31
nbspublicschool
www.github.com/MadExploits
Terminal
AUTO ROOT
Adminer
Backdoor Destroyer
Linux Exploit
Lock Shell
Lock File
Create User
CREATE RDP
PHP Mailer
BACKCONNECT
UNLOCK SHELL
HASH IDENTIFIER
CPANEL RESET
CREATE WP USER
README
+ Create Folder
+ Create File
/
usr /
share /
doc /
python-docs-2.7.5 /
html /
library /
[ HOME SHELL ]
Name
Size
Permission
Action
2to3.html
49.27
KB
-rw-r--r--
__builtin__.html
10.26
KB
-rw-r--r--
__future__.html
13.79
KB
-rw-r--r--
__main__.html
7.05
KB
-rw-r--r--
_winreg.html
59.21
KB
-rw-r--r--
abc.html
23.9
KB
-rw-r--r--
aepack.html
13.16
KB
-rw-r--r--
aetools.html
14.91
KB
-rw-r--r--
aetypes.html
18.88
KB
-rw-r--r--
aifc.html
22.4
KB
-rw-r--r--
al.html
17.34
KB
-rw-r--r--
allos.html
33.72
KB
-rw-r--r--
anydbm.html
16.33
KB
-rw-r--r--
archiving.html
9.26
KB
-rw-r--r--
argparse.html
237.62
KB
-rw-r--r--
array.html
29.29
KB
-rw-r--r--
ast.html
34.98
KB
-rw-r--r--
asynchat.html
31.43
KB
-rw-r--r--
asyncore.html
36.51
KB
-rw-r--r--
atexit.html
16.8
KB
-rw-r--r--
audioop.html
31.36
KB
-rw-r--r--
autogil.html
8.19
KB
-rw-r--r--
base64.html
19.67
KB
-rw-r--r--
basehttpserver.html
34.04
KB
-rw-r--r--
bastion.html
11.04
KB
-rw-r--r--
bdb.html
36.68
KB
-rw-r--r--
binascii.html
20.67
KB
-rw-r--r--
binhex.html
10.58
KB
-rw-r--r--
bisect.html
23.24
KB
-rw-r--r--
bsddb.html
26.43
KB
-rw-r--r--
bz2.html
26.08
KB
-rw-r--r--
calendar.html
37.79
KB
-rw-r--r--
carbon.html
48.94
KB
-rw-r--r--
cd.html
27.96
KB
-rw-r--r--
cgi.html
49.92
KB
-rw-r--r--
cgihttpserver.html
13.1
KB
-rw-r--r--
cgitb.html
11.41
KB
-rw-r--r--
chunk.html
14.66
KB
-rw-r--r--
cmath.html
25.63
KB
-rw-r--r--
cmd.html
26.09
KB
-rw-r--r--
code.html
24.58
KB
-rw-r--r--
codecs.html
100.64
KB
-rw-r--r--
codeop.html
14.84
KB
-rw-r--r--
collections.html
133.96
KB
-rw-r--r--
colorpicker.html
7.52
KB
-rw-r--r--
colorsys.html
11.04
KB
-rw-r--r--
commands.html
14.36
KB
-rw-r--r--
compileall.html
16.83
KB
-rw-r--r--
compiler.html
67.75
KB
-rw-r--r--
configparser.html
62.13
KB
-rw-r--r--
constants.html
12.83
KB
-rw-r--r--
contextlib.html
19.39
KB
-rw-r--r--
cookie.html
39.07
KB
-rw-r--r--
cookielib.html
83.82
KB
-rw-r--r--
copy.html
12.19
KB
-rw-r--r--
copy_reg.html
13.76
KB
-rw-r--r--
crypt.html
10.04
KB
-rw-r--r--
crypto.html
7.59
KB
-rw-r--r--
csv.html
67.37
KB
-rw-r--r--
ctypes.html
238.78
KB
-rw-r--r--
curses.ascii.html
22.29
KB
-rw-r--r--
curses.html
146.63
KB
-rw-r--r--
curses.panel.html
14.39
KB
-rw-r--r--
custominterp.html
7.62
KB
-rw-r--r--
datatypes.html
16.84
KB
-rw-r--r--
datetime.html
226.59
KB
-rw-r--r--
dbhash.html
15.48
KB
-rw-r--r--
dbm.html
12.07
KB
-rw-r--r--
debug.html
10.15
KB
-rw-r--r--
decimal.html
194.44
KB
-rw-r--r--
development.html
14.17
KB
-rw-r--r--
difflib.html
84.83
KB
-rw-r--r--
dircache.html
11.41
KB
-rw-r--r--
dis.html
69.95
KB
-rw-r--r--
distutils.html
8.05
KB
-rw-r--r--
dl.html
16.33
KB
-rw-r--r--
doctest.html
165.54
KB
-rw-r--r--
docxmlrpcserver.html
16.43
KB
-rw-r--r--
dumbdbm.html
14.02
KB
-rw-r--r--
dummy_thread.html
9.43
KB
-rw-r--r--
dummy_threading.html
8.37
KB
-rw-r--r--
easydialogs.html
30.55
KB
-rw-r--r--
email-examples.html
45.65
KB
-rw-r--r--
email.charset.html
26.8
KB
-rw-r--r--
email.encoders.html
11.86
KB
-rw-r--r--
email.errors.html
15.77
KB
-rw-r--r--
email.generator.html
20.77
KB
-rw-r--r--
email.header.html
26.92
KB
-rw-r--r--
email.html
44.24
KB
-rw-r--r--
email.iterators.html
11.52
KB
-rw-r--r--
email.message.html
63.16
KB
-rw-r--r--
email.mime.html
27.93
KB
-rw-r--r--
email.parser.html
30.45
KB
-rw-r--r--
email.util.html
24.46
KB
-rw-r--r--
errno.html
37.99
KB
-rw-r--r--
exceptions.html
56.13
KB
-rw-r--r--
fcntl.html
22.67
KB
-rw-r--r--
filecmp.html
22.3
KB
-rw-r--r--
fileformats.html
9.14
KB
-rw-r--r--
fileinput.html
24.28
KB
-rw-r--r--
filesys.html
10.2
KB
-rw-r--r--
fl.html
49.92
KB
-rw-r--r--
fm.html
11.91
KB
-rw-r--r--
fnmatch.html
14.58
KB
-rw-r--r--
formatter.html
34.06
KB
-rw-r--r--
fpectl.html
16.01
KB
-rw-r--r--
fpformat.html
10.59
KB
-rw-r--r--
fractions.html
22.61
KB
-rw-r--r--
framework.html
33.34
KB
-rw-r--r--
frameworks.html
7.14
KB
-rw-r--r--
ftplib.html
43.99
KB
-rw-r--r--
functions.html
183.14
KB
-rw-r--r--
functools.html
27.17
KB
-rw-r--r--
future_builtins.html
13.04
KB
-rw-r--r--
gc.html
25.75
KB
-rw-r--r--
gdbm.html
15.96
KB
-rw-r--r--
gensuitemodule.html
11.51
KB
-rw-r--r--
getopt.html
23.66
KB
-rw-r--r--
getpass.html
10.65
KB
-rw-r--r--
gettext.html
78.76
KB
-rw-r--r--
gl.html
22.09
KB
-rw-r--r--
glob.html
13.26
KB
-rw-r--r--
grp.html
10.49
KB
-rw-r--r--
gzip.html
18.99
KB
-rw-r--r--
hashlib.html
18.2
KB
-rw-r--r--
heapq.html
31.61
KB
-rw-r--r--
hmac.html
10.46
KB
-rw-r--r--
hotshot.html
18.65
KB
-rw-r--r--
htmllib.html
25.32
KB
-rw-r--r--
htmlparser.html
39.11
KB
-rw-r--r--
httplib.html
62.95
KB
-rw-r--r--
i18n.html
9.52
KB
-rw-r--r--
ic.html
17.17
KB
-rw-r--r--
idle.html
20.9
KB
-rw-r--r--
imageop.html
14.76
KB
-rw-r--r--
imaplib.html
51.99
KB
-rw-r--r--
imgfile.html
11.71
KB
-rw-r--r--
imghdr.html
11.3
KB
-rw-r--r--
imp.html
34.34
KB
-rw-r--r--
importlib.html
8.26
KB
-rw-r--r--
imputil.html
31.81
KB
-rw-r--r--
index.html
72.78
KB
-rw-r--r--
inspect.html
50.71
KB
-rw-r--r--
internet.html
24.87
KB
-rw-r--r--
intro.html
8.93
KB
-rw-r--r--
io.html
98.13
KB
-rw-r--r--
ipc.html
13.41
KB
-rw-r--r--
itertools.html
115.91
KB
-rw-r--r--
jpeg.html
12.74
KB
-rw-r--r--
json.html
67.04
KB
-rw-r--r--
keyword.html
7.68
KB
-rw-r--r--
language.html
11.03
KB
-rw-r--r--
linecache.html
10.59
KB
-rw-r--r--
locale.html
55.14
KB
-rw-r--r--
logging.config.html
63.36
KB
-rw-r--r--
logging.handlers.html
69.64
KB
-rw-r--r--
logging.html
95.64
KB
-rw-r--r--
mac.html
21.79
KB
-rw-r--r--
macos.html
14.76
KB
-rw-r--r--
macosa.html
12.96
KB
-rw-r--r--
macostools.html
15.52
KB
-rw-r--r--
macpath.html
7.76
KB
-rw-r--r--
mailbox.html
156.75
KB
-rw-r--r--
mailcap.html
13.21
KB
-rw-r--r--
markup.html
18.77
KB
-rw-r--r--
marshal.html
17.98
KB
-rw-r--r--
math.html
39.24
KB
-rw-r--r--
md5.html
13.97
KB
-rw-r--r--
mhlib.html
21.54
KB
-rw-r--r--
mimetools.html
19.25
KB
-rw-r--r--
mimetypes.html
28.39
KB
-rw-r--r--
mimewriter.html
15.02
KB
-rw-r--r--
mimify.html
13.36
KB
-rw-r--r--
miniaeframe.html
12.2
KB
-rw-r--r--
misc.html
6.87
KB
-rw-r--r--
mm.html
9.03
KB
-rw-r--r--
mmap.html
28.36
KB
-rw-r--r--
modulefinder.html
15.31
KB
-rw-r--r--
modules.html
8.46
KB
-rw-r--r--
msilib.html
52.43
KB
-rw-r--r--
msvcrt.html
19.37
KB
-rw-r--r--
multifile.html
24.3
KB
-rw-r--r--
multiprocessing.html
365.71
KB
-rw-r--r--
mutex.html
11.23
KB
-rw-r--r--
netdata.html
16.98
KB
-rw-r--r--
netrc.html
12.3
KB
-rw-r--r--
new.html
12.12
KB
-rw-r--r--
nis.html
10.64
KB
-rw-r--r--
nntplib.html
41.92
KB
-rw-r--r--
numbers.html
37.75
KB
-rw-r--r--
numeric.html
13.55
KB
-rw-r--r--
operator.html
82
KB
-rw-r--r--
optparse.html
222.56
KB
-rw-r--r--
os.html
214.25
KB
-rw-r--r--
os.path.html
38.34
KB
-rw-r--r--
ossaudiodev.html
41.5
KB
-rw-r--r--
othergui.html
9.08
KB
-rw-r--r--
parser.html
39.36
KB
-rw-r--r--
pdb.html
33.96
KB
-rw-r--r--
persistence.html
14.87
KB
-rw-r--r--
pickle.html
102.27
KB
-rw-r--r--
pickletools.html
10.63
KB
-rw-r--r--
pipes.html
18.01
KB
-rw-r--r--
pkgutil.html
25.11
KB
-rw-r--r--
platform.html
28.37
KB
-rw-r--r--
plistlib.html
17.03
KB
-rw-r--r--
popen2.html
25.43
KB
-rw-r--r--
poplib.html
22.32
KB
-rw-r--r--
posix.html
14.41
KB
-rw-r--r--
posixfile.html
19.76
KB
-rw-r--r--
pprint.html
29.92
KB
-rw-r--r--
profile.html
63.56
KB
-rw-r--r--
pty.html
9.48
KB
-rw-r--r--
pwd.html
11.43
KB
-rw-r--r--
py_compile.html
11.12
KB
-rw-r--r--
pyclbr.html
14.71
KB
-rw-r--r--
pydoc.html
11.48
KB
-rw-r--r--
pyexpat.html
71.53
KB
-rw-r--r--
python.html
12.27
KB
-rw-r--r--
queue.html
24.22
KB
-rw-r--r--
quopri.html
11.9
KB
-rw-r--r--
random.html
37.83
KB
-rw-r--r--
re.html
134.74
KB
-rw-r--r--
readline.html
28.24
KB
-rw-r--r--
repr.html
20.43
KB
-rw-r--r--
resource.html
26.48
KB
-rw-r--r--
restricted.html
11.65
KB
-rw-r--r--
rexec.html
37.41
KB
-rw-r--r--
rfc822.html
42.22
KB
-rw-r--r--
rlcompleter.html
13.51
KB
-rw-r--r--
robotparser.html
12.27
KB
-rw-r--r--
runpy.html
19.34
KB
-rw-r--r--
sched.html
18.54
KB
-rw-r--r--
scrolledtext.html
9.32
KB
-rw-r--r--
select.html
39.67
KB
-rw-r--r--
sets.html
36.92
KB
-rw-r--r--
sgi.html
9.71
KB
-rw-r--r--
sgmllib.html
30.77
KB
-rw-r--r--
sha.html
12.09
KB
-rw-r--r--
shelve.html
27.02
KB
-rw-r--r--
shlex.html
32.1
KB
-rw-r--r--
shutil.html
40.22
KB
-rw-r--r--
signal.html
31.14
KB
-rw-r--r--
simplehttpserver.html
18.41
KB
-rw-r--r--
simplexmlrpcserver.html
31.39
KB
-rw-r--r--
site.html
23.64
KB
-rw-r--r--
smtpd.html
12.46
KB
-rw-r--r--
smtplib.html
42.13
KB
-rw-r--r--
sndhdr.html
10.02
KB
-rw-r--r--
socket.html
106.34
KB
-rw-r--r--
socketserver.html
59.83
KB
-rw-r--r--
someos.html
15.11
KB
-rw-r--r--
spwd.html
10.33
KB
-rw-r--r--
sqlite3.html
139.5
KB
-rw-r--r--
ssl.html
65.62
KB
-rw-r--r--
stat.html
32.31
KB
-rw-r--r--
statvfs.html
10.6
KB
-rw-r--r--
stdtypes.html
260.4
KB
-rw-r--r--
string.html
106.65
KB
-rw-r--r--
stringio.html
18.81
KB
-rw-r--r--
stringprep.html
16.13
KB
-rw-r--r--
strings.html
14.93
KB
-rw-r--r--
struct.html
40.88
KB
-rw-r--r--
subprocess.html
84.91
KB
-rw-r--r--
sun.html
6.84
KB
-rw-r--r--
sunau.html
27.1
KB
-rw-r--r--
sunaudio.html
17.79
KB
-rw-r--r--
symbol.html
7.66
KB
-rw-r--r--
symtable.html
22.94
KB
-rw-r--r--
sys.html
98.7
KB
-rw-r--r--
sysconfig.html
23.84
KB
-rw-r--r--
syslog.html
17.92
KB
-rw-r--r--
tabnanny.html
10.63
KB
-rw-r--r--
tarfile.html
78.68
KB
-rw-r--r--
telnetlib.html
25.48
KB
-rw-r--r--
tempfile.html
29.42
KB
-rw-r--r--
termios.html
16.01
KB
-rw-r--r--
test.html
52.62
KB
-rw-r--r--
textwrap.html
27.25
KB
-rw-r--r--
thread.html
20.47
KB
-rw-r--r--
threading.html
76.69
KB
-rw-r--r--
time.html
56.93
KB
-rw-r--r--
timeit.html
36.27
KB
-rw-r--r--
tix.html
46.96
KB
-rw-r--r--
tk.html
23.64
KB
-rw-r--r--
tkinter.html
67.67
KB
-rw-r--r--
token.html
19.62
KB
-rw-r--r--
tokenize.html
18.45
KB
-rw-r--r--
trace.html
25.54
KB
-rw-r--r--
traceback.html
33.44
KB
-rw-r--r--
ttk.html
101.75
KB
-rw-r--r--
tty.html
9.06
KB
-rw-r--r--
turtle.html
211.74
KB
-rw-r--r--
types.html
27.59
KB
-rw-r--r--
undoc.html
23.16
KB
-rw-r--r--
unicodedata.html
18.55
KB
-rw-r--r--
unittest.html
202.85
KB
-rw-r--r--
unix.html
10.55
KB
-rw-r--r--
urllib.html
58.68
KB
-rw-r--r--
urllib2.html
100.58
KB
-rw-r--r--
urlparse.html
40.41
KB
-rw-r--r--
user.html
11.83
KB
-rw-r--r--
userdict.html
29.73
KB
-rw-r--r--
uu.html
11.03
KB
-rw-r--r--
uuid.html
28.19
KB
-rw-r--r--
warnings.html
46.6
KB
-rw-r--r--
wave.html
22.22
KB
-rw-r--r--
weakref.html
36.52
KB
-rw-r--r--
webbrowser.html
23.07
KB
-rw-r--r--
whichdb.html
8.85
KB
-rw-r--r--
windows.html
9.33
KB
-rw-r--r--
winsound.html
18.75
KB
-rw-r--r--
wsgiref.html
81.04
KB
-rw-r--r--
xdrlib.html
29.94
KB
-rw-r--r--
xml.dom.html
89.04
KB
-rw-r--r--
xml.dom.minidom.html
40.42
KB
-rw-r--r--
xml.dom.pulldom.html
12.71
KB
-rw-r--r--
xml.etree.elementtree.html
93.22
KB
-rw-r--r--
xml.html
16.49
KB
-rw-r--r--
xml.sax.handler.html
38.63
KB
-rw-r--r--
xml.sax.html
20.22
KB
-rw-r--r--
xml.sax.reader.html
39.09
KB
-rw-r--r--
xml.sax.utils.html
14.26
KB
-rw-r--r--
xmlrpclib.html
60.79
KB
-rw-r--r--
zipfile.html
53.14
KB
-rw-r--r--
zipimport.html
20.42
KB
-rw-r--r--
zlib.html
25.46
KB
-rw-r--r--
Delete
Unzip
Zip
${this.title}
Close
Code Editor : ssl.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>17.3. ssl — TLS/SSL wrapper for socket objects — Python 2.7.5 documentation</title> <link rel="stylesheet" href="../_static/default.css" type="text/css" /> <link rel="stylesheet" href="../_static/pygments.css" type="text/css" /> <script type="text/javascript"> var DOCUMENTATION_OPTIONS = { URL_ROOT: '../', VERSION: '2.7.5', COLLAPSE_INDEX: false, FILE_SUFFIX: '.html', HAS_SOURCE: true }; </script> <script type="text/javascript" src="../_static/jquery.js"></script> <script type="text/javascript" src="../_static/underscore.js"></script> <script type="text/javascript" src="../_static/doctools.js"></script> <script type="text/javascript" src="../_static/sidebar.js"></script> <link rel="search" type="application/opensearchdescription+xml" title="Search within Python 2.7.5 documentation" href="../_static/opensearch.xml"/> <link rel="author" title="About these documents" href="../about.html" /> <link rel="copyright" title="Copyright" href="../copyright.html" /> <link rel="top" title="Python 2.7.5 documentation" href="../index.html" /> <link rel="up" title="17. Interprocess Communication and Networking" href="ipc.html" /> <link rel="next" title="17.4. signal — Set handlers for asynchronous events" href="signal.html" /> <link rel="prev" title="17.2. socket — Low-level networking interface" href="socket.html" /> <link rel="shortcut icon" type="image/png" href="../_static/py.png" /> <script type="text/javascript" src="../_static/copybutton.js"></script> </head> <body> <div class="related"> <h3>Navigation</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="../genindex.html" title="General Index" accesskey="I">index</a></li> <li class="right" > <a href="../py-modindex.html" title="Python Module Index" >modules</a> |</li> <li class="right" > <a href="signal.html" title="17.4. signal — Set handlers for asynchronous events" accesskey="N">next</a> |</li> <li class="right" > <a href="socket.html" title="17.2. socket — Low-level networking interface" accesskey="P">previous</a> |</li> <li><img src="../_static/py.png" alt="" style="vertical-align: middle; margin-top: -1px"/></li> <li><a href="http://www.python.org/">Python</a> »</li> <li> <a href="../index.html">Python 2.7.5 documentation</a> » </li> <li><a href="index.html" >The Python Standard Library</a> »</li> <li><a href="ipc.html" accesskey="U">17. Interprocess Communication and Networking</a> »</li> </ul> </div> <div class="document"> <div class="documentwrapper"> <div class="bodywrapper"> <div class="body"> <div class="section" id="module-ssl"> <span id="ssl-tls-ssl-wrapper-for-socket-objects"></span><h1>17.3. <a class="reference internal" href="#module-ssl" title="ssl: TLS/SSL wrapper for socket objects"><tt class="xref py py-mod docutils literal"><span class="pre">ssl</span></tt></a> — TLS/SSL wrapper for socket objects<a class="headerlink" href="#module-ssl" title="Permalink to this headline">¶</a></h1> <span class="target" id="index-0"></span><p class="versionadded" id="index-1"> <span class="versionmodified">New in version 2.6.</span></p> <p><strong>Source code:</strong> <a class="reference external" href="http://hg.python.org/cpython/file/2.7/Lib/ssl.py">Lib/ssl.py</a></p> <hr class="docutils" /> <p>This module provides access to Transport Layer Security (often known as “Secure Sockets Layer”) encryption and peer authentication facilities for network sockets, both client-side and server-side. This module uses the OpenSSL library. It is available on all modern Unix systems, Windows, Mac OS X, and probably additional platforms, as long as OpenSSL is installed on that platform.</p> <div class="admonition note"> <p class="first admonition-title">Note</p> <p class="last">Some behavior may be platform dependent, since calls are made to the operating system socket APIs. The installed version of OpenSSL may also cause variations in behavior.</p> </div> <p>This section documents the objects and functions in the <tt class="docutils literal"><span class="pre">ssl</span></tt> module; for more general information about TLS, SSL, and certificates, the reader is referred to the documents in the “See Also” section at the bottom.</p> <p>This module provides a class, <tt class="xref py py-class docutils literal"><span class="pre">ssl.SSLSocket</span></tt>, which is derived from the <a class="reference internal" href="socket.html#socket.socket" title="socket.socket"><tt class="xref py py-class docutils literal"><span class="pre">socket.socket</span></tt></a> type, and provides a socket-like wrapper that also encrypts and decrypts the data going over the socket with SSL. It supports additional <tt class="xref py py-meth docutils literal"><span class="pre">read()</span></tt> and <tt class="xref py py-meth docutils literal"><span class="pre">write()</span></tt> methods, along with a method, <tt class="xref py py-meth docutils literal"><span class="pre">getpeercert()</span></tt>, to retrieve the certificate of the other side of the connection, and a method, <tt class="xref py py-meth docutils literal"><span class="pre">cipher()</span></tt>, to retrieve the cipher being used for the secure connection.</p> <div class="section" id="functions-constants-and-exceptions"> <h2>17.3.1. Functions, Constants, and Exceptions<a class="headerlink" href="#functions-constants-and-exceptions" title="Permalink to this headline">¶</a></h2> <dl class="exception"> <dt id="ssl.SSLError"> <em class="property">exception </em><tt class="descclassname">ssl.</tt><tt class="descname">SSLError</tt><a class="headerlink" href="#ssl.SSLError" title="Permalink to this definition">¶</a></dt> <dd><p>Raised to signal an error from the underlying SSL implementation. This signifies some problem in the higher-level encryption and authentication layer that’s superimposed on the underlying network connection. This error is a subtype of <a class="reference internal" href="socket.html#socket.error" title="socket.error"><tt class="xref py py-exc docutils literal"><span class="pre">socket.error</span></tt></a>, which in turn is a subtype of <a class="reference internal" href="exceptions.html#exceptions.IOError" title="exceptions.IOError"><tt class="xref py py-exc docutils literal"><span class="pre">IOError</span></tt></a>.</p> </dd></dl> <dl class="function"> <dt id="ssl.wrap_socket"> <tt class="descclassname">ssl.</tt><tt class="descname">wrap_socket</tt><big>(</big><em>sock</em>, <em>keyfile=None</em>, <em>certfile=None</em>, <em>server_side=False</em>, <em>cert_reqs=CERT_NONE</em>, <em>ssl_version={see docs}</em>, <em>ca_certs=None</em>, <em>do_handshake_on_connect=True</em>, <em>suppress_ragged_eofs=True</em>, <em>ciphers=None</em><big>)</big><a class="headerlink" href="#ssl.wrap_socket" title="Permalink to this definition">¶</a></dt> <dd><p>Takes an instance <tt class="docutils literal"><span class="pre">sock</span></tt> of <a class="reference internal" href="socket.html#socket.socket" title="socket.socket"><tt class="xref py py-class docutils literal"><span class="pre">socket.socket</span></tt></a>, and returns an instance of <tt class="xref py py-class docutils literal"><span class="pre">ssl.SSLSocket</span></tt>, a subtype of <a class="reference internal" href="socket.html#socket.socket" title="socket.socket"><tt class="xref py py-class docutils literal"><span class="pre">socket.socket</span></tt></a>, which wraps the underlying socket in an SSL context. For client-side sockets, the context construction is lazy; if the underlying socket isn’t connected yet, the context construction will be performed after <tt class="xref py py-meth docutils literal"><span class="pre">connect()</span></tt> is called on the socket. For server-side sockets, if the socket has no remote peer, it is assumed to be a listening socket, and the server-side SSL wrapping is automatically performed on client connections accepted via the <tt class="xref py py-meth docutils literal"><span class="pre">accept()</span></tt> method. <a class="reference internal" href="#ssl.wrap_socket" title="ssl.wrap_socket"><tt class="xref py py-func docutils literal"><span class="pre">wrap_socket()</span></tt></a> may raise <a class="reference internal" href="#ssl.SSLError" title="ssl.SSLError"><tt class="xref py py-exc docutils literal"><span class="pre">SSLError</span></tt></a>.</p> <p>The <tt class="docutils literal"><span class="pre">keyfile</span></tt> and <tt class="docutils literal"><span class="pre">certfile</span></tt> parameters specify optional files which contain a certificate to be used to identify the local side of the connection. See the discussion of <a class="reference internal" href="#ssl-certificates"><em>Certificates</em></a> for more information on how the certificate is stored in the <tt class="docutils literal"><span class="pre">certfile</span></tt>.</p> <p>Often the private key is stored in the same file as the certificate; in this case, only the <tt class="docutils literal"><span class="pre">certfile</span></tt> parameter need be passed. If the private key is stored in a separate file, both parameters must be used. If the private key is stored in the <tt class="docutils literal"><span class="pre">certfile</span></tt>, it should come before the first certificate in the certificate chain:</p> <div class="highlight-python"><pre>-----BEGIN RSA PRIVATE KEY----- ... (private key in base64 encoding) ... -----END RSA PRIVATE KEY----- -----BEGIN CERTIFICATE----- ... (certificate in base64 PEM encoding) ... -----END CERTIFICATE-----</pre> </div> <p>The parameter <tt class="docutils literal"><span class="pre">server_side</span></tt> is a boolean which identifies whether server-side or client-side behavior is desired from this socket.</p> <p>The parameter <tt class="docutils literal"><span class="pre">cert_reqs</span></tt> specifies whether a certificate is required from the other side of the connection, and whether it will be validated if provided. It must be one of the three values <a class="reference internal" href="#ssl.CERT_NONE" title="ssl.CERT_NONE"><tt class="xref py py-const docutils literal"><span class="pre">CERT_NONE</span></tt></a> (certificates ignored), <a class="reference internal" href="#ssl.CERT_OPTIONAL" title="ssl.CERT_OPTIONAL"><tt class="xref py py-const docutils literal"><span class="pre">CERT_OPTIONAL</span></tt></a> (not required, but validated if provided), or <a class="reference internal" href="#ssl.CERT_REQUIRED" title="ssl.CERT_REQUIRED"><tt class="xref py py-const docutils literal"><span class="pre">CERT_REQUIRED</span></tt></a> (required and validated). If the value of this parameter is not <a class="reference internal" href="#ssl.CERT_NONE" title="ssl.CERT_NONE"><tt class="xref py py-const docutils literal"><span class="pre">CERT_NONE</span></tt></a>, then the <tt class="docutils literal"><span class="pre">ca_certs</span></tt> parameter must point to a file of CA certificates.</p> <p>The <tt class="docutils literal"><span class="pre">ca_certs</span></tt> file contains a set of concatenated “certification authority” certificates, which are used to validate certificates passed from the other end of the connection. See the discussion of <a class="reference internal" href="#ssl-certificates"><em>Certificates</em></a> for more information about how to arrange the certificates in this file.</p> <p>The parameter <tt class="docutils literal"><span class="pre">ssl_version</span></tt> specifies which version of the SSL protocol to use. Typically, the server chooses a particular protocol version, and the client must adapt to the server’s choice. Most of the versions are not interoperable with the other versions. If not specified, the default is <a class="reference internal" href="#ssl.PROTOCOL_SSLv23" title="ssl.PROTOCOL_SSLv23"><tt class="xref py py-data docutils literal"><span class="pre">PROTOCOL_SSLv23</span></tt></a>; it provides the most compatibility with other versions.</p> <p>Here’s a table showing which versions in a client (down the side) can connect to which versions in a server (along the top):</p> <blockquote> <div><table border="1" class="docutils"> <colgroup> <col width="39%" /> <col width="15%" /> <col width="15%" /> <col width="16%" /> <col width="15%" /> </colgroup> <tbody valign="top"> <tr class="row-odd"><td><em>client</em> / <strong>server</strong></td> <td><strong>SSLv2</strong></td> <td><strong>SSLv3</strong></td> <td><strong>SSLv23</strong></td> <td><strong>TLSv1</strong></td> </tr> <tr class="row-even"><td><em>SSLv2</em></td> <td>yes</td> <td>no</td> <td>yes</td> <td>no</td> </tr> <tr class="row-odd"><td><em>SSLv3</em></td> <td>no</td> <td>yes</td> <td>yes</td> <td>no</td> </tr> <tr class="row-even"><td><em>SSLv23</em></td> <td>yes</td> <td>no</td> <td>yes</td> <td>no</td> </tr> <tr class="row-odd"><td><em>TLSv1</em></td> <td>no</td> <td>no</td> <td>yes</td> <td>yes</td> </tr> </tbody> </table> </div></blockquote> <div class="admonition note"> <p class="first admonition-title">Note</p> <p class="last">Which connections succeed will vary depending on the version of OpenSSL. For instance, in some older versions of OpenSSL (such as 0.9.7l on OS X 10.4), an SSLv2 client could not connect to an SSLv23 server. Another example: beginning with OpenSSL 1.0.0, an SSLv23 client will not actually attempt SSLv2 connections unless you explicitly enable SSLv2 ciphers; for example, you might specify <tt class="docutils literal"><span class="pre">"ALL"</span></tt> or <tt class="docutils literal"><span class="pre">"SSLv2"</span></tt> as the <em>ciphers</em> parameter to enable them.</p> </div> <p>The <em>ciphers</em> parameter sets the available ciphers for this SSL object. It should be a string in the <a class="reference external" href="http://www.openssl.org/docs/apps/ciphers.html#CIPHER_LIST_FORMAT">OpenSSL cipher list format</a>.</p> <p>The parameter <tt class="docutils literal"><span class="pre">do_handshake_on_connect</span></tt> specifies whether to do the SSL handshake automatically after doing a <tt class="xref py py-meth docutils literal"><span class="pre">socket.connect()</span></tt>, or whether the application program will call it explicitly, by invoking the <a class="reference internal" href="#ssl.SSLSocket.do_handshake" title="ssl.SSLSocket.do_handshake"><tt class="xref py py-meth docutils literal"><span class="pre">SSLSocket.do_handshake()</span></tt></a> method. Calling <a class="reference internal" href="#ssl.SSLSocket.do_handshake" title="ssl.SSLSocket.do_handshake"><tt class="xref py py-meth docutils literal"><span class="pre">SSLSocket.do_handshake()</span></tt></a> explicitly gives the program control over the blocking behavior of the socket I/O involved in the handshake.</p> <p>The parameter <tt class="docutils literal"><span class="pre">suppress_ragged_eofs</span></tt> specifies how the <tt class="xref py py-meth docutils literal"><span class="pre">SSLSocket.read()</span></tt> method should signal unexpected EOF from the other end of the connection. If specified as <a class="reference internal" href="constants.html#True" title="True"><tt class="xref py py-const docutils literal"><span class="pre">True</span></tt></a> (the default), it returns a normal EOF in response to unexpected EOF errors raised from the underlying socket; if <a class="reference internal" href="constants.html#False" title="False"><tt class="xref py py-const docutils literal"><span class="pre">False</span></tt></a>, it will raise the exceptions back to the caller.</p> <p class="versionchanged"> <span class="versionmodified">Changed in version 2.7: </span>New optional argument <em>ciphers</em>.</p> </dd></dl> <dl class="function"> <dt id="ssl.RAND_status"> <tt class="descclassname">ssl.</tt><tt class="descname">RAND_status</tt><big>(</big><big>)</big><a class="headerlink" href="#ssl.RAND_status" title="Permalink to this definition">¶</a></dt> <dd><p>Returns True if the SSL pseudo-random number generator has been seeded with ‘enough’ randomness, and False otherwise. You can use <a class="reference internal" href="#ssl.RAND_egd" title="ssl.RAND_egd"><tt class="xref py py-func docutils literal"><span class="pre">ssl.RAND_egd()</span></tt></a> and <a class="reference internal" href="#ssl.RAND_add" title="ssl.RAND_add"><tt class="xref py py-func docutils literal"><span class="pre">ssl.RAND_add()</span></tt></a> to increase the randomness of the pseudo-random number generator.</p> </dd></dl> <dl class="function"> <dt id="ssl.RAND_egd"> <tt class="descclassname">ssl.</tt><tt class="descname">RAND_egd</tt><big>(</big><em>path</em><big>)</big><a class="headerlink" href="#ssl.RAND_egd" title="Permalink to this definition">¶</a></dt> <dd><p>If you are running an entropy-gathering daemon (EGD) somewhere, and <tt class="docutils literal"><span class="pre">path</span></tt> is the pathname of a socket connection open to it, this will read 256 bytes of randomness from the socket, and add it to the SSL pseudo-random number generator to increase the security of generated secret keys. This is typically only necessary on systems without better sources of randomness.</p> <p>See <a class="reference external" href="http://egd.sourceforge.net/">http://egd.sourceforge.net/</a> or <a class="reference external" href="http://prngd.sourceforge.net/">http://prngd.sourceforge.net/</a> for sources of entropy-gathering daemons.</p> </dd></dl> <dl class="function"> <dt id="ssl.RAND_add"> <tt class="descclassname">ssl.</tt><tt class="descname">RAND_add</tt><big>(</big><em>bytes</em>, <em>entropy</em><big>)</big><a class="headerlink" href="#ssl.RAND_add" title="Permalink to this definition">¶</a></dt> <dd><p>Mixes the given <tt class="docutils literal"><span class="pre">bytes</span></tt> into the SSL pseudo-random number generator. The parameter <tt class="docutils literal"><span class="pre">entropy</span></tt> (a float) is a lower bound on the entropy contained in string (so you can always use <tt class="xref py py-const docutils literal"><span class="pre">0.0</span></tt>). See <span class="target" id="index-2"></span><a class="rfc reference external" href="http://tools.ietf.org/html/rfc1750.html"><strong>RFC 1750</strong></a> for more information on sources of entropy.</p> </dd></dl> <dl class="function"> <dt id="ssl.cert_time_to_seconds"> <tt class="descclassname">ssl.</tt><tt class="descname">cert_time_to_seconds</tt><big>(</big><em>timestring</em><big>)</big><a class="headerlink" href="#ssl.cert_time_to_seconds" title="Permalink to this definition">¶</a></dt> <dd><p>Returns a floating-point value containing a normal seconds-after-the-epoch time value, given the time-string representing the “notBefore” or “notAfter” date from a certificate.</p> <p>Here’s an example:</p> <div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="kn">import</span> <span class="nn">ssl</span> <span class="gp">>>> </span><span class="n">ssl</span><span class="o">.</span><span class="n">cert_time_to_seconds</span><span class="p">(</span><span class="s">"May 9 00:00:00 2007 GMT"</span><span class="p">)</span> <span class="go">1178694000.0</span> <span class="gp">>>> </span><span class="kn">import</span> <span class="nn">time</span> <span class="gp">>>> </span><span class="n">time</span><span class="o">.</span><span class="n">ctime</span><span class="p">(</span><span class="n">ssl</span><span class="o">.</span><span class="n">cert_time_to_seconds</span><span class="p">(</span><span class="s">"May 9 00:00:00 2007 GMT"</span><span class="p">))</span> <span class="go">'Wed May 9 00:00:00 2007'</span> <span class="go">>>></span> </pre></div> </div> </dd></dl> <dl class="function"> <dt id="ssl.get_server_certificate"> <tt class="descclassname">ssl.</tt><tt class="descname">get_server_certificate</tt><big>(</big><em>addr</em>, <em>ssl_version=PROTOCOL_SSLv3</em>, <em>ca_certs=None</em><big>)</big><a class="headerlink" href="#ssl.get_server_certificate" title="Permalink to this definition">¶</a></dt> <dd><p>Given the address <tt class="docutils literal"><span class="pre">addr</span></tt> of an SSL-protected server, as a (<em>hostname</em>, <em>port-number</em>) pair, fetches the server’s certificate, and returns it as a PEM-encoded string. If <tt class="docutils literal"><span class="pre">ssl_version</span></tt> is specified, uses that version of the SSL protocol to attempt to connect to the server. If <tt class="docutils literal"><span class="pre">ca_certs</span></tt> is specified, it should be a file containing a list of root certificates, the same format as used for the same parameter in <a class="reference internal" href="#ssl.wrap_socket" title="ssl.wrap_socket"><tt class="xref py py-func docutils literal"><span class="pre">wrap_socket()</span></tt></a>. The call will attempt to validate the server certificate against that set of root certificates, and will fail if the validation attempt fails.</p> </dd></dl> <dl class="function"> <dt id="ssl.DER_cert_to_PEM_cert"> <tt class="descclassname">ssl.</tt><tt class="descname">DER_cert_to_PEM_cert</tt><big>(</big><em>DER_cert_bytes</em><big>)</big><a class="headerlink" href="#ssl.DER_cert_to_PEM_cert" title="Permalink to this definition">¶</a></dt> <dd><p>Given a certificate as a DER-encoded blob of bytes, returns a PEM-encoded string version of the same certificate.</p> </dd></dl> <dl class="function"> <dt id="ssl.PEM_cert_to_DER_cert"> <tt class="descclassname">ssl.</tt><tt class="descname">PEM_cert_to_DER_cert</tt><big>(</big><em>PEM_cert_string</em><big>)</big><a class="headerlink" href="#ssl.PEM_cert_to_DER_cert" title="Permalink to this definition">¶</a></dt> <dd><p>Given a certificate as an ASCII PEM string, returns a DER-encoded sequence of bytes for that same certificate.</p> </dd></dl> <dl class="data"> <dt id="ssl.CERT_NONE"> <tt class="descclassname">ssl.</tt><tt class="descname">CERT_NONE</tt><a class="headerlink" href="#ssl.CERT_NONE" title="Permalink to this definition">¶</a></dt> <dd><p>Value to pass to the <tt class="docutils literal"><span class="pre">cert_reqs</span></tt> parameter to <tt class="xref py py-func docutils literal"><span class="pre">sslobject()</span></tt> when no certificates will be required or validated from the other side of the socket connection.</p> </dd></dl> <dl class="data"> <dt id="ssl.CERT_OPTIONAL"> <tt class="descclassname">ssl.</tt><tt class="descname">CERT_OPTIONAL</tt><a class="headerlink" href="#ssl.CERT_OPTIONAL" title="Permalink to this definition">¶</a></dt> <dd><p>Value to pass to the <tt class="docutils literal"><span class="pre">cert_reqs</span></tt> parameter to <tt class="xref py py-func docutils literal"><span class="pre">sslobject()</span></tt> when no certificates will be required from the other side of the socket connection, but if they are provided, will be validated. Note that use of this setting requires a valid certificate validation file also be passed as a value of the <tt class="docutils literal"><span class="pre">ca_certs</span></tt> parameter.</p> </dd></dl> <dl class="data"> <dt id="ssl.CERT_REQUIRED"> <tt class="descclassname">ssl.</tt><tt class="descname">CERT_REQUIRED</tt><a class="headerlink" href="#ssl.CERT_REQUIRED" title="Permalink to this definition">¶</a></dt> <dd><p>Value to pass to the <tt class="docutils literal"><span class="pre">cert_reqs</span></tt> parameter to <tt class="xref py py-func docutils literal"><span class="pre">sslobject()</span></tt> when certificates will be required from the other side of the socket connection. Note that use of this setting requires a valid certificate validation file also be passed as a value of the <tt class="docutils literal"><span class="pre">ca_certs</span></tt> parameter.</p> </dd></dl> <dl class="data"> <dt id="ssl.PROTOCOL_SSLv2"> <tt class="descclassname">ssl.</tt><tt class="descname">PROTOCOL_SSLv2</tt><a class="headerlink" href="#ssl.PROTOCOL_SSLv2" title="Permalink to this definition">¶</a></dt> <dd><p>Selects SSL version 2 as the channel encryption protocol.</p> <p>This protocol is not available if OpenSSL is compiled with OPENSSL_NO_SSL2 flag.</p> <div class="admonition warning"> <p class="first admonition-title">Warning</p> <p class="last">SSL version 2 is insecure. Its use is highly discouraged.</p> </div> </dd></dl> <dl class="data"> <dt id="ssl.PROTOCOL_SSLv23"> <tt class="descclassname">ssl.</tt><tt class="descname">PROTOCOL_SSLv23</tt><a class="headerlink" href="#ssl.PROTOCOL_SSLv23" title="Permalink to this definition">¶</a></dt> <dd><p>Selects SSL version 2 or 3 as the channel encryption protocol. This is a setting to use with servers for maximum compatibility with the other end of an SSL connection, but it may cause the specific ciphers chosen for the encryption to be of fairly low quality.</p> </dd></dl> <dl class="data"> <dt id="ssl.PROTOCOL_SSLv3"> <tt class="descclassname">ssl.</tt><tt class="descname">PROTOCOL_SSLv3</tt><a class="headerlink" href="#ssl.PROTOCOL_SSLv3" title="Permalink to this definition">¶</a></dt> <dd><p>Selects SSL version 3 as the channel encryption protocol. For clients, this is the maximally compatible SSL variant.</p> </dd></dl> <dl class="data"> <dt id="ssl.PROTOCOL_TLSv1"> <tt class="descclassname">ssl.</tt><tt class="descname">PROTOCOL_TLSv1</tt><a class="headerlink" href="#ssl.PROTOCOL_TLSv1" title="Permalink to this definition">¶</a></dt> <dd><p>Selects TLS version 1 as the channel encryption protocol. This is the most modern version, and probably the best choice for maximum protection, if both sides can speak it.</p> </dd></dl> <dl class="data"> <dt id="ssl.OPENSSL_VERSION"> <tt class="descclassname">ssl.</tt><tt class="descname">OPENSSL_VERSION</tt><a class="headerlink" href="#ssl.OPENSSL_VERSION" title="Permalink to this definition">¶</a></dt> <dd><p>The version string of the OpenSSL library loaded by the interpreter:</p> <div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">ssl</span><span class="o">.</span><span class="n">OPENSSL_VERSION</span> <span class="go">'OpenSSL 0.9.8k 25 Mar 2009'</span> </pre></div> </div> <p class="versionadded"> <span class="versionmodified">New in version 2.7.</span></p> </dd></dl> <dl class="data"> <dt id="ssl.OPENSSL_VERSION_INFO"> <tt class="descclassname">ssl.</tt><tt class="descname">OPENSSL_VERSION_INFO</tt><a class="headerlink" href="#ssl.OPENSSL_VERSION_INFO" title="Permalink to this definition">¶</a></dt> <dd><p>A tuple of five integers representing version information about the OpenSSL library:</p> <div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">ssl</span><span class="o">.</span><span class="n">OPENSSL_VERSION_INFO</span> <span class="go">(0, 9, 8, 11, 15)</span> </pre></div> </div> <p class="versionadded"> <span class="versionmodified">New in version 2.7.</span></p> </dd></dl> <dl class="data"> <dt id="ssl.OPENSSL_VERSION_NUMBER"> <tt class="descclassname">ssl.</tt><tt class="descname">OPENSSL_VERSION_NUMBER</tt><a class="headerlink" href="#ssl.OPENSSL_VERSION_NUMBER" title="Permalink to this definition">¶</a></dt> <dd><p>The raw version number of the OpenSSL library, as a single integer:</p> <div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">ssl</span><span class="o">.</span><span class="n">OPENSSL_VERSION_NUMBER</span> <span class="go">9470143L</span> <span class="gp">>>> </span><span class="nb">hex</span><span class="p">(</span><span class="n">ssl</span><span class="o">.</span><span class="n">OPENSSL_VERSION_NUMBER</span><span class="p">)</span> <span class="go">'0x9080bfL'</span> </pre></div> </div> <p class="versionadded"> <span class="versionmodified">New in version 2.7.</span></p> </dd></dl> </div> <div class="section" id="sslsocket-objects"> <h2>17.3.2. SSLSocket Objects<a class="headerlink" href="#sslsocket-objects" title="Permalink to this headline">¶</a></h2> <p>SSL sockets provide the following methods of <a class="reference internal" href="socket.html#socket-objects"><em>Socket Objects</em></a>:</p> <ul class="simple"> <li><a class="reference internal" href="socket.html#socket.socket.accept" title="socket.socket.accept"><tt class="xref py py-meth docutils literal"><span class="pre">accept()</span></tt></a></li> <li><a class="reference internal" href="socket.html#socket.socket.bind" title="socket.socket.bind"><tt class="xref py py-meth docutils literal"><span class="pre">bind()</span></tt></a></li> <li><a class="reference internal" href="socket.html#socket.socket.close" title="socket.socket.close"><tt class="xref py py-meth docutils literal"><span class="pre">close()</span></tt></a></li> <li><a class="reference internal" href="socket.html#socket.socket.connect" title="socket.socket.connect"><tt class="xref py py-meth docutils literal"><span class="pre">connect()</span></tt></a></li> <li><a class="reference internal" href="socket.html#socket.socket.fileno" title="socket.socket.fileno"><tt class="xref py py-meth docutils literal"><span class="pre">fileno()</span></tt></a></li> <li><a class="reference internal" href="socket.html#socket.socket.getpeername" title="socket.socket.getpeername"><tt class="xref py py-meth docutils literal"><span class="pre">getpeername()</span></tt></a>, <a class="reference internal" href="socket.html#socket.socket.getsockname" title="socket.socket.getsockname"><tt class="xref py py-meth docutils literal"><span class="pre">getsockname()</span></tt></a></li> <li><a class="reference internal" href="socket.html#socket.socket.getsockopt" title="socket.socket.getsockopt"><tt class="xref py py-meth docutils literal"><span class="pre">getsockopt()</span></tt></a>, <a class="reference internal" href="socket.html#socket.socket.setsockopt" title="socket.socket.setsockopt"><tt class="xref py py-meth docutils literal"><span class="pre">setsockopt()</span></tt></a></li> <li><a class="reference internal" href="socket.html#socket.socket.gettimeout" title="socket.socket.gettimeout"><tt class="xref py py-meth docutils literal"><span class="pre">gettimeout()</span></tt></a>, <a class="reference internal" href="socket.html#socket.socket.settimeout" title="socket.socket.settimeout"><tt class="xref py py-meth docutils literal"><span class="pre">settimeout()</span></tt></a>, <a class="reference internal" href="socket.html#socket.socket.setblocking" title="socket.socket.setblocking"><tt class="xref py py-meth docutils literal"><span class="pre">setblocking()</span></tt></a></li> <li><a class="reference internal" href="socket.html#socket.socket.listen" title="socket.socket.listen"><tt class="xref py py-meth docutils literal"><span class="pre">listen()</span></tt></a></li> <li><a class="reference internal" href="socket.html#socket.socket.makefile" title="socket.socket.makefile"><tt class="xref py py-meth docutils literal"><span class="pre">makefile()</span></tt></a></li> <li><a class="reference internal" href="socket.html#socket.socket.recv" title="socket.socket.recv"><tt class="xref py py-meth docutils literal"><span class="pre">recv()</span></tt></a>, <a class="reference internal" href="socket.html#socket.socket.recv_into" title="socket.socket.recv_into"><tt class="xref py py-meth docutils literal"><span class="pre">recv_into()</span></tt></a> (but passing a non-zero <tt class="docutils literal"><span class="pre">flags</span></tt> argument is not allowed)</li> <li><a class="reference internal" href="socket.html#socket.socket.send" title="socket.socket.send"><tt class="xref py py-meth docutils literal"><span class="pre">send()</span></tt></a>, <a class="reference internal" href="socket.html#socket.socket.sendall" title="socket.socket.sendall"><tt class="xref py py-meth docutils literal"><span class="pre">sendall()</span></tt></a> (with the same limitation)</li> <li><a class="reference internal" href="socket.html#socket.socket.shutdown" title="socket.socket.shutdown"><tt class="xref py py-meth docutils literal"><span class="pre">shutdown()</span></tt></a></li> </ul> <p>However, since the SSL (and TLS) protocol has its own framing atop of TCP, the SSL sockets abstraction can, in certain respects, diverge from the specification of normal, OS-level sockets.</p> <p>SSL sockets also have the following additional methods and attributes:</p> <dl class="method"> <dt id="ssl.SSLSocket.getpeercert"> <tt class="descclassname">SSLSocket.</tt><tt class="descname">getpeercert</tt><big>(</big><em>binary_form=False</em><big>)</big><a class="headerlink" href="#ssl.SSLSocket.getpeercert" title="Permalink to this definition">¶</a></dt> <dd><p>If there is no certificate for the peer on the other end of the connection, returns <tt class="docutils literal"><span class="pre">None</span></tt>.</p> <p>If the <tt class="docutils literal"><span class="pre">binary_form</span></tt> parameter is <a class="reference internal" href="constants.html#False" title="False"><tt class="xref py py-const docutils literal"><span class="pre">False</span></tt></a>, and a certificate was received from the peer, this method returns a <a class="reference internal" href="stdtypes.html#dict" title="dict"><tt class="xref py py-class docutils literal"><span class="pre">dict</span></tt></a> instance. If the certificate was not validated, the dict is empty. If the certificate was validated, it returns a dict with the keys <tt class="docutils literal"><span class="pre">subject</span></tt> (the principal for which the certificate was issued), and <tt class="docutils literal"><span class="pre">notAfter</span></tt> (the time after which the certificate should not be trusted). The certificate was already validated, so the <tt class="docutils literal"><span class="pre">notBefore</span></tt> and <tt class="docutils literal"><span class="pre">issuer</span></tt> fields are not returned. If a certificate contains an instance of the <em>Subject Alternative Name</em> extension (see <span class="target" id="index-3"></span><a class="rfc reference external" href="http://tools.ietf.org/html/rfc3280.html"><strong>RFC 3280</strong></a>), there will also be a <tt class="docutils literal"><span class="pre">subjectAltName</span></tt> key in the dictionary.</p> <p>The “subject” field is a tuple containing the sequence of relative distinguished names (RDNs) given in the certificate’s data structure for the principal, and each RDN is a sequence of name-value pairs:</p> <div class="highlight-python"><div class="highlight"><pre><span class="p">{</span><span class="s">'notAfter'</span><span class="p">:</span> <span class="s">'Feb 16 16:54:50 2013 GMT'</span><span class="p">,</span> <span class="s">'subject'</span><span class="p">:</span> <span class="p">(((</span><span class="s">'countryName'</span><span class="p">,</span> <span class="s">u'US'</span><span class="p">),),</span> <span class="p">((</span><span class="s">'stateOrProvinceName'</span><span class="p">,</span> <span class="s">u'Delaware'</span><span class="p">),),</span> <span class="p">((</span><span class="s">'localityName'</span><span class="p">,</span> <span class="s">u'Wilmington'</span><span class="p">),),</span> <span class="p">((</span><span class="s">'organizationName'</span><span class="p">,</span> <span class="s">u'Python Software Foundation'</span><span class="p">),),</span> <span class="p">((</span><span class="s">'organizationalUnitName'</span><span class="p">,</span> <span class="s">u'SSL'</span><span class="p">),),</span> <span class="p">((</span><span class="s">'commonName'</span><span class="p">,</span> <span class="s">u'somemachine.python.org'</span><span class="p">),))}</span> </pre></div> </div> <p>If the <tt class="docutils literal"><span class="pre">binary_form</span></tt> parameter is <a class="reference internal" href="constants.html#True" title="True"><tt class="xref py py-const docutils literal"><span class="pre">True</span></tt></a>, and a certificate was provided, this method returns the DER-encoded form of the entire certificate as a sequence of bytes, or <a class="reference internal" href="constants.html#None" title="None"><tt class="xref py py-const docutils literal"><span class="pre">None</span></tt></a> if the peer did not provide a certificate. Whether the peer provides a certificate depends on the SSL socket’s role:</p> <ul class="simple"> <li>for a client SSL socket, the server will always provide a certificate, regardless of whether validation was required;</li> <li>for a server SSL socket, the client will only provide a certificate when requested by the server; therefore <a class="reference internal" href="#ssl.SSLSocket.getpeercert" title="ssl.SSLSocket.getpeercert"><tt class="xref py py-meth docutils literal"><span class="pre">getpeercert()</span></tt></a> will return <a class="reference internal" href="constants.html#None" title="None"><tt class="xref py py-const docutils literal"><span class="pre">None</span></tt></a> if you used <a class="reference internal" href="#ssl.CERT_NONE" title="ssl.CERT_NONE"><tt class="xref py py-const docutils literal"><span class="pre">CERT_NONE</span></tt></a> (rather than <a class="reference internal" href="#ssl.CERT_OPTIONAL" title="ssl.CERT_OPTIONAL"><tt class="xref py py-const docutils literal"><span class="pre">CERT_OPTIONAL</span></tt></a> or <a class="reference internal" href="#ssl.CERT_REQUIRED" title="ssl.CERT_REQUIRED"><tt class="xref py py-const docutils literal"><span class="pre">CERT_REQUIRED</span></tt></a>).</li> </ul> </dd></dl> <dl class="method"> <dt id="ssl.SSLSocket.cipher"> <tt class="descclassname">SSLSocket.</tt><tt class="descname">cipher</tt><big>(</big><big>)</big><a class="headerlink" href="#ssl.SSLSocket.cipher" title="Permalink to this definition">¶</a></dt> <dd><p>Returns a three-value tuple containing the name of the cipher being used, the version of the SSL protocol that defines its use, and the number of secret bits being used. If no connection has been established, returns <tt class="docutils literal"><span class="pre">None</span></tt>.</p> </dd></dl> <dl class="method"> <dt id="ssl.SSLSocket.do_handshake"> <tt class="descclassname">SSLSocket.</tt><tt class="descname">do_handshake</tt><big>(</big><big>)</big><a class="headerlink" href="#ssl.SSLSocket.do_handshake" title="Permalink to this definition">¶</a></dt> <dd><p>Perform a TLS/SSL handshake. If this is used with a non-blocking socket, it may raise <a class="reference internal" href="#ssl.SSLError" title="ssl.SSLError"><tt class="xref py py-exc docutils literal"><span class="pre">SSLError</span></tt></a> with an <tt class="docutils literal"><span class="pre">arg[0]</span></tt> of <tt class="xref py py-const docutils literal"><span class="pre">SSL_ERROR_WANT_READ</span></tt> or <tt class="xref py py-const docutils literal"><span class="pre">SSL_ERROR_WANT_WRITE</span></tt>, in which case it must be called again until it completes successfully. For example, to simulate the behavior of a blocking socket, one might write:</p> <div class="highlight-python"><div class="highlight"><pre><span class="k">while</span> <span class="bp">True</span><span class="p">:</span> <span class="k">try</span><span class="p">:</span> <span class="n">s</span><span class="o">.</span><span class="n">do_handshake</span><span class="p">()</span> <span class="k">break</span> <span class="k">except</span> <span class="n">ssl</span><span class="o">.</span><span class="n">SSLError</span> <span class="k">as</span> <span class="n">err</span><span class="p">:</span> <span class="k">if</span> <span class="n">err</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="n">ssl</span><span class="o">.</span><span class="n">SSL_ERROR_WANT_READ</span><span class="p">:</span> <span class="n">select</span><span class="o">.</span><span class="n">select</span><span class="p">([</span><span class="n">s</span><span class="p">],</span> <span class="p">[],</span> <span class="p">[])</span> <span class="k">elif</span> <span class="n">err</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="n">ssl</span><span class="o">.</span><span class="n">SSL_ERROR_WANT_WRITE</span><span class="p">:</span> <span class="n">select</span><span class="o">.</span><span class="n">select</span><span class="p">([],</span> <span class="p">[</span><span class="n">s</span><span class="p">],</span> <span class="p">[])</span> <span class="k">else</span><span class="p">:</span> <span class="k">raise</span> </pre></div> </div> </dd></dl> <dl class="method"> <dt id="ssl.SSLSocket.unwrap"> <tt class="descclassname">SSLSocket.</tt><tt class="descname">unwrap</tt><big>(</big><big>)</big><a class="headerlink" href="#ssl.SSLSocket.unwrap" title="Permalink to this definition">¶</a></dt> <dd><p>Performs the SSL shutdown handshake, which removes the TLS layer from the underlying socket, and returns the underlying socket object. This can be used to go from encrypted operation over a connection to unencrypted. The socket instance returned should always be used for further communication with the other side of the connection, rather than the original socket instance (which may not function properly after the unwrap).</p> </dd></dl> <span class="target" id="index-4"></span></div> <div class="section" id="certificates"> <span id="ssl-certificates"></span><span id="index-5"></span><h2>17.3.3. Certificates<a class="headerlink" href="#certificates" title="Permalink to this headline">¶</a></h2> <p>Certificates in general are part of a public-key / private-key system. In this system, each <em>principal</em>, (which may be a machine, or a person, or an organization) is assigned a unique two-part encryption key. One part of the key is public, and is called the <em>public key</em>; the other part is kept secret, and is called the <em>private key</em>. The two parts are related, in that if you encrypt a message with one of the parts, you can decrypt it with the other part, and <strong>only</strong> with the other part.</p> <p>A certificate contains information about two principals. It contains the name of a <em>subject</em>, and the subject’s public key. It also contains a statement by a second principal, the <em>issuer</em>, that the subject is who he claims to be, and that this is indeed the subject’s public key. The issuer’s statement is signed with the issuer’s private key, which only the issuer knows. However, anyone can verify the issuer’s statement by finding the issuer’s public key, decrypting the statement with it, and comparing it to the other information in the certificate. The certificate also contains information about the time period over which it is valid. This is expressed as two fields, called “notBefore” and “notAfter”.</p> <p>In the Python use of certificates, a client or server can use a certificate to prove who they are. The other side of a network connection can also be required to produce a certificate, and that certificate can be validated to the satisfaction of the client or server that requires such validation. The connection attempt can be set to raise an exception if the validation fails. Validation is done automatically, by the underlying OpenSSL framework; the application need not concern itself with its mechanics. But the application does usually need to provide sets of certificates to allow this process to take place.</p> <p>Python uses files to contain certificates. They should be formatted as “PEM” (see <span class="target" id="index-6"></span><a class="rfc reference external" href="http://tools.ietf.org/html/rfc1422.html"><strong>RFC 1422</strong></a>), which is a base-64 encoded form wrapped with a header line and a footer line:</p> <div class="highlight-python"><pre>-----BEGIN CERTIFICATE----- ... (certificate in base64 PEM encoding) ... -----END CERTIFICATE-----</pre> </div> <p>The Python files which contain certificates can contain a sequence of certificates, sometimes called a <em>certificate chain</em>. This chain should start with the specific certificate for the principal who “is” the client or server, and then the certificate for the issuer of that certificate, and then the certificate for the issuer of <em>that</em> certificate, and so on up the chain till you get to a certificate which is <em>self-signed</em>, that is, a certificate which has the same subject and issuer, sometimes called a <em>root certificate</em>. The certificates should just be concatenated together in the certificate file. For example, suppose we had a three certificate chain, from our server certificate to the certificate of the certification authority that signed our server certificate, to the root certificate of the agency which issued the certification authority’s certificate:</p> <div class="highlight-python"><pre>-----BEGIN CERTIFICATE----- ... (certificate for your server)... -----END CERTIFICATE----- -----BEGIN CERTIFICATE----- ... (the certificate for the CA)... -----END CERTIFICATE----- -----BEGIN CERTIFICATE----- ... (the root certificate for the CA's issuer)... -----END CERTIFICATE-----</pre> </div> <p>If you are going to require validation of the other side of the connection’s certificate, you need to provide a “CA certs” file, filled with the certificate chains for each issuer you are willing to trust. Again, this file just contains these chains concatenated together. For validation, Python will use the first chain it finds in the file which matches.</p> <p>Some “standard” root certificates are available from various certification authorities: <a class="reference external" href="http://www.cacert.org/index.php?id=3">CACert.org</a>, <a class="reference external" href="http://www.thawte.com/roots/">Thawte</a>, <a class="reference external" href="http://www.verisign.com/support/roots.html">Verisign</a>, <a class="reference external" href="http://www.PositiveSSL.com/ssl-certificate-support/cert_installation/UTN-USERFirst-Hardware.crt">Positive SSL</a> (used by python.org), <a class="reference external" href="http://www.geotrust.com/resources/root_certificates/index.asp">Equifax and GeoTrust</a>.</p> <p>In general, if you are using SSL3 or TLS1, you don’t need to put the full chain in your “CA certs” file; you only need the root certificates, and the remote peer is supposed to furnish the other certificates necessary to chain from its certificate to a root certificate. See <span class="target" id="index-7"></span><a class="rfc reference external" href="http://tools.ietf.org/html/rfc4158.html"><strong>RFC 4158</strong></a> for more discussion of the way in which certification chains can be built.</p> <p>If you are going to create a server that provides SSL-encrypted connection services, you will need to acquire a certificate for that service. There are many ways of acquiring appropriate certificates, such as buying one from a certification authority. Another common practice is to generate a self-signed certificate. The simplest way to do this is with the OpenSSL package, using something like the following:</p> <div class="highlight-python"><pre>% openssl req -new -x509 -days 365 -nodes -out cert.pem -keyout cert.pem Generating a 1024 bit RSA private key .......++++++ .............................++++++ writing new private key to 'cert.pem' ----- You are about to be asked to enter information that will be incorporated into your certificate request. What you are about to enter is what is called a Distinguished Name or a DN. There are quite a few fields but you can leave some blank For some fields there will be a default value, If you enter '.', the field will be left blank. ----- Country Name (2 letter code) [AU]:US State or Province Name (full name) [Some-State]:MyState Locality Name (eg, city) []:Some City Organization Name (eg, company) [Internet Widgits Pty Ltd]:My Organization, Inc. Organizational Unit Name (eg, section) []:My Group Common Name (eg, YOUR name) []:myserver.mygroup.myorganization.com Email Address []:ops@myserver.mygroup.myorganization.com %</pre> </div> <p>The disadvantage of a self-signed certificate is that it is its own root certificate, and no one else will have it in their cache of known (and trusted) root certificates.</p> </div> <div class="section" id="examples"> <h2>17.3.4. Examples<a class="headerlink" href="#examples" title="Permalink to this headline">¶</a></h2> <div class="section" id="testing-for-ssl-support"> <h3>17.3.4.1. Testing for SSL support<a class="headerlink" href="#testing-for-ssl-support" title="Permalink to this headline">¶</a></h3> <p>To test for the presence of SSL support in a Python installation, user code should use the following idiom:</p> <div class="highlight-python"><div class="highlight"><pre><span class="k">try</span><span class="p">:</span> <span class="kn">import</span> <span class="nn">ssl</span> <span class="k">except</span> <span class="ne">ImportError</span><span class="p">:</span> <span class="k">pass</span> <span class="k">else</span><span class="p">:</span> <span class="o">...</span> <span class="c"># do something that requires SSL support</span> </pre></div> </div> </div> <div class="section" id="client-side-operation"> <h3>17.3.4.2. Client-side operation<a class="headerlink" href="#client-side-operation" title="Permalink to this headline">¶</a></h3> <p>This example connects to an SSL server, prints the server’s address and certificate, sends some bytes, and reads part of the response:</p> <div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">socket</span><span class="o">,</span> <span class="nn">ssl</span><span class="o">,</span> <span class="nn">pprint</span> <span class="n">s</span> <span class="o">=</span> <span class="n">socket</span><span class="o">.</span><span class="n">socket</span><span class="p">(</span><span class="n">socket</span><span class="o">.</span><span class="n">AF_INET</span><span class="p">,</span> <span class="n">socket</span><span class="o">.</span><span class="n">SOCK_STREAM</span><span class="p">)</span> <span class="c"># require a certificate from the server</span> <span class="n">ssl_sock</span> <span class="o">=</span> <span class="n">ssl</span><span class="o">.</span><span class="n">wrap_socket</span><span class="p">(</span><span class="n">s</span><span class="p">,</span> <span class="n">ca_certs</span><span class="o">=</span><span class="s">"/etc/ca_certs_file"</span><span class="p">,</span> <span class="n">cert_reqs</span><span class="o">=</span><span class="n">ssl</span><span class="o">.</span><span class="n">CERT_REQUIRED</span><span class="p">)</span> <span class="n">ssl_sock</span><span class="o">.</span><span class="n">connect</span><span class="p">((</span><span class="s">'www.verisign.com'</span><span class="p">,</span> <span class="mi">443</span><span class="p">))</span> <span class="k">print</span> <span class="nb">repr</span><span class="p">(</span><span class="n">ssl_sock</span><span class="o">.</span><span class="n">getpeername</span><span class="p">())</span> <span class="k">print</span> <span class="n">ssl_sock</span><span class="o">.</span><span class="n">cipher</span><span class="p">()</span> <span class="k">print</span> <span class="n">pprint</span><span class="o">.</span><span class="n">pformat</span><span class="p">(</span><span class="n">ssl_sock</span><span class="o">.</span><span class="n">getpeercert</span><span class="p">())</span> <span class="c"># Set a simple HTTP request -- use httplib in actual code.</span> <span class="n">ssl_sock</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s">"""GET / HTTP/1.0</span><span class="se">\r</span><span class="s"></span> <span class="s">Host: www.verisign.com</span><span class="se">\r\n\r\n</span><span class="s">"""</span><span class="p">)</span> <span class="c"># Read a chunk of data. Will not necessarily</span> <span class="c"># read all the data returned by the server.</span> <span class="n">data</span> <span class="o">=</span> <span class="n">ssl_sock</span><span class="o">.</span><span class="n">read</span><span class="p">()</span> <span class="c"># note that closing the SSLSocket will also close the underlying socket</span> <span class="n">ssl_sock</span><span class="o">.</span><span class="n">close</span><span class="p">()</span> </pre></div> </div> <p>As of September 6, 2007, the certificate printed by this program looked like this:</p> <div class="highlight-python"><div class="highlight"><pre><span class="p">{</span><span class="s">'notAfter'</span><span class="p">:</span> <span class="s">'May 8 23:59:59 2009 GMT'</span><span class="p">,</span> <span class="s">'subject'</span><span class="p">:</span> <span class="p">(((</span><span class="s">'serialNumber'</span><span class="p">,</span> <span class="s">u'2497886'</span><span class="p">),),</span> <span class="p">((</span><span class="s">'1.3.6.1.4.1.311.60.2.1.3'</span><span class="p">,</span> <span class="s">u'US'</span><span class="p">),),</span> <span class="p">((</span><span class="s">'1.3.6.1.4.1.311.60.2.1.2'</span><span class="p">,</span> <span class="s">u'Delaware'</span><span class="p">),),</span> <span class="p">((</span><span class="s">'countryName'</span><span class="p">,</span> <span class="s">u'US'</span><span class="p">),),</span> <span class="p">((</span><span class="s">'postalCode'</span><span class="p">,</span> <span class="s">u'94043'</span><span class="p">),),</span> <span class="p">((</span><span class="s">'stateOrProvinceName'</span><span class="p">,</span> <span class="s">u'California'</span><span class="p">),),</span> <span class="p">((</span><span class="s">'localityName'</span><span class="p">,</span> <span class="s">u'Mountain View'</span><span class="p">),),</span> <span class="p">((</span><span class="s">'streetAddress'</span><span class="p">,</span> <span class="s">u'487 East Middlefield Road'</span><span class="p">),),</span> <span class="p">((</span><span class="s">'organizationName'</span><span class="p">,</span> <span class="s">u'VeriSign, Inc.'</span><span class="p">),),</span> <span class="p">((</span><span class="s">'organizationalUnitName'</span><span class="p">,</span> <span class="s">u'Production Security Services'</span><span class="p">),),</span> <span class="p">((</span><span class="s">'organizationalUnitName'</span><span class="p">,</span> <span class="s">u'Terms of use at www.verisign.com/rpa (c)06'</span><span class="p">),),</span> <span class="p">((</span><span class="s">'commonName'</span><span class="p">,</span> <span class="s">u'www.verisign.com'</span><span class="p">),))}</span> </pre></div> </div> <p>which is a fairly poorly-formed <tt class="docutils literal"><span class="pre">subject</span></tt> field.</p> </div> <div class="section" id="server-side-operation"> <h3>17.3.4.3. Server-side operation<a class="headerlink" href="#server-side-operation" title="Permalink to this headline">¶</a></h3> <p>For server operation, typically you’d need to have a server certificate, and private key, each in a file. You’d open a socket, bind it to a port, call <tt class="xref py py-meth docutils literal"><span class="pre">listen()</span></tt> on it, then start waiting for clients to connect:</p> <div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">socket</span><span class="o">,</span> <span class="nn">ssl</span> <span class="n">bindsocket</span> <span class="o">=</span> <span class="n">socket</span><span class="o">.</span><span class="n">socket</span><span class="p">()</span> <span class="n">bindsocket</span><span class="o">.</span><span class="n">bind</span><span class="p">((</span><span class="s">'myaddr.mydomain.com'</span><span class="p">,</span> <span class="mi">10023</span><span class="p">))</span> <span class="n">bindsocket</span><span class="o">.</span><span class="n">listen</span><span class="p">(</span><span class="mi">5</span><span class="p">)</span> </pre></div> </div> <p>When one did, you’d call <tt class="xref py py-meth docutils literal"><span class="pre">accept()</span></tt> on the socket to get the new socket from the other end, and use <a class="reference internal" href="#ssl.wrap_socket" title="ssl.wrap_socket"><tt class="xref py py-func docutils literal"><span class="pre">wrap_socket()</span></tt></a> to create a server-side SSL context for it:</p> <div class="highlight-python"><div class="highlight"><pre><span class="k">while</span> <span class="bp">True</span><span class="p">:</span> <span class="n">newsocket</span><span class="p">,</span> <span class="n">fromaddr</span> <span class="o">=</span> <span class="n">bindsocket</span><span class="o">.</span><span class="n">accept</span><span class="p">()</span> <span class="n">connstream</span> <span class="o">=</span> <span class="n">ssl</span><span class="o">.</span><span class="n">wrap_socket</span><span class="p">(</span><span class="n">newsocket</span><span class="p">,</span> <span class="n">server_side</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span> <span class="n">certfile</span><span class="o">=</span><span class="s">"mycertfile"</span><span class="p">,</span> <span class="n">keyfile</span><span class="o">=</span><span class="s">"mykeyfile"</span><span class="p">,</span> <span class="n">ssl_version</span><span class="o">=</span><span class="n">ssl</span><span class="o">.</span><span class="n">PROTOCOL_TLSv1</span><span class="p">)</span> <span class="k">try</span><span class="p">:</span> <span class="n">deal_with_client</span><span class="p">(</span><span class="n">connstream</span><span class="p">)</span> <span class="k">finally</span><span class="p">:</span> <span class="n">connstream</span><span class="o">.</span><span class="n">shutdown</span><span class="p">(</span><span class="n">socket</span><span class="o">.</span><span class="n">SHUT_RDWR</span><span class="p">)</span> <span class="n">connstream</span><span class="o">.</span><span class="n">close</span><span class="p">()</span> </pre></div> </div> <p>Then you’d read data from the <tt class="docutils literal"><span class="pre">connstream</span></tt> and do something with it till you are finished with the client (or the client is finished with you):</p> <div class="highlight-python"><div class="highlight"><pre><span class="k">def</span> <span class="nf">deal_with_client</span><span class="p">(</span><span class="n">connstream</span><span class="p">):</span> <span class="n">data</span> <span class="o">=</span> <span class="n">connstream</span><span class="o">.</span><span class="n">read</span><span class="p">()</span> <span class="c"># null data means the client is finished with us</span> <span class="k">while</span> <span class="n">data</span><span class="p">:</span> <span class="k">if</span> <span class="ow">not</span> <span class="n">do_something</span><span class="p">(</span><span class="n">connstream</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span> <span class="c"># we'll assume do_something returns False</span> <span class="c"># when we're finished with client</span> <span class="k">break</span> <span class="n">data</span> <span class="o">=</span> <span class="n">connstream</span><span class="o">.</span><span class="n">read</span><span class="p">()</span> <span class="c"># finished with client</span> </pre></div> </div> <p>And go back to listening for new client connections.</p> <div class="admonition-see-also admonition seealso"> <p class="first admonition-title">See also</p> <dl class="last docutils"> <dt>Class <a class="reference internal" href="socket.html#socket.socket" title="socket.socket"><tt class="xref py py-class docutils literal"><span class="pre">socket.socket</span></tt></a></dt> <dd>Documentation of underlying <a class="reference internal" href="socket.html#module-socket" title="socket: Low-level networking interface."><tt class="xref py py-mod docutils literal"><span class="pre">socket</span></tt></a> class</dd> <dt><a class="reference external" href="http://www3.rad.com/networks/applications/secure/tls.htm">TLS (Transport Layer Security) and SSL (Secure Socket Layer)</a></dt> <dd>Debby Koren</dd> <dt><a class="reference external" href="http://www.ietf.org/rfc/rfc1422">RFC 1422: Privacy Enhancement for Internet Electronic Mail: Part II: Certificate-Based Key Management</a></dt> <dd>Steve Kent</dd> <dt><a class="reference external" href="http://www.ietf.org/rfc/rfc1750">RFC 1750: Randomness Recommendations for Security</a></dt> <dd>D. Eastlake et. al.</dd> <dt><a class="reference external" href="http://www.ietf.org/rfc/rfc3280">RFC 3280: Internet X.509 Public Key Infrastructure Certificate and CRL Profile</a></dt> <dd>Housley et. al.</dd> </dl> </div> </div> </div> </div> </div> </div> </div> <div class="sphinxsidebar"> <div class="sphinxsidebarwrapper"> <h3><a href="../contents.html">Table Of Contents</a></h3> <ul> <li><a class="reference internal" href="#">17.3. <tt class="docutils literal"><span class="pre">ssl</span></tt> — TLS/SSL wrapper for socket objects</a><ul> <li><a class="reference internal" href="#functions-constants-and-exceptions">17.3.1. Functions, Constants, and Exceptions</a></li> <li><a class="reference internal" href="#sslsocket-objects">17.3.2. SSLSocket Objects</a></li> <li><a class="reference internal" href="#certificates">17.3.3. Certificates</a></li> <li><a class="reference internal" href="#examples">17.3.4. Examples</a><ul> <li><a class="reference internal" href="#testing-for-ssl-support">17.3.4.1. Testing for SSL support</a></li> <li><a class="reference internal" href="#client-side-operation">17.3.4.2. Client-side operation</a></li> <li><a class="reference internal" href="#server-side-operation">17.3.4.3. Server-side operation</a></li> </ul> </li> </ul> </li> </ul> <h4>Previous topic</h4> <p class="topless"><a href="socket.html" title="previous chapter">17.2. <tt class="docutils literal"><span class="pre">socket</span></tt> — Low-level networking interface</a></p> <h4>Next topic</h4> <p class="topless"><a href="signal.html" title="next chapter">17.4. <tt class="docutils literal"><span class="pre">signal</span></tt> — Set handlers for asynchronous events</a></p> <h3>This Page</h3> <ul class="this-page-menu"> <li><a href="../bugs.html">Report a Bug</a></li> <li><a href="../_sources/library/ssl.txt" rel="nofollow">Show Source</a></li> </ul> <div id="searchbox" style="display: none"> <h3>Quick search</h3> <form class="search" action="../search.html" method="get"> <input type="text" name="q" /> <input type="submit" value="Go" /> <input type="hidden" name="check_keywords" value="yes" /> <input type="hidden" name="area" value="default" /> </form> <p class="searchtip" style="font-size: 90%"> Enter search terms or a module, class or function name. </p> </div> <script type="text/javascript">$('#searchbox').show(0);</script> </div> </div> <div class="clearer"></div> </div> <div class="related"> <h3>Navigation</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="../genindex.html" title="General Index" >index</a></li> <li class="right" > <a href="../py-modindex.html" title="Python Module Index" >modules</a> |</li> <li class="right" > <a href="signal.html" title="17.4. signal — Set handlers for asynchronous events" >next</a> |</li> <li class="right" > <a href="socket.html" title="17.2. socket — Low-level networking interface" >previous</a> |</li> <li><img src="../_static/py.png" alt="" style="vertical-align: middle; margin-top: -1px"/></li> <li><a href="http://www.python.org/">Python</a> »</li> <li> <a href="../index.html">Python 2.7.5 documentation</a> » </li> <li><a href="index.html" >The Python Standard Library</a> »</li> <li><a href="ipc.html" >17. Interprocess Communication and Networking</a> »</li> </ul> </div> <div class="footer"> © <a href="../copyright.html">Copyright</a> 1990-2020, Python Software Foundation. <br /> The Python Software Foundation is a non-profit corporation. <a href="http://www.python.org/psf/donations/">Please donate.</a> <br /> Last updated on Oct 13, 2020. <a href="../bugs.html">Found a bug</a>? <br /> Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3. </div> </body> </html>
Close