Datasets:

Modalities:
Text
Formats:
json
Languages:
code
Size:
< 1K
Tags:
code
Libraries:
Datasets
pandas
License:
File size: 3,083 Bytes
6312f15
1
package net.sf.borg.model.sync.ical;import org.apache.commons.httpclient.HttpClientError;import org.apache.commons.httpclient.params.HttpConnectionParams;import org.apache.commons.httpclient.protocol.ControllerThreadSocketFactory;import org.apache.commons.httpclient.protocol.SecureProtocolSocketFactory;import javax.net.ssl.SSLContext;import javax.net.ssl.TrustManager;import java.io.IOException;import java.net.InetAddress;import java.net.Socket;import java.util.logging.Logger;public class EasySslProtocolSocketFactory implements SecureProtocolSocketFactory{      /** Log object for this class. */	static private final Logger LOG = Logger.getLogger("net.sf.borg");private SSLContext sslcontext = null;  /**   * Constructor for EasySSLProtocolSocketFactory.   */  public EasySslProtocolSocketFactory()  {    super();  }  /**   * @see SecureProtocolSocketFactory#createSocket(java.lang.String,int,java.net.InetAddress,int)   */  public Socket createSocket(String host, int port, InetAddress clientHost, int clientPort)    throws IOException {    return getSSLContext().getSocketFactory().createSocket(host, port, clientHost, clientPort);  }    public Socket createSocket(final String host, final int port, final InetAddress localAddress, final int localPort,    final HttpConnectionParams params) throws IOException {    if (params == null)    {      throw new IllegalArgumentException("Parameters may not be null");    }    int timeout = params.getConnectionTimeout();    if (timeout == 0)    {      return createSocket(host, port, localAddress, localPort);    }    else    {      // To be eventually deprecated when migrated to Java 1.4 or above      return ControllerThreadSocketFactory.createSocket(this, host, port, localAddress, localPort, timeout);    }  }  /**   * @see SecureProtocolSocketFactory#createSocket(java.lang.String,int)   */  public Socket createSocket(String host, int port) throws IOException {    return getSSLContext().getSocketFactory().createSocket(host, port);  }  /**   * @see SecureProtocolSocketFactory#createSocket(java.net.Socket,java.lang.String,int,boolean)   */  public Socket createSocket(Socket socket, String host, int port, boolean autoClose)    throws IOException {    return getSSLContext().getSocketFactory().createSocket(socket, host, port, autoClose);  }  public boolean equals(Object obj)  {    return ((obj != null) && obj.getClass().equals(EasySslProtocolSocketFactory.class));  }  public int hashCode()  {    return EasySslProtocolSocketFactory.class.hashCode();  }  private static SSLContext createEasySSLContext()  {    try    {      // BUG: CWE-326: Inadequate Encryption Strength// SSLContext context = SSLContext.getInstance("SSL");// FIXED:       context.init(null, new TrustManager[] { new EasyX509TrustManager(null) }, null);      return context;    }    catch (Exception e)    {      LOG.severe(e.getMessage());      throw new HttpClientError(e.toString());    }  }  private SSLContext getSSLContext()  {    if (this.sslcontext == null)    {      this.sslcontext = createEasySSLContext();    }    return this.sslcontext;  }}