Re: Limiting RMI to localhost



On Jun 30, 8:49 pm, Tom Anderson <t...@xxxxxxxxxxxxxxx> wrote:
On Mon, 30 Jun 2008, Ronny Schuetz wrote:
I'm writing a big application that I divide into 2 processes (server
and interface) with RMI to communicate between them. I would like to
limit the access to the server only from the interface process and also
only from the local machine. Is there a way to limit RMI to localhost
only?

I cannot block all sockets outside the machine since I use them in the
server process.

Can't you setup to RMI server socket to explicitly listen on
localhost:<your port>? This way it shouldn't be accessible from outside.

A server socket bound to localhost will be able to receive connections
from outside. Unless you mean that <your port> would also be firewalled?
That should work.

How about using the version of UnicastRemoteObject.exportObject that takes
a pair of socket factories? The important one would be the
RMIServerSocketFactory; you could use that to make a special subclass of
ServerSocket that overrides accept() to check the client's address.
Something like:

public Socket accept() throws IOException {
        while (true) {
                Socket sock = super.accept() ;
                if (sock.getRemoteAddress().equals(sock.getLocalAddress())) {
                        return sock ;
                } else {
                        // might want to log the attempted connection
                        try {
                                sock.close() ;
                        } catch (IOException e) {
                                // might want to log this too
                        }
                }
        }

}

I'm not absolutely sure that this will always work; if you bind the server
socket to localhost, but open connections to yourself via an explicit
name, the addreses might not match. I don't really know how to deal with
that - what's a good general way of asking if an InetAddress refers to an
interface on the local machine? Perhaps you should just make the rule even
stricter, and say that only connections via the loopback interface will be
accepted; this avoids the problem.

The RMIClientSocketFactory would just open sockets in the normal way. It
wouldn't do the clever stuff that RMI's default socket factory does -
falling back to HTTP and so on. It could even do the remote-vs-local
address checking itself, and abort any attempts to connect to remote
machines. This obviously wouldn't be enough to guarantee security, as a
malicious attacker could just not use this factory.

Another really cool thing to do would be to write a pair of client and
server socket factories that used unix domain sockets (AF_UNIX), rather
than TCP/IP sockets (AF_INET). These are local-only by definition, and
ought to be faster (but probably aren't). They would only work on unix,
though. And there isn't AF_UNIX support in the standard java libraries.

You might also be able to do something by using RMI-IIOP and using the
controls your ORB provides.

tom

--
It's odd to discover your quips in other people's .sig files. --
Benjamin Rosenbaum

Thanks!!
I'll try that and report if it worked.
.



Relevant Pages

  • Re: TCP server stop receiving new connections
    ... before I start the server. ... Maybe has something to do with the Socket ... integrate in your application not just network interface. ...
    (microsoft.public.win32.programmer.networks)
  • Re: Limiting RMI to localhost
    ... I would like to limit the access to the server only from the interface process and also only from the local machine. ... Is there a way to limit RMI to localhost only? ... A server socket bound to localhost will be able to receive connections from outside. ...
    (comp.lang.java.programmer)
  • Re: What doesnt lend itself to OO?
    ... The whole idea that a subsystem is just ... > The first line exists in the server. ... objects between client and server i.e. as far as the client code is ... > external interface is the traditional input interface whose ...
    (comp.object)
  • Re: Brian Kernighan, maybe Im not worthy, maybe Im scum
    ... If you think I'm giving a verbose pseud write access to my server, ... interface appears in C Sharp as consisting of sbyte arrays. ... failed to see that a for loop is not just a while loop because a while ... chilling effect on freedom of speech. ...
    (comp.programming)
  • Re: Cannot get NAT to route in RRAS
    ... The basic problem is that you are using an ADSL modem on the server. ... I would suggest that you set up a demand-dial interface to act as the ... Static Route wizard, create a default route using this interface (ie put ...
    (microsoft.public.win2000.ras_routing)