Skip to content

Commit febe8f2

Browse files
committed
Add missing ssl options for urllib3
1 parent a415769 commit febe8f2

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SSLModuleBuiltins.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ public void postInitialize(Python3Core core) {
231231
module.setAttribute(tsLiteral("HAS_ECDH"), false);
232232
module.setAttribute(tsLiteral("HAS_NPN"), false);
233233
module.setAttribute(tsLiteral("HAS_ALPN"), true);
234+
module.setAttribute(tsLiteral("HAS_NEVER_CHECK_COMMON_NAME"), false);
234235
module.setAttribute(tsLiteral("HAS_SSLv2"), false);
235236
boolean hasSSLv3 = supportedProtocols.contains(SSLProtocol.SSLv3);
236237
module.setAttribute(tsLiteral("HAS_SSLv3"), hasSSLv3);
@@ -268,13 +269,15 @@ public void postInitialize(Python3Core core) {
268269
module.setAttribute(tsLiteral("SSL_ERROR_EOF"), SSLErrorCode.ERROR_EOF.getErrno());
269270
module.setAttribute(tsLiteral("SSL_ERROR_INVALID_ERROR_CODE"), 10);
270271

271-
module.setAttribute(tsLiteral("OP_ALL"), SSLOptions.DEFAULT_OPTIONS);
272+
module.setAttribute(tsLiteral("OP_ALL"), SSLOptions.SSL_OP_ALL);
272273
module.setAttribute(tsLiteral("OP_NO_SSLv2"), SSLOptions.SSL_OP_NO_SSLv2);
273274
module.setAttribute(tsLiteral("OP_NO_SSLv3"), SSLOptions.SSL_OP_NO_SSLv3);
274275
module.setAttribute(tsLiteral("OP_NO_TLSv1"), SSLOptions.SSL_OP_NO_TLSv1);
275276
module.setAttribute(tsLiteral("OP_NO_TLSv1_1"), SSLOptions.SSL_OP_NO_TLSv1_1);
276277
module.setAttribute(tsLiteral("OP_NO_TLSv1_2"), SSLOptions.SSL_OP_NO_TLSv1_2);
277278
module.setAttribute(tsLiteral("OP_NO_TLSv1_3"), SSLOptions.SSL_OP_NO_TLSv1_3);
279+
module.setAttribute(tsLiteral("OP_NO_COMPRESSION"), SSLOptions.SSL_OP_NO_COMPRESSION);
280+
module.setAttribute(tsLiteral("OP_NO_TICKET"), SSLOptions.SSL_OP_NO_TICKET);
278281

279282
module.setAttribute(tsLiteral("VERIFY_DEFAULT"), 0);
280283
module.setAttribute(tsLiteral("VERIFY_CRL_CHECK_LEAF"), X509_V_FLAG_CRL_CHECK);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ssl/SSLContextBuiltins.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ PSSLContext createContext(VirtualFrame frame, Object type, int protocol,
177177
verifyMode = SSLModuleBuiltins.SSL_CERT_NONE;
178178
}
179179
PSSLContext context = factory().createSSLContext(type, method, SSLModuleBuiltins.X509_V_FLAG_TRUSTED_FIRST, checkHostname, verifyMode, createSSLContext());
180-
long options = SSLOptions.DEFAULT_OPTIONS;
180+
long options = SSLOptions.SSL_OP_ALL;
181181
if (method != SSLMethod.SSL3) {
182182
options |= SSLOptions.SSL_OP_NO_SSLv3;
183183
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ssl/SSLOperationNode.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@
4343
import static com.oracle.graal.python.builtins.PythonBuiltinClassType.MemoryError;
4444
import static com.oracle.graal.python.builtins.objects.exception.OSErrorEnum.EAGAIN;
4545
import static com.oracle.graal.python.builtins.objects.exception.OSErrorEnum.EWOULDBLOCK;
46-
import static com.oracle.graal.python.util.PythonUtils.toTruffleStringUncached;
4746
import static com.oracle.graal.python.util.PythonUtils.TS_ENCODING;
47+
import static com.oracle.graal.python.util.PythonUtils.toTruffleStringUncached;
4848

4949
import java.nio.ByteBuffer;
5050
import java.security.cert.CertificateException;
@@ -171,6 +171,7 @@ void doSocket(VirtualFrame frame, PSSLSocket socket, ByteBuffer appInput, ByteBu
171171
@Cached PConstructAndRaiseNode constructAndRaiseNode,
172172
@Cached TruffleString.FromJavaStringNode fromJavaStringNode) {
173173
assert socket.getSocket() != null;
174+
prepare(socket);
174175
TimeoutHelper timeoutHelper = null;
175176
if (socket.getSocket().getTimeoutNs() > 0) {
176177
timeoutHelper = new TimeoutHelper(socket.getSocket().getTimeoutNs());
@@ -272,6 +273,7 @@ void doSocket(VirtualFrame frame, PSSLSocket socket, ByteBuffer appInput, ByteBu
272273
@Specialization(guards = "socket.getSocket() == null")
273274
void doMemory(VirtualFrame frame, PSSLSocket socket, ByteBuffer appInput, ByteBuffer targetBuffer, SSLOperation operation,
274275
@Cached PConstructAndRaiseNode constructAndRaiseNode) {
276+
prepare(socket);
275277
SSLOperationStatus status;
276278
try {
277279
status = loop(socket, appInput, targetBuffer, operation);
@@ -307,6 +309,17 @@ void doMemory(VirtualFrame frame, PSSLSocket socket, ByteBuffer appInput, ByteBu
307309
}
308310
}
309311

312+
private static void prepare(PSSLSocket socket) {
313+
if ((socket.getContext().getOptions() & SSLOptions.SSL_OP_NO_TICKET) != 0) {
314+
invalidateSession(socket);
315+
}
316+
}
317+
318+
@TruffleBoundary
319+
private static void invalidateSession(PSSLSocket socket) {
320+
socket.getEngine().getSession().invalidate();
321+
}
322+
310323
private static void putAsMuchAsPossible(ByteBuffer target, PMemoryBIO sourceBIO) {
311324
ByteBuffer source = sourceBIO.getBufferForReading();
312325
int remaining = Math.min(source.remaining(), target.remaining());

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ssl/SSLOptions.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,16 @@
4242

4343
public abstract class SSLOptions {
4444

45-
public static final int DEFAULT_OPTIONS = 0;
46-
4745
public static final int SSL_OP_NO_SSLv2 = 0;
4846
public static final int SSL_OP_NO_SSLv3 = 0x2000000;
4947
public static final int SSL_OP_NO_TLSv1 = 0x4000000;
5048
public static final int SSL_OP_NO_TLSv1_1 = 0x10000000;
5149
public static final int SSL_OP_NO_TLSv1_2 = 0x8000000;
5250
public static final int SSL_OP_NO_TLSv1_3 = 0x20000000;
51+
52+
// We just ignore this because Java's TLS doesn't provide compression anyway
53+
public static final int SSL_OP_NO_COMPRESSION = 0x20000;
54+
public static final int SSL_OP_NO_TICKET = 0x4000;
55+
56+
public static final int SSL_OP_ALL = SSL_OP_NO_COMPRESSION;
5357
}

0 commit comments

Comments
 (0)