Skip to content

Commit

Permalink
Merge pull request #23 from tsegismont/fix-vertx-setup
Browse files Browse the repository at this point in the history
Fixes following-up Vert.x upgrade
  • Loading branch information
zyclonite authored Jan 21, 2024
2 parents f6b51e3 + 585ed2e commit 2894d59
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
6 changes: 5 additions & 1 deletion src/docker/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
"webservice":{
"host":"0.0.0.0",
"port":8022,
"ssl":false
"ssl": false,
"cors-relative-origins": [
"chrome-extension://[a-p]{32}",
"(https|http)://.*"
]
},
"application":{
"authentication":false,
Expand Down
12 changes: 7 additions & 5 deletions src/main/java/net/zyclonite/nassh/MainVerticle.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import io.vertx.core.Promise;
import io.vertx.core.http.HttpServer;
import io.vertx.core.http.HttpServerOptions;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;
import io.vertx.core.net.SelfSignedCertificate;
import io.vertx.ext.web.Router;
Expand Down Expand Up @@ -42,11 +43,12 @@ public void start(final Promise<Void> startPromise) {
}
server = vertx.createHttpServer(options);
final Router router = Router.router(vertx);
router.route().handler(CorsHandler
.create()
.addRelativeOrigin(".*")
.allowCredentials(true)
);
CorsHandler corsHandler = CorsHandler.create().allowCredentials(true);
JsonArray relOrigins = webserviceConfig.getJsonArray("cors-relative-origins");
for (int i = 0; i < relOrigins.size(); i++) {
corsHandler.addRelativeOrigin(relOrigins.getString(i));
}
router.route().handler(corsHandler);
router.get("/cookie").handler(new CookieHandler(config().getJsonObject("application").copy().put("auth", config().getJsonObject("google-sso"))));
router.post("/cookie").handler(new CookiePostHandler(vertx, new JsonObject().put("auth", config().getJsonObject("google-sso"))));
router.get("/proxy").handler(new ProxyHandler(vertx, config()));
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/net/zyclonite/nassh/handler/ProxyHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import io.vertx.core.Vertx;
import io.vertx.core.http.HttpServerRequest;
import io.vertx.core.http.HttpServerResponse;
import io.vertx.core.impl.VertxImpl;
import io.vertx.core.impl.VertxInternal;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;
import io.vertx.core.net.NetClient;
Expand All @@ -39,14 +39,16 @@ public class ProxyHandler implements Handler<RoutingContext> {
private final LocalMap<String, Session> sessions;
private final int sessionlimit;
private final boolean authentication;
private final Vertx vertx;
private final VertxInternal vertx;
private final NetClient client;
private final JsonObject config;
private final JsonArray accessList;
private final JsonArray whiteList;
private final JsonArray blackList;

public ProxyHandler(final Vertx vertx, final JsonObject config) {
this.vertx = vertx;
this.vertx = (VertxInternal) vertx;
this.client = vertx.createNetClient(new NetClientOptions().setRegisterWriteHandler(true).setReconnectAttempts(10).setReconnectInterval(500));
this.config = config;
this.authentication = config.getJsonObject("application").getBoolean("authentication", true);
this.sessions = vertx.sharedData().getLocalMap(Constants.SESSIONS);
Expand Down Expand Up @@ -84,7 +86,7 @@ public void handle(final RoutingContext context) {
logger.warn(() -> "ssh session limit of " + sessionlimit + " reached");
return;
}
((VertxImpl) vertx).resolveAddress(host, result -> {
vertx.resolveAddress(host, result -> {
if (result.succeeded()) {
final InetAddress address = result.result();
vertx.executeBlocking(() -> AccessHelper.isHostAllowed(accessList, whiteList, blackList, address, authSession), false)
Expand Down Expand Up @@ -123,7 +125,6 @@ public void handle(final RoutingContext context) {

private Promise<UUID> connectTcpEndpoint(final UUID sid, final String host, final int port, final String clienthost) {
final Promise<UUID> promise = Promise.promise();
final NetClient client = vertx.createNetClient(new NetClientOptions().setReconnectAttempts(10).setReconnectInterval(500));
client.connect(port, host, asyncResult -> {
if (asyncResult.succeeded()) {
logger.info(() -> "Connected to ssh server: " + host + ":" + port + " (" + clienthost + ")");
Expand Down

0 comments on commit 2894d59

Please sign in to comment.