Important: Previous commit will not work. I add the actual cecker in this one.

This commit is contained in:
Katerina 2024-05-17 14:15:47 +03:00
parent f083820765
commit 927d75d2c5
1 changed files with 36 additions and 0 deletions

View File

@ -0,0 +1,36 @@
package eu.dnetlib.validatorapi.utils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLPeerUnverifiedException;
import java.net.URL;
import java.security.cert.Certificate;
public class CheckCertificate {
private static final Logger log = LogManager.getLogger(CheckCertificate.class);
public static boolean isValidCertificate(String httpsURL) {
try {
URL myUrl = new URL(httpsURL);
HttpsURLConnection conn = (HttpsURLConnection) myUrl.openConnection();
conn.connect();
// Get the certificate
Certificate[] certs = conn.getServerCertificates();
conn.disconnect();
return true;
} catch (SSLPeerUnverifiedException ssle) {
log.error("Certificate Validation Error.", ssle);
return false;
} catch (Exception e) {
log.error("Certificate Validation Error.", e);
return false;
}
}
}