Search in sources :

Example 6 with Pairing

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

the class Silo method start.

public void start() {
    synchronized (pairingsLock) {
        for (Pairing pairing : activePairingsByUUID.values()) {
            Log.i(TAG, "starting " + Base64.encodeAsString(pairing.workstationPublicKey));
            SQSPoller poller = pollers.remove(pairing);
            if (poller != null) {
                poller.stop();
            }
            pollers.put(pairing, new SQSPoller(context, pairing));
        }
    }
}
Also used : SQSPoller(co.krypt.krypton.transport.SQSPoller) Pairing(co.krypt.krypton.pairing.Pairing)

Example 7 with Pairing

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

the class SealInstrumentedTest method seal_inverts.

@Test
public void seal_inverts() 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");
    for (int i = 0; i < 1024; i++) {
        byte[] message = SecureRandom.getSeed(i);
        byte[] ciphertext = pairing.seal(message);
        byte[] unsealed = pairing.unseal(ciphertext);
        assertTrue(Arrays.equals(message, unsealed));
    }
}
Also used : Pairing(co.krypt.krypton.pairing.Pairing) Test(org.junit.Test)

Example 8 with Pairing

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

the class SodiumInstrumentedTest method wrap_isCorrect.

@Test
public void wrap_isCorrect() 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())));
    byte[] enclavePubKey = new byte[Sodium.crypto_box_publickeybytes()];
    byte[] enclavePrivKey = new byte[Sodium.crypto_box_secretkeybytes()];
    assertTrue(0 == Sodium.crypto_box_seed_keypair(pubKey, privKey, SecureRandom.getSeed(Sodium.crypto_box_seedbytes())));
    Pairing pairing = new Pairing(pubKey, enclavePrivKey, enclavePubKey, "workstation");
    byte[] ciphertext = pairing.wrapKey();
    byte[] unwrapped = new byte[ciphertext.length - Sodium.crypto_box_sealbytes()];
    assertTrue(0 == Sodium.crypto_box_seal_open(unwrapped, ciphertext, ciphertext.length, pubKey, privKey));
    assertTrue(Arrays.equals(unwrapped, enclavePrivKey));
}
Also used : Pairing(co.krypt.krypton.pairing.Pairing) Test(org.junit.Test)

Example 9 with Pairing

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

the class ApprovalDialog method showApprovalDialog.

