Package org.bouncycastle.util.test

Examples of org.bouncycastle.util.test.SimpleTestResult


            byte[]                    bytes = bOut.toByteArray();

            if (bytes.length != req.length)
            {
                return new SimpleTestResult(false, getName() + ": failed length test");
            }

            for (int i = 0; i != req.length; i++)
            {
                if (bytes[i] != req[i])
                {
                    return new SimpleTestResult(false, getName() + ": failed comparison test");
                }
            }
           
            TestResult res = valueCheck(PKCSObjectIdentifiers.pkcs_9_at_contentType.getId());
            if (!res.isSuccessful())
            {
                return res;
            }
           
            res = valueCheck("1.1.127.32512.8323072.2130706432.545460846592.139637976727552.35747322042253312.9151314442816847872");
            if (!res.isSuccessful())
            {
                return res;
            }
        }
        catch (Exception e)
        {
            return new SimpleTestResult(false, getName() + ": Exception - " + e.toString());
        }

        return new SimpleTestResult(true, getName() + ": Okay");
    }
View Full Code Here


            X509CertificateStructure    obj = new X509CertificateStructure(seq);
            TBSCertificateStructure     tbsCert = obj.getTBSCertificate();
           
            if (!tbsCert.getSubject().toString().equals(subjects[id - 1]))
            {
                return new SimpleTestResult(false, getName() + ": failed subject test for certificate id " + id);
            }
           
            if (tbsCert.getVersion() == 3)
            {
                X509Extensions                ext = tbsCert.getExtensions();
                if (ext != null)
                {
                    Enumeration    en = ext.oids();
                    while (en.hasMoreElements())
                    {
                        DERObjectIdentifier    oid = (DERObjectIdentifier)en.nextElement();
                        X509Extension            extVal = ext.getExtension(oid);
                       
                        ASN1OctetString        oct = extVal.getValue();
                        ASN1InputStream        extIn = new ASN1InputStream(new ByteArrayInputStream(oct.getOctets()));
                       
                        if (oid.equals(X509Extensions.SubjectKeyIdentifier))
                        {
                            SubjectKeyIdentifier si = SubjectKeyIdentifier.getInstance(extIn.readObject());
                        }
                        else if (oid.equals(X509Extensions.KeyUsage))
                        {
                            DERBitString ku = KeyUsage.getInstance(extIn.readObject());
                        }
                        else if (oid.equals(X509Extensions.ExtendedKeyUsage))
                        {
                            ExtendedKeyUsage ku = ExtendedKeyUsage.getInstance(extIn.readObject());
                           
                            ASN1Sequence    sq = (ASN1Sequence)ku.getDERObject();
                            for (int i = 0; i != sq.size(); i++)
                            {
                                DERObjectIdentifier    p = KeyPurposeId.getInstance(sq.getObjectAt(i));
                            }
                        }
                        else if (oid.equals(X509Extensions.SubjectAlternativeName))
                        {
                            GeneralNames    gn = GeneralNames.getInstance(extIn.readObject());
                           
                            ASN1Sequence    sq = (ASN1Sequence)gn.getDERObject();
                            for (int i = 0; i != sq.size(); i++)
                            {
                                GeneralName    n = GeneralName.getInstance(sq.getObjectAt(i));
                            }
                        }
                        else if (oid.equals(X509Extensions.IssuerAlternativeName))
                        {
                            GeneralNames    gn = GeneralNames.getInstance(extIn.readObject());
                           
                            ASN1Sequence    sq = (ASN1Sequence)gn.getDERObject();
                            for (int i = 0; i != sq.size(); i++)
                            {
                                GeneralName    n = GeneralName.getInstance(sq.getObjectAt(i));
                            }
                        }
                        else if (oid.equals(X509Extensions.CRLDistributionPoints))
                        {
                            CRLDistPoint    p = CRLDistPoint.getInstance(extIn.readObject());
                           
                            DistributionPoint[] points = p.getDistributionPoints();
                            for (int i = 0; i != points.length; i++)
                            {
                                ;
                            }
                        }
                        else if (oid.equals(X509Extensions.CertificatePolicies))
                        {
                            ASN1Sequence    cp = (ASN1Sequence)extIn.readObject();
                           
                            for (int i = 0; i != cp.size(); i++)
                            {
                                PolicyInformation.getInstance(cp.getObjectAt(i));
                            }
                        }
                        else if (oid.equals(X509Extensions.AuthorityKeyIdentifier))
                        {
                            AuthorityKeyIdentifier    auth = AuthorityKeyIdentifier.getInstance(extIn.readObject());
                        }
                        else if (oid.equals(X509Extensions.BasicConstraints))
                        {
                            BasicConstraints    bc = BasicConstraints.getInstance(extIn.readObject());
                        }
                        else
                        {
                            //System.out.println(oid.getId());
                        }
                    }
                }
            }
        }
        catch (Exception e)
        {
            e.printStackTrace();
            return new SimpleTestResult(false, dump + System.getProperty("line.separator") + getName() + ": " + id + " failed - exception " + e.toString());
        }

        return new SimpleTestResult(true, getName() + ": " + id + " Okay");
    }
