1 7 package org.jboss.test; 8 9 import java.security.MessageDigest ; 10 import java.security.Security ; 11 12 import junit.extensions.TestSetup; 13 import junit.framework.Test; 14 import junit.framework.TestCase; 15 import junit.framework.TestSuite; 16 17 import org.jboss.crypto.JBossSXProvider; 18 import org.jboss.security.Util; 19 20 26 public class SecurityProviderlTestCase extends TestCase 27 { 28 public SecurityProviderlTestCase(String name) 29 { 30 super(name); 31 } 32 33 38 public void testSHAInterleave() throws Exception 39 { 40 System.out.println("testSHAInterleave"); 41 MessageDigest md = MessageDigest.getInstance("SHA-SRP"); 42 byte[] test = "session_key".getBytes(); 43 44 byte[] hash1 = Util.sessionKeyHash(test); 45 String hash1b64 = Util.encodeBase64(hash1); 46 System.out.println("hash1 = "+hash1b64); 47 byte[] hash2 = md.digest(test); 48 String hash2b64 = Util.encodeBase64(hash2); 49 System.out.println("hash2 = "+hash2b64); 50 super.assertTrue(hash1b64.equals(hash2b64) == false); 51 } 52 54 public void testSHAReverseInterleave() throws Exception 55 { 56 System.out.println("testSHAReverseInterleave"); 57 MessageDigest md = MessageDigest.getInstance("SHA-SRP-Reverse"); 58 byte[] test = "session_key".getBytes(); 59 60 byte[] hash1 = Util.sessionKeyHash(test); 61 String hash1b64 = Util.encodeBase64(hash1); 62 System.out.println("hash1 = "+hash1b64); 63 byte[] hash2 = md.digest(test); 64 String hash2b64 = Util.encodeBase64(hash2); 65 System.out.println("hash2 = "+hash2b64); 66 super.assertEquals(hash1b64, hash2b64); 67 } 68 69 public static Test suite() 70 { 71 TestSuite suite = new TestSuite(SecurityProviderlTestCase.class); 72 73 TestSetup wrapper = new TestSetup(suite) 75 { 76 protected void setUp() throws Exception 77 { 78 Util.init(); 79 JBossSXProvider provider = new JBossSXProvider(); 80 Security.addProvider(provider); 81 } 82 protected void tearDown() throws Exception 83 { 84 Security.removeProvider(JBossSXProvider.PROVIDER_NAME); 85 } 86 }; 87 return wrapper; 88 } 89 90 public static void main(java.lang.String [] args) 91 { 92 System.setErr(System.out); 93 Test suite = suite(); 94 junit.textui.TestRunner.run(suite); 95 } 96 } 97 | Popular Tags |