1 22 package org.jboss.test; 23 24 import java.io.IOException ; 25 import javax.naming.InitialContext ; 26 27 import org.jboss.logging.Logger; 28 import org.apache.log4j.ConsoleAppender; 29 import org.apache.log4j.PatternLayout; 30 31 import org.jboss.security.srp.SRPClientSession; 32 import org.jboss.security.srp.SRPServerInterface; 33 import org.jboss.security.srp.SRPParameters; 34 import org.jboss.logging.XLevel; 35 36 43 public class TstClient 44 { 45 public static void main(String [] args) throws Exception 46 { 47 String username = args[0]; 48 char[] password = args[1].toCharArray(); 49 String serviceName = args.length == 3 ? args[2] : "srp-test/SRPServerInterface"; 50 51 Logger root = Logger.getRoot(); 53 root.setLevel(XLevel.TRACE); 54 root.addAppender(new ConsoleAppender(new PatternLayout("%x%m%n"))); 55 56 InitialContext ctx = new InitialContext (); 57 SRPServerInterface server = (SRPServerInterface) ctx.lookup(serviceName); 58 System.out.println("Found SRPServerInterface, "+server); 59 SRPParameters params = server.getSRPParameters(username); 60 System.out.println("Found params for username: " + username); 61 SRPClientSession client = new SRPClientSession(username, password, params); 62 byte[] A = client.exponential(); 63 byte[] B = server.init(username, A); 64 System.out.println("Sent A public key, got B public key"); 65 byte[] M1 = client.response(B); 66 byte[] M2 = server.verify(username, M1); 67 System.out.println("Sent M1 challenge, got M2 challenge"); 68 if (client.verify(M2) == false) 69 throw new SecurityException ("Failed to validate server reply"); 70 System.out.println("Validation successful"); 71 server.close(username); 72 } 73 } 74 | Popular Tags |