< prev index next >

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

Print this page
rev 52900 : 8232581: Improve TLS verification
Reviewed-by: xuelei, rhalade, mschoene


  73         }
  74     }
  75 
  76     /**
  77      * The "ClientKeyExchange" handshake message consumer.
  78      */
  79     private static final
  80             class ClientKeyExchangeConsumer implements SSLConsumer {
  81         // Prevent instantiation of this class.
  82         private ClientKeyExchangeConsumer() {
  83             // blank
  84         }
  85 
  86         @Override
  87         public void consume(ConnectionContext context,
  88                 ByteBuffer message) throws IOException {
  89             // The consuming happens in server side only.
  90             ServerHandshakeContext shc = (ServerHandshakeContext)context;
  91             // clean up this consumer
  92             shc.handshakeConsumers.remove(SSLHandshake.CLIENT_KEY_EXCHANGE.id);










  93             SSLKeyExchange ke = SSLKeyExchange.valueOf(
  94                     shc.negotiatedCipherSuite.keyExchange,
  95                     shc.negotiatedProtocol);
  96             if (ke != null) {
  97                 for (Map.Entry<Byte, SSLConsumer> hc :
  98                         ke.getHandshakeConsumers(shc)) {
  99                     if (hc.getKey() == SSLHandshake.CLIENT_KEY_EXCHANGE.id) {
 100                         hc.getValue().consume(context, message);
 101                         return;
 102                     }
 103                 }
 104             }
 105 
 106             // not consumer defined.
 107             throw shc.conContext.fatal(Alert.UNEXPECTED_MESSAGE,
 108                         "Unexpected ClientKeyExchange handshake message.");
 109         }
 110     }
 111 }
 112 


  73         }
  74     }
  75 
  76     /**
  77      * The "ClientKeyExchange" handshake message consumer.
  78      */
  79     private static final
  80             class ClientKeyExchangeConsumer implements SSLConsumer {
  81         // Prevent instantiation of this class.
  82         private ClientKeyExchangeConsumer() {
  83             // blank
  84         }
  85 
  86         @Override
  87         public void consume(ConnectionContext context,
  88                 ByteBuffer message) throws IOException {
  89             // The consuming happens in server side only.
  90             ServerHandshakeContext shc = (ServerHandshakeContext)context;
  91             // clean up this consumer
  92             shc.handshakeConsumers.remove(SSLHandshake.CLIENT_KEY_EXCHANGE.id);
  93 
  94             // Check for an unprocessed client Certificate message.  If that
  95             // handshake consumer is still present then that expected message
  96             // was not sent.
  97             if (shc.handshakeConsumers.containsKey(
  98                     SSLHandshake.CERTIFICATE.id)) {
  99                 throw shc.conContext.fatal(Alert.UNEXPECTED_MESSAGE,
 100                         "Unexpected ClientKeyExchange handshake message.");
 101             }
 102 
 103             SSLKeyExchange ke = SSLKeyExchange.valueOf(
 104                     shc.negotiatedCipherSuite.keyExchange,
 105                     shc.negotiatedProtocol);
 106             if (ke != null) {
 107                 for (Map.Entry<Byte, SSLConsumer> hc :
 108                         ke.getHandshakeConsumers(shc)) {
 109                     if (hc.getKey() == SSLHandshake.CLIENT_KEY_EXCHANGE.id) {
 110                         hc.getValue().consume(context, message);
 111                         return;
 112                     }
 113                 }
 114             }
 115 
 116             // not consumer defined.
 117             throw shc.conContext.fatal(Alert.UNEXPECTED_MESSAGE,
 118                         "Unexpected ClientKeyExchange handshake message.");
 119         }
 120     }
 121 }
 122 
< prev index next >