mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-14 11:49:04 +01:00
get the actual ip address on local wifi and add it to qr code
This commit is contained in:
@@ -2,9 +2,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.AgreementPublicKey;
|
||||
import org.briarproject.bramble.api.data.BdfList;
|
||||
import org.briarproject.briar.api.socialbackup.recovery.CustodianTask;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.security.PublicKey;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
public class CustodianTaskImpl implements CustodianTask {
|
||||
@@ -12,6 +17,7 @@ public class CustodianTaskImpl implements CustodianTask {
|
||||
private boolean cancelled = false;
|
||||
private Observer observer;
|
||||
private ClientHelper clientHelper;
|
||||
private InetSocketAddress remoteSocketAddress;
|
||||
|
||||
@Inject
|
||||
CustodianTaskImpl(ClientHelper clientHelper) {
|
||||
@@ -33,12 +39,13 @@ public class CustodianTaskImpl implements CustodianTask {
|
||||
public void qrCodeDecoded(byte[] qrCodePayloadRaw) {
|
||||
try {
|
||||
BdfList qrCodePayload = clientHelper.toList(qrCodePayloadRaw);
|
||||
byte[] publicKeyRaw = qrCodePayload.getRaw(0);
|
||||
AgreementPublicKey publicKey = new AgreementPublicKey(qrCodePayload.getRaw(0));
|
||||
byte[] addressRaw = qrCodePayload.getRaw(1);
|
||||
Long port = qrCodePayload.getLong(2);
|
||||
System.out.println(" Qr code decoded " + publicKeyRaw.length + " " + addressRaw.length + " "+ port);
|
||||
int port = qrCodePayload.getLong(2).intValue();
|
||||
remoteSocketAddress = new InetSocketAddress(InetAddress.getByAddress(addressRaw), port);
|
||||
System.out.println(" Qr code decoded " + publicKey.getEncoded().length + " " + remoteSocketAddress);
|
||||
observer.onStateChanged(new CustodianTask.State.SendingShard());
|
||||
} catch (FormatException e) {
|
||||
} catch (Exception e) {
|
||||
observer.onStateChanged(new CustodianTask.State.Failure(State.Failure.Reason.QR_CODE_INVALID));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,13 +33,14 @@ public class SecretOwnerTaskImpl implements SecretOwnerTask {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start(Observer observer) {
|
||||
// TODO use the actual ip address on local network
|
||||
byte[] hostBytes = { (byte) 192, (byte) 168, 1,1};
|
||||
// TODO add version number
|
||||
public void start(Observer observer, InetAddress inetAddress) {
|
||||
if (inetAddress == null) observer.onStateChanged(new State.Failure());
|
||||
System.out.println("InetAddress is " + inetAddress);
|
||||
socketAddress = new InetSocketAddress(inetAddress, 3002);
|
||||
// TODO start listening on socketAddress
|
||||
try {
|
||||
// TODO add version number
|
||||
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());
|
||||
|
||||
Reference in New Issue
Block a user