Search in sources :

Example 1 with Pairing

use of co.krypt.krypton.pairing.Pairing 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 2 with Pairing

use of co.krypt.krypton.pairing.Pairing 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)

Example 3 with Pairing

use of co.krypt.krypton.pairing.Pairing in project krypton-android by kryptco.

the class Policy method onAction.

public static void onAction(final Context context, final String requestID, final String action) {
    Log.i(TAG, action + " requestID " + requestID);
    final Pair<Pairing, Request> pairingAndRequest;
    // Lock manually to prevent deadlock from Silo
    synchronized (Policy.class) {
        pairingAndRequest = pendingRequestCache.remove(requestID);
    }
    if (pairingAndRequest == null) {
        Log.e(TAG, "requestID " + requestID + " not pending");
        return;
    }
    Silo silo = Silo.shared(context);
    OpenDatabaseHelper db = silo.pairings().dbHelper;
    Notifications.clearRequest(context, pairingAndRequest.second);
    switch(action) {
        case APPROVE_ONCE:
            try {
                silo.respondToRequest(pairingAndRequest.first, pairingAndRequest.second, true);
                new Analytics(context).postEvent(pairingAndRequest.second.analyticsCategory(), "background approve", "once", null, false);
            } catch (Exception e) {
                e.printStackTrace();
            }
            break;
        case APPROVE_ALL_TEMPORARILY:
            try {
                pairingAndRequest.second.body.visit(new RequestBody.Visitor<Void, Unrecoverable>() {

                    @Override
                    public Void visit(MeRequest meRequest) throws Unrecoverable {
                        return null;
                    }

                    @Override
                    public Void visit(SignRequest signRequest) throws Unrecoverable {
                        try {
                            Approval.approveSSHAnyHost(db, pairingAndRequest.first.uuid);
                        } catch (IOException | SQLException e) {
                            throw new Unrecoverable(e);
                        }
                        return null;
                    }

                    @Override
                    public Void visit(GitSignRequest gitSignRequest) throws Unrecoverable {
                        gitSignRequest.body.visit(new GitSignRequestBody.Visitor<Void, Unrecoverable>() {

                            @Override
                            public Void visit(CommitInfo commit) throws Unrecoverable {
                                try {
                                    Approval.approveGitCommitSignatures(db, pairingAndRequest.first.uuid);
                                } catch (IOException | SQLException e) {
                                    throw new Unrecoverable(e);
                                }
                                return null;
                            }

                            @Override
                            public Void visit(TagInfo tag) throws Unrecoverable {
                                try {
                                    Approval.approveGitTagSignatures(db, pairingAndRequest.first.uuid);
                                } catch (IOException | SQLException e) {
                                    throw new Unrecoverable(e);
                                }
                                return null;
                            }
                        });
                        return null;
                    }

                    @Override
                    public Void visit(UnpairRequest unpairRequest) throws Unrecoverable {
                        return null;
                    }

                    @Override
                    public Void visit(HostsRequest hostsRequest) throws Unrecoverable {
                        return null;
                    }

                    @Override
                    public Void visit(ReadTeamRequest readTeamRequest) throws Unrecoverable {
                        try {
                            Approval.approveReadTeamData(db, pairingAndRequest.first.uuid);
                        } catch (IOException | SQLException e) {
                            throw new Unrecoverable(e);
                        }
                        return null;
                    }

                    @Override
                    public Void visit(LogDecryptionRequest logDecryptionRequest) throws Unrecoverable {
                        try {
                            Approval.approveReadTeamData(db, pairingAndRequest.first.uuid);
                        } catch (IOException | SQLException e) {
                            throw new Unrecoverable(e);
                        }
                        return null;
                    }

                    @Override
                    public Void visit(TeamOperationRequest teamOperationRequest) throws Unrecoverable {
                        return null;
                    }
                });
                silo.respondToRequest(pairingAndRequest.first, pairingAndRequest.second, true);
                new Analytics(context).postEvent(pairingAndRequest.second.analyticsCategory(), "background approve", "time", (int) temporaryApprovalSeconds(context, pairingAndRequest.second), false);
            } catch (Exception e) {
                e.printStackTrace();
            }
            break;
        case APPROVE_THIS_TEMPORARILY:
            try {
                pairingAndRequest.second.body.visit(new RequestBody.Visitor<Void, Unrecoverable>() {

                    @Override
                    public Void visit(MeRequest meRequest) throws Unrecoverable {
                        return null;
                    }

                    @Override
                    public Void visit(SignRequest signRequest) throws Unrecoverable {
                        String user = signRequest.user();
                        if (signRequest.hostNameVerified && signRequest.hostAuth.hostNames.length > 0) {
                            try {
                                Approval.approveSSHUserHost(db, pairingAndRequest.first.uuid, user, signRequest.hostAuth.hostNames[0]);
                            } catch (IOException | SQLException e) {
                                throw new Unrecoverable(e);
                            }
                        }
                        return null;
                    }

                    @Override
                    public Void visit(GitSignRequest gitSignRequest) throws Unrecoverable {
                        return null;
                    }

                    @Override
                    public Void visit(UnpairRequest unpairRequest) throws Unrecoverable {
                        return null;
                    }

                    @Override
                    public Void visit(HostsRequest hostsRequest) throws Unrecoverable {
                        return null;
                    }

                    @Override
                    public Void visit(ReadTeamRequest readTeamRequest) throws Unrecoverable {
                        return null;
                    }

                    @Override
                    public Void visit(LogDecryptionRequest logDecryptionRequest) throws Unrecoverable {
                        return null;
                    }

                    @Override
                    public Void visit(TeamOperationRequest teamOperationRequest) throws Unrecoverable {
                        return null;
                    }
                });
                silo.respondToRequest(pairingAndRequest.first, pairingAndRequest.second, true);
                new Analytics(context).postEvent(pairingAndRequest.second.analyticsCategory(), "background approve this", "time", (int) temporaryApprovalSeconds(context, pairingAndRequest.second), false);
            } catch (Exception e) {
                e.printStackTrace();
            }
        case REJECT:
            try {
                silo.respondToRequest(pairingAndRequest.first, pairingAndRequest.second, false);
                new Analytics(context).postEvent(pairingAndRequest.second.analyticsCategory(), "background reject", null, null, false);
            } catch (Unrecoverable e) {
                e.printStackTrace();
            }
            break;
    }
}
Also used : MeRequest(co.krypt.krypton.protocol.MeRequest) SQLException(java.sql.SQLException) Unrecoverable(co.krypt.krypton.exception.Unrecoverable) TeamOperationRequest(co.krypt.krypton.protocol.TeamOperationRequest) OpenDatabaseHelper(co.krypt.krypton.db.OpenDatabaseHelper) GitSignRequest(co.krypt.krypton.protocol.GitSignRequest) TagInfo(co.krypt.krypton.git.TagInfo) CommitInfo(co.krypt.krypton.git.CommitInfo) Pairing(co.krypt.krypton.pairing.Pairing) Silo(co.krypt.krypton.silo.Silo) RequestBody(co.krypt.krypton.protocol.RequestBody) GitSignRequestBody(co.krypt.krypton.protocol.GitSignRequestBody) SignRequest(co.krypt.krypton.protocol.SignRequest) GitSignRequest(co.krypt.krypton.protocol.GitSignRequest) ReadTeamRequest(co.krypt.krypton.protocol.ReadTeamRequest) UnpairRequest(co.krypt.krypton.protocol.UnpairRequest) SignRequest(co.krypt.krypton.protocol.SignRequest) MeRequest(co.krypt.krypton.protocol.MeRequest) Request(co.krypt.krypton.protocol.Request) LogDecryptionRequest(co.krypt.krypton.protocol.LogDecryptionRequest) HostsRequest(co.krypt.krypton.protocol.HostsRequest) GitSignRequest(co.krypt.krypton.protocol.GitSignRequest) TeamOperationRequest(co.krypt.krypton.protocol.TeamOperationRequest) HostsRequest(co.krypt.krypton.protocol.HostsRequest) IOException(java.io.IOException) UnpairRequest(co.krypt.krypton.protocol.UnpairRequest) Analytics(co.krypt.krypton.analytics.Analytics) SQLException(java.sql.SQLException) IOException(java.io.IOException) ReadTeamRequest(co.krypt.krypton.protocol.ReadTeamRequest) LogDecryptionRequest(co.krypt.krypton.protocol.LogDecryptionRequest)

