📄 sslsocket.java
字号:
else { return super.getLocalSocketAddress(); } } public SocketChannel getChannel() { return channel; } public boolean isBound() { if (underlyingSocket != null) { return underlyingSocket.isBound(); } else { return super.isBound(); } //throw new UnsupportedOperationException("1.4 methods not enabled"); } public boolean isClosed() { if (underlyingSocket != null) { return underlyingSocket.isClosed(); } else { return super.isClosed(); } //throw new UnsupportedOperationException("1.4 methods not enabled"); } //public SocketAddress getRemoteSocketAddress() //{ // if (underlyingSocket != null) // { // return underlyingSocket.getRemoteSocketAddress(); // } // else // { // return super.getRemoteSocketAddress(); // } //} public void setOOBInline(boolean flag) throws SocketException { //if (underlyingSocket != null) // { // underlyingSocket.setOOBInline(flag); // } //else // { // super.setOOBInline(flag); // } throw new UnsupportedOperationException("1.4 methods not enabled"); } public boolean getOOBInline() throws SocketException { //if (underlyingSocket != null) // { // return underlyingSocket.getOOBInline(); // } //else // { // return super.getOOBInline(); // } throw new UnsupportedOperationException("1.4 methods not enabled"); } public void setKeepAlive(boolean flag) throws SocketException { //if (underlyingSocket != null) // { // underlyingSocket.setKeepAlive(flag); // } //else // { // super.setKeepAlive(flag); // } throw new UnsupportedOperationException("1.4 methods not enabled"); } public boolean getKeepAlive() throws SocketException { //if (underlyingSocket != null) // { // return underlyingSocket.getKeepAlive(); // } //else // { // return super.getKeepAlive(); // } throw new UnsupportedOperationException("1.4 methods not enabled"); } public void setTrafficClass(int clazz) throws SocketException { //if (underlyingSocket != null) // { // underlyingSocket.setTrafficClass(clazz); // } //else // { // super.setTrafficClass(clazz); // } throw new UnsupportedOperationException("1.4 methods not enabled"); } public int getTrafficClass() throws SocketException { //if (underlyingSocket != null) // { // return underlyingSocket.getTrafficClass(); // } //else // { // return super.getTrafficClass(); // } throw new UnsupportedOperationException("1.4 methods not enabled"); } public void setReuseAddress(boolean flag) throws SocketException { //if (underlyingSocket != null) // { // underlyingSocket.setReuseAddress(flag); // } //else // { // super.setReuseAddress(flag); // } throw new UnsupportedOperationException("1.4 methods not enabled"); } public boolean getReuseAddress() throws SocketException { //if (underlyingSocket != null) // { // return underlyingSocket.getReuseAddress(); // } //else // { // return super.getReuseAddress(); // } throw new UnsupportedOperationException("1.4 methods not enabled"); } public void shutdownInput() throws IOException { //if (underlyingSocket != null) // { // underlyingSocket.shutdownInput(); // } //else // { // super.shutdownInput(); // } throw new UnsupportedOperationException("1.4 methods not enabled"); } public void shutdownOutput() throws IOException { //if (underlyingSocket != null) // { // underlyingSocket.shutdownOutput(); // } //else // { // super.shutdownOutput(); // } throw new UnsupportedOperationException("1.4 methods not enabled"); } public boolean isConnected() { if (underlyingSocket != null) { return underlyingSocket.isConnected(); } else { return super.isConnected(); } //throw new UnsupportedOperationException("1.4 methods not enabled"); } public boolean isInputShutdown() { //if (underlyingSocket != null) // { // return underlyingSocket.isInputShutdown(); // } //else // { // return super.isInputShutdown(); // } throw new UnsupportedOperationException("1.4 methods not enabled"); } public boolean isOutputShutdown() { //if (underlyingSocket != null) // { // return underlyingSocket.isOutputShutdown(); // } //else // { // return super.isOutputShutdown(); // } throw new UnsupportedOperationException("1.4 methods not enabled"); } protected void finalize() { if (session.currentAlert == null) { try { close(); } catch (Exception ignore) { } } }// Package methods. // ------------------------------------------------------------------------- void setSessionContext(SessionContext sessionContext) { this.sessionContext = sessionContext; } void setEnabledCipherSuites(List suites) { session.enabledSuites = suites; } void setEnabledProtocols(SortedSet protocols) { session.enabledProtocols = protocols; } void setSRPTrustManager(SRPTrustManager srpTrustManager) { session.srpTrustManager = srpTrustManager; } void setTrustManager(X509TrustManager trustManager) { session.trustManager = trustManager; } void setKeyManager(X509KeyManager keyManager) { session.keyManager = keyManager; } void setRandom(SecureRandom random) { session.random = random; } void sendAlert (Alert alert) throws IOException { RecordOutputStream out = new RecordOutputStream (socketOut, ContentType.ALERT, session.params); out.write (alert.getEncoded ()); } /** * Gets the most-recently-received alert message. * * @return The alert message. */ Alert checkAlert() { return session.currentAlert; } synchronized void checkHandshakeDone() throws IOException { if (!handshakeDone) { startHandshake(); } Alert alert = session.currentAlert; if (alert != null && alert.getLevel() == Alert.Level.FATAL) { throw new AlertException(alert, false); } if (handshakeIn.available() > 0 && !clientMode) { handshakeDone = false; startHandshake(); } }// Own methods. // ------------------------------------------------------------------------- private static final byte[] SENDER_CLIENT = new byte[] { 0x43, 0x4C, 0x4E, 0x54 }; private static final byte[] SENDER_SERVER = new byte[] { 0x53, 0x52, 0x56, 0x52 }; private void changeCipherSpec () throws IOException { RecordOutputStream out = new RecordOutputStream (socketOut, ContentType.CHANGE_CIPHER_SPEC, session.params); out.write (1); } private void readChangeCipherSpec () throws IOException { RecordInputStream in = new RecordInputStream (recordInput, ContentType.CHANGE_CIPHER_SPEC); if (in.read() != 1) { throw new SSLProtocolException ("bad change cipher spec message"); } } /** * Initializes the application data streams and starts the record layer * threads. */ private synchronized void setupIO() throws IOException { if (recordInput != null) { return; } if (underlyingSocket != null) { socketIn = underlyingSocket.getInputStream(); socketOut = underlyingSocket.getOutputStream(); } else { socketIn = super.getInputStream(); socketOut = super.getOutputStream(); }// recordLayer = new ThreadGroup("record_layer");// recordInput = new RecordInput(in, session, recordLayer);// recordOutput = new RecordOutput(out, session, recordLayer);// recordInput.setRecordOutput(recordOutput);// recordLayer.setDaemon(true);// recordInput.start();// recordOutput.start(); recordInput = new RecordInput (socketIn, session); applicationIn = new SSLSocketInputStream( new RecordInputStream (recordInput, ContentType.APPLICATION_DATA), this); applicationOut = new SSLSocketOutputStream( new RecordOutputStream (socketOut, ContentType.APPLICATION_DATA, session.params), this); handshakeIn = new SSLSocketInputStream( new RecordInputStream (recordInput, ContentType.HANDSHAKE), this, false); handshakeOut = new BufferedOutputStream (new SSLSocketOutputStream( new RecordOutputStream (socketOut, ContentType.HANDSHAKE, session.params), this, false), 8096); } private void handshakeCompleted () { handshakeDone = true; HandshakeCompletedEvent event = new HandshakeCompletedEvent (this, session); for (Iterator it = handshakeListeners.iterator (); it.hasNext (); ) { try { ((HandshakeCompletedListener) it.next ()).handshakeCompleted (event); } catch (Throwable t) { } } if (createSessions) { synchronized (session) { sessionContext.addSession (session.sessionId, session); session.access (); } } if (DEBUG_HANDSHAKE_LAYER) { logger.log (Component.SSL_HANDSHAKE, "Handshake finished in {0}", Thread.currentThread()); handshakeTime = System.currentTimeMillis() - handshakeTime; logger.log (Component.SSL_HANDSHAKE, "Elapsed time {0}s", new Long (handshakeTime / 1000)); } } /* * Perform the client handshake. The process looks like this: * * ClientHello --> * ServerHello <-- * Certificate* <-- * ServerKeyExchange* <-- * CertificateRequest* <-- * ServerHelloDone* <-- * Certificate* --> * ClientKeyExchange --> * CertificateVerify* --> * [ChangeCipherSpec] --> * Finished --> * [ChangeCipherSpec] <-- * Finished <--
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -