Skip to content

Commit

Permalink
TKSS-812: Cleanup TLCP codes
Browse files Browse the repository at this point in the history
  • Loading branch information
johnshajiang committed Jul 4, 2024
1 parent 6f223c4 commit 9ae05cc
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public Map.Entry<Byte, HandshakeProducer>[] getHandshakeProducers(
});
} // Otherwise, SSL/TLS does not use this method.

return new Map.Entry[0];
return (Map.Entry<Byte, HandshakeProducer>[])(new Map.Entry[0]);
}

static final class TLCPPossession implements SSLPossession {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import java.nio.ByteBuffer;
import java.security.PublicKey;
import java.security.cert.CertPathValidatorException;
import java.security.cert.CertPathValidatorException.BasicReason;
import java.security.cert.CertificateEncodingException;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
Expand Down Expand Up @@ -823,16 +824,16 @@ private static Alert getCertificateAlert(
Alert.BAD_CERT_STATUS_RESPONSE :
Alert.CERTIFICATE_REVOKED;
} else if (
reason == CertPathValidatorException.BasicReason.UNDETERMINED_REVOCATION_STATUS) {
reason == BasicReason.UNDETERMINED_REVOCATION_STATUS) {
alert = chc.staplingActive ?
Alert.BAD_CERT_STATUS_RESPONSE :
Alert.CERTIFICATE_UNKNOWN;
} else if (reason == CertPathValidatorException.BasicReason.ALGORITHM_CONSTRAINED) {
} else if (reason == BasicReason.ALGORITHM_CONSTRAINED) {
alert = Alert.UNSUPPORTED_CERTIFICATE;
} else if (reason == CertPathValidatorException.BasicReason.EXPIRED) {
} else if (reason == BasicReason.EXPIRED) {
alert = Alert.CERTIFICATE_EXPIRED;
} else if (reason == CertPathValidatorException.BasicReason.INVALID_SIGNATURE ||
reason == CertPathValidatorException.BasicReason.NOT_YET_VALID) {
} else if (reason == BasicReason.INVALID_SIGNATURE ||
reason == BasicReason.NOT_YET_VALID) {
alert = Alert.BAD_CERTIFICATE;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,32 +83,36 @@ public Map.Entry<Byte, HandshakeProducer>[] getHandshakeProducers(
if (handshakeContext.sslConfig.isClientMode) {
switch (this) {
case SM2:
return new Map.Entry[] {
new SimpleImmutableEntry<>(
SSLHandshake.CLIENT_KEY_EXCHANGE.id,
SM2ClientKeyExchange.sm2HandshakeProducer)};
return (Map.Entry<Byte,
HandshakeProducer>[]) new Map.Entry[] {
new SimpleImmutableEntry<>(
SSLHandshake.CLIENT_KEY_EXCHANGE.id,
SM2ClientKeyExchange.sm2HandshakeProducer)};
case SM2E:
return new Map.Entry[] {
new SimpleImmutableEntry<>(
SSLHandshake.CLIENT_KEY_EXCHANGE.id,
SM2EClientKeyExchange.sm2eHandshakeProducer)};
return (Map.Entry<Byte,
HandshakeProducer>[]) new Map.Entry[] {
new SimpleImmutableEntry<>(
SSLHandshake.CLIENT_KEY_EXCHANGE.id,
SM2EClientKeyExchange.sm2eHandshakeProducer)};
}
} else {
switch (this) {
case SM2:
return new Map.Entry[] {
new SimpleImmutableEntry<>(
SSLHandshake.SERVER_KEY_EXCHANGE.id,
SM2ServerKeyExchange.sm2HandshakeProducer)};
return (Map.Entry<Byte,
HandshakeProducer>[]) new Map.Entry[] {
new SimpleImmutableEntry<>(
SSLHandshake.SERVER_KEY_EXCHANGE.id,
SM2ServerKeyExchange.sm2HandshakeProducer)};
case SM2E:
return new Map.Entry[] {
new SimpleImmutableEntry<>(
SSLHandshake.SERVER_KEY_EXCHANGE.id,
SM2EServerKeyExchange.sm2eHandshakeProducer)};
return (Map.Entry<Byte,
HandshakeProducer>[]) new Map.Entry[] {
new SimpleImmutableEntry<>(
SSLHandshake.SERVER_KEY_EXCHANGE.id,
SM2EServerKeyExchange.sm2eHandshakeProducer)};
}
}

return new Map.Entry[0];
return (Map.Entry<Byte, HandshakeProducer>[]) (new Map.Entry[0]);
}

@Override
Expand All @@ -122,31 +126,35 @@ public Map.Entry<Byte, SSLConsumer>[] getHandshakeConsumers(
if (handshakeContext.sslConfig.isClientMode) {
switch (this) {
case SM2:
return new Map.Entry[] {
new SimpleImmutableEntry<>(
SSLHandshake.SERVER_KEY_EXCHANGE.id,
SM2ServerKeyExchange.sm2HandshakeConsumer)};
return (Map.Entry<Byte,
SSLConsumer>[]) new Map.Entry[] {
new SimpleImmutableEntry<>(
SSLHandshake.SERVER_KEY_EXCHANGE.id,
SM2ServerKeyExchange.sm2HandshakeConsumer)};
case SM2E:
return new Map.Entry[] {
new SimpleImmutableEntry<>(
SSLHandshake.SERVER_KEY_EXCHANGE.id,
SM2EServerKeyExchange.sm2eHandshakeConsumer)};
return (Map.Entry<Byte,
SSLConsumer>[]) new Map.Entry[] {
new SimpleImmutableEntry<>(
SSLHandshake.SERVER_KEY_EXCHANGE.id,
SM2EServerKeyExchange.sm2eHandshakeConsumer)};
}
} else {
switch (this) {
case SM2:
return new Map.Entry[] {
new SimpleImmutableEntry<>(
SSLHandshake.CLIENT_KEY_EXCHANGE.id,
SM2ClientKeyExchange.sm2HandshakeConsumer)};
return (Map.Entry<Byte,
SSLConsumer>[]) new Map.Entry[] {
new SimpleImmutableEntry<>(
SSLHandshake.CLIENT_KEY_EXCHANGE.id,
SM2ClientKeyExchange.sm2HandshakeConsumer)};
case SM2E:
return new Map.Entry[] {
new SimpleImmutableEntry<>(
SSLHandshake.CLIENT_KEY_EXCHANGE.id,
SM2EClientKeyExchange.sm2eHandshakeConsumer)};
return (Map.Entry<Byte,
SSLConsumer>[]) new Map.Entry[] {
new SimpleImmutableEntry<>(
SSLHandshake.CLIENT_KEY_EXCHANGE.id,
SM2EClientKeyExchange.sm2eHandshakeConsumer)};
}
}

return new Map.Entry[0];
return (Map.Entry<Byte, SSLConsumer>[])(new Map.Entry[0]);
}
}

0 comments on commit 9ae05cc

Please sign in to comment.