Search in sources :

Example 6 with PublicKeyStub

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

the class SignerTest method testGetPrivateKey.

/**
     * verify Signer.getPrivateKey() returns null or private key
     */
public void testGetPrivateKey() throws Exception {
    byte[] privateKeyData = { 1, 2, 3, 4, 5 };
    PrivateKeyStub privateKey = new PrivateKeyStub("private", "fff", privateKeyData);
    PublicKeyStub publicKey = new PublicKeyStub("public", "fff", null);
    KeyPair kp = new KeyPair(publicKey, privateKey);
    Signer s = new SignerStub("sss5");
    assertNull(s.getPrivateKey());
    s.setKeyPair(kp);
    assertSame(privateKey, s.getPrivateKey());
}
Also used : Signer(java.security.Signer) KeyPair(java.security.KeyPair) PrivateKeyStub(org.apache.harmony.security.tests.support.PrivateKeyStub) SignerStub(org.apache.harmony.security.tests.support.SignerStub) PublicKeyStub(org.apache.harmony.security.tests.support.PublicKeyStub)

Example 7 with PublicKeyStub

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

the class SignerTest method test_toString.

/**
     * java.security.Signer#toString()
     */
public void test_toString() throws Exception {
    Signer s1 = new SignerStub("testToString1");
    assertEquals("[Signer]testToString1", s1.toString());
    Signer s2 = new SignerStub("testToString2", IdentityScope.getSystemScope());
    s2.toString();
    KeyPair kp = new KeyPair(new PublicKeyStub("public", "SignerTest.testToString", null), new PrivateKeyStub("private", "SignerTest.testToString", null));
    s1.setKeyPair(kp);
    s1.toString();
    s2.setKeyPair(kp);
    s2.toString();
}
Also used : Signer(java.security.Signer) KeyPair(java.security.KeyPair) PrivateKeyStub(org.apache.harmony.security.tests.support.PrivateKeyStub) SignerStub(org.apache.harmony.security.tests.support.SignerStub) PublicKeyStub(org.apache.harmony.security.tests.support.PublicKeyStub)

Example 8 with PublicKeyStub

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

the class IdentityTest method testGetPublicKey.

/**
     * verify Identity.getPublicKey() returns public key
     */
public void testGetPublicKey() throws Exception {
    Identity i = new IdentityStub("testGetPublicKey");
    assertNull(i.getPublicKey());
    PublicKey pk = new PublicKeyStub("kkk", "Identity.testGetPublicKey", null);
    i.setPublicKey(pk);
    assertSame(pk, i.getPublicKey());
}
Also used : IdentityStub(org.apache.harmony.security.tests.support.IdentityStub) PublicKey(java.security.PublicKey) PublicKeyStub(org.apache.harmony.security.tests.support.PublicKeyStub) Identity(java.security.Identity)

Example 9 with PublicKeyStub

use of org.apache.harmony.security.tests.support.PublicKeyStub 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

PublicKeyStub (org.apache.harmony.security.tests.support.PublicKeyStub)9 Identity (java.security.Identity)7 IdentityStub (org.apache.harmony.security.tests.support.IdentityStub)7 CertificateStub (org.apache.harmony.security.tests.support.CertificateStub)4 KeyManagementException (java.security.KeyManagementException)2 KeyPair (java.security.KeyPair)2 PublicKey (java.security.PublicKey)2 Signer (java.security.Signer)2 PrivateKeyStub (org.apache.harmony.security.tests.support.PrivateKeyStub)2 SignerStub (org.apache.harmony.security.tests.support.SignerStub)2