<commit_before>package nerd.tuxmobil.fahrplan.congress.net;

import android.annotation.SuppressLint;
import android.app.Application;
import android.content.Context;
import android.util.Log;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.HashMap;
import java.util.Map;

import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;

import nerd.tuxmobil.fahrplan.congress.MyApp;
import nerd.tuxmobil.fahrplan.congress.net.exceptions.CertificateDomainMismatchException;

// modified copy from K-9 Mail


public final class TrustManagerFactory {

    private static final String LOG_TAG = "TrustManagerFactory";

    private static X509TrustManager defaultTrustManager;

    private static X509TrustManager insecureTrustManager;

    private static X509TrustManager localTrustManager;

    private static X509Certificate[] lastCertChain = null;

    private static File keyStoreFile;

    private static KeyStore keyStore;


    @SuppressLint("TrustAllX509TrustManager")
    private static class InsecureX509TrustManager implements X509TrustManager {

        public void checkClientTrusted(X509Certificate[] chain, String authType)
                throws CertificateException {
        }

        public void checkServerTrusted(X509Certificate[] chain, String authType)
                throws CertificateException {
        }

        public X509Certificate[] getAcceptedIssuers() {
            return null;
        }
    }

    private static class SecureX509TrustManager implements X509TrustManager {

        private static final Map<String, SecureX509TrustManager> mTrustManager =
                new HashMap<>();

        private final String mHost;

        private SecureX509TrustManager(String host) {
            Log.d("TrustManagerFactory", "SecureX509TrustManager(" + host + ")");
            mHost = host;
        }

        public static synchronized X509TrustManager getInstance(String host) {
            SecureX509TrustManager trustManager;
            if (mTrustManager.containsKey(host)) {
                trustManager = mTrustManager.get(host);
            } else {
                trustManager = new SecureX509TrustManager(host);
                mTrustManager.put(host, trustManager);
            }

            return trustManager;
        }

        public void checkClientTrusted(X509Certificate[] chain, String authType)
                throws CertificateException {
            defaultTrustManager.checkClientTrusted(chain, authType);
        }

        public void checkServerTrusted(X509Certificate[] chain, String authType)
                throws CertificateException {
            TrustManagerFactory.setLastCertChain(chain);
            if (!DomainNameChecker.match(chain[0], mHost)) {
                throw new CertificateDomainMismatchException("Certificate domain name does not match " + mHost);
            }
            try {
                // Try localTrustManager first, since self-signed certificates
                // are used in most of the cases
                Log.d(LOG_TAG, "trying localTrustManager");
                localTrustManager.checkServerTrusted(new X509Certificate[]{chain[0]}, authType);
            } catch (CertificateException e) {
                /* Here fallback on to trustworthy CAs in Android */

                /* SSL Pinning, do not trust any CA */
                Log.d(LOG_TAG, "trying defaultTrustManager");
                defaultTrustManager.checkServerTrusted(chain, authType);
            }
        }

        public X509Certificate[] getAcceptedIssuers() {
            return defaultTrustManager.getAcceptedIssuers();
        }

    }
<commit_msg>Add missing override annotations.<commit_after>package nerd.tuxmobil.fahrplan.congress.net;

import android.annotation.SuppressLint;
import android.app.Application;
import android.content.Context;
import android.util.Log;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.HashMap;
import java.util.Map;

import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;

import nerd.tuxmobil.fahrplan.congress.MyApp;
import nerd.tuxmobil.fahrplan.congress.net.exceptions.CertificateDomainMismatchException;

// modified copy from K-9 Mail


public final class TrustManagerFactory {

    private static final String LOG_TAG = "TrustManagerFactory";

    private static X509TrustManager defaultTrustManager;

    private static X509TrustManager insecureTrustManager;

    private static X509TrustManager localTrustManager;

    private static X509Certificate[] lastCertChain = null;

    private static File keyStoreFile;

    private static KeyStore keyStore;


    @SuppressLint("TrustAllX509TrustManager")
    private static class InsecureX509TrustManager implements X509TrustManager {

        @Override
        public void checkClientTrusted(X509Certificate[] chain, String authType)
                throws CertificateException {
        }

        @Override
        public void checkServerTrusted(X509Certificate[] chain, String authType)
                throws CertificateException {
        }

        @Override
        public X509Certificate[] getAcceptedIssuers() {
            return null;
        }
    }

    private static class SecureX509TrustManager implements X509TrustManager {

        private static final Map<String, SecureX509TrustManager> mTrustManager =
                new HashMap<>();

        private final String mHost;

        private SecureX509TrustManager(String host) {
            Log.d("TrustManagerFactory", "SecureX509TrustManager(" + host + ")");
            mHost = host;
        }

        public static synchronized X509TrustManager getInstance(String host) {
            SecureX509TrustManager trustManager;
            if (mTrustManager.containsKey(host)) {
                trustManager = mTrustManager.get(host);
            } else {
                trustManager = new SecureX509TrustManager(host);
                mTrustManager.put(host, trustManager);
            }

            return trustManager;
        }

        @Override
        public void checkClientTrusted(X509Certificate[] chain, String authType)
                throws CertificateException {
            defaultTrustManager.checkClientTrusted(chain, authType);
        }

        @Override
        public void checkServerTrusted(X509Certificate[] chain, String authType)
                throws CertificateException {
            TrustManagerFactory.setLastCertChain(chain);
            if (!DomainNameChecker.match(chain[0], mHost)) {
                throw new CertificateDomainMismatchException("Certificate domain name does not match " + mHost);
            }
            try {
                // Try localTrustManager first, since self-signed certificates
                // are used in most of the cases
                Log.d(LOG_TAG, "trying localTrustManager");
                localTrustManager.checkServerTrusted(new X509Certificate[]{chain[0]}, authType);
            } catch (CertificateException e) {
                /* Here fallback on to trustworthy CAs in Android */

                /* SSL Pinning, do not trust any CA */
                Log.d(LOG_TAG, "trying defaultTrustManager");
                defaultTrustManager.checkServerTrusted(chain, authType);
            }
        }

        @Override
        public X509Certificate[] getAcceptedIssuers() {
            return defaultTrustManager.getAcceptedIssuers();
        }

    }

{'fraction_non_alphanumeric': 0.07150063051702396, 'fraction_numerical': 0.018915510718789406, 'mean_word_length': 2.7078073866292662, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '6892151', 'n_tokens_mistral': 2187, 'n_tokens_neox': 1925, 'n_words': 471}