Search in sources :

Example 1 with PrivateKeyUsageExtension

use of sun.security.x509.PrivateKeyUsageExtension in project jdk8u_jdk by JetBrains.

the class X509CertSelectorTest method testPrivateKeyValid.

/*
     * Tests matching on the private key validity component contained in the
     * certificate.
     */
private void testPrivateKeyValid() throws IOException, CertificateException {
    System.out.println("X.509 Certificate Match on privateKeyValid");
    // bad match
    X509CertSelector selector = new X509CertSelector();
    Calendar cal = Calendar.getInstance();
    cal.set(1968, 12, 31);
    selector.setPrivateKeyValid(cal.getTime());
    checkMatch(selector, cert, false);
    // good match
    DerInputStream in = new DerInputStream(cert.getExtensionValue("2.5.29.16"));
    byte[] encoded = in.getOctetString();
    PrivateKeyUsageExtension ext = new PrivateKeyUsageExtension(false, encoded);
    Date validDate = (Date) ext.get(PrivateKeyUsageExtension.NOT_BEFORE);
    selector.setPrivateKeyValid(validDate);
    checkMatch(selector, cert, true);
}
Also used : Calendar(java.util.Calendar) X509CertSelector(java.security.cert.X509CertSelector) DerInputStream(sun.security.util.DerInputStream) PrivateKeyUsageExtension(sun.security.x509.PrivateKeyUsageExtension) Date(java.util.Date)

Aggregations

X509CertSelector (java.security.cert.X509CertSelector)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1 DerInputStream (sun.security.util.DerInputStream)1 PrivateKeyUsageExtension (sun.security.x509.PrivateKeyUsageExtension)1