Search in sources :

Example 1 with UsernamePasswordAuthenticator

use of sockslib.server.UsernamePasswordAuthenticator in project bnd by bndtools.

the class HttpClientProxyTest method createSecureSocks5.

private void createSecureSocks5() throws IOException, InterruptedException {
    UserManager userManager = new MemoryBasedUserManager();
    userManager.create(new User("proxyuser", "good"));
    SocksServerBuilder builder = SocksServerBuilder.newSocks5ServerBuilder();
    builder.setBindPort(++socksProxyPort);
    builder.setUserManager(userManager);
    builder.addSocksMethods(new UsernamePasswordMethod(new UsernamePasswordAuthenticator() {

        @Override
        public void doAuthenticate(Credentials arg0, Session arg1) throws AuthenticationException {
            // does not get called?
            System.out.println("Authenticating");
            super.doAuthenticate(arg0, arg1);
            authenticationCalled.set(true);
        }
    }));
    socks5Proxy = builder.build();
    socks5Proxy.getSessionManager().addSessionListener("abc", new SessionListener() {

        @Override
        public void onException(Session arg0, Exception arg1) {
            System.err.println("Exception " + arg0 + " " + arg1);
            arg1.printStackTrace();
            exception.set(arg1);
        }

        @Override
        public void onCommand(Session arg0, CommandMessage arg1) throws CloseSessionException {
            System.err.println("Command " + arg0 + " " + arg1);
        }

        @Override
        public void onClose(Session arg0) {
            System.err.println("Close " + arg0);
        }

        @Override
        public void onCreate(Session arg0) throws CloseSessionException {
            System.err.println("Create " + arg0);
            created.incrementAndGet();
        }
    });
    socks5Proxy.start();
}
Also used : User(sockslib.server.manager.User) UsernamePasswordMethod(sockslib.common.methods.UsernamePasswordMethod) CloseSessionException(sockslib.server.listener.CloseSessionException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) AuthenticationException(sockslib.common.AuthenticationException) CommandMessage(sockslib.server.msg.CommandMessage) SocksServerBuilder(sockslib.server.SocksServerBuilder) UserManager(sockslib.server.manager.UserManager) MemoryBasedUserManager(sockslib.server.manager.MemoryBasedUserManager) MemoryBasedUserManager(sockslib.server.manager.MemoryBasedUserManager) UsernamePasswordAuthenticator(sockslib.server.UsernamePasswordAuthenticator) SessionListener(sockslib.server.listener.SessionListener) CloseSessionException(sockslib.server.listener.CloseSessionException) Credentials(sockslib.common.Credentials) Session(sockslib.server.Session)

Example 2 with UsernamePasswordAuthenticator

use of sockslib.server.UsernamePasswordAuthenticator in project bnd by bndtools.

the class Standalone method createSecureSocks5.

void createSecureSocks5() throws IOException, InterruptedException {
    UserManager userManager = new MemoryBasedUserManager();
    userManager.create(new User("proxyuser", "good"));
    SocksServerBuilder builder = SocksServerBuilder.newSocks5ServerBuilder();
    builder.setBindPort(9090);
    // builder.setUserManager(userManager);
    UsernamePasswordMethod usernamePasswordMethod = new UsernamePasswordMethod();
    usernamePasswordMethod.setAuthenticator(new UsernamePasswordAuthenticator() {

        @Override
        public void doAuthenticate(Credentials arg0, Session arg1) throws AuthenticationException {
            super.doAuthenticate(arg0, arg1);
            System.out.println("Auth " + arg0 + " " + arg1);
        }
    });
    builder.setSocksMethods(usernamePasswordMethod).setUserManager(userManager);
    socks5Proxy = builder.build();
    socks5Proxy.getSessionManager().addSessionListener("abc", new SessionListener() {

        @Override
        public void onException(Session arg0, Exception arg1) {
            System.err.println("Exception " + arg0 + " " + arg1);
            arg1.printStackTrace();
        }

        @Override
        public void onCommand(Session arg0, CommandMessage arg1) throws CloseSessionException {
            System.err.println("Command " + arg0 + " " + arg1);
        }

        @Override
        public void onClose(Session arg0) {
            System.err.println("Close " + arg0);
        }

        @Override
        public void onCreate(Session arg0) throws CloseSessionException {
            System.err.println("Create " + arg0);
        }
    });
    socks5Proxy.start();
}
Also used : User(sockslib.server.manager.User) AuthenticationException(sockslib.common.AuthenticationException) UsernamePasswordMethod(sockslib.common.methods.UsernamePasswordMethod) CloseSessionException(sockslib.server.listener.CloseSessionException) IOException(java.io.IOException) AuthenticationException(sockslib.common.AuthenticationException) CommandMessage(sockslib.server.msg.CommandMessage) SocksServerBuilder(sockslib.server.SocksServerBuilder) UserManager(sockslib.server.manager.UserManager) MemoryBasedUserManager(sockslib.server.manager.MemoryBasedUserManager) MemoryBasedUserManager(sockslib.server.manager.MemoryBasedUserManager) UsernamePasswordAuthenticator(sockslib.server.UsernamePasswordAuthenticator) SessionListener(sockslib.server.listener.SessionListener) CloseSessionException(sockslib.server.listener.CloseSessionException) Credentials(sockslib.common.Credentials) Session(sockslib.server.Session)

