-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExpiryDate.java
More file actions
37 lines (33 loc) · 1.11 KB
/
ExpiryDate.java
File metadata and controls
37 lines (33 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLPeerUnverifiedException;
import java.net.URL;
import java.security.cert.Certificate;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
/*
This class looks for all the certificate chains and returns the earliest expiry date
*/
public class ExpiryDate {
public String returnExpiryDate(URL url, HttpsURLConnection connection) throws SSLPeerUnverifiedException
{
String result = "";
try {
Certificate[] certs = connection.getServerCertificates();
ArrayList<Date> dates = new ArrayList<Date>();
for (Certificate cert : certs) {
if (cert instanceof X509Certificate) {
X509Certificate sslCommon = (X509Certificate) cert;
dates.add(sslCommon.getNotAfter());
}
}
Collections.sort(dates);
result = dates.get(0).toString();
}
catch (Exception e){
result = "null";
}
return result;
}
}