View Full Code Here

            // Version
            if (!(acInfo.getVersion().equals(new DERInteger(1)))
                    && (!(acInfo.getVersion().equals(new DERInteger(2)))))
            {
                return new SimpleTestResult(false,
                        "failed AC Version test for id " + id);
            }

            // Holder
            Holder h = acInfo.getHolder();
            if (h == null)
            {
                return new SimpleTestResult(false,
                        "failed AC Holder test, it's null, for id " + id);
            }

            // Issuer
            AttCertIssuer aci = acInfo.getIssuer();
            if (aci == null)
            {
                return new SimpleTestResult(false,
                        "failed AC Issuer test, it's null, for id " + id);
            }

            // Signature
            AlgorithmIdentifier sig = acInfo.getSignature();
            if (sig == null)
            {
                return new SimpleTestResult(false,
                        "failed AC Signature test for id " + id);
            }

            // Serial
            DERInteger serial = acInfo.getSerialNumber();

            // Validity
            AttCertValidityPeriod validity = acInfo.getAttrCertValidityPeriod();
            if (validity == null)
            {
                return new SimpleTestResult(false,
                        "failed AC AttCertValidityPeriod test for id " + id);
            }

            // Attributes
            ASN1Sequence attribSeq = acInfo.getAttributes();
            Attribute att[] = new Attribute[attribSeq.size()];
            for (int i = 0; i < attribSeq.size(); i++)
            {
                att[i] = Attribute.getInstance(attribSeq.getObjectAt(i));
            }

            // IssuerUniqueId
            // TODO, how to best test?

            // X509 Extensions
            X509Extensions ext = acInfo.getExtensions();
            if (ext != null)
            {
                Enumeration en = ext.oids();
                while (en.hasMoreElements())
                {
                    DERObjectIdentifier oid = (DERObjectIdentifier) en
                            .nextElement();
                    X509Extension extVal = ext.getExtension(oid);
                }
            }

        }
        catch (Exception e)
        {
            e.printStackTrace();
            return new SimpleTestResult(false, dump
                    + System.getProperty("line.separator") + getName() + ": "
                    + id + " failed - exception " + e.toString());
        }

        return new SimpleTestResult(true, getName() + ": " + id + " Okay");
    }
View Full Code Here

  if (!res.isSuccessful())
  {
      return res;
  }

        return new SimpleTestResult(true, getName() + ": Okay");
    }
