📄 protocol.java
字号:
AccessController.checkPermission(HTTPS_PERMISSION_NAME, name); permissionChecked = true; } catch (InterruptedSecurityException ise) { throw new InterruptedIOException( "Interrupted while trying to ask the user permission"); } try { AccessController. checkPermission(AccessController.TRUSTED_APP_PERMISSION_NAME); ownerTrusted = true; } catch (SecurityException se) { ownerTrusted = false; } } /** * Get the request header value for the named property. * @param key property name of specific HTTP 1.1 header field * @return value of the named property, if found, null otherwise. */ public String getRequestProperty(String key) { /* https handles the proxy fields in a different way */ if (key.toLowerCase().startsWith("proxy-")) { return proxyHeaders.getPropertyIgnoreCase(key); } return super.getRequestProperty(key); } /** * Add the named field to the list of request fields. * * @param key key for the request header field. * @param value the value for the request header field. */ protected void setRequestField(String key, String value) { /* https handles the proxy fields in a different way */ if (key.toLowerCase().startsWith("proxy-")) { proxyHeaders.setPropertyIgnoreCase(key, value); return; } super.setRequestField(key, value); } /** * Connect to the underlying secure socket transport. * Perform the SSL handshake and then proceeded to the underlying * HTTP protocol connect semantics. * * @return SSL/TCP stream connection * @exception IOException is thrown if the connection cannot be opened */ protected StreamConnection connect() throws IOException { StreamConnection sc; String httpsTunnel; com.sun.midp.io.j2me.socket.Protocol tcpConnection; OutputStream tcpOutputStream; InputStream tcpInputStream; X509Certificate serverCert; if (!permissionChecked) { throw new SecurityException(); } sc = connectionPool.get(classSecurityToken, protocol, url.host, url.port); if (sc != null) { return sc; } // Open socket connection tcpConnection = new com.sun.midp.io.j2me.socket.Protocol(); // check to see if a protocol is specified for the tunnel httpsTunnel = Configuration.getProperty("com.sun.midp.io.http.proxy"); if (httpsTunnel != null) { // Make the connection to the ssl tunnel tcpConnection.openPrim(classSecurityToken, "//" + httpsTunnel); // Do not delay request since this delays the response. tcpConnection.setSocketOption(SocketConnection.DELAY, 0); tcpOutputStream = tcpConnection.openOutputStream(); tcpInputStream = tcpConnection.openInputStream(); // Do the handshake with the ssl tunnel try { doTunnelHandshake(tcpOutputStream, tcpInputStream); } catch (IOException ioe) { String temp = ioe.getMessage(); tcpConnection.close(); tcpOutputStream.close(); tcpInputStream.close(); if (temp.indexOf(" 500 ") > -1) { throw new ConnectionNotFoundException(temp); } throw ioe; } } else { tcpConnection.openPrim(classSecurityToken, "//" + hostAndPort); // Do not delay request since this delays the response. tcpConnection.setSocketOption(SocketConnection.DELAY, 0); tcpOutputStream = tcpConnection.openOutputStream(); tcpInputStream = tcpConnection.openInputStream(); } tcpConnection.close(); try { // Get the SSLStreamConnection sslConnection = new SSLStreamConnection(url.host, url.port, tcpInputStream, tcpOutputStream, WebPublicKeyStore.getTrustedKeyStore()); } catch (Exception e) { try { tcpInputStream.close(); } catch (Throwable t) { // Ignore, we are processing an exception } try { tcpOutputStream.close(); } catch (Throwable t) { // Ignore, we are processing an exception } if (e instanceof IOException) { throw (IOException)e; } else { throw (RuntimeException)e; } } try { serverCert = sslConnection.getServerCertificate(); /* * if the subject alternate name is a DNS name or an IP address, * then use that instead of the common name for a site name match */ int i; Vector v = serverCert.getSubjectAltNames(); boolean altNamePresent = false; for (i = 0; i < v.size(); i++) { SubjectAlternativeName altName = (SubjectAlternativeName) v.elementAt(i); // For IP address, it needs to be exact match if (altName.getSubjectAltNameType() == X509Certificate.TYPE_IP_ADDRESS) { String ipAddress = (String)altName.getSubjectAltName(); altNamePresent = true; if (url.host.equalsIgnoreCase(ipAddress)) { break; } } else if (altName.getSubjectAltNameType() == X509Certificate.TYPE_DNS_NAME) { // compare DNS Name with host in url String dnsName = ((String)altName.getSubjectAltName()).toLowerCase(); altNamePresent = true; if (checkSiteName(url.host, dnsName)) { break; } } } if (altNamePresent) { if (i == v.size()) { throw new CertificateException( "Subject alternative name did not match site name", serverCert, CertificateException.SITENAME_MISMATCH); } } else { String cname = getCommonName(serverCert.getSubject()); if (cname == null) { throw new CertificateException( "Common name missing from subject name", serverCert, CertificateException.SITENAME_MISMATCH); } if (!checkSiteName(url.host, cname)) { throw new CertificateException(serverCert, CertificateException.SITENAME_MISMATCH); } } return sslConnection; } catch (Exception e) { try { sslConnection.close(); } catch (Throwable t) { // Ignore, we are processing an exception } if (e instanceof IOException) { throw (IOException)e; } else { throw (RuntimeException)e; } } } /** * disconnect the current connection. * * @param connection connection return from {@link #connect()} * @param inputStream input stream opened from <code>connection</code> * @param outputStream output stream opened from <code>connection</code> * @exception IOException if an I/O error occurs while * the connection is terminated. */ protected void disconnect(StreamConnection connection, InputStream inputStream, OutputStream outputStream) throws IOException { try { try { inputStream.close(); } finally { try { outputStream.close(); } finally { connection.close(); } } } catch (IOException e) { if (Logging.REPORT_LEVEL <= Logging.WARNING) { Logging.report(Logging.WARNING, LogChannels.LC_PROTOCOL, "Exception while closing streams|connection"); } } catch (NullPointerException e) { } } /** * Return the security information associated with this connection. * If the connection is still in <CODE>Setup</CODE> state then * the connection is initiated to establish the secure connection * to the server. The method returns when the connection is * established and the <CODE>Certificate</CODE> supplied by the * server has been validated. * The <CODE>SecurityInfo</CODE> is only returned if the * connection has been successfully made to the server. * * @return the security information associated with this open connection. * * @exception CertificateException if the <code>Certificate</code> * supplied by the server cannot be validated. * The <code>CertificateException</code> will contain * the information about the error and indicate the certificate in the * validation chain with the error. * @exception IOException if an arbitrary connection failure occurs */ public SecurityInfo getSecurityInfo() throws IOException { ensureOpen(); sendRequest(); if (sslConnection == null) { /* * This is a persistent connection so the connect method did * not get called, so the stream connection of HTTP class * will be a SSL connection. Get the info from that. */ StreamConnection sc = ((StreamConnectionElement)getStreamConnection()). getBaseConnection(); return ((SSLStreamConnection)sc).getSecurityInfo(); } return sslConnection.getSecurityInfo(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -