Search in sources :

Example 6 with GeneralNameInterface

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

the class X509CertSelectorTest method testSubjectAltName.

/*
     * Tests matching on the subject alternative name extension contained in the
     * certificate.
     */
private void testSubjectAltName() throws IOException {
    System.out.println("X.509 Certificate Match on subjectAltName");
    // bad match
    X509CertSelector selector = new X509CertSelector();
    GeneralNameInterface dnsName = new DNSName("foo.com");
    DerOutputStream tmp = new DerOutputStream();
    dnsName.encode(tmp);
    selector.addSubjectAlternativeName(2, tmp.toByteArray());
    checkMatch(selector, cert, false);
    // good match
    DerInputStream in = new DerInputStream(cert.getExtensionValue("2.5.29.17"));
    byte[] encoded = in.getOctetString();
    SubjectAlternativeNameExtension ext = new SubjectAlternativeNameExtension(false, encoded);
    GeneralNames names = (GeneralNames) ext.get(SubjectAlternativeNameExtension.SUBJECT_NAME);
    GeneralName name = (GeneralName) names.get(0);
    selector.setSubjectAlternativeNames(null);
    DerOutputStream tmp2 = new DerOutputStream();
    name.getName().encode(tmp2);
    selector.addSubjectAlternativeName(name.getType(), tmp2.toByteArray());
    checkMatch(selector, cert, true);
    // good match 2 (matches at least one)
    selector.setMatchAllSubjectAltNames(false);
    selector.addSubjectAlternativeName(2, "foo.com");
    checkMatch(selector, cert, true);
}
Also used : GeneralNameInterface(sun.security.x509.GeneralNameInterface) GeneralNames(sun.security.x509.GeneralNames) DerOutputStream(sun.security.util.DerOutputStream) SubjectAlternativeNameExtension(sun.security.x509.SubjectAlternativeNameExtension) X509CertSelector(java.security.cert.X509CertSelector) DerInputStream(sun.security.util.DerInputStream) GeneralName(sun.security.x509.GeneralName) DNSName(sun.security.x509.DNSName)

Example 7 with GeneralNameInterface

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

the class ForwardState method clone.

/*
     * Clone current state. The state is cloned as each cert is
     * added to the path. This is necessary if backtracking occurs,
     * and a prior state needs to be restored.
     *
     * Note that this is a SMART clone. Not all fields are fully copied,
     * because some of them will
     * not have their contents modified by subsequent calls to updateState.
     */
@Override
// Safe casts assuming clone() works correctly
@SuppressWarnings("unchecked")
public Object clone() {
    try {
        ForwardState clonedState = (ForwardState) super.clone();
        /* clone checkers, if cloneable */
        clonedState.forwardCheckers = (ArrayList<PKIXCertPathChecker>) forwardCheckers.clone();
        ListIterator<PKIXCertPathChecker> li = clonedState.forwardCheckers.listIterator();
        while (li.hasNext()) {
            PKIXCertPathChecker checker = li.next();
            if (checker instanceof Cloneable) {
                li.set((PKIXCertPathChecker) checker.clone());
            }
        }
        /*
             * Shallow copy traversed names. There is no need to
             * deep copy contents, since the elements of the Set
             * are never modified by subsequent calls to updateState().
             */
        clonedState.subjectNamesTraversed = (HashSet<GeneralNameInterface>) subjectNamesTraversed.clone();
        return clonedState;
    } catch (CloneNotSupportedException e) {
        throw new InternalError(e.toString(), e);
    }
}
Also used : GeneralNameInterface(sun.security.x509.GeneralNameInterface) PKIXCertPathChecker(java.security.cert.PKIXCertPathChecker)

Aggregations

GeneralNameInterface (sun.security.x509.GeneralNameInterface)5 IOException (java.io.IOException)2 PKIXCertPathChecker (java.security.cert.PKIXCertPathChecker)2 GeneralName (sun.security.x509.GeneralName)2 GeneralNames (sun.security.x509.GeneralNames)2 SubjectAlternativeNameExtension (sun.security.x509.SubjectAlternativeNameExtension)2 X500Name (sun.security.x509.X500Name)2 URI (java.net.URI)1 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 CRLException (java.security.cert.CRLException)1 CertStoreException (java.security.cert.CertStoreException)1 CertificateException (java.security.cert.CertificateException)1 X509CertSelector (java.security.cert.X509CertSelector)1 DerInputStream (sun.security.util.DerInputStream)1 DerOutputStream (sun.security.util.DerOutputStream)1 DNSName (sun.security.x509.DNSName)1 GeneralSubtree (sun.security.x509.GeneralSubtree)1 GeneralSubtrees (sun.security.x509.GeneralSubtrees)1 NameConstraintsExtension (sun.security.x509.NameConstraintsExtension)1