mirror of
https://github.com/google/nomulus.git
synced 2025-04-30 12:07:51 +02:00
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:
parent
6b19f015bf
commit
349caec80b
3 changed files with 61 additions and 46 deletions
|
@ -155,33 +155,37 @@ 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
|
||||||
future -> {
|
.addListener(
|
||||||
if (future.isSuccess()) {
|
future -> {
|
||||||
ChannelFuture unusedFuture = finished.setSuccess();
|
if (future.isSuccess()) {
|
||||||
} else {
|
ChannelFuture unusedFuture = finished.setSuccess();
|
||||||
ChannelFuture unusedFuture = finished.setFailure(future.cause());
|
} else {
|
||||||
}
|
ChannelFuture unusedFuture = finished.setFailure(future.cause());
|
||||||
},
|
}
|
||||||
// If we don't have a persistent connection, close the connection to this
|
})
|
||||||
// channel
|
.addListener(
|
||||||
future -> {
|
// If we don't have a persistent connection, close the connection to
|
||||||
if (!protocol().persistentConnection()) {
|
// this
|
||||||
|
// channel
|
||||||
|
future -> {
|
||||||
|
if (!protocol().persistentConnection()) {
|
||||||
|
|
||||||
ChannelFuture closedFuture = channel().close();
|
ChannelFuture closedFuture = channel().close();
|
||||||
closedFuture.addListener(
|
closedFuture.addListener(
|
||||||
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"
|
||||||
} else {
|
+ " ProbingStep");
|
||||||
logger.atWarning().log(
|
} else {
|
||||||
"Issue closing stale channel. Most likely already "
|
logger.atWarning().log(
|
||||||
+ "closed.");
|
"Issue closing stale channel. Most likely already "
|
||||||
}
|
+ "closed.");
|
||||||
});
|
}
|
||||||
}
|
});
|
||||||
});
|
}
|
||||||
|
});
|
||||||
},
|
},
|
||||||
delay().getStandardSeconds(),
|
delay().getStandardSeconds(),
|
||||||
TimeUnit.SECONDS);
|
TimeUnit.SECONDS);
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -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);
|
||||||
|
|
Loading…
Add table
Reference in a new issue