Search in sources :

Example 1 with NetworkMessage

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));
}
Also used : NetworkMessage(co.krypt.krypton.protocol.NetworkMessage)

Example 2 with NetworkMessage

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;
}
Also used : SQSPoller(co.krypt.krypton.transport.SQSPoller) NetworkMessage(co.krypt.krypton.protocol.NetworkMessage) Pairing(co.krypt.krypton.pairing.Pairing)

Example 3 with NetworkMessage

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();
    }
}
Also used : UnpairRequest(co.krypt.krypton.protocol.UnpairRequest) SignRequest(co.krypt.krypton.protocol.SignRequest) Request(co.krypt.krypton.protocol.Request) LogDecryptionRequest(co.krypt.krypton.protocol.LogDecryptionRequest) TeamOperationRequest(co.krypt.krypton.protocol.TeamOperationRequest) ReadTeamRequest(co.krypt.krypton.protocol.ReadTeamRequest) MeRequest(co.krypt.krypton.protocol.MeRequest) HostsRequest(co.krypt.krypton.protocol.HostsRequest) GitSignRequest(co.krypt.krypton.protocol.GitSignRequest) NetworkMessage(co.krypt.krypton.protocol.NetworkMessage) Pairing(co.krypt.krypton.pairing.Pairing) CryptoException(co.krypt.krypton.exception.CryptoException) TransportException(co.krypt.krypton.exception.TransportException) ProtocolException(co.krypt.krypton.exception.ProtocolException) SQLException(java.sql.SQLException) MismatchedHostKeyException(co.krypt.krypton.exception.MismatchedHostKeyException) IOException(java.io.IOException)

Aggregations

NetworkMessage (co.krypt.krypton.protocol.NetworkMessage)3 Pairing (co.krypt.krypton.pairing.Pairing)2 CryptoException (co.krypt.krypton.exception.CryptoException)1 MismatchedHostKeyException (co.krypt.krypton.exception.MismatchedHostKeyException)1 ProtocolException (co.krypt.krypton.exception.ProtocolException)1 TransportException (co.krypt.krypton.exception.TransportException)1 GitSignRequest (co.krypt.krypton.protocol.GitSignRequest)1 HostsRequest (co.krypt.krypton.protocol.HostsRequest)1 LogDecryptionRequest (co.krypt.krypton.protocol.LogDecryptionRequest)1 MeRequest (co.krypt.krypton.protocol.MeRequest)1 ReadTeamRequest (co.krypt.krypton.protocol.ReadTeamRequest)1 Request (co.krypt.krypton.protocol.Request)1 SignRequest (co.krypt.krypton.protocol.SignRequest)1 TeamOperationRequest (co.krypt.krypton.protocol.TeamOperationRequest)1 UnpairRequest (co.krypt.krypton.protocol.UnpairRequest)1 SQSPoller (co.krypt.krypton.transport.SQSPoller)1 IOException (java.io.IOException)1 SQLException (java.sql.SQLException)1