User: starksm 
  Date: 02/04/08 21:13:03

  Modified:    src/main/org/jboss/test Tag: Branch_2_4
                        NamespacePermission.java
                        NamespacePermissionCollection.java
                        PasswordHasher.java PermissionName.java
                        SRPLoginTest.java SRPServerImpl.java
                        SecurityPolicyParserTest.java SimpleSRPServer.java
                        TestJCE.java TestProtocol.java TestSRPLogin.java
                        TestSecurityPolicyParser.java TstClient.java
                        TstTimedCache.java
  Log:
  Merge the changes from 3.0 into 2.4
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.2.4.1   +1 -1      jbosssx/src/main/org/jboss/test/NamespacePermission.java
  
  Index: NamespacePermission.java
  ===================================================================
  RCS file: /cvsroot/jboss/jbosssx/src/main/org/jboss/test/NamespacePermission.java,v
  retrieving revision 1.2
  retrieving revision 1.2.4.1
  diff -u -r1.2 -r1.2.4.1
  --- NamespacePermission.java  6 Mar 2001 02:18:58 -0000       1.2
  +++ NamespacePermission.java  9 Apr 2002 04:13:03 -0000       1.2.4.1
  @@ -7,7 +7,7 @@
   
   /** A path like heirarchical permission.
   
  -@author  [EMAIL PROTECTED]
  +@author [EMAIL PROTECTED]
   @version $Revsiion:$
   */
   public class NamespacePermission extends BasicPermission
  
  
  
  1.2.4.1   +2 -2      
