| 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 */  | 
 | 
 | 
 | 
package sun.security.ssl;  | 
 | 
 | 
 | 
import java.io.IOException;  | 
 | 
import java.nio.ByteBuffer;  | 
 | 
import java.util.Map;  | 
 | 
import sun.security.ssl.SSLHandshake.HandshakeMessage;  | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 */  | 
 | 
final class ClientKeyExchange { | 
 | 
    static final SSLConsumer handshakeConsumer =  | 
 | 
            new ClientKeyExchangeConsumer();  | 
 | 
    static final HandshakeProducer handshakeProducer =  | 
 | 
            new ClientKeyExchangeProducer();  | 
 | 
 | 
 | 
 | 
 | 
      | 
 | 
 | 
 | 
     */  | 
 | 
    private static final  | 
 | 
            class ClientKeyExchangeProducer implements HandshakeProducer { | 
 | 
          | 
 | 
        private ClientKeyExchangeProducer() { | 
 | 
            // blank  | 
 | 
        }  | 
 | 
 | 
 | 
        @Override  | 
 | 
        public byte[] produce(ConnectionContext context,  | 
 | 
                HandshakeMessage message) throws IOException { | 
 | 
              | 
 | 
            ClientHandshakeContext chc = (ClientHandshakeContext)context;  | 
 | 
            SSLKeyExchange ke = SSLKeyExchange.valueOf(  | 
 | 
                        chc.negotiatedCipherSuite.keyExchange,  | 
 | 
                        chc.negotiatedProtocol);  | 
 | 
            if (ke != null) { | 
 | 
                for (Map.Entry<Byte, HandshakeProducer> hp :  | 
 | 
                        ke.getHandshakeProducers(chc)) { | 
 | 
                    if (hp.getKey() == SSLHandshake.CLIENT_KEY_EXCHANGE.id) { | 
 | 
                        return hp.getValue().produce(context, message);  | 
 | 
                    }  | 
 | 
                }  | 
 | 
            }  | 
 | 
 | 
 | 
              | 
 | 
            throw chc.conContext.fatal(Alert.UNEXPECTED_MESSAGE,  | 
 | 
                        "Unexpected ClientKeyExchange handshake message.");  | 
 | 
        }  | 
 | 
    }  | 
 | 
 | 
 | 
      | 
 | 
 | 
 | 
     */  | 
 | 
    private static final  | 
 | 
            class ClientKeyExchangeConsumer implements SSLConsumer { | 
 | 
          | 
 | 
        private ClientKeyExchangeConsumer() { | 
 | 
            // blank  | 
 | 
        }  | 
 | 
 | 
 | 
        @Override  | 
 | 
        public void consume(ConnectionContext context,  | 
 | 
                ByteBuffer message) throws IOException { | 
 | 
              | 
 | 
            ServerHandshakeContext shc = (ServerHandshakeContext)context;  | 
 | 
              | 
 | 
            shc.handshakeConsumers.remove(SSLHandshake.CLIENT_KEY_EXCHANGE.id);  | 
 | 
 | 
 | 
            // Check for an unprocessed client Certificate message.  If that  | 
 | 
            // handshake consumer is still present then that expected message  | 
 | 
              | 
 | 
            if (shc.handshakeConsumers.containsKey(  | 
 | 
                    SSLHandshake.CERTIFICATE.id)) { | 
 | 
                throw shc.conContext.fatal(Alert.UNEXPECTED_MESSAGE,  | 
 | 
                        "Unexpected ClientKeyExchange handshake message.");  | 
 | 
            }  | 
 | 
 | 
 | 
            SSLKeyExchange ke = SSLKeyExchange.valueOf(  | 
 | 
                    shc.negotiatedCipherSuite.keyExchange,  | 
 | 
                    shc.negotiatedProtocol);  | 
 | 
            if (ke != null) { | 
 | 
                for (Map.Entry<Byte, SSLConsumer> hc :  | 
 | 
                        ke.getHandshakeConsumers(shc)) { | 
 | 
                    if (hc.getKey() == SSLHandshake.CLIENT_KEY_EXCHANGE.id) { | 
 | 
                        hc.getValue().consume(context, message);  | 
 | 
                        return;  | 
 | 
                    }  | 
 | 
                }  | 
 | 
            }  | 
 | 
 | 
 | 
              | 
 | 
            throw shc.conContext.fatal(Alert.UNEXPECTED_MESSAGE,  | 
 | 
                        "Unexpected ClientKeyExchange handshake message.");  | 
 | 
        }  | 
 | 
    }  | 
 | 
}  | 
 | 
 |