Qr code payload contains socket address and public key

This commit is contained in:
ameba23
2021-04-13 11:13:28 +02:00
parent f7e40657ee
commit df37a39cb4
7 changed files with 86 additions and 34 deletions

View File

@@ -10,7 +10,9 @@ import org.briarproject.bramble.api.versioning.ClientVersioningManager;
import org.briarproject.briar.api.conversation.ConversationManager;
import org.briarproject.briar.api.socialbackup.SocialBackupExchangeManager;
import org.briarproject.briar.api.socialbackup.SocialBackupManager;
import org.briarproject.briar.api.socialbackup.recovery.CustodianTask;
import org.briarproject.briar.api.socialbackup.recovery.SecretOwnerTask;
import org.briarproject.briar.socialbackup.recovery.CustodianTaskImpl;
import org.briarproject.briar.socialbackup.recovery.SecretOwnerTaskImpl;
import javax.inject.Inject;
@@ -103,4 +105,9 @@ public class SocialBackupModule {
SecretOwnerTask secretOwnerTask(SecretOwnerTaskImpl secretOwnerTask) {
return secretOwnerTask;
}
@Provides
CustodianTask custodianTask(CustodianTaskImpl custodianTask) {
return custodianTask;
}
}

View File

@@ -1,15 +1,45 @@
package org.briarproject.briar.socialbackup.recovery;
import org.briarproject.bramble.api.FormatException;
import org.briarproject.bramble.api.client.ClientHelper;
import org.briarproject.bramble.api.data.BdfList;
import org.briarproject.briar.api.socialbackup.recovery.CustodianTask;
import javax.inject.Inject;
public class CustodianTaskImpl implements CustodianTask {
private boolean cancelled = false;
private Observer observer;
private ClientHelper clientHelper;
@Inject
CustodianTaskImpl(ClientHelper clientHelper) {
this.clientHelper = clientHelper;
}
@Override
public void start(Observer observer) {
this.observer = observer;
observer.onStateChanged(new CustodianTask.State.Connecting());
}
@Override
public void cancel() {
cancelled = true;
}
@Override
public void qrCodeDecoded(byte[] qrCodePayloadRaw) {
try {
BdfList qrCodePayload = clientHelper.toList(qrCodePayloadRaw);
byte[] publicKeyRaw = qrCodePayload.getRaw(0);
byte[] addressRaw = qrCodePayload.getRaw(1);
Long port = qrCodePayload.getLong(2);
System.out.println(" Qr code decoded " + publicKeyRaw.length + " " + addressRaw.length + " "+ port);
observer.onStateChanged(new CustodianTask.State.SendingShard());
} catch (FormatException e) {
observer.onStateChanged(new CustodianTask.State.Failure(State.Failure.Reason.QR_CODE_INVALID));
}
}
}

View File

@@ -1,10 +1,14 @@
package org.briarproject.briar.socialbackup.recovery;
import org.briarproject.bramble.api.FormatException;
import org.briarproject.bramble.api.client.ClientHelper;
import org.briarproject.bramble.api.crypto.CryptoComponent;
import org.briarproject.bramble.api.crypto.KeyPair;
import org.briarproject.bramble.api.data.BdfList;
import org.briarproject.bramble.api.lifecycle.IoExecutor;
import org.briarproject.briar.api.socialbackup.recovery.SecretOwnerTask;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.util.concurrent.Executor;
@@ -16,20 +20,34 @@ public class SecretOwnerTaskImpl implements SecretOwnerTask {
private final Executor ioExecutor;
private final KeyPair localKeyPair;
private boolean cancelled = false;
private InetSocketAddress socketAddress;
private ClientHelper clientHelper;
@Inject
SecretOwnerTaskImpl(CryptoComponent crypto,
@IoExecutor Executor ioExecutor) {
@IoExecutor Executor ioExecutor, ClientHelper clientHelper) {
this.crypto = crypto;
this.ioExecutor = ioExecutor;
this.clientHelper = clientHelper;
localKeyPair = crypto.generateAgreementKeyPair();
}
@Override
public void start(Observer observer) {
// TODO use the actual ip address on local network
InetSocketAddress socketAddress = InetSocketAddress.createUnresolved("192.168.1.1", 1234);
observer.onStateChanged(new State.Listening(localKeyPair.getPublic(), socketAddress));
byte[] hostBytes = { (byte) 192, (byte) 168, 1,1};
// TODO add version number
try {
BdfList payloadList = new BdfList();
socketAddress = new InetSocketAddress(InetAddress.getByAddress(hostBytes), 1234);
payloadList.add(localKeyPair.getPublic().getEncoded());
payloadList.add(socketAddress.getAddress().getAddress());
payloadList.add(socketAddress.getPort());
observer.onStateChanged(
new State.Listening(clientHelper.toByteArray(payloadList)));
} catch (Exception e) {
observer.onStateChanged(new State.Failure());
}
}
@Override