diff options
Diffstat (limited to 'bcpkix/src/main/java/org/bouncycastle/mozilla')
5 files changed, 0 insertions, 305 deletions
diff --git a/bcpkix/src/main/java/org/bouncycastle/mozilla/SignedPublicKeyAndChallenge.java b/bcpkix/src/main/java/org/bouncycastle/mozilla/SignedPublicKeyAndChallenge.java deleted file mode 100644 index f9c4bca..0000000 --- a/bcpkix/src/main/java/org/bouncycastle/mozilla/SignedPublicKeyAndChallenge.java +++ /dev/null @@ -1,139 +0,0 @@ -package org.bouncycastle.mozilla; - -import java.io.ByteArrayInputStream; -import java.security.InvalidKeyException; -import java.security.KeyFactory; -import java.security.NoSuchAlgorithmException; -import java.security.NoSuchProviderException; -import java.security.PublicKey; -import java.security.Signature; -import java.security.SignatureException; -import java.security.spec.X509EncodedKeySpec; - -import org.bouncycastle.asn1.ASN1InputStream; -import org.bouncycastle.asn1.ASN1Object; -import org.bouncycastle.asn1.ASN1Primitive; -import org.bouncycastle.asn1.ASN1Sequence; -import org.bouncycastle.asn1.DERBitString; -import org.bouncycastle.asn1.mozilla.PublicKeyAndChallenge; -import org.bouncycastle.asn1.x509.AlgorithmIdentifier; -import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo; - -/** - * This is designed to parse the SignedPublicKeyAndChallenge created by the - * KEYGEN tag included by Mozilla based browsers. - * <pre> - * PublicKeyAndChallenge ::= SEQUENCE { - * spki SubjectPublicKeyInfo, - * challenge IA5STRING - * } - * - * SignedPublicKeyAndChallenge ::= SEQUENCE { - * publicKeyAndChallenge PublicKeyAndChallenge, - * signatureAlgorithm AlgorithmIdentifier, - * signature BIT STRING - * } - * </pre> - */ -public class SignedPublicKeyAndChallenge - extends ASN1Object -{ - private static ASN1Sequence toDERSequence(byte[] bytes) - { - try - { - ByteArrayInputStream bIn = new ByteArrayInputStream(bytes); - ASN1InputStream aIn = new ASN1InputStream(bIn); - - return (ASN1Sequence)aIn.readObject(); - } - catch (Exception e) - { - throw new IllegalArgumentException("badly encoded request"); - } - } - - private ASN1Sequence spkacSeq; - private PublicKeyAndChallenge pkac; - private AlgorithmIdentifier signatureAlgorithm; - private DERBitString signature; - - public SignedPublicKeyAndChallenge(byte[] bytes) - { - spkacSeq = toDERSequence(bytes); - pkac = PublicKeyAndChallenge.getInstance(spkacSeq.getObjectAt(0)); - signatureAlgorithm = - AlgorithmIdentifier.getInstance(spkacSeq.getObjectAt(1)); - signature = (DERBitString)spkacSeq.getObjectAt(2); - } - - public ASN1Primitive toASN1Primitive() - { - return spkacSeq; - } - - public PublicKeyAndChallenge getPublicKeyAndChallenge() - { - return pkac; - } - - public boolean verify() - throws NoSuchAlgorithmException, SignatureException, - NoSuchProviderException, InvalidKeyException - { - return verify(null); - } - - public boolean verify(String provider) - throws NoSuchAlgorithmException, SignatureException, - NoSuchProviderException, InvalidKeyException - { - Signature sig = null; - if (provider == null) - { - sig = Signature.getInstance(signatureAlgorithm.getAlgorithm().getId()); - } - else - { - sig = Signature.getInstance(signatureAlgorithm.getAlgorithm().getId(), provider); - } - PublicKey pubKey = this.getPublicKey(provider); - sig.initVerify(pubKey); - try - { - DERBitString pkBytes = new DERBitString(pkac); - sig.update(pkBytes.getBytes()); - - return sig.verify(signature.getBytes()); - } - catch (Exception e) - { - throw new InvalidKeyException("error encoding public key"); - } - } - - public PublicKey getPublicKey(String provider) - throws NoSuchAlgorithmException, NoSuchProviderException, - InvalidKeyException - { - SubjectPublicKeyInfo subjectPKInfo = pkac.getSubjectPublicKeyInfo(); - try - { - DERBitString bStr = new DERBitString(subjectPKInfo); - X509EncodedKeySpec xspec = new X509EncodedKeySpec(bStr.getBytes()); - - - AlgorithmIdentifier keyAlg = subjectPKInfo.getAlgorithm(); - - KeyFactory factory = - KeyFactory.getInstance(keyAlg.getAlgorithm().getId(),provider); - - return factory.generatePublic(xspec); - - } - catch (Exception e) - { - throw new InvalidKeyException("error encoding public key"); - } - } -} diff --git a/bcpkix/src/main/java/org/bouncycastle/mozilla/package.html b/bcpkix/src/main/java/org/bouncycastle/mozilla/package.html deleted file mode 100644 index dd2203e..0000000 --- a/bcpkix/src/main/java/org/bouncycastle/mozilla/package.html +++ /dev/null @@ -1,5 +0,0 @@ -<html> -<body bgcolor="#ffffff"> -Support class for mozilla signed public key and challenge. -</body> -</html> diff --git a/bcpkix/src/main/java/org/bouncycastle/mozilla/test/AllTests.java b/bcpkix/src/main/java/org/bouncycastle/mozilla/test/AllTests.java deleted file mode 100644 index 3c0dcc6..0000000 --- a/bcpkix/src/main/java/org/bouncycastle/mozilla/test/AllTests.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.bouncycastle.mozilla.test; - -import java.security.Security; - -import org.bouncycastle.jce.provider.BouncyCastleProvider; -import org.bouncycastle.util.test.SimpleTestResult; - -import junit.framework.*; - -public class AllTests - extends TestCase -{ - public void testMozilla() - { - Security.addProvider(new BouncyCastleProvider()); - - org.bouncycastle.util.test.Test[] tests = new org.bouncycastle.util.test.Test[] { new SPKACTest() }; - - for (int i = 0; i != tests.length; i++) - { - SimpleTestResult result = (SimpleTestResult)tests[i].perform(); - - if (!result.isSuccessful()) - { - fail(result.toString()); - } - } - } - - public static void main (String[] args) - { - junit.textui.TestRunner.run(suite()); - } - - public static Test suite() - { - TestSuite suite = new TestSuite("Mozilla Tests"); - - suite.addTestSuite(AllTests.class); - - return suite; - } -} diff --git a/bcpkix/src/main/java/org/bouncycastle/mozilla/test/SPKACTest.java b/bcpkix/src/main/java/org/bouncycastle/mozilla/test/SPKACTest.java deleted file mode 100644 index 192bfd8..0000000 --- a/bcpkix/src/main/java/org/bouncycastle/mozilla/test/SPKACTest.java +++ /dev/null @@ -1,113 +0,0 @@ -package org.bouncycastle.mozilla.test; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.security.PublicKey; -import java.security.Security; - -import org.bouncycastle.asn1.ASN1InputStream; -import org.bouncycastle.asn1.ASN1Primitive; -import org.bouncycastle.asn1.DERIA5String; -import org.bouncycastle.asn1.DEROutputStream; -import org.bouncycastle.asn1.mozilla.PublicKeyAndChallenge; -import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo; -import org.bouncycastle.jce.provider.BouncyCastleProvider; -import org.bouncycastle.mozilla.SignedPublicKeyAndChallenge; -import org.bouncycastle.util.encoders.Base64; -import org.bouncycastle.util.test.SimpleTest; - -public class SPKACTest - extends SimpleTest -{ - byte[] spkac = Base64.decode( - "MIIBOjCBpDCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEApne7ti0ibPhV8Iht"+ - "7Pws5iRckM7x4mtZYxEpeX5/IO8tDsBFdY86ewuY2f2KCca0oMWr43kdkZbPyzf4"+ - "CSV+0fZm9MJyNMywygZjoOCC+rS8kr0Ef31iHChhYsyejJnjw116Jnn96syhdHY6"+ - "lVD1rK0nn5ZkHjxU74gjoZu6BJMCAwEAARYAMA0GCSqGSIb3DQEBBAUAA4GBAKFL"+ - "g/luv0C7gMTI8ZKfFoSyi7Q7kiSQcmSj1WJgT56ouIRJO5NdvB/1n4GNik8VOAU0"+ - "NRztvGy3ZGqgbSav7lrxcNEvXH+dLbtS97s7yiaozpsOcEHqsBribpLOTRzYa8ci"+ - "CwkPmIiYqcby11diKLpd+W9RFYNme2v0rrbM2CyV"); - - - public String getName() - { - return "SignedPubicKeyAndChallenge"; - } - - public void spkacTest(String testName, byte[] req) - throws Exception - { - SignedPublicKeyAndChallenge spkac; - - spkac = new SignedPublicKeyAndChallenge(req); - - PublicKeyAndChallenge pkac = spkac.getPublicKeyAndChallenge(); - PublicKey pubKey = spkac.getPublicKey("BC"); - ASN1Primitive obj = pkac.toASN1Primitive(); - if (obj == null) - { - fail("Error - " + testName + " PKAC ASN1Primitive was null."); - } - - obj = spkac.toASN1Primitive(); - if (obj == null) - { - fail("Error - "+testName+ " SPKAC ASN1Primitive was null."); - } - - SubjectPublicKeyInfo spki = pkac.getSubjectPublicKeyInfo(); - if (spki == null) - { - fail("Error - "+testName + " SubjectPublicKeyInfo was null."); - } - - DERIA5String challenge = pkac.getChallenge(); - // Most cases this will be a string of length zero. - if (challenge == null) - { - fail(":Error - "+testName+ " challenge was null."); - } - - ByteArrayInputStream bIn = new ByteArrayInputStream(req); - ASN1InputStream dIn = new ASN1InputStream(bIn); - - - ByteArrayOutputStream bOut = new ByteArrayOutputStream(); - DEROutputStream dOut = new DEROutputStream(bOut); - - dOut.writeObject(spkac.toASN1Primitive()); - - byte[] bytes = bOut.toByteArray(); - - if (bytes.length != req.length) - { - fail(testName + " failed length test"); - } - - for (int i = 0; i != req.length; i++) - { - if (bytes[i] != req[i]) - { - fail(testName + " failed comparison test"); - } - } - - if (!spkac.verify("BC")) - { - fail(testName + " verification failed"); - } - } - - public void performTest() - throws Exception - { - spkacTest("spkac", spkac); - } - - public static void main(String[] args) - { - Security.addProvider(new BouncyCastleProvider()); - - runTest(new SPKACTest()); - } -} diff --git a/bcpkix/src/main/java/org/bouncycastle/mozilla/test/package.html b/bcpkix/src/main/java/org/bouncycastle/mozilla/test/package.html deleted file mode 100644 index 54047ad..0000000 --- a/bcpkix/src/main/java/org/bouncycastle/mozilla/test/package.html +++ /dev/null @@ -1,5 +0,0 @@ -<html> -<body bgcolor="#ffffff"> -Test class for mozilla signed public key and challenge. -</body> -</html> |