--- a/src/main/java/de/unixwork/im/Xmpp.java Thu Dec 26 17:19:15 2024 +0100 +++ b/src/main/java/de/unixwork/im/Xmpp.java Mon Dec 30 11:44:48 2024 +0100 @@ -62,9 +62,9 @@ String account = config.getUsername() + "@" + config.getHostString() + "/IM5"; SessionID sid = new SessionID(account, xid, "xmpp"); - Session session = new SessionImpl(sid, otr); - String[] outgoingMessage; + Session session = otrSM.getSession(sid); //new SessionImpl(sid, otr); try { + System.out.println("otr session start"); session.startSession(); } catch (OtrException ex) { Logger.getLogger(Xmpp.class.getName()).log(Level.SEVERE, null, ex); @@ -130,9 +130,28 @@ connect(); connection.addAsyncStanzaListener((stanza -> { var jid = stanza.getFrom(); + boolean isSecure = false; if(jid != null) { String body = ((Message)stanza).getBody(); - App.getInstance().dispatchMessage(jid, body, true); + if(body.startsWith("?OTR")) { + String account = config.getUsername() + "@" + config.getHostString() + "/IM5"; + SessionID sid = new SessionID(account, jid.asBareJid().toString(), "xmpp"); + Session sn = otrSM.getSession(sid); + String cryptoMsg = body; + body = null; + try { + String otrMsg = sn.transformReceiving(cryptoMsg); + System.out.println("otr transformed: " + otrMsg); + body = otrMsg; + isSecure = true; + } catch (OtrException ex) { + Logger.getLogger(Xmpp.class.getName()).log(Level.SEVERE, null, ex); + } + } + + if(body != null) { + App.getInstance().dispatchMessage(jid, body, isSecure); + } } }), MessageWithBodiesFilter.INSTANCE); connection.addAsyncStanzaListener(stanza -> {