Skip to content

Commit

Permalink
8259385: Cleanup unused assignment
Browse files Browse the repository at this point in the history
Reviewed-by: attila
  • Loading branch information
XueleiFan committed Jan 11, 2021
1 parent 9154f64 commit b72de3c
Show file tree
Hide file tree
Showing 18 changed files with 70 additions and 79 deletions.
Expand Up @@ -1103,7 +1103,7 @@ private CTCertStatusResponseProducer() {
public byte[] produce(ConnectionContext context,
HandshakeMessage message) throws IOException {
ServerHandshakeContext shc = (ServerHandshakeContext)context;
byte[] producedData = null;
byte[] producedData;

// Stapling needs to be active and have valid data to proceed
if (shc.stapleParams == null) {
Expand Down
44 changes: 21 additions & 23 deletions src/java.base/share/classes/sun/security/ssl/CertificateStatus.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -85,8 +85,8 @@ final class CertificateStatus {
static final class CertificateStatusMessage extends HandshakeMessage {

final CertStatusRequestType statusType;
int encodedResponsesLen = 0;
int messageLength = -1;
final int encodedResponsesLen;
final int messageLength;
final List<byte[]> encodedResponses = new ArrayList<>();

CertificateStatusMessage(HandshakeContext handshakeContext) {
Expand Down Expand Up @@ -114,6 +114,7 @@ static final class CertificateStatusMessage extends HandshakeMessage {
// Walk the certificate list and add the correct encoded responses
// to the encoded responses list
statusType = stapleParams.statReqType;
int encodedLen = 0;
if (statusType == CertStatusRequestType.OCSP) {
// Just worry about the first cert in the chain
byte[] resp = stapleParams.responseMap.get(certChain[0]);
Expand All @@ -124,22 +125,23 @@ static final class CertificateStatusMessage extends HandshakeMessage {
resp = new byte[0];
}
encodedResponses.add(resp);
encodedResponsesLen += resp.length + 3;
encodedLen += resp.length + 3;
} else if (statusType == CertStatusRequestType.OCSP_MULTI) {
for (X509Certificate cert : certChain) {
byte[] resp = stapleParams.responseMap.get(cert);
if (resp == null) {
resp = new byte[0];
}
encodedResponses.add(resp);
encodedResponsesLen += resp.length + 3;
encodedLen += resp.length + 3;
}
} else {
throw new IllegalArgumentException(
"Unsupported StatusResponseType: " + statusType);
}

messageLength = messageLength();
encodedResponsesLen = encodedLen;
messageLength = messageLength(statusType, encodedResponsesLen);
}

CertificateStatusMessage(HandshakeContext handshakeContext,
Expand Down Expand Up @@ -182,7 +184,18 @@ static final class CertificateStatusMessage extends HandshakeMessage {
Alert.HANDSHAKE_FAILURE,
"Unsupported StatusResponseType: " + statusType);
}
messageLength = messageLength();
messageLength = messageLength(statusType, encodedResponsesLen);
}

private static int messageLength(
CertStatusRequestType statusType, int encodedResponsesLen) {
if (statusType == CertStatusRequestType.OCSP) {
return 1 + encodedResponsesLen;
} else if (statusType == CertStatusRequestType.OCSP_MULTI) {
return 4 + encodedResponsesLen;
}

return -1;
}

@Override
Expand All @@ -192,17 +205,6 @@ public SSLHandshake handshakeType() {

@Override
public int messageLength() {
int len = 1;

if (messageLength == -1) {
if (statusType == CertStatusRequestType.OCSP) {
len += encodedResponsesLen;
} else if (statusType == CertStatusRequestType.OCSP_MULTI) {
len += 3 + encodedResponsesLen;
}
messageLength = len;
}

return messageLength;
}

Expand All @@ -214,11 +216,7 @@ public void send(HandshakeOutStream s) throws IOException {
} else if (statusType == CertStatusRequestType.OCSP_MULTI) {
s.putInt24(encodedResponsesLen);
for (byte[] respBytes : encodedResponses) {
if (respBytes != null) {
s.putBytes24(respBytes);
} else {
s.putBytes24(null);
}
s.putBytes24(respBytes);
}
} else {
// It is highly unlikely that we will fall into this section
Expand Down
30 changes: 15 additions & 15 deletions src/java.base/share/classes/sun/security/ssl/CertificateVerify.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -74,15 +74,15 @@ static final class S30CertificateVerifyMessage extends HandshakeMessage {

// This happens in client side only.
ClientHandshakeContext chc = (ClientHandshakeContext)context;
byte[] temproary = null;
byte[] temporary;
String algorithm = x509Possession.popPrivateKey.getAlgorithm();
try {
Signature signer =
getSignature(algorithm, x509Possession.popPrivateKey);
byte[] hashes = chc.handshakeHash.digest(algorithm,
chc.handshakeSession.getMasterSecret());
signer.update(hashes);
temproary = signer.sign();
temporary = signer.sign();
} catch (NoSuchAlgorithmException nsae) {
throw chc.conContext.fatal(Alert.INTERNAL_ERROR,
"Unsupported signature algorithm (" + algorithm +
Expand All @@ -92,7 +92,7 @@ static final class S30CertificateVerifyMessage extends HandshakeMessage {
"Cannot produce CertificateVerify signature", gse);
}

this.signature = temproary;
this.signature = temporary;
}

S30CertificateVerifyMessage(HandshakeContext context,
Expand Down Expand Up @@ -194,7 +194,7 @@ public String toString() {
*/
private static Signature getSignature(String algorithm,
Key key) throws GeneralSecurityException {
Signature signer = null;
Signature signer;
switch (algorithm) {
case "RSA":
signer = Signature.getInstance(JsseJce.SIGNATURE_RAWRSA);
Expand Down Expand Up @@ -330,14 +330,14 @@ static final class T10CertificateVerifyMessage extends HandshakeMessage {

// This happens in client side only.
ClientHandshakeContext chc = (ClientHandshakeContext)context;
byte[] temproary = null;
byte[] temporary;
String algorithm = x509Possession.popPrivateKey.getAlgorithm();
try {
Signature signer =
getSignature(algorithm, x509Possession.popPrivateKey);
byte[] hashes = chc.handshakeHash.digest(algorithm);
signer.update(hashes);
temproary = signer.sign();
temporary = signer.sign();
} catch (NoSuchAlgorithmException nsae) {
throw chc.conContext.fatal(Alert.INTERNAL_ERROR,
"Unsupported signature algorithm (" + algorithm +
Expand All @@ -347,7 +347,7 @@ static final class T10CertificateVerifyMessage extends HandshakeMessage {
"Cannot produce CertificateVerify signature", gse);
}

this.signature = temproary;
this.signature = temporary;
}

T10CertificateVerifyMessage(HandshakeContext context,
Expand Down Expand Up @@ -448,7 +448,7 @@ public String toString() {
*/
private static Signature getSignature(String algorithm,
Key key) throws GeneralSecurityException {
Signature signer = null;
Signature signer;
switch (algorithm) {
case "RSA":
signer = Signature.getInstance(JsseJce.SIGNATURE_RAWRSA);
Expand Down Expand Up @@ -605,17 +605,17 @@ static final class T12CertificateVerifyMessage extends HandshakeMessage {
}

this.signatureScheme = schemeAndSigner.getKey();
byte[] temproary = null;
byte[] temporary;
try {
Signature signer = schemeAndSigner.getValue();
signer.update(chc.handshakeHash.archived());
temproary = signer.sign();
temporary = signer.sign();
} catch (SignatureException ikse) {
throw chc.conContext.fatal(Alert.HANDSHAKE_FAILURE,
"Cannot produce CertificateVerify signature", ikse);
}

this.signature = temproary;
this.signature = temporary;
}

T12CertificateVerifyMessage(HandshakeContext handshakeContext,
Expand Down Expand Up @@ -930,17 +930,17 @@ static final class T13CertificateVerifyMessage extends HandshakeMessage {
serverSignHead.length, hashValue.length);
}

byte[] temproary = null;
byte[] temporary;
try {
Signature signer = schemeAndSigner.getValue();
signer.update(contentCovered);
temproary = signer.sign();
temporary = signer.sign();
} catch (SignatureException ikse) {
throw context.conContext.fatal(Alert.HANDSHAKE_FAILURE,
"Cannot produce CertificateVerify signature", ikse);
}

this.signature = temproary;
this.signature = temporary;
}

T13CertificateVerifyMessage(HandshakeContext context,
Expand Down
Expand Up @@ -123,7 +123,7 @@ class DHServerKeyExchangeMessage extends HandshakeMessage {
} else {
useExplicitSigAlgorithm =
shc.negotiatedProtocol.useTLS12PlusSpec();
Signature signer = null;
Signature signer;
if (useExplicitSigAlgorithm) {
Map.Entry<SignatureScheme, Signature> schemeAndSigner =
SignatureScheme.getSignerOfPreferableAlgorithm(
Expand Down Expand Up @@ -155,7 +155,7 @@ class DHServerKeyExchangeMessage extends HandshakeMessage {
}
}

byte[] signature = null;
byte[] signature;
try {
updateSignature(signer, shc.clientHelloRandom.randomBytes,
shc.serverHelloRandom.randomBytes);
Expand Down Expand Up @@ -415,7 +415,7 @@ public String toString() {

private static Signature getSignature(String keyAlgorithm,
Key key) throws NoSuchAlgorithmException, InvalidKeyException {
Signature signer = null;
Signature signer;
switch (keyAlgorithm) {
case "DSA":
signer = Signature.getInstance(JsseJce.SIGNATURE_DSA);
Expand Down
Expand Up @@ -1118,7 +1118,7 @@ private Plaintext acquireCachedMessage() throws SSLProtocolException {
bufferedFragments.remove(rFrag); // popup the fragment

ByteBuffer fragment = ByteBuffer.wrap(rFrag.fragment);
ByteBuffer plaintextFragment = null;
ByteBuffer plaintextFragment;
try {
Plaintext plaintext = readCipher.decrypt(
rFrag.contentType, fragment, rFrag.recordEnS);
Expand Down
Expand Up @@ -367,15 +367,13 @@ public byte[] produce(ConnectionContext context,

SSLCredentials sslCredentials = null;
NamedGroup ng = null;
PublicKey publicKey = null;

// Find a good EC/XEC credential to use, determine the
// NamedGroup to use for creating Possessions/Credentials/Keys.
for (SSLCredentials cd : chc.handshakeCredentials) {
if (cd instanceof NamedGroupCredentials) {
NamedGroupCredentials creds = (NamedGroupCredentials)cd;
ng = creds.getNamedGroup();
publicKey = creds.getPublicKey();
sslCredentials = cd;
break;
}
Expand Down
Expand Up @@ -133,7 +133,7 @@ class ECDHServerKeyExchangeMessage extends HandshakeMessage {
} else {
useExplicitSigAlgorithm =
shc.negotiatedProtocol.useTLS12PlusSpec();
Signature signer = null;
Signature signer;
if (useExplicitSigAlgorithm) {
Map.Entry<SignatureScheme, Signature> schemeAndSigner =
SignatureScheme.getSignerOfPreferableAlgorithm(
Expand Down Expand Up @@ -165,7 +165,7 @@ class ECDHServerKeyExchangeMessage extends HandshakeMessage {
}
}

byte[] signature = null;
byte[] signature;
try {
updateSignature(signer, shc.clientHelloRandom.randomBytes,
shc.serverHelloRandom.randomBytes,
Expand Down Expand Up @@ -419,7 +419,7 @@ public String toString() {

private static Signature getSignature(String keyAlgorithm,
Key key) throws NoSuchAlgorithmException, InvalidKeyException {
Signature signer = null;
Signature signer;
switch (keyAlgorithm) {
case "EC":
signer = Signature.getInstance(JsseJce.SIGNATURE_ECDSA);
Expand Down
2 changes: 1 addition & 1 deletion src/java.base/share/classes/sun/security/ssl/Finished.java
Expand Up @@ -79,7 +79,7 @@ private static final class FinishedMessage extends HandshakeMessage {
VerifyDataScheme vds =
VerifyDataScheme.valueOf(context.negotiatedProtocol);

byte[] vd = null;
byte[] vd;
try {
vd = vds.createVerifyData(context, false);
} catch (IOException ioe) {
Expand Down
Expand Up @@ -486,7 +486,7 @@ private long t13Encrypt(
}

// use the right TLSCiphertext.opaque_type and legacy_record_version
ProtocolVersion pv = protocolVersion;
ProtocolVersion pv;
if (!encCipher.isNullCipher()) {
pv = ProtocolVersion.TLS12;
contentType = ContentType.APPLICATION_DATA.id;
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -135,7 +135,7 @@ static RSAPremasterSecret decode(ServerHandshakeContext shc,
byte[] encrypted) throws GeneralSecurityException {

byte[] encoded = null;
boolean needFailover = false;
boolean needFailover;
Cipher cipher = Cipher.getInstance(JsseJce.CIPHER_RSA_PKCS1);
try {
// Try UNWRAP_MODE mode firstly.
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -83,7 +83,7 @@ private RSAServerKeyExchangeMessage(HandshakeContext handshakeContext,
RSAPublicKeySpec spec = JsseJce.getRSAPublicKeySpec(publicKey);
this.modulus = Utilities.toByteArray(spec.getModulus());
this.exponent = Utilities.toByteArray(spec.getPublicExponent());
byte[] signature = null;
byte[] signature;
try {
Signature signer = RSASignature.getInstance();
signer.initSign(x509Possession.popPrivateKey,
Expand Down

1 comment on commit b72de3c

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.