do quick start with HT-SHA-256-NONE part 1/2

This commit is contained in:
Daniel Gultsch 2022-10-15 18:56:31 +02:00 committed by Arne
parent 3aa27b531a
commit 0126ea987b
2 changed files with 111 additions and 21 deletions

View file

@ -96,7 +96,7 @@ public final class Config {
public static final boolean FORCE_ORBOT = false; // always use TOR
public static final boolean QUICKSTART_ENABLED = false;
public static final boolean QUICKSTART_ENABLED = true;
//Notification settings
public static final boolean HIDE_MESSAGE_TEXT_IN_NOTIFICATION = false;

View file

@ -14,6 +14,9 @@ import java.security.PublicKey;
import java.security.interfaces.DSAPublicKey;
import java.util.Locale;
import eu.siacs.conversations.crypto.sasl.HashedToken;
import eu.siacs.conversations.crypto.sasl.HashedTokenSha256;
import eu.siacs.conversations.crypto.sasl.HashedTokenSha512;
import org.json.JSONException;
import org.json.JSONObject;
@ -63,6 +66,8 @@ public class Account extends AbstractEntity implements AvatarService.Avatarable
public static final String RESOURCE = "resource";
public static final String PINNED_MECHANISM = "pinned_mechanism";
public static final String PINNED_CHANNEL_BINDING = "pinned_channel_binding";
public static final String FAST_MECHANISM = "fast_mechanism";
public static final String FAST_TOKEN = "fast_token";
public static final int OPTION_DISABLED = 1;
public static final int OPTION_REGISTER = 2;
@ -112,14 +117,42 @@ public class Account extends AbstractEntity implements AvatarService.Avatarable
private String pinnedChannelBinding;
public Account(final Jid jid, final String password) {
this(java.util.UUID.randomUUID().toString(), jid,
password, 0, null, "", null, null, null, 5222, Presence.Status.ONLINE, null, null, null);
this(
java.util.UUID.randomUUID().toString(),
jid,
password,
0,
null,
"",
null,
null,
null,
5222,
Presence.Status.ONLINE,
null,
null,
null,
null,
null);
}
private Account(final String uuid, final Jid jid,
final String password, final int options, final String rosterVersion, final String keys,
final String avatar, String displayName, String hostname, int port,
final Presence.Status status, String statusMessage, final String pinnedMechanism, final String pinnedChannelBinding) {
private Account(
final String uuid,
final Jid jid,
final String password,
final int options,
final String rosterVersion,
final String keys,
final String avatar,
String displayName,
String hostname,
int port,
final Presence.Status status,
String statusMessage,
final String pinnedMechanism,
final String pinnedChannelBinding,
final String fastMechanism,
final String fastToken) {
this.uuid = uuid;
this.jid = jid;
this.password = password;
@ -140,21 +173,29 @@ public class Account extends AbstractEntity implements AvatarService.Avatarable
this.presenceStatusMessage = statusMessage;
this.pinnedMechanism = pinnedMechanism;
this.pinnedChannelBinding = pinnedChannelBinding;
this.fastMechanism = fastMechanism;
this.fastToken = fastToken;
}
public static Account fromCursor(final Cursor cursor) {
final Jid jid;
try {
final String resource = cursor.getString(cursor.getColumnIndexOrThrow(RESOURCE));
jid = Jid.of(
cursor.getString(cursor.getColumnIndexOrThrow(USERNAME)),
cursor.getString(cursor.getColumnIndexOrThrow(SERVER)),
resource == null || resource.trim().isEmpty() ? null : resource);
jid =
Jid.of(
cursor.getString(cursor.getColumnIndexOrThrow(USERNAME)),
cursor.getString(cursor.getColumnIndexOrThrow(SERVER)),
resource == null || resource.trim().isEmpty() ? null : resource);
} catch (final IllegalArgumentException e) {
Log.d(Config.LOGTAG, cursor.getString(cursor.getColumnIndexOrThrow(USERNAME)) + "@" + cursor.getString(cursor.getColumnIndexOrThrow(SERVER)));
Log.d(
Config.LOGTAG,
cursor.getString(cursor.getColumnIndexOrThrow(USERNAME))
+ "@"
+ cursor.getString(cursor.getColumnIndexOrThrow(SERVER)));
throw new AssertionError(e);
}
return new Account(cursor.getString(cursor.getColumnIndexOrThrow(UUID)),
return new Account(
cursor.getString(cursor.getColumnIndexOrThrow(UUID)),
jid,
cursor.getString(cursor.getColumnIndexOrThrow(PASSWORD)),
cursor.getInt(cursor.getColumnIndexOrThrow(OPTIONS)),
@ -164,10 +205,13 @@ public class Account extends AbstractEntity implements AvatarService.Avatarable
cursor.getString(cursor.getColumnIndexOrThrow(DISPLAY_NAME)),
cursor.getString(cursor.getColumnIndexOrThrow(HOSTNAME)),
cursor.getInt(cursor.getColumnIndexOrThrow(PORT)),
Presence.Status.fromShowString(cursor.getString(cursor.getColumnIndexOrThrow(STATUS))),
Presence.Status.fromShowString(
cursor.getString(cursor.getColumnIndexOrThrow(STATUS))),
cursor.getString(cursor.getColumnIndexOrThrow(STATUS_MESSAGE)),
cursor.getString(cursor.getColumnIndexOrThrow(PINNED_MECHANISM)),
cursor.getString(cursor.getColumnIndexOrThrow(PINNED_CHANNEL_BINDING)));
cursor.getString(cursor.getColumnIndexOrThrow(PINNED_CHANNEL_BINDING)),
cursor.getString(cursor.getColumnIndexOrThrow(FAST_MECHANISM)),
cursor.getString(cursor.getColumnIndexOrThrow(FAST_TOKEN)));
}
public boolean httpUploadAvailable(long size) {
@ -318,9 +362,17 @@ public class Account extends AbstractEntity implements AvatarService.Avatarable
public void setPinnedMechanism(final SaslMechanism mechanism) {
this.pinnedMechanism = mechanism.getMechanism();
if (mechanism instanceof ScramPlusMechanism) {
this.pinnedChannelBinding = ((ScramPlusMechanism) mechanism).getChannelBinding().toString();
this.pinnedChannelBinding =
((ScramPlusMechanism) mechanism).getChannelBinding().toString();
} else {
this.pinnedChannelBinding = null;
}
}
public void setFastToken(final HashedToken.Mechanism mechanism, final String token) {
this.fastMechanism = mechanism.name();
this.fastToken = token;
}
public void resetPinnedMechanism() {
this.pinnedMechanism = null;
@ -341,11 +393,38 @@ public class Account extends AbstractEntity implements AvatarService.Avatarable
}
}
public SaslMechanism getPinnedMechanism() {
private SaslMechanism getPinnedMechanism() {
final String mechanism = Strings.nullToEmpty(this.pinnedMechanism);
final ChannelBinding channelBinding = ChannelBinding.get(this.pinnedChannelBinding);
return new SaslMechanism.Factory(this).of(mechanism, channelBinding);
}
private HashedToken getFastMechanism() {
final HashedToken.Mechanism fastMechanism = HashedToken.Mechanism.ofOrNull(this.fastMechanism);
final String token = this.fastToken;
if (fastMechanism == null || Strings.isNullOrEmpty(token)) {
return null;
}
if (fastMechanism.hashFunction.equals("SHA-256")) {
return new HashedTokenSha256(this, fastMechanism.channelBinding);
} else if (fastMechanism.hashFunction.equals("SHA-512")) {
return new HashedTokenSha512(this, fastMechanism.channelBinding);
} else {
return null;
}
}
public SaslMechanism getQuickStartMechanism() {
final HashedToken hashedTokenMechanism = getFastMechanism();
if (hashedTokenMechanism != null) {
return hashedTokenMechanism;
}
return getPinnedMechanism();
}
public String getFastToken() {
return this.fastToken;
}
public State getTrueStatus() {
return this.status;
@ -448,6 +527,8 @@ public class Account extends AbstractEntity implements AvatarService.Avatarable
values.put(RESOURCE, jid.getResource());
values.put(PINNED_MECHANISM, pinnedMechanism);
values.put(PINNED_CHANNEL_BINDING, pinnedChannelBinding);
values.put(FAST_MECHANISM, this.fastMechanism);
values.put(FAST_TOKEN, this.fastToken);
return values;
}
@ -517,7 +598,7 @@ public class Account extends AbstractEntity implements AvatarService.Avatarable
public int activeDevicesWithRtpCapability() {
int i = 0;
for(Presence presence : getSelfContact().getPresences().getPresences()) {
for (Presence presence : getSelfContact().getPresences().getPresences()) {
if (RtpCapability.check(presence) != RtpCapability.Capability.NONE) {
i++;
}
@ -671,10 +752,18 @@ public class Account extends AbstractEntity implements AvatarService.Avatarable
if (axolotlService == null) {
return fingerprints;
}
fingerprints.add(new XmppUri.Fingerprint(XmppUri.FingerprintType.OMEMO, axolotlService.getOwnFingerprint().substring(2), axolotlService.getOwnDeviceId()));
fingerprints.add(
new XmppUri.Fingerprint(
XmppUri.FingerprintType.OMEMO,
axolotlService.getOwnFingerprint().substring(2),
axolotlService.getOwnDeviceId()));
for (XmppAxolotlSession session : axolotlService.findOwnSessions()) {
if (session.getTrust().isVerified() && session.getTrust().isActive()) {
fingerprints.add(new XmppUri.Fingerprint(XmppUri.FingerprintType.OMEMO, session.getFingerprint().substring(2).replaceAll("\\s", ""), session.getRemoteAddress().getDeviceId()));
fingerprints.add(
new XmppUri.Fingerprint(
XmppUri.FingerprintType.OMEMO,
session.getFingerprint().substring(2).replaceAll("\\s", ""),
session.getRemoteAddress().getDeviceId()));
}
}
return fingerprints;
@ -682,7 +771,8 @@ public class Account extends AbstractEntity implements AvatarService.Avatarable
public boolean isBlocked(final ListItem contact) {
final Jid jid = contact.getJid();
return jid != null && (blocklist.contains(jid.asBareJid()) || blocklist.contains(jid.getDomain()));
return jid != null
&& (blocklist.contains(jid.asBareJid()) || blocklist.contains(jid.getDomain()));
}
public boolean isBlocked(final Jid jid) {