Example 3 with UsernamePasswordAuthenticator

use of sockslib.server.UsernamePasswordAuthenticator in project bnd by bndtools.

the class IndexedReposWithComms method createSecureSocks5.

private void createSecureSocks5() throws IOException, InterruptedException {
    UserManager userManager = new MemoryBasedUserManager();
    userManager.create(new User("proxyuser", "good"));
    SocksServerBuilder builder = SocksServerBuilder.newSocks5ServerBuilder();
    builder.setBindAddr(InetAddress.getLoopbackAddress());
    builder.setBindPort(9090);
    builder.setUserManager(userManager);
    builder.addSocksMethods(new UsernamePasswordMethod(new UsernamePasswordAuthenticator() {

        @Override
        public void doAuthenticate(Credentials arg0, Session arg1) throws AuthenticationException {
            // does not get called?
            System.out.println("Authenticating");
            super.doAuthenticate(arg0, arg1);
        }
    }));
    socks5Proxy = builder.build();
    socks5Proxy.getSessionManager().addSessionListener("abc", new SessionListener() {

        @Override
        public void onException(Session arg0, Exception arg1) {
            System.err.println("Exception " + arg0 + " " + arg1);
            arg1.printStackTrace();
        }

        @Override
        public void onCommand(Session arg0, CommandMessage arg1) throws CloseSessionException {
            System.err.println("Command " + arg0 + " " + arg1);
        }

        @Override
        public void onClose(Session arg0) {
            System.err.println("Close " + arg0);
        }

        @Override
        public void onCreate(Session arg0) throws CloseSessionException {
            System.err.println("Create " + arg0);
        }
    });
    socks5Proxy.start();
}
Also used : User(sockslib.server.manager.User) UsernamePasswordMethod(sockslib.common.methods.UsernamePasswordMethod) CloseSessionException(sockslib.server.listener.CloseSessionException) IOException(java.io.IOException) AuthenticationException(sockslib.common.AuthenticationException) CommandMessage(sockslib.server.msg.CommandMessage) SocksServerBuilder(sockslib.server.SocksServerBuilder) UserManager(sockslib.server.manager.UserManager) MemoryBasedUserManager(sockslib.server.manager.MemoryBasedUserManager) MemoryBasedUserManager(sockslib.server.manager.MemoryBasedUserManager) UsernamePasswordAuthenticator(sockslib.server.UsernamePasswordAuthenticator) SessionListener(sockslib.server.listener.SessionListener) CloseSessionException(sockslib.server.listener.CloseSessionException) Credentials(sockslib.common.Credentials) Session(sockslib.server.Session)

Aggregations

IOException (java.io.IOException)3 AuthenticationException (sockslib.common.AuthenticationException)3 Credentials (sockslib.common.Credentials)3 UsernamePasswordMethod (sockslib.common.methods.UsernamePasswordMethod)3 Session (sockslib.server.Session)3 SocksServerBuilder (sockslib.server.SocksServerBuilder)3 UsernamePasswordAuthenticator (sockslib.server.UsernamePasswordAuthenticator)3 CloseSessionException (sockslib.server.listener.CloseSessionException)3 SessionListener (sockslib.server.listener.SessionListener)3 MemoryBasedUserManager (sockslib.server.manager.MemoryBasedUserManager)3 User (sockslib.server.manager.User)3 UserManager (sockslib.server.manager.UserManager)3 CommandMessage (sockslib.server.msg.CommandMessage)3 MalformedURLException (java.net.MalformedURLException)1