View Full Code Here

           
            DERObject[] readValues = new DERObject[values.length];
           
            if (!isSameAs(bOut.toByteArray(), data))
            {
                return new SimpleTestResult(false, getName() + ": Failed data check");
            }
           
            ByteArrayInputStream    bIn = new ByteArrayInputStream(bOut.toByteArray());
            ASN1InputStream         aIn = new ASN1InputStream(bIn);
           
            for (int i = 0; i != values.length; i++)
            {
                DERObject   o = aIn.readObject();
                if (!values[i].equals(o))
                {
                    return new SimpleTestResult(false, getName() + ": Failed equality test for " + o);
                }
               
                if (o.hashCode() != values[i].hashCode())
                {
                    return new SimpleTestResult(false, getName() + ": Failed hashCode test for " + o);
                }
            }
           
            return new SimpleTestResult(true, getName() + ": Okay");
        }
        catch (Exception e)
        {
            return new SimpleTestResult(false, getName() + ": Failed - exception " + e.toString(), e);
        }
    }
View Full Code Here

       
        try
        {
            if (!isSameAs(attr.getEncoded(), attrBytes))
            {
                return new SimpleTestResult(false, getName() + ": Failed attr data check");
            }
           
            ByteArrayInputStream    bIn = new ByteArrayInputStream(attrBytes);
            ASN1InputStream         aIn = new ASN1InputStream(bIn);
           
            DERObject   o = aIn.readObject();
            if (!attr.equals(o))
            {
                return new SimpleTestResult(false, getName() + ": Failed equality test for attr");
            }
           
            if (!isSameAs(pref.getEncoded(), prefBytes))
            {
                return new SimpleTestResult(false, getName() + ": Failed attr data check");
            }
           
            bIn = new ByteArrayInputStream(prefBytes);
            aIn = new ASN1InputStream(bIn);
           
            o = aIn.readObject();
            if (!pref.equals(o))
            {
                return new SimpleTestResult(false, getName() + ": Failed equality test for pref");
            }
           
            return new SimpleTestResult(true, getName() + ": Okay");
        }
        catch (Exception e)
        {
            return new SimpleTestResult(false, getName() + ": Failed - exception " + e.toString(), e);
        }
    }
View Full Code Here

        {
            info = new EncryptedPrivateKeyInfo((ASN1Sequence)aIn.readObject());
        }
        catch (Exception e)
        {
            return new SimpleTestResult(false, getName() + ": test " + id + " failed construction - exception " + e.toString());
        }
   
        ByteArrayOutputStream   bOut = new ByteArrayOutputStream();
        DEROutputStream         dOut = new DEROutputStream(bOut);

        try
        {
            dOut.writeObject(info);
        }
        catch (Exception e)
        {
            return new SimpleTestResult(false, getName() + ": test " + id + " failed writing - exception " + e.toString());
        }

        byte[]  bytes = bOut.toByteArray();

        if (bytes.length != sample.length)
        {
            try
            {
                bIn = new ByteArrayInputStream(bytes);
                aIn = new ASN1InputStream(bIn);

                DERObject   obj = aIn.readObject();
   
                return new SimpleTestResult(false, getName() + ": test " + id + " length mismatch - expected " + sample.length + System.getProperty("line.separator") + ASN1Dump.dumpAsString(info) + " got " + bytes.length + System.getProperty("line.separator") + ASN1Dump.dumpAsString(obj));
            }
            catch (Exception e)
            {
                e.printStackTrace();
                return new SimpleTestResult(false, getName() + ": test " + id + " length mismatch - exception " + e.toString());
            }
        }

        for (int i = 0; i != bytes.length; i++)
        {
            if (bytes[i] != sample[i])
            {
                return new SimpleTestResult(false, getName() + ": test " + id + " data mismatch");
            }
        }

        return new SimpleTestResult(true, getName() + ": test " + id + " Okay");
    }
View Full Code Here

        if (!result.isSuccessful())
        {
            return result;
        }

        return new SimpleTestResult(true, getName() + ": Okay");
    }
