nonce is 4 bytes

This commit is contained in:
Vincent Breitmoser
2015-03-02 20:40:37 +01:00
parent 8bec183eda
commit e059b5550c

View File

@@ -79,14 +79,14 @@ public class LinkedIdentity {
b.append(mSubUri); b.append(mSubUri);
byte[] nonceBytes = Hex.decode(mNonce); byte[] nonceBytes = Hex.decode(mNonce);
if (nonceBytes.length != 12) { if (nonceBytes.length != 4) {
throw new AssertionError("nonce must be 12 bytes"); throw new AssertionError("nonce must be 4 bytes");
} }
byte[] data = Strings.toUTF8ByteArray(b.toString()); byte[] data = Strings.toUTF8ByteArray(b.toString());
byte[] result = new byte[data.length+12]; byte[] result = new byte[data.length+4];
System.arraycopy(nonceBytes, 0, result, 0, 12); System.arraycopy(nonceBytes, 0, result, 0, 4);
System.arraycopy(data, 0, result, 12, data.length); System.arraycopy(data, 0, result, 4, data.length);
return result; return result;
} }
@@ -100,10 +100,10 @@ public class LinkedIdentity {
} }
byte[] data = subpacket.getData(); byte[] data = subpacket.getData();
String nonce = Hex.toHexString(data, 0, 12); String nonce = Hex.toHexString(data, 0, 4);
try { try {
return parseUri(nonce, Strings.fromUTF8ByteArray(Arrays.copyOfRange(data, 12, data.length))); return parseUri(nonce, Strings.fromUTF8ByteArray(Arrays.copyOfRange(data, 4, data.length)));
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
Log.e(Constants.TAG, "error parsing uri in (suspected) linked id packet"); Log.e(Constants.TAG, "error parsing uri in (suspected) linked id packet");
@@ -161,12 +161,12 @@ public class LinkedIdentity {
public static String generateNonce() { public static String generateNonce() {
// TODO make this actually random // TODO make this actually random
// byte[] data = new byte[96]; // byte[] data = new byte[4];
// new SecureRandom().nextBytes(data); // new SecureRandom().nextBytes(data);
// return Hex.toHexString(data); // return Hex.toHexString(data);
// debug for now // debug for now
return "0123456789abcdef01234567"; return "01234567";
} }
} }