提交 ccdd069a 编写于 作者: X xuelei

8004019: Removes unused method HandshakeHash.setCertificateVerifyAlg()

Summary: certification verification in HandshakeHash was abandoned during TLS 1.2 implementation
Reviewed-by: xuelei, weijun
Contributed-by: NFlorian Weimer <fweimer@redhat.com>
上级 92bd7522
...@@ -557,10 +557,6 @@ final class ClientHandshaker extends Handshaker { ...@@ -557,10 +557,6 @@ final class ClientHandshaker extends Handshaker {
} }
if (resumingSession && session != null) { if (resumingSession && session != null) {
if (protocolVersion.v >= ProtocolVersion.TLS12.v) {
handshakeHash.setCertificateVerifyAlg(null);
}
setHandshakeSessionSE(session); setHandshakeSessionSE(session);
return; return;
} }
...@@ -975,8 +971,6 @@ final class ClientHandshaker extends Handshaker { ...@@ -975,8 +971,6 @@ final class ClientHandshaker extends Handshaker {
throw new SSLHandshakeException( throw new SSLHandshakeException(
"No supported hash algorithm"); "No supported hash algorithm");
} }
handshakeHash.setCertificateVerifyAlg(hashAlg);
} }
m3 = new CertificateVerify(protocolVersion, handshakeHash, m3 = new CertificateVerify(protocolVersion, handshakeHash,
...@@ -994,10 +988,6 @@ final class ClientHandshaker extends Handshaker { ...@@ -994,10 +988,6 @@ final class ClientHandshaker extends Handshaker {
} }
m3.write(output); m3.write(output);
output.doHashes(); output.doHashes();
} else {
if (protocolVersion.v >= ProtocolVersion.TLS12.v) {
handshakeHash.setCertificateVerifyAlg(null);
}
} }
/* /*
......
...@@ -29,7 +29,6 @@ package sun.security.ssl; ...@@ -29,7 +29,6 @@ package sun.security.ssl;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.security.*; import java.security.*;
import java.util.Locale; import java.util.Locale;
import java.util.Set;
/** /**
* Abstraction for the SSL/TLS hash of all handshake messages that is * Abstraction for the SSL/TLS hash of all handshake messages that is
...@@ -49,28 +48,23 @@ import java.util.Set; ...@@ -49,28 +48,23 @@ import java.util.Set;
* 1. protocolDetermined(version) should be called when the negotiated * 1. protocolDetermined(version) should be called when the negotiated
* protocol version is determined. * protocol version is determined.
* *
* 2. Before protocolDetermined() is called, only update(), reset(), * 2. Before protocolDetermined() is called, only update(), and reset()
* restrictCertificateVerifyAlgs(), setFinishedAlg(), and * and setFinishedAlg() can be called.
* setCertificateVerifyAlg() can be called.
* *
* 3. After protocolDetermined() is called, reset() cannot be called. * 3. After protocolDetermined() is called, reset() cannot be called.
* *
* 4. After protocolDetermined() is called, if the version is pre-TLS 1.2, * 4. After protocolDetermined() is called, if the version is pre-TLS 1.2,
* getFinishedHash() and getCertificateVerifyHash() cannot be called. Otherwise, * getFinishedHash() cannot be called. Otherwise,
* getMD5Clone() and getSHAClone() cannot be called. * getMD5Clone() and getSHAClone() cannot be called.
* *
* 5. getMD5Clone() and getSHAClone() can only be called after * 5. getMD5Clone() and getSHAClone() can only be called after
* protocolDetermined() is called and version is pre-TLS 1.2. * protocolDetermined() is called and version is pre-TLS 1.2.
* *
* 6. getFinishedHash() and getCertificateVerifyHash() can only be called after * 6. getFinishedHash() can only be called after protocolDetermined()
* all protocolDetermined(), setCertificateVerifyAlg() and setFinishedAlg() * and setFinishedAlg() have been called and the version is TLS 1.2.
* have been called and the version is TLS 1.2. If a CertificateVerify message
* is to be used, call setCertificateVerifyAlg() with the hash algorithm as the
* argument. Otherwise, you still must call setCertificateVerifyAlg(null) before
* calculating any hash value.
* *
* Suggestions: Call protocolDetermined(), restrictCertificateVerifyAlgs(), * Suggestion: Call protocolDetermined() and setFinishedAlg()
* setFinishedAlg(), and setCertificateVerifyAlg() as early as possible. * as early as possible.
* *
* Example: * Example:
* <pre> * <pre>
...@@ -80,21 +74,13 @@ import java.util.Set; ...@@ -80,21 +74,13 @@ import java.util.Set;
* hh.setFinishedAlg("SHA-256"); * hh.setFinishedAlg("SHA-256");
* hh.update(serverHelloBytes); * hh.update(serverHelloBytes);
* ... * ...
* hh.setCertificateVerifyAlg("SHA-384");
* hh.update(CertificateVerifyBytes); * hh.update(CertificateVerifyBytes);
* byte[] cvDigest = hh.getCertificateVerifyHash();
* ... * ...
* hh.update(finished1); * hh.update(finished1);
* byte[] finDigest1 = hh.getFinishedHash(); * byte[] finDigest1 = hh.getFinishedHash();
* hh.update(finished2); * hh.update(finished2);
* byte[] finDigest2 = hh.getFinishedHash(); * byte[] finDigest2 = hh.getFinishedHash();
* </pre> * </pre>
* If no CertificateVerify message is to be used, call
* <pre>
* hh.setCertificateVerifyAlg(null);
* </pre>
* This call can be made once you are certain that this message
* will never be used.
*/ */
final class HandshakeHash { final class HandshakeHash {
...@@ -105,28 +91,19 @@ final class HandshakeHash { ...@@ -105,28 +91,19 @@ final class HandshakeHash {
// 2: TLS 1.2 // 2: TLS 1.2
private int version = -1; private int version = -1;
private ByteArrayOutputStream data = new ByteArrayOutputStream(); private ByteArrayOutputStream data = new ByteArrayOutputStream();
private final boolean isServer;
// For TLS 1.1 // For TLS 1.1
private MessageDigest md5, sha; private MessageDigest md5, sha;
private final int clonesNeeded; // needs to be saved for later use private final int clonesNeeded; // needs to be saved for later use
// For TLS 1.2 // For TLS 1.2
// cvAlgDetermined == true means setCertificateVerifyAlg() is called
private boolean cvAlgDetermined = false;
private String cvAlg;
private MessageDigest finMD; private MessageDigest finMD;
/** /**
* Create a new HandshakeHash. needCertificateVerify indicates whether * Create a new HandshakeHash. needCertificateVerify indicates whether
* a hash for the certificate verify message is required. The argument * a hash for the certificate verify message is required.
* algs is a set of all possible hash algorithms that might be used in
* TLS 1.2. If the caller is sure that TLS 1.2 won't be used or no
* CertificateVerify message will be used, leave it null or empty.
*/ */
HandshakeHash(boolean isServer, boolean needCertificateVerify, HandshakeHash(boolean needCertificateVerify) {
Set<String> algs) {
this.isServer = isServer;
clonesNeeded = needCertificateVerify ? 3 : 2; clonesNeeded = needCertificateVerify ? 3 : 2;
} }
...@@ -256,46 +233,10 @@ final class HandshakeHash { ...@@ -256,46 +233,10 @@ final class HandshakeHash {
finMD.update(data.toByteArray()); finMD.update(data.toByteArray());
} }
/**
* Restricts the possible algorithms for the CertificateVerify. Called by
* the server based on info in CertRequest. The argument must be a subset
* of the argument with the same name in the constructor. The method can be
* called multiple times. If the caller is sure that no CertificateVerify
* message will be used, leave this argument null or empty.
*/
void restrictCertificateVerifyAlgs(Set<String> algs) {
if (version == 1) {
throw new RuntimeException(
"setCertificateVerifyAlg() cannot be called for TLS 1.1");
}
// Not used yet
}
/**
* Specifies the hash algorithm used in CertificateVerify.
* Can be called multiple times.
*/
void setCertificateVerifyAlg(String s) {
// Can be called multiple times, but only set once
if (cvAlgDetermined) return;
cvAlg = s == null ? null : normalizeAlgName(s);
cvAlgDetermined = true;
}
byte[] getAllHandshakeMessages() { byte[] getAllHandshakeMessages() {
return data.toByteArray(); return data.toByteArray();
} }
/**
* Calculates the hash in the CertificateVerify. Must be called right
* after setCertificateVerifyAlg()
*/
/*byte[] getCertificateVerifyHash() {
throw new Error("Do not call getCertificateVerifyHash()");
}*/
/** /**
* Calculates the hash in Finished. Must be called after setFinishedAlg(). * Calculates the hash in Finished. Must be called after setFinishedAlg().
* This method can be called twice, for Finished messages of the server * This method can be called twice, for Finished messages of the server
......
...@@ -489,11 +489,7 @@ abstract class Handshaker { ...@@ -489,11 +489,7 @@ abstract class Handshaker {
// We accumulate digests of the handshake messages so that // We accumulate digests of the handshake messages so that
// we can read/write CertificateVerify and Finished messages, // we can read/write CertificateVerify and Finished messages,
// getting assurance against some particular active attacks. // getting assurance against some particular active attacks.
Set<String> localSupportedHashAlgorithms = handshakeHash = new HandshakeHash(needCertVerify);
SignatureAndHashAlgorithm.getHashAlgorithmNames(
getLocalSupportedSignAlgs());
handshakeHash = new HandshakeHash(!isClient, needCertVerify,
localSupportedHashAlgorithms);
// Generate handshake input/output stream. // Generate handshake input/output stream.
input = new HandshakeInStream(handshakeHash); input = new HandshakeInStream(handshakeHash);
......
...@@ -58,9 +58,6 @@ final class MAC { ...@@ -58,9 +58,6 @@ final class MAC {
// Value of the null MAC is fixed // Value of the null MAC is fixed
private static final byte nullMAC[] = new byte[0]; private static final byte nullMAC[] = new byte[0];
// internal identifier for the MAC algorithm
private final MacAlg macAlg;
// stuff defined by the kind of MAC algorithm // stuff defined by the kind of MAC algorithm
private final int macSize; private final int macSize;
...@@ -85,7 +82,6 @@ final class MAC { ...@@ -85,7 +82,6 @@ final class MAC {
private MAC() { private MAC() {
macSize = 0; macSize = 0;
macAlg = M_NULL;
mac = null; mac = null;
block = null; block = null;
} }
...@@ -95,7 +91,6 @@ final class MAC { ...@@ -95,7 +91,6 @@ final class MAC {
*/ */
MAC(MacAlg macAlg, ProtocolVersion protocolVersion, SecretKey key) MAC(MacAlg macAlg, ProtocolVersion protocolVersion, SecretKey key)
throws NoSuchAlgorithmException, InvalidKeyException { throws NoSuchAlgorithmException, InvalidKeyException {
this.macAlg = macAlg;
this.macSize = macAlg.size; this.macSize = macAlg.size;
String algorithm; String algorithm;
......
...@@ -670,9 +670,6 @@ final class ServerHandshaker extends Handshaker { ...@@ -670,9 +670,6 @@ final class ServerHandshaker extends Handshaker {
} }
if (protocolVersion.v >= ProtocolVersion.TLS12.v) { if (protocolVersion.v >= ProtocolVersion.TLS12.v) {
if (resumingSession) {
handshakeHash.setCertificateVerifyAlg(null);
}
handshakeHash.setFinishedAlg(cipherSuite.prfAlg.getPRFHashAlg()); handshakeHash.setFinishedAlg(cipherSuite.prfAlg.getPRFHashAlg());
} }
...@@ -882,7 +879,6 @@ final class ServerHandshaker extends Handshaker { ...@@ -882,7 +879,6 @@ final class ServerHandshaker extends Handshaker {
throw new SSLHandshakeException( throw new SSLHandshakeException(
"No supported signature algorithm"); "No supported signature algorithm");
} }
handshakeHash.restrictCertificateVerifyAlgs(localHashAlgs);
} }
caCerts = sslContext.getX509TrustManager().getAcceptedIssuers(); caCerts = sslContext.getX509TrustManager().getAcceptedIssuers();
...@@ -893,10 +889,6 @@ final class ServerHandshaker extends Handshaker { ...@@ -893,10 +889,6 @@ final class ServerHandshaker extends Handshaker {
m4.print(System.out); m4.print(System.out);
} }
m4.write(output); m4.write(output);
} else {
if (protocolVersion.v >= ProtocolVersion.TLS12.v) {
handshakeHash.setCertificateVerifyAlg(null);
}
} }
/* /*
...@@ -1456,8 +1448,6 @@ final class ServerHandshaker extends Handshaker { ...@@ -1456,8 +1448,6 @@ final class ServerHandshaker extends Handshaker {
throw new SSLHandshakeException( throw new SSLHandshakeException(
"No supported hash algorithm"); "No supported hash algorithm");
} }
handshakeHash.setCertificateVerifyAlg(hashAlg);
} }
try { try {
...@@ -1672,11 +1662,6 @@ final class ServerHandshaker extends Handshaker { ...@@ -1672,11 +1662,6 @@ final class ServerHandshaker extends Handshaker {
* not *REQUIRED*, this is an acceptable condition.) * not *REQUIRED*, this is an acceptable condition.)
*/ */
if (doClientAuth == SSLEngineImpl.clauth_requested) { if (doClientAuth == SSLEngineImpl.clauth_requested) {
// Smart (aka stupid) to forecast that no CertificateVerify
// message will be received.
if (protocolVersion.v >= ProtocolVersion.TLS12.v) {
handshakeHash.setCertificateVerifyAlg(null);
}
return; return;
} else { } else {
fatalSE(Alerts.alert_bad_certificate, fatalSE(Alerts.alert_bad_certificate,
......
...@@ -77,9 +77,6 @@ final class SignatureAndHashAlgorithm { ...@@ -77,9 +77,6 @@ final class SignatureAndHashAlgorithm {
// the hash algorithm // the hash algorithm
private HashAlgorithm hash; private HashAlgorithm hash;
// the signature algorithm
private SignatureAlgorithm signature;
// id in 16 bit MSB format, i.e. 0x0603 for SHA512withECDSA // id in 16 bit MSB format, i.e. 0x0603 for SHA512withECDSA
private int id; private int id;
...@@ -96,7 +93,6 @@ final class SignatureAndHashAlgorithm { ...@@ -96,7 +93,6 @@ final class SignatureAndHashAlgorithm {
private SignatureAndHashAlgorithm(HashAlgorithm hash, private SignatureAndHashAlgorithm(HashAlgorithm hash,
SignatureAlgorithm signature, String algorithm, int priority) { SignatureAlgorithm signature, String algorithm, int priority) {
this.hash = hash; this.hash = hash;
this.signature = signature;
this.algorithm = algorithm; this.algorithm = algorithm;
this.id = ((hash.value & 0xFF) << 8) | (signature.value & 0xFF); this.id = ((hash.value & 0xFF) << 8) | (signature.value & 0xFF);
this.priority = priority; this.priority = priority;
...@@ -105,11 +101,10 @@ final class SignatureAndHashAlgorithm { ...@@ -105,11 +101,10 @@ final class SignatureAndHashAlgorithm {
// constructor for unsupported algorithm // constructor for unsupported algorithm
private SignatureAndHashAlgorithm(String algorithm, int id, int sequence) { private SignatureAndHashAlgorithm(String algorithm, int id, int sequence) {
this.hash = HashAlgorithm.valueOf((id >> 8) & 0xFF); this.hash = HashAlgorithm.valueOf((id >> 8) & 0xFF);
this.signature = SignatureAlgorithm.valueOf(id & 0xFF);
this.algorithm = algorithm; this.algorithm = algorithm;
this.id = id; this.id = id;
// add one more to the sequece number, in case that the number is zero // add one more to the sequence number, in case that the number is zero
this.priority = SUPPORTED_ALG_PRIORITY_MAX_NUM + sequence + 1; this.priority = SUPPORTED_ALG_PRIORITY_MAX_NUM + sequence + 1;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册