Example 4 with Pairing

use of co.krypt.krypton.pairing.Pairing in project krypton-android by kryptco.

the class OnboardingActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    setTheme(R.style.AppTheme);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_onboarding);
    new Analytics(getApplicationContext()).postEvent("onboard", "start", null, null, false);
    FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
    OnboardingProgress progress = new OnboardingProgress(getApplicationContext());
    GenerateFragment generateFragment;
    EnterEmailFragment enterEmailFragment;
    FirstPairFragment firstPairFragment;
    TestSSHFragment testSSHFragment;
    switch(progress.currentStage()) {
        case NONE:
            generateFragment = new GenerateFragment();
            fragmentTransaction.add(R.id.activity_onboarding, generateFragment).commit();
            break;
        case GENERATE:
            generateFragment = new GenerateFragment();
            fragmentTransaction.add(R.id.activity_onboarding, generateFragment).commit();
            break;
        case GENERATING:
            // generation must have failed, start from beginning
            generateFragment = new GenerateFragment();
            fragmentTransaction.add(R.id.activity_onboarding, generateFragment).commit();
            break;
        case ENTER_EMAIL:
            enterEmailFragment = new EnterEmailFragment();
            fragmentTransaction.add(R.id.activity_onboarding, enterEmailFragment).commit();
            break;
        case FIRST_PAIR:
            firstPairFragment = new FirstPairFragment();
            fragmentTransaction.add(R.id.activity_onboarding, firstPairFragment).commit();
            break;
        case TEST_SSH:
            Iterator<Pairing> pairings = Silo.shared(getApplicationContext()).pairings().loadAll().iterator();
            if (pairings.hasNext()) {
                testSSHFragment = TestSSHFragment.newInstance(pairings.next().workstationName);
                fragmentTransaction.add(R.id.activity_onboarding, testSSHFragment).commit();
            } else {
                // revert to FirstPair stage
                firstPairFragment = new FirstPairFragment();
                fragmentTransaction.add(R.id.activity_onboarding, firstPairFragment).commit();
            }
            break;
    }
    if (getIntent() != null) {
        onNewIntent(getIntent());
    }
}
Also used : FragmentTransaction(android.support.v4.app.FragmentTransaction) Pairing(co.krypt.krypton.pairing.Pairing) Analytics(co.krypt.krypton.analytics.Analytics)