View Full Code Here

            {
                DERGeneralizedTime    t = new DERGeneralizedTime(input[i]);

                if (!t.getTime().equals(output[i]))
                {
                    return new SimpleTestResult(false, getName() + ": failed conversion test");
                }
            }
        }
        catch (Exception e)
        {
            return new SimpleTestResult(false, getName() + ": Exception - " + e.toString());
        }

        return new SimpleTestResult(true, getName() + ": Okay");
    }
View Full Code Here

            sig.update(data);

            if (!sig.verify(sigBytes))
            {
                return new SimpleTestResult(false, "SHA1 verification failed");
            }

            sig = Signature.getInstance("MD2WithRSAEncryption", "BC");

            sig.initSign(signingKey);

            sig.update(data);

            sigBytes = sig.sign();

            sig.initVerify(verifyKey);

            sig.update(data);

            if (!sig.verify(sigBytes))
            {
                return new SimpleTestResult(false, "MD2 verification failed");
            }

            sig = Signature.getInstance("MD5WithRSAEncryption", "BC");

            sig.initSign(signingKey);

            sig.update(data);

            sigBytes = sig.sign();

            sig.initVerify(verifyKey);

            sig.update(data);

            if (!sig.verify(sigBytes))
            {
                return new SimpleTestResult(false, "MD5 verification failed");
            }

            sig = Signature.getInstance("RIPEMD160WithRSAEncryption", "BC");

            sig.initSign(signingKey);

            sig.update(data);

            sigBytes = sig.sign();

            sig.initVerify(verifyKey);

            sig.update(data);

            if (!sig.verify(sigBytes))
            {
                return new SimpleTestResult(false, "RIPEMD160 verification failed");
            }

            //
            // RIPEMD-128
            //
            sig = Signature.getInstance("RIPEMD128WithRSAEncryption", "BC");

            sig.initSign(signingKey);

            sig.update(data);

            sigBytes = sig.sign();

            sig.initVerify(verifyKey);

            sig.update(data);

            if (!sig.verify(sigBytes))
            {
                return new SimpleTestResult(false, "RIPEMD128 verification failed");
            }

            //
            // RIPEMD256
            //
            sig = Signature.getInstance("RIPEMD256WithRSAEncryption", "BC");

            sig.initSign(signingKey);

            sig.update(data);

            sigBytes = sig.sign();

            sig.initVerify(verifyKey);

            sig.update(data);

            if (!sig.verify(sigBytes))
            {
                return new SimpleTestResult(false, "RIPEMD256 verification failed");
            }

            //
            // SHA-224
            //
            sig = Signature.getInstance("SHA224WithRSAEncryption", "BC");

            sig.initSign(signingKey);

            sig.update(data);

            sigBytes = sig.sign();

            sig.initVerify(verifyKey);

            sig.update(data);

            if (!sig.verify(sigBytes))
            {
                return new SimpleTestResult(false, "SHA224 verification failed");
            }
           
            //
            // SHA-256
            //
            sig = Signature.getInstance("SHA256WithRSAEncryption", "BC");

            sig.initSign(signingKey);

            sig.update(data);

            sigBytes = sig.sign();

            sig.initVerify(verifyKey);

            sig.update(data);

            if (!sig.verify(sigBytes))
            {
                return new SimpleTestResult(false, "SHA256 verification failed");
            }
           
            //
            // SHA-384
            //
            sig = Signature.getInstance("SHA384WithRSAEncryption", "BC");

            sig.initSign(signingKey);

            sig.update(data);

            sigBytes = sig.sign();

            sig.initVerify(verifyKey);

            sig.update(data);

            if (!sig.verify(sigBytes))
            {
                return new SimpleTestResult(false, "SHA384 verification failed");
            }
           
            //
            // SHA-512
            //
            sig = Signature.getInstance("SHA512WithRSAEncryption", "BC");

            sig.initSign(signingKey);

            sig.update(data);

            sigBytes = sig.sign();

            sig.initVerify(verifyKey);

            sig.update(data);

            if (!sig.verify(sigBytes))
            {
                return new SimpleTestResult(false, "SHA512 verification failed");
            }

            //
            // ISO Sigs.
            //
            sig = Signature.getInstance("MD5WithRSA/ISO9796-2", "BC");

            sig.initSign(signingKey);

            sig.update(data);

            sigBytes = sig.sign();

            sig.initVerify(verifyKey);

            sig.update(data);

            if (!sig.verify(sigBytes))
            {
                return new SimpleTestResult(false, "MD5/ISO verification failed");
            }

            sig = Signature.getInstance("SHA1WithRSA/ISO9796-2", "BC");

            sig.initSign(signingKey);

            sig.update(data);

            sigBytes = sig.sign();

            sig.initVerify(verifyKey);

            sig.update(data);

            if (!sig.verify(sigBytes))
            {
                return new SimpleTestResult(false, "SHA1/ISO verification failed");
            }

            sig = Signature.getInstance("RIPEMD160WithRSA/ISO9796-2", "BC");

            sig.initSign(signingKey);

            sig.update(data);

            sigBytes = sig.sign();

            sig.initVerify(verifyKey);

            sig.update(data);

            if (!sig.verify(sigBytes))
            {
                return new SimpleTestResult(false, "RIPEMD160/ISO verification failed");
            }

            //
            // standard vector test - B.1.3 RIPEMD160, implicit.
            //
            BigInteger  mod = new BigInteger("ffffffff78f6c55506c59785e871211ee120b0b5dd644aa796d82413a47b24573f1be5745b5cd9950f6b389b52350d4e01e90009669a8720bf265a2865994190a661dea3c7828e2e7ca1b19651adc2d5", 16);
            BigInteger  pub = new BigInteger("03", 16);
            BigInteger  pri = new BigInteger("2aaaaaaa942920e38120ee965168302fd0301d73a4e60c7143ceb0adf0bf30b9352f50e8b9e4ceedd65343b2179005b2f099915e4b0c37e41314bb0821ad8330d23cba7f589e0f129b04c46b67dfce9d", 16);

            KeyFactory  f = KeyFactory.getInstance("RSA", "BC");

            PrivateKey  privKey = f.generatePrivate(new RSAPrivateKeySpec(mod, pri));
            PublicKey   pubKey = f.generatePublic(new RSAPublicKeySpec(mod, pub));
            byte[]      testSig = Hex.decode("5cf9a01854dbacaec83aae8efc563d74538192e95466babacd361d7c86000fe42dcb4581e48e4feb862d04698da9203b1803b262105104d510b365ee9c660857ba1c001aa57abfd1c8de92e47c275cae");

            data = Hex.decode("fedcba9876543210fedcba9876543210fedcba9876543210fedcba9876543210fedcba9876543210fedcba9876543210fedcba9876543210fedcba9876543210fedcba9876543210fedcba9876543210fedcba9876543210fedcba9876543210fedcba9876543210fedcba9876543210");

            sig = Signature.getInstance("RIPEMD160WithRSA/ISO9796-2", "BC");

            sig.initSign(privKey);

            sig.update(data);

            sigBytes = sig.sign();

            if (!isEqualTo(testSig, sigBytes))
            {
                return new SimpleTestResult(false, "SigTest: failed ISO9796-2 generation Test");
            }

            sig.initVerify(pubKey);

            sig.update(data);

            if (!sig.verify(sigBytes))
            {
                return new SimpleTestResult(false, "RIPEMD160/ISO verification failed");
            }

            return new SimpleTestResult(true, getName() + ": Okay");
        }
        catch (Exception e)
        {
            return new SimpleTestResult(false, getName() + ": exception - " + e.toString());
        }
    }
View Full Code Here

TOP

Related Classes of org.bouncycastle.util.test.SimpleTestResult

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.