Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
f06628b0
Commit
f06628b0
authored
Nov 21, 2007
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make read() and certificate() return bytes instead of bytearray instances.
parent
254348e2
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
31 deletions
+23
-31
Modules/_ssl.c
Modules/_ssl.c
+23
-31
No files found.
Modules/_ssl.c
View file @
f06628b0
...
@@ -504,7 +504,7 @@ _create_tuple_for_attribute (ASN1_OBJECT *name, ASN1_STRING *value) {
...
@@ -504,7 +504,7 @@ _create_tuple_for_attribute (ASN1_OBJECT *name, ASN1_STRING *value) {
name_obj
=
PyUnicode_FromStringAndSize
(
namebuf
,
buflen
);
name_obj
=
PyUnicode_FromStringAndSize
(
namebuf
,
buflen
);
if
(
name_obj
==
NULL
)
if
(
name_obj
==
NULL
)
goto
fail
;
goto
fail
;
buflen
=
ASN1_STRING_to_UTF8
(
&
valuebuf
,
value
);
buflen
=
ASN1_STRING_to_UTF8
(
&
valuebuf
,
value
);
if
(
buflen
<
0
)
{
if
(
buflen
<
0
)
{
_setSSLError
(
NULL
,
0
,
__FILE__
,
__LINE__
);
_setSSLError
(
NULL
,
0
,
__FILE__
,
__LINE__
);
...
@@ -590,7 +590,7 @@ _create_tuple_for_X509_NAME (X509_NAME *xname)
...
@@ -590,7 +590,7 @@ _create_tuple_for_X509_NAME (X509_NAME *xname)
fprintf(stderr, "RDN level %d, attribute %s: %s\n",
fprintf(stderr, "RDN level %d, attribute %s: %s\n",
entry->set,
entry->set,
PyString_AS_STRING(PyTuple_GET_ITEM(attr, 0)),
PyString_AS_STRING(PyTuple_GET_ITEM(attr, 0)),
PyString_AS_STRING(PyTuple_GET_ITEM(attr, 1)));
PyString_AS_STRING(PyTuple_GET_ITEM(attr, 1)));
*/
*/
if
(
attr
==
NULL
)
if
(
attr
==
NULL
)
goto
fail1
;
goto
fail1
;
...
@@ -628,7 +628,7 @@ _create_tuple_for_X509_NAME (X509_NAME *xname)
...
@@ -628,7 +628,7 @@ _create_tuple_for_X509_NAME (X509_NAME *xname)
static
PyObject
*
static
PyObject
*
_get_peer_alt_names
(
X509
*
certificate
)
{
_get_peer_alt_names
(
X509
*
certificate
)
{
/* this code follows the procedure outlined in
/* this code follows the procedure outlined in
OpenSSL's crypto/x509v3/v3_prn.c:X509v3_EXT_print()
OpenSSL's crypto/x509v3/v3_prn.c:X509v3_EXT_print()
function to extract the STACK_OF(GENERAL_NAME),
function to extract the STACK_OF(GENERAL_NAME),
...
@@ -641,7 +641,7 @@ _get_peer_alt_names (X509 *certificate) {
...
@@ -641,7 +641,7 @@ _get_peer_alt_names (X509 *certificate) {
X509_EXTENSION
*
ext
=
NULL
;
X509_EXTENSION
*
ext
=
NULL
;
GENERAL_NAMES
*
names
=
NULL
;
GENERAL_NAMES
*
names
=
NULL
;
GENERAL_NAME
*
name
;
GENERAL_NAME
*
name
;
X509V3_EXT_METHOD
*
method
;
X509V3_EXT_METHOD
*
method
;
BIO
*
biobuf
=
NULL
;
BIO
*
biobuf
=
NULL
;
char
buf
[
2048
];
char
buf
[
2048
];
char
*
vptr
;
char
*
vptr
;
...
@@ -663,7 +663,7 @@ _get_peer_alt_names (X509 *certificate) {
...
@@ -663,7 +663,7 @@ _get_peer_alt_names (X509 *certificate) {
if
(
peer_alt_names
==
NULL
)
if
(
peer_alt_names
==
NULL
)
goto
fail
;
goto
fail
;
}
}
/* now decode the altName */
/* now decode the altName */
ext
=
X509_get_ext
(
certificate
,
i
);
ext
=
X509_get_ext
(
certificate
,
i
);
if
(
!
(
method
=
X509V3_EXT_get
(
ext
)))
{
if
(
!
(
method
=
X509V3_EXT_get
(
ext
)))
{
...
@@ -714,7 +714,7 @@ _get_peer_alt_names (X509 *certificate) {
...
@@ -714,7 +714,7 @@ _get_peer_alt_names (X509 *certificate) {
goto
fail
;
goto
fail
;
}
}
PyTuple_SET_ITEM
(
t
,
1
,
v
);
PyTuple_SET_ITEM
(
t
,
1
,
v
);
}
else
{
}
else
{
/* for everything else, we use the OpenSSL print form */
/* for everything else, we use the OpenSSL print form */
...
@@ -764,7 +764,7 @@ _get_peer_alt_names (X509 *certificate) {
...
@@ -764,7 +764,7 @@ _get_peer_alt_names (X509 *certificate) {
}
else
{
}
else
{
return
peer_alt_names
;
return
peer_alt_names
;
}
}
fail:
fail:
if
(
biobuf
!=
NULL
)
if
(
biobuf
!=
NULL
)
...
@@ -817,7 +817,7 @@ _decode_certificate (X509 *certificate, int verbose) {
...
@@ -817,7 +817,7 @@ _decode_certificate (X509 *certificate, int verbose) {
goto
fail0
;
goto
fail0
;
}
}
Py_DECREF
(
issuer
);
Py_DECREF
(
issuer
);
version
=
PyInt_FromLong
(
X509_get_version
(
certificate
)
+
1
);
version
=
PyInt_FromLong
(
X509_get_version
(
certificate
)
+
1
);
if
(
PyDict_SetItemString
(
retval
,
"version"
,
version
)
<
0
)
{
if
(
PyDict_SetItemString
(
retval
,
"version"
,
version
)
<
0
)
{
Py_DECREF
(
version
);
Py_DECREF
(
version
);
...
@@ -825,10 +825,10 @@ _decode_certificate (X509 *certificate, int verbose) {
...
@@ -825,10 +825,10 @@ _decode_certificate (X509 *certificate, int verbose) {
}
}
Py_DECREF
(
version
);
Py_DECREF
(
version
);
}
}
/* get a memory buffer */
/* get a memory buffer */
biobuf
=
BIO_new
(
BIO_s_mem
());
biobuf
=
BIO_new
(
BIO_s_mem
());
if
(
verbose
)
{
if
(
verbose
)
{
(
void
)
BIO_reset
(
biobuf
);
(
void
)
BIO_reset
(
biobuf
);
...
@@ -897,7 +897,7 @@ _decode_certificate (X509 *certificate, int verbose) {
...
@@ -897,7 +897,7 @@ _decode_certificate (X509 *certificate, int verbose) {
}
}
Py_DECREF
(
peer_alt_names
);
Py_DECREF
(
peer_alt_names
);
}
}
BIO_free
(
biobuf
);
BIO_free
(
biobuf
);
return
retval
;
return
retval
;
...
@@ -945,7 +945,7 @@ PySSL_test_decode_certificate (PyObject *mod, PyObject *args) {
...
@@ -945,7 +945,7 @@ PySSL_test_decode_certificate (PyObject *mod, PyObject *args) {
retval
=
_decode_certificate
(
x
,
verbose
);
retval
=
_decode_certificate
(
x
,
verbose
);
fail0:
fail0:
if
(
cert
!=
NULL
)
BIO_free
(
cert
);
if
(
cert
!=
NULL
)
BIO_free
(
cert
);
return
retval
;
return
retval
;
}
}
...
@@ -977,7 +977,7 @@ PySSL_peercert(PySSLObject *self, PyObject *args)
...
@@ -977,7 +977,7 @@ PySSL_peercert(PySSLObject *self, PyObject *args)
return
NULL
;
return
NULL
;
}
}
/* this is actually an immutable bytes sequence */
/* this is actually an immutable bytes sequence */
retval
=
Py
Bytes
_FromStringAndSize
retval
=
Py
String
_FromStringAndSize
((
const
char
*
)
bytes_buf
,
len
);
((
const
char
*
)
bytes_buf
,
len
);
OPENSSL_free
(
bytes_buf
);
OPENSSL_free
(
bytes_buf
);
return
retval
;
return
retval
;
...
@@ -1044,7 +1044,7 @@ static PyObject *PySSL_cipher (PySSLObject *self) {
...
@@ -1044,7 +1044,7 @@ static PyObject *PySSL_cipher (PySSLObject *self) {
goto
fail0
;
goto
fail0
;
PyTuple_SET_ITEM
(
retval
,
2
,
v
);
PyTuple_SET_ITEM
(
retval
,
2
,
v
);
return
retval
;
return
retval
;
fail0:
fail0:
Py_DECREF
(
retval
);
Py_DECREF
(
retval
);
return
NULL
;
return
NULL
;
...
@@ -1281,13 +1281,8 @@ static PyObject *PySSL_SSLread(PySSLObject *self, PyObject *args)
...
@@ -1281,13 +1281,8 @@ static PyObject *PySSL_SSLread(PySSLObject *self, PyObject *args)
Py_DECREF
(
buf
);
Py_DECREF
(
buf
);
return
NULL
;
return
NULL
;
}
else
if
(
sockstate
==
SOCKET_HAS_BEEN_CLOSED
)
{
}
else
if
(
sockstate
==
SOCKET_HAS_BEEN_CLOSED
)
{
/* should contain a zero-length string */
count
=
0
;
if
(
!
buf_passed
)
{
goto
done
;
PyBytes_Resize
(
buf
,
0
);
return
buf
;
}
else
{
return
PyInt_FromLong
(
0
);
}
}
}
}
}
do
{
do
{
...
@@ -1312,12 +1307,8 @@ static PyObject *PySSL_SSLread(PySSLObject *self, PyObject *args)
...
@@ -1312,12 +1307,8 @@ static PyObject *PySSL_SSLread(PySSLObject *self, PyObject *args)
(
SSL_get_shutdown
(
self
->
ssl
)
==
(
SSL_get_shutdown
(
self
->
ssl
)
==
SSL_RECEIVED_SHUTDOWN
))
SSL_RECEIVED_SHUTDOWN
))
{
{
if
(
!
buf_passed
)
{
count
=
0
;
PyBytes_Resize
(
buf
,
0
);
goto
done
;
return
buf
;
}
else
{
return
PyInt_FromLong
(
0
);
}
}
else
{
}
else
{
sockstate
=
SOCKET_OPERATION_OK
;
sockstate
=
SOCKET_OPERATION_OK
;
}
}
...
@@ -1338,11 +1329,12 @@ static PyObject *PySSL_SSLread(PySSLObject *self, PyObject *args)
...
@@ -1338,11 +1329,12 @@ static PyObject *PySSL_SSLread(PySSLObject *self, PyObject *args)
}
}
return
PySSL_SetError
(
self
,
count
,
__FILE__
,
__LINE__
);
return
PySSL_SetError
(
self
,
count
,
__FILE__
,
__LINE__
);
}
}
done:
if
(
!
buf_passed
)
{
if
(
!
buf_passed
)
{
if
(
count
!=
len
)
{
PyObject
*
res
=
PyString_FromStringAndSize
(
PyBytes_
Resize
(
buf
,
count
);
PyBytes_
AS_STRING
(
buf
)
,
count
);
}
Py_DECREF
(
buf
);
return
buf
;
return
res
;
}
else
{
}
else
{
return
PyInt_FromLong
(
count
);
return
PyInt_FromLong
(
count
);
}
}
...
...
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