add jingle message init namespace to features

This commit is contained in:
Daniel Gultsch 2020-04-21 14:59:03 +02:00
parent 5b12e23382
commit 442b952700
1 changed files with 110 additions and 112 deletions

View File

@ -23,127 +23,125 @@ import eu.siacs.conversations.xmpp.XmppConnection;
import eu.siacs.conversations.xmpp.jingle.stanzas.FileTransferDescription; import eu.siacs.conversations.xmpp.jingle.stanzas.FileTransferDescription;
public abstract class AbstractGenerator { public abstract class AbstractGenerator {
private final String[] FEATURES = { private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.US);
Namespace.JINGLE, private final String[] FEATURES = {
Namespace.JINGLE,
//Jingle File Transfer //Jingle File Transfer
FileTransferDescription.Version.FT_3.getNamespace(), FileTransferDescription.Version.FT_3.getNamespace(),
FileTransferDescription.Version.FT_4.getNamespace(), FileTransferDescription.Version.FT_4.getNamespace(),
FileTransferDescription.Version.FT_5.getNamespace(), FileTransferDescription.Version.FT_5.getNamespace(),
Namespace.JINGLE_TRANSPORTS_S5B, Namespace.JINGLE_TRANSPORTS_S5B,
Namespace.JINGLE_TRANSPORTS_IBB, Namespace.JINGLE_TRANSPORTS_IBB,
Namespace.JINGLE_ENCRYPTED_TRANSPORT, Namespace.JINGLE_ENCRYPTED_TRANSPORT,
Namespace.JINGLE_ENCRYPTED_TRANSPORT_OMEMO, Namespace.JINGLE_ENCRYPTED_TRANSPORT_OMEMO,
"http://jabber.org/protocol/muc", "http://jabber.org/protocol/muc",
"jabber:x:conference", "jabber:x:conference",
Namespace.OOB, Namespace.OOB,
"http://jabber.org/protocol/caps", "http://jabber.org/protocol/caps",
"http://jabber.org/protocol/disco#info", "http://jabber.org/protocol/disco#info",
"urn:xmpp:avatar:metadata+notify", "urn:xmpp:avatar:metadata+notify",
Namespace.NICK+"+notify", Namespace.NICK + "+notify",
"urn:xmpp:ping", "urn:xmpp:ping",
"jabber:iq:version", "jabber:iq:version",
"http://jabber.org/protocol/chatstates" "http://jabber.org/protocol/chatstates"
}; };
private final String[] MESSAGE_CONFIRMATION_FEATURES = { private final String[] MESSAGE_CONFIRMATION_FEATURES = {
"urn:xmpp:chat-markers:0", "urn:xmpp:chat-markers:0",
"urn:xmpp:receipts" "urn:xmpp:receipts"
}; };
private final String[] MESSAGE_CORRECTION_FEATURES = { private final String[] MESSAGE_CORRECTION_FEATURES = {
"urn:xmpp:message-correct:0" "urn:xmpp:message-correct:0"
}; };
private final String[] PRIVACY_SENSITIVE = { private final String[] PRIVACY_SENSITIVE = {
"urn:xmpp:time" //XEP-0202: Entity Time leaks time zone "urn:xmpp:time" //XEP-0202: Entity Time leaks time zone
}; };
private final String[] VOIP_NAMESPACES = {
Namespace.JINGLE_TRANSPORT_ICE_UDP,
Namespace.JINGLE_FEATURE_AUDIO,
Namespace.JINGLE_FEATURE_VIDEO,
Namespace.JINGLE_APPS_RTP,
Namespace.JINGLE_APPS_DTLS,
Namespace.JINGLE_MESSAGE
};
protected XmppConnectionService mXmppConnectionService;
private String mVersion = null;
private final String[] VOIP_NAMESPACES = { AbstractGenerator(XmppConnectionService service) {
Namespace.JINGLE_TRANSPORT_ICE_UDP, this.mXmppConnectionService = service;
Namespace.JINGLE_FEATURE_AUDIO, }
Namespace.JINGLE_FEATURE_VIDEO,
Namespace.JINGLE_APPS_RTP,
Namespace.JINGLE_APPS_DTLS,
};
private String mVersion = null;
private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.US); public static String getTimestamp(long time) {
DATE_FORMAT.setTimeZone(TimeZone.getTimeZone("UTC"));
return DATE_FORMAT.format(time);
}
protected XmppConnectionService mXmppConnectionService; String getIdentityVersion() {
if (mVersion == null) {
this.mVersion = PhoneHelper.getVersionName(mXmppConnectionService);
}
return this.mVersion;
}
AbstractGenerator(XmppConnectionService service) { String getIdentityName() {
this.mXmppConnectionService = service; return mXmppConnectionService.getString(R.string.app_name);
} }
String getIdentityVersion() { public String getUserAgent() {
if (mVersion == null) { return mXmppConnectionService.getString(R.string.app_name) + '/' + getIdentityVersion();
this.mVersion = PhoneHelper.getVersionName(mXmppConnectionService); }
}
return this.mVersion;
}
String getIdentityName() { String getIdentityType() {
return mXmppConnectionService.getString(R.string.app_name); if ("chromium".equals(android.os.Build.BRAND)) {
} return "pc";
} else {
return mXmppConnectionService.getString(R.string.default_resource).toLowerCase();
}
}
public String getUserAgent() { String getCapHash(final Account account) {
return mXmppConnectionService.getString(R.string.app_name) + '/' + getIdentityVersion(); StringBuilder s = new StringBuilder();
} s.append("client/").append(getIdentityType()).append("//").append(getIdentityName()).append('<');
MessageDigest md;
try {
md = MessageDigest.getInstance("SHA-1");
} catch (NoSuchAlgorithmException e) {
return null;
}
String getIdentityType() { for (String feature : getFeatures(account)) {
if ("chromium".equals(android.os.Build.BRAND)) { s.append(feature).append('<');
return "pc"; }
} else { final byte[] sha1 = md.digest(s.toString().getBytes());
return mXmppConnectionService.getString(R.string.default_resource).toLowerCase(); return Base64.encodeToString(sha1, Base64.NO_WRAP);
} }
}
String getCapHash(final Account account) { public List<String> getFeatures(Account account) {
StringBuilder s = new StringBuilder(); final XmppConnection connection = account.getXmppConnection();
s.append("client/").append(getIdentityType()).append("//").append(getIdentityName()).append('<'); final ArrayList<String> features = new ArrayList<>(Arrays.asList(FEATURES));
MessageDigest md; if (mXmppConnectionService.confirmMessages()) {
try { features.addAll(Arrays.asList(MESSAGE_CONFIRMATION_FEATURES));
md = MessageDigest.getInstance("SHA-1"); }
} catch (NoSuchAlgorithmException e) { if (mXmppConnectionService.allowMessageCorrection()) {
return null; features.addAll(Arrays.asList(MESSAGE_CORRECTION_FEATURES));
} }
if (Config.supportOmemo()) {
features.add(AxolotlService.PEP_DEVICE_LIST_NOTIFY);
}
if (!mXmppConnectionService.useTorToConnect() && !account.isOnion()) {
features.addAll(Arrays.asList(PRIVACY_SENSITIVE));
features.addAll(Arrays.asList(VOIP_NAMESPACES));
}
if (mXmppConnectionService.broadcastLastActivity()) {
features.add(Namespace.IDLE);
}
if (connection != null && connection.getFeatures().bookmarks2()) {
features.add(Namespace.BOOKMARKS2 + "+notify");
} else {
features.add(Namespace.BOOKMARKS + "+notify");
}
for (String feature : getFeatures(account)) { Collections.sort(features);
s.append(feature).append('<'); return features;
} }
final byte[] sha1 = md.digest(s.toString().getBytes());
return Base64.encodeToString(sha1, Base64.NO_WRAP);
}
public static String getTimestamp(long time) {
DATE_FORMAT.setTimeZone(TimeZone.getTimeZone("UTC"));
return DATE_FORMAT.format(time);
}
public List<String> getFeatures(Account account) {
final XmppConnection connection = account.getXmppConnection();
final ArrayList<String> features = new ArrayList<>(Arrays.asList(FEATURES));
if (mXmppConnectionService.confirmMessages()) {
features.addAll(Arrays.asList(MESSAGE_CONFIRMATION_FEATURES));
}
if (mXmppConnectionService.allowMessageCorrection()) {
features.addAll(Arrays.asList(MESSAGE_CORRECTION_FEATURES));
}
if (Config.supportOmemo()) {
features.add(AxolotlService.PEP_DEVICE_LIST_NOTIFY);
}
if (!mXmppConnectionService.useTorToConnect() && !account.isOnion()) {
features.addAll(Arrays.asList(PRIVACY_SENSITIVE));
features.addAll(Arrays.asList(VOIP_NAMESPACES));
}
if (mXmppConnectionService.broadcastLastActivity()) {
features.add(Namespace.IDLE);
}
if (connection != null && connection.getFeatures().bookmarks2()) {
features.add(Namespace.BOOKMARKS2 +"+notify");
} else {
features.add(Namespace.BOOKMARKS+"+notify");
}
Collections.sort(features);
return features;
}
} }