jbosssx/src/main/org/jboss/test/NamespacePermissionCollection.java
  
  Index: NamespacePermissionCollection.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jbosssx/src/main/org/jboss/test/NamespacePermissionCollection.java,v
  retrieving revision 1.2
  retrieving revision 1.2.4.1
  diff -u -r1.2 -r1.2.4.1
  --- NamespacePermissionCollection.java        6 Mar 2001 02:18:58 -0000       1.2
  +++ NamespacePermissionCollection.java        9 Apr 2002 04:13:03 -0000       1.2.4.1
  @@ -13,8 +13,8 @@
   
   /** The PermissionCollection object for NamespacePermissions.
   
  -@author  [EMAIL PROTECTED]
  -@version $Revision: 1.2 $
  +@author [EMAIL PROTECTED]
  +@version $Revision: 1.2.4.1 $
   */
   public class NamespacePermissionCollection extends PermissionCollection
   {
  
  
  
  1.1.2.2   +1 -1      jbosssx/src/main/org/jboss/test/PasswordHasher.java
  
  Index: PasswordHasher.java
  ===================================================================
  RCS file: /cvsroot/jboss/jbosssx/src/main/org/jboss/test/PasswordHasher.java,v
  retrieving revision 1.1.2.1
  retrieving revision 1.1.2.2
  diff -u -r1.1.2.1 -r1.1.2.2
  --- PasswordHasher.java       6 Feb 2002 20:03:26 -0000       1.1.2.1
  +++ PasswordHasher.java       9 Apr 2002 04:13:03 -0000       1.1.2.2
  @@ -8,7 +8,7 @@
   PasswordHasher [hashAlgorithm [hashEncoding [hashCharset]]] password
   
    @author [EMAIL PROTECTED]
  - @version $Revision: 1.1.2.1 $
  + @version $Revision: 1.1.2.2 $
    */
   public class PasswordHasher
   {
  
  
  
  1.1.4.1   +2 -2      jbosssx/src/main/org/jboss/test/PermissionName.java
  
  Index: PermissionName.java
  ===================================================================
  RCS file: /cvsroot/jboss/jbosssx/src/main/org/jboss/test/PermissionName.java,v
  retrieving revision 1.1
  retrieving revision 1.1.4.1
  diff -u -r1.1 -r1.1.4.1
  --- PermissionName.java       5 Mar 2001 09:53:37 -0000       1.1
  +++ PermissionName.java       9 Apr 2002 04:13:03 -0000       1.1.4.1
  @@ -11,8 +11,8 @@
   /** A javax.naming.Name based key class used as the name attribute
   by NamespacePermissions.
   
  -@author [EMAIL PROTECTED]
  -@version $Revision: 1.1 $
  +@author [EMAIL PROTECTED]
  +@version $Revision: 1.1.4.1 $
   */
   public class PermissionName implements Comparable, Serializable
   {
  
  
  
  1.2.2.1   +2 -2      jbosssx/src/main/org/jboss/test/SRPLoginTest.java
  
  Index: SRPLoginTest.java
  ===================================================================
  RCS file: /cvsroot/jboss/jbosssx/src/main/org/jboss/test/SRPLoginTest.java,v
  retrieving revision 1.2
  retrieving revision 1.2.2.1
  diff -u -r1.2 -r1.2.2.1
  --- SRPLoginTest.java 12 Apr 2001 02:53:57 -0000      1.2
  +++ SRPLoginTest.java 9 Apr 2002 04:13:03 -0000       1.2.2.1
  @@ -17,8 +17,8 @@
   
   @see org.jboss.security.srp.jaas.SRPLoginModule
   
  -@author [EMAIL PROTECTED]
  -@version $Revision: 1.2 $
  +@author [EMAIL PROTECTED]
  +@version $Revision: 1.2.2.1 $
   */
   public class SRPLoginTest extends junit.framework.TestCase
   {
  
  
  
  1.1.4.1   +2 -2      jbosssx/src/main/org/jboss/test/SRPServerImpl.java
  
  Index: SRPServerImpl.java
  ===================================================================
  RCS file: /cvsroot/jboss/jbosssx/src/main/org/jboss/test/SRPServerImpl.java,v
  retrieving revision 1.1
  retrieving revision 1.1.4.1
  diff -u -r1.1 -r1.1.4.1
  --- SRPServerImpl.java        4 Apr 2001 21:39:02 -0000       1.1
  +++ SRPServerImpl.java        9 Apr 2002 04:13:03 -0000       1.1.4.1
  @@ -20,8 +20,8 @@
   exports it on the standard RMI register 1099 port. It creates a
   SerialObjectStore as the SRPVerifierStore for the SRPRemoteServer.
   
  -@author [EMAIL PROTECTED]
  -@version $Revision: 1.1 $
  +@author [EMAIL PROTECTED]
  +@version $Revision: 1.1.4.1 $
   */
   public class SRPServerImpl
   {
  
  
  
  1.1.4.1   +3 -3      jbosssx/src/main/org/jboss/test/SecurityPolicyParserTest.java
  
  Index: SecurityPolicyParserTest.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jbosssx/src/main/org/jboss/test/SecurityPolicyParserTest.java,v
  retrieving revision 1.1
  retrieving revision 1.1.4.1
  diff -u -r1.1 -r1.1.4.1
  --- SecurityPolicyParserTest.java     4 Apr 2001 21:39:02 -0000       1.1
  +++ SecurityPolicyParserTest.java     9 Apr 2002 04:13:03 -0000       1.1.4.1
  @@ -21,8 +21,8 @@
   
   /** Tests of the SecurityPolicyParser and SecurityPolicy classes.
   
  -@author [EMAIL PROTECTED]
  -@version $Revision: 1.1 $
  +@author [EMAIL PROTECTED]
  +@version $Revision: 1.1.4.1 $
   */
   public class SecurityPolicyParserTest extends junit.framework.TestCase
   {
  @@ -53,7 +53,7 @@
           PermissionCollection perms = policy.getPermissions(subject, cs);
           Permission p = new NamespacePermission("Project1/Documents/Public", "r---");
           boolean implied = perms.implies(p);
  -        assert(p.toString(), implied);
  +        assertTrue(p.toString(), implied);
       }
   
       public void testSubject() throws LoginException
  
  
  
  1.2.4.2   +50 -41    jbosssx/src/main/org/jboss/test/SimpleSRPServer.java
  
  Index: SimpleSRPServer.java
  ===================================================================
  RCS file: /cvsroot/jboss/jbosssx/src/main/org/jboss/test/SimpleSRPServer.java,v
  retrieving revision 1.2.4.1
  retrieving revision 1.2.4.2
  diff -u -r1.2.4.1 -r1.2.4.2
  --- SimpleSRPServer.java      29 Dec 2001 04:32:45 -0000      1.2.4.1
  +++ SimpleSRPServer.java      9 Apr 2002 04:13:03 -0000       1.2.4.2
  @@ -4,55 +4,64 @@
   import java.math.BigInteger;
   import java.rmi.RemoteException;
   import java.security.KeyException;
  +import java.security.NoSuchAlgorithmException;
   
   import org.jboss.security.Util;
   import org.jboss.security.srp.SRPConf;
  +import org.jboss.security.srp.SRPParameters;
   import org.jboss.security.srp.SRPServerInterface;
  -import org.jboss.security.srp.SRPServerInterface.SRPParameters;
   import org.jboss.security.srp.SRPServerSession;
   
   /** A simple hard coded implementation of SRPServerInterface that validates
  -    any given username to the password and salt provided to its constructor.
  -
  -@author [EMAIL PROTECTED]
  -@version $Revision: 1.2.4.1 $
  -*/
  + any given username to the password and salt provided to its constructor.
  + 
  + @author [EMAIL PROTECTED]
  + @version $Revision: 1.2.4.2 $
  + */
   public class SimpleSRPServer implements SRPServerInterface
   {
  -    SRPParameters params = new SRPParameters();
  -    SRPServerSession session;
  -    String password;
  -
  -    SimpleSRPServer(String password, String salt)
  -    {
  -        params.N = SRPConf.getDefaultParams().Nbytes();
  -        params.g = SRPConf.getDefaultParams().gbytes();
  -        params.s = Util.fromb64(salt);
  -        this.password = password;
  -    }
  -
  -    public SRPParameters getSRPParameters(String username) throws KeyException, 
RemoteException
  -    {
  -        return params;
  -    }
  -
  -    public byte[] init(String username,byte[] A) throws SecurityException, 
RemoteException
  -    {
  -        // Calculate the password verfier v
  -        byte[] v = Util.calculateVerifier(username, password, params.s, params.N, 
params.g);
  -        // Create an SRP session
  -        session = new SRPServerSession(username, params.s, v, params.N, params.g);
  -        byte[] B = session.exponential();
  -        session.buildSessionKey(A);
  -
  -        return B;
  -    }
  -
  -    public byte[] verify(String username, byte[] M1) throws SecurityException, 
RemoteException
  -    {
  -        if( session.verify(M1) == false )
  -            throw new SecurityException("Failed to verify M1");
  -        return session.getServerResponse();
  -    }
  +   SRPParameters params;
  +   SRPServerSession session;
  +   char[] password;
  +   
  +   SimpleSRPServer(char[] password, String salt)
  +   {
  +      byte[] N = SRPConf.getDefaultParams().Nbytes();
  +      byte[] g = SRPConf.getDefaultParams().gbytes();
  +      byte[] s = Util.fromb64(salt);
  +      params = new SRPParameters(N, g, s);
  +      this.password = password;
  +   }
  +   
  +   public SRPParameters getSRPParameters(String username) throws KeyException, 
RemoteException
  +   {
  +      return params;
  +   }
  +   
  +   public byte[] init(String username,byte[] A) throws SecurityException,
  +      NoSuchAlgorithmException, RemoteException
  +   {
  +      // Calculate the password verfier v
  +      byte[] v = Util.calculateVerifier(username, password, params.s, params.N, 
params.g);
  +      // Create an SRP session
  +      session = new SRPServerSession(username, v, params);
  +      byte[] B = session.exponential();
  +      session.buildSessionKey(A);
  +      
  +      return B;
  +   }
  +   
  +   public byte[] verify(String username, byte[] M1) throws SecurityException, 
RemoteException
  +   {
  +      if( session.verify(M1) == false )
  +         throw new SecurityException("Failed to verify M1");
  +      return session.getServerResponse();
  +   }
  +  
  +   /** Close the SRP session for the given username.
  +    */
  +   public void close(String username) throws SecurityException, RemoteException
  +   {
  +   }
   
   }
  
  
  
  1.1.4.2   +106 -120  jbosssx/src/main/org/jboss/test/TestJCE.java
  
  Index: TestJCE.java
  ===================================================================
  RCS file: /cvsroot/jboss/jbosssx/src/main/org/jboss/test/TestJCE.java,v
  retrieving revision 1.1.4.1
  retrieving revision 1.1.4.2
  diff -u -r1.1.4.1 -r1.1.4.2
  --- TestJCE.java      29 Dec 2001 04:32:45 -0000      1.1.4.1
  +++ TestJCE.java      9 Apr 2002 04:13:03 -0000       1.1.4.2
  @@ -2,137 +2,123 @@
   
   import java.io.Serializable;
   import java.math.BigInteger;
  -import java.rmi.RemoteException;
  +import java.security.AlgorithmParameters;
   import java.security.Key;
   import java.security.KeyException;
   import java.security.MessageDigest;
  +import java.security.Provider;
   import java.security.SecureRandom;
  +import java.security.Security;
  +import java.util.Iterator;
   import javax.crypto.Cipher;
   import javax.crypto.KeyGenerator;
   import javax.crypto.SealedObject;
   import javax.crypto.SecretKey;
   import javax.crypto.spec.SecretKeySpec;
   
  -import org.apache.log4j.Category;
  -import org.apache.log4j.FileAppender;
  -import org.apache.log4j.NDC;
  -import org.apache.log4j.PatternLayout;
  -
  -import org.jboss.logging.TracePriority;
  -import org.jboss.security.Util;
  -import org.jboss.security.srp.SRPConf;
  -import org.jboss.security.srp.SRPServerInterface;
  -import org.jboss.security.srp.SRPServerInterface.SRPParameters;
  -import org.jboss.security.srp.SRPClientSession;
  -import org.jboss.security.srp.SRPServerSession;
  -
  -/** Tests of the Java Cryptography framework
  +/** Tests of the Java Cryptography Extension framework
  + @author [EMAIL PROTECTED]
  + @version $Revision: 1.1.4.2 $
   */
   public class TestJCE
   {
  -    SimpleSRPServer server;
  -    SRPClientSession client;
  -
  -    TestJCE() throws Exception
  -    {
  -        // Set up a simple configuration that logs on the console.
  -        Category root = Category.getRoot();
  -        root.setPriority(TracePriority.TRACE);
  -        root.addAppender(new FileAppender(new PatternLayout("%x%m%n"), System.out));
  -        Util.init();
  -        NDC.push("S,");
  -        server = new SimpleSRPServer("secret", "123456");
  -        NDC.pop();
  -    }
  -    void login(String username, String password) throws Exception
  -    {
  -        SRPParameters params = server.getSRPParameters(username);
  -        NDC.push("C,");
  -        client = new SRPClientSession(username, password, params.s, params.N, 
params.g);
  -        byte[] A = client.exponential();
  -        NDC.pop();
  -        NDC.push("S,");
  -        byte[] B = server.init(username, A);
  -        NDC.pop();
  -        NDC.push("C,");
  -        byte[] M1 = client.response(B);
  -        NDC.pop();
  -        NDC.push("S,");
  -        byte[] M2 = server.verify(username, M1);
  -        NDC.pop();
  -        NDC.push("C,");
  -        if( client.verify(M2) == false )
  -            throw new SecurityException("Failed to validate server reply");
  -        NDC.pop();
  -    }
  -
  -    /** Performs an SRP exchange and then uses the resulting session key to
  -     encrypt/decrypt a msg.
  -    */
  -    void testSecureExchange() throws Exception
  -    {
  -        login("jduke", "secret");
  -        System.out.println("Logged into server");
  -        byte[] kbytes = client.getSessionKey();
  -        System.out.println("Session key size = "+kbytes.length);
  -        SecretKeySpec clientKey = new SecretKeySpec(kbytes, "Blowfish");
  -        System.out.println("clientKey");
  -        Cipher cipher = Cipher.getInstance("Blowfish");
  -        cipher.init(Cipher.ENCRYPT_MODE, clientKey);
  -        SealedObject msg = new SealedObject("This is a secret", cipher);
  -
  -        // Now use the server key to decrypt the msg
  -        byte[] skbytes = server.session.getSessionKey();
  -        SecretKeySpec serverKey = new SecretKeySpec(skbytes, "Blowfish");
  -        Cipher scipher = Cipher.getInstance("Blowfish");
  -        cipher.init(Cipher.DECRYPT_MODE, serverKey);
  -        String theMsg = (String) msg.getObject(cipher);
  -        System.out.println("Decrypted: "+theMsg);
  -        // Try a key that should fail
  -        KeyGenerator kgen = KeyGenerator.getInstance("Blowfish");
  -        kgen.init(320);
  -        SecretKey key = kgen.generateKey();
  -        cipher.init(Cipher.DECRYPT_MODE, key);
  -        try
  -        {
  -            String tmp = (String) msg.getObject(cipher);
  -            throw new IllegalArgumentException("Should have failed to decrypt the 
msg");
  -        }
  -        catch(Exception e)
  -        {
  -            System.out.println("Arbitrary key failed as expected");
  -        }
  -    }
  -
  -    static void testKey() throws Exception
  -    {
  -        KeyGenerator kgen = KeyGenerator.getInstance("Blowfish");
  -        kgen.init(320);
  -        SecretKey key = kgen.generateKey();
  -        byte[] kbytes = key.getEncoded();
  -        System.out.println("key.Algorithm = "+key.getAlgorithm());
  -        System.out.println("key.Format = "+key.getFormat());
  -        System.out.println("key.Encoded Size = "+kbytes.length);
  -        SecureRandom rnd = SecureRandom.getInstance("SHA1PRNG");
  -        BigInteger bi = new BigInteger(320, rnd);
  -        byte[] k2bytes = bi.toByteArray();
  -        SecretKeySpec keySpec = new SecretKeySpec(k2bytes, "Blowfish");
  -        System.out.println("key2.Algorithm = "+key.getAlgorithm());
  -        System.out.println("key2.Format = "+key.getFormat());
  -        System.out.println("key2.Encoded Size = "+kbytes.length);        
  -    }
  -
  -    public static void main(String[] args)
  -    {
  -        try
  -        {
  -            System.setOut(System.err);
  -            TestJCE tst = new TestJCE();
  -            tst.testSecureExchange();
  -        }
  -        catch(Throwable t)
  -        {
  -            t.printStackTrace();
  -        }
  -    }
  +   static void showProviders() throws Exception
  +   {
  +      Provider[] providers = Security.getProviders();
  +      for(int p = 0; p < providers.length; p ++)
  +      {
  +         Iterator iter = providers[p].keySet().iterator();
  +         System.out.println("Provider: "+providers[p].getInfo());
  +         while( iter.hasNext() )
  +         {
  +            String key = (String) iter.next();
  +            System.out.println("  key="+key+", 
value="+providers[p].getProperty(key));
  +         }
  +      }
  +   }
  +
  +   static void testBlowfish() throws Exception
  +   {
  +      KeyGenerator kgen = KeyGenerator.getInstance("Blowfish");
  +      Cipher cipher = Cipher.getInstance("Blowfish");
  +      SecretKey key = null;
  +      int minKeyBits = -1, maxKeyBits = 0;
  +      int minCipherBits = -1, maxCipherBits = 0;
  +      for(int size = 1; size <= 448/8; size ++)
  +      {
  +         int bits = size * 8;
  +         try
  +         {
  +            kgen.init(bits);
  +            key = kgen.generateKey();
  +            if( minKeyBits == -1 )
  +               minKeyBits = bits;
  +            maxKeyBits = bits;
  +         }
  +         catch(Exception e)
  +         {
  +         }
  +
  +         try
  +         {
  +            cipher.init(Cipher.ENCRYPT_MODE, key);
  +            if( minCipherBits == -1 )
  +               minCipherBits = bits;
  +            maxCipherBits = bits;
  +         }
  +         catch(Exception e)
  +         {
  +         }
  +      }
  +      System.out.println("Key range: "+minKeyBits+".."+maxKeyBits);
  +      System.out.println("Cipher range: "+minCipherBits+".."+maxCipherBits);
  +   }
  +
  +   static void testKey() throws Exception
  +   {
  +      int size = 8 * 24;
  +      KeyGenerator kgen = KeyGenerator.getInstance("Blowfish");
  +      kgen.init(size);
  +      SecretKey key = kgen.generateKey();
  +      byte[] kbytes = key.getEncoded();
  +      System.out.println("key.Algorithm = "+key.getAlgorithm());
  +      System.out.println("key.Format = "+key.getFormat());
  +      System.out.println("key.Encoded Size = "+kbytes.length);
  +      
  +      Cipher cipher = Cipher.getInstance("Blowfish");
  +      AlgorithmParameters params = cipher.getParameters();
  +      System.out.println("Blowfish.params = "+params);
  +      cipher.init(Cipher.ENCRYPT_MODE, key);
  +      SealedObject msg = new SealedObject("This is a secret", cipher);
  +      
  +      SecretKeySpec serverKey = new SecretKeySpec(kbytes, "Blowfish");
  +      Cipher scipher = Cipher.getInstance("Blowfish");
  +      scipher.init(Cipher.DECRYPT_MODE, serverKey);
  +      String theMsg = (String) msg.getObject(scipher);
  +      System.out.println("Decrypted: "+theMsg);
  +      
  +      SecureRandom rnd = SecureRandom.getInstance("SHA1PRNG");
  +      BigInteger bi = new BigInteger(320, rnd);
  +      byte[] k2bytes = bi.toByteArray();
  +      SecretKeySpec keySpec = new SecretKeySpec(k2bytes, "Blowfish");
  +      System.out.println("key2.Algorithm = "+key.getAlgorithm());
  +      System.out.println("key2.Format = "+key.getFormat());
  +      System.out.println("key2.Encoded Size = "+kbytes.length);
  +   }
  +   
  +   public static void main(String[] args)
  +   {
  +      try
  +      {
  +         System.setOut(System.err);
  +         TestJCE tst = new TestJCE();
  +         tst.showProviders();
  +         //tst.testKey();
  +         tst.testBlowfish();
  +      }
  +      catch(Throwable t)
  +      {
  +         t.printStackTrace();
  +      }
  +   }
   }
  
  
  
  1.1.4.3   +131 -121  jbosssx/src/main/org/jboss/test/TestProtocol.java
  
  Index: TestProtocol.java
  ===================================================================
  RCS file: /cvsroot/jboss/jbosssx/src/main/org/jboss/test/TestProtocol.java,v
  retrieving revision 1.1.4.2
  retrieving revision 1.1.4.3
  diff -u -r1.1.4.2 -r1.1.4.3
  --- TestProtocol.java 29 Dec 2001 04:32:45 -0000      1.1.4.2
  +++ TestProtocol.java 9 Apr 2002 04:13:03 -0000       1.1.4.3
  @@ -11,145 +11,155 @@
   import java.rmi.RemoteException;
   import java.security.KeyException;
   import java.security.MessageDigest;
  +import java.security.NoSuchAlgorithmException;
   
   import org.apache.log4j.Category;
   import org.apache.log4j.ConsoleAppender;
   import org.apache.log4j.NDC;
   import org.apache.log4j.PatternLayout;
   
  +import org.jboss.logging.Logger;
   import org.jboss.logging.TracePriority;
  -import org.jboss.security.Logger;
   import org.jboss.security.Util;
   import org.jboss.security.srp.SRPConf;
   import org.jboss.security.srp.SRPServerInterface;
  -import org.jboss.security.srp.SRPServerInterface.SRPParameters;
   import org.jboss.security.srp.SRPClientSession;
  +import org.jboss.security.srp.SRPParameters;
   import org.jboss.security.srp.SRPServerSession;
   
   /** Test of the SRP protocol msg exchange sequence.
  -
  -@author [EMAIL PROTECTED]
  -@version $Revision: 1.1.4.2 $
  -*/
  + 
  + @author [EMAIL PROTECTED]
  + @version $Revision: 1.1.4.3 $
  + */
   public class TestProtocol extends junit.framework.TestCase
   {
  -    static Logger log = Logger.getLogger(TestProtocol.class);
  -    String username = "jduke";
  -    String password = "theduke";
  -    SRPServerInterface server;
  -
  -    /** A simple hard coded implementation of SRPServerInterface that validates
  +   static Logger log = Logger.getLogger(TestProtocol.class);
  +   String username = "jduke";
  +   char[] password = "theduke".toCharArray();
  +   SRPServerInterface server;
  +   
  +   /** A simple hard coded implementation of SRPServerInterface that validates
       any given username to the password and salt provided to its constructor.
       */
  -    static class TstImpl implements SRPServerInterface
  -    {
  -        SRPParameters params = new SRPParameters();
  -        SRPServerSession session;
  -        String password;
  -
  -        TstImpl(String password, String salt)
  -        {
  -            BigInteger N = SRPConf.getDefaultParams().N();
  -            log.trace("N: "+Util.tob64(N.toByteArray()));
  -            BigInteger g = SRPConf.getDefaultParams().g();
  -            log.trace("g: "+Util.tob64(g.toByteArray()));
  -            params.N = SRPConf.getDefaultParams().Nbytes();
  -            log.trace("N': "+Util.tob64(params.N));
  -            params.g = SRPConf.getDefaultParams().gbytes();
  -            log.trace("g': "+Util.tob64(params.g));
  -            byte[] hn = Util.newDigest().digest(params.N);
  -            log.trace("H(N): "+Util.tob64(hn));
  -            byte[] hg = Util.newDigest().digest(params.g);
  -            log.trace("H(g): "+Util.tob64(hg));
  -            params.s = Util.fromb64(salt);
  -            this.password = password;
  -        }
  -
  -        public SRPParameters getSRPParameters(String username) throws KeyException, 
RemoteException
  -        {
  -            return params;
  -        }
  -
  -        public byte[] init(String username,byte[] A) throws SecurityException, 
RemoteException
  -        {
  -            // Calculate the password verfier v
  -            byte[] v = Util.calculateVerifier(username, password, params.s, 
params.N, params.g);
  -            // Create an SRP session
  -            session = new SRPServerSession(username, params.s, v, params.N, 
params.g);
  -            byte[] B = session.exponential();
  -            session.buildSessionKey(A);
  -
  -            return B;
  -        }
  -
  -        public byte[] verify(String username, byte[] M1) throws SecurityException, 
RemoteException
  -        {
  -            if( session.verify(M1) == false )
  -                throw new SecurityException("Failed to verify M1");
  -            return session.getServerResponse();
  -        }
  -    }
  -
  -    public TestProtocol(String name)
  -    {
  -        super(name);
  -    }
  -
  -    protected void setUp() throws Exception
  -    {
  -        // Set up a simple configuration that logs on the console.
  -        Category root = Category.getRoot();
  -        root.setPriority(TracePriority.TRACE);
  -        root.addAppender(new ConsoleAppender(new PatternLayout("%x%m%n")));
  -        Util.init();
  -        NDC.push("S,");
  -        server = new TstImpl(password, "123456");
  -        NDC.pop();
  -    }
  -
  -    public void testProtocol() throws Exception
  -    {
  -        SRPParameters params = server.getSRPParameters(username);
  -        NDC.push("C,");
  -        SRPClientSession client = new SRPClientSession(username, password, 
params.s, params.N, params.g);
  -        byte[] A = client.exponential();
  -        NDC.pop();
  -        NDC.push("S,");
  -        byte[] B = server.init(username, A);
  -        NDC.pop();
  -        NDC.push("C,");
  -        byte[] M1 = client.response(B);
  -        NDC.pop();
  -        NDC.push("S,");
  -        byte[] M2 = server.verify(username, M1);
  -        NDC.pop();
  -        NDC.push("C,");
  -        if( client.verify(M2) == false )
  -            throw new SecurityException("Failed to validate server reply");
  -        NDC.pop();
  -    }
  -
  -    /**
  +   static class TstImpl implements SRPServerInterface
  +   {
  +      SRPParameters params;
  +      SRPServerSession session;
  +      char[] password;
  +      
  +      TstImpl(char[] password, String salt)
  +      {
  +         BigInteger N = SRPConf.getDefaultParams().N();
  +         log.trace("N: "+Util.tob64(N.toByteArray()));
  +         BigInteger g = SRPConf.getDefaultParams().g();
  +         log.trace("g: "+Util.tob64(g.toByteArray()));
  +         byte[] Nb = SRPConf.getDefaultParams().Nbytes();
  +         log.trace("N': "+Util.tob64(params.N));
  +         byte[] gb = SRPConf.getDefaultParams().gbytes();
  +         log.trace("g': "+Util.tob64(params.g));
  +         byte[] hn = Util.newDigest().digest(params.N);
  +         log.trace("H(N): "+Util.tob64(hn));
  +         byte[] hg = Util.newDigest().digest(params.g);
  +         log.trace("H(g): "+Util.tob64(hg));
  +         byte[] sb = Util.fromb64(salt);
  +         this.password = password;
  +         params = new SRPParameters(Nb, gb, sb);
  +      }
  +      
  +      public SRPParameters getSRPParameters(String username) throws KeyException, 
RemoteException
  +      {
  +         return params;
  +      }
  +      
  +      public byte[] init(String username,byte[] A) throws SecurityException,
  +         NoSuchAlgorithmException, RemoteException
  +      {
  +         // Calculate the password verfier v
  +         byte[] v = Util.calculateVerifier(username, password, params.s, params.N, 
params.g);
  +         // Create an SRP session
  +         session = new SRPServerSession(username, v, params);
  +         byte[] B = session.exponential();
  +         session.buildSessionKey(A);
  +         
  +         return B;
  +      }
  +      
  +      public byte[] verify(String username, byte[] M1) throws SecurityException, 
RemoteException
  +      {
  +         if( session.verify(M1) == false )
  +            throw new SecurityException("Failed to verify M1");
  +         return session.getServerResponse();
  +      }
  +      
  +      /** Close the SRP session for the given username.
  +       */
  +      public void close(String username) throws SecurityException, RemoteException
  +      {
  +      }
  +
  +   }
  +   
  +   public TestProtocol(String name)
  +   {
  +      super(name);
  +   }
  +   
  +   protected void setUp() throws Exception
  +   {
  +      // Set up a simple configuration that logs on the console.
  +      Category root = Category.getRoot();
  +      root.setPriority(TracePriority.TRACE);
  +      root.addAppender(new ConsoleAppender(new PatternLayout("%x%m%n")));
  +      Util.init();
  +      NDC.push("S,");
  +      server = new TstImpl(password, "123456");
  +      NDC.pop();
  +   }
  +   
  +   public void testProtocol() throws Exception
  +   {
  +      SRPParameters params = server.getSRPParameters(username);
  +      NDC.push("C,");
  +      SRPClientSession client = new SRPClientSession(username, password, params);
  +      byte[] A = client.exponential();
  +      NDC.pop();
  +      NDC.push("S,");
  +      byte[] B = server.init(username, A);
  +      NDC.pop();
  +      NDC.push("C,");
  +      byte[] M1 = client.response(B);
  +      NDC.pop();
  +      NDC.push("S,");
  +      byte[] M2 = server.verify(username, M1);
  +      NDC.pop();
  +      NDC.push("C,");
  +      if( client.verify(M2) == false )
  +         throw new SecurityException("Failed to validate server reply");
  +      NDC.pop();
  +   }
  +   
  +   /**
       * @param args the command line arguments
       */
  -    public static void main(String args[])
  -    {
  -        long start = System.currentTimeMillis();
  -        try
  -        {
  -            TestProtocol tst = new TestProtocol("main");
  -            tst.setUp();
  -            tst.testProtocol();
  -        }
  -        catch(Exception e)
  -        {
  -            e.printStackTrace(System.out);
  -        }
  -        finally
  -        {
  -            long end = System.currentTimeMillis();
  -            System.out.println("Elapsed time = "+(end - start));
  -        }
  -    }
  -
  +   public static void main(String args[])
  +   {
  +      long start = System.currentTimeMillis();
  +      try
  +      {
  +         TestProtocol tst = new TestProtocol("main");
  +         tst.setUp();
  +         tst.testProtocol();
  +      }
  +      catch(Exception e)
  +      {
  +         e.printStackTrace(System.out);
  +      }
  +      finally
  +      {
  +         long end = System.currentTimeMillis();
  +         System.out.println("Elapsed time = "+(end - start));
  +      }
  +   }
  +   
   }
  
  
  
  1.2.2.2   +3 -3      jbosssx/src/main/org/jboss/test/TestSRPLogin.java
  
  Index: TestSRPLogin.java
  ===================================================================
  RCS file: /cvsroot/jboss/jbosssx/src/main/org/jboss/test/TestSRPLogin.java,v
  retrieving revision 1.2.2.1
  retrieving revision 1.2.2.2
  diff -u -r1.2.2.1 -r1.2.2.2
  --- TestSRPLogin.java 29 Dec 2001 04:32:45 -0000      1.2.2.1
  +++ TestSRPLogin.java 9 Apr 2002 04:13:03 -0000       1.2.2.2
  @@ -17,9 +17,9 @@
    
    @see org.jboss.security.srp.jaas.SRPLoginModule
    
  - @author [EMAIL PROTECTED]
  - @version $Revision: 1.2.2.1 $
  - */
  +@author [EMAIL PROTECTED]
  +@version $Revision: 1.2.2.2 $
  +*/
   public class TestSRPLogin extends junit.framework.TestCase
   {
      public TestSRPLogin(String name)
  
  
  
  1.1.4.1   +3 -3      jbosssx/src/main/org/jboss/test/TestSecurityPolicyParser.java
  
  Index: TestSecurityPolicyParser.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jbosssx/src/main/org/jboss/test/TestSecurityPolicyParser.java,v
  retrieving revision 1.1
  retrieving revision 1.1.4.1
  diff -u -r1.1 -r1.1.4.1
  --- TestSecurityPolicyParser.java     5 Mar 2001 09:53:38 -0000       1.1
  +++ TestSecurityPolicyParser.java     9 Apr 2002 04:13:03 -0000       1.1.4.1
  @@ -21,8 +21,8 @@
   
   /** Tests of the SecurityPolicyParser and SecurityPolicy classes.
   
  -@author [EMAIL PROTECTED]
  -@version $Revision: 1.1 $
  +@author [EMAIL PROTECTED]
  +@version $Revision: 1.1.4.1 $
   */
   public class TestSecurityPolicyParser extends junit.framework.TestCase
   {
  @@ -53,7 +53,7 @@
        PermissionCollection perms = policy.getPermissions(subject, cs);
        Permission p = new NamespacePermission("Project1/Documents/Public", "r---");
        boolean implied = perms.implies(p);
  -     assert(p.toString(), implied);
  +     assertTrue(p.toString(), implied);
       }
   
       public void testSubject() throws LoginException
  
  
  
  1.1.4.1   +5 -5      jbosssx/src/main/org/jboss/test/TstClient.java
  
  Index: TstClient.java
  ===================================================================
  RCS file: /cvsroot/jboss/jbosssx/src/main/org/jboss/test/TstClient.java,v
  retrieving revision 1.1
  retrieving revision 1.1.4.1
  diff -u -r1.1 -r1.1.4.1
  --- TstClient.java    5 Mar 2001 09:53:38 -0000       1.1
  +++ TstClient.java    9 Apr 2002 04:13:03 -0000       1.1.4.1
  @@ -8,26 +8,26 @@
   
   import org.jboss.security.srp.SRPClientSession;
   import org.jboss.security.srp.SRPServerInterface;
  -import org.jboss.security.srp.SRPServerInterface.SRPParameters;
  +import org.jboss.security.srp.SRPParameters;
   
   /** A simple test client that looks up the SimpleSRPServer in the RMI
   registry and attempts to validate the username and password passed
   on the command line.
   
  -@author [EMAIL PROTECTED]
  -@version $Revision: 1.1 $
  +@author [EMAIL PROTECTED]
  +@version $Revision: 1.1.4.1 $
   */
   public class TstClient
   {
       public static void main(String[] args) throws Exception
       {
           String username = args[0];
  -        String password = args[1];
  +        char[] password = args[1].toCharArray();
           SRPServerInterface server = (SRPServerInterface) 
Naming.lookup("SimpleSRPServer");
           System.out.println("Found SRPServerInterface");
           SRPParameters params = server.getSRPParameters(username);
           System.out.println("Found params for username: "+username);
  -        SRPClientSession client = new SRPClientSession(username, password, 
params.s, params.N, params.g);
  +        SRPClientSession client = new SRPClientSession(username, password, params);
           byte[] A = client.exponential();
           byte[] B = server.init(username, A);
           System.out.println("Sent A public key, got B public key");
  
  
  
  1.1.4.1   +2 -2      jbosssx/src/main/org/jboss/test/TstTimedCache.java
  
  Index: TstTimedCache.java
  ===================================================================
  RCS file: /cvsroot/jboss/jbosssx/src/main/org/jboss/test/TstTimedCache.java,v
  retrieving revision 1.1
  retrieving revision 1.1.4.1
  diff -u -r1.1 -r1.1.4.1
  --- TstTimedCache.java        5 Mar 2001 09:53:38 -0000       1.1
  +++ TstTimedCache.java        9 Apr 2002 04:13:03 -0000       1.1.4.1
  @@ -13,8 +13,8 @@
   
   @see org.jboss.util.TimedCachePolicy
   
  -@author [EMAIL PROTECTED]
  -@version $Revision: 1.1 $
  +@author [EMAIL PROTECTED]
  +@version $Revision: 1.1.4.1 $
   */
   public class TstTimedCache
   {
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to