comparison src/net/sourceforge/jsocks/server/ServerAuthenticator.java @ 349:205ee2873330

update jsocks to 2011-03-19
author Carl Byington <carl@five-ten-sg.com>
date Fri, 01 Aug 2014 11:23:10 -0700
parents 0ce5cc452d02
children 72de889ecfe7
comparison
equal deleted inserted replaced
348:29076621bab0 349:205ee2873330
1 package net.sourceforge.jsocks.server; 1 package socks.server;
2 2
3 import java.io.IOException; 3 import java.io.IOException;
4 import java.io.InputStream; 4 import java.io.InputStream;
5 import java.io.OutputStream; 5 import java.io.OutputStream;
6 import java.net.Socket;
6 import java.net.DatagramPacket; 7 import java.net.DatagramPacket;
7 import java.net.Socket;
8
9 import net.sourceforge.jsocks.ProxyMessage; 8 import net.sourceforge.jsocks.ProxyMessage;
10 import net.sourceforge.jsocks.UDPEncapsulation; 9 import net.sourceforge.jsocks.UDPEncapsulation;
11 10
12 /** 11 /**
13 Classes implementing this interface should provide socks server with 12 Classes implementing this interface should provide socks server with
14 authentication and authorization of users. 13 authentication and authorization of users.
15 **/ 14 **/
16 public interface ServerAuthenticator { 15 public interface ServerAuthenticator{
17 16
18 /** 17 /**
19 This method is called when a new connection accepted by the server. 18 This method is called when a new connection accepted by the server.
20 <p> 19 <p>
21 At this point no data have been extracted from the connection. It is 20 At this point no data have been extracted from the connection. It is
22 responsibility of this method to ensure that the next byte in the 21 responsibility of this method to ensure that the next byte in the
23 stream after this method have been called is the first byte of the 22 stream after this method have been called is the first byte of the
24 socks request message. For SOCKSv4 there is no authentication data and 23 socks request message. For SOCKSv4 there is no authentication data and
25 the first byte in the stream is part of the request. With SOCKSv5 however 24 the first byte in the stream is part of the request. With SOCKSv5 however
26 there is an authentication data first. It is expected that implementaions 25 there is an authentication data first. It is expected that implementaions
27 will process this authentication data. 26 will process this authentication data.
28 <p> 27 <p>
29 If authentication was successful an instance of ServerAuthentication 28 If authentication was successful an instance of ServerAuthentication
30 should be returned, it later will be used by the server to perform 29 should be returned, it later will be used by the server to perform
31 authorization and some other things. If authentication fails null should 30 authorization and some other things. If authentication fails null should
32 be returned, or an exception may be thrown. 31 be returned, or an exception may be thrown.
33 32
34 @param s Accepted Socket. 33 @param s Accepted Socket.
35 @return An instance of ServerAuthenticator to be used for this connection 34 @return An instance of ServerAuthenticator to be used for this connection
36 or null 35 or null
37 */ 36 */
38 ServerAuthenticator startSession(Socket s) throws IOException; 37 ServerAuthenticator startSession(Socket s) throws IOException;
39 38
40 /** 39 /**
41 This method should return input stream which should be used on the 40 This method should return input stream which should be used on the
42 accepted socket. 41 accepted socket.
43 <p> 42 <p>
44 SOCKSv5 allows to have multiple authentication methods, and these methods 43 SOCKSv5 allows to have multiple authentication methods, and these methods
45 might require some kind of transformations being made on the data. 44 might require some kind of transformations being made on the data.
46 <p> 45 <p>
47 This method is called on the object returned from the startSession 46 This method is called on the object returned from the startSession
48 function. 47 function.
49 */ 48 */
50 InputStream getInputStream(); 49 InputStream getInputStream();
51 /** 50 /**
52 This method should return output stream to use to write to the accepted 51 This method should return output stream to use to write to the accepted
53 socket. 52 socket.
54 <p> 53 <p>
55 SOCKSv5 allows to have multiple authentication methods, and these methods 54 SOCKSv5 allows to have multiple authentication methods, and these methods
56 might require some kind of transformations being made on the data. 55 might require some kind of transformations being made on the data.
57 <p> 56 <p>
58 This method is called on the object returned from the startSession 57 This method is called on the object returned from the startSession
59 function. 58 function.
60 */ 59 */
61 OutputStream getOutputStream(); 60 OutputStream getOutputStream();
62 61
63 /** 62 /**
64 This method should return UDPEncapsulation, which should be used 63 This method should return UDPEncapsulation, which should be used
65 on the datagrams being send in/out. 64 on the datagrams being send in/out.
66 <p> 65 <p>
67 If no transformation should be done on the datagrams, this method 66 If no transformation should be done on the datagrams, this method
68 should return null. 67 should return null.
69 <p> 68 <p>
70 This method is called on the object returned from the startSession 69 This method is called on the object returned from the startSession
71 function. 70 function.
72 */ 71 */
73 72
74 UDPEncapsulation getUdpEncapsulation(); 73 UDPEncapsulation getUdpEncapsulation();
75 74
76 /** 75 /**
77 This method is called when a request have been read. 76 This method is called when a request have been read.
78 <p> 77 <p>
79 Implementation should decide wether to grant request or not. Returning 78 Implementation should decide wether to grant request or not. Returning
80 true implies granting the request, false means request should be rejected. 79 true implies granting the request, false means request should be rejected.
81 <p> 80 <p>
82 This method is called on the object returned from the startSession 81 This method is called on the object returned from the startSession
83 function. 82 function.
84 @param msg Request message. 83 @param msg Request message.
85 @return true to grant request, false to reject it. 84 @return true to grant request, false to reject it.
86 */ 85 */
87 boolean checkRequest(ProxyMessage msg); 86 boolean checkRequest(ProxyMessage msg);
88 87
89 /** 88 /**
90 This method is called when datagram is received by the server. 89 This method is called when datagram is received by the server.
91 <p> 90 <p>
92 Implementaions should decide wether it should be forwarded or dropped. 91 Implementaions should decide wether it should be forwarded or dropped.
93 It is expecteed that implementation will use datagram address and port 92 It is expecteed that implementation will use datagram address and port
94 information to make a decision, as well as anything else. Address and 93 information to make a decision, as well as anything else. Address and
95 port of the datagram are always correspond to remote machine. It is 94 port of the datagram are always correspond to remote machine. It is
96 either destination or source address. If out is true address is destination 95 either destination or source address. If out is true address is destination
97 address, else it is a source address, address of the machine from which 96 address, else it is a source address, address of the machine from which
98 datagram have been received for the client. 97 datagram have been received for the client.
99 <p> 98 <p>
100 Implementaions should return true if the datagram is to be forwarded, and 99 Implementaions should return true if the datagram is to be forwarded, and
101 false if the datagram should be dropped. 100 false if the datagram should be dropped.
102 <p> 101 <p>
103 This method is called on the object returned from the startSession 102 This method is called on the object returned from the startSession
104 function. 103 function.
105 104
106 @param out If true the datagram is being send out(from the client), 105 @param out If true the datagram is being send out(from the client),
107 otherwise it is an incoming datagram. 106 otherwise it is an incoming datagram.
108 @return True to forward datagram false drop it silently. 107 @return True to forward datagram false drop it silently.
109 */ 108 */
110 boolean checkRequest(DatagramPacket dp, boolean out); 109 boolean checkRequest(DatagramPacket dp, boolean out);
111 110
112 /** 111 /**
113 This method is called when session is completed. Either due to normal 112 This method is called when session is completed. Either due to normal
114 termination or due to any error condition. 113 termination or due to any error condition.
115 <p> 114 <p>
116 This method is called on the object returned from the startSession 115 This method is called on the object returned from the startSession
117 function. 116 function.
118 */ 117 */
119 void endSession(); 118 void endSession();
120 } 119 }