Example 5 with Pairing

use of co.krypt.krypton.pairing.Pairing in project krypton-android by kryptco.

the class SealInstrumentedTest method sealTamper_fails.

@Test(expected = CryptoException.class)
public void sealTamper_fails() throws Exception {
    byte[] pubKey = new byte[Sodium.crypto_box_publickeybytes()];
    byte[] privKey = new byte[Sodium.crypto_box_secretkeybytes()];
    assertTrue(0 == Sodium.crypto_box_seed_keypair(pubKey, privKey, SecureRandom.getSeed(Sodium.crypto_box_seedbytes())));
    Pairing pairing = Pairing.generate(pubKey, "workstation");
    byte[] message = SecureRandom.getSeed(37);
    byte[] ciphertext = pairing.seal(message);
    ciphertext[17] ^= 0xff;
    byte[] unsealed = pairing.unseal(ciphertext);
}
Also used : Pairing(co.krypt.krypton.pairing.Pairing) Test(org.junit.Test)

Aggregations

Pairing (co.krypt.krypton.pairing.Pairing)11 View (android.view.View)3 TextView (android.widget.TextView)3 Analytics (co.krypt.krypton.analytics.Analytics)3 GitSignRequest (co.krypt.krypton.protocol.GitSignRequest)3 HostsRequest (co.krypt.krypton.protocol.HostsRequest)3 LogDecryptionRequest (co.krypt.krypton.protocol.LogDecryptionRequest)3 MeRequest (co.krypt.krypton.protocol.MeRequest)3 ReadTeamRequest (co.krypt.krypton.protocol.ReadTeamRequest)3 Request (co.krypt.krypton.protocol.Request)3 SignRequest (co.krypt.krypton.protocol.SignRequest)3 TeamOperationRequest (co.krypt.krypton.protocol.TeamOperationRequest)3 UnpairRequest (co.krypt.krypton.protocol.UnpairRequest)3 SQLException (java.sql.SQLException)3 Test (org.junit.Test)3 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)2 RecyclerView (android.support.v7.widget.RecyclerView)2 NetworkMessage (co.krypt.krypton.protocol.NetworkMessage)2 RequestBody (co.krypt.krypton.protocol.RequestBody)2 SQSPoller (co.krypt.krypton.transport.SQSPoller)2