Merge branch 'main' of tildegit.org:alexlehm/vertx-gemini-server
This commit is contained in:
commit
4ecca0df72
4
pom.xml
4
pom.xml
|
@ -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>
|
||||
|
|
|
@ -41,7 +41,7 @@ public class MainVerticle extends AbstractVerticle {
|
|||
|
||||
List<NetSocket> clients=new ArrayList<>();
|
||||
|
||||
// X509TrustManager tm=new MyTrustManager();
|
||||
// X509TrustManager tm=new MyTrustManager();
|
||||
|
||||
@Override
|
||||
public void start(Promise<Void> startPromise) throws Exception {
|
||||
|
@ -52,7 +52,7 @@ public class MainVerticle extends AbstractVerticle {
|
|||
// String certPath="c:/temp/cert.pem";
|
||||
String certPath="/home/lehmann/gemini-chat/cert.pem";
|
||||
|
||||
// TrustOptions trustOptions=new MyTrustOptions(vertx);
|
||||
// TrustOptions trustOptions=new MyTrustOptions(vertx);
|
||||
|
||||
TrustManagerFactory trustMgrFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
|
||||
KeyStore keystore=KeyStore.getInstance("JKS");
|
||||
|
@ -67,20 +67,20 @@ public class MainVerticle extends AbstractVerticle {
|
|||
.setCertPath(certPath)
|
||||
.setKeyPath(certPath))
|
||||
.setSsl(true)
|
||||
// .setTrustOptions(trustOptions)
|
||||
// .setTrustOptions(trustOptions)
|
||||
.setTrustOptions(TrustOptions.wrap(trustManager))
|
||||
|
||||
// .setOpenSslEngineOptions(new OpenSSLEngineOptions())
|
||||
// .setOpenSslEngineOptions(new OpenSSLEngineOptions())
|
||||
.setClientAuth(ClientAuth.REQUEST)
|
||||
;
|
||||
|
||||
// SSLContext sc = SSLContext.getInstance("SSL");
|
||||
// sc.init(null, new X509TrustManager[] { tm }, null);
|
||||
// HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
|
||||
// SSLContext sc = SSLContext.getInstance("SSL");
|
||||
// sc.init(null, new X509TrustManager[] { tm }, null);
|
||||
// HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
|
||||
|
||||
vertx.createNetServer(options).connectHandler(conn -> {
|
||||
conn.handler(event -> {
|
||||
System.out.println(new Date().toString()+"accepted connection:"+conn.remoteAddress());
|
||||
System.out.println(new Date().toString()+" accepted connection:"+conn.remoteAddress());
|
||||
String url=event.toString("UTF-8");
|
||||
if(!url.endsWith("\r\n")) {
|
||||
conn.write("40 format error\r\n");
|
||||
|
@ -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 {
|
||||
|
@ -130,18 +147,29 @@ public class MainVerticle extends AbstractVerticle {
|
|||
}
|
||||
}
|
||||
} catch (SSLPeerUnverifiedException | CertificateEncodingException | NoSuchAlgorithmException ex) {
|
||||
// ex.printStackTrace();
|
||||
// ex.printStackTrace();
|
||||
conn.write("60 cert required\r\n");
|
||||
}
|
||||
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");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
56
src/main/java/cx/lehmann/gemini/gemini/MyTrustManager.java
Normal file
56
src/main/java/cx/lehmann/gemini/gemini/MyTrustManager.java
Normal 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();
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user