Do not Strigprep JIDs from database

This commit is contained in:
Mateusz "maxmati" Nowoty?ski 2015-03-05 22:11:59 +01:00 committed by iNPUTmice
parent 4ee4eeb5e7
commit 74e5317095
4 changed files with 13 additions and 11 deletions

View File

@ -80,7 +80,7 @@ public class Contact implements ListItem, Blockable {
cursor.getLong(cursor.getColumnIndex(LAST_TIME))); cursor.getLong(cursor.getColumnIndex(LAST_TIME)));
final Jid jid; final Jid jid;
try { try {
jid = Jid.fromString(cursor.getString(cursor.getColumnIndex(JID))); jid = Jid.fromString(cursor.getString(cursor.getColumnIndex(JID)), true);
} catch (final InvalidJidException e) { } catch (final InvalidJidException e) {
// TODO: Borked DB... handle this somehow? // TODO: Borked DB... handle this somehow?
return null; return null;

View File

@ -2,10 +2,8 @@ package eu.siacs.conversations.entities;
import android.content.ContentValues; import android.content.ContentValues;
import android.database.Cursor; import android.database.Cursor;
import android.os.SystemClock;
import net.java.otr4j.OtrException; import net.java.otr4j.OtrException;
import net.java.otr4j.crypto.OtrCryptoEngineImpl;
import net.java.otr4j.crypto.OtrCryptoException; import net.java.otr4j.crypto.OtrCryptoException;
import net.java.otr4j.session.SessionID; import net.java.otr4j.session.SessionID;
import net.java.otr4j.session.SessionImpl; import net.java.otr4j.session.SessionImpl;
@ -371,7 +369,7 @@ public class Conversation extends AbstractEntity implements Blockable {
public static Conversation fromCursor(Cursor cursor) { public static Conversation fromCursor(Cursor cursor) {
Jid jid; Jid jid;
try { try {
jid = Jid.fromString(cursor.getString(cursor.getColumnIndex(CONTACTJID))); jid = Jid.fromString(cursor.getString(cursor.getColumnIndex(CONTACTJID)), true);
} catch (final InvalidJidException e) { } catch (final InvalidJidException e) {
// Borked DB.. // Borked DB..
jid = null; jid = null;

View File

@ -117,7 +117,7 @@ public class Message extends AbstractEntity {
try { try {
String value = cursor.getString(cursor.getColumnIndex(COUNTERPART)); String value = cursor.getString(cursor.getColumnIndex(COUNTERPART));
if (value != null) { if (value != null) {
jid = Jid.fromString(value); jid = Jid.fromString(value, true);
} else { } else {
jid = null; jid = null;
} }
@ -128,7 +128,7 @@ public class Message extends AbstractEntity {
try { try {
String value = cursor.getString(cursor.getColumnIndex(TRUE_COUNTERPART)); String value = cursor.getString(cursor.getColumnIndex(TRUE_COUNTERPART));
if (value != null) { if (value != null) {
trueCounterpart = Jid.fromString(value); trueCounterpart = Jid.fromString(value, true);
} else { } else {
trueCounterpart = null; trueCounterpart = null;
} }

View File

@ -46,7 +46,11 @@ public final class Jid {
} }
public static Jid fromString(final String jid) throws InvalidJidException { public static Jid fromString(final String jid) throws InvalidJidException {
return new Jid(jid); return Jid.fromString(jid, false);
}
public static Jid fromString(final String jid, final boolean safe) throws InvalidJidException {
return new Jid(jid, safe);
} }
public static Jid fromParts(final String localpart, public static Jid fromParts(final String localpart,
@ -61,10 +65,10 @@ public final class Jid {
if (resourcepart != null && !resourcepart.isEmpty()) { if (resourcepart != null && !resourcepart.isEmpty()) {
out = out + "/" + resourcepart; out = out + "/" + resourcepart;
} }
return new Jid(out); return new Jid(out, false);
} }
private Jid(final String jid) throws InvalidJidException { private Jid(final String jid, final boolean safe) throws InvalidJidException {
if (jid == null) throw new InvalidJidException(InvalidJidException.IS_NULL); if (jid == null) throw new InvalidJidException(InvalidJidException.IS_NULL);
Jid fromCache = Jid.cache.get(jid); Jid fromCache = Jid.cache.get(jid);
@ -104,7 +108,7 @@ public final class Jid {
} else { } else {
final String lp = jid.substring(0, atLoc); final String lp = jid.substring(0, atLoc);
try { try {
localpart = Config.DISABLE_STRING_PREP ? lp : Stringprep.nodeprep(lp); localpart = Config.DISABLE_STRING_PREP || safe ? lp : Stringprep.nodeprep(lp);
} catch (final StringprepException e) { } catch (final StringprepException e) {
throw new InvalidJidException(InvalidJidException.STRINGPREP_FAIL, e); throw new InvalidJidException(InvalidJidException.STRINGPREP_FAIL, e);
} }
@ -119,7 +123,7 @@ public final class Jid {
if (slashCount > 0) { if (slashCount > 0) {
final String rp = jid.substring(slashLoc + 1, jid.length()); final String rp = jid.substring(slashLoc + 1, jid.length());
try { try {
resourcepart = Config.DISABLE_STRING_PREP ? rp : Stringprep.resourceprep(rp); resourcepart = Config.DISABLE_STRING_PREP || safe ? rp : Stringprep.resourceprep(rp);
} catch (final StringprepException e) { } catch (final StringprepException e) {
throw new InvalidJidException(InvalidJidException.STRINGPREP_FAIL, e); throw new InvalidJidException(InvalidJidException.STRINGPREP_FAIL, e);
} }