private String getUserAgent() { String userAgent = (String) java.security.AccessController.doPrivileged( new sun.security.action.GetPropertyAction("https.agent")); if (userAgent == null || userAgent.length() == 0) { userAgent = "JSSE"; } return userAgent; }
private String getProxyHost() { String host = (String) java.security.AccessController.doPrivileged( new sun.security.action.GetPropertyAction("https.proxyHost")); if (host != null && host.length() == 0) { host = null; } return host; }
private int getProxyPort() { final int port[] = {0}; java.security.AccessController.doPrivileged( new java.security.PrivilegedAction() { public Object run() { if (System.getProperty("https.proxyHost") != null) { port[0] = Integer.getInteger("https.proxyPort", 80).intValue(); } return null; } }); return (port[0] < 0) ? super.getDefaultPort() : port[0]; }
/** * Overrides HTTP protocol handler method so that we return an SSL socket, not a TCP socket. This * establishes a secure tunnel if appropriate. * * @param host the host to connect to * @param port the port on that host. * @exception IOException on errors including a host doesn't authenicate corectly. * @exception UnknownHostException if "host" is unknown */ protected Socket doConnect(String host, int port) throws IOException, UnknownHostException { // doConnect() ends up getting called from the // HttpClient constructor, so our constructor can't do any // meaningful initialization. This could be made nicer // by refactoring HttpClient and HttpsClient so that they // have a common base class. instTunnelHost = ((instTunnelHost != null) ? instTunnelHost : getProxyHost()); instTunnelPort = ((instTunnelPort != 0) ? instTunnelPort : getProxyPort()); Socket s = null; SSLSocketFactory factory; factory = sslSocketFactory; if (instTunnelHost == null || isNonProxyHost()) { s = factory.createSocket(host, port); } else { try { s = (Socket) java.security.AccessController.doPrivileged( new java.security.PrivilegedExceptionAction() { public Object run() throws IOException { return new Socket(instTunnelHost, instTunnelPort); } }); } catch (java.security.PrivilegedActionException pae) { throw (IOException) pae.getException(); } catch (IOException ex) { // If we fail to connect through the tunnel, try it // locally, as a last resort. If this doesn't work, // throw the original exception. try { s = (SSLSocket) factory.createSocket(host, port); } catch (IOException ignored) { throw ex; } } } return s; }