use of java.security.cert.X509CertSelector in project robovm by robovm.
the class X509CertSelectorTest method test_getSubjectKeyIdentifier.
/**
* java.security.cert.X509CertSelector#getSubjectKeyIdentifier()
*/
public void test_getSubjectKeyIdentifier() {
// random value
byte[] skid1 = new byte[] { 1, 2, 3, 4, 5 };
// random value
byte[] skid2 = new byte[] { 4, 5, 5, 4, 3, 2, 1 };
X509CertSelector selector = new X509CertSelector();
assertNull("Selector should return null", selector.getSubjectKeyIdentifier());
selector.setSubjectKeyIdentifier(skid1);
assertTrue("The returned keyID should be equal to specified", Arrays.equals(skid1, selector.getSubjectKeyIdentifier()));
selector.getSubjectKeyIdentifier()[0]++;
assertTrue("The returned keyID should be equal to specified", Arrays.equals(skid1, selector.getSubjectKeyIdentifier()));
assertFalse("The returned keyID should differ", Arrays.equals(skid2, selector.getSubjectKeyIdentifier()));
}
use of java.security.cert.X509CertSelector in project robovm by robovm.
the class X509CertSelectorTest method test_getSubjectPublicKeyAlgID.
/**
* java.security.cert.X509CertSelector#getSubjectPublicKeyAlgID()
*/
public void test_getSubjectPublicKeyAlgID() throws Exception {
X509CertSelector selector = new X509CertSelector();
String[] validOIDs = { "0.0.20", "1.25.0", "2.0.39", "0.2.10", "1.35.15", "2.17.89" };
assertNull("Selector should return null", selector.getSubjectPublicKeyAlgID());
for (int i = 0; i < validOIDs.length; i++) {
try {
selector.setSubjectPublicKeyAlgID(validOIDs[i]);
assertEquals(validOIDs[i], selector.getSubjectPublicKeyAlgID());
} catch (IOException e) {
System.out.println("t = " + e.getMessage());
//fail("Unexpected exception " + e.getMessage());
}
}
// RSA encryption
String pkaid1 = "1.2.840.113549.1.1.1";
// MD5 with RSA encryption
String pkaid2 = "1.2.840.113549.1.1.4";
selector.setSubjectPublicKeyAlgID(pkaid1);
assertTrue("The returned oid should be equal to specified", pkaid1.equals(selector.getSubjectPublicKeyAlgID()));
assertFalse("The returned oid should differ", pkaid2.equals(selector.getSubjectPublicKeyAlgID()));
}
use of java.security.cert.X509CertSelector in project robovm by robovm.
the class X509CertSelectorTest method test_setSubjectPublicKeyLB$.
/**
* java.security.cert.X509CertSelector#setSubjectPublicKey(byte[])
*/
public void test_setSubjectPublicKeyLB$() throws Exception {
//SubjectPublicKeyInfo ::= SEQUENCE {
// algorithm AlgorithmIdentifier,
// subjectPublicKey BIT STRING }
byte[] enc = { // SEQUENCE
0x30, // SEQUENCE
0x0E, // SEQUENCE
0x30, // SEQUENCE
0x07, //OID
0x06, //OID
0x02, //OID
0x03, //OID
0x05, //ANY
0x01, //ANY
0x01, //ANY
0x07, // subjectPublicKey
0x03, // subjectPublicKey
0x03, // subjectPublicKey
0x01, // subjectPublicKey
0x01, // subjectPublicKey
0x06 };
X509CertSelector selector = new X509CertSelector();
selector.setSubjectPublicKey(enc);
PublicKey key = selector.getSubjectPublicKey();
assertEquals("0.3.5", key.getAlgorithm());
assertEquals("X.509", key.getFormat());
assertTrue(Arrays.equals(enc, key.getEncoded()));
assertNotNull(key.toString());
}
use of java.security.cert.X509CertSelector in project robovm by robovm.
the class X509CertSelectorTest method test_setExtendedKeyUsageLjava_util_Set.
/**
* java.security.cert.X509CertSelector#setExtendedKeyUsage(Set<String>)
*/
public void test_setExtendedKeyUsageLjava_util_Set() throws Exception {
HashSet<String> ku1 = new HashSet<String>(Arrays.asList(new String[] { "1.3.6.1.5.5.7.3.1", "1.3.6.1.5.5.7.3.2", "1.3.6.1.5.5.7.3.3", "1.3.6.1.5.5.7.3.4", "1.3.6.1.5.5.7.3.8", "1.3.6.1.5.5.7.3.9", "1.3.6.1.5.5.7.3.5", "1.3.6.1.5.5.7.3.6", "1.3.6.1.5.5.7.3.7" }));
HashSet<String> ku2 = new HashSet<String>(Arrays.asList(new String[] { "1.3.6.1.5.5.7.3.1", "1.3.6.1.5.5.7.3.2", "1.3.6.1.5.5.7.3.3", "1.3.6.1.5.5.7.3.4", "1.3.6.1.5.5.7.3.8", "1.3.6.1.5.5.7.3.9", "1.3.6.1.5.5.7.3.5", "1.3.6.1.5.5.7.3.6" }));
TestCert cert1 = new TestCert(ku1);
TestCert cert2 = new TestCert(ku2);
X509CertSelector selector = new X509CertSelector();
selector.setExtendedKeyUsage(null);
assertTrue("Any certificate should match in the case of null " + "extendedKeyUsage criteria.", selector.match(cert1) && selector.match(cert2));
selector.setExtendedKeyUsage(ku1);
assertEquals(ku1, selector.getExtendedKeyUsage());
selector.setExtendedKeyUsage(ku2);
assertEquals(ku2, selector.getExtendedKeyUsage());
}
use of java.security.cert.X509CertSelector in project robovm by robovm.
the class X509CertSelectorTest method test_clone.
/**
* java.security.cert.X509CertSelector#clone()
*/
public void test_clone() throws Exception {
X509CertSelector selector = new X509CertSelector();
X509CertSelector selector1 = (X509CertSelector) selector.clone();
assertEquals(selector.getMatchAllSubjectAltNames(), selector1.getMatchAllSubjectAltNames());
assertEquals(selector.getAuthorityKeyIdentifier(), selector1.getAuthorityKeyIdentifier());
assertEquals(selector.getBasicConstraints(), selector1.getBasicConstraints());
assertEquals(selector.getCertificate(), selector1.getCertificate());
assertEquals(selector.getCertificateValid(), selector1.getCertificateValid());
assertEquals(selector.getExtendedKeyUsage(), selector1.getExtendedKeyUsage());
assertEquals(selector.getIssuer(), selector1.getIssuer());
assertEquals(selector.getIssuerAsBytes(), selector1.getIssuerAsBytes());
assertEquals(selector.getIssuerAsString(), selector1.getIssuerAsString());
assertEquals(selector.getKeyUsage(), selector1.getKeyUsage());
assertEquals(selector.getNameConstraints(), selector1.getNameConstraints());
assertEquals(selector.getPathToNames(), selector1.getPathToNames());
assertEquals(selector.getPolicy(), selector1.getPolicy());
assertEquals(selector.getPrivateKeyValid(), selector1.getPrivateKeyValid());
assertEquals(selector.getSerialNumber(), selector1.getSerialNumber());
assertEquals(selector.getSubject(), selector1.getSubject());
assertEquals(selector.getSubjectAlternativeNames(), selector1.getSubjectAlternativeNames());
assertEquals(selector.getSubjectAsBytes(), selector1.getSubjectAsBytes());
assertEquals(selector.getSubjectAsString(), selector1.getSubjectAsString());
assertEquals(selector.getSubjectKeyIdentifier(), selector1.getSubjectKeyIdentifier());
assertEquals(selector.getSubjectPublicKey(), selector1.getSubjectPublicKey());
assertEquals(selector.getSubjectPublicKeyAlgID(), selector1.getSubjectPublicKeyAlgID());
selector = null;
try {
selector.clone();
fail();
} catch (NullPointerException expected) {
}
}
Aggregations