private void checkTrusted(X509Certificate[] x509Certificates) throws CertificateException{ final X509Certificate certificate = x509Certificates[0]; final String thumbPrint = CertificateUtil.create().thumbPrint(certificate); final String address = CertUtil.subjectCN(certificate); if (!certificateValidForKnownHost(address, thumbPrint)) { throw new CertificateException("Connections not allowed"); } }
private void checkTrusted(X509Certificate[] x509Certificates) throws CertificateException{ final X509Certificate certificate = x509Certificates[0]; final String thumbPrint = CertificateUtil.create().thumbPrint(certificate); final String address = CertUtil.subjectCN(certificate); if (!certificateValidForKnownHost(address, thumbPrint)) { throw new CertificateException("Connections not allowed"); } }
/** * Gets a list of subject names defined for the given certificate. The list includes the first common name (CN) * specified in the subject distinguished name (if defined) and all subject alternative names of the given type. * * @param cert X.509 certificate to examine. * @param types One or more subject alternative name types to fetch. * * @return List of subject names. * * @throws EncodingException on cert field extraction. */ public static List<String> subjectNames(final X509Certificate cert, final GeneralNameType... types) throws EncodingException { final List<String> names = new ArrayList<>(); final String cn = subjectCN(cert); if (cn != null) { names.add(cn); } final GeneralNames altNames = subjectAltNames(cert, types); if (altNames == null) { return names; } for (GeneralName name : altNames.getNames()) { names.add(name.getName().toString()); } return names; }
/** * Gets a list of all subject names defined for the given certificate. The list includes the first common name (CN) * specified in the subject distinguished name (if defined) and all subject alternative names. * * @param cert X.509 certificate to examine. * * @return List of subject names. * * @throws EncodingException on cert field extraction. */ public static List<String> subjectNames(final X509Certificate cert) throws EncodingException { final List<String> names = new ArrayList<>(); final String cn = subjectCN(cert); if (cn != null) { names.add(cn); } final GeneralNames altNames = subjectAltNames(cert); if (altNames == null) { return names; } for (GeneralName name : altNames.getNames()) { names.add(name.getName().toString()); } return names; }
private void checkTrusted(X509Certificate[] x509Certificates) throws CertificateException { final X509Certificate certificate = x509Certificates[0]; final String thumbPrint = CertificateUtil.create().thumbPrint(certificate); final String address = CertUtil.subjectCN(certificate); if (!certificateExistsInKnownHosts(address)) { try { addServerToKnownHostsList(address, thumbPrint); } catch (IOException ex) { throw new CertificateException("Failed to save address and certificate fingerprint to whitelist. Cause by ", ex); } } else { if (!certificateValidForKnownHost(address, thumbPrint)) { throw new CertificateException("This address has been associated with a different certificate"); } } } }
private void checkTrusted(X509Certificate[] x509Certificates) throws CertificateException { final X509Certificate certificate = x509Certificates[0]; final String thumbPrint = CertificateUtil.create().thumbPrint(certificate); final String address = CertUtil.subjectCN(certificate); if (!certificateExistsInKnownHosts(address)) { try { addServerToKnownHostsList(address, thumbPrint); } catch (IOException ex) { throw new CertificateException("Failed to save address and certificate fingerprint to whitelist. Cause by ", ex); } } else { if (!certificateValidForKnownHost(address, thumbPrint)) { throw new CertificateException("This address has been associated with a different certificate"); } } } }