|
@@ -1,6 +1,8 @@
|
|
|
package com.example.demo.demos.web.service.impl;
|
|
package com.example.demo.demos.web.service.impl;
|
|
|
|
|
|
|
|
import com.example.demo.demos.web.service.EcsService;
|
|
import com.example.demo.demos.web.service.EcsService;
|
|
|
|
|
+import com.example.demo.demos.web.util.DateUtil;
|
|
|
|
|
+import com.example.demo.demos.web.util.SslUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
import javax.net.ssl.HttpsURLConnection;
|
|
import javax.net.ssl.HttpsURLConnection;
|
|
@@ -12,18 +14,21 @@ import java.security.cert.X509Certificate;
|
|
|
public class EcsServiceImpl implements EcsService {
|
|
public class EcsServiceImpl implements EcsService {
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public X509Certificate getCertificate(String url) {
|
|
|
|
|
|
|
+ public String getCertificate(String url) {
|
|
|
URL u = null;
|
|
URL u = null;
|
|
|
HttpsURLConnection conn = null;
|
|
HttpsURLConnection conn = null;
|
|
|
try {
|
|
try {
|
|
|
u = new URL("https://"+url);
|
|
u = new URL("https://"+url);
|
|
|
|
|
+ //信任所有SSL证书
|
|
|
|
|
+// SslUtils.ignoreSsl();
|
|
|
conn = (HttpsURLConnection) u.openConnection();
|
|
conn = (HttpsURLConnection) u.openConnection();
|
|
|
conn.connect();
|
|
conn.connect();
|
|
|
|
|
|
|
|
// 获取服务器证书链
|
|
// 获取服务器证书链
|
|
|
Certificate[] certificates = conn.getServerCertificates();
|
|
Certificate[] certificates = conn.getServerCertificates();
|
|
|
// 通常证书链的第一个证书是服务器证书
|
|
// 通常证书链的第一个证书是服务器证书
|
|
|
- return (X509Certificate) certificates[0];
|
|
|
|
|
|
|
+ X509Certificate certificate = (X509Certificate) certificates[0];
|
|
|
|
|
+ return "域名"+url+",有效期"+DateUtil.parseDateToStr(DateUtil.YYYY_MM_DD,certificate.getNotAfter());
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
|
}finally {
|
|
}finally {
|