Skip to content

Commit

Permalink
feat: disablePidCheck flag
Browse files Browse the repository at this point in the history
  • Loading branch information
jclab-joseph committed Jun 7, 2023
1 parent edc4097 commit cc9c766
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 24 deletions.
9 changes: 6 additions & 3 deletions java/core/src/main/java/kr/jclab/sipc/server/SipcServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ static SipcServer create(
SocketAddress localAddress,
int handshakeTimeoutMilliseconds,
boolean allowReconnect,
WindowsNativeSupport windowsNativeSupport
WindowsNativeSupport windowsNativeSupport,
boolean disablePidCheck
) throws NoSuchAlgorithmException {
EventLoopHolder eventLoopHolder = new EventLoopHolder();

Expand All @@ -72,7 +73,8 @@ static SipcServer create(
localAddress,
handshakeTimeoutMilliseconds,
allowReconnect,
windowsNativeSupport
windowsNativeSupport,
disablePidCheck
);
} else {
if (localAddress == null) {
Expand All @@ -85,7 +87,8 @@ static SipcServer create(
localPrivateKey,
localAddress,
handshakeTimeoutMilliseconds,
allowReconnect
allowReconnect,
disablePidCheck
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,24 +55,10 @@ public CompletableFuture<Boolean> onClientHello(byte[] rawPayload) {

int expectedPid = this.sipcChild.getPid().get();
if (expectedPid != 0) {
if (expectedPid == pid) {
this.verified = true;
completableFuture.complete(true);
} else {
completableFuture.completeExceptionally(new InvalidConnectionInfoException());
}
checkPid(completableFuture, expectedPid);
} else {
this.sipcChild.getPid().compute((updatedPid) -> {
if (updatedPid == pid) {
try {
this.verified = true;
completableFuture.complete(true);
} catch (Exception e) {
completableFuture.completeExceptionally(e);
}
} else {
completableFuture.completeExceptionally(new InvalidConnectionInfoException());
}
checkPid(completableFuture, updatedPid);
});
}
return completableFuture;
Expand All @@ -82,6 +68,19 @@ public CompletableFuture<Boolean> onClientHello(byte[] rawPayload) {
return completableFuture;
}

private void checkPid(CompletableFuture<Boolean> completableFuture, int expectedPid) {
if (this.serverContext.isDisablePidCheck() || expectedPid == pid) {
this.verified = true;
try {
completableFuture.complete(true);
} catch (Exception e) {
completableFuture.completeExceptionally(e);
}
} else {
completableFuture.completeExceptionally(new InvalidConnectionInfoException());
}
}

public void noiseHandshakeComplete(Channel channel) {
checkNotNull(this.connectionId);
checkNotNull(this.sipcChild);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,20 @@ public class SipcServerContext {
@Setter
private boolean allowReconnect = false;

@Getter
private final boolean disablePidCheck;

private ScheduledFuture<?> handshakeTimer = null;

public SipcServerContext(
EventLoopHolder eventLoopHolder,
DHState localPrivateKey,
SipcProto.TransportType transportType,
WindowsNativeSupport windowsNativeSupport
WindowsNativeSupport windowsNativeSupport,
boolean disablePidCheck
) throws NoSuchAlgorithmException {
this.disablePidCheck = disablePidCheck;

this.eventLoopHolder = eventLoopHolder;
if (localPrivateKey == null) {
localPrivateKey = Noise.createDH("25519");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,16 @@ public UnixDomainSocketSipcServer(
DHState localPrivateKey,
SocketAddress localAddress,
int handshakeTimeoutMilliseconds,
boolean allowReconnect
boolean allowReconnect,
boolean disablePidCheck
) throws NoSuchAlgorithmException {
super(
new SipcServerContext(
eventLoopHolder,
localPrivateKey,
SipcProto.TransportType.kUnixDomainSocket,
null
null,
disablePidCheck
)
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,16 @@ public WindowsNamedPipeSipcServer(
SocketAddress localAddress,
int handshakeTimeoutMilliseconds,
boolean allowReconnect,
WindowsNativeSupport windowsNativeSupport
WindowsNativeSupport windowsNativeSupport,
boolean disablePidCheck
) throws NoSuchAlgorithmException {
super(
new SipcServerContext(
eventLoopHolder,
localPrivateKey,
SipcProto.TransportType.kWindowsNamedPipe,
windowsNativeSupport
windowsNativeSupport,
disablePidCheck
)
);

Expand Down

0 comments on commit cc9c766

Please sign in to comment.