Java Code Examples for java.security.cert.CertificateParsingException#printStackTrace()

The following examples show how to use java.security.cert.CertificateParsingException#printStackTrace() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BurpCertificate.java    From SAMLRaider with MIT License 6 votes vote down vote up
public List<String> getSubjectAlternativeNames() {
	List<String> subjectAlternativeNames = new LinkedList<String>();

	try {
		if (certificate.getSubjectAlternativeNames() == null) {
			return subjectAlternativeNames;
		}

		for (List<?> i : certificate.getSubjectAlternativeNames()) {
			subjectAlternativeNames.add(i.get(1) + " (" + ObjectIdentifier.getSubjectAlternativeNames((Integer) i.get(0)) + ")");
		}
	} catch (CertificateParsingException e) {
		e.printStackTrace();
	}

	return subjectAlternativeNames;
}
 
Example 2
Source File: BurpCertificate.java    From SAMLRaider with MIT License 6 votes vote down vote up
public List<String> getIssuerAlternativeNames() {
	List<String> issuerAlternativeNames = new LinkedList<String>();

	try {
		if (certificate.getIssuerAlternativeNames() == null) {
			return issuerAlternativeNames;
		}

		for (List<?> i : certificate.getIssuerAlternativeNames()) {
			issuerAlternativeNames.add(i.get(1) + " (" + ObjectIdentifier.getSubjectAlternativeNames((Integer) i.get(0)) + ")");
		}
	} catch (CertificateParsingException e) {
		e.printStackTrace();
	}

	return issuerAlternativeNames;
}
 
Example 3
Source File: BurpCertificate.java    From SAMLRaider with MIT License 6 votes vote down vote up
public List<String> getExtendedKeyUsage() {
	List<String> extendedKeyUsage = new LinkedList<>();

	try {
		if (certificate.getExtendedKeyUsage() == null) {
			return extendedKeyUsage;
		}

		for (String i : certificate.getExtendedKeyUsage()) {
			extendedKeyUsage.add(ObjectIdentifier.getExtendedKeyUsage(i));
		}
	} catch (CertificateParsingException e) {
		e.printStackTrace();
	}

	return extendedKeyUsage;
}
 
Example 4
Source File: SSLHostnameVerifier.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * Extracts the array of SubjectAlt DNS names from an X509Certificate.
 * Returns null if there aren't any.
 * <p/>
 * Note:  Java doesn't appear able to extract international characters
 * from the SubjectAlts.  It can only extract international characters
 * from the CN field.
 * <p/>
 * (Or maybe the version of OpenSSL I'm using to test isn't storing the
 * international characters correctly in the SubjectAlts?).
 *
 * @param cert X509Certificate
 * @return Array of SubjectALT DNS names stored in the certificate.
 */
public static String[] getDNSSubjectAlts(X509Certificate cert) {
    final List<String> subjectAltList = new LinkedList<String>();
    Collection<List<?>> c = null;
    try {
        c = cert.getSubjectAlternativeNames();
    }
    catch (CertificateParsingException cpe) {
        // Should probably log.debug() this?
        cpe.printStackTrace();
    }
    if (c != null) {
        Iterator<List<?>> it = c.iterator();
        while (it.hasNext()) {
            List<?> list = it.next();
            int type = ((Integer) list.get(0)).intValue();
            // If type is 2, then we've got a dNSName
            if (type == 2) {
                String s = (String) list.get(1);
                subjectAltList.add(s);
            }
        }
    }
    if (!subjectAltList.isEmpty()) {
        String[] subjectAlts = new String[subjectAltList.size()];
        subjectAltList.toArray(subjectAlts);
        return subjectAlts;
    } else {
        return null;
    }
}
 
Example 5
Source File: SSLHostnameVerifier.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * Extracts the array of SubjectAlt DNS names from an X509Certificate.
 * Returns null if there aren't any.
 * <p/>
 * Note:  Java doesn't appear able to extract international characters
 * from the SubjectAlts.  It can only extract international characters
 * from the CN field.
 * <p/>
 * (Or maybe the version of OpenSSL I'm using to test isn't storing the
 * international characters correctly in the SubjectAlts?).
 *
 * @param cert X509Certificate
 * @return Array of SubjectALT DNS names stored in the certificate.
 */
public static String[] getDNSSubjectAlts(X509Certificate cert) {
    final List<String> subjectAltList = new LinkedList<String>();
    Collection<List<?>> c = null;
    try {
        c = cert.getSubjectAlternativeNames();
    }
    catch (CertificateParsingException cpe) {
        // Should probably log.debug() this?
        cpe.printStackTrace();
    }
    if (c != null) {
        Iterator<List<?>> it = c.iterator();
        while (it.hasNext()) {
            List<?> list = it.next();
            int type = ((Integer) list.get(0)).intValue();
            // If type is 2, then we've got a dNSName
            if (type == 2) {
                String s = (String) list.get(1);
                subjectAltList.add(s);
            }
        }
    }
    if (!subjectAltList.isEmpty()) {
        String[] subjectAlts = new String[subjectAltList.size()];
        subjectAltList.toArray(subjectAlts);
        return subjectAlts;
    } else {
        return null;
    }
}
 