public static void showApprovalDialog(final Activity activity, final String requestID) {
    Pair<Pairing, Request> pendingRequestAndPairing = Policy.getPendingRequestAndPairing(requestID);
    if (pendingRequestAndPairing == null) {
        Log.e(TAG, "user clicked notification for unknown request");
        return;
    }
    Pairing pairing = pendingRequestAndPairing.first;
    Request request = pendingRequestAndPairing.second;
    AlertDialog.Builder builder = new AlertDialog.Builder(activity);
    builder.setIcon(R.mipmap.ic_launcher);
    // setPositiveButton: right button
    // setNeutralButton: left button
    // setNegativeButton: middle button
    long temporaryApprovalSeconds = Policy.temporaryApprovalSeconds(activity, request);
    boolean temporaryApprovalEnabled = temporaryApprovalSeconds > 0;
    String temporaryApprovalDuration = Policy.temporaryApprovalDuration(activity, request);
    request.body.visit(new RequestBody.Visitor<Void, RuntimeException>() {

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

        @Override
        public Void visit(SignRequest signRequest) throws RuntimeException {
            builder.setPositiveButton("Once", (dialog, id) -> Policy.onAction(activity.getApplicationContext(), requestID, Policy.APPROVE_ONCE));
            if (temporaryApprovalEnabled) {
                builder.setNeutralButton("All for " + temporaryApprovalDuration, (dialog, id) -> Policy.onAction(activity.getApplicationContext(), requestID, Policy.APPROVE_ALL_TEMPORARILY));
                if (signRequest.hostNameVerified) {
                    builder.setNegativeButton("This host for " + temporaryApprovalDuration, (dialog, id) -> Policy.onAction(activity.getApplicationContext(), requestID, Policy.APPROVE_THIS_TEMPORARILY));
                }
            }
            return null;
        }

        @Override
        public Void visit(GitSignRequest gitSignRequest) throws RuntimeException {
            builder.setPositiveButton("Once", (dialog, id) -> Policy.onAction(activity.getApplicationContext(), requestID, Policy.APPROVE_ONCE));
            if (temporaryApprovalEnabled) {
                builder.setNeutralButton("All for " + temporaryApprovalDuration, (dialog, id) -> Policy.onAction(activity.getApplicationContext(), requestID, Policy.APPROVE_ALL_TEMPORARILY));
            }
            return null;
        }

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

        @Override
        public Void visit(HostsRequest hostsRequest) throws RuntimeException {
            builder.setPositiveButton("Allow", (dialog, id) -> Policy.onAction(activity.getApplicationContext(), requestID, Policy.APPROVE_ONCE));
            if (temporaryApprovalEnabled) {
                builder.setNeutralButton("All for " + temporaryApprovalDuration, (dialog, id) -> Policy.onAction(activity.getApplicationContext(), requestID, Policy.APPROVE_ALL_TEMPORARILY));
            }
            return null;
        }

        @Override
        public Void visit(ReadTeamRequest readTeamRequest) throws RuntimeException {
            builder.setPositiveButton("Allow for " + temporaryApprovalDuration, (dialog, id) -> Policy.onAction(activity.getApplicationContext(), requestID, Policy.APPROVE_ALL_TEMPORARILY));
            return null;
        }

        @Override
        public Void visit(LogDecryptionRequest logDecryptionRequest) throws RuntimeException {
            builder.setPositiveButton("Allow for " + temporaryApprovalDuration, (dialog, id) -> Policy.onAction(activity.getApplicationContext(), requestID, Policy.APPROVE_ALL_TEMPORARILY));
            return null;
        }

        @Override
        public Void visit(TeamOperationRequest teamOperationRequest) throws RuntimeException {
            builder.setPositiveButton("Allow", (dialog, id) -> Policy.onAction(activity.getApplicationContext(), requestID, Policy.APPROVE_ONCE));
            return null;
        }
    });
    builder.setOnDismissListener(dialogInterface -> {
        Policy.onAction(activity.getApplicationContext(), requestID, Policy.REJECT);
    });
    View requestView = activity.getLayoutInflater().inflate(R.layout.request, null);
    TextView workstationNameText = (TextView) requestView.findViewById(R.id.workstationName);
    workstationNameText.setText(pairing.workstationName);
    ConstraintLayout content = (ConstraintLayout) requestView.findViewById(R.id.content);
    request.fillView(content);
    builder.setView(requestView);
    builder.create().show();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) ReadTeamRequest(co.krypt.krypton.protocol.ReadTeamRequest) UnpairRequest(co.krypt.krypton.protocol.UnpairRequest) HostsRequest(co.krypt.krypton.protocol.HostsRequest) SignRequest(co.krypt.krypton.protocol.SignRequest) Pairing(co.krypt.krypton.pairing.Pairing) MeRequest(co.krypt.krypton.protocol.MeRequest) Request(co.krypt.krypton.protocol.Request) RequestBody(co.krypt.krypton.protocol.RequestBody) AlertDialog(android.support.v7.app.AlertDialog) TextView(android.widget.TextView) Pair(android.support.v4.util.Pair) GitSignRequest(co.krypt.krypton.protocol.GitSignRequest) View(android.view.View) LogDecryptionRequest(co.krypt.krypton.protocol.LogDecryptionRequest) ConstraintLayout(android.support.constraint.ConstraintLayout) Activity(android.app.Activity) R(co.krypt.krypton.R) Policy(co.krypt.krypton.policy.Policy) TeamOperationRequest(co.krypt.krypton.protocol.TeamOperationRequest) Log(android.util.Log) MeRequest(co.krypt.krypton.protocol.MeRequest) TeamOperationRequest(co.krypt.krypton.protocol.TeamOperationRequest) ConstraintLayout(android.support.constraint.ConstraintLayout) GitSignRequest(co.krypt.krypton.protocol.GitSignRequest) TextView(android.widget.TextView) Pairing(co.krypt.krypton.pairing.Pairing) RequestBody(co.krypt.krypton.protocol.RequestBody) SignRequest(co.krypt.krypton.protocol.SignRequest) GitSignRequest(co.krypt.krypton.protocol.GitSignRequest) ReadTeamRequest(co.krypt.krypton.protocol.ReadTeamRequest) UnpairRequest(co.krypt.krypton.protocol.UnpairRequest) HostsRequest(co.krypt.krypton.protocol.HostsRequest) SignRequest(co.krypt.krypton.protocol.SignRequest) MeRequest(co.krypt.krypton.protocol.MeRequest) Request(co.krypt.krypton.protocol.Request) GitSignRequest(co.krypt.krypton.protocol.GitSignRequest) LogDecryptionRequest(co.krypt.krypton.protocol.LogDecryptionRequest) TeamOperationRequest(co.krypt.krypton.protocol.TeamOperationRequest) HostsRequest(co.krypt.krypton.protocol.HostsRequest) UnpairRequest(co.krypt.krypton.protocol.UnpairRequest) TextView(android.widget.TextView) View(android.view.View) ReadTeamRequest(co.krypt.krypton.protocol.ReadTeamRequest) LogDecryptionRequest(co.krypt.krypton.protocol.LogDecryptionRequest)

Example 10 with Pairing

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

the class DeviceDetailFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_device_detail, container, false);
    final Pairing pairing = Silo.shared(getContext()).pairings().getPairing(pairingUUID);
    if (pairing == null) {
        return view;
    }
    View deviceCardView = inflater.inflate(R.layout.device_card, container, false);
    TextView deviceName = (TextView) deviceCardView.findViewById(R.id.deviceName);
    deviceName.setText(pairing.workstationName);
    manualButton = (RadioButton) deviceCardView.findViewById(R.id.alwaysAsk);
    automaticButton = (RadioButton) deviceCardView.findViewById(R.id.automaticApprovalButton);
    viewTemporaryApprovalsButton = deviceCardView.findViewById(R.id.temporaryApprovalsViewButton);
    viewTemporaryApprovalsButton.setOnClickListener(v -> {
        ApprovalsFragment f = ApprovalsFragment.newInstance(pairing.uuid);
        getFragmentManager().beginTransaction().setCustomAnimations(R.anim.enter_from_right_fast, R.anim.exit_to_right_fast, R.anim.enter_from_right_fast, R.anim.exit_to_right_fast).addToBackStack(null).add(R.id.childFragmentContainer, f).commit();
    });
    resetTemporaryApprovalsButton = deviceCardView.findViewById(R.id.temporaryApprovalsResetButton);
    resetTemporaryApprovalsButton.setOnClickListener(v -> {
        try {
            Approval.deleteApprovalsForPairing(Silo.shared(v.getContext()).pairings().dbHelper.getApprovalDao(), pairing.uuid);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    });
    temporaryApprovalsContainer = deviceCardView.findViewById(R.id.temporaryApprovalsContainer);
    updateApprovalButtons();
    unpairButton = (Button) deviceCardView.findViewById(R.id.unpairButton);
    unpairButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Silo.shared(v.getContext()).unpair(pairing, true);
            new Analytics(getContext()).postEvent("device", "unpair", null, null, false);
            getFragmentManager().popBackStackImmediate();
        }
    });
    final SwitchCompat askUnknownHostsSwitch = (SwitchCompat) deviceCardView.findViewById(R.id.requireUnknownHostApprovalSwitch);
    askUnknownHostsSwitch.setChecked(new Pairings(getContext()).requireUnknownHostManualApproval(pairing));
    askUnknownHostsSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            new Pairings(getContext()).setRequireUnknownHostManualApproval(pairing, isChecked);
        }
    });
    signatureLogAdapter.deviceCardView.set(deviceCardView);
    RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.list);
    Context context = recyclerView.getContext();
    if (mColumnCount <= 1) {
        recyclerView.setLayoutManager(new LinearLayoutManager(context));
    } else {
        recyclerView.setLayoutManager(new GridLayoutManager(context, mColumnCount));
    }
    recyclerView.setAdapter(signatureLogAdapter);
    onDeviceLogReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            signatureLogAdapter.setLogs(Silo.shared(getContext()).pairings().getAllLogsTimeDescending(pairingUUID));
        }
    };
    IntentFilter filter = new IntentFilter();
    filter.addAction(Pairings.ON_DEVICE_LOG_ACTION);
    LocalBroadcastManager.getInstance(context).registerReceiver(onDeviceLogReceiver, filter);
    Silo.shared(getContext()).pairings().registerOnSharedPreferenceChangedListener(this);
    return view;
}
Also used : Context(android.content.Context) IntentFilter(android.content.IntentFilter) ApprovalsFragment(co.krypt.krypton.approval.ApprovalsFragment) SQLException(java.sql.SQLException) Intent(android.content.Intent) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) BroadcastReceiver(android.content.BroadcastReceiver) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) Analytics(co.krypt.krypton.analytics.Analytics) Pairings(co.krypt.krypton.pairing.Pairings) GridLayoutManager(android.support.v7.widget.GridLayoutManager) TextView(android.widget.TextView) RecyclerView(android.support.v7.widget.RecyclerView) Pairing(co.krypt.krypton.pairing.Pairing) CompoundButton(android.widget.CompoundButton) SwitchCompat(android.support.v7.widget.SwitchCompat)

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