How to understand java Socket-Permissions?
Asked Answered
F

1

6
permission java.net.SocketPermission "192.168.1.1:31337", "connect, accept, resolve";

What does the following permission allow? Is my Application allowed to accept connections only from 192.168.1.1:31337 (maybe an external client) or to accept connections on to 192.168.1.1:31337 (my application is running on 192.168.1.1:31337, where is the difference to 'listen'?).

Fleischman answered 5/9, 2012 at 14:53 Comment(0)
R
4

If your code is an applet or running under a java security manager you need to explicitly grant it permissions to do stuff.

In order for a resource access to be allowed for an applet (or an application running with a security manager), the corresponding permission must be explicitly granted to the code attempting the access.

By default your code has no socket permission. Your permission says that your code has the permission to accept connection on, to connect to and to resolve only the host with IP 192.168.1.1 on port 31337.

The "accept" and "connect" actions are obvious.

The "resolve" action is implied when any of the other actions are present. The action "resolve" refers to host/ip name service lookups.

The "listen" action is only meaningful when used with "localhost".

The difference between listen and accept is that listening means "be prepared for connection and see if there is a connection waiting" and accepting means "ok, accept it".

See the docs for permissions in java 7. and java.net.SocketPermission java docs

Retroact answered 5/9, 2012 at 15:15 Comment(2)
Well, the sun documentation says: Similarly, if the following permission: p2 = new SocketPermission("localhost:1024-", "accept,connect,listen"); is granted to some code, it allows that code to accept connections on, connect to, or listen on any port between 1024 and 65535 on the local host. So "accept" allows connections to the specific host, not from the specific host.Fleischman
Of course is "on", not "from". The remainder of the answer suggest this. Corrected. Thanks.Retroact

© 2022 - 2024 — McMap. All rights reserved.