Example 6
Source File: MemorizingTrustManager.java    From Pix-Art-Messenger with GNU General Public License v3.0 5 votes vote down vote up
private String hostNameMessage(X509Certificate cert, String hostname) {
    StringBuffer si = new StringBuffer();

    si.append(master.getString(R.string.mtm_hostname_mismatch, hostname));
    si.append("\n\n");
    try {
        Collection<List<?>> sans = cert.getSubjectAlternativeNames();
        if (sans == null) {
            si.append(cert.getSubjectDN());
            si.append("\n");
        } else for (List<?> altName : sans) {
            Object name = altName.get(1);
            if (name instanceof String) {
                si.append("[");
                si.append((Integer) altName.get(0));
                si.append("] ");
                si.append(name);
                si.append("\n");
            }
        }
    } catch (CertificateParsingException e) {
        e.printStackTrace();
        si.append("<Parsing error: ");
        si.append(e.getLocalizedMessage());
        si.append(">\n");
    }
    si.append("\n");
    si.append(master.getString(R.string.mtm_connect_anyway));
    si.append("\n\n");
    si.append(master.getString(R.string.mtm_cert_details));
    certDetails(si, cert);
    return si.toString();
}
 
Example 7
Source File: Alexa.java    From BotLibre with Eclipse Public License 1.0 5 votes vote down vote up
private boolean checkCertSubjectAlternativeName(X509Certificate cert) {
	Collection<List<?>> san;
	try {
		san = cert.getSubjectAlternativeNames();
		for (List<?> s : san) {
			for(Object q : s) {
				if(q.equals("echo-api.amazon.com")) { return true; }
			}
		}
	} catch (CertificateParsingException e) {
		e.printStackTrace();
	}
	return false;
}
 
Example 8
Source File: MemorizingTrustManager.java    From Conversations with GNU General Public License v3.0 5 votes vote down vote up
private String hostNameMessage(X509Certificate cert, String hostname) {
    StringBuffer si = new StringBuffer();

    si.append(master.getString(R.string.mtm_hostname_mismatch, hostname));
    si.append("\n\n");
    try {
        Collection<List<?>> sans = cert.getSubjectAlternativeNames();
        if (sans == null) {
            si.append(cert.getSubjectDN());
            si.append("\n");
        } else for (List<?> altName : sans) {
            Object name = altName.get(1);
            if (name instanceof String) {
                si.append("[");
                si.append((Integer) altName.get(0));
                si.append("] ");
                si.append(name);
                si.append("\n");
            }
        }
    } catch (CertificateParsingException e) {
        e.printStackTrace();
        si.append("<Parsing error: ");
        si.append(e.getLocalizedMessage());
        si.append(">\n");
    }
    si.append("\n");
    si.append(master.getString(R.string.mtm_connect_anyway));
    si.append("\n\n");
    si.append(master.getString(R.string.mtm_cert_details));
    certDetails(si, cert);
    return si.toString();
}
 
Example 9
Source File: ServerTrustManager.java    From AndroidPNClient with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the JID representation of an XMPP entity contained as a SubjectAltName extension
 * in the certificate. If none was found then return <tt>null</tt>.
 *
 * @param certificate the certificate presented by the remote entity.
 * @return the JID representation of an XMPP entity contained as a SubjectAltName extension
 *         in the certificate. If none was found then return <tt>null</tt>.
 */
private static List<String> getSubjectAlternativeNames(X509Certificate certificate) {
    List<String> identities = new ArrayList<String>();
    try {
        Collection<List<?>> altNames = certificate.getSubjectAlternativeNames();
        // Check that the certificate includes the SubjectAltName extension
        if (altNames == null) {
            return Collections.emptyList();
        }
        // Use the type OtherName to search for the certified server name
        /*for (List item : altNames) {
            Integer type = (Integer) item.get(0);
            if (type == 0) {
                // Type OtherName found so return the associated value
                try {
                    // Value is encoded using ASN.1 so decode it to get the server's identity
                    ASN1InputStream decoder = new ASN1InputStream((byte[]) item.toArray()[1]);
                    DEREncodable encoded = decoder.readObject();
                    encoded = ((DERSequence) encoded).getObjectAt(1);
                    encoded = ((DERTaggedObject) encoded).getObject();
                    encoded = ((DERTaggedObject) encoded).getObject();
                    String identity = ((DERUTF8String) encoded).getString();
                    // Add the decoded server name to the list of identities
                    identities.add(identity);
                }
                catch (UnsupportedEncodingException e) {
                    // Ignore
                }
                catch (IOException e) {
                    // Ignore
                }
                catch (Exception e) {
                    e.printStackTrace();
                }
            }
            // Other types are not good for XMPP so ignore them
            System.out.println("SubjectAltName of invalid type found: " + certificate);
        }*/
    }
    catch (CertificateParsingException e) {
        e.printStackTrace();
    }
    return identities;
}