Skip to content

Commit 1be9253

Browse files
authored
[Entitlements] Network entitlement classes + Datagram socket check functions (#119735)
1 parent 5123b94 commit 1be9253

File tree

11 files changed

+485
-73
lines changed

11 files changed

+485
-73
lines changed

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,16 @@
1313
import java.io.PrintStream;
1414
import java.io.PrintWriter;
1515
import java.net.ContentHandlerFactory;
16+
import java.net.DatagramPacket;
17+
import java.net.DatagramSocket;
1618
import java.net.DatagramSocketImplFactory;
1719
import java.net.FileNameMap;
20+
import java.net.InetAddress;
21+
import java.net.MulticastSocket;
22+
import java.net.NetworkInterface;
1823
import java.net.ProxySelector;
1924
import java.net.ResponseCache;
25+
import java.net.SocketAddress;
2026
import java.net.SocketImplFactory;
2127
import java.net.URL;
2228
import java.net.URLStreamHandler;
@@ -189,4 +195,28 @@ public interface EntitlementChecker {
189195

190196
// The only implementation of SSLSession#getSessionContext(); unfortunately it's an interface, so we need to check the implementation
191197
void check$sun_security_ssl_SSLSessionImpl$getSessionContext(Class<?> callerClass, SSLSession sslSession);
198+
199+
void check$java_net_DatagramSocket$bind(Class<?> callerClass, DatagramSocket that, SocketAddress addr);
200+
201+
void check$java_net_DatagramSocket$connect(Class<?> callerClass, DatagramSocket that, InetAddress addr);
202+
203+
void check$java_net_DatagramSocket$connect(Class<?> callerClass, DatagramSocket that, SocketAddress addr);
204+
205+
void check$java_net_DatagramSocket$send(Class<?> callerClass, DatagramSocket that, DatagramPacket p);
206+
207+
void check$java_net_DatagramSocket$receive(Class<?> callerClass, DatagramSocket that, DatagramPacket p);
208+
209+
void check$java_net_DatagramSocket$joinGroup(Class<?> callerClass, DatagramSocket that, SocketAddress addr, NetworkInterface ni);
210+
211+
void check$java_net_DatagramSocket$leaveGroup(Class<?> callerClass, DatagramSocket that, SocketAddress addr, NetworkInterface ni);
212+
213+
void check$java_net_MulticastSocket$joinGroup(Class<?> callerClass, MulticastSocket that, InetAddress addr);
214+
215+
void check$java_net_MulticastSocket$joinGroup(Class<?> callerClass, MulticastSocket that, SocketAddress addr, NetworkInterface ni);
216+
217+
void check$java_net_MulticastSocket$leaveGroup(Class<?> callerClass, MulticastSocket that, InetAddress addr);
218+
219+
void check$java_net_MulticastSocket$leaveGroup(Class<?> callerClass, MulticastSocket that, SocketAddress addr, NetworkInterface ni);
220+
221+
void check$java_net_MulticastSocket$send(Class<?> callerClass, MulticastSocket that, DatagramPacket p, byte ttl);
192222
}

libs/entitlement/qa/common/src/main/java/org/elasticsearch/entitlement/qa/common/DummyImplementations.java

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,15 @@
99

1010
package org.elasticsearch.entitlement.qa.common;
1111

12+
import java.io.IOException;
13+
import java.net.DatagramPacket;
14+
import java.net.DatagramSocket;
15+
import java.net.DatagramSocketImpl;
1216
import java.net.InetAddress;
17+
import java.net.NetworkInterface;
1318
import java.net.Socket;
19+
import java.net.SocketAddress;
20+
import java.net.SocketException;
1421
import java.security.cert.Certificate;
1522
import java.text.BreakIterator;
1623
import java.text.Collator;
@@ -327,8 +334,77 @@ public Socket createSocket(Socket s, String host, int port, boolean autoClose) {
327334
}
328335
}
329336

337+
static class DummyDatagramSocket extends DatagramSocket {
338+
DummyDatagramSocket() throws SocketException {
339+
super(new DatagramSocketImpl() {
340+
@Override
341+
protected void create() throws SocketException {}
342+
343+
@Override
344+
protected void bind(int lport, InetAddress laddr) throws SocketException {}
345+
346+
@Override
347+
protected void send(DatagramPacket p) throws IOException {}
348+
349+
@Override
350+
protected int peek(InetAddress i) throws IOException {
351+
return 0;
352+
}
353+
354+
@Override
355+
protected int peekData(DatagramPacket p) throws IOException {
356+
return 0;
357+
}
358+
359+
@Override
360+
protected void receive(DatagramPacket p) throws IOException {}
361+
362+
@Override
363+
protected void setTTL(byte ttl) throws IOException {}
364+
365+
@Override
366+
protected byte getTTL() throws IOException {
367+
return 0;
368+
}
369+
370+
@Override
371+
protected void setTimeToLive(int ttl) throws IOException {}
372+
373+
@Override
374+
protected int getTimeToLive() throws IOException {
375+
return 0;
376+
}
377+
378+
@Override
379+
protected void join(InetAddress inetaddr) throws IOException {}
380+
381+
@Override
382+
protected void leave(InetAddress inetaddr) throws IOException {}
383+
384+
@Override
385+
protected void joinGroup(SocketAddress mcastaddr, NetworkInterface netIf) throws IOException {}
386+
387+
@Override
388+
protected void leaveGroup(SocketAddress mcastaddr, NetworkInterface netIf) throws IOException {}
389+
390+
@Override
391+
protected void close() {}
392+
393+
@Override
394+
public void setOption(int optID, Object value) throws SocketException {}
395+
396+
@Override
397+
public Object getOption(int optID) throws SocketException {
398+
return null;
399+
}
400+
401+
@Override
402+
protected void connect(InetAddress address, int port) throws SocketException {}
403+
});
404+
}
405+
}
406+
330407
private static RuntimeException unexpected() {
331408
return new IllegalStateException("This method isn't supposed to be called");
332409
}
333-
334410
}

0 commit comments

Comments
 (0)