Skip to content

Commit 5cc4a87

Browse files
committed
instrument sun HttpsURLConnection classes
1 parent 4bd65e5 commit 5cc4a87

File tree

4 files changed

+438
-0
lines changed

4 files changed

+438
-0
lines changed

libs/entitlement/bridge/src/main/java/org/elasticsearch/entitlement/bridge/EntitlementChecker.java

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,119 @@ public interface EntitlementChecker {
410410

411411
void check$sun_net_www_protocol_http_HttpURLConnection$getHeaderFieldKey(Class<?> callerClass, java.net.HttpURLConnection that, int n);
412412

413+
void check$sun_net_www_protocol_https_HttpsURLConnectionImpl$connect(Class<?> callerClass, javax.net.ssl.HttpsURLConnection that);
414+
415+
void check$sun_net_www_protocol_https_HttpsURLConnectionImpl$getOutputStream(
416+
Class<?> callerClass,
417+
javax.net.ssl.HttpsURLConnection that
418+
);
419+
420+
void check$sun_net_www_protocol_https_HttpsURLConnectionImpl$getInputStream(
421+
Class<?> callerClass,
422+
javax.net.ssl.HttpsURLConnection that
423+
);
424+
425+
void check$sun_net_www_protocol_https_HttpsURLConnectionImpl$getErrorStream(
426+
Class<?> callerClass,
427+
javax.net.ssl.HttpsURLConnection that
428+
);
429+
430+
void check$sun_net_www_protocol_https_HttpsURLConnectionImpl$getHeaderField(
431+
Class<?> callerClass,
432+
javax.net.ssl.HttpsURLConnection that,
433+
String name
434+
);
435+
436+
void check$sun_net_www_protocol_https_HttpsURLConnectionImpl$getHeaderFields(
437+
Class<?> callerClass,
438+
javax.net.ssl.HttpsURLConnection that
439+
);
440+
441+
void check$sun_net_www_protocol_https_HttpsURLConnectionImpl$getHeaderField(
442+
Class<?> callerClass,
443+
javax.net.ssl.HttpsURLConnection that,
444+
int n
445+
);
446+
447+
void check$sun_net_www_protocol_https_HttpsURLConnectionImpl$getHeaderFieldKey(
448+
Class<?> callerClass,
449+
javax.net.ssl.HttpsURLConnection that,
450+
int n
451+
);
452+
453+
void check$sun_net_www_protocol_https_HttpsURLConnectionImpl$getResponseCode(
454+
Class<?> callerClass,
455+
javax.net.ssl.HttpsURLConnection that
456+
);
457+
458+
void check$sun_net_www_protocol_https_HttpsURLConnectionImpl$getResponseMessage(
459+
Class<?> callerClass,
460+
javax.net.ssl.HttpsURLConnection that
461+
);
462+
463+
void check$sun_net_www_protocol_https_HttpsURLConnectionImpl$getContentLength(
464+
Class<?> callerClass,
465+
javax.net.ssl.HttpsURLConnection that
466+
);
467+
468+
void check$sun_net_www_protocol_https_HttpsURLConnectionImpl$getContentLengthLong(
469+
Class<?> callerClass,
470+
javax.net.ssl.HttpsURLConnection that
471+
);
472+
473+
void check$sun_net_www_protocol_https_HttpsURLConnectionImpl$getContentType(
474+
Class<?> callerClass,
475+
javax.net.ssl.HttpsURLConnection that
476+
);
477+
478+
void check$sun_net_www_protocol_https_HttpsURLConnectionImpl$getContentEncoding(
479+
Class<?> callerClass,
480+
javax.net.ssl.HttpsURLConnection that
481+
);
482+
483+
void check$sun_net_www_protocol_https_HttpsURLConnectionImpl$getExpiration(Class<?> callerClass, javax.net.ssl.HttpsURLConnection that);
484+
485+
void check$sun_net_www_protocol_https_HttpsURLConnectionImpl$getDate(Class<?> callerClass, javax.net.ssl.HttpsURLConnection that);
486+
487+
void check$sun_net_www_protocol_https_HttpsURLConnectionImpl$getLastModified(
488+
Class<?> callerClass,
489+
javax.net.ssl.HttpsURLConnection that
490+
);
491+
492+
void check$sun_net_www_protocol_https_HttpsURLConnectionImpl$getHeaderFieldInt(
493+
Class<?> callerClass,
494+
javax.net.ssl.HttpsURLConnection that,
495+
String name,
496+
int defaultValue
497+
);
498+
499+
void check$sun_net_www_protocol_https_HttpsURLConnectionImpl$getHeaderFieldLong(
500+
Class<?> callerClass,
501+
javax.net.ssl.HttpsURLConnection that,
502+
String name,
503+
long defaultValue
504+
);
505+
506+
void check$sun_net_www_protocol_https_HttpsURLConnectionImpl$getHeaderFieldDate(
507+
Class<?> callerClass,
508+
javax.net.ssl.HttpsURLConnection that,
509+
String name,
510+
long defaultValue
511+
);
512+
513+
void check$sun_net_www_protocol_https_HttpsURLConnectionImpl$getContent(Class<?> callerClass, javax.net.ssl.HttpsURLConnection that);
514+
515+
void check$sun_net_www_protocol_https_HttpsURLConnectionImpl$getContent(
516+
Class<?> callerClass,
517+
javax.net.ssl.HttpsURLConnection that,
518+
Class<?>[] classes
519+
);
520+
521+
void check$sun_net_www_protocol_https_AbstractDelegateHttpsURLConnection$connect(
522+
Class<?> callerClass,
523+
javax.net.ssl.HttpsURLConnection that
524+
);
525+
413526
// Network miscellanea
414527

415528
// HttpClient#send and sendAsync are abstract, so we instrument their internal implementations

libs/entitlement/qa/entitled-plugin/src/main/java/org/elasticsearch/entitlement/qa/entitled/EntitledActions.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ public static URLConnection createHttpURLConnection() throws IOException {
6464
return URI.create("http://127.0.0.1:12345/").toURL().openConnection();
6565
}
6666

67+
public static URLConnection createHttpsURLConnection() throws IOException {
68+
return URI.create("https://127.0.0.1:12345/").toURL().openConnection();
69+
}
70+
6771
public static URLConnection createFtpURLConnection() throws IOException {
6872
return URI.create("ftp://127.0.0.1:12345/").toURL().openConnection();
6973
}

libs/entitlement/qa/entitlement-test-plugin/src/main/java/org/elasticsearch/entitlement/qa/test/URLConnectionNetworkActions.java

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
import java.net.URL;
2626
import java.net.URLConnection;
2727

28+
import javax.net.ssl.HttpsURLConnection;
29+
2830
import static org.elasticsearch.entitlement.qa.test.EntitlementTest.ExpectedAccess.PLUGINS;
2931

3032
@SuppressWarnings("unused") // everything is called via reflection
@@ -79,6 +81,17 @@ private static void withJdkHttpConnection(CheckedConsumer<HttpURLConnection, Exc
7981
}
8082
}
8183

84+
private static void withJdkHttpsConnection(CheckedConsumer<HttpsURLConnection, Exception> connectionConsumer) throws Exception {
85+
var conn = EntitledActions.createHttpsURLConnection();
86+
// Be sure we got the connection implementation we want
87+
assert HttpsURLConnection.class.isAssignableFrom(conn.getClass());
88+
try {
89+
connectionConsumer.accept((HttpsURLConnection) conn);
90+
} catch (java.net.ConnectException e) {
91+
// It's OK, it means we passed entitlement checks, and we tried to connect
92+
}
93+
}
94+
8295
private static void withJdkFtpConnection(CheckedConsumer<URLConnection, Exception> connectionConsumer) throws Exception {
8396
var conn = EntitledActions.createFtpURLConnection();
8497
// Be sure we got the connection implementation we want
@@ -302,4 +315,118 @@ static void sunHttpURLConnectionGetHeaderFieldWithIndex() throws Exception {
302315
static void sunHttpURLConnectionGetHeaderFieldKey() throws Exception {
303316
withJdkHttpConnection(conn -> conn.getHeaderFieldKey(0));
304317
}
318+
319+
// https
320+
@EntitlementTest(expectedAccess = PLUGINS)
321+
static void sunHttpsURLConnectionImplConnect() throws Exception {
322+
withJdkHttpsConnection(HttpsURLConnection::connect);
323+
}
324+
325+
@EntitlementTest(expectedAccess = PLUGINS)
326+
static void sunHttpsURLConnectionImplGetOutputStream() throws Exception {
327+
withJdkHttpsConnection(httpsURLConnection -> {
328+
httpsURLConnection.setDoOutput(true);
329+
httpsURLConnection.getOutputStream();
330+
});
331+
}
332+
333+
@EntitlementTest(expectedAccess = PLUGINS)
334+
static void sunHttpsURLConnectionImplGetInputStream() throws Exception {
335+
withJdkHttpsConnection(HttpsURLConnection::getInputStream);
336+
}
337+
338+
@EntitlementTest(expectedAccess = PLUGINS)
339+
static void sunHttpsURLConnectionImplGetErrorStream() throws Exception {
340+
withJdkHttpsConnection(HttpsURLConnection::getErrorStream);
341+
}
342+
343+
@EntitlementTest(expectedAccess = PLUGINS)
344+
static void sunHttpsURLConnectionImplGetHeaderFieldWithName() throws Exception {
345+
withJdkHttpsConnection(httpsURLConnection -> httpsURLConnection.getHeaderField("date"));
346+
}
347+
348+
@EntitlementTest(expectedAccess = PLUGINS)
349+
static void sunHttpsURLConnectionImplGetHeaderFields() throws Exception {
350+
withJdkHttpsConnection(HttpsURLConnection::getHeaderFields);
351+
}
352+
353+
@EntitlementTest(expectedAccess = PLUGINS)
354+
static void sunHttpsURLConnectionImplGetHeaderFieldWithIndex() throws Exception {
355+
withJdkHttpsConnection(httpsURLConnection -> httpsURLConnection.getHeaderField(0));
356+
}
357+
358+
@EntitlementTest(expectedAccess = PLUGINS)
359+
static void sunHttpsURLConnectionImplGetHeaderFieldKey() throws Exception {
360+
withJdkHttpsConnection(httpsURLConnection -> httpsURLConnection.getHeaderFieldKey(0));
361+
}
362+
363+
@EntitlementTest(expectedAccess = PLUGINS)
364+
static void sunHttpsURLConnectionImplGetResponseCode() throws Exception {
365+
withJdkHttpsConnection(HttpsURLConnection::getResponseCode);
366+
}
367+
368+
@EntitlementTest(expectedAccess = PLUGINS)
369+
static void sunHttpsURLConnectionImplGetResponseMessage() throws Exception {
370+
withJdkHttpsConnection(HttpsURLConnection::getResponseMessage);
371+
}
372+
373+
@EntitlementTest(expectedAccess = PLUGINS)
374+
static void sunHttpsURLConnectionImplGetContentLength() throws Exception {
375+
withJdkHttpsConnection(HttpsURLConnection::getContentLength);
376+
}
377+
378+
@EntitlementTest(expectedAccess = PLUGINS)
379+
static void sunHttpsURLConnectionImpl$getContentLengthLong() throws Exception {
380+
withJdkHttpsConnection(HttpsURLConnection::getContentLengthLong);
381+
}
382+
383+
@EntitlementTest(expectedAccess = PLUGINS)
384+
static void sunHttpsURLConnectionImplGetContentType() throws Exception {
385+
withJdkHttpsConnection(HttpsURLConnection::getContentType);
386+
}
387+
388+
@EntitlementTest(expectedAccess = PLUGINS)
389+
static void sunHttpsURLConnectionImplGetContentEncoding() throws Exception {
390+
withJdkHttpsConnection(HttpsURLConnection::getContentEncoding);
391+
}
392+
393+
@EntitlementTest(expectedAccess = PLUGINS)
394+
static void sunHttpsURLConnectionImplGetExpiration() throws Exception {
395+
withJdkHttpsConnection(HttpsURLConnection::getExpiration);
396+
}
397+
398+
@EntitlementTest(expectedAccess = PLUGINS)
399+
static void sunHttpsURLConnectionImplGetDate() throws Exception {
400+
withJdkHttpsConnection(HttpsURLConnection::getDate);
401+
}
402+
403+
@EntitlementTest(expectedAccess = PLUGINS)
404+
static void sunHttpsURLConnectionImplGetLastModified() throws Exception {
405+
withJdkHttpsConnection(HttpsURLConnection::getLastModified);
406+
}
407+
408+
@EntitlementTest(expectedAccess = PLUGINS)
409+
static void sunHttpsURLConnectionImplGetHeaderFieldInt() throws Exception {
410+
withJdkHttpsConnection(httpsURLConnection -> httpsURLConnection.getHeaderFieldInt("content-length", -1));
411+
}
412+
413+
@EntitlementTest(expectedAccess = PLUGINS)
414+
static void sunHttpsURLConnectionImplGetHeaderFieldLong() throws Exception {
415+
withJdkHttpsConnection(httpsURLConnection -> httpsURLConnection.getHeaderFieldLong("content-length", -1));
416+
}
417+
418+
@EntitlementTest(expectedAccess = PLUGINS)
419+
static void sunHttpsURLConnectionImplGetHeaderFieldDate() throws Exception {
420+
withJdkHttpsConnection(httpsURLConnection -> httpsURLConnection.getHeaderFieldDate("date", 0));
421+
}
422+
423+
@EntitlementTest(expectedAccess = PLUGINS)
424+
static void sunHttpsURLConnectionImplGetContent() throws Exception {
425+
withJdkHttpsConnection(HttpsURLConnection::getContent);
426+
}
427+
428+
@EntitlementTest(expectedAccess = PLUGINS)
429+
static void sunHttpsURLConnectionImplGetContentWithClasses() throws Exception {
430+
withJdkHttpsConnection(httpsURLConnection -> httpsURLConnection.getContent(new Class<?>[] { String.class }));
431+
}
305432
}

0 commit comments

Comments
 (0)