Merge pull request #2018 from SamWhited/sasl_anonymous

SASL ANONYMOUS (no UI)
This commit is contained in:
Daniel Gultsch 2016-09-14 09:34:20 +02:00 committed by GitHub
commit 7b52e6984c
2 changed files with 32 additions and 1 deletions

View File

@ -0,0 +1,28 @@
package eu.siacs.conversations.crypto.sasl;
import java.security.SecureRandom;
import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.xml.TagWriter;
public class Anonymous extends SaslMechanism {
public Anonymous(TagWriter tagWriter, Account account, SecureRandom rng) {
super(tagWriter, account, rng);
}
@Override
public int getPriority() {
return 0;
}
@Override
public String getMechanism() {
return "ANONYMOUS";
}
@Override
public String getClientFirstMessage() {
return "";
}
}

View File

@ -55,6 +55,7 @@ import javax.net.ssl.X509TrustManager;
import de.duenndns.ssl.MemorizingTrustManager; import de.duenndns.ssl.MemorizingTrustManager;
import eu.siacs.conversations.Config; import eu.siacs.conversations.Config;
import eu.siacs.conversations.crypto.XmppDomainVerifier; import eu.siacs.conversations.crypto.XmppDomainVerifier;
import eu.siacs.conversations.crypto.sasl.Anonymous;
import eu.siacs.conversations.crypto.sasl.DigestMd5; import eu.siacs.conversations.crypto.sasl.DigestMd5;
import eu.siacs.conversations.crypto.sasl.External; import eu.siacs.conversations.crypto.sasl.External;
import eu.siacs.conversations.crypto.sasl.Plain; import eu.siacs.conversations.crypto.sasl.Plain;
@ -841,6 +842,8 @@ public class XmppConnection implements Runnable {
saslMechanism = new Plain(tagWriter, account); saslMechanism = new Plain(tagWriter, account);
} else if (mechanisms.contains("DIGEST-MD5")) { } else if (mechanisms.contains("DIGEST-MD5")) {
saslMechanism = new DigestMd5(tagWriter, account, mXmppConnectionService.getRNG()); saslMechanism = new DigestMd5(tagWriter, account, mXmppConnectionService.getRNG());
} else if (mechanisms.contains("ANONYMOUS")) {
saslMechanism = new Anonymous(tagWriter, account, mXmppConnectionService.getRNG());
} }
if (saslMechanism != null) { if (saslMechanism != null) {
final JSONObject keys = account.getKeys(); final JSONObject keys = account.getKeys();
@ -978,7 +981,7 @@ public class XmppConnection implements Runnable {
final Element jid = bind.findChild("jid"); final Element jid = bind.findChild("jid");
if (jid != null && jid.getContent() != null) { if (jid != null && jid.getContent() != null) {
try { try {
account.setResource(Jid.fromString(jid.getContent()).getResourcepart()); account.setJid(Jid.fromString(jid.getContent()));
if (streamFeatures.hasChild("session") if (streamFeatures.hasChild("session")
&& !streamFeatures.findChild("session").hasChild("optional")) { && !streamFeatures.findChild("session").hasChild("optional")) {
sendStartSession(); sendStartSession();