mirror of https://github.com/python/cpython
Merged revisions 81115 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r81115 | antoine.pitrou | 2010-05-12 16:02:34 +0200 (mer., 12 mai 2010) | 3 lines Improve _ssl.c formatting ........
This commit is contained in:
parent
ca561f5e72
commit
96125cf170
|
@ -181,8 +181,7 @@ PySSL_SetError(PySSLObject *obj, int ret, char *filename, int lineno)
|
||||||
break;
|
break;
|
||||||
case SSL_ERROR_WANT_X509_LOOKUP:
|
case SSL_ERROR_WANT_X509_LOOKUP:
|
||||||
p = PY_SSL_ERROR_WANT_X509_LOOKUP;
|
p = PY_SSL_ERROR_WANT_X509_LOOKUP;
|
||||||
errstr =
|
errstr = "The operation did not complete (X509 lookup)";
|
||||||
"The operation did not complete (X509 lookup)";
|
|
||||||
break;
|
break;
|
||||||
case SSL_ERROR_WANT_CONNECT:
|
case SSL_ERROR_WANT_CONNECT:
|
||||||
p = PY_SSL_ERROR_WANT_CONNECT;
|
p = PY_SSL_ERROR_WANT_CONNECT;
|
||||||
|
@ -193,15 +192,14 @@ PySSL_SetError(PySSLObject *obj, int ret, char *filename, int lineno)
|
||||||
unsigned long e = ERR_get_error();
|
unsigned long e = ERR_get_error();
|
||||||
if (e == 0) {
|
if (e == 0) {
|
||||||
if (ret == 0 || !obj->Socket) {
|
if (ret == 0 || !obj->Socket) {
|
||||||
p = PY_SSL_ERROR_EOF;
|
p = PY_SSL_ERROR_EOF;
|
||||||
errstr =
|
errstr = "EOF occurred in violation of protocol";
|
||||||
"EOF occurred in violation of protocol";
|
|
||||||
} else if (ret == -1) {
|
} else if (ret == -1) {
|
||||||
/* underlying BIO reported an I/O error */
|
/* underlying BIO reported an I/O error */
|
||||||
return obj->Socket->errorhandler();
|
return obj->Socket->errorhandler();
|
||||||
} else { /* possible? */
|
} else { /* possible? */
|
||||||
p = PY_SSL_ERROR_SYSCALL;
|
p = PY_SSL_ERROR_SYSCALL;
|
||||||
errstr = "Some I/O error occurred";
|
errstr = "Some I/O error occurred";
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
p = PY_SSL_ERROR_SYSCALL;
|
p = PY_SSL_ERROR_SYSCALL;
|
||||||
|
@ -218,8 +216,7 @@ PySSL_SetError(PySSLObject *obj, int ret, char *filename, int lineno)
|
||||||
/* XXX Protected by global interpreter lock */
|
/* XXX Protected by global interpreter lock */
|
||||||
errstr = ERR_error_string(e, NULL);
|
errstr = ERR_error_string(e, NULL);
|
||||||
else { /* possible? */
|
else { /* possible? */
|
||||||
errstr =
|
errstr = "A failure in the SSL library occurred";
|
||||||
"A failure in the SSL library occurred";
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -316,7 +313,7 @@ newPySSLObject(PySocketSockObject *Sock, char *key_file, char *cert_file,
|
||||||
if (certreq != PY_SSL_CERT_NONE) {
|
if (certreq != PY_SSL_CERT_NONE) {
|
||||||
if (cacerts_file == NULL) {
|
if (cacerts_file == NULL) {
|
||||||
errstr = ERRSTR("No root certificates specified for "
|
errstr = ERRSTR("No root certificates specified for "
|
||||||
"verification of other-side certificates.");
|
"verification of other-side certificates.");
|
||||||
goto fail;
|
goto fail;
|
||||||
} else {
|
} else {
|
||||||
PySSL_BEGIN_ALLOW_THREADS
|
PySSL_BEGIN_ALLOW_THREADS
|
||||||
|
@ -472,15 +469,15 @@ static PyObject *PySSL_SSLdo_handshake(PySSLObject *self)
|
||||||
}
|
}
|
||||||
if (sockstate == SOCKET_HAS_TIMED_OUT) {
|
if (sockstate == SOCKET_HAS_TIMED_OUT) {
|
||||||
PyErr_SetString(PySSLErrorObject,
|
PyErr_SetString(PySSLErrorObject,
|
||||||
ERRSTR("The handshake operation timed out"));
|
ERRSTR("The handshake operation timed out"));
|
||||||
return NULL;
|
return NULL;
|
||||||
} else if (sockstate == SOCKET_HAS_BEEN_CLOSED) {
|
} else if (sockstate == SOCKET_HAS_BEEN_CLOSED) {
|
||||||
PyErr_SetString(PySSLErrorObject,
|
PyErr_SetString(PySSLErrorObject,
|
||||||
ERRSTR("Underlying socket has been closed."));
|
ERRSTR("Underlying socket has been closed."));
|
||||||
return NULL;
|
return NULL;
|
||||||
} else if (sockstate == SOCKET_TOO_LARGE_FOR_SELECT) {
|
} else if (sockstate == SOCKET_TOO_LARGE_FOR_SELECT) {
|
||||||
PyErr_SetString(PySSLErrorObject,
|
PyErr_SetString(PySSLErrorObject,
|
||||||
ERRSTR("Underlying socket too large for select()."));
|
ERRSTR("Underlying socket too large for select()."));
|
||||||
return NULL;
|
return NULL;
|
||||||
} else if (sockstate == SOCKET_IS_NONBLOCKING) {
|
} else if (sockstate == SOCKET_IS_NONBLOCKING) {
|
||||||
break;
|
break;
|
||||||
|
@ -543,7 +540,7 @@ _create_tuple_for_attribute (ASN1_OBJECT *name, ASN1_STRING *value) {
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
value_obj = PyUnicode_DecodeUTF8((char *) valuebuf,
|
value_obj = PyUnicode_DecodeUTF8((char *) valuebuf,
|
||||||
buflen, "strict");
|
buflen, "strict");
|
||||||
OPENSSL_free(valuebuf);
|
OPENSSL_free(valuebuf);
|
||||||
if (value_obj == NULL) {
|
if (value_obj == NULL) {
|
||||||
Py_DECREF(name_obj);
|
Py_DECREF(name_obj);
|
||||||
|
@ -1193,11 +1190,9 @@ static PyObject *PySSL_SSLwrite(PySSLObject *self, PyObject *args)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (err == SSL_ERROR_WANT_READ) {
|
if (err == SSL_ERROR_WANT_READ) {
|
||||||
sockstate =
|
sockstate = check_socket_and_wait_for_timeout(self->Socket, 0);
|
||||||
check_socket_and_wait_for_timeout(self->Socket, 0);
|
|
||||||
} else if (err == SSL_ERROR_WANT_WRITE) {
|
} else if (err == SSL_ERROR_WANT_WRITE) {
|
||||||
sockstate =
|
sockstate = check_socket_and_wait_for_timeout(self->Socket, 1);
|
||||||
check_socket_and_wait_for_timeout(self->Socket, 1);
|
|
||||||
} else {
|
} else {
|
||||||
sockstate = SOCKET_OPERATION_OK;
|
sockstate = SOCKET_OPERATION_OK;
|
||||||
}
|
}
|
||||||
|
@ -1278,7 +1273,7 @@ static PyObject *PySSL_SSLread(PySSLObject *self, PyObject *args)
|
||||||
return NULL;
|
return NULL;
|
||||||
} else if (sockstate == SOCKET_TOO_LARGE_FOR_SELECT) {
|
} else if (sockstate == SOCKET_TOO_LARGE_FOR_SELECT) {
|
||||||
PyErr_SetString(PySSLErrorObject,
|
PyErr_SetString(PySSLErrorObject,
|
||||||
"Underlying socket too large for select().");
|
"Underlying socket too large for select().");
|
||||||
Py_DECREF(buf);
|
Py_DECREF(buf);
|
||||||
return NULL;
|
return NULL;
|
||||||
} else if (sockstate == SOCKET_HAS_BEEN_CLOSED) {
|
} else if (sockstate == SOCKET_HAS_BEEN_CLOSED) {
|
||||||
|
@ -1287,7 +1282,7 @@ static PyObject *PySSL_SSLread(PySSLObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
Py_DECREF(buf);
|
Py_DECREF(buf);
|
||||||
PyErr_SetString(PySSLErrorObject,
|
PyErr_SetString(PySSLErrorObject,
|
||||||
"Socket closed without SSL shutdown handshake");
|
"Socket closed without SSL shutdown handshake");
|
||||||
return NULL;
|
return NULL;
|
||||||
} else {
|
} else {
|
||||||
/* should contain a zero-length string */
|
/* should contain a zero-length string */
|
||||||
|
@ -1307,11 +1302,9 @@ static PyObject *PySSL_SSLread(PySSLObject *self, PyObject *args)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (err == SSL_ERROR_WANT_READ) {
|
if (err == SSL_ERROR_WANT_READ) {
|
||||||
sockstate =
|
sockstate = check_socket_and_wait_for_timeout(self->Socket, 0);
|
||||||
check_socket_and_wait_for_timeout(self->Socket, 0);
|
|
||||||
} else if (err == SSL_ERROR_WANT_WRITE) {
|
} else if (err == SSL_ERROR_WANT_WRITE) {
|
||||||
sockstate =
|
sockstate = check_socket_and_wait_for_timeout(self->Socket, 1);
|
||||||
check_socket_and_wait_for_timeout(self->Socket, 1);
|
|
||||||
} else if ((err == SSL_ERROR_ZERO_RETURN) &&
|
} else if ((err == SSL_ERROR_ZERO_RETURN) &&
|
||||||
(SSL_get_shutdown(self->ssl) ==
|
(SSL_get_shutdown(self->ssl) ==
|
||||||
SSL_RECEIVED_SHUTDOWN))
|
SSL_RECEIVED_SHUTDOWN))
|
||||||
|
@ -1482,7 +1475,7 @@ PySSL_RAND_add(PyObject *self, PyObject *args)
|
||||||
double entropy;
|
double entropy;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "s#d:RAND_add", &buf, &len, &entropy))
|
if (!PyArg_ParseTuple(args, "s#d:RAND_add", &buf, &len, &entropy))
|
||||||
return NULL;
|
return NULL;
|
||||||
RAND_add(buf, len, entropy);
|
RAND_add(buf, len, entropy);
|
||||||
Py_INCREF(Py_None);
|
Py_INCREF(Py_None);
|
||||||
return Py_None;
|
return Py_None;
|
||||||
|
@ -1513,15 +1506,15 @@ PySSL_RAND_egd(PyObject *self, PyObject *arg)
|
||||||
int bytes;
|
int bytes;
|
||||||
|
|
||||||
if (!PyString_Check(arg))
|
if (!PyString_Check(arg))
|
||||||
return PyErr_Format(PyExc_TypeError,
|
return PyErr_Format(PyExc_TypeError,
|
||||||
"RAND_egd() expected string, found %s",
|
"RAND_egd() expected string, found %s",
|
||||||
Py_TYPE(arg)->tp_name);
|
Py_TYPE(arg)->tp_name);
|
||||||
bytes = RAND_egd(PyString_AS_STRING(arg));
|
bytes = RAND_egd(PyString_AS_STRING(arg));
|
||||||
if (bytes == -1) {
|
if (bytes == -1) {
|
||||||
PyErr_SetString(PySSLErrorObject,
|
PyErr_SetString(PySSLErrorObject,
|
||||||
"EGD connection failed or EGD did not return "
|
"EGD connection failed or EGD did not return "
|
||||||
"enough data to seed the PRNG");
|
"enough data to seed the PRNG");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return PyInt_FromLong(bytes);
|
return PyInt_FromLong(bytes);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue