Fix a few lint errors (#361)

Replace deprecated bouncycastle class in SslInitializerTestUils.

Generic array as vargs: worked around it in ProbingAction and
removed unused method in CircularList.
This commit is contained in:
Weimin Yu 2019-11-12 11:14:51 -05:00 committed by GitHub
parent 6b19f015bf
commit 349caec80b
3 changed files with 61 additions and 46 deletions

View file

@ -155,15 +155,18 @@ public abstract class ProbingAction implements Callable<ChannelFuture> {
// Write appropriate outboundMessage to pipeline // Write appropriate outboundMessage to pipeline
ChannelFuture unusedFutureWriteAndFlush = ChannelFuture unusedFutureWriteAndFlush =
channel().writeAndFlush(outboundMessage()); channel().writeAndFlush(outboundMessage());
channelFuture.addListeners( channelFuture
.addListener(
future -> { future -> {
if (future.isSuccess()) { if (future.isSuccess()) {
ChannelFuture unusedFuture = finished.setSuccess(); ChannelFuture unusedFuture = finished.setSuccess();
} else { } else {
ChannelFuture unusedFuture = finished.setFailure(future.cause()); ChannelFuture unusedFuture = finished.setFailure(future.cause());
} }
}, })
// If we don't have a persistent connection, close the connection to this .addListener(
// If we don't have a persistent connection, close the connection to
// this
// channel // channel
future -> { future -> {
if (!protocol().persistentConnection()) { if (!protocol().persistentConnection()) {
@ -173,7 +176,8 @@ public abstract class ProbingAction implements Callable<ChannelFuture> {
f -> { f -> {
if (f.isSuccess()) { if (f.isSuccess()) {
logger.atInfo().log( logger.atInfo().log(
"Closed stale channel. Moving on to next ProbingStep"); "Closed stale channel. Moving on to next"
+ " ProbingStep");
} else { } else {
logger.atWarning().log( logger.atWarning().log(
"Issue closing stale channel. Most likely already " "Issue closing stale channel. Most likely already "

View file

@ -29,9 +29,18 @@ import java.time.Duration;
import java.time.Instant; import java.time.Instant;
import java.util.Date; import java.util.Date;
import javax.net.ssl.SSLSession; import javax.net.ssl.SSLSession;
import javax.security.auth.x500.X500Principal; import org.bouncycastle.asn1.x500.X500Name;
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo;
import org.bouncycastle.cert.X509CertificateHolder;
import org.bouncycastle.cert.X509v3CertificateBuilder;
import org.bouncycastle.cert.jcajce.JcaX509CertificateConverter;
import org.bouncycastle.crypto.util.PrivateKeyFactory;
import org.bouncycastle.jce.provider.BouncyCastleProvider; import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.bouncycastle.x509.X509V3CertificateGenerator; import org.bouncycastle.operator.ContentSigner;
import org.bouncycastle.operator.DefaultDigestAlgorithmIdentifierFinder;
import org.bouncycastle.operator.DefaultSignatureAlgorithmIdentifierFinder;
import org.bouncycastle.operator.bc.BcRSAContentSignerBuilder;
/** Utility class that provides methods used by {@link SslClientInitializerTest} */ /** Utility class that provides methods used by {@link SslClientInitializerTest} */
public class SslInitializerTestUtils { public class SslInitializerTestUtils {
@ -53,16 +62,26 @@ public class SslInitializerTestUtils {
*/ */
public static X509Certificate signKeyPair( public static X509Certificate signKeyPair(
SelfSignedCertificate ssc, KeyPair keyPair, String hostname) throws Exception { SelfSignedCertificate ssc, KeyPair keyPair, String hostname) throws Exception {
X509V3CertificateGenerator certGen = new X509V3CertificateGenerator(); X500Name subjectDnName = new X500Name("CN=" + hostname);
X500Principal dnName = new X500Principal("CN=" + hostname); BigInteger serialNumber = (BigInteger.valueOf(System.currentTimeMillis()));
certGen.setSerialNumber(BigInteger.valueOf(System.currentTimeMillis())); X500Name issuerDnName = new X500Name(ssc.cert().getIssuerDN().getName());
certGen.setSubjectDN(dnName); Date from = Date.from(Instant.now().minus(Duration.ofDays(1)));
certGen.setIssuerDN(ssc.cert().getSubjectX500Principal()); Date to = Date.from(Instant.now().plus(Duration.ofDays(1)));
certGen.setNotBefore(Date.from(Instant.now().minus(Duration.ofDays(1)))); SubjectPublicKeyInfo subPubKeyInfo =
certGen.setNotAfter(Date.from(Instant.now().plus(Duration.ofDays(1)))); SubjectPublicKeyInfo.getInstance(keyPair.getPublic().getEncoded());
certGen.setPublicKey(keyPair.getPublic()); AlgorithmIdentifier sigAlgId =
certGen.setSignatureAlgorithm("SHA256WithRSAEncryption"); new DefaultSignatureAlgorithmIdentifierFinder().find("SHA256WithRSAEncryption");
return certGen.generate(ssc.key(), "BC"); AlgorithmIdentifier digAlgId = new DefaultDigestAlgorithmIdentifierFinder().find(sigAlgId);
ContentSigner sigGen =
new BcRSAContentSignerBuilder(sigAlgId, digAlgId)
.build(PrivateKeyFactory.createKey(ssc.key().getEncoded()));
X509v3CertificateBuilder v3CertGen =
new X509v3CertificateBuilder(
issuerDnName, serialNumber, from, to, subjectDnName, subPubKeyInfo);
X509CertificateHolder certificateHolder = v3CertGen.build(sigGen);
return new JcaX509CertificateConverter().setProvider("BC").getCertificate(certificateHolder);
} }
/** /**

View file

@ -92,14 +92,6 @@ public class CircularList<T> {
return this; return this;
} }
/** Simply calls {@code addElement}, for each element in {@code elements}. */
public AbstractBuilder<T, C> add(T... values) {
for (T element : values) {
add(element);
}
return this;
}
/** Simply calls {@code addElement}, for each element in {@code elements}. */ /** Simply calls {@code addElement}, for each element in {@code elements}. */
public AbstractBuilder<T, C> add(Iterable<T> values) { public AbstractBuilder<T, C> add(Iterable<T> values) {
values.forEach(this::add); values.forEach(this::add);