Skip to content

Commit

Permalink
cleanup + 4 forks
Browse files Browse the repository at this point in the history
  • Loading branch information
Hellblazer committed May 19, 2024
1 parent 6ee2041 commit 2584519
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ jobs:
cache: 'maven'
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Build with Maven
run: ./mvnw -batch-mode clean install -Ppre --file pom.xml
run: ./mvnw -batch-mode clean install -Dforks=4 -Ppre --file pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import java.net.InetAddress;
import java.security.Provider;
import java.security.SecureRandom;
import java.security.cert.X509Certificate;
Expand Down Expand Up @@ -73,7 +72,6 @@ public class MtlsTest {
public static void beforeClass() throws Exception {
var entropy = SecureRandom.getInstance("SHA1PRNG");
entropy.setSeed(new byte[] { 6, 6, 6 });
String localhost = InetAddress.getLoopbackAddress().getHostName();
var stereotomy = new StereotomyImpl(new MemKeyStore(), new MemKERL(DigestAlgorithm.DEFAULT), entropy);
identities = IntStream.range(0, CARDINALITY).mapToObj(i -> {
return stereotomy.newIdentifier();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ static String allocatePort() {
return HostAndPort.fromParts(addr.getHostName(), addr.getPort()).toString();
}

static <T extends SocketAddress> T reify(String encoded) {
var hnp = HostAndPort.fromString(encoded);
return (T) new InetSocketAddress(hnp.getHost(), hnp.getPort());
}

SocketAddress addressFor(Member to);

String getAlias();
Expand All @@ -32,6 +37,6 @@ static String allocatePort() {

ClientAuth getClientAuth();

CertificateValidator getValiator();
CertificateValidator getValidator();

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import io.netty.handler.ssl.ApplicationProtocolConfig.Protocol;
import io.netty.handler.ssl.ApplicationProtocolConfig.SelectedListenerFailureBehavior;
import io.netty.handler.ssl.ApplicationProtocolConfig.SelectorFailureBehavior;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.net.ssl.SSLException;
import javax.net.ssl.SSLPeerUnverifiedException;
Expand All @@ -51,15 +53,17 @@
* @author hal.hildebrand
*/
public class MtlsServer implements RouterSupplier {
static final String TL_SV1_3 = "TLSv1.3";
private static final Provider PROVIDER_JSSE = Security.getProvider("SunJSSE");
private final LoadingCache<X509Certificate, Digest> cachedMembership;
private final Function<Member, ClientContextSupplier> contextSupplier;
private final EndpointProvider epProvider;
private final Member from;
private final Context.Key<SSLSession> sslSessionContext = Context.key("SSLSession");
private final ServerContextSupplier supplier;
private final Executor executor;
static final String TL_SV1_3 = "TLSv1.3";
private static final Provider PROVIDER_JSSE = Security.getProvider("SunJSSE");
private static final Logger log = LoggerFactory.getLogger(MtlsServer.class);

private final LoadingCache<X509Certificate, Digest> cachedMembership;
private final Function<Member, ClientContextSupplier> contextSupplier;
private final EndpointProvider epProvider;
private final Member from;
private final Context.Key<SSLSession> sslSessionContext = Context.key("SSLSession");
private final ServerContextSupplier supplier;
private final Executor executor;

public MtlsServer(Member from, EndpointProvider epProvider, Function<Member, ClientContextSupplier> contextSupplier,
ServerContextSupplier supplier) {
Expand Down Expand Up @@ -148,7 +152,7 @@ public RouterImpl router(ServerConnectionCache.Builder cacheBuilder, Supplier<Li
.withOption(ChannelOption.SO_REUSEADDR, true)
.sslContext(supplier.forServer(ClientAuth.REQUIRE,
epProvider.getAlias(),
epProvider.getValiator(),
epProvider.getValidator(),
PROVIDER_JSSE))
.fallbackHandlerRegistry(new MutableHandlerRegistry())
.withChildOption(ChannelOption.TCP_NODELAY, true)
Expand All @@ -174,8 +178,10 @@ public Digest getFrom() {
}

private ManagedChannel connectTo(Member to) {
return new MtlsClient(epProvider.addressFor(to), epProvider.getClientAuth(), epProvider.getAlias(),
contextSupplier.apply(from), epProvider.getValiator(), executor).getChannel();
var address = epProvider.addressFor(to);
log.debug("Connecting to: {} address: {} on: {}", to.getId(), address, from.getId());
return new MtlsClient(address, epProvider.getClientAuth(), epProvider.getAlias(), contextSupplier.apply(from),
epProvider.getValidator(), executor).getChannel();
}

private X509Certificate getCert() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@
*/
package com.salesforce.apollo.archipelago;

import com.google.common.net.HostAndPort;
import com.salesforce.apollo.cryptography.ssl.CertificateValidator;
import com.salesforce.apollo.membership.Member;
import io.netty.handler.ssl.ClientAuth;

import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.util.function.Function;

Expand All @@ -27,15 +25,15 @@ public class StandardEpProvider implements EndpointProvider {

public StandardEpProvider(String bindAddress, ClientAuth clientAuth, CertificateValidator validator,
Function<Member, String> resolver) {
this.bindAddress = reify(bindAddress);
this.bindAddress = EndpointProvider.reify(bindAddress);
this.clientAuth = clientAuth;
this.validator = validator;
this.resolver = resolver;
}

@Override
public SocketAddress addressFor(Member to) {
return reify(resolver.apply(to));
return EndpointProvider.reify(resolver.apply(to));
}

@Override
Expand All @@ -54,12 +52,7 @@ public ClientAuth getClientAuth() {
}

@Override
public CertificateValidator getValiator() {
public CertificateValidator getValidator() {
return validator;
}

private SocketAddress reify(String encoded) {
var hnp = HostAndPort.fromString(encoded);
return new InetSocketAddress(hnp.getHost(), hnp.getPort());
}
}

0 comments on commit 2584519

Please sign in to comment.