jdk/src/java.base/share/classes/sun/security/ssl/HandshakeMessage.java
changeset 32649 2ee9017c7597
parent 32032 22badc53802f
child 34380 2b2609379881
equal deleted inserted replaced
32648:1fa861caf840 32649:2ee9017c7597
   295     private final boolean       isDTLS;
   295     private final boolean       isDTLS;
   296     byte[]                      compression_methods;
   296     byte[]                      compression_methods;
   297 
   297 
   298     HelloExtensions extensions = new HelloExtensions();
   298     HelloExtensions extensions = new HelloExtensions();
   299 
   299 
   300     private final static byte[]  NULL_COMPRESSION = new byte[] {0};
   300     private static final byte[]  NULL_COMPRESSION = new byte[] {0};
   301 
   301 
   302     ClientHello(SecureRandom generator, ProtocolVersion protocolVersion,
   302     ClientHello(SecureRandom generator, ProtocolVersion protocolVersion,
   303             SessionId sessionId, CipherSuiteList cipherSuites,
   303             SessionId sessionId, CipherSuiteList cipherSuites,
   304             boolean isDTLS) {
   304             boolean isDTLS) {
   305 
   305 
   922  * If a server certificate is sent, there is no anonymity.  However,
   922  * If a server certificate is sent, there is no anonymity.  However,
   923  * when a certificate is sent, ephemeral keys may still be used to
   923  * when a certificate is sent, ephemeral keys may still be used to
   924  * exchange the premaster secret.  That's how RSA_EXPORT often works,
   924  * exchange the premaster secret.  That's how RSA_EXPORT often works,
   925  * as well as how the DHE_* flavors work.
   925  * as well as how the DHE_* flavors work.
   926  */
   926  */
   927 static abstract class ServerKeyExchange extends HandshakeMessage
   927 abstract static class ServerKeyExchange extends HandshakeMessage
   928 {
   928 {
   929     @Override
   929     @Override
   930     int messageType() { return ht_server_key_exchange; }
   930     int messageType() { return ht_server_key_exchange; }
   931 }
   931 }
   932 
   932 
  1075  */
  1075  */
  1076 static final
  1076 static final
  1077 class DH_ServerKeyExchange extends ServerKeyExchange
  1077 class DH_ServerKeyExchange extends ServerKeyExchange
  1078 {
  1078 {
  1079     // Fix message encoding, see 4348279
  1079     // Fix message encoding, see 4348279
  1080     private final static boolean dhKeyExchangeFix =
  1080     private static final boolean dhKeyExchangeFix =
  1081         Debug.getBooleanProperty("com.sun.net.ssl.dhKeyExchangeFix", true);
  1081         Debug.getBooleanProperty("com.sun.net.ssl.dhKeyExchangeFix", true);
  1082 
  1082 
  1083     private byte[]                dh_p;        // 1 to 2^16 - 1 bytes
  1083     private byte[]                dh_p;        // 1 to 2^16 - 1 bytes
  1084     private byte[]                dh_g;        // 1 to 2^16 - 1 bytes
  1084     private byte[]                dh_g;        // 1 to 2^16 - 1 bytes
  1085     private byte[]                dh_Ys;       // 1 to 2^16 - 1 bytes
  1085     private byte[]                dh_Ys;       // 1 to 2^16 - 1 bytes
  1360  */
  1360  */
  1361 static final
  1361 static final
  1362 class ECDH_ServerKeyExchange extends ServerKeyExchange {
  1362 class ECDH_ServerKeyExchange extends ServerKeyExchange {
  1363 
  1363 
  1364     // constants for ECCurveType
  1364     // constants for ECCurveType
  1365     private final static int CURVE_EXPLICIT_PRIME = 1;
  1365     private static final int CURVE_EXPLICIT_PRIME = 1;
  1366     private final static int CURVE_EXPLICIT_CHAR2 = 2;
  1366     private static final int CURVE_EXPLICIT_CHAR2 = 2;
  1367     private final static int CURVE_NAMED_CURVE    = 3;
  1367     private static final int CURVE_NAMED_CURVE    = 3;
  1368 
  1368 
  1369     // id of the curve we are using
  1369     // id of the curve we are using
  1370     private int curveId;
  1370     private int curveId;
  1371     // encoded public point
  1371     // encoded public point
  1372     private byte[] pointBytes;
  1372     private byte[] pointBytes;
  1658     // From RFC 4492 (ECC)
  1658     // From RFC 4492 (ECC)
  1659     static final int    cct_ecdsa_sign       = 64;
  1659     static final int    cct_ecdsa_sign       = 64;
  1660     static final int    cct_rsa_fixed_ecdh   = 65;
  1660     static final int    cct_rsa_fixed_ecdh   = 65;
  1661     static final int    cct_ecdsa_fixed_ecdh = 66;
  1661     static final int    cct_ecdsa_fixed_ecdh = 66;
  1662 
  1662 
  1663     private final static byte[] TYPES_NO_ECC = { cct_rsa_sign, cct_dss_sign };
  1663     private static final byte[] TYPES_NO_ECC = { cct_rsa_sign, cct_dss_sign };
  1664     private final static byte[] TYPES_ECC =
  1664     private static final byte[] TYPES_ECC =
  1665         { cct_rsa_sign, cct_dss_sign, cct_ecdsa_sign };
  1665         { cct_rsa_sign, cct_dss_sign, cct_ecdsa_sign };
  1666 
  1666 
  1667     byte[]                types;               // 1 to 255 types
  1667     byte[]                types;               // 1 to 255 types
  1668     DistinguishedName[]   authorities;         // 3 to 2^16 - 1
  1668     DistinguishedName[]   authorities;         // 3 to 2^16 - 1
  1669         // ... "3" because that's the smallest DER-encoded X500 DN
  1669         // ... "3" because that's the smallest DER-encoded X500 DN
  2117         }
  2117         }
  2118         md.update(pad2);
  2118         md.update(pad2);
  2119         md.update(temp);
  2119         md.update(temp);
  2120     }
  2120     }
  2121 
  2121 
  2122     private final static Class<?> delegate;
  2122     private static final Class<?> delegate;
  2123     private final static Field spiField;
  2123     private static final Field spiField;
  2124 
  2124 
  2125     static {
  2125     static {
  2126         try {
  2126         try {
  2127             delegate = Class.forName("java.security.MessageDigest$Delegate");
  2127             delegate = Class.forName("java.security.MessageDigest$Delegate");
  2128             spiField = delegate.getDeclaredField("digestSpi");
  2128             spiField = delegate.getDeclaredField("digestSpi");
  2141             }
  2141             }
  2142         });
  2142         });
  2143     }
  2143     }
  2144 
  2144 
  2145     // ConcurrentHashMap does not allow null values, use this marker object
  2145     // ConcurrentHashMap does not allow null values, use this marker object
  2146     private final static Object NULL_OBJECT = new Object();
  2146     private static final Object NULL_OBJECT = new Object();
  2147 
  2147 
  2148     // cache Method objects per Spi class
  2148     // cache Method objects per Spi class
  2149     // Note that this will prevent the Spi classes from being GC'd. We assume
  2149     // Note that this will prevent the Spi classes from being GC'd. We assume
  2150     // that is not a problem.
  2150     // that is not a problem.
  2151     private final static Map<Class<?>,Object> methodCache =
  2151     private static final Map<Class<?>,Object> methodCache =
  2152                                         new ConcurrentHashMap<>();
  2152                                         new ConcurrentHashMap<>();
  2153 
  2153 
  2154     private static void digestKey(MessageDigest md, SecretKey key) {
  2154     private static void digestKey(MessageDigest md, SecretKey key) {
  2155         try {
  2155         try {
  2156             // Verify that md is implemented via MessageDigestSpi, not
  2156             // Verify that md is implemented via MessageDigestSpi, not
  2239  * connection (e.g. a previous handshake arranged one).
  2239  * connection (e.g. a previous handshake arranged one).
  2240  */
  2240  */
  2241 static final class Finished extends HandshakeMessage {
  2241 static final class Finished extends HandshakeMessage {
  2242 
  2242 
  2243     // constant for a Finished message sent by the client
  2243     // constant for a Finished message sent by the client
  2244     final static int CLIENT = 1;
  2244     static final int CLIENT = 1;
  2245 
  2245 
  2246     // constant for a Finished message sent by the server
  2246     // constant for a Finished message sent by the server
  2247     final static int SERVER = 2;
  2247     static final int SERVER = 2;
  2248 
  2248 
  2249     // enum Sender:  "CLNT" and "SRVR"
  2249     // enum Sender:  "CLNT" and "SRVR"
  2250     private static final byte[] SSL_CLIENT = { 0x43, 0x4C, 0x4E, 0x54 };
  2250     private static final byte[] SSL_CLIENT = { 0x43, 0x4C, 0x4E, 0x54 };
  2251     private static final byte[] SSL_SERVER = { 0x53, 0x52, 0x56, 0x52 };
  2251     private static final byte[] SSL_SERVER = { 0x53, 0x52, 0x56, 0x52 };
  2252 
  2252