Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
40a0f66e
Kaydet (Commit)
40a0f66e
authored
Agu 12, 2008
tarafından
Bill Janssen
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
clean up ssl.py; expose unwrap and add test for it
üst
6aa2d1fe
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
69 additions
and
4 deletions
+69
-4
ssl.py
Lib/ssl.py
+9
-1
test_ssl.py
Lib/test/test_ssl.py
+20
-3
_ssl.c
Modules/_ssl.c
+40
-0
No files found.
Lib/ssl.py
Dosyayı görüntüle @
40a0f66e
...
@@ -75,10 +75,10 @@ from _ssl import (
...
@@ -75,10 +75,10 @@ from _ssl import (
SSL_ERROR_INVALID_ERROR_CODE
,
SSL_ERROR_INVALID_ERROR_CODE
,
)
)
from
socket
import
socket
,
AF_INET
,
SOCK_STREAM
,
error
from
socket
import
getnameinfo
as
_getnameinfo
from
socket
import
getnameinfo
as
_getnameinfo
from
socket
import
error
as
socket_error
from
socket
import
error
as
socket_error
from
socket
import
dup
as
_dup
from
socket
import
dup
as
_dup
from
socket
import
socket
,
AF_INET
,
SOCK_STREAM
import
base64
# for DER-to-PEM translation
import
base64
# for DER-to-PEM translation
import
traceback
import
traceback
...
@@ -296,6 +296,14 @@ class SSLSocket(socket):
...
@@ -296,6 +296,14 @@ class SSLSocket(socket):
self
.
_sslobj
=
None
self
.
_sslobj
=
None
socket
.
shutdown
(
self
,
how
)
socket
.
shutdown
(
self
,
how
)
def
unwrap
(
self
):
if
self
.
_sslobj
:
s
=
self
.
_sslobj
.
shutdown
()
self
.
_sslobj
=
None
return
s
else
:
raise
ValueError
(
"No SSL wrapper around "
+
str
(
self
))
def
_real_close
(
self
):
def
_real_close
(
self
):
self
.
_sslobj
=
None
self
.
_sslobj
=
None
# self._closed = True
# self._closed = True
...
...
Lib/test/test_ssl.py
Dosyayı görüntüle @
40a0f66e
...
@@ -279,6 +279,15 @@ else:
...
@@ -279,6 +279,15 @@ else:
self
.
write
(
"OK
\n
"
.
encode
(
"ASCII"
,
"strict"
))
self
.
write
(
"OK
\n
"
.
encode
(
"ASCII"
,
"strict"
))
if
not
self
.
wrap_conn
():
if
not
self
.
wrap_conn
():
return
return
elif
(
self
.
server
.
starttls_server
and
self
.
sslconn
and
amsg
.
strip
()
==
'ENDTLS'
):
if
support
.
verbose
and
self
.
server
.
connectionchatty
:
sys
.
stdout
.
write
(
" server: read ENDTLS from client, sending OK...
\n
"
)
self
.
write
(
"OK
\n
"
.
encode
(
"ASCII"
,
"strict"
))
self
.
sock
=
self
.
sslconn
.
unwrap
()
self
.
sslconn
=
None
if
support
.
verbose
and
self
.
server
.
connectionchatty
:
sys
.
stdout
.
write
(
" server: connection is now unencrypted...
\n
"
)
else
:
else
:
if
(
support
.
verbose
and
if
(
support
.
verbose
and
self
.
server
.
connectionchatty
):
self
.
server
.
connectionchatty
):
...
@@ -868,7 +877,7 @@ else:
...
@@ -868,7 +877,7 @@ else:
def
testSTARTTLS
(
self
):
def
testSTARTTLS
(
self
):
msgs
=
(
"msg 1"
,
"MSG 2"
,
"STARTTLS"
,
"MSG 3"
,
"msg 4"
)
msgs
=
(
"msg 1"
,
"MSG 2"
,
"STARTTLS"
,
"MSG 3"
,
"msg 4"
,
"ENDTLS"
,
"msg 5"
,
"msg 6"
)
server
=
ThreadedEchoServer
(
CERTFILE
,
server
=
ThreadedEchoServer
(
CERTFILE
,
ssl_version
=
ssl
.
PROTOCOL_TLSv1
,
ssl_version
=
ssl
.
PROTOCOL_TLSv1
,
...
@@ -910,8 +919,16 @@ else:
...
@@ -910,8 +919,16 @@ else:
" client: read
%
s from server, starting TLS...
\n
"
" client: read
%
s from server, starting TLS...
\n
"
%
repr
(
msg
))
%
repr
(
msg
))
conn
=
ssl
.
wrap_socket
(
s
,
ssl_version
=
ssl
.
PROTOCOL_TLSv1
)
conn
=
ssl
.
wrap_socket
(
s
,
ssl_version
=
ssl
.
PROTOCOL_TLSv1
)
wrapped
=
True
wrapped
=
True
elif
(
indata
==
"ENDTLS"
and
str
(
outdata
,
'ASCII'
,
'replace'
)
.
strip
()
.
lower
()
.
startswith
(
"ok"
)):
if
support
.
verbose
:
msg
=
str
(
outdata
,
'ASCII'
,
'replace'
)
sys
.
stdout
.
write
(
" client: read
%
s from server, ending TLS...
\n
"
%
repr
(
msg
))
s
=
conn
.
unwrap
()
wrapped
=
False
else
:
else
:
if
support
.
verbose
:
if
support
.
verbose
:
msg
=
str
(
outdata
,
'ASCII'
,
'replace'
)
msg
=
str
(
outdata
,
'ASCII'
,
'replace'
)
...
@@ -922,7 +939,7 @@ else:
...
@@ -922,7 +939,7 @@ else:
if
wrapped
:
if
wrapped
:
conn
.
write
(
"over
\n
"
.
encode
(
"ASCII"
,
"strict"
))
conn
.
write
(
"over
\n
"
.
encode
(
"ASCII"
,
"strict"
))
else
:
else
:
s
.
send
(
"over
\n
"
)
s
.
send
(
"over
\n
"
.
encode
(
"ASCII"
,
"strict"
)
)
if
wrapped
:
if
wrapped
:
conn
.
close
()
conn
.
close
()
else
:
else
:
...
...
Modules/_ssl.c
Dosyayı görüntüle @
40a0f66e
...
@@ -1370,6 +1370,42 @@ PyDoc_STRVAR(PySSL_SSLread_doc,
...
@@ -1370,6 +1370,42 @@ PyDoc_STRVAR(PySSL_SSLread_doc,
\n
\
\n
\
Read up to len bytes from the SSL socket."
);
Read up to len bytes from the SSL socket."
);
static
PyObject
*
PySSL_SSLshutdown
(
PySSLObject
*
self
)
{
int
err
;
PySocketSockObject
*
sock
=
(
PySocketSockObject
*
)
PyWeakref_GetObject
(
self
->
Socket
);
/* Guard against closed socket */
if
((((
PyObject
*
)
sock
)
==
Py_None
)
||
(
sock
->
sock_fd
<
0
))
{
_setSSLError
(
"Underlying socket connection gone"
,
PY_SSL_ERROR_NO_SOCKET
,
__FILE__
,
__LINE__
);
return
NULL
;
}
PySSL_BEGIN_ALLOW_THREADS
err
=
SSL_shutdown
(
self
->
ssl
);
if
(
err
==
0
)
{
/* we need to call it again to finish the shutdown */
err
=
SSL_shutdown
(
self
->
ssl
);
}
PySSL_END_ALLOW_THREADS
if
(
err
<
0
)
return
PySSL_SetError
(
self
,
err
,
__FILE__
,
__LINE__
);
else
{
Py_INCREF
(
sock
);
return
(
PyObject
*
)
sock
;
}
}
PyDoc_STRVAR
(
PySSL_SSLshutdown_doc
,
"shutdown(s) -> socket
\n
\
\n
\
Does the SSL shutdown handshake with the remote end, and returns
\n
\
the underlying socket object."
);
static
PyMethodDef
PySSLMethods
[]
=
{
static
PyMethodDef
PySSLMethods
[]
=
{
{
"do_handshake"
,
(
PyCFunction
)
PySSL_SSLdo_handshake
,
METH_NOARGS
},
{
"do_handshake"
,
(
PyCFunction
)
PySSL_SSLdo_handshake
,
METH_NOARGS
},
{
"write"
,
(
PyCFunction
)
PySSL_SSLwrite
,
METH_VARARGS
,
{
"write"
,
(
PyCFunction
)
PySSL_SSLwrite
,
METH_VARARGS
,
...
@@ -1381,6 +1417,8 @@ static PyMethodDef PySSLMethods[] = {
...
@@ -1381,6 +1417,8 @@ static PyMethodDef PySSLMethods[] = {
{
"peer_certificate"
,
(
PyCFunction
)
PySSL_peercert
,
METH_VARARGS
,
{
"peer_certificate"
,
(
PyCFunction
)
PySSL_peercert
,
METH_VARARGS
,
PySSL_peercert_doc
},
PySSL_peercert_doc
},
{
"cipher"
,
(
PyCFunction
)
PySSL_cipher
,
METH_NOARGS
},
{
"cipher"
,
(
PyCFunction
)
PySSL_cipher
,
METH_NOARGS
},
{
"shutdown"
,
(
PyCFunction
)
PySSL_SSLshutdown
,
METH_NOARGS
,
PySSL_SSLshutdown_doc
},
{
NULL
,
NULL
}
{
NULL
,
NULL
}
};
};
...
@@ -1480,6 +1518,8 @@ fails or if it does provide enough data to seed PRNG.");
...
@@ -1480,6 +1518,8 @@ fails or if it does provide enough data to seed PRNG.");
#endif
#endif
/* List of functions exported by this module. */
/* List of functions exported by this module. */
static
PyMethodDef
PySSL_methods
[]
=
{
static
PyMethodDef
PySSL_methods
[]
=
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment