use of java.security.cert.TrustAnchor in project robovm by robovm.
the class TrustAnchorTest method testTrustAnchorX509CertificatebyteArray03.
/**
* Test #3 for <code>TrustAnchor(X509Certificate, byte[])</code>
* constructor<br>
* Assertion: creates <code>TrustAnchor</code> instance<br>
* Test preconditions: <code>null</code> as nameConstraints passed<br>
* Expected: must pass without any exceptions
*/
public final void testTrustAnchorX509CertificatebyteArray03() throws Exception {
CertificateFactory certFact = CertificateFactory.getInstance("X509");
X509Certificate pemCert = (X509Certificate) certFact.generateCertificate(new ByteArrayInputStream(TestUtils.getX509Certificate_v3()));
try {
new TrustAnchor(pemCert, null);
} catch (Exception e) {
fail("Unexpected exeption " + e.getMessage());
}
}
use of java.security.cert.TrustAnchor in project robovm by robovm.
the class TrustAnchorTest method testGetTrustedCer02.
/**
* Test #2 for <code>getCAName()</code> method<br>
*
* Assertion: returns ... <code>null</code> if <code>TrustAnchor</code>
* was not specified as trusted certificate<br>
* Test preconditions: test object is not specified as trusted certificate<br>
* Expected: <code>null</code> as return value<br>
* @throws InvalidKeySpecException
*/
public final void testGetTrustedCer02() throws Exception {
PublicKey pk = new TestKeyPair(keyAlg).getPublic();
// sub testcase 1
TrustAnchor ta = new TrustAnchor(validCaNameRfc2253, pk, null);
assertNull("null1", ta.getTrustedCert());
// sub testcase 2
X500Principal x500p = new X500Principal(validCaNameRfc2253);
ta = new TrustAnchor(x500p, pk, null);
assertNull("null2", ta.getTrustedCert());
X509Certificate cert = new TestCertUtils.TestX509Certificate(x500p, x500p);
TrustAnchor ta2 = new TrustAnchor(cert, null);
assertSame(cert, ta2.getTrustedCert());
}
use of java.security.cert.TrustAnchor in project robovm by robovm.
the class TrustAnchorTest method testToString.
/**
* Test #1 for <code>toString()</code> method<br>
*
* Assertion: returns a formatted string describing the TrustAnchor<br>
* Test preconditions: valid parameters are passed to the constructors<br>
* Expected: not null string<br>
*/
public final void testToString() throws Exception {
PublicKey pk = new TestKeyPair(keyAlg).getPublic();
TrustAnchor ta1 = new TrustAnchor(validCaNameRfc2253, pk, getFullEncoding());
assertNotNull(ta1.toString());
X500Principal x500p = new X500Principal(validCaNameRfc2253);
TrustAnchor ta2 = new TrustAnchor(x500p, pk, getEncodingNoMinMax());
assertNotNull(ta2.toString());
CertificateFactory certFact = CertificateFactory.getInstance("X509");
X509Certificate pemCert = (X509Certificate) certFact.generateCertificate(new ByteArrayInputStream(TestUtils.getX509Certificate_v3()));
TrustAnchor ta3 = new TrustAnchor(pemCert, getEncodingPSOnly());
assertNotNull(ta3.toString());
}
use of java.security.cert.TrustAnchor in project robovm by robovm.
the class TrustAnchorTest method testTrustAnchorStringPublicKeybyteArray04.
/**
* Test #4 for <code>TrustAnchor(String, PublicKey, byte[])</code> constructor<br>
* Assertion: <code>NullPointerException</code> if <code>caName</code>
* or <code>caPublicKey</code> parameter is <code>null</code><br>
* Test preconditions: pass <code>null</code> as mentioned parameter<br>
* Expected: NullPointerException
*/
public final void testTrustAnchorStringPublicKeybyteArray04() throws Exception {
PublicKey pk = new TestKeyPair(keyAlg).getPublic();
// sub testcase 1: 'caName' param is null
try {
new TrustAnchor((String) null, pk, getEncodingPSOnly());
fail("NullPointerException has not been thrown");
} catch (NullPointerException ok) {
}
// sub testcase 2: 'caPublicKey' param is null
try {
new TrustAnchor(validCaNameRfc2253, null, getEncodingPSOnly());
fail("NullPointerException has not been thrown");
} catch (NullPointerException ok) {
}
// sub testcase 3: 'caName' and 'caPublicKey' params are null
try {
new TrustAnchor((String) null, null, getEncodingPSOnly());
fail("NullPointerException has not been thrown");
} catch (NullPointerException ok) {
}
// sub testcase 4: 'caName' param is empty
try {
new TrustAnchor("", pk, getEncodingPSOnly());
fail("IllegalArgumentException has not been thrown");
} catch (IllegalArgumentException ok) {
}
// sub testcase 5: 'caName' param is incorrect distinguished name
try {
new TrustAnchor("AID.11.12=A", pk, getEncodingPSOnly());
fail("IllegalArgumentException has not been thrown");
} catch (IllegalArgumentException ok) {
}
}
use of java.security.cert.TrustAnchor in project robovm by robovm.
the class TrustAnchorTest method testTrustAnchorX509CertificatebyteArray01.
/**
* Test #1 for <code>TrustAnchor(X509Certificate, byte[])</code>
* constructor<br>
* Assertion: creates <code>TrustAnchor</code> instance<br>
* Test preconditions: valid parameters passed<br>
* Expected: must pass without any exceptions
*/
public final void testTrustAnchorX509CertificatebyteArray01() throws CertificateException {
CertificateFactory certFact = CertificateFactory.getInstance("X509");
X509Certificate pemCert = (X509Certificate) certFact.generateCertificate(new ByteArrayInputStream(TestUtils.getX509Certificate_v3()));
// sub testcase 1
TrustAnchor ta1 = new TrustAnchor(pemCert, getFullEncoding());
assertNull(ta1.getCA());
assertNull(ta1.getCAName());
assertNull(ta1.getCAPublicKey());
assertTrue(Arrays.equals(getFullEncoding(), ta1.getNameConstraints()));
assertEquals(pemCert, ta1.getTrustedCert());
// sub testcase 2
TrustAnchor ta2 = new TrustAnchor(pemCert, getEncodingPSOnly());
assertNull(ta2.getCA());
assertNull(ta2.getCAName());
assertNull(ta2.getCAPublicKey());
assertTrue(Arrays.equals(getEncodingPSOnly(), ta2.getNameConstraints()));
assertEquals(pemCert, ta2.getTrustedCert());
// sub testcase 3
TrustAnchor ta3 = new TrustAnchor(pemCert, getEncodingESOnly());
assertNull(ta3.getCA());
assertNull(ta3.getCAName());
assertNull(ta3.getCAPublicKey());
assertTrue(Arrays.equals(getEncodingESOnly(), ta3.getNameConstraints()));
assertEquals(pemCert, ta3.getTrustedCert());
// sub testcase 4
TrustAnchor ta4 = new TrustAnchor(pemCert, getEncodingNoMinMax());
assertNull(ta4.getCA());
assertNull(ta4.getCAName());
assertNull(ta4.getCAPublicKey());
assertTrue(Arrays.equals(getEncodingNoMinMax(), ta4.getNameConstraints()));
assertEquals(pemCert, ta4.getTrustedCert());
}
Aggregations