001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.security.test;
023:
024: import java.io.Serializable;
025: import java.math.BigInteger;
026: import java.rmi.RemoteException;
027: import java.security.KeyException;
028: import java.security.NoSuchAlgorithmException;
029:
030: import org.jboss.security.Util;
031: import org.jboss.security.srp.SRPConf;
032: import org.jboss.security.srp.SRPParameters;
033: import org.jboss.security.srp.SRPServerInterface;
034: import org.jboss.security.srp.SRPServerSession;
035:
036: /** A simple hard coded implementation of SRPServerInterface that validates
037: any given username to the password and salt provided to its constructor.
038:
039: @author Scott.Stark@jboss.org
040: @version $Revision: 57210 $
041: */
042: public class SimpleSRPServer implements SRPServerInterface {
043: SRPParameters params;
044: SRPServerSession session;
045: char[] password;
046:
047: public Object[] getSRPParameters(String username,
048: boolean mutipleSessions) throws KeyException,
049: RemoteException {
050: return new Object[0];
051: }
052:
053: public byte[] init(String username, byte[] A, int sessionID)
054: throws SecurityException, NoSuchAlgorithmException,
055: RemoteException {
056: return new byte[0];
057: }
058:
059: public byte[] verify(String username, byte[] M1, int sessionID)
060: throws SecurityException, RemoteException {
061: return new byte[0];
062: }
063:
064: public byte[] verify(String username, byte[] M1, Object auxChallenge)
065: throws SecurityException, RemoteException {
066: return new byte[0];
067: }
068:
069: public byte[] verify(String username, byte[] M1,
070: Object auxChallenge, int sessionID)
071: throws SecurityException, RemoteException {
072: return new byte[0];
073: }
074:
075: public void close(String username, int sessionID)
076: throws SecurityException, RemoteException {
077: }
078:
079: SimpleSRPServer(char[] password, String salt) {
080: byte[] N = SRPConf.getDefaultParams().Nbytes();
081: byte[] g = SRPConf.getDefaultParams().gbytes();
082: byte[] s = Util.fromb64(salt);
083: params = new SRPParameters(N, g, s);
084: this .password = password;
085: }
086:
087: public SRPParameters getSRPParameters(String username)
088: throws KeyException, RemoteException {
089: return params;
090: }
091:
092: public byte[] init(String username, byte[] A)
093: throws SecurityException, NoSuchAlgorithmException,
094: RemoteException {
095: // Calculate the password verfier v
096: byte[] v = Util.calculateVerifier(username, password, params.s,
097: params.N, params.g);
098: // Create an SRP session
099: session = new SRPServerSession(username, v, params);
100: byte[] B = session.exponential();
101: session.buildSessionKey(A);
102:
103: return B;
104: }
105:
106: public byte[] verify(String username, byte[] M1)
107: throws SecurityException, RemoteException {
108: if (session.verify(M1) == false)
109: throw new SecurityException("Failed to verify M1");
110: return session.getServerResponse();
111: }
112:
113: /** Close the SRP session for the given username.
114: */
115: public void close(String username) throws SecurityException,
116: RemoteException {
117: }
118:
119: }
|