Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
bpo-34001: add checks for LibreSSL
LibreSSL behaves differently than OpenSSL when setting protocol
bounds. This commit fixes some failing tests and adds checks and
more detailed error messages.
  • Loading branch information
Alan Huang Alan Huang
Alan Huang authored and Alan Huang committed Jul 3, 2018
commit 8352fd3bbeef09cc14af61a0b88a8fcefd2279e3
24 changes: 24 additions & 0 deletions Modules/_ssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -3386,6 +3386,8 @@ set_min_max_proto_version(PySSLContext *self, PyObject *arg, int what)
long min;
long max;
long v;
long prev;
long new;
int result;

if (!PyArg_Parse(arg, "l", &v))
Expand Down Expand Up @@ -3432,7 +3434,18 @@ set_min_max_proto_version(PySSLContext *self, PyObject *arg, int what)
);
return -1;
}
prev = SSL_CTX_get_min_proto_version(self->ctx);
result = SSL_CTX_set_min_proto_version(self->ctx, v);
new = SSL_CTX_get_min_proto_version(self->ctx);
#if defined(LIBRESSL_VERSION_NUMBER)
if((v != 0 && v != new) ||
(v == 0 && PY_PROTO_MINIMUM_AVAILABLE != new)) {
PyErr_Format(PyExc_ValueError,
"Unsupported protocol version 0x%x", v);
SSL_CTX_set_min_proto_version(self->ctx, prev);
return -1;
}
#endif
}
else {
/* set_maximum_version */
Expand All @@ -3457,7 +3470,18 @@ set_min_max_proto_version(PySSLContext *self, PyObject *arg, int what)
);
return -1;
}
prev = SSL_CTX_get_max_proto_version(self->ctx);
result = SSL_CTX_set_max_proto_version(self->ctx, v);
new = SSL_CTX_get_max_proto_version(self->ctx);
#if defined(LIBRESSL_VERSION_NUMBER)
if((v != 0 && v != SSL_CTX_get_max_proto_version(self->ctx)) ||
(v == 0 && PY_PROTO_MAXIMUM_AVAILABLE != SSL_CTX_get_max_proto_version(self->ctx))) {
PyErr_Format(PyExc_ValueError,
"Unsupported protocol version 0x%x", v);
result = SSL_CTX_set_max_proto_version(self->ctx, prev);
return -1;
}
#endif
}
if (result == 0) {
PyErr_Format(PyExc_ValueError,
Expand Down