1 22 package org.jboss.test; 23 24 import java.io.Serializable ; 25 import java.math.BigInteger ; 26 import java.rmi.RemoteException ; 27 import java.security.KeyException ; 28 import java.security.NoSuchAlgorithmException ; 29 30 import org.jboss.security.Util; 31 import org.jboss.security.srp.SRPConf; 32 import org.jboss.security.srp.SRPParameters; 33 import org.jboss.security.srp.SRPServerInterface; 34 import org.jboss.security.srp.SRPServerSession; 35 36 42 public class SimpleSRPServer implements SRPServerInterface 43 { 44 SRPParameters params; 45 SRPServerSession session; 46 char[] password; 47 48 public Object [] getSRPParameters(String username, boolean mutipleSessions) 49 throws KeyException , RemoteException 50 { 51 return new Object [0]; 52 } 53 54 public byte[] init(String username, byte[] A, int sessionID) throws SecurityException , 55 NoSuchAlgorithmException , RemoteException 56 { 57 return new byte[0]; 58 } 59 60 public byte[] verify(String username, byte[] M1, int sessionID) 61 throws SecurityException , RemoteException 62 { 63 return new byte[0]; 64 } 65 66 public byte[] verify(String username, byte[] M1, Object auxChallenge) 67 throws SecurityException , RemoteException 68 { 69 return new byte[0]; 70 } 71 72 public byte[] verify(String username, byte[] M1, Object auxChallenge, int sessionID) 73 throws SecurityException , RemoteException 74 { 75 return new byte[0]; 76 } 77 78 public void close(String username, int sessionID) throws SecurityException , RemoteException 79 { 80 } 81 82 SimpleSRPServer(char[] password, String salt) 83 { 84 byte[] N = SRPConf.getDefaultParams().Nbytes(); 85 byte[] g = SRPConf.getDefaultParams().gbytes(); 86 byte[] s = Util.fromb64(salt); 87 params = new SRPParameters(N, g, s); 88 this.password = password; 89 } 90 91 public SRPParameters getSRPParameters(String username) throws KeyException , RemoteException 92 { 93 return params; 94 } 95 96 public byte[] init(String username,byte[] A) throws SecurityException , 97 NoSuchAlgorithmException , RemoteException 98 { 99 byte[] v = Util.calculateVerifier(username, password, params.s, params.N, params.g); 101 session = new SRPServerSession(username, v, params); 103 byte[] B = session.exponential(); 104 session.buildSessionKey(A); 105 106 return B; 107 } 108 109 public byte[] verify(String username, byte[] M1) throws SecurityException , RemoteException 110 { 111 if( session.verify(M1) == false ) 112 throw new SecurityException ("Failed to verify M1"); 113 return session.getServerResponse(); 114 } 115 116 118 public void close(String username) throws SecurityException , RemoteException 119 { 120 } 121 122 } 123 | Popular Tags |