<commit_before>package org.geoint.keyhole.ssl;

import java.util.logging.Level;
import java.util.logging.Logger;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
import org.apache.commons.httpclient.protocol.Protocol;
import org.apache.commons.httpclient.protocol.ProtocolSocketFactory;
import org.jsslutils.extra.apachehttpclient.SslContextedSecureProtocolSocketFactory;

/**
 *
 */
@WebListener("terribleTrustManager")
public class TerribleTrustManagerInstaller implements ServletContextListener {

    private static final Logger logger = Logger
            .getLogger(TerribleTrustManagerInstaller.class.getName());

    @Override
    public void contextInitialized(ServletContextEvent sce) {
        logger.log(Level.WARNING, "This proxy currently disables ssl server"
                + " valiation.  This will be fixed in a future version.");
        
        try {
            //register it with the Java SSLContext
            SSLContext sc = SSLContext.getInstance("SSL");
            sc.init(null, new TrustManager[]{new TerribleTrustManager()},
                    new java.security.SecureRandom());
            HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
            
        } catch (Exception e) {
            logger.log(Level.SEVERE, "Unable to register SSL work around, "
                    + "requsts to HTTPS servers with invalid certificates will "
                    + "not work.", e);
        }
        
        try {
            
            //also register it with the Apache httpclient (sigh)
            SSLContext sc = SSLContext.getInstance("SSL");
            sc.init(null, new TrustManager[]{new TerribleTrustManager()},
                    new java.security.SecureRandom());
            SslContextedSecureProtocolSocketFactory secureProtocolSocketFactory
                    = new SslContextedSecureProtocolSocketFactory(sc);
            secureProtocolSocketFactory.setHostnameVerification(false);
            Protocol.registerProtocol("https", new Protocol("https",
                    (ProtocolSocketFactory) secureProtocolSocketFactory, 443));
        } catch (Exception e) {
            
        }
    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {

    }

}<commit_msg>cleaned up trust manager registration<commit_after>package org.geoint.keyhole.ssl;

import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
import org.apache.commons.httpclient.protocol.Protocol;
import org.apache.commons.httpclient.protocol.ProtocolSocketFactory;
import org.jsslutils.extra.apachehttpclient.SslContextedSecureProtocolSocketFactory;

/**
 *
 */
@WebListener("terribleTrustManager")
public class TerribleTrustManagerInstaller implements ServletContextListener {

    private static final Logger logger = Logger
            .getLogger(TerribleTrustManagerInstaller.class.getName());

    @Override
    public void contextInitialized(ServletContextEvent sce) {
        logger.log(Level.WARNING, "This proxy currently disables ssl server"
                + " valiation.  This will be fixed in a future version.");

        SSLContext sc = null;
        try {
            //register global accept trust manager with the Java SSLContext
            sc = SSLContext.getInstance("SSL");
            sc.init(null, new TrustManager[]{new TerribleTrustManager()},
                    new java.security.SecureRandom());

            //set this context as the JVM default SSL socket factory
            HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());

            //also register with Apach httpclient3, as it does not use the 
            //JVM default 
            SslContextedSecureProtocolSocketFactory secureProtocolSocketFactory
                    = new SslContextedSecureProtocolSocketFactory(sc, false);
            Protocol.registerProtocol("https", new Protocol("https",
                    (ProtocolSocketFactory) secureProtocolSocketFactory, 443));

        } catch (NoSuchAlgorithmException | KeyManagementException e) {
            logger.log(Level.SEVERE, "Unable to register SSL work around, "
                    + "requsts to HTTPS servers with invalid certificates will "
                    + "not work.", e);
        }
    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {

    }

}
{'fraction_non_alphanumeric': 0.082423243354626, 'fraction_numerical': 0.001442406758705955, 'mean_word_length': 2.939935064935065, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3021961', 'n_tokens_mistral': 1226, 'n_tokens_neox': 1178, 'n_words': 282}