<commit_before>package org.postgresql.ssl.jdbc4;

import java.io.Console;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.security.KeyManagementException;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.Certificate;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.util.Iterator;
import java.util.Properties;

import javax.naming.InvalidNameException;
import javax.naming.ldap.LdapName;
import javax.naming.ldap.Rdn;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.KeyManager;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLPeerUnverifiedException;
import javax.net.ssl.SSLSession;
import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory;
import javax.security.auth.callback.Callback;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.callback.PasswordCallback;
import javax.security.auth.callback.UnsupportedCallbackException;
import javax.security.auth.x500.X500Principal;

import org.postgresql.ssl.NonValidatingFactory.NonValidatingTM;
import org.postgresql.ssl.WrappedFactory;
import org.postgresql.util.GT;
import org.postgresql.util.PSQLException;
import org.postgresql.util.PSQLState;

/**
 * Provide an SSLSocketFactory that is compatible with the libpq
 * behaviour.
 */
public class LibPQFactory extends WrappedFactory implements HostnameVerifier {

    LazyKeyManager km = null;
    String sslmode; 
    /**
     * 
     * @param info the connection parameters
     * The following parameters are used:
     * sslmode,sslcert,sslkey,sslrootcert,sslhostnameverifier,sslpasswordcallback,sslpassword
     * @throws GeneralSecurityException
     * @throws IOException 
     * @throws UnsupportedCallbackException 
     */
    public LibPQFactory(Properties info) throws PSQLException {
      try
      {
        sslmode = info.getProperty("sslmode");
        SSLContext ctx = SSLContext.getInstance("TLS"); // or "SSL" ?
        
        //Determinig the default file location
        String pathsep = System.getProperty("path.separator");
        String defaultdir;
        boolean defaultfile = false;
        if (System.getProperty("os.name").toLowerCase().indexOf("windows") > -1)
        { //It is Windows
          defaultdir = System.getenv("APPDATA")+pathsep+"postgresql"+pathsep;
        } else {
          defaultdir = System.getProperty("user.home")+pathsep+".postgresql"+pathsep;
        }
        
        //Load the client's certificate and key
        String sslcertfile = info.getProperty("sslcert");
        if (sslcertfile == null)
        { //Fall back to default
          defaultfile = true;<commit_msg>Use proper System property<commit_after>package org.postgresql.ssl.jdbc4;

import java.io.Console;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.security.KeyManagementException;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.Certificate;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.util.Iterator;
import java.util.Properties;

import javax.naming.InvalidNameException;
import javax.naming.ldap.LdapName;
import javax.naming.ldap.Rdn;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.KeyManager;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLPeerUnverifiedException;
import javax.net.ssl.SSLSession;
import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory;
import javax.security.auth.callback.Callback;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.callback.PasswordCallback;
import javax.security.auth.callback.UnsupportedCallbackException;
import javax.security.auth.x500.X500Principal;

import org.postgresql.ssl.NonValidatingFactory.NonValidatingTM;
import org.postgresql.ssl.WrappedFactory;
import org.postgresql.util.GT;
import org.postgresql.util.PSQLException;
import org.postgresql.util.PSQLState;

/**
 * Provide an SSLSocketFactory that is compatible with the libpq
 * behaviour.
 */
public class LibPQFactory extends WrappedFactory implements HostnameVerifier {

    LazyKeyManager km = null;
    String sslmode; 
    /**
     * 
     * @param info the connection parameters
     * The following parameters are used:
     * sslmode,sslcert,sslkey,sslrootcert,sslhostnameverifier,sslpasswordcallback,sslpassword
     * @throws GeneralSecurityException
     * @throws IOException 
     * @throws UnsupportedCallbackException 
     */
    public LibPQFactory(Properties info) throws PSQLException {
      try
      {
        sslmode = info.getProperty("sslmode");
        SSLContext ctx = SSLContext.getInstance("TLS"); // or "SSL" ?
        
        //Determinig the default file location
        String pathsep = System.getProperty("file.separator");
        String defaultdir;
        boolean defaultfile = false;
        if (System.getProperty("os.name").toLowerCase().indexOf("windows") > -1)
        { //It is Windows
          defaultdir = System.getenv("APPDATA")+pathsep+"postgresql"+pathsep;
        } else {
          defaultdir = System.getProperty("user.home")+pathsep+".postgresql"+pathsep;
        }
        
        //Load the client's certificate and key
        String sslcertfile = info.getProperty("sslcert");
        if (sslcertfile == null)
        { //Fall back to default
          defaultfile = true;
{'fraction_non_alphanumeric': 0.09659982563208369, 'fraction_numerical': 0.0038360941586748037, 'mean_word_length': 4.058201058201059, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '1357612', 'n_tokens_mistral': 1620, 'n_tokens_neox': 1598, 'n_words': 330}