diff options
Diffstat (limited to 'support/src/test')
17 files changed, 1743 insertions, 0 deletions
diff --git a/support/src/test/java/tests/security/AlgorithmParameterAsymmetricHelper.java b/support/src/test/java/tests/security/AlgorithmParameterAsymmetricHelper.java new file mode 100644 index 0000000..89809e1 --- /dev/null +++ b/support/src/test/java/tests/security/AlgorithmParameterAsymmetricHelper.java @@ -0,0 +1,101 @@ +/* + * Copyright (C) 2009 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package tests.security; + +import java.security.AlgorithmParameters; +import java.security.InvalidAlgorithmParameterException; +import java.security.InvalidKeyException; +import java.security.KeyPair; +import java.security.KeyPairGenerator; +import java.security.NoSuchAlgorithmException; +import java.util.Arrays; +import javax.crypto.BadPaddingException; +import javax.crypto.Cipher; +import javax.crypto.IllegalBlockSizeException; +import javax.crypto.NoSuchPaddingException; +import junit.framework.Assert; + +public class AlgorithmParameterAsymmetricHelper extends TestHelper<AlgorithmParameters> { + + private static final String plainData = "some data to encrypt and decrypt"; + private final String algorithmName; + + public AlgorithmParameterAsymmetricHelper(String algorithmName) { + this.algorithmName = algorithmName; + } + + @Override + public void test(AlgorithmParameters parameters) { + + KeyPairGenerator generator = null; + try { + generator = KeyPairGenerator.getInstance(algorithmName); + } catch (NoSuchAlgorithmException e) { + Assert.fail(e.getMessage()); + } + + generator.initialize(1024); + + KeyPair keyPair = generator.generateKeyPair(); + + + Cipher cipher = null; + try { + cipher = Cipher.getInstance(algorithmName); + } catch (NoSuchAlgorithmException e) { + Assert.fail(e.getMessage()); + } catch (NoSuchPaddingException e) { + Assert.fail(e.getMessage()); + } + + try { + cipher.init(Cipher.ENCRYPT_MODE, keyPair.getPublic(), parameters); + } catch (InvalidKeyException e) { + Assert.fail(e.getMessage()); + } catch (InvalidAlgorithmParameterException e) { + Assert.fail(e.getMessage()); + } + + byte[] bs = null; + try { + bs = cipher.doFinal(plainData.getBytes()); + } catch (IllegalBlockSizeException e) { + Assert.fail(e.getMessage()); + } catch (BadPaddingException e) { + Assert.fail(e.getMessage()); + } + + try { + cipher.init(Cipher.DECRYPT_MODE, keyPair.getPrivate(), parameters); + } catch (InvalidKeyException e) { + Assert.fail(e.getMessage()); + } catch (InvalidAlgorithmParameterException e) { + Assert.fail(e.getMessage()); + } + + byte[] decrypted = null; + try { + decrypted = cipher.doFinal(bs); + } catch (IllegalBlockSizeException e) { + Assert.fail(e.getMessage()); + } catch (BadPaddingException e) { + Assert.fail(e.getMessage()); + } + + Assert.assertTrue(Arrays.equals(plainData.getBytes(), decrypted)); + } +} diff --git a/support/src/test/java/tests/security/AlgorithmParameterGeneratorTest.java b/support/src/test/java/tests/security/AlgorithmParameterGeneratorTest.java new file mode 100644 index 0000000..80065f3 --- /dev/null +++ b/support/src/test/java/tests/security/AlgorithmParameterGeneratorTest.java @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2009 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package tests.security; + +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTargetNew; +import dalvik.annotation.TestTargets; +import java.security.AlgorithmParameterGenerator; +import java.security.AlgorithmParameters; +import java.security.NoSuchAlgorithmException; +import junit.framework.TestCase; + +public abstract class AlgorithmParameterGeneratorTest extends TestCase { + + private final String algorithmName; + private final TestHelper<AlgorithmParameters> helper; + + protected AlgorithmParameterGeneratorTest(String algorithmName, TestHelper<AlgorithmParameters> helper) { + this.algorithmName = algorithmName; + this.helper = helper; + } + + @TestTargets({ + @TestTargetNew( + level=TestLevel.ADDITIONAL, + method="getInstance", + args={String.class} + ), + @TestTargetNew( + level=TestLevel.ADDITIONAL, + method="init", + args={int.class} + ), + @TestTargetNew( + level=TestLevel.COMPLETE, + method="method", + args={} + ) + }) + public void testAlgorithmParameterGenerator() { + AlgorithmParameterGenerator generator = null; + try { + generator = AlgorithmParameterGenerator.getInstance(algorithmName); + } catch (NoSuchAlgorithmException e) { + fail(e.getMessage()); + } + + generator.init(1024); + + AlgorithmParameters parameters = generator.generateParameters(); + + assertNotNull("generated parameters are null", parameters); + + helper.test(parameters); + } +} diff --git a/support/src/test/java/tests/security/AlgorithmParameterKeyAgreementHelper.java b/support/src/test/java/tests/security/AlgorithmParameterKeyAgreementHelper.java new file mode 100644 index 0000000..870abf9 --- /dev/null +++ b/support/src/test/java/tests/security/AlgorithmParameterKeyAgreementHelper.java @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2009 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package tests.security; + +import java.security.AlgorithmParameters; +import java.security.InvalidKeyException; +import java.security.KeyPair; +import java.security.KeyPairGenerator; +import java.security.NoSuchAlgorithmException; +import javax.crypto.KeyAgreement; +import junit.framework.Assert; + +public class AlgorithmParameterKeyAgreementHelper extends TestHelper<AlgorithmParameters> { + + private final String algorithmName; + + public AlgorithmParameterKeyAgreementHelper(String algorithmName) { + this.algorithmName = algorithmName; + } + + @Override + public void test(AlgorithmParameters parameters) { + + KeyPairGenerator generator = null; + try { + generator = KeyPairGenerator.getInstance(algorithmName); + } catch (NoSuchAlgorithmException e) { + Assert.fail(e.getMessage()); + } + + generator.initialize(1024); + + KeyPair keyPair = generator.generateKeyPair(); + + KeyAgreement keyAgreement = null; + try { + keyAgreement = KeyAgreement.getInstance(algorithmName); + } catch (NoSuchAlgorithmException e) { + Assert.fail(e.getMessage()); + } + + try { + keyAgreement.init(keyPair.getPrivate()); + } catch (InvalidKeyException e) { + Assert.fail(e.getMessage()); + } + try { + keyAgreement.doPhase(keyPair.getPublic(), true); + } catch (InvalidKeyException e) { + Assert.fail(e.getMessage()); + } catch (IllegalStateException e) { + Assert.fail(e.getMessage()); + } + Assert.assertNotNull("generated secret is null", keyAgreement + .generateSecret()); + } +} diff --git a/support/src/test/java/tests/security/AlgorithmParameterSignatureHelper.java b/support/src/test/java/tests/security/AlgorithmParameterSignatureHelper.java new file mode 100644 index 0000000..f132578 --- /dev/null +++ b/support/src/test/java/tests/security/AlgorithmParameterSignatureHelper.java @@ -0,0 +1,114 @@ +/* + * Copyright (C) 2009 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package tests.security; + +import java.security.AlgorithmParameters; +import java.security.InvalidAlgorithmParameterException; +import java.security.InvalidKeyException; +import java.security.KeyPair; +import java.security.KeyPairGenerator; +import java.security.NoSuchAlgorithmException; +import java.security.Signature; +import java.security.SignatureException; +import java.security.spec.AlgorithmParameterSpec; +import java.security.spec.InvalidParameterSpecException; +import junit.framework.Assert; + +public class AlgorithmParameterSignatureHelper<T extends AlgorithmParameterSpec> + extends TestHelper<AlgorithmParameters> { + + private final String algorithmName; + private final String plainData = "some data do sign and verify"; + private final Class<T> parameterSpecClass; + + public AlgorithmParameterSignatureHelper(String algorithmName, Class<T> parameterSpecCla1ss) { + this.algorithmName = algorithmName; + this.parameterSpecClass = parameterSpecCla1ss; + } + + @Override + public void test(AlgorithmParameters parameters) { + + Signature signature = null; + try { + signature = Signature.getInstance(algorithmName); + } catch (NoSuchAlgorithmException e) { + Assert.fail(e.getMessage()); + } + + + T parameterSpec = null; + try { + parameterSpec = parameters.getParameterSpec(parameterSpecClass); + } catch (InvalidParameterSpecException e) { + Assert.fail(e.getMessage()); + } + + KeyPairGenerator generator = null; + try { + generator = KeyPairGenerator.getInstance(algorithmName); + } catch (NoSuchAlgorithmException e) { + Assert.fail(e.getMessage()); + } + + try { + generator.initialize(parameterSpec); + } catch (InvalidAlgorithmParameterException e) { + Assert.fail(e.getMessage()); + } + + KeyPair keyPair = generator.genKeyPair(); + + try { + signature.initSign(keyPair.getPrivate()); + } catch (InvalidKeyException e) { + Assert.fail(e.getMessage()); + } + + try { + signature.update(plainData.getBytes()); + } catch (SignatureException e) { + Assert.fail(e.getMessage()); + } + + byte[] signed = null; + try { + signed = signature.sign(); + } catch (SignatureException e) { + Assert.fail(e.getMessage()); + } + + try { + signature.initVerify(keyPair.getPublic()); + } catch (InvalidKeyException e) { + Assert.fail(e.getMessage()); + } + + try { + signature.update(plainData.getBytes()); + } catch (SignatureException e) { + Assert.fail(e.getMessage()); + } + + try { + Assert.assertTrue("signature could not be verified", signature + .verify(signed)); + } catch (SignatureException e) { + Assert.fail(e.getMessage()); + } + } +} diff --git a/support/src/test/java/tests/security/AlgorithmParameterSymmetricHelper.java b/support/src/test/java/tests/security/AlgorithmParameterSymmetricHelper.java new file mode 100644 index 0000000..86d87ce --- /dev/null +++ b/support/src/test/java/tests/security/AlgorithmParameterSymmetricHelper.java @@ -0,0 +1,114 @@ +/* + * Copyright (C) 2009 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package tests.security; + +import java.security.AlgorithmParameters; +import java.security.InvalidAlgorithmParameterException; +import java.security.InvalidKeyException; +import java.security.Key; +import java.security.NoSuchAlgorithmException; +import java.util.Arrays; +import javax.crypto.BadPaddingException; +import javax.crypto.Cipher; +import javax.crypto.IllegalBlockSizeException; +import javax.crypto.KeyGenerator; +import javax.crypto.NoSuchPaddingException; +import junit.framework.Assert; + +public class AlgorithmParameterSymmetricHelper extends TestHelper<AlgorithmParameters> { + + private static final String plainData = "some data to encrypt and decrypt"; + private final String algorithmName; + private final int keySize; + private String blockmode; + + public AlgorithmParameterSymmetricHelper(String algorithmName, int keySize) { + this.algorithmName = algorithmName; + this.keySize = keySize; + } + + public AlgorithmParameterSymmetricHelper(String algorithmName, String blockmode, int keySize) { + this(algorithmName, keySize); + this.blockmode = blockmode; + } + + @Override + public void test(AlgorithmParameters parameters) { + + KeyGenerator generator = null; + try { + generator = KeyGenerator.getInstance(algorithmName); + } catch (NoSuchAlgorithmException e) { + Assert.fail(e.getMessage()); + } + + generator.init(keySize); + + Key key = generator.generateKey(); + + + Cipher cipher = null; + try { + String transformation = algorithmName; + if (blockmode != null) + { + transformation += "/" + blockmode; + } + cipher = Cipher.getInstance(transformation); + } catch (NoSuchAlgorithmException e) { + Assert.fail(e.getMessage()); + } catch (NoSuchPaddingException e) { + Assert.fail(e.getMessage()); + } + + try { + cipher.init(Cipher.ENCRYPT_MODE, key, parameters); + } catch (InvalidKeyException e) { + Assert.fail(e.getMessage()); + } catch (InvalidAlgorithmParameterException e) { + Assert.fail(e.getMessage()); + } + + byte[] bs = null; + try { + bs = cipher.doFinal(plainData.getBytes()); + } catch (IllegalBlockSizeException e) { + Assert.fail(e.getMessage()); + } catch (BadPaddingException e) { + Assert.fail(e.getMessage()); + } + + try { + cipher.init(Cipher.DECRYPT_MODE, key, parameters); + } catch (InvalidKeyException e) { + Assert.fail(e.getMessage()); + } catch (InvalidAlgorithmParameterException e) { + Assert.fail(e.getMessage()); + } + + byte[] decrypted = null; + try { + decrypted = cipher.doFinal(bs); + } catch (IllegalBlockSizeException e) { + Assert.fail(e.getMessage()); + } catch (BadPaddingException e) { + Assert.fail(e.getMessage()); + } + + Assert.assertTrue(Arrays.equals(plainData.getBytes(), decrypted)); + } +} diff --git a/support/src/test/java/tests/security/AlgorithmParametersTest.java b/support/src/test/java/tests/security/AlgorithmParametersTest.java new file mode 100644 index 0000000..d5c1910 --- /dev/null +++ b/support/src/test/java/tests/security/AlgorithmParametersTest.java @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2009 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package tests.security; + +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTargetNew; +import dalvik.annotation.TestTargets; +import java.security.AlgorithmParameters; +import java.security.NoSuchAlgorithmException; +import java.security.spec.AlgorithmParameterSpec; +import java.security.spec.InvalidParameterSpecException; +import junit.framework.TestCase; + +public class AlgorithmParametersTest extends TestCase { + + private final String algorithmName; + private final TestHelper<AlgorithmParameters> helper; + private final AlgorithmParameterSpec parameterData; + + public AlgorithmParametersTest(String algorithmName, + TestHelper<AlgorithmParameters> helper, AlgorithmParameterSpec parameterData) { + this.algorithmName = algorithmName; + this.helper = helper; + this.parameterData = parameterData; + } + + @TestTargets({ + @TestTargetNew( + level=TestLevel.ADDITIONAL, + method="getInstance", + args={String.class} + ), + @TestTargetNew( + level=TestLevel.ADDITIONAL, + method="init", + args={byte[].class} + ), + @TestTargetNew( + level=TestLevel.COMPLETE, + method="method", + args={} + ) + }) + public void testAlgorithmParameters() { + AlgorithmParameters algorithmParameters = null; + try { + algorithmParameters = AlgorithmParameters + .getInstance(algorithmName); + } catch (NoSuchAlgorithmException e) { + fail(e.getMessage()); + } + + try { + algorithmParameters.init(parameterData); + } catch (InvalidParameterSpecException e) { + fail(e.getMessage()); + } + + helper.test(algorithmParameters); + } +} diff --git a/support/src/test/java/tests/security/CipherAsymmetricCryptHelper.java b/support/src/test/java/tests/security/CipherAsymmetricCryptHelper.java new file mode 100644 index 0000000..fe7c714 --- /dev/null +++ b/support/src/test/java/tests/security/CipherAsymmetricCryptHelper.java @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2009 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package tests.security; + +import java.security.KeyPair; +import javax.crypto.Cipher; + +public class CipherAsymmetricCryptHelper extends CipherHelper<KeyPair> { + + private static final String plainData = "some data to encrypt and decrypt test"; + + public CipherAsymmetricCryptHelper(String algorithmName) { + super(algorithmName, plainData, Cipher.ENCRYPT_MODE, + Cipher.DECRYPT_MODE); + } + + public void test(KeyPair keyPair) { + test(keyPair.getPrivate(), keyPair.getPublic()); + } +} diff --git a/support/src/test/java/tests/security/CipherHelper.java b/support/src/test/java/tests/security/CipherHelper.java new file mode 100644 index 0000000..cb1ba88 --- /dev/null +++ b/support/src/test/java/tests/security/CipherHelper.java @@ -0,0 +1,83 @@ +/* + * Copyright (C) 2009 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package tests.security; + +import java.security.InvalidKeyException; +import java.security.Key; +import java.security.NoSuchAlgorithmException; +import javax.crypto.BadPaddingException; +import javax.crypto.Cipher; +import javax.crypto.IllegalBlockSizeException; +import javax.crypto.NoSuchPaddingException; +import junit.framework.Assert; + +public abstract class CipherHelper<T> extends TestHelper<T> { + + private final String algorithmName; + private final String plainData; + private final int mode1; + private final int mode2; + + public CipherHelper(String algorithmName, String plainData, int mode1, int mode2) { + this.algorithmName = algorithmName; + this.plainData = plainData; + this.mode1 = mode1; + this.mode2 = mode2; + } + + public void test(Key encryptKey, Key decryptKey) { + Cipher cipher = null; + try { + cipher = Cipher.getInstance(algorithmName); + } catch (NoSuchAlgorithmException e) { + Assert.fail(e.getMessage()); + } catch (NoSuchPaddingException e) { + Assert.fail(e.getMessage()); + } + try { + cipher.init(mode1, encryptKey); + } catch (InvalidKeyException e) { + Assert.fail(e.getMessage()); + } + + byte[] encrypted = crypt(cipher, plainData.getBytes()); + + try { + cipher.init(mode2, decryptKey); + } catch (InvalidKeyException e) { + Assert.fail(e.getMessage()); + } + + byte[] decrypted = crypt(cipher, encrypted); + + String decryptedString = new String(decrypted); + + Assert.assertEquals("transformed data does not match", plainData, + decryptedString); + } + + public byte[] crypt(Cipher cipher, byte[] input) { + try { + return cipher.doFinal(input); + } catch (IllegalBlockSizeException e) { + Assert.fail(e.getMessage()); + } catch (BadPaddingException e) { + Assert.fail(e.getMessage()); + } + return null; + } +} diff --git a/support/src/test/java/tests/security/CipherSymmetricCryptHelper.java b/support/src/test/java/tests/security/CipherSymmetricCryptHelper.java new file mode 100644 index 0000000..8b93211 --- /dev/null +++ b/support/src/test/java/tests/security/CipherSymmetricCryptHelper.java @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2009 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package tests.security; + +import javax.crypto.Cipher; +import javax.crypto.SecretKey; + +public class CipherSymmetricCryptHelper extends CipherHelper<SecretKey/*, U*/> { + + private static final String plainData = "some data to encrypt and decrypt test"; + + public CipherSymmetricCryptHelper(String algorithmName) { + super(algorithmName, plainData, Cipher.ENCRYPT_MODE, + Cipher.DECRYPT_MODE); + } + + public void test(SecretKey key) { + test(key, key); + } +} diff --git a/support/src/test/java/tests/security/DefaultKeys.java b/support/src/test/java/tests/security/DefaultKeys.java new file mode 100644 index 0000000..e83efc6 --- /dev/null +++ b/support/src/test/java/tests/security/DefaultKeys.java @@ -0,0 +1,206 @@ +/* + * Copyright (C) 2009 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package tests.security; + +import java.security.KeyFactory; +import java.security.NoSuchAlgorithmException; +import java.security.PrivateKey; +import java.security.PublicKey; +import java.security.spec.InvalidKeySpecException; +import java.security.spec.KeySpec; +import java.security.spec.PKCS8EncodedKeySpec; +import java.security.spec.X509EncodedKeySpec; +import java.util.HashMap; + +public class DefaultKeys { + private static final byte[] RSA_private = new byte[] { + (byte) 0x30, (byte) 0x82, (byte) 0x02, (byte) 0x75, (byte) 0x02, (byte) 0x01, (byte) 0x00, (byte) 0x30, (byte) 0x0D, (byte) 0x06, (byte) 0x09, (byte) 0x2A, (byte) 0x86, (byte) 0x48, (byte) 0x86, (byte) 0xF7, (byte) 0x0D, + (byte) 0x01, (byte) 0x01, (byte) 0x01, (byte) 0x05, (byte) 0x00, (byte) 0x04, (byte) 0x82, (byte) 0x02, (byte) 0x5F, (byte) 0x30, (byte) 0x82, (byte) 0x02, (byte) 0x5B, (byte) 0x02, (byte) 0x01, (byte) 0x00, (byte) 0x02, + (byte) 0x81, (byte) 0x81, (byte) 0x00, (byte) 0x99, (byte) 0xA5, (byte) 0x96, (byte) 0x72, (byte) 0xAE, (byte) 0xBB, (byte) 0x59, (byte) 0x36, (byte) 0xA8, (byte) 0x12, (byte) 0x17, (byte) 0x05, (byte) 0x4C, (byte) 0x63, + (byte) 0x9E, (byte) 0xB8, (byte) 0x85, (byte) 0xD4, (byte) 0x2D, (byte) 0x71, (byte) 0xD7, (byte) 0x29, (byte) 0xB9, (byte) 0x05, (byte) 0x0F, (byte) 0xB4, (byte) 0x57, (byte) 0xFB, (byte) 0xD3, (byte) 0x95, (byte) 0x5C, + (byte) 0x21, (byte) 0xEC, (byte) 0xB5, (byte) 0xEB, (byte) 0x67, (byte) 0xA2, (byte) 0x4F, (byte) 0xC1, (byte) 0x93, (byte) 0xEF, (byte) 0x96, (byte) 0x41, (byte) 0x05, (byte) 0x3D, (byte) 0xC5, (byte) 0x3E, (byte) 0x04, + (byte) 0x4D, (byte) 0xC6, (byte) 0xCF, (byte) 0x32, (byte) 0x7C, (byte) 0x1F, (byte) 0x66, (byte) 0xA3, (byte) 0xC5, (byte) 0x27, (byte) 0x79, (byte) 0xEC, (byte) 0x2E, (byte) 0x67, (byte) 0xFA, (byte) 0x19, (byte) 0x5B, + (byte) 0xE3, (byte) 0xB1, (byte) 0x69, (byte) 0xDA, (byte) 0x63, (byte) 0xBC, (byte) 0xDA, (byte) 0xD3, (byte) 0xBB, (byte) 0xAD, (byte) 0x8C, (byte) 0x38, (byte) 0x7B, (byte) 0x4A, (byte) 0x9C, (byte) 0xD4, (byte) 0x4D, + (byte) 0xD2, (byte) 0x33, (byte) 0xB7, (byte) 0x4E, (byte) 0x04, (byte) 0xB6, (byte) 0xDF, (byte) 0x62, (byte) 0x55, (byte) 0x48, (byte) 0x5C, (byte) 0x94, (byte) 0x02, (byte) 0xF7, (byte) 0x84, (byte) 0xE6, (byte) 0x9B, + (byte) 0x57, (byte) 0xFF, (byte) 0x17, (byte) 0x2A, (byte) 0xA1, (byte) 0x74, (byte) 0x8D, (byte) 0x07, (byte) 0xD8, (byte) 0xCE, (byte) 0xF7, (byte) 0x0B, (byte) 0x59, (byte) 0xFB, (byte) 0x13, (byte) 0x6E, (byte) 0xF1, + (byte) 0xC3, (byte) 0xAB, (byte) 0x3E, (byte) 0x72, (byte) 0x1B, (byte) 0x62, (byte) 0x09, (byte) 0xE8, (byte) 0xD8, (byte) 0x41, (byte) 0x69, (byte) 0xE1, (byte) 0x02, (byte) 0x03, (byte) 0x01, (byte) 0x00, (byte) 0x01, + (byte) 0x02, (byte) 0x81, (byte) 0x80, (byte) 0x57, (byte) 0xD6, (byte) 0x1C, (byte) 0x2E, (byte) 0x2F, (byte) 0xCA, (byte) 0x16, (byte) 0xF4, (byte) 0x72, (byte) 0x1C, (byte) 0xF5, (byte) 0x60, (byte) 0x28, (byte) 0x0D, + (byte) 0x83, (byte) 0x7D, (byte) 0x85, (byte) 0xB4, (byte) 0x88, (byte) 0xCE, (byte) 0x5D, (byte) 0xED, (byte) 0x12, (byte) 0x42, (byte) 0xDC, (byte) 0x79, (byte) 0x83, (byte) 0x1B, (byte) 0x0A, (byte) 0x18, (byte) 0x86, + (byte) 0xF5, (byte) 0x35, (byte) 0xF7, (byte) 0xC2, (byte) 0x3E, (byte) 0x1A, (byte) 0xC2, (byte) 0x71, (byte) 0xAD, (byte) 0xFA, (byte) 0xF7, (byte) 0xF0, (byte) 0xEF, (byte) 0xE8, (byte) 0x22, (byte) 0x4C, (byte) 0x93, + (byte) 0xF5, (byte) 0x4A, (byte) 0xC4, (byte) 0xC4, (byte) 0xDD, (byte) 0xC4, (byte) 0xAD, (byte) 0xCE, (byte) 0xCE, (byte) 0x35, (byte) 0x05, (byte) 0x34, (byte) 0x8A, (byte) 0x4B, (byte) 0x12, (byte) 0xE4, (byte) 0x69, + (byte) 0xE6, (byte) 0xDA, (byte) 0x07, (byte) 0x1A, (byte) 0x77, (byte) 0x5C, (byte) 0xA7, (byte) 0x21, (byte) 0x41, (byte) 0x89, (byte) 0x8C, (byte) 0x95, (byte) 0x6A, (byte) 0x5D, (byte) 0x9C, (byte) 0x3C, (byte) 0xAE, + (byte) 0xC3, (byte) 0xE4, (byte) 0x64, (byte) 0x54, (byte) 0xDA, (byte) 0xFB, (byte) 0xBA, (byte) 0xA6, (byte) 0xE5, (byte) 0x8A, (byte) 0x7F, (byte) 0xFA, (byte) 0x1A, (byte) 0x3F, (byte) 0x9B, (byte) 0xAB, (byte) 0xDA, + (byte) 0x3D, (byte) 0x3B, (byte) 0x43, (byte) 0xF0, (byte) 0x0C, (byte) 0x06, (byte) 0x57, (byte) 0x43, (byte) 0x45, (byte) 0xEE, (byte) 0x8C, (byte) 0x27, (byte) 0x05, (byte) 0xAF, (byte) 0xCD, (byte) 0x5A, (byte) 0x47, + (byte) 0xB9, (byte) 0xEA, (byte) 0xD9, (byte) 0xAA, (byte) 0x66, (byte) 0xDB, (byte) 0xE3, (byte) 0xDC, (byte) 0x54, (byte) 0x47, (byte) 0x60, (byte) 0x01, (byte) 0x02, (byte) 0x41, (byte) 0x00, (byte) 0xED, (byte) 0xE9, + (byte) 0xBD, (byte) 0xD5, (byte) 0x02, (byte) 0x6D, (byte) 0x44, (byte) 0x0E, (byte) 0x3F, (byte) 0x74, (byte) 0x0C, (byte) 0x45, (byte) 0x54, (byte) 0x88, (byte) 0xFE, (byte) 0x5C, (byte) 0xFC, (byte) 0xF2, (byte) 0x31, + (byte) 0x7B, (byte) 0xAF, (byte) 0x15, (byte) 0x77, (byte) 0x7A, (byte) 0xDC, (byte) 0xC6, (byte) 0x9E, (byte) 0x7E, (byte) 0xC1, (byte) 0xCA, (byte) 0x84, (byte) 0xC7, (byte) 0x4B, (byte) 0xC4, (byte) 0x41, (byte) 0xE1, + (byte) 0x85, (byte) 0xE4, (byte) 0x5A, (byte) 0xA7, (byte) 0x3D, (byte) 0x54, (byte) 0x87, (byte) 0x0D, (byte) 0x7A, (byte) 0xC5, (byte) 0x47, (byte) 0x5C, (byte) 0xF2, (byte) 0xAD, (byte) 0x14, (byte) 0x4D, (byte) 0x63, + (byte) 0xB0, (byte) 0xDC, (byte) 0x34, (byte) 0xB5, (byte) 0xDA, (byte) 0x17, (byte) 0x0D, (byte) 0x4E, (byte) 0x2B, (byte) 0x9E, (byte) 0x81, (byte) 0x02, (byte) 0x41, (byte) 0x00, (byte) 0xA5, (byte) 0x53, (byte) 0xDB, + (byte) 0xD8, (byte) 0x28, (byte) 0x57, (byte) 0x65, (byte) 0x2B, (byte) 0xFA, (byte) 0xF2, (byte) 0x21, (byte) 0xB8, (byte) 0x60, (byte) 0xAE, (byte) 0x43, (byte) 0x4B, (byte) 0x51, (byte) 0x85, (byte) 0xCB, (byte) 0xDA, + (byte) 0x89, (byte) 0x5A, (byte) 0x7D, (byte) 0x05, (byte) 0xDA, (byte) 0xFC, (byte) 0xAF, (byte) 0x46, (byte) 0x86, (byte) 0xBC, (byte) 0x3F, (byte) 0xD1, (byte) 0xEA, (byte) 0xA4, (byte) 0x56, (byte) 0xA3, (byte) 0xE6, + (byte) 0xD4, (byte) 0xA2, (byte) 0x08, (byte) 0x93, (byte) 0x63, (byte) 0x21, (byte) 0x0E, (byte) 0xC5, (byte) 0x3C, (byte) 0x97, (byte) 0x7E, (byte) 0x71, (byte) 0x0B, (byte) 0x79, (byte) 0xF8, (byte) 0x60, (byte) 0x73, + (byte) 0xD1, (byte) 0xF9, (byte) 0xD4, (byte) 0x66, (byte) 0x29, (byte) 0x7D, (byte) 0xDC, (byte) 0x22, (byte) 0xDB, (byte) 0x61, (byte) 0x02, (byte) 0x40, (byte) 0x5D, (byte) 0x3D, (byte) 0xEF, (byte) 0x85, (byte) 0x4D, + (byte) 0x27, (byte) 0x2F, (byte) 0xB5, (byte) 0xF9, (byte) 0xCE, (byte) 0x6C, (byte) 0x84, (byte) 0xBB, (byte) 0x85, (byte) 0xD9, (byte) 0x52, (byte) 0xEE, (byte) 0x5B, (byte) 0xA9, (byte) 0x63, (byte) 0x15, (byte) 0x12, + (byte) 0x6F, (byte) 0xBA, (byte) 0x3A, (byte) 0x4E, (byte) 0xA9, (byte) 0x8D, (byte) 0x7A, (byte) 0x3B, (byte) 0xF9, (byte) 0xDF, (byte) 0xF5, (byte) 0xE4, (byte) 0xDC, (byte) 0x01, (byte) 0x1C, (byte) 0x2D, (byte) 0x8C, + (byte) 0x0D, (byte) 0xE1, (byte) 0x6E, (byte) 0x80, (byte) 0x63, (byte) 0x9B, (byte) 0x0B, (byte) 0x38, (byte) 0x55, (byte) 0xC8, (byte) 0x52, (byte) 0x67, (byte) 0x13, (byte) 0x91, (byte) 0x8F, (byte) 0x9E, (byte) 0x2E, + (byte) 0x16, (byte) 0x5B, (byte) 0x7C, (byte) 0x0F, (byte) 0x5D, (byte) 0xE4, (byte) 0xA0, (byte) 0x81, (byte) 0x02, (byte) 0x40, (byte) 0x20, (byte) 0x12, (byte) 0x11, (byte) 0x5E, (byte) 0x70, (byte) 0x0C, (byte) 0xEC, + (byte) 0x02, (byte) 0x49, (byte) 0x0E, (byte) 0xB9, (byte) 0x3D, (byte) 0xD3, (byte) 0xFB, (byte) 0x59, (byte) 0xF0, (byte) 0x7D, (byte) 0x62, (byte) 0xEF, (byte) 0xF5, (byte) 0x77, (byte) 0x99, (byte) 0x87, (byte) 0x11, + (byte) 0x20, (byte) 0xB6, (byte) 0xCD, (byte) 0xA5, (byte) 0x67, (byte) 0xB3, (byte) 0x92, (byte) 0xC9, (byte) 0xBC, (byte) 0xB3, (byte) 0x9E, (byte) 0x5E, (byte) 0xF3, (byte) 0x03, (byte) 0x22, (byte) 0x5F, (byte) 0x79, + (byte) 0x7F, (byte) 0xCC, (byte) 0x44, (byte) 0xDA, (byte) 0x3B, (byte) 0xF3, (byte) 0xC3, (byte) 0x42, (byte) 0x58, (byte) 0x90, (byte) 0x93, (byte) 0x7E, (byte) 0xDA, (byte) 0x58, (byte) 0xCC, (byte) 0x16, (byte) 0xC8, + (byte) 0xAE, (byte) 0x99, (byte) 0xCC, (byte) 0x9F, (byte) 0x32, (byte) 0x61, (byte) 0x02, (byte) 0x40, (byte) 0x02, (byte) 0x29, (byte) 0xDB, (byte) 0x00, (byte) 0x0F, (byte) 0x0A, (byte) 0x17, (byte) 0x33, (byte) 0x7E, + (byte) 0xC5, (byte) 0xEC, (byte) 0x21, (byte) 0x47, (byte) 0x65, (byte) 0xDC, (byte) 0xE5, (byte) 0xC2, (byte) 0x0D, (byte) 0x42, (byte) 0x28, (byte) 0xE1, (byte) 0x17, (byte) 0x1A, (byte) 0x00, (byte) 0xBD, (byte) 0xBE, + (byte) 0x1C, (byte) 0x7D, (byte) 0xCA, (byte) 0x93, (byte) 0x67, (byte) 0x8F, (byte) 0x28, (byte) 0xB7, (byte) 0x60, (byte) 0x8E, (byte) 0xF0, (byte) 0x5D, (byte) 0xCD, (byte) 0xFA, (byte) 0xDD, (byte) 0x6B, (byte) 0x72, + (byte) 0xF7, (byte) 0x48, (byte) 0xD9, (byte) 0x3C, (byte) 0x40, (byte) 0x7C, (byte) 0xB0, (byte) 0xD7, (byte) 0x58, (byte) 0xC2, (byte) 0x53, (byte) 0xAD, (byte) 0x04, (byte) 0xF6, (byte) 0x0B, (byte) 0x35, (byte) 0x51, + (byte) 0x45, (byte) 0xB9, (byte) 0x4F, (byte) 0x49 }; + private static final byte[] RSA_public = new byte[] { + (byte) 0x30, (byte) 0x81, (byte) 0x9F, (byte) 0x30, (byte) 0x0D, (byte) 0x06, (byte) 0x09, (byte) 0x2A, (byte) 0x86, (byte) 0x48, (byte) 0x86, (byte) 0xF7, (byte) 0x0D, (byte) 0x01, (byte) 0x01, (byte) 0x01, (byte) 0x05, + (byte) 0x00, (byte) 0x03, (byte) 0x81, (byte) 0x8D, (byte) 0x00, (byte) 0x30, (byte) 0x81, (byte) 0x89, (byte) 0x02, (byte) 0x81, (byte) 0x81, (byte) 0x00, (byte) 0x99, (byte) 0xA5, (byte) 0x96, (byte) 0x72, (byte) 0xAE, + (byte) 0xBB, (byte) 0x59, (byte) 0x36, (byte) 0xA8, (byte) 0x12, (byte) 0x17, (byte) 0x05, (byte) 0x4C, (byte) 0x63, (byte) 0x9E, (byte) 0xB8, (byte) 0x85, (byte) 0xD4, (byte) 0x2D, (byte) 0x71, (byte) 0xD7, (byte) 0x29, + (byte) 0xB9, (byte) 0x05, (byte) 0x0F, (byte) 0xB4, (byte) 0x57, (byte) 0xFB, (byte) 0xD3, (byte) 0x95, (byte) 0x5C, (byte) 0x21, (byte) 0xEC, (byte) 0xB5, (byte) 0xEB, (byte) 0x67, (byte) 0xA2, (byte) 0x4F, (byte) 0xC1, + (byte) 0x93, (byte) 0xEF, (byte) 0x96, (byte) 0x41, (byte) 0x05, (byte) 0x3D, (byte) 0xC5, (byte) 0x3E, (byte) 0x04, (byte) 0x4D, (byte) 0xC6, (byte) 0xCF, (byte) 0x32, (byte) 0x7C, (byte) 0x1F, (byte) 0x66, (byte) 0xA3, + (byte) 0xC5, (byte) 0x27, (byte) 0x79, (byte) 0xEC, (byte) 0x2E, (byte) 0x67, (byte) 0xFA, (byte) 0x19, (byte) 0x5B, (byte) 0xE3, (byte) 0xB1, (byte) 0x69, (byte) 0xDA, (byte) 0x63, (byte) 0xBC, (byte) 0xDA, (byte) 0xD3, + (byte) 0xBB, (byte) 0xAD, (byte) 0x8C, (byte) 0x38, (byte) 0x7B, (byte) 0x4A, (byte) 0x9C, (byte) 0xD4, (byte) 0x4D, (byte) 0xD2, (byte) 0x33, (byte) 0xB7, (byte) 0x4E, (byte) 0x04, (byte) 0xB6, (byte) 0xDF, (byte) 0x62, + (byte) 0x55, (byte) 0x48, (byte) 0x5C, (byte) 0x94, (byte) 0x02, (byte) 0xF7, (byte) 0x84, (byte) 0xE6, (byte) 0x9B, (byte) 0x57, (byte) 0xFF, (byte) 0x17, (byte) 0x2A, (byte) 0xA1, (byte) 0x74, (byte) 0x8D, (byte) 0x07, + (byte) 0xD8, (byte) 0xCE, (byte) 0xF7, (byte) 0x0B, (byte) 0x59, (byte) 0xFB, (byte) 0x13, (byte) 0x6E, (byte) 0xF1, (byte) 0xC3, (byte) 0xAB, (byte) 0x3E, (byte) 0x72, (byte) 0x1B, (byte) 0x62, (byte) 0x09, (byte) 0xE8, + (byte) 0xD8, (byte) 0x41, (byte) 0x69, (byte) 0xE1, (byte) 0x02, (byte) 0x03, (byte) 0x01, (byte) 0x00, (byte) 0x01 }; + private static final byte[] DSA_private = new byte[] { + (byte) 0x30, (byte) 0x82, (byte) 0x01, (byte) 0x4B, (byte) 0x02, (byte) 0x01, (byte) 0x00, (byte) 0x30, (byte) 0x82, (byte) 0x01, (byte) 0x2C, (byte) 0x06, (byte) 0x07, (byte) 0x2A, (byte) 0x86, (byte) 0x48, (byte) 0xCE, + (byte) 0x38, (byte) 0x04, (byte) 0x01, (byte) 0x30, (byte) 0x82, (byte) 0x01, (byte) 0x1F, (byte) 0x02, (byte) 0x81, (byte) 0x81, (byte) 0x00, (byte) 0xFD, (byte) 0x7F, (byte) 0x53, (byte) 0x81, (byte) 0x1D, (byte) 0x75, + (byte) 0x12, (byte) 0x29, (byte) 0x52, (byte) 0xDF, (byte) 0x4A, (byte) 0x9C, (byte) 0x2E, (byte) 0xEC, (byte) 0xE4, (byte) 0xE7, (byte) 0xF6, (byte) 0x11, (byte) 0xB7, (byte) 0x52, (byte) 0x3C, (byte) 0xEF, (byte) 0x44, + (byte) 0x00, (byte) 0xC3, (byte) 0x1E, (byte) 0x3F, (byte) 0x80, (byte) 0xB6, (byte) 0x51, (byte) 0x26, (byte) 0x69, (byte) 0x45, (byte) 0x5D, (byte) 0x40, (byte) 0x22, (byte) 0x51, (byte) 0xFB, (byte) 0x59, (byte) 0x3D, + (byte) 0x8D, (byte) 0x58, (byte) 0xFA, (byte) 0xBF, (byte) 0xC5, (byte) 0xF5, (byte) 0xBA, (byte) 0x30, (byte) 0xF6, (byte) 0xCB, (byte) 0x9B, (byte) 0x55, (byte) 0x6C, (byte) 0xD7, (byte) 0x81, (byte) 0x3B, (byte) 0x80, + (byte) 0x1D, (byte) 0x34, (byte) 0x6F, (byte) 0xF2, (byte) 0x66, (byte) 0x60, (byte) 0xB7, (byte) 0x6B, (byte) 0x99, (byte) 0x50, (byte) 0xA5, (byte) 0xA4, (byte) 0x9F, (byte) 0x9F, (byte) 0xE8, (byte) 0x04, (byte) 0x7B, + (byte) 0x10, (byte) 0x22, (byte) 0xC2, (byte) 0x4F, (byte) 0xBB, (byte) 0xA9, (byte) 0xD7, (byte) 0xFE, (byte) 0xB7, (byte) 0xC6, (byte) 0x1B, (byte) 0xF8, (byte) 0x3B, (byte) 0x57, (byte) 0xE7, (byte) 0xC6, (byte) 0xA8, + (byte) 0xA6, (byte) 0x15, (byte) 0x0F, (byte) 0x04, (byte) 0xFB, (byte) 0x83, (byte) 0xF6, (byte) 0xD3, (byte) 0xC5, (byte) 0x1E, (byte) 0xC3, (byte) 0x02, (byte) 0x35, (byte) 0x54, (byte) 0x13, (byte) 0x5A, (byte) 0x16, + (byte) 0x91, (byte) 0x32, (byte) 0xF6, (byte) 0x75, (byte) 0xF3, (byte) 0xAE, (byte) 0x2B, (byte) 0x61, (byte) 0xD7, (byte) 0x2A, (byte) 0xEF, (byte) 0xF2, (byte) 0x22, (byte) 0x03, (byte) 0x19, (byte) 0x9D, (byte) 0xD1, + (byte) 0x48, (byte) 0x01, (byte) 0xC7, (byte) 0x02, (byte) 0x15, (byte) 0x00, (byte) 0x97, (byte) 0x60, (byte) 0x50, (byte) 0x8F, (byte) 0x15, (byte) 0x23, (byte) 0x0B, (byte) 0xCC, (byte) 0xB2, (byte) 0x92, (byte) 0xB9, + (byte) 0x82, (byte) 0xA2, (byte) 0xEB, (byte) 0x84, (byte) 0x0B, (byte) 0xF0, (byte) 0x58, (byte) 0x1C, (byte) 0xF5, (byte) 0x02, (byte) 0x81, (byte) 0x81, (byte) 0x00, (byte) 0xF7, (byte) 0xE1, (byte) 0xA0, (byte) 0x85, + (byte) 0xD6, (byte) 0x9B, (byte) 0x3D, (byte) 0xDE, (byte) 0xCB, (byte) 0xBC, (byte) 0xAB, (byte) 0x5C, (byte) 0x36, (byte) 0xB8, (byte) 0x57, (byte) 0xB9, (byte) 0x79, (byte) 0x94, (byte) 0xAF, (byte) 0xBB, (byte) 0xFA, + (byte) 0x3A, (byte) 0xEA, (byte) 0x82, (byte) 0xF9, (byte) 0x57, (byte) 0x4C, (byte) 0x0B, (byte) 0x3D, (byte) 0x07, (byte) 0x82, (byte) 0x67, (byte) 0x51, (byte) 0x59, (byte) 0x57, (byte) 0x8E, (byte) 0xBA, (byte) 0xD4, + (byte) 0x59, (byte) 0x4F, (byte) 0xE6, (byte) 0x71, (byte) 0x07, (byte) 0x10, (byte) 0x81, (byte) 0x80, (byte) 0xB4, (byte) 0x49, (byte) 0x16, (byte) 0x71, (byte) 0x23, (byte) 0xE8, (byte) 0x4C, (byte) 0x28, (byte) 0x16, + (byte) 0x13, (byte) 0xB7, (byte) 0xCF, (byte) 0x09, (byte) 0x32, (byte) 0x8C, (byte) 0xC8, (byte) 0xA6, (byte) 0xE1, (byte) 0x3C, (byte) 0x16, (byte) 0x7A, (byte) 0x8B, (byte) 0x54, (byte) 0x7C, (byte) 0x8D, (byte) 0x28, + (byte) 0xE0, (byte) 0xA3, (byte) 0xAE, (byte) 0x1E, (byte) 0x2B, (byte) 0xB3, (byte) 0xA6, (byte) 0x75, (byte) 0x91, (byte) 0x6E, (byte) 0xA3, (byte) 0x7F, (byte) 0x0B, (byte) 0xFA, (byte) 0x21, (byte) 0x35, (byte) 0x62, + (byte) 0xF1, (byte) 0xFB, (byte) 0x62, (byte) 0x7A, (byte) 0x01, (byte) 0x24, (byte) 0x3B, (byte) 0xCC, (byte) 0xA4, (byte) 0xF1, (byte) 0xBE, (byte) 0xA8, (byte) 0x51, (byte) 0x90, (byte) 0x89, (byte) 0xA8, (byte) 0x83, + (byte) 0xDF, (byte) 0xE1, (byte) 0x5A, (byte) 0xE5, (byte) 0x9F, (byte) 0x06, (byte) 0x92, (byte) 0x8B, (byte) 0x66, (byte) 0x5E, (byte) 0x80, (byte) 0x7B, (byte) 0x55, (byte) 0x25, (byte) 0x64, (byte) 0x01, (byte) 0x4C, + (byte) 0x3B, (byte) 0xFE, (byte) 0xCF, (byte) 0x49, (byte) 0x2A, (byte) 0x04, (byte) 0x16, (byte) 0x02, (byte) 0x14, (byte) 0x0E, (byte) 0x90, (byte) 0xB7, (byte) 0x92, (byte) 0x01, (byte) 0x98, (byte) 0xCD, (byte) 0x85, + (byte) 0x87, (byte) 0x77, (byte) 0x2F, (byte) 0xB4, (byte) 0x31, (byte) 0xFD, (byte) 0xDE, (byte) 0xFA, (byte) 0x08, (byte) 0x6D, (byte) 0x0C, (byte) 0xE3 }; + private static final byte[] DSA_public = new byte[] { + (byte) 0x30, (byte) 0x82, (byte) 0x01, (byte) 0xB8, (byte) 0x30, (byte) 0x82, (byte) 0x01, (byte) 0x2C, (byte) 0x06, (byte) 0x07, (byte) 0x2A, (byte) 0x86, (byte) 0x48, (byte) 0xCE, (byte) 0x38, (byte) 0x04, (byte) 0x01, + (byte) 0x30, (byte) 0x82, (byte) 0x01, (byte) 0x1F, (byte) 0x02, (byte) 0x81, (byte) 0x81, (byte) 0x00, (byte) 0xFD, (byte) 0x7F, (byte) 0x53, (byte) 0x81, (byte) 0x1D, (byte) 0x75, (byte) 0x12, (byte) 0x29, (byte) 0x52, + (byte) 0xDF, (byte) 0x4A, (byte) 0x9C, (byte) 0x2E, (byte) 0xEC, (byte) 0xE4, (byte) 0xE7, (byte) 0xF6, (byte) 0x11, (byte) 0xB7, (byte) 0x52, (byte) 0x3C, (byte) 0xEF, (byte) 0x44, (byte) 0x00, (byte) 0xC3, (byte) 0x1E, + (byte) 0x3F, (byte) 0x80, (byte) 0xB6, (byte) 0x51, (byte) 0x26, (byte) 0x69, (byte) 0x45, (byte) 0x5D, (byte) 0x40, (byte) 0x22, (byte) 0x51, (byte) 0xFB, (byte) 0x59, (byte) 0x3D, (byte) 0x8D, (byte) 0x58, (byte) 0xFA, + (byte) 0xBF, (byte) 0xC5, (byte) 0xF5, (byte) 0xBA, (byte) 0x30, (byte) 0xF6, (byte) 0xCB, (byte) 0x9B, (byte) 0x55, (byte) 0x6C, (byte) 0xD7, (byte) 0x81, (byte) 0x3B, (byte) 0x80, (byte) 0x1D, (byte) 0x34, (byte) 0x6F, + (byte) 0xF2, (byte) 0x66, (byte) 0x60, (byte) 0xB7, (byte) 0x6B, (byte) 0x99, (byte) 0x50, (byte) 0xA5, (byte) 0xA4, (byte) 0x9F, (byte) 0x9F, (byte) 0xE8, (byte) 0x04, (byte) 0x7B, (byte) 0x10, (byte) 0x22, (byte) 0xC2, + (byte) 0x4F, (byte) 0xBB, (byte) 0xA9, (byte) 0xD7, (byte) 0xFE, (byte) 0xB7, (byte) 0xC6, (byte) 0x1B, (byte) 0xF8, (byte) 0x3B, (byte) 0x57, (byte) 0xE7, (byte) 0xC6, (byte) 0xA8, (byte) 0xA6, (byte) 0x15, (byte) 0x0F, + (byte) 0x04, (byte) 0xFB, (byte) 0x83, (byte) 0xF6, (byte) 0xD3, (byte) 0xC5, (byte) 0x1E, (byte) 0xC3, (byte) 0x02, (byte) 0x35, (byte) 0x54, (byte) 0x13, (byte) 0x5A, (byte) 0x16, (byte) 0x91, (byte) 0x32, (byte) 0xF6, + (byte) 0x75, (byte) 0xF3, (byte) 0xAE, (byte) 0x2B, (byte) 0x61, (byte) 0xD7, (byte) 0x2A, (byte) 0xEF, (byte) 0xF2, (byte) 0x22, (byte) 0x03, (byte) 0x19, (byte) 0x9D, (byte) 0xD1, (byte) 0x48, (byte) 0x01, (byte) 0xC7, + (byte) 0x02, (byte) 0x15, (byte) 0x00, (byte) 0x97, (byte) 0x60, (byte) 0x50, (byte) 0x8F, (byte) 0x15, (byte) 0x23, (byte) 0x0B, (byte) 0xCC, (byte) 0xB2, (byte) 0x92, (byte) 0xB9, (byte) 0x82, (byte) 0xA2, (byte) 0xEB, + (byte) 0x84, (byte) 0x0B, (byte) 0xF0, (byte) 0x58, (byte) 0x1C, (byte) 0xF5, (byte) 0x02, (byte) 0x81, (byte) 0x81, (byte) 0x00, (byte) 0xF7, (byte) 0xE1, (byte) 0xA0, (byte) 0x85, (byte) 0xD6, (byte) 0x9B, (byte) 0x3D, + (byte) 0xDE, (byte) 0xCB, (byte) 0xBC, (byte) 0xAB, (byte) 0x5C, (byte) 0x36, (byte) 0xB8, (byte) 0x57, (byte) 0xB9, (byte) 0x79, (byte) 0x94, (byte) 0xAF, (byte) 0xBB, (byte) 0xFA, (byte) 0x3A, (byte) 0xEA, (byte) 0x82, + (byte) 0xF9, (byte) 0x57, (byte) 0x4C, (byte) 0x0B, (byte) 0x3D, (byte) 0x07, (byte) 0x82, (byte) 0x67, (byte) 0x51, (byte) 0x59, (byte) 0x57, (byte) 0x8E, (byte) 0xBA, (byte) 0xD4, (byte) 0x59, (byte) 0x4F, (byte) 0xE6, + (byte) 0x71, (byte) 0x07, (byte) 0x10, (byte) 0x81, (byte) 0x80, (byte) 0xB4, (byte) 0x49, (byte) 0x16, (byte) 0x71, (byte) 0x23, (byte) 0xE8, (byte) 0x4C, (byte) 0x28, (byte) 0x16, (byte) 0x13, (byte) 0xB7, (byte) 0xCF, + (byte) 0x09, (byte) 0x32, (byte) 0x8C, (byte) 0xC8, (byte) 0xA6, (byte) 0xE1, (byte) 0x3C, (byte) 0x16, (byte) 0x7A, (byte) 0x8B, (byte) 0x54, (byte) 0x7C, (byte) 0x8D, (byte) 0x28, (byte) 0xE0, (byte) 0xA3, (byte) 0xAE, + (byte) 0x1E, (byte) 0x2B, (byte) 0xB3, (byte) 0xA6, (byte) 0x75, (byte) 0x91, (byte) 0x6E, (byte) 0xA3, (byte) 0x7F, (byte) 0x0B, (byte) 0xFA, (byte) 0x21, (byte) 0x35, (byte) 0x62, (byte) 0xF1, (byte) 0xFB, (byte) 0x62, + (byte) 0x7A, (byte) 0x01, (byte) 0x24, (byte) 0x3B, (byte) 0xCC, (byte) 0xA4, (byte) 0xF1, (byte) 0xBE, (byte) 0xA8, (byte) 0x51, (byte) 0x90, (byte) 0x89, (byte) 0xA8, (byte) 0x83, (byte) 0xDF, (byte) 0xE1, (byte) 0x5A, + (byte) 0xE5, (byte) 0x9F, (byte) 0x06, (byte) 0x92, (byte) 0x8B, (byte) 0x66, (byte) 0x5E, (byte) 0x80, (byte) 0x7B, (byte) 0x55, (byte) 0x25, (byte) 0x64, (byte) 0x01, (byte) 0x4C, (byte) 0x3B, (byte) 0xFE, (byte) 0xCF, + (byte) 0x49, (byte) 0x2A, (byte) 0x03, (byte) 0x81, (byte) 0x85, (byte) 0x00, (byte) 0x02, (byte) 0x81, (byte) 0x81, (byte) 0x00, (byte) 0x98, (byte) 0x33, (byte) 0x90, (byte) 0x14, (byte) 0x79, (byte) 0xC7, (byte) 0xC8, + (byte) 0x57, (byte) 0xE1, (byte) 0x82, (byte) 0x53, (byte) 0x5B, (byte) 0x6E, (byte) 0x01, (byte) 0x07, (byte) 0x1E, (byte) 0xA5, (byte) 0x98, (byte) 0xC4, (byte) 0x57, (byte) 0x5D, (byte) 0x23, (byte) 0xAB, (byte) 0x72, + (byte) 0x9A, (byte) 0xB3, (byte) 0x2F, (byte) 0x39, (byte) 0xCB, (byte) 0xC5, (byte) 0xD0, (byte) 0x97, (byte) 0xD5, (byte) 0x62, (byte) 0x8C, (byte) 0xD9, (byte) 0xE6, (byte) 0xE2, (byte) 0x05, (byte) 0xC6, (byte) 0x05, + (byte) 0x71, (byte) 0x16, (byte) 0xE3, (byte) 0xE8, (byte) 0x04, (byte) 0xE8, (byte) 0x46, (byte) 0x12, (byte) 0x0C, (byte) 0xF8, (byte) 0xFC, (byte) 0x8E, (byte) 0x15, (byte) 0x26, (byte) 0x32, (byte) 0xF7, (byte) 0x8C, + (byte) 0x04, (byte) 0x3B, (byte) 0x53, (byte) 0x68, (byte) 0x9A, (byte) 0xA3, (byte) 0xB7, (byte) 0x4D, (byte) 0x13, (byte) 0x40, (byte) 0x0F, (byte) 0xBE, (byte) 0x03, (byte) 0x87, (byte) 0xD8, (byte) 0xF1, (byte) 0xFE, + (byte) 0x4B, (byte) 0xF5, (byte) 0x44, (byte) 0x19, (byte) 0x29, (byte) 0xBB, (byte) 0x0D, (byte) 0x0C, (byte) 0x52, (byte) 0xC6, (byte) 0x84, (byte) 0x33, (byte) 0x62, (byte) 0x73, (byte) 0x5D, (byte) 0x03, (byte) 0xFF, + (byte) 0x6F, (byte) 0x0A, (byte) 0x5A, (byte) 0xF3, (byte) 0x9E, (byte) 0x52, (byte) 0xF2, (byte) 0xC2, (byte) 0xC8, (byte) 0x00, (byte) 0x52, (byte) 0xC7, (byte) 0x75, (byte) 0xA4, (byte) 0xFD, (byte) 0x71, (byte) 0x2D, + (byte) 0x7B, (byte) 0x7A, (byte) 0x31, (byte) 0x27, (byte) 0x6E, (byte) 0xAC, (byte) 0xB6, (byte) 0x40, (byte) 0x14, (byte) 0x4E, (byte) 0xB4, (byte) 0xBB, (byte) 0xB1, (byte) 0x51, (byte) 0x63, (byte) 0x29, (byte) 0x81, + (byte) 0x06, (byte) 0xF9 }; + private static final byte[] DH_private = new byte[] { + (byte) 0x30, (byte) 0x82, (byte) 0x01, (byte) 0xA8, (byte) 0x02, (byte) 0x01, (byte) 0x00, (byte) 0x30, (byte) 0x82, (byte) 0x01, (byte) 0x1B, (byte) 0x06, (byte) 0x09, (byte) 0x2A, (byte) 0x86, (byte) 0x48, (byte) 0x86, + (byte) 0xF7, (byte) 0x0D, (byte) 0x01, (byte) 0x03, (byte) 0x01, (byte) 0x30, (byte) 0x82, (byte) 0x01, (byte) 0x0C, (byte) 0x02, (byte) 0x81, (byte) 0x81, (byte) 0x00, (byte) 0xFD, (byte) 0x7F, (byte) 0x53, (byte) 0x81, + (byte) 0x1D, (byte) 0x75, (byte) 0x12, (byte) 0x29, (byte) 0x52, (byte) 0xDF, (byte) 0x4A, (byte) 0x9C, (byte) 0x2E, (byte) 0xEC, (byte) 0xE4, (byte) 0xE7, (byte) 0xF6, (byte) 0x11, (byte) 0xB7, (byte) 0x52, (byte) 0x3C, + (byte) 0xEF, (byte) 0x44, (byte) 0x00, (byte) 0xC3, (byte) 0x1E, (byte) 0x3F, (byte) 0x80, (byte) 0xB6, (byte) 0x51, (byte) 0x26, (byte) 0x69, (byte) 0x45, (byte) 0x5D, (byte) 0x40, (byte) 0x22, (byte) 0x51, (byte) 0xFB, + (byte) 0x59, (byte) 0x3D, (byte) 0x8D, (byte) 0x58, (byte) 0xFA, (byte) 0xBF, (byte) 0xC5, (byte) 0xF5, (byte) 0xBA, (byte) 0x30, (byte) 0xF6, (byte) 0xCB, (byte) 0x9B, (byte) 0x55, (byte) 0x6C, (byte) 0xD7, (byte) 0x81, + (byte) 0x3B, (byte) 0x80, (byte) 0x1D, (byte) 0x34, (byte) 0x6F, (byte) 0xF2, (byte) 0x66, (byte) 0x60, (byte) 0xB7, (byte) 0x6B, (byte) 0x99, (byte) 0x50, (byte) 0xA5, (byte) 0xA4, (byte) 0x9F, (byte) 0x9F, (byte) 0xE8, + (byte) 0x04, (byte) 0x7B, (byte) 0x10, (byte) 0x22, (byte) 0xC2, (byte) 0x4F, (byte) 0xBB, (byte) 0xA9, (byte) 0xD7, (byte) 0xFE, (byte) 0xB7, (byte) 0xC6, (byte) 0x1B, (byte) 0xF8, (byte) 0x3B, (byte) 0x57, (byte) 0xE7, + (byte) 0xC6, (byte) 0xA8, (byte) 0xA6, (byte) 0x15, (byte) 0x0F, (byte) 0x04, (byte) 0xFB, (byte) 0x83, (byte) 0xF6, (byte) 0xD3, (byte) 0xC5, (byte) 0x1E, (byte) 0xC3, (byte) 0x02, (byte) 0x35, (byte) 0x54, (byte) 0x13, + (byte) 0x5A, (byte) 0x16, (byte) 0x91, (byte) 0x32, (byte) 0xF6, (byte) 0x75, (byte) 0xF3, (byte) 0xAE, (byte) 0x2B, (byte) 0x61, (byte) 0xD7, (byte) 0x2A, (byte) 0xEF, (byte) 0xF2, (byte) 0x22, (byte) 0x03, (byte) 0x19, + (byte) 0x9D, (byte) 0xD1, (byte) 0x48, (byte) 0x01, (byte) 0xC7, (byte) 0x02, (byte) 0x81, (byte) 0x81, (byte) 0x00, (byte) 0xF7, (byte) 0xE1, (byte) 0xA0, (byte) 0x85, (byte) 0xD6, (byte) 0x9B, (byte) 0x3D, (byte) 0xDE, + (byte) 0xCB, (byte) 0xBC, (byte) 0xAB, (byte) 0x5C, (byte) 0x36, (byte) 0xB8, (byte) 0x57, (byte) 0xB9, (byte) 0x79, (byte) 0x94, (byte) 0xAF, (byte) 0xBB, (byte) 0xFA, (byte) 0x3A, (byte) 0xEA, (byte) 0x82, (byte) 0xF9, + (byte) 0x57, (byte) 0x4C, (byte) 0x0B, (byte) 0x3D, (byte) 0x07, (byte) 0x82, (byte) 0x67, (byte) 0x51, (byte) 0x59, (byte) 0x57, (byte) 0x8E, (byte) 0xBA, (byte) 0xD4, (byte) 0x59, (byte) 0x4F, (byte) 0xE6, (byte) 0x71, + (byte) 0x07, (byte) 0x10, (byte) 0x81, (byte) 0x80, (byte) 0xB4, (byte) 0x49, (byte) 0x16, (byte) 0x71, (byte) 0x23, (byte) 0xE8, (byte) 0x4C, (byte) 0x28, (byte) 0x16, (byte) 0x13, (byte) 0xB7, (byte) 0xCF, (byte) 0x09, + (byte) 0x32, (byte) 0x8C, (byte) 0xC8, (byte) 0xA6, (byte) 0xE1, (byte) 0x3C, (byte) 0x16, (byte) 0x7A, (byte) 0x8B, (byte) 0x54, (byte) 0x7C, (byte) 0x8D, (byte) 0x28, (byte) 0xE0, (byte) 0xA3, (byte) 0xAE, (byte) 0x1E, + (byte) 0x2B, (byte) 0xB3, (byte) 0xA6, (byte) 0x75, (byte) 0x91, (byte) 0x6E, (byte) 0xA3, (byte) 0x7F, (byte) 0x0B, (byte) 0xFA, (byte) 0x21, (byte) 0x35, (byte) 0x62, (byte) 0xF1, (byte) 0xFB, (byte) 0x62, (byte) 0x7A, + (byte) 0x01, (byte) 0x24, (byte) 0x3B, (byte) 0xCC, (byte) 0xA4, (byte) 0xF1, (byte) 0xBE, (byte) 0xA8, (byte) 0x51, (byte) 0x90, (byte) 0x89, (byte) 0xA8, (byte) 0x83, (byte) 0xDF, (byte) 0xE1, (byte) 0x5A, (byte) 0xE5, + (byte) 0x9F, (byte) 0x06, (byte) 0x92, (byte) 0x8B, (byte) 0x66, (byte) 0x5E, (byte) 0x80, (byte) 0x7B, (byte) 0x55, (byte) 0x25, (byte) 0x64, (byte) 0x01, (byte) 0x4C, (byte) 0x3B, (byte) 0xFE, (byte) 0xCF, (byte) 0x49, + (byte) 0x2A, (byte) 0x02, (byte) 0x02, (byte) 0x03, (byte) 0xFE, (byte) 0x04, (byte) 0x81, (byte) 0x83, (byte) 0x02, (byte) 0x81, (byte) 0x80, (byte) 0x35, (byte) 0xFE, (byte) 0x44, (byte) 0x0A, (byte) 0xA3, (byte) 0xA0, + (byte) 0xCB, (byte) 0x52, (byte) 0xC2, (byte) 0x32, (byte) 0xCA, (byte) 0x38, (byte) 0x1F, (byte) 0x18, (byte) 0xEB, (byte) 0x27, (byte) 0x6E, (byte) 0x77, (byte) 0x25, (byte) 0x40, (byte) 0x1F, (byte) 0x64, (byte) 0x5D, + (byte) 0x4B, (byte) 0x59, (byte) 0x41, (byte) 0xB6, (byte) 0xCB, (byte) 0xDF, (byte) 0x73, (byte) 0xE0, (byte) 0x01, (byte) 0x5A, (byte) 0x79, (byte) 0x0D, (byte) 0x8D, (byte) 0x08, (byte) 0xE6, (byte) 0x7F, (byte) 0x86, + (byte) 0x58, (byte) 0xCF, (byte) 0x7F, (byte) 0x4B, (byte) 0x2E, (byte) 0xDB, (byte) 0x4C, (byte) 0xDF, (byte) 0x75, (byte) 0xB5, (byte) 0x16, (byte) 0xC4, (byte) 0xA9, (byte) 0x49, (byte) 0xEE, (byte) 0x00, (byte) 0x56, + (byte) 0xA0, (byte) 0x60, (byte) 0x08, (byte) 0x8E, (byte) 0x0D, (byte) 0xC7, (byte) 0xC9, (byte) 0x45, (byte) 0x0C, (byte) 0x5D, (byte) 0xB7, (byte) 0x4C, (byte) 0xC4, (byte) 0x7E, (byte) 0xAB, (byte) 0x1F, (byte) 0xEA, + (byte) 0xCF, (byte) 0x08, (byte) 0x6D, (byte) 0x05, (byte) 0xA1, (byte) 0x7F, (byte) 0x63, (byte) 0x6F, (byte) 0xB3, (byte) 0x91, (byte) 0xA3, (byte) 0xE1, (byte) 0xB0, (byte) 0x36, (byte) 0x02, (byte) 0x3F, (byte) 0x55, + (byte) 0x71, (byte) 0x38, (byte) 0x37, (byte) 0x9A, (byte) 0x19, (byte) 0xA3, (byte) 0xAF, (byte) 0xC8, (byte) 0xD5, (byte) 0x22, (byte) 0xDD, (byte) 0x00, (byte) 0x81, (byte) 0x19, (byte) 0xB6, (byte) 0x3C, (byte) 0x5F, + (byte) 0xD9, (byte) 0xDF, (byte) 0xFD, (byte) 0x58, (byte) 0xB1, (byte) 0xE6, (byte) 0xD1, (byte) 0xD2, (byte) 0x58, (byte) 0xEF, (byte) 0x44, (byte) 0x6E, (byte) 0x66, (byte) 0x92, (byte) 0x1E, (byte) 0x30, (byte) 0x0B, + (byte) 0x90, (byte) 0x8E, (byte) 0x29 }; + private static final byte[] DH_public = new byte[] { + (byte) 0x30, (byte) 0x82, (byte) 0x01, (byte) 0xA7, (byte) 0x30, (byte) 0x82, (byte) 0x01, (byte) 0x1B, (byte) 0x06, (byte) 0x09, (byte) 0x2A, (byte) 0x86, (byte) 0x48, (byte) 0x86, (byte) 0xF7, (byte) 0x0D, (byte) 0x01, + (byte) 0x03, (byte) 0x01, (byte) 0x30, (byte) 0x82, (byte) 0x01, (byte) 0x0C, (byte) 0x02, (byte) 0x81, (byte) 0x81, (byte) 0x00, (byte) 0xFD, (byte) 0x7F, (byte) 0x53, (byte) 0x81, (byte) 0x1D, (byte) 0x75, (byte) 0x12, + (byte) 0x29, (byte) 0x52, (byte) 0xDF, (byte) 0x4A, (byte) 0x9C, (byte) 0x2E, (byte) 0xEC, (byte) 0xE4, (byte) 0xE7, (byte) 0xF6, (byte) 0x11, (byte) 0xB7, (byte) 0x52, (byte) 0x3C, (byte) 0xEF, (byte) 0x44, (byte) 0x00, + (byte) 0xC3, (byte) 0x1E, (byte) 0x3F, (byte) 0x80, (byte) 0xB6, (byte) 0x51, (byte) 0x26, (byte) 0x69, (byte) 0x45, (byte) 0x5D, (byte) 0x40, (byte) 0x22, (byte) 0x51, (byte) 0xFB, (byte) 0x59, (byte) 0x3D, (byte) 0x8D, + (byte) 0x58, (byte) 0xFA, (byte) 0xBF, (byte) 0xC5, (byte) 0xF5, (byte) 0xBA, (byte) 0x30, (byte) 0xF6, (byte) 0xCB, (byte) 0x9B, (byte) 0x55, (byte) 0x6C, (byte) 0xD7, (byte) 0x81, (byte) 0x3B, (byte) 0x80, (byte) 0x1D, + (byte) 0x34, (byte) 0x6F, (byte) 0xF2, (byte) 0x66, (byte) 0x60, (byte) 0xB7, (byte) 0x6B, (byte) 0x99, (byte) 0x50, (byte) 0xA5, (byte) 0xA4, (byte) 0x9F, (byte) 0x9F, (byte) 0xE8, (byte) 0x04, (byte) 0x7B, (byte) 0x10, + (byte) 0x22, (byte) 0xC2, (byte) 0x4F, (byte) 0xBB, (byte) 0xA9, (byte) 0xD7, (byte) 0xFE, (byte) 0xB7, (byte) 0xC6, (byte) 0x1B, (byte) 0xF8, (byte) 0x3B, (byte) 0x57, (byte) 0xE7, (byte) 0xC6, (byte) 0xA8, (byte) 0xA6, + (byte) 0x15, (byte) 0x0F, (byte) 0x04, (byte) 0xFB, (byte) 0x83, (byte) 0xF6, (byte) 0xD3, (byte) 0xC5, (byte) 0x1E, (byte) 0xC3, (byte) 0x02, (byte) 0x35, (byte) 0x54, (byte) 0x13, (byte) 0x5A, (byte) 0x16, (byte) 0x91, + (byte) 0x32, (byte) 0xF6, (byte) 0x75, (byte) 0xF3, (byte) 0xAE, (byte) 0x2B, (byte) 0x61, (byte) 0xD7, (byte) 0x2A, (byte) 0xEF, (byte) 0xF2, (byte) 0x22, (byte) 0x03, (byte) 0x19, (byte) 0x9D, (byte) 0xD1, (byte) 0x48, + (byte) 0x01, (byte) 0xC7, (byte) 0x02, (byte) 0x81, (byte) 0x81, (byte) 0x00, (byte) 0xF7, (byte) 0xE1, (byte) 0xA0, (byte) 0x85, (byte) 0xD6, (byte) 0x9B, (byte) 0x3D, (byte) 0xDE, (byte) 0xCB, (byte) 0xBC, (byte) 0xAB, + (byte) 0x5C, (byte) 0x36, (byte) 0xB8, (byte) 0x57, (byte) 0xB9, (byte) 0x79, (byte) 0x94, (byte) 0xAF, (byte) 0xBB, (byte) 0xFA, (byte) 0x3A, (byte) 0xEA, (byte) 0x82, (byte) 0xF9, (byte) 0x57, (byte) 0x4C, (byte) 0x0B, + (byte) 0x3D, (byte) 0x07, (byte) 0x82, (byte) 0x67, (byte) 0x51, (byte) 0x59, (byte) 0x57, (byte) 0x8E, (byte) 0xBA, (byte) 0xD4, (byte) 0x59, (byte) 0x4F, (byte) 0xE6, (byte) 0x71, (byte) 0x07, (byte) 0x10, (byte) 0x81, + (byte) 0x80, (byte) 0xB4, (byte) 0x49, (byte) 0x16, (byte) 0x71, (byte) 0x23, (byte) 0xE8, (byte) 0x4C, (byte) 0x28, (byte) 0x16, (byte) 0x13, (byte) 0xB7, (byte) 0xCF, (byte) 0x09, (byte) 0x32, (byte) 0x8C, (byte) 0xC8, + (byte) 0xA6, (byte) 0xE1, (byte) 0x3C, (byte) 0x16, (byte) 0x7A, (byte) 0x8B, (byte) 0x54, (byte) 0x7C, (byte) 0x8D, (byte) 0x28, (byte) 0xE0, (byte) 0xA3, (byte) 0xAE, (byte) 0x1E, (byte) 0x2B, (byte) 0xB3, (byte) 0xA6, + (byte) 0x75, (byte) 0x91, (byte) 0x6E, (byte) 0xA3, (byte) 0x7F, (byte) 0x0B, (byte) 0xFA, (byte) 0x21, (byte) 0x35, (byte) 0x62, (byte) 0xF1, (byte) 0xFB, (byte) 0x62, (byte) 0x7A, (byte) 0x01, (byte) 0x24, (byte) 0x3B, + (byte) 0xCC, (byte) 0xA4, (byte) 0xF1, (byte) 0xBE, (byte) 0xA8, (byte) 0x51, (byte) 0x90, (byte) 0x89, (byte) 0xA8, (byte) 0x83, (byte) 0xDF, (byte) 0xE1, (byte) 0x5A, (byte) 0xE5, (byte) 0x9F, (byte) 0x06, (byte) 0x92, + (byte) 0x8B, (byte) 0x66, (byte) 0x5E, (byte) 0x80, (byte) 0x7B, (byte) 0x55, (byte) 0x25, (byte) 0x64, (byte) 0x01, (byte) 0x4C, (byte) 0x3B, (byte) 0xFE, (byte) 0xCF, (byte) 0x49, (byte) 0x2A, (byte) 0x02, (byte) 0x02, + (byte) 0x03, (byte) 0xFE, (byte) 0x03, (byte) 0x81, (byte) 0x85, (byte) 0x00, (byte) 0x02, (byte) 0x81, (byte) 0x81, (byte) 0x00, (byte) 0xD4, (byte) 0xC2, (byte) 0xC2, (byte) 0x84, (byte) 0xEB, (byte) 0xEC, (byte) 0xB6, + (byte) 0xF1, (byte) 0x29, (byte) 0x2B, (byte) 0xAB, (byte) 0x8F, (byte) 0xC1, (byte) 0x48, (byte) 0x4C, (byte) 0x47, (byte) 0xCE, (byte) 0x0B, (byte) 0x97, (byte) 0x4C, (byte) 0xFC, (byte) 0x27, (byte) 0x10, (byte) 0x0A, + (byte) 0x5F, (byte) 0x3E, (byte) 0xE6, (byte) 0xF9, (byte) 0x9B, (byte) 0x15, (byte) 0xDF, (byte) 0x83, (byte) 0x01, (byte) 0xFA, (byte) 0x69, (byte) 0x57, (byte) 0xEC, (byte) 0x6B, (byte) 0x68, (byte) 0xC7, (byte) 0x96, + (byte) 0x33, (byte) 0x98, (byte) 0xA4, (byte) 0xB0, (byte) 0xA3, (byte) 0x18, (byte) 0x01, (byte) 0x66, (byte) 0x7A, (byte) 0x4A, (byte) 0xF3, (byte) 0x3C, (byte) 0xD9, (byte) 0x2A, (byte) 0x48, (byte) 0xFD, (byte) 0x3A, + (byte) 0x31, (byte) 0xFC, (byte) 0x97, (byte) 0x52, (byte) 0x36, (byte) 0x20, (byte) 0x0E, (byte) 0x69, (byte) 0xB6, (byte) 0x32, (byte) 0x8B, (byte) 0x4E, (byte) 0xDA, (byte) 0x8B, (byte) 0x04, (byte) 0x88, (byte) 0xF8, + (byte) 0x30, (byte) 0xA9, (byte) 0x65, (byte) 0x68, (byte) 0x47, (byte) 0xBB, (byte) 0xA1, (byte) 0xF6, (byte) 0xD6, (byte) 0x18, (byte) 0x11, (byte) 0x48, (byte) 0x8D, (byte) 0x8F, (byte) 0x4B, (byte) 0xC1, (byte) 0xE1, + (byte) 0xA4, (byte) 0x43, (byte) 0x83, (byte) 0x1F, (byte) 0x6B, (byte) 0x6D, (byte) 0xEE, (byte) 0xA7, (byte) 0xA3, (byte) 0x5F, (byte) 0xD2, (byte) 0x95, (byte) 0x09, (byte) 0xD4, (byte) 0xEA, (byte) 0x85, (byte) 0x0C, + (byte) 0xA5, (byte) 0xC9, (byte) 0x93, (byte) 0xCE, (byte) 0xC1, (byte) 0x1D, (byte) 0x30, (byte) 0x73, (byte) 0xA3, (byte) 0xE1, (byte) 0x69, (byte) 0xA8, (byte) 0x11, (byte) 0x98, (byte) 0x78, (byte) 0xF3, (byte) 0xF9, + (byte) 0x8F, (byte) 0x04 }; + + + + private static final HashMap<String, KeySpec> keys = new HashMap<String, KeySpec>(); + static { + keys.put("DH_public", new X509EncodedKeySpec(DH_public)); + keys.put("DH_private", new PKCS8EncodedKeySpec(DH_private)); + keys.put("DSA_public", new X509EncodedKeySpec(DSA_public)); + keys.put("DSA_private", new PKCS8EncodedKeySpec(DSA_private)); + keys.put("RSA_public", new X509EncodedKeySpec(RSA_public)); + keys.put("RSA_private", new PKCS8EncodedKeySpec(RSA_private)); + } + + public static PrivateKey getPrivateKey(String algorithmName) throws NoSuchAlgorithmException, InvalidKeySpecException + { + KeyFactory factory = KeyFactory.getInstance(algorithmName); + return factory.generatePrivate(keys.get(algorithmName + "_private")); + } + + public static PublicKey getPublicKey(String algorithmName) throws NoSuchAlgorithmException, InvalidKeySpecException + { + KeyFactory factory = KeyFactory.getInstance(algorithmName); + return factory.generatePublic(keys.get(algorithmName + "_public")); + } +} diff --git a/support/src/test/java/tests/security/KeyAgreementHelper.java b/support/src/test/java/tests/security/KeyAgreementHelper.java new file mode 100644 index 0000000..57593c5 --- /dev/null +++ b/support/src/test/java/tests/security/KeyAgreementHelper.java @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2009 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package tests.security; + +import java.security.InvalidKeyException; +import java.security.KeyPair; +import java.security.NoSuchAlgorithmException; +import java.security.PrivateKey; +import java.security.PublicKey; +import javax.crypto.KeyAgreement; +import junit.framework.Assert; + +public class KeyAgreementHelper extends TestHelper<KeyPair> { + + private final String algorithmName; + + public KeyAgreementHelper(String algorithmName) { + this.algorithmName = algorithmName; + } + + @Override public void test(KeyPair keyPair) { + test(keyPair.getPrivate(), keyPair.getPublic()); + } + + void test(PrivateKey encryptKey, PublicKey decryptKey) { + + KeyAgreement keyAgreement = null; + try { + keyAgreement = KeyAgreement.getInstance(algorithmName); + } catch (NoSuchAlgorithmException e) { + Assert.fail(e.getMessage()); + } + + try { + keyAgreement.init(encryptKey); + } catch (InvalidKeyException e) { + Assert.fail(e.getMessage()); + } + try { + keyAgreement.doPhase(decryptKey, true); + } catch (InvalidKeyException e) { + Assert.fail(e.getMessage()); + } catch (IllegalStateException e) { + Assert.fail(e.getMessage()); + } + Assert.assertNotNull("generated secret is null", keyAgreement + .generateSecret()); + + } +} diff --git a/support/src/test/java/tests/security/KeyFactoryTest.java b/support/src/test/java/tests/security/KeyFactoryTest.java new file mode 100644 index 0000000..179254a --- /dev/null +++ b/support/src/test/java/tests/security/KeyFactoryTest.java @@ -0,0 +1,122 @@ +/* + * Copyright (C) 2009 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package tests.security; + +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTargetNew; +import dalvik.annotation.TestTargets; +import java.security.Key; +import java.security.KeyFactory; +import java.security.KeyPair; +import java.security.NoSuchAlgorithmException; +import java.security.PrivateKey; +import java.security.PublicKey; +import java.security.spec.InvalidKeySpecException; +import java.security.spec.KeySpec; +import junit.framework.TestCase; + +public abstract class KeyFactoryTest<PublicKeySpec extends KeySpec, PrivateKeySpec extends KeySpec> + extends TestCase { + + private final String algorithmName; + private final Class<PublicKeySpec> publicKeySpecClass; + private final Class<PrivateKeySpec> privateKeySpecClass; + private KeyFactory factory; + + public KeyFactoryTest(String algorithmName, + Class<PublicKeySpec> publicKeySpecClass, + Class<PrivateKeySpec> privateKeySpecClass) { + this.algorithmName = algorithmName; + this.publicKeySpecClass = publicKeySpecClass; + this.privateKeySpecClass = privateKeySpecClass; + } + + protected void setUp() throws Exception { + super.setUp(); + factory = getFactory(); + } + + private KeyFactory getFactory() { + try { + return KeyFactory.getInstance(algorithmName); + } catch (NoSuchAlgorithmException e) { + fail(e.getMessage()); + } + return null; + } + + @TestTargets({ + @TestTargetNew( + level = TestLevel.ADDITIONAL, + method = "getKeySpec", + args = {Key.class, Class.class} + ), + @TestTargetNew( + level = TestLevel.ADDITIONAL, + method = "generatePrivate", + args = {KeySpec.class} + ), + @TestTargetNew( + level = TestLevel.ADDITIONAL, + method = "generatePublic", + args = {KeySpec.class} + ), + @TestTargetNew( + level=TestLevel.COMPLETE, + method="method", + args={} + ) + }) + public void testKeyFactory() { + PrivateKeySpec privateKeySpec = null; + try { + privateKeySpec = factory.getKeySpec(DefaultKeys.getPrivateKey(algorithmName), + privateKeySpecClass); + } catch (InvalidKeySpecException e) { + fail(e.getMessage()); + } catch (NoSuchAlgorithmException e) { + fail(e.getMessage()); + } + + PrivateKey privateKey = null; + try { + privateKey = factory.generatePrivate(privateKeySpec); + } catch (InvalidKeySpecException e) { + fail(e.getMessage()); + } + + PublicKeySpec publicKeySpec = null; + try { + publicKeySpec = factory.getKeySpec(DefaultKeys.getPublicKey(algorithmName), + publicKeySpecClass); + } catch (InvalidKeySpecException e) { + fail(e.getMessage()); + } catch (NoSuchAlgorithmException e) { + fail(e.getMessage()); + } + + PublicKey publicKey = null; + try { + publicKey = factory.generatePublic(publicKeySpec); + } catch (InvalidKeySpecException e) { + fail(e.getMessage()); + } + + check(new KeyPair(publicKey, privateKey)); + } + + protected void check(KeyPair keyPair) {} +} diff --git a/support/src/test/java/tests/security/KeyPairGeneratorTest.java b/support/src/test/java/tests/security/KeyPairGeneratorTest.java new file mode 100644 index 0000000..adf8d4d --- /dev/null +++ b/support/src/test/java/tests/security/KeyPairGeneratorTest.java @@ -0,0 +1,81 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package tests.security; + +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTargetNew; +import dalvik.annotation.TestTargets; +import java.security.KeyPair; +import java.security.KeyPairGenerator; +import java.security.NoSuchAlgorithmException; +import junit.framework.TestCase; + +public abstract class KeyPairGeneratorTest extends TestCase { + + private final String algorithmName; + private final TestHelper<KeyPair> helper; + + private KeyPairGenerator generator; + + protected KeyPairGeneratorTest(String algorithmName, TestHelper<KeyPair> helper) { + this.algorithmName = algorithmName; + this.helper = helper; + } + + protected void setUp() throws Exception { + super.setUp(); + generator = getKeyPairGenerator(); + } + + private KeyPairGenerator getKeyPairGenerator() { + try { + return KeyPairGenerator.getInstance(algorithmName); + } catch (NoSuchAlgorithmException e) { + fail("cannot get KeyPairGenerator: " + e); + return null; + } + } + + @TestTargets({ + @TestTargetNew( + level = TestLevel.ADDITIONAL, + method = "initialize", + args = {int.class} + ), + @TestTargetNew( + level = TestLevel.ADDITIONAL, + method = "generateKeyPair", + args = {} + ), + @TestTargetNew( + level=TestLevel.COMPLETE, + method="method", + args={} + ) + }) + public void testKeyPairGenerator() throws NoSuchAlgorithmException { + generator.initialize(1024); + + KeyPair keyPair = generator.generateKeyPair(); + + assertNotNull("no keypair generated", keyPair); + assertNotNull("no public key generated", keyPair.getPublic()); + assertNotNull("no private key generated", keyPair.getPrivate()); + + helper.test(keyPair); + } +} diff --git a/support/src/test/java/tests/security/MessageDigestTest.java b/support/src/test/java/tests/security/MessageDigestTest.java new file mode 100644 index 0000000..9ae4881 --- /dev/null +++ b/support/src/test/java/tests/security/MessageDigestTest.java @@ -0,0 +1,320 @@ +/* + * Copyright (C) 2009 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package tests.security; + +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTargetNew; +import dalvik.annotation.TestTargets; + +import junit.framework.TestCase; + +import java.io.IOException; +import java.io.InputStream; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +public abstract class MessageDigestTest extends TestCase { + + private String digestAlgorithmName; + + protected MessageDigestTest(String digestAlgorithmName) { + super(); + this.digestAlgorithmName = digestAlgorithmName; + } + + private MessageDigest digest; + private InputStream sourceData; + private byte[] checkDigest; + + @Override + protected void setUp() throws Exception { + super.setUp(); + + this.source3 = getLongMessage(1000000); + this.digest = getMessageDigest(); + this.sourceData = getSourceData(); + this.checkDigest = getCheckDigest(); + } + + @Override + public void tearDown() throws Exception { + super.tearDown(); + + // This is critical. The MessageDigest tests consume a lot of memory due + // to the 1 MB buffers being allocated. We need to make sure all data is + // freed after each test. Otherwise the Android runtime simply dies at + // some point. + source1 = null; + source2 = null; + source3 = null; + + expected1 = null; + expected2 = null; + expected3 = null; + + digest = null; + sourceData = null; + checkDigest = null; + + System.gc(); + } + + MessageDigest getMessageDigest() + { + try { + return MessageDigest.getInstance(digestAlgorithmName); + } catch (NoSuchAlgorithmException e) { + fail("failed to get digest instance: " + e); + return null; + } + } + + InputStream getSourceData() + { + InputStream sourceStream = getClass().getResourceAsStream( + digestAlgorithmName + ".data"); + assertNotNull("digest source data not found: " + digestAlgorithmName, + sourceStream); + return sourceStream; + } + + byte[] getCheckDigest() + { + InputStream checkDigestStream = getClass().getResourceAsStream( + digestAlgorithmName + ".check"); + byte[] checkDigest = new byte[digest.getDigestLength()]; + int read = 0; + int index = 0; + try { + while ((read = checkDigestStream.read()) != -1) + { + checkDigest[index++] = (byte)read; + } + } catch (IOException e) { + fail("failed to read digest golden data: " + digestAlgorithmName); + } + return checkDigest; + } + + @TestTargets({ + @TestTargetNew( + level = TestLevel.ADDITIONAL, + method = "update", + args = {byte[].class,int.class,int.class} + ), + @TestTargetNew( + level = TestLevel.ADDITIONAL, + method = "digest", + args = {} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + method = "method", + args = {} + ) + }) + public void testMessageDigest1() + { + byte[] buf = new byte[128]; + int read = 0; + try { + while ((read = sourceData.read(buf)) != -1) + { + digest.update(buf, 0, read); + } + } catch (IOException e) { + fail("failed to read digest data"); + } + + byte[] computedDigest = digest.digest(); + + assertNotNull("computed digest is is null", computedDigest); + assertEquals("digest length mismatch", checkDigest.length, + computedDigest.length); + + for (int i = 0; i < checkDigest.length; i++) + { + assertEquals("byte " + i + " of computed and check digest differ", + checkDigest[i], computedDigest[i]); + } + + } + + @TestTargets({ + @TestTargetNew( + level = TestLevel.ADDITIONAL, + method = "update", + args = {byte.class} + ), + @TestTargetNew( + level = TestLevel.ADDITIONAL, + method = "digest", + args = {} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + method = "method", + args = {} + ) + }) + public void testMessageDigest2() + { + int val; + try { + while ((val = sourceData.read()) != -1) + { + digest.update((byte)val); + } + } catch (IOException e) { + fail("failed to read digest data"); + } + + byte[] computedDigest = digest.digest(); + + assertNotNull("computed digest is is null", computedDigest); + assertEquals("digest length mismatch", checkDigest.length, + computedDigest.length); + for (int i = 0; i < checkDigest.length; i++) + { + assertEquals("byte " + i + " of computed and check digest differ", + checkDigest[i], computedDigest[i]); + } + + } + + + /** + * Official FIPS180-2 testcases + */ + + protected String source1, source2, source3; + protected String expected1, expected2, expected3; + + String getLongMessage(int length) { + StringBuilder sourceBuilder = new StringBuilder(length); + for (int i = 0; i < length / 10; i++) { + sourceBuilder.append("aaaaaaaaaa"); + } + return sourceBuilder.toString(); + } + + @TestTargets({ + @TestTargetNew( + level = TestLevel.ADDITIONAL, + method = "update", + args = {byte.class} + ), + @TestTargetNew( + level = TestLevel.ADDITIONAL, + method = "digest", + args = {} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + method = "method", + args = {} + ) + }) + public void testfips180_2_singleblock() { + + digest.update(source1.getBytes(), 0, source1.length()); + + byte[] computedDigest = digest.digest(); + + assertNotNull("computed digest is null", computedDigest); + + StringBuilder sb = new StringBuilder(); + String res; + for (int i = 0; i < computedDigest.length; i++) + { + res = Integer.toHexString(computedDigest[i] & 0xFF); + sb.append((res.length() == 1 ? "0" : "") + res); + } + assertEquals("computed and check digest differ", expected1, + sb.toString()); + } + + @TestTargets({ + @TestTargetNew( + level = TestLevel.ADDITIONAL, + method = "update", + args = {byte.class} + ), + @TestTargetNew( + level = TestLevel.ADDITIONAL, + method = "digest", + args = {} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + method = "method", + args = {} + ) + }) + public void testfips180_2_multiblock() { + + digest.update(source2.getBytes(), 0, source2.length()); + + byte[] computedDigest = digest.digest(); + + assertNotNull("computed digest is null", computedDigest); + + StringBuilder sb = new StringBuilder(); + String res; + for (int i = 0; i < computedDigest.length; i++) + { + res = Integer.toHexString(computedDigest[i] & 0xFF); + sb.append((res.length() == 1 ? "0" : "") + res); + } + assertEquals("computed and check digest differ", expected2, + sb.toString()); + } + + @TestTargets({ + @TestTargetNew( + level = TestLevel.ADDITIONAL, + method = "update", + args = {byte.class} + ), + @TestTargetNew( + level = TestLevel.ADDITIONAL, + method = "digest", + args = {} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + method = "method", + args = {} + ) + }) + public void testfips180_2_longMessage() { + + digest.update(source3.getBytes(), 0, source3.length()); + + byte[] computedDigest = digest.digest(); + + assertNotNull("computed digest is null", computedDigest); + + StringBuilder sb = new StringBuilder(); + String res; + for (int i = 0; i < computedDigest.length; i++) + { + res = Integer.toHexString(computedDigest[i] & 0xFF); + sb.append((res.length() == 1 ? "0" : "") + res); + } + assertEquals("computed and check digest differ", expected3, + sb.toString()); + } +} diff --git a/support/src/test/java/tests/security/SignatureHelper.java b/support/src/test/java/tests/security/SignatureHelper.java new file mode 100644 index 0000000..c29efad --- /dev/null +++ b/support/src/test/java/tests/security/SignatureHelper.java @@ -0,0 +1,89 @@ +/* + * Copyright (C) 2009 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package tests.security; + +import java.security.InvalidKeyException; +import java.security.KeyPair; +import java.security.NoSuchAlgorithmException; +import java.security.PrivateKey; +import java.security.PublicKey; +import java.security.Signature; +import java.security.SignatureException; +import junit.framework.Assert; + +public class SignatureHelper extends TestHelper<KeyPair> { + + private final String algorithmName; + private final String plainData = "some data do sign and verify"; + + public SignatureHelper(String algorithmName) { + this.algorithmName = algorithmName; + } + + @Override + public void test(KeyPair keyPair) { + test(keyPair.getPrivate(), keyPair.getPublic()); + } + + public void test(PrivateKey encryptKey, PublicKey decryptKey) { + + Signature signature = null; + try { + signature = Signature.getInstance(algorithmName); + } catch (NoSuchAlgorithmException e) { + Assert.fail(e.getMessage()); + } + + try { + signature.initSign(encryptKey); + } catch (InvalidKeyException e) { + Assert.fail(e.getMessage()); + } + + try { + signature.update(plainData.getBytes()); + } catch (SignatureException e) { + Assert.fail(e.getMessage()); + } + + byte[] signed = null; + try { + signed = signature.sign(); + } catch (SignatureException e) { + Assert.fail(e.getMessage()); + } + + try { + signature.initVerify(decryptKey); + } catch (InvalidKeyException e) { + Assert.fail(e.getMessage()); + } + + try { + signature.update(plainData.getBytes()); + } catch (SignatureException e) { + Assert.fail(e.getMessage()); + } + + try { + Assert.assertTrue("signature could not be verified", signature + .verify(signed)); + } catch (SignatureException e) { + Assert.fail(e.getMessage()); + } + } +} diff --git a/support/src/test/java/tests/security/SignatureTest.java b/support/src/test/java/tests/security/SignatureTest.java new file mode 100644 index 0000000..c23d7ca --- /dev/null +++ b/support/src/test/java/tests/security/SignatureTest.java @@ -0,0 +1,146 @@ +/* + * Copyright (C) 2009 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package tests.security; + +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTargetNew; +import dalvik.annotation.TestTargets; + +import junit.framework.TestCase; + +import java.security.InvalidKeyException; +import java.security.KeyPair; +import java.security.KeyPairGenerator; +import java.security.NoSuchAlgorithmException; +import java.security.PrivateKey; +import java.security.PublicKey; +import java.security.Signature; +import java.security.SignatureException; +public abstract class SignatureTest extends TestCase { + + private final String algorithmName; + private final String keyAlgorithmName; + private static final String signData = "some data to sign an"; //d verify"; + KeyPairGenerator generator; + KeyPair keyPair; + + public SignatureTest(String algorithmName, String keyAlgorithmName) { + this.algorithmName = algorithmName; + this.keyAlgorithmName = keyAlgorithmName; + } + + protected void setUp() throws Exception { + super.setUp(); + generator = getGenerator(); + keyPair = getKeyPair(); + } + + private KeyPair getKeyPair() { + return generator.generateKeyPair(); + } + + private KeyPairGenerator getGenerator() { + try { + return KeyPairGenerator.getInstance(keyAlgorithmName); + } catch (NoSuchAlgorithmException e) { + fail(e.getMessage()); + } + return null; + } + + @TestTargets({ + @TestTargetNew( + level = TestLevel.ADDITIONAL, + method = "getInstance", + args = {String.class} + ), + @TestTargetNew( + level = TestLevel.ADDITIONAL, + method = "initSign", + args = {PrivateKey.class} + ), + @TestTargetNew( + level = TestLevel.ADDITIONAL, + method = "update", + args = {byte[].class} + ), + @TestTargetNew( + level = TestLevel.ADDITIONAL, + method = "sign", + args = {} + ), + @TestTargetNew( + level = TestLevel.ADDITIONAL, + method = "initVerify", + args = {PublicKey.class} + ), + @TestTargetNew( + level = TestLevel.ADDITIONAL, + method = "verify", + args = {byte[].class} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + method = "method", + args = {} + ) + }) + public void testSignature() { + Signature signature = null; + try { + signature = Signature.getInstance(algorithmName); + } catch (NoSuchAlgorithmException e) { + fail(e.getMessage()); + } + + try { + signature.initSign(keyPair.getPrivate()); + } catch (InvalidKeyException e) { + fail(e.getMessage()); + } + + try { + signature.update(signData.getBytes()); + } catch (SignatureException e) { + fail(e.getMessage()); + } + + byte[] sign = null; + try { + sign = signature.sign(); + } catch (SignatureException e) { + fail(e.getMessage()); + } + + try { + signature.initVerify(keyPair.getPublic()); + } catch (InvalidKeyException e) { + fail(e.getMessage()); + } + + try { + signature.update(signData.getBytes()); + } catch (SignatureException e) { + fail(e.getMessage()); + } + + try { + assertTrue(signature.verify(sign)); + } catch (SignatureException e) { + fail(e.getMessage()); + } + } +} diff --git a/support/src/test/java/tests/security/TestHelper.java b/support/src/test/java/tests/security/TestHelper.java new file mode 100644 index 0000000..aa5c9fd --- /dev/null +++ b/support/src/test/java/tests/security/TestHelper.java @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2009 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package tests.security; + +public abstract class TestHelper<T> { + public abstract void test(T testObject); +} |