Search in sources :

Example 1 with Silo

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

use of co.krypt.krypton.silo.Silo in project krypton-android by kryptco.

the class PairFragment method onPairingFailure.

private void onPairingFailure(final Pairing pairing) {
    Silo silo = Silo.shared(getContext());
    silo.unpair(pairing, false);
    pendingPairingQR.set(null);
    new Analytics(silo.context).postEvent("device", "pair", "failed", null, false);
    pairingStatusText.setText("Failed to pair with\n" + pairing.workstationName);
    pairingStatusView.setVisibility(View.VISIBLE);
    pairingStatusView.postDelayed(new Runnable() {

        @Override
        public void run() {
            pairingStatusView.setVisibility(View.INVISIBLE);
        }
    }, 2000);
}
Also used : Silo(co.krypt.krypton.silo.Silo) Analytics(co.krypt.krypton.analytics.Analytics)

Aggregations

Analytics (co.krypt.krypton.analytics.Analytics)2 Silo (co.krypt.krypton.silo.Silo)2 OpenDatabaseHelper (co.krypt.krypton.db.OpenDatabaseHelper)1 Unrecoverable (co.krypt.krypton.exception.Unrecoverable)1 CommitInfo (co.krypt.krypton.git.CommitInfo)1 TagInfo (co.krypt.krypton.git.TagInfo)1 Pairing (co.krypt.krypton.pairing.Pairing)1 GitSignRequest (co.krypt.krypton.protocol.GitSignRequest)1 GitSignRequestBody (co.krypt.krypton.protocol.GitSignRequestBody)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 RequestBody (co.krypt.krypton.protocol.RequestBody)1 SignRequest (co.krypt.krypton.protocol.SignRequest)1 TeamOperationRequest (co.krypt.krypton.protocol.TeamOperationRequest)1 UnpairRequest (co.krypt.krypton.protocol.UnpairRequest)1 IOException (java.io.IOException)1 SQLException (java.sql.SQLException)1