package com.cf.imes.module.executor.util.fileConversion.admin.api.webcad;

import javax.net.ssl.*;

/**
 * @projectName: cf_imes_server
 * @author: 晨丰科技
 * @date: 2025/3/11 14:51
 */
public class SSLUtils {
    private static void trustAllHttpsCertificates() throws Exception {
        SSLContext sc = SSLContext.getInstance("TLSv1.2");
        HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
    }

    /**
     * 忽略HTTPS请求的SSL证书，必须在openConnection之前调用
     *
     * @throws Exception
     */
    public static void ignoreSsl() {
        try {
            HostnameVerifier hv = (urlHostName, session) -> {
                System.out.println("Warning: URL Host: " + urlHostName + " vs. " + session.getPeerHost());
                return true;
            };
            trustAllHttpsCertificates();
            HttpsURLConnection.setDefaultHostnameVerifier(hv);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

