Search in sources :

Example 1 with CertificateStub

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

the class IdentityTest method testAddCertificate1.

/**
     * verify addCertificate(Certificate certificate) adds a certificate for this identity.
     * If the identity has a public key, the public key in the certificate must be the same
     *
     */
public void testAddCertificate1() throws Exception {
    Identity i = new IdentityStub("iii");
    PublicKeyStub pk1 = new PublicKeyStub("kkk", "fff", new byte[] { 1, 2, 3, 4, 5 });
    i.setPublicKey(pk1);
    // try with the same key
    CertificateStub c1 = new CertificateStub("fff", null, null, pk1);
    i.addCertificate(c1);
    assertSame(c1, i.certificates()[0]);
    // try Certificate with different key
    try {
        i.addCertificate(new CertificateStub("ccc", null, null, new PublicKeyStub("k2", "fff", new byte[] { 6, 7, 8, 9, 0 })));
        fail("KeyManagementException should be thrown");
    } catch (KeyManagementException ok) {
    }
}
Also used : IdentityStub(org.apache.harmony.security.tests.support.IdentityStub) CertificateStub(org.apache.harmony.security.tests.support.CertificateStub) PublicKeyStub(org.apache.harmony.security.tests.support.PublicKeyStub) Identity(java.security.Identity) KeyManagementException(java.security.KeyManagementException)

Example 2 with CertificateStub

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

the class IdentityTest method testSetPublicKey4.

//
//  Commented out since there will no be fix for the test failure
//    /**
//     *
//     * verify Identity.setPublicKey() throws KeyManagementException if key is already used
//     *
//     */
//    public void testSetPublicKey3() throws Exception {
//        Identity i1 = new IdentityStub("testSetPublicKey3_1", IdentityScope.getSystemScope());
//        Identity i2 = new IdentityStub("testSetPublicKey3_2", IdentityScope.getSystemScope());
//        PublicKey pk = new PublicKeyStub("kkk", "fff", new byte[]{1,2,3,4,5});
//        i1.setPublicKey(pk);
//        try {
//            i2.setPublicKey(pk);
//            fail("KeyManagementException should be thrown - key already used");
//        } catch (KeyManagementException ok) {};
//    }
/**
     *
     * verify Identity.setPublicKey()  removes old key and all identity's certificates
     *
     */
public void testSetPublicKey4() throws Exception {
    Identity i = new IdentityStub("testSetPublicKey4");
    PublicKeyStub pk1 = new PublicKeyStub("kkk", "Identity.testSetPublicKey4", null);
    CertificateStub c1 = new CertificateStub("fff", null, null, pk1);
    CertificateStub c2 = new CertificateStub("zzz", null, null, pk1);
    i.addCertificate(c1);
    i.addCertificate(c2);
    assertEquals(2, i.certificates().length);
    assertSame(pk1, i.getPublicKey());
    PublicKeyStub pk2 = new PublicKeyStub("zzz", "Identity.testSetPublicKey4", null);
    i.setPublicKey(pk2);
    assertSame(pk2, i.getPublicKey());
    assertEquals(0, i.certificates().length);
}
Also used : IdentityStub(org.apache.harmony.security.tests.support.IdentityStub) CertificateStub(org.apache.harmony.security.tests.support.CertificateStub) PublicKeyStub(org.apache.harmony.security.tests.support.PublicKeyStub) Identity(java.security.Identity)

Example 3 with CertificateStub

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

the class IdentityTest method testAddCertificate2.

/**
     * verify addCertificate(Certificate certificate) adds a certificate for this identity.
     * if the identity does not have a public key, the identity's public key is set to be that specified in the certificate.
     */
public void testAddCertificate2() throws Exception {
    Identity i = new IdentityStub("iii");
    PublicKeyStub pk1 = new PublicKeyStub("kkk", "fff", null);
    CertificateStub c1 = new CertificateStub("fff", null, null, pk1);
    i.addCertificate(c1);
    assertSame(c1, i.certificates()[0]);
    assertSame(pk1, i.getPublicKey());
}
Also used : IdentityStub(org.apache.harmony.security.tests.support.IdentityStub) CertificateStub(org.apache.harmony.security.tests.support.CertificateStub) PublicKeyStub(org.apache.harmony.security.tests.support.PublicKeyStub) Identity(java.security.Identity)

Example 4 with CertificateStub

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

the class IdentityTest method testCertificates.

//
//  Commented out since there will no be fix for the test failure
//    /**
//     * verify removeCertificate(Certificate certificate) removes certificate
//     */
//    public void testRemoveCertificate1() throws Exception{
//        Identity i = new IdentityStub("iii");
//        PublicKeyStub pk1 = new PublicKeyStub("kkk", "fff", null);
//        CertificateStub c1 = new CertificateStub("fff", null, null, pk1);
//        i.addCertificate(c1);
//        assertSame(c1, i.certificates()[0]);
//        i.removeCertificate(c1);
//        assertEquals(0, i.certificates().length);
//        // throw KeyManagementException if certificate not found
//        try {
//            i.removeCertificate(c1);
//            fail("KeyManagementException should be thrown");
//        } catch (KeyManagementException ok) {
//        }
//        try {
//            i.removeCertificate(null);
//            fail("KeyManagementException should be thrown");
//        } catch (KeyManagementException ok) {
//
//        }
//    }
/**
     * verify certificates() returns a copy of all certificates for this identity
     */
public void testCertificates() throws Exception {
    Identity i = new IdentityStub("iii");
    PublicKeyStub pk1 = new PublicKeyStub("kkk", "fff", null);
    CertificateStub c1 = new CertificateStub("fff", null, null, pk1);
    CertificateStub c2 = new CertificateStub("zzz", null, null, pk1);
    i.addCertificate(c1);
    i.addCertificate(c2);
    java.security.Certificate[] s = i.certificates();
    assertEquals(2, s.length);
    assertTrue(c1.equals(s[0]) || c2.equals(s[0]));
    assertTrue(c1.equals(s[1]) || c2.equals(s[1]));
    s[0] = null;
    s[1] = null;
    // check that the copy was modified
    s = i.certificates();
    assertEquals(2, s.length);
    assertTrue(c1.equals(s[0]) || c2.equals(s[0]));
    assertTrue(c1.equals(s[1]) || c2.equals(s[1]));
}
Also used : IdentityStub(org.apache.harmony.security.tests.support.IdentityStub) CertificateStub(org.apache.harmony.security.tests.support.CertificateStub) PublicKeyStub(org.apache.harmony.security.tests.support.PublicKeyStub) Identity(java.security.Identity)

Aggregations

Identity (java.security.Identity)4 CertificateStub (org.apache.harmony.security.tests.support.CertificateStub)4 IdentityStub (org.apache.harmony.security.tests.support.IdentityStub)4 PublicKeyStub (org.apache.harmony.security.tests.support.PublicKeyStub)4 KeyManagementException (java.security.KeyManagementException)1