Merge branch 'main' of tildegit.org:alexlehm/vertx-gemini-server

This commit is contained in:
Alexander Lehmann 2023-08-02 19:58:00 +02:00
commit 4ecca0df72
3 changed files with 139 additions and 59 deletions

View File

@ -58,10 +58,6 @@
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-tcnative-boringssl-static</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>

View File

@ -99,6 +99,23 @@ public class MainVerticle extends AbstractVerticle {
conn.write("30 gemini://gemini.lehmann.cx:11965/\r\n");
conn.close();
}
else if(path.equals("/")) {
conn.write("20 text/gemini\r\n");
conn.write("# a very simple chat server\n");
conn.write("the chat page loads indefintely (until the connection breaks at least)\n");
conn.write("and shows chat messages sent by other users\n");
conn.write("messages can be sent via the /post url and use the client certificate to authenticate\n");
conn.write("currently the sha256 hash of the client cert is used as user-id\n");
conn.write("\n");
conn.write("the source code for the server is at\n");
conn.write("=> https://tildegit.org/alexlehm/vertx-gemini-server\n");
conn.write("the author of this chat is reachable via\n");
conn.write("=> gemini://gemini.lehmann.cx/\n");
conn.write("\n");
conn.write("click on the link to get started\n");
conn.write("=> /chat\n");
conn.close();
}
else if(path.startsWith("/post")) {
System.out.println("post");
try {
@ -136,12 +153,23 @@ public class MainVerticle extends AbstractVerticle {
conn.close();
} else {
System.out.println("conn2");
for (NetSocket socket:clients) {
socket.write("one client connected. count is "+(clients.size()+1)+"\n");
}
clients.add(conn);
conn.write("20 text/gemini\r\n");
conn.write("to post messages, go to\n");
conn.write("=> post post page\n");
conn.write("preferably in a new window\n");
conn.write("currently "+clients.size()+" reading clients are connected\n");
conn.write("chat start\n");
conn.closeHandler(v -> {
System.out.println("a client closed");
clients.remove(conn);
for (NetSocket socket:clients) {
socket.write("one client disconnected. count is "+clients.size()+"\n");
}
});
}
}
}

View File

@ -0,0 +1,56 @@
/**
*
*/
package cx.lehmann.gemini.gemini;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
/**
* @author <a href="https://oss.lehmann.cx/">Alexander Lehmann</a>
*
*/
public class MyTrustManager implements X509TrustManager {
// private final Logger LOGGER=LoggerFactory.getLogger(this.getClass());
final X509TrustManager tm;
/**
* @param tm
*/
public MyTrustManager(TrustManager tm) {
this.tm=(X509TrustManager)tm;
}
@Override
public void checkClientTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {
// LOGGER.info("checkClientTrusted");
System.out.println("checkClientTrusted");
}
@Override
public void checkServerTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {
// LOGGER.info("checkServerTrusted");
System.out.println("checkServerTrusted");
}
// X509Certificate certs[]= {};
@Override
public X509Certificate[] getAcceptedIssuers() {
// LOGGER.info("getAcceptedIssuers");
System.out.println("getAcceptedIssuers");
// Exception ex=new Exception();
// ex.printStackTrace();
return tm.getAcceptedIssuers();
}
}