mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-11 18:29:05 +01:00
Merge branch '2397-wrong-type-of-qr-code' into 'master'
Show appropriate error message if user scans wrong kind of QR code Closes #2397 See merge request briar/briar!1748
This commit is contained in:
@@ -1,18 +1,26 @@
|
||||
package org.briarproject.bramble.api.keyagreement;
|
||||
|
||||
public interface KeyAgreementConstants {
|
||||
import org.briarproject.bramble.api.mailbox.MailboxConstants;
|
||||
|
||||
/**
|
||||
* The version of the BQP protocol used in beta releases. This version
|
||||
* number is reserved.
|
||||
*/
|
||||
byte BETA_PROTOCOL_VERSION = 89;
|
||||
public interface KeyAgreementConstants {
|
||||
|
||||
/**
|
||||
* The current version of the BQP protocol.
|
||||
*/
|
||||
byte PROTOCOL_VERSION = 4;
|
||||
|
||||
/**
|
||||
* The QR code format identifier, used to distinguish BQP QR codes from
|
||||
* QR codes used for other purposes. See
|
||||
* {@link MailboxConstants#QR_FORMAT_ID}.
|
||||
*/
|
||||
byte QR_FORMAT_ID = 0;
|
||||
|
||||
/**
|
||||
* The QR code format version.
|
||||
*/
|
||||
byte QR_FORMAT_VERSION = PROTOCOL_VERSION;
|
||||
|
||||
/**
|
||||
* The length of the BQP key commitment in bytes.
|
||||
*/
|
||||
|
||||
@@ -7,5 +7,5 @@ import java.io.IOException;
|
||||
@NotNullByDefault
|
||||
public interface PayloadParser {
|
||||
|
||||
Payload parse(byte[] raw) throws IOException;
|
||||
Payload parse(String payload) throws IOException;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.briarproject.bramble.api.mailbox;
|
||||
|
||||
import org.briarproject.bramble.api.keyagreement.KeyAgreementConstants;
|
||||
import org.briarproject.bramble.api.plugin.TransportId;
|
||||
|
||||
import java.util.List;
|
||||
@@ -19,6 +20,18 @@ public interface MailboxConstants {
|
||||
*/
|
||||
TransportId ID = new TransportId("org.briarproject.bramble.mailbox");
|
||||
|
||||
/**
|
||||
* The QR code format identifier, used to distinguish mailbox QR codes
|
||||
* from QR codes used for other purposes. See
|
||||
* {@link KeyAgreementConstants#QR_FORMAT_ID};
|
||||
*/
|
||||
byte QR_FORMAT_ID = 1;
|
||||
|
||||
/**
|
||||
* The QR code format version.
|
||||
*/
|
||||
byte QR_FORMAT_VERSION = 0;
|
||||
|
||||
/**
|
||||
* Mailbox API versions that we support as a client. This is reported to our
|
||||
* contacts by {@link MailboxUpdateManager}.
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package org.briarproject.bramble.api.mailbox;
|
||||
|
||||
import org.briarproject.bramble.api.qrcode.QrCodeClassifier.QrCodeType;
|
||||
|
||||
public abstract class MailboxPairingState {
|
||||
|
||||
public abstract static class Pending extends MailboxPairingState {
|
||||
@@ -29,6 +31,14 @@ public abstract class MailboxPairingState {
|
||||
}
|
||||
|
||||
public static class InvalidQrCode extends MailboxPairingState {
|
||||
|
||||
public final QrCodeType qrCodeType;
|
||||
public final int formatVersion;
|
||||
|
||||
public InvalidQrCode(QrCodeType qrCodeType, int formatVersion) {
|
||||
this.qrCodeType = qrCodeType;
|
||||
this.formatVersion = formatVersion;
|
||||
}
|
||||
}
|
||||
|
||||
public static class MailboxAlreadyPaired extends MailboxPairingState {
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package org.briarproject.bramble.api.qrcode;
|
||||
|
||||
import org.briarproject.bramble.api.Pair;
|
||||
import org.briarproject.nullsafety.NotNullByDefault;
|
||||
|
||||
@NotNullByDefault
|
||||
public interface QrCodeClassifier {
|
||||
|
||||
enum QrCodeType {
|
||||
BQP,
|
||||
MAILBOX,
|
||||
UNKNOWN
|
||||
}
|
||||
|
||||
Pair<QrCodeType, Integer> classifyQrCode(String payload);
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package org.briarproject.bramble.api.qrcode;
|
||||
|
||||
import org.briarproject.bramble.api.FormatException;
|
||||
import org.briarproject.bramble.api.qrcode.QrCodeClassifier.QrCodeType;
|
||||
import org.briarproject.nullsafety.NotNullByDefault;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
/**
|
||||
* Thrown when a QR code that has been scanned does not have the expected type.
|
||||
*/
|
||||
@Immutable
|
||||
@NotNullByDefault
|
||||
public class WrongQrCodeTypeException extends FormatException {
|
||||
|
||||
private final QrCodeType qrCodeType;
|
||||
|
||||
public WrongQrCodeTypeException(QrCodeType qrCodeType) {
|
||||
this.qrCodeType = qrCodeType;
|
||||
}
|
||||
|
||||
public QrCodeType getQrCodeType() {
|
||||
return qrCodeType;
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,6 @@ package org.briarproject.bramble.util;
|
||||
import org.briarproject.bramble.api.FormatException;
|
||||
import org.briarproject.nullsafety.NotNullByDefault;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.CharacterCodingException;
|
||||
import java.nio.charset.Charset;
|
||||
@@ -17,13 +16,18 @@ import javax.annotation.Nullable;
|
||||
import static java.nio.charset.CodingErrorAction.IGNORE;
|
||||
import static java.util.regex.Pattern.CASE_INSENSITIVE;
|
||||
|
||||
@SuppressWarnings("CharsetObjectCanBeUsed")
|
||||
@NotNullByDefault
|
||||
public class StringUtils {
|
||||
|
||||
private static final Charset UTF_8 = Charset.forName("UTF-8");
|
||||
private static Pattern MAC = Pattern.compile("[0-9a-f]{2}:[0-9a-f]{2}:" +
|
||||
"[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}",
|
||||
CASE_INSENSITIVE);
|
||||
public static final Charset UTF_8 = Charset.forName("UTF-8");
|
||||
public static final Charset US_ASCII = Charset.forName("US-ASCII");
|
||||
public static final Charset ISO_8859_1 = Charset.forName("ISO-8859-1");
|
||||
|
||||
private static final Pattern MAC =
|
||||
Pattern.compile("[0-9a-f]{2}:[0-9a-f]{2}:" +
|
||||
"[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}",
|
||||
CASE_INSENSITIVE);
|
||||
|
||||
private static final char[] HEX = new char[] {
|
||||
'0', '1', '2', '3', '4', '5', '6', '7',
|
||||
@@ -45,11 +49,7 @@ public class StringUtils {
|
||||
}
|
||||
|
||||
public static byte[] toUtf8(String s) {
|
||||
try {
|
||||
return s.getBytes("UTF-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
return s.getBytes(UTF_8);
|
||||
}
|
||||
|
||||
public static String fromUtf8(byte[] bytes) {
|
||||
|
||||
Reference in New Issue
Block a user