socks.server
Interface ServerAuthenticator

All Known Implementing Classes:
ServerAuthenticatorNone

public interface ServerAuthenticator

Classes implementing this interface should provide socks server with authentication and authorization of users.


Method Summary
 boolean checkRequest(java.net.DatagramPacket dp, boolean out)
          This method is called when datagram is received by the server.
 boolean checkRequest(ProxyMessage msg)
          This method is called when a request have been read.
 void endSession()
          This method is called when session is completed.
 java.io.InputStream getInputStream()
          This method should return input stream which should be used on the accepted socket.
 java.io.OutputStream getOutputStream()
          This method should return output stream to use to write to the accepted socket.
 UDPEncapsulation getUdpEncapsulation()
          This method should return UDPEncapsulation, which should be used on the datagrams being send in/out.
 ServerAuthenticator startSession(java.net.Socket s)
          This method is called when a new connection accepted by the server.
 

Method Detail

startSession

public ServerAuthenticator startSession(java.net.Socket s)
                                 throws java.io.IOException
This method is called when a new connection accepted by the server.

At this point no data have been extracted from the connection. It is responsibility of this method to ensure that the next byte in the stream after this method have been called is the first byte of the socks request message. For SOCKSv4 there is no authentication data and the first byte in the stream is part of the request. With SOCKSv5 however there is an authentication data first. It is expected that implementaions will process this authentication data.

If authentication was successful an instance of ServerAuthentication should be returned, it later will be used by the server to perform authorization and some other things. If authentication fails null should be returned, or an exception may be thrown.

Parameters:
s - Accepted Socket.
Returns:
An instance of ServerAuthenticator to be used for this connection or null

getInputStream

public java.io.InputStream getInputStream()
This method should return input stream which should be used on the accepted socket.

SOCKSv5 allows to have multiple authentication methods, and these methods might require some kind of transformations being made on the data.

This method is called on the object returned from the startSession function.


getOutputStream

public java.io.OutputStream getOutputStream()
This method should return output stream to use to write to the accepted socket.

SOCKSv5 allows to have multiple authentication methods, and these methods might require some kind of transformations being made on the data.

This method is called on the object returned from the startSession function.


getUdpEncapsulation

public UDPEncapsulation getUdpEncapsulation()
This method should return UDPEncapsulation, which should be used on the datagrams being send in/out.

If no transformation should be done on the datagrams, this method should return null.

This method is called on the object returned from the startSession function.


checkRequest

public boolean checkRequest(ProxyMessage msg)
This method is called when a request have been read.

Implementation should decide wether to grant request or not. Returning true implies granting the request, false means request should be rejected.

This method is called on the object returned from the startSession function.

Parameters:
msg - Request message.
Returns:
true to grant request, false to reject it.

checkRequest

public boolean checkRequest(java.net.DatagramPacket dp,
                            boolean out)
This method is called when datagram is received by the server.

Implementaions should decide wether it should be forwarded or dropped. It is expecteed that implementation will use datagram address and port information to make a decision, as well as anything else. Address and port of the datagram are always correspond to remote machine. It is either destination or source address. If out is true address is destination address, else it is a source address, address of the machine from which datagram have been received for the client.

Implementaions should return true if the datagram is to be forwarded, and false if the datagram should be dropped.

This method is called on the object returned from the startSession function.

Parameters:
out - If true the datagram is being send out(from the client), otherwise it is an incoming datagram.
Returns:
True to forward datagram false drop it silently.

endSession

public void endSession()
This method is called when session is completed. Either due to normal termination or due to any error condition.

This method is called on the object returned from the startSession function.