use of javax.security.auth.x500.X500Principal in project robovm by robovm.
the class X509CertSelectorTest method test_getSubjectAsBytes.
/**
* java.security.cert.X509CertSelector#getSubjectAsBytes()
*/
public void test_getSubjectAsBytes() throws Exception {
byte[] name1 = new byte[] // manually obtained DER encoding of "O=First Org." issuer name;
{ 48, 21, 49, 19, 48, 17, 6, 3, 85, 4, 10, 19, 10, 70, 105, 114, 115, 116, 32, 79, 114, 103, 46 };
byte[] name2 = new byte[] // manually obtained DER encoding of "O=Second Org." issuer name;
{ 48, 22, 49, 20, 48, 18, 6, 3, 85, 4, 10, 19, 11, 83, 101, 99, 111, 110, 100, 32, 79, 114, 103, 46 };
X500Principal sub1 = new X500Principal(name1);
X500Principal sub2 = new X500Principal(name2);
X509CertSelector selector = new X509CertSelector();
assertNull("Selector should return null", selector.getSubjectAsBytes());
selector.setSubject(sub1);
assertTrue("The returned issuer should be equal to specified", Arrays.equals(name1, selector.getSubjectAsBytes()));
assertFalse("The returned issuer should differ", name2.equals(selector.getSubjectAsBytes()));
selector.setSubject(sub2);
assertTrue("The returned issuer should be equal to specified", Arrays.equals(name2, selector.getSubjectAsBytes()));
}
use of javax.security.auth.x500.X500Principal in project robovm by robovm.
the class X509Certificate2Test method testGetIssuerX500Principal.
public void testGetIssuerX500Principal() {
// return valid encoding
MyX509Certificate cert = new MyX509Certificate() {
private static final long serialVersionUID = 638659908323741165L;
public byte[] getEncoded() {
return TestUtils.getX509Certificate_v1();
}
};
assertEquals(new X500Principal("CN=Z"), cert.getIssuerX500Principal());
}
use of javax.security.auth.x500.X500Principal in project robovm by robovm.
the class X509Certificate2Test method testGetSubjectX500Principal.
public void testGetSubjectX500Principal() {
// return valid encoding
MyX509Certificate cert = new MyX509Certificate() {
private static final long serialVersionUID = -3625913637413840694L;
public byte[] getEncoded() {
return TestUtils.getX509Certificate_v1();
}
};
assertEquals(new X500Principal("CN=Y"), cert.getSubjectX500Principal());
}
use of javax.security.auth.x500.X500Principal 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 javax.security.auth.x500.X500Principal 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());
}
Aggregations