use of co.krypt.krypton.protocol.NetworkMessage in project krypton-android by kryptco.
the class Silo method send.
private void send(Pairing pairing, Response response) throws CryptoException, TransportException {
byte[] responseJson = JSON.toJson(response).getBytes();
byte[] sealed = pairing.seal(responseJson);
send(pairing, new NetworkMessage(NetworkMessage.Header.CIPHERTEXT, sealed));
}
use of co.krypt.krypton.protocol.NetworkMessage in project krypton-android by kryptco.
the class Silo method pair.
public Pairing pair(Pairing pairing) throws CryptoException, TransportException {
synchronized (pairingsLock) {
Pairing oldPairing = activePairingsByUUID.get(pairing.uuid);
if (oldPairing != null) {
Log.w(TAG, "already paired with " + pairing.workstationName);
return oldPairing;
}
byte[] wrappedKey = pairing.wrapKey();
NetworkMessage wrappedKeyMessage = new NetworkMessage(NetworkMessage.Header.WRAPPED_PUBLIC_KEY, wrappedKey);
send(pairing, wrappedKeyMessage);
pairingStorage.pair(pairing);
activePairingsByUUID.put(pairing.uuid, pairing);
pollers.put(pairing, new SQSPoller(context, pairing));
if (bluetoothTransport != null) {
bluetoothTransport.add(pairing);
bluetoothTransport.send(pairing, wrappedKeyMessage);
}
}
return pairing;
}
use of co.krypt.krypton.protocol.NetworkMessage in project krypton-android by kryptco.
the class Silo method onMessageJob.
private void onMessageJob(UUID pairingUUID, byte[] incoming, String communicationMedium) {
try {
NetworkMessage message = NetworkMessage.parse(incoming);
Pairing pairing;
synchronized (pairingsLock) {
pairing = activePairingsByUUID.get(pairingUUID);
}
if (pairing == null) {
Log.e(TAG, "not valid pairing: " + pairingUUID);
return;
}
switch(message.header) {
case CIPHERTEXT:
byte[] json = pairing.unseal(message.message);
Request request = JSON.fromJson(json, Request.class);
handle(pairing, request, communicationMedium);
break;
case WRAPPED_KEY:
break;
case WRAPPED_PUBLIC_KEY:
break;
}
} catch (Exception e) {
e.printStackTrace();
}
}
Aggregations