aboutsummaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authorChristian Schneppe <christian.schneppe@pix-art.de>2020-01-24 20:28:36 +0100
committerChristian Schneppe <christian.schneppe@pix-art.de>2020-01-24 20:29:53 +0100
commita917c5403f89c8c6351bc379fc91e981139dd25e (patch)
treecc28da5c85429eb29b157c3638bd1f220ba67c64 /src/main
parent6ff2ae4e0246aac275b88e1e39242c4994fd3dd9 (diff)
support xmpp uris with single 'omemo' parameter for fingerprint (w/o sid)
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/de/pixart/messenger/ui/UriHandlerActivity.java4
-rw-r--r--src/main/java/de/pixart/messenger/ui/WelcomeActivity.java4
-rw-r--r--src/main/java/de/pixart/messenger/utils/XmppUri.java171
3 files changed, 85 insertions, 94 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/UriHandlerActivity.java b/src/main/java/de/pixart/messenger/ui/UriHandlerActivity.java
index 0ab443a81..9c5d54774 100644
--- a/src/main/java/de/pixart/messenger/ui/UriHandlerActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/UriHandlerActivity.java
@@ -88,7 +88,7 @@ public class UriHandlerActivity extends AppCompatActivity {
final XmppUri xmppUri = new XmppUri(uri);
final List<Jid> accounts = DatabaseBackend.getInstance(this).getAccountJids(true);
if (SignupUtils.isSupportTokenRegistry() && xmppUri.isValidJid()) {
- final String preauth = xmppUri.getParamater("preauth");
+ final String preauth = xmppUri.getParameter("preauth");
final Jid jid = xmppUri.getJid();
if (xmppUri.isAction(XmppUri.ACTION_REGISTER)) {
if (jid.getEscapedLocal() != null && accounts.contains(jid.asBareJid())) {
@@ -99,7 +99,7 @@ public class UriHandlerActivity extends AppCompatActivity {
startActivity(intent);
return;
}
- if (xmppUri.isAction(XmppUri.ACTION_ROSTER) && "y".equals(xmppUri.getParamater("ibr"))) {
+ if (xmppUri.isAction(XmppUri.ACTION_ROSTER) && "y".equals(xmppUri.getParameter("ibr"))) {
intent = SignupUtils.getTokenRegistrationIntent(this, Jid.ofDomain(jid.getDomain()), preauth);
intent.putExtra(StartConversationActivity.EXTRA_INVITE_URI, xmppUri.toString());
startActivity(intent);
diff --git a/src/main/java/de/pixart/messenger/ui/WelcomeActivity.java b/src/main/java/de/pixart/messenger/ui/WelcomeActivity.java
index 0e1b7f604..fa7581a7a 100644
--- a/src/main/java/de/pixart/messenger/ui/WelcomeActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/WelcomeActivity.java
@@ -50,12 +50,12 @@ public class WelcomeActivity extends XmppActivity {
private boolean processXmppUri(final XmppUri xmppUri) {
if (xmppUri.isValidJid()) {
- final String preauth = xmppUri.getParamater("preauth");
+ final String preauth = xmppUri.getParameter("preauth");
final Jid jid = xmppUri.getJid();
final Intent intent;
if (xmppUri.isAction(XmppUri.ACTION_REGISTER)) {
intent = SignupUtils.getTokenRegistrationIntent(this, jid, preauth);
- } else if (xmppUri.isAction(XmppUri.ACTION_ROSTER) && "y".equals(xmppUri.getParamater("ibr"))) {
+ } else if (xmppUri.isAction(XmppUri.ACTION_ROSTER) && "y".equals(xmppUri.getParameter("ibr"))) {
intent = SignupUtils.getTokenRegistrationIntent(this, Jid.ofDomain(jid.getDomain()), preauth);
intent.putExtra(StartConversationActivity.EXTRA_INVITE_URI, xmppUri.toString());
} else {
diff --git a/src/main/java/de/pixart/messenger/utils/XmppUri.java b/src/main/java/de/pixart/messenger/utils/XmppUri.java
index 0e9fe7087..340c242a7 100644
--- a/src/main/java/de/pixart/messenger/utils/XmppUri.java
+++ b/src/main/java/de/pixart/messenger/utils/XmppUri.java
@@ -7,8 +7,6 @@ import androidx.annotation.NonNull;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
-import org.jetbrains.annotations.NotNull;
-
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.ArrayList;
@@ -16,27 +14,22 @@ import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Map;
-import java.util.regex.Pattern;
import rocks.xmpp.addr.Jid;
public class XmppUri {
+ public static final String ACTION_JOIN = "join";
+ public static final String ACTION_MESSAGE = "message";
+ public static final String ACTION_REGISTER = "register";
+ public static final String ACTION_ROSTER = "roster";
+ private static final String OMEMO_URI_PARAM = "omemo-sid-";
+ private static final String OTR_URI_PARAM = "otr-fingerprint";
protected Uri uri;
protected String jid;
- protected String fingerprint;
private List<Fingerprint> fingerprints = new ArrayList<>();
private Map<String, String> parameters = Collections.emptyMap();
private boolean safeSource = true;
- public static final String OMEMO_URI_PARAM = "omemo-sid-";
- private static final String OTR_URI_PARAM = "otr-fingerprint";
- public static final String ACTION_JOIN = "join";
-
- public static final String ACTION_MESSAGE = "message";
- public static final String ACTION_REGISTER = "register";
- public static final String ACTION_ROSTER = "roster";
-
- public static Pattern XMPP_URI = Patterns.XMPP_PATTERN;
public XmppUri(String uri) {
try {
@@ -59,6 +52,79 @@ public class XmppUri {
parse(uri);
}
+ private static Map<String, String> parseParameters(final String query, final char seperator) {
+ final ImmutableMap.Builder<String, String> builder = new ImmutableMap.Builder<>();
+ final String[] pairs = query == null ? new String[0] : query.split(String.valueOf(seperator));
+ for (String pair : pairs) {
+ final String[] parts = pair.split("=", 2);
+ if (parts.length == 0) {
+ continue;
+ }
+ final String key = parts[0].toLowerCase(Locale.US);
+ final String value;
+ if (parts.length == 2) {
+ String decoded;
+ try {
+ decoded = URLDecoder.decode(parts[1], "UTF-8");
+ } catch (UnsupportedEncodingException e) {
+ decoded = "";
+ }
+ value = decoded;
+ } else {
+ value = "";
+ }
+ builder.put(key, value);
+ }
+ return builder.build();
+ }
+
+ private static List<Fingerprint> parseFingerprints(Map<String, String> parameters) {
+ ImmutableList.Builder<Fingerprint> builder = new ImmutableList.Builder<>();
+ for (Map.Entry<String, String> parameter : parameters.entrySet()) {
+ final String key = parameter.getKey();
+ final String value = parameter.getValue().toLowerCase(Locale.US);
+ if (key.startsWith(OMEMO_URI_PARAM)) {
+ try {
+ final int id = Integer.parseInt(key.substring(OMEMO_URI_PARAM.length()));
+ builder.add(new Fingerprint(FingerprintType.OMEMO, value, id));
+ } catch (Exception e) {
+ //ignoring invalid device id
+ }
+ } else if ("omemo".equals(key)) {
+ builder.add(new Fingerprint(FingerprintType.OMEMO, value, 0));
+ }
+ }
+ return builder.build();
+ }
+
+ public static String getFingerprintUri(final String base, final List<XmppUri.Fingerprint> fingerprints, char separator) {
+ StringBuilder builder = new StringBuilder(base);
+ builder.append('?');
+ for (int i = 0; i < fingerprints.size(); ++i) {
+ XmppUri.FingerprintType type = fingerprints.get(i).type;
+ if (type == XmppUri.FingerprintType.OMEMO) {
+ builder.append(XmppUri.OMEMO_URI_PARAM);
+ builder.append(fingerprints.get(i).deviceId);
+ } else if (type == XmppUri.FingerprintType.OTR) {
+ builder.append(XmppUri.OTR_URI_PARAM);
+ }
+ builder.append('=');
+ builder.append(fingerprints.get(i).fingerprint);
+ if (i != fingerprints.size() - 1) {
+ builder.append(separator);
+ }
+ }
+ return builder.toString();
+ }
+
+ private static String lameUrlDecode(String url) {
+ return url.replace("%23", "#").replace("%25", "%");
+ }
+
+ public static String lameUrlEncode(String url) {
+ return url.replace("%", "%25").replace("#", "%23");
+ }
+
public boolean isSafeSource() {
return safeSource;
}
@@ -118,32 +184,6 @@ public class XmppUri {
}
}
- private static Map<String, String> parseParameters(final String query, final char seperator) {
- final ImmutableMap.Builder<String, String> builder = new ImmutableMap.Builder<>();
- final String[] pairs = query == null ? new String[0] : query.split(String.valueOf(seperator));
- for (String pair : pairs) {
- final String[] parts = pair.split("=", 2);
- if (parts.length == 0) {
- continue;
- }
- final String key = parts[0].toLowerCase(Locale.US);
- final String value;
- if (parts.length == 2) {
- String decoded;
- try {
- decoded = URLDecoder.decode(parts[1], "UTF-8");
- } catch (UnsupportedEncodingException e) {
- decoded = "";
- }
- value = decoded;
- } else {
- value = "";
- }
- builder.put(key, value);
- }
- return builder.build();
- }
-
@Override
@NonNull
public String toString() {
@@ -153,23 +193,6 @@ public class XmppUri {
return "";
}
- private static List<Fingerprint> parseFingerprints(Map<String, String> parameters) {
- ImmutableList.Builder<Fingerprint> builder = new ImmutableList.Builder<>();
- for (Map.Entry<String, String> parameter : parameters.entrySet()) {
- final String key = parameter.getKey();
- final String value = parameter.getValue().toLowerCase(Locale.US);
- if (key.startsWith(OMEMO_URI_PARAM)) {
- try {
- final int id = Integer.parseInt(key.substring(OMEMO_URI_PARAM.length()));
- builder.add(new Fingerprint(FingerprintType.OMEMO, value, id));
- } catch (Exception e) {
- //ignoring invalid device id
- }
- }
- }
- return builder.build();
- }
-
public boolean isAction(final String action) {
return parameters.containsKey(action);
}
@@ -202,7 +225,7 @@ public class XmppUri {
return parameters.get("name");
}
- public String getParamater(String key) {
+ public String getParameter(String key) {
return this.parameters.get(key);
}
@@ -219,53 +242,21 @@ public class XmppUri {
OTR
}
- public static String getFingerprintUri(String base, List<XmppUri.Fingerprint> fingerprints, char separator) {
- StringBuilder builder = new StringBuilder(base);
- builder.append('?');
- for (int i = 0; i < fingerprints.size(); ++i) {
- XmppUri.FingerprintType type = fingerprints.get(i).type;
- if (type == XmppUri.FingerprintType.OMEMO) {
- builder.append(XmppUri.OMEMO_URI_PARAM);
- builder.append(fingerprints.get(i).deviceId);
- } else if (type == XmppUri.FingerprintType.OTR) {
- builder.append(XmppUri.OTR_URI_PARAM);
- }
- builder.append('=');
- builder.append(fingerprints.get(i).fingerprint);
- if (i != fingerprints.size() - 1) {
- builder.append(separator);
- }
- }
- return builder.toString();
- }
-
public static class Fingerprint {
public final FingerprintType type;
public final String fingerprint;
final int deviceId;
- public Fingerprint(FingerprintType type, String fingerprint) {
- this(type, fingerprint, 0);
- }
-
public Fingerprint(FingerprintType type, String fingerprint, int deviceId) {
this.type = type;
this.fingerprint = fingerprint;
this.deviceId = deviceId;
}
- @NotNull
+ @NonNull
@Override
public String toString() {
return type.toString() + ": " + fingerprint + (deviceId != 0 ? " " + deviceId : "");
}
}
-
- private static String lameUrlDecode(String url) {
- return url.replace("%23", "#").replace("%25", "%");
- }
-
- public static String lameUrlEncode(String url) {
- return url.replace("%", "%25").replace("#", "%23");
- }
}