src/main/java/de/unixwork/im/Xmpp.java

changeset 4
856befba7674
parent 2
94c6a715fa44
equal deleted inserted replaced
3:25a32e2dfde5 4:856befba7674
60 60
61 public void startOTR(String xid) { 61 public void startOTR(String xid) {
62 String account = config.getUsername() + "@" + config.getHostString() + "/IM5"; 62 String account = config.getUsername() + "@" + config.getHostString() + "/IM5";
63 SessionID sid = new SessionID(account, xid, "xmpp"); 63 SessionID sid = new SessionID(account, xid, "xmpp");
64 64
65 Session session = new SessionImpl(sid, otr); 65 Session session = otrSM.getSession(sid); //new SessionImpl(sid, otr);
66 String[] outgoingMessage; 66 try {
67 try { 67 System.out.println("otr session start");
68 session.startSession(); 68 session.startSession();
69 } catch (OtrException ex) { 69 } catch (OtrException ex) {
70 Logger.getLogger(Xmpp.class.getName()).log(Level.SEVERE, null, ex); 70 Logger.getLogger(Xmpp.class.getName()).log(Level.SEVERE, null, ex);
71 } 71 }
72 72
128 public void run() { 128 public void run() {
129 try { 129 try {
130 connect(); 130 connect();
131 connection.addAsyncStanzaListener((stanza -> { 131 connection.addAsyncStanzaListener((stanza -> {
132 var jid = stanza.getFrom(); 132 var jid = stanza.getFrom();
133 boolean isSecure = false;
133 if(jid != null) { 134 if(jid != null) {
134 String body = ((Message)stanza).getBody(); 135 String body = ((Message)stanza).getBody();
135 App.getInstance().dispatchMessage(jid, body, true); 136 if(body.startsWith("?OTR")) {
137 String account = config.getUsername() + "@" + config.getHostString() + "/IM5";
138 SessionID sid = new SessionID(account, jid.asBareJid().toString(), "xmpp");
139 Session sn = otrSM.getSession(sid);
140 String cryptoMsg = body;
141 body = null;
142 try {
143 String otrMsg = sn.transformReceiving(cryptoMsg);
144 System.out.println("otr transformed: " + otrMsg);
145 body = otrMsg;
146 isSecure = true;
147 } catch (OtrException ex) {
148 Logger.getLogger(Xmpp.class.getName()).log(Level.SEVERE, null, ex);
149 }
150 }
151
152 if(body != null) {
153 App.getInstance().dispatchMessage(jid, body, isSecure);
154 }
136 } 155 }
137 }), MessageWithBodiesFilter.INSTANCE); 156 }), MessageWithBodiesFilter.INSTANCE);
138 connection.addAsyncStanzaListener(stanza -> { 157 connection.addAsyncStanzaListener(stanza -> {
139 if (stanza instanceof Presence) { 158 if (stanza instanceof Presence) {
140 Presence presence = (Presence) stanza; 159 Presence presence = (Presence) stanza;

mercurial