All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.noear.water.utils.CaUtils Maven / Gradle / Ivy

There is a newer version: 2.14.2
Show newest version
package org.noear.water.utils;

import javax.net.ssl.HttpsURLConnection;
import java.io.IOException;
import java.net.URL;
import java.security.cert.Certificate;
import java.security.cert.X509Certificate;
import java.util.Date;

/**
 * @author noear 2022/7/25 created
 */
public class CaUtils {
    public static Date getCaEndTime(String url) throws IOException {
        X509Certificate certificate = getCa(url);
        return certificate.getNotAfter();
    }

    public static X509Certificate getCa(String url) throws IOException {
        URL caUrl = new URL(url);
        HttpsURLConnection connection = (HttpsURLConnection) caUrl.openConnection();

        connection.setUseCaches(false);
        connection.connect();
        Certificate certificate = null;
        if (connection.getServerCertificates().length > 0) {
            certificate = connection.getServerCertificates()[0];
        }
        connection.disconnect();

        return (X509Certificate) certificate;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy