< prev index next >

src/java.base/share/classes/sun/net/www/protocol/https/HttpsClient.java

Print this page
rev 14210 : 8154231: Simplify access to System properties from JDK code
Reviewed-by: rriggs


  24  */
  25 
  26 
  27 package sun.net.www.protocol.https;
  28 
  29 import java.io.IOException;
  30 import java.io.UnsupportedEncodingException;
  31 import java.io.PrintStream;
  32 import java.io.BufferedOutputStream;
  33 import java.net.InetAddress;
  34 import java.net.Socket;
  35 import java.net.SocketException;
  36 import java.net.URL;
  37 import java.net.UnknownHostException;
  38 import java.net.InetSocketAddress;
  39 import java.net.Proxy;
  40 import java.security.Principal;
  41 import java.security.cert.*;
  42 import java.util.StringTokenizer;
  43 import java.util.Vector;
  44 import java.security.AccessController;
  45 
  46 import javax.security.auth.x500.X500Principal;
  47 
  48 import javax.net.ssl.*;
  49 import sun.net.www.http.HttpClient;
  50 import sun.net.www.protocol.http.HttpURLConnection;
  51 import sun.security.action.*;
  52 
  53 import sun.security.util.HostnameChecker;
  54 import sun.security.ssl.SSLSocketImpl;
  55 
  56 import sun.util.logging.PlatformLogger;
  57 import static sun.net.www.protocol.http.HttpURLConnection.TunnelState.*;
  58 
  59 
  60 /**
  61  * This class provides HTTPS client URL support, building on the standard
  62  * "sun.net.www" HTTP protocol handler.  HTTPS is the same protocol as HTTP,
  63  * but differs in the transport layer which it uses:  <UL>
  64  *


 122     protected int getDefaultPort() { return httpsPortNumber; }
 123 
 124     private HostnameVerifier hv;
 125     private SSLSocketFactory sslSocketFactory;
 126 
 127     // HttpClient.proxyDisabled will always be false, because we don't
 128     // use an application-level HTTP proxy.  We might tunnel through
 129     // our http proxy, though.
 130 
 131 
 132     // INSTANCE DATA
 133 
 134     // last negotiated SSL session
 135     private SSLSession  session;
 136 
 137     private String [] getCipherSuites() {
 138         //
 139         // If ciphers are assigned, sort them into an array.
 140         //
 141         String ciphers [];
 142         String cipherString = AccessController.doPrivileged(
 143                 new GetPropertyAction("https.cipherSuites"));
 144 
 145         if (cipherString == null || "".equals(cipherString)) {
 146             ciphers = null;
 147         } else {
 148             StringTokenizer     tokenizer;
 149             Vector<String>      v = new Vector<String>();
 150 
 151             tokenizer = new StringTokenizer(cipherString, ",");
 152             while (tokenizer.hasMoreTokens())
 153                 v.addElement(tokenizer.nextToken());
 154             ciphers = new String [v.size()];
 155             for (int i = 0; i < ciphers.length; i++)
 156                 ciphers [i] = v.elementAt(i);
 157         }
 158         return ciphers;
 159     }
 160 
 161     private String [] getProtocols() {
 162         //
 163         // If protocols are assigned, sort them into an array.
 164         //
 165         String protocols [];
 166         String protocolString = AccessController.doPrivileged(
 167                 new GetPropertyAction("https.protocols"));
 168 
 169         if (protocolString == null || "".equals(protocolString)) {
 170             protocols = null;
 171         } else {
 172             StringTokenizer     tokenizer;
 173             Vector<String>      v = new Vector<String>();
 174 
 175             tokenizer = new StringTokenizer(protocolString, ",");
 176             while (tokenizer.hasMoreTokens())
 177                 v.addElement(tokenizer.nextToken());
 178             protocols = new String [v.size()];
 179             for (int i = 0; i < protocols.length; i++) {
 180                 protocols [i] = v.elementAt(i);
 181             }
 182         }
 183         return protocols;
 184     }
 185 
 186     private String getUserAgent() {
 187         String userAgent = java.security.AccessController.doPrivileged(
 188                 new sun.security.action.GetPropertyAction("https.agent"));
 189         if (userAgent == null || userAgent.length() == 0) {
 190             userAgent = "JSSE";
 191         }
 192         return userAgent;
 193     }
 194 
 195     // CONSTRUCTOR, FACTORY
 196 
 197 
 198     /**
 199      * Create an HTTPS client URL.  Traffic will be tunneled through any
 200      * intermediate nodes rather than proxied, so that confidentiality
 201      * of data exchanged can be preserved.  However, note that all the
 202      * anonymous SSL flavors are subject to "person-in-the-middle"
 203      * attacks against confidentiality.  If you enable use of those
 204      * flavors, you may be giving up the protection you get through
 205      * SSL tunneling.
 206      *
 207      * Use New to get new HttpsClient. This constructor is meant to be
 208      * used only by New method. New properly checks for URL spoofing.




  24  */
  25 
  26 
  27 package sun.net.www.protocol.https;
  28 
  29 import java.io.IOException;
  30 import java.io.UnsupportedEncodingException;
  31 import java.io.PrintStream;
  32 import java.io.BufferedOutputStream;
  33 import java.net.InetAddress;
  34 import java.net.Socket;
  35 import java.net.SocketException;
  36 import java.net.URL;
  37 import java.net.UnknownHostException;
  38 import java.net.InetSocketAddress;
  39 import java.net.Proxy;
  40 import java.security.Principal;
  41 import java.security.cert.*;
  42 import java.util.StringTokenizer;
  43 import java.util.Vector;

  44 
  45 import javax.security.auth.x500.X500Principal;
  46 
  47 import javax.net.ssl.*;
  48 import sun.net.www.http.HttpClient;
  49 import sun.net.www.protocol.http.HttpURLConnection;
  50 import sun.security.action.*;
  51 
  52 import sun.security.util.HostnameChecker;
  53 import sun.security.ssl.SSLSocketImpl;
  54 
  55 import sun.util.logging.PlatformLogger;
  56 import static sun.net.www.protocol.http.HttpURLConnection.TunnelState.*;
  57 
  58 
  59 /**
  60  * This class provides HTTPS client URL support, building on the standard
  61  * "sun.net.www" HTTP protocol handler.  HTTPS is the same protocol as HTTP,
  62  * but differs in the transport layer which it uses:  <UL>
  63  *


 121     protected int getDefaultPort() { return httpsPortNumber; }
 122 
 123     private HostnameVerifier hv;
 124     private SSLSocketFactory sslSocketFactory;
 125 
 126     // HttpClient.proxyDisabled will always be false, because we don't
 127     // use an application-level HTTP proxy.  We might tunnel through
 128     // our http proxy, though.
 129 
 130 
 131     // INSTANCE DATA
 132 
 133     // last negotiated SSL session
 134     private SSLSession  session;
 135 
 136     private String [] getCipherSuites() {
 137         //
 138         // If ciphers are assigned, sort them into an array.
 139         //
 140         String ciphers [];
 141         String cipherString =
 142                 GetPropertyAction.getProperty("https.cipherSuites");
 143 
 144         if (cipherString == null || "".equals(cipherString)) {
 145             ciphers = null;
 146         } else {
 147             StringTokenizer     tokenizer;
 148             Vector<String>      v = new Vector<String>();
 149 
 150             tokenizer = new StringTokenizer(cipherString, ",");
 151             while (tokenizer.hasMoreTokens())
 152                 v.addElement(tokenizer.nextToken());
 153             ciphers = new String [v.size()];
 154             for (int i = 0; i < ciphers.length; i++)
 155                 ciphers [i] = v.elementAt(i);
 156         }
 157         return ciphers;
 158     }
 159 
 160     private String [] getProtocols() {
 161         //
 162         // If protocols are assigned, sort them into an array.
 163         //
 164         String protocols [];
 165         String protocolString =
 166                 GetPropertyAction.getProperty("https.protocols");
 167 
 168         if (protocolString == null || "".equals(protocolString)) {
 169             protocols = null;
 170         } else {
 171             StringTokenizer     tokenizer;
 172             Vector<String>      v = new Vector<String>();
 173 
 174             tokenizer = new StringTokenizer(protocolString, ",");
 175             while (tokenizer.hasMoreTokens())
 176                 v.addElement(tokenizer.nextToken());
 177             protocols = new String [v.size()];
 178             for (int i = 0; i < protocols.length; i++) {
 179                 protocols [i] = v.elementAt(i);
 180             }
 181         }
 182         return protocols;
 183     }
 184 
 185     private String getUserAgent() {
 186         String userAgent = GetPropertyAction.getProperty("https.agent");

 187         if (userAgent == null || userAgent.length() == 0) {
 188             userAgent = "JSSE";
 189         }
 190         return userAgent;
 191     }
 192 
 193     // CONSTRUCTOR, FACTORY
 194 
 195 
 196     /**
 197      * Create an HTTPS client URL.  Traffic will be tunneled through any
 198      * intermediate nodes rather than proxied, so that confidentiality
 199      * of data exchanged can be preserved.  However, note that all the
 200      * anonymous SSL flavors are subject to "person-in-the-middle"
 201      * attacks against confidentiality.  If you enable use of those
 202      * flavors, you may be giving up the protection you get through
 203      * SSL tunneling.
 204      *
 205      * Use New to get new HttpsClient. This constructor is meant to be
 206      * used only by New method. New properly checks for URL spoofing.


< prev index next >