-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExpiry.java
More file actions
32 lines (28 loc) · 1.06 KB
/
Expiry.java
File metadata and controls
32 lines (28 loc) · 1.06 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
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;
/*
This class looks for all the certificate chains and calculates 'how far' is the earliest expiry date.
*/
public class Expiry {
public Long returnExpiry(URL url, HttpsURLConnection connection) throws SSLPeerUnverifiedException
{
Certificate[] certs = connection.getServerCertificates();
ArrayList<Long> differences = new ArrayList();
for(Certificate cert: certs)
{
if(cert instanceof X509Certificate)
{
X509Certificate sslCommon = (X509Certificate) cert;
//System.out.println("Expires: " + sslCommon.getNotAfter());
differences.add((sslCommon.getNotAfter().getTime() - System.currentTimeMillis())/(1000*24*60*60));
}
}
Collections.sort(differences);
return differences.get(0);
}
}