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

org.pepsoft.worldpainter.browser.WPTrustManager Maven / Gradle / Ivy

There is a newer version: 2.23.2
Show newest version
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.pepsoft.worldpainter.browser;

import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import javax.net.ssl.X509TrustManager;

/**
 *
 * @author pepijn
 */
public class WPTrustManager implements X509TrustManager {
    public WPTrustManager(X509Certificate trustedCert) {
        this.trustedCert = trustedCert;
    }
    
    @Override
    public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
        throw new UnsupportedOperationException("Not supported");
    }

    @Override
    public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
        for (X509Certificate cert: chain) {
            cert.checkValidity();
            if (cert.equals(trustedCert)) {
//                System.out.println("Trusted certificate found!");
                return;
//            } else {
//                System.out.println("Untrusted certificate found!");
            }
//            System.out.println(cert);
        }
        throw new CertificateException("No certificate provided or certificate not trusted");
    }

    @Override
    public X509Certificate[] getAcceptedIssuers() {
        return new X509Certificate[] {trustedCert};
    }
    
    private final X509Certificate trustedCert;
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy