Search in sources :

Example 16 with MyCertificate

use of org.apache.harmony.security.tests.support.cert.MyCertificate in project robovm by robovm.

the class CertificateTest method testGetEncoded.

// the following tests just call methods
// that are abstract in <code>Certificate</code>
// (So they just like signature tests)
/**
     * This test just calls <code>getEncoded()</code> method<br>
     * @throws CertificateException
     */
public final void testGetEncoded() throws CertificateException {
    Certificate c1 = new MyCertificate("TEST_TYPE", testEncoding);
    assertNotNull(c1.getEncoded());
    assertTrue(Arrays.equals(testEncoding, c1.getEncoded()));
    CertificateFactory cf = CertificateFactory.getInstance("X.509");
    byte[] expectedEncoding = cert.getEncoded();
    Certificate actual = cf.generateCertificate(new ByteArrayInputStream(expectedEncoding));
    byte[] actualEncoding = actual.getEncoded();
    assertTrue(Arrays.equals(expectedEncoding, actualEncoding));
    assertFalse(expectedEncoding[4] == 200);
    expectedEncoding[4] = (byte) 200;
    try {
        cf.generateCertificate(new ByteArrayInputStream(expectedEncoding));
        fail();
    } catch (CertificateException expected) {
    }
}
Also used : MyCertificate(org.apache.harmony.security.tests.support.cert.MyCertificate) ByteArrayInputStream(java.io.ByteArrayInputStream) CertificateException(java.security.cert.CertificateException) CertificateFactory(java.security.cert.CertificateFactory) Certificate(java.security.cert.Certificate) MyCertificate(org.apache.harmony.security.tests.support.cert.MyCertificate) MyFailingCertificate(org.apache.harmony.security.tests.support.cert.MyFailingCertificate)

Example 17 with MyCertificate

use of org.apache.harmony.security.tests.support.cert.MyCertificate in project robovm by robovm.

the class CertificateTest method testVerifyPublicKey2.

/**
     * This test just calls <code>verify(PublicKey)</code> method<br>
     *
     * @throws InvalidKeyException
     * @throws CertificateException
     * @throws NoSuchAlgorithmException
     * @throws NoSuchProviderException
     * @throws SignatureException
     * @throws IOException
     * @throws InvalidAlgorithmParameterException
     */
public final void testVerifyPublicKey2() throws InvalidKeyException, CertificateException, NoSuchAlgorithmException, NoSuchProviderException, SignatureException, InvalidAlgorithmParameterException, IOException {
    Certificate c1 = new MyCertificate("TEST_TYPE", testEncoding);
    c1.verify(null);
    cert.verify(cert.getPublicKey());
    PublicKey k = cert.getPublicKey();
    MyModifiablePublicKey changedEncoding = new MyModifiablePublicKey(k);
    changedEncoding.setEncoding(new byte[cert.getEncoded().length - 1]);
    try {
        cert.verify(c1.getPublicKey());
        fail();
    } catch (InvalidKeyException expected) {
    }
    try {
        cert.verify(changedEncoding);
        fail();
    } catch (Exception expected) {
    }
}
Also used : MyCertificate(org.apache.harmony.security.tests.support.cert.MyCertificate) PublicKey(java.security.PublicKey) InvalidKeyException(java.security.InvalidKeyException) SignatureException(java.security.SignatureException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) ObjectStreamException(java.io.ObjectStreamException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeyException(java.security.InvalidKeyException) NoSuchProviderException(java.security.NoSuchProviderException) CertificateEncodingException(java.security.cert.CertificateEncodingException) Certificate(java.security.cert.Certificate) MyCertificate(org.apache.harmony.security.tests.support.cert.MyCertificate) MyFailingCertificate(org.apache.harmony.security.tests.support.cert.MyFailingCertificate)

Example 18 with MyCertificate

use of org.apache.harmony.security.tests.support.cert.MyCertificate in project robovm by robovm.

the class CertificateTest method testCertificate.

/**
     * Test for <code>Certificate(String type)</code> method<br>
     */
public final void testCertificate() throws Exception {
    Certificate c1 = new MyCertificate("TEST_TYPE", testEncoding);
    assertTrue(Arrays.equals(testEncoding, c1.getEncoded()));
    assertEquals("TEST", c1.getPublicKey().getAlgorithm());
    assertTrue(Arrays.equals(new byte[] { (byte) 1, (byte) 2, (byte) 3 }, c1.getPublicKey().getEncoded()));
    assertEquals("TEST_FORMAT", c1.getPublicKey().getFormat());
    assertEquals("TEST_TYPE", c1.getType());
}
Also used : MyCertificate(org.apache.harmony.security.tests.support.cert.MyCertificate) Certificate(java.security.cert.Certificate) MyCertificate(org.apache.harmony.security.tests.support.cert.MyCertificate) MyFailingCertificate(org.apache.harmony.security.tests.support.cert.MyFailingCertificate)

Example 19 with MyCertificate

use of org.apache.harmony.security.tests.support.cert.MyCertificate in project robovm by robovm.

the class CertificateTest method testGetType.

/**
     * Test for <code>getType()</code> method<br>
     * Assertion: returns this certificate type
     */
public final void testGetType() {
    Certificate c1 = new MyCertificate("TEST_TYPE", testEncoding);
    assertEquals("TEST_TYPE", c1.getType());
}
Also used : MyCertificate(org.apache.harmony.security.tests.support.cert.MyCertificate) Certificate(java.security.cert.Certificate) MyCertificate(org.apache.harmony.security.tests.support.cert.MyCertificate) MyFailingCertificate(org.apache.harmony.security.tests.support.cert.MyFailingCertificate)

Example 20 with MyCertificate

use of org.apache.harmony.security.tests.support.cert.MyCertificate in project robovm by robovm.

the class CertificateTest method testGetPublicKey.

/**
     * This test just calls <code>testGetPublicKey()</code> method<br>
     */
public final void testGetPublicKey() {
    Certificate c1 = new MyCertificate("TEST_TYPE", testEncoding);
    c1.getPublicKey();
}
Also used : MyCertificate(org.apache.harmony.security.tests.support.cert.MyCertificate) Certificate(java.security.cert.Certificate) MyCertificate(org.apache.harmony.security.tests.support.cert.MyCertificate) MyFailingCertificate(org.apache.harmony.security.tests.support.cert.MyFailingCertificate)

Aggregations

MyCertificate (org.apache.harmony.security.tests.support.cert.MyCertificate)32 Certificate (java.security.cert.Certificate)26 MyFailingCertificate (org.apache.harmony.security.tests.support.cert.MyFailingCertificate)15 Vector (java.util.Vector)6 CollectionCertStoreParameters (java.security.cert.CollectionCertStoreParameters)5 ObjectStreamException (java.io.ObjectStreamException)4 CertificateException (java.security.cert.CertificateException)4 KeyStore (java.security.KeyStore)3 CertificateFactory (java.security.cert.CertificateFactory)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 MyCertificateRep (org.apache.harmony.security.tests.support.cert.MyCertificate.MyCertificateRep)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 ObjectOutputStream (java.io.ObjectOutputStream)1 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)1 InvalidKeyException (java.security.InvalidKeyException)1 KeyStoreException (java.security.KeyStoreException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 NoSuchProviderException (java.security.NoSuchProviderException)1 PrivateKey (java.security.PrivateKey)1