a
This commit is contained in:
73
src/SSLCertChecker.java
Normal file
73
src/SSLCertChecker.java
Normal file
@@ -0,0 +1,73 @@
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import javax.net.ssl.SSLPeerUnverifiedException;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.security.cert.Certificate;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
public class SSLCertChecker {
|
||||
public static boolean isValidHttpsUrl(String urlString) {
|
||||
try {
|
||||
URL url = new URL(urlString);
|
||||
return "https".equalsIgnoreCase(url.getProtocol());
|
||||
} catch (MalformedURLException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public static void readUrls(String file) {
|
||||
try(BufferedReader br = new BufferedReader(new FileReader(file))){
|
||||
String urls;
|
||||
while ((urls = br.readLine()) != null){
|
||||
if(isValidHttpsUrl(urls)) {
|
||||
System.out.println(urls);
|
||||
checkCert(urls);
|
||||
}
|
||||
else
|
||||
System.out.println(urls+" is not valid");
|
||||
}
|
||||
}
|
||||
catch (IOException e){
|
||||
System.out.println("Error reading file");
|
||||
}
|
||||
}
|
||||
public static void checkCert(String curl){
|
||||
try {
|
||||
URL url = new URL(curl);
|
||||
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
|
||||
connection.connect();
|
||||
|
||||
Certificate[] certs = connection.getServerCertificates();
|
||||
for (Certificate cert : certs) {
|
||||
if (cert instanceof X509Certificate) {
|
||||
X509Certificate x509Cert = (X509Certificate) cert;
|
||||
Date expiryDate = x509Cert.getNotAfter();
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
System.out.println("Zertifikatsablaufdatum: " + sdf.format(expiryDate));
|
||||
|
||||
// Überprüfen, ob das Zertifikat abgelaufen ist
|
||||
if (expiryDate.before(new Date())) {
|
||||
System.out.println("WARNUNG: Das SSL-Zertifikat ist abgelaufen!");
|
||||
} else {
|
||||
System.out.println("Das SSL-Zertifikat ist gültig.");
|
||||
}
|
||||
}
|
||||
}
|
||||
connection.disconnect();
|
||||
} catch (SSLPeerUnverifiedException e) {
|
||||
System.out.println("SSL-Fehler: Zertifikat kann nicht verifiziert werden.");
|
||||
} catch (Exception e) {
|
||||
System.out.println("Fehler beim Abrufen des Zertifikats: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
public static void main(String[] args){
|
||||
if(args.length <1)
|
||||
System.out.println("Kein Url-File angegeben");
|
||||
readUrls(args[0]);
|
||||
|
||||
}
|
||||
}
|
||||
3
src/urls.txt
Normal file
3
src/urls.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
https://edv.zsi-tec.com
|
||||
https://ticket.edv.zsi-tec.com
|
||||
https://mail.zsi-tec.com
|
||||
Reference in New Issue
Block a user