01: /*
02: * JBoss, Home of Professional Open Source.
03: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
04: * as indicated by the @author tags. See the copyright.txt file in the
05: * distribution for a full listing of individual contributors.
06: *
07: * This is free software; you can redistribute it and/or modify it
08: * under the terms of the GNU Lesser General Public License as
09: * published by the Free Software Foundation; either version 2.1 of
10: * the License, or (at your option) any later version.
11: *
12: * This software is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: *
17: * You should have received a copy of the GNU Lesser General Public
18: * License along with this software; if not, write to the Free
19: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21: */
22: package org.jboss.security.test;
23:
24: import java.io.IOException;
25: import javax.naming.InitialContext;
26:
27: import org.apache.log4j.Category;
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: /** A simple test client that looks up the SimpleSRPServer in the RMI
37: registry and attempts to validate the username and password passed
38: on the command line.
39:
40: @author Scott.Stark@jboss.org
41: @version $Revision: 57210 $
42: */
43: public class TstClient {
44: public static void main(String[] args) throws Exception {
45: String username = args[0];
46: char[] password = args[1].toCharArray();
47: String serviceName = args.length == 3 ? args[2]
48: : "srp-test/SRPServerInterface";
49:
50: // Set up a simple configuration that logs on the console.
51: Category root = Category.getRoot();
52: root.setLevel(XLevel.TRACE);
53: root.addAppender(new ConsoleAppender(
54: new PatternLayout("%x%m%n")));
55:
56: InitialContext ctx = new InitialContext();
57: SRPServerInterface server = (SRPServerInterface) ctx
58: .lookup(serviceName);
59: System.out.println("Found SRPServerInterface, " + server);
60: SRPParameters params = server.getSRPParameters(username);
61: System.out.println("Found params for username: " + username);
62: SRPClientSession client = new SRPClientSession(username,
63: password, params);
64: byte[] A = client.exponential();
65: byte[] B = server.init(username, A);
66: System.out.println("Sent A public key, got B public key");
67: byte[] M1 = client.response(B);
68: byte[] M2 = server.verify(username, M1);
69: System.out.println("Sent M1 challenge, got M2 challenge");
70: if (client.verify(M2) == false)
71: throw new SecurityException(
72: "Failed to validate server reply");
73: System.out.println("Validation successful");
74: server.close(username);
75: }
76: }
|