< prev index next >

src/java.base/share/classes/sun/security/ssl/TransportContext.java

Print this page




  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.security.ssl;
  27 
  28 import java.io.IOException;
  29 import java.security.AccessControlContext;
  30 import java.security.AccessController;
  31 import java.security.PrivilegedAction;
  32 import java.util.HashMap;
  33 import java.util.HashSet;
  34 import java.util.List;
  35 import java.util.Map;
  36 import java.util.Set;
  37 import javax.net.ssl.HandshakeCompletedEvent;
  38 import javax.net.ssl.HandshakeCompletedListener;
  39 import javax.net.ssl.SSLEngineResult.HandshakeStatus;
  40 import javax.net.ssl.SSLException;
  41 import javax.net.ssl.SSLSocket;

  42 
  43 /**
  44  * SSL/(D)TLS transportation context.
  45  */
  46 class TransportContext implements ConnectionContext {
  47     final SSLTransport              transport;
  48 
  49     // registered plaintext consumers
  50     final Map<Byte, SSLConsumer>    consumers;
  51     final AccessControlContext      acc;
  52 
  53     final SSLContextImpl            sslContext;
  54     final SSLConfiguration          sslConfig;
  55     final InputRecord               inputRecord;
  56     final OutputRecord              outputRecord;
  57 
  58     // connection status
  59     boolean                         isUnsureMode;
  60     boolean                         isNegotiated = false;
  61     boolean                         isBroken = false;


 141 
 142     // Dispatch plaintext to a specific consumer.
 143     void dispatch(Plaintext plaintext) throws IOException {
 144         if (plaintext == null) {
 145             return;
 146         }
 147 
 148         ContentType ct = ContentType.valueOf(plaintext.contentType);
 149         if (ct == null) {
 150             throw fatal(Alert.UNEXPECTED_MESSAGE,
 151                 "Unknown content type: " + plaintext.contentType);
 152         }
 153 
 154         switch (ct) {
 155             case HANDSHAKE:
 156                 byte type = HandshakeContext.getHandshakeType(this,
 157                         plaintext);
 158                 if (handshakeContext == null) {
 159                     if (type == SSLHandshake.KEY_UPDATE.id ||
 160                             type == SSLHandshake.NEW_SESSION_TICKET.id) {
 161                         if (!isNegotiated) {
 162                             throw fatal(Alert.UNEXPECTED_MESSAGE,
 163                                     "Unexpected unnegotiated post-handshake" +
 164                                             " message: " +
 165                                             SSLHandshake.nameOf(type));
 166                         }
 167                         if (type == SSLHandshake.KEY_UPDATE.id &&
 168                                 !protocolVersion.useTLS13PlusSpec()) {
 169                             throw fatal(Alert.UNEXPECTED_MESSAGE,
 170                                     "Unexpected post-handshake message: " +
 171                                     SSLHandshake.nameOf(type));
 172                         }
 173                         handshakeContext = new PostHandshakeContext(this);
 174                     } else {
 175                         handshakeContext = sslConfig.isClientMode ?
 176                                 new ClientHandshakeContext(sslContext, this) :
 177                                 new ServerHandshakeContext(sslContext, this);
 178                         outputRecord.initHandshaker();
 179                     }
 180                 }
 181                 handshakeContext.dispatch(type, plaintext);
 182                 break;
 183             case ALERT:
 184                 Alert.alertConsumer.consume(this, plaintext.fragment);
 185                 break;
 186             default:
 187                 SSLConsumer consumer = consumers.get(plaintext.contentType);
 188                 if (consumer != null) {
 189                     consumer.consume(this, plaintext.fragment);
 190                 } else {
 191                     throw fatal(Alert.UNEXPECTED_MESSAGE,
 192                         "Unexpected content: " + plaintext.contentType);
 193                 }




  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.security.ssl;
  27 
  28 import java.io.IOException;
  29 import java.security.AccessControlContext;
  30 import java.security.AccessController;
  31 import java.security.PrivilegedAction;
  32 import java.util.HashMap;
  33 import java.util.HashSet;
  34 import java.util.List;
  35 import java.util.Map;
  36 import java.util.Set;
  37 import javax.net.ssl.HandshakeCompletedEvent;
  38 import javax.net.ssl.HandshakeCompletedListener;
  39 import javax.net.ssl.SSLEngineResult.HandshakeStatus;
  40 import javax.net.ssl.SSLException;
  41 import javax.net.ssl.SSLSocket;
  42 import sun.security.ssl.SupportedGroupsExtension.NamedGroup;
  43 
  44 /**
  45  * SSL/(D)TLS transportation context.
  46  */
  47 class TransportContext implements ConnectionContext {
  48     final SSLTransport              transport;
  49 
  50     // registered plaintext consumers
  51     final Map<Byte, SSLConsumer>    consumers;
  52     final AccessControlContext      acc;
  53 
  54     final SSLContextImpl            sslContext;
  55     final SSLConfiguration          sslConfig;
  56     final InputRecord               inputRecord;
  57     final OutputRecord              outputRecord;
  58 
  59     // connection status
  60     boolean                         isUnsureMode;
  61     boolean                         isNegotiated = false;
  62     boolean                         isBroken = false;


 142 
 143     // Dispatch plaintext to a specific consumer.
 144     void dispatch(Plaintext plaintext) throws IOException {
 145         if (plaintext == null) {
 146             return;
 147         }
 148 
 149         ContentType ct = ContentType.valueOf(plaintext.contentType);
 150         if (ct == null) {
 151             throw fatal(Alert.UNEXPECTED_MESSAGE,
 152                 "Unknown content type: " + plaintext.contentType);
 153         }
 154 
 155         switch (ct) {
 156             case HANDSHAKE:
 157                 byte type = HandshakeContext.getHandshakeType(this,
 158                         plaintext);
 159                 if (handshakeContext == null) {
 160                     if (type == SSLHandshake.KEY_UPDATE.id ||
 161                             type == SSLHandshake.NEW_SESSION_TICKET.id) {
 162                         if (isNegotiated &&
 163                                 protocolVersion.useTLS13PlusSpec()) {
 164                             handshakeContext = new PostHandshakeContext(this);
 165                         } else {




 166                             throw fatal(Alert.UNEXPECTED_MESSAGE,
 167                                     "Unexpected post-handshake message: " +
 168                                     SSLHandshake.nameOf(type));
 169                         }

 170                     } else {
 171                         handshakeContext = sslConfig.isClientMode ?
 172                                 new ClientHandshakeContext(sslContext, this) :
 173                                 new ServerHandshakeContext(sslContext, this);
 174                         outputRecord.initHandshaker();
 175                     }
 176                 }
 177                 handshakeContext.dispatch(type, plaintext);
 178                 break;
 179             case ALERT:
 180                 Alert.alertConsumer.consume(this, plaintext.fragment);
 181                 break;
 182             default:
 183                 SSLConsumer consumer = consumers.get(plaintext.contentType);
 184                 if (consumer != null) {
 185                     consumer.consume(this, plaintext.fragment);
 186                 } else {
 187                     throw fatal(Alert.UNEXPECTED_MESSAGE,
 188                         "Unexpected content: " + plaintext.contentType);
 189                 }


< prev index next >