Search in sources :

Example 11 with CryptoException

use of co.krypt.krypton.exception.CryptoException in project krypton-android by kryptco.

the class MemberEnterEmail method onCreateView.

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    final View v = inflater.inflate(R.layout.fragment_teams_invite_inperson_member_enter_email, container, false);
    email = v.findViewById(R.id.memberEmailInPerson);
    email.setText("loading...");
    email.setTextColor(getResources().getColor(R.color.appGray, null));
    email.setEnabled(false);
    Email.colorValidEmail(email);
    nextButton = v.findViewById(R.id.inpersonEmailNext);
    nextButton.setOnClickListener(b -> {
        EventBus.getDefault().unregister(this);
        nextButton.setEnabled(false);
        new Thread(() -> {
            try {
                new MeStorage(getContext()).setEmail(email.getText().toString().trim());
            } catch (CryptoException e) {
                co.krypt.krypton.uiutils.Error.shortToast(getContext(), "Failed to set email: " + e.getMessage());
                e.printStackTrace();
                return;
            }
            getActivity().runOnUiThread(() -> Transitions.beginSlide(this).replace(R.id.fragmentOverlay, new MemberQR()).addToBackStack(null).commitAllowingStateLoss());
        }).start();
    });
    nextButton.setEnabled(false);
    EventBus.getDefault().register(this);
    EventBus.getDefault().post(new GetProfile(getContext()));
    return v;
}
Also used : MeStorage(co.krypt.krypton.me.MeStorage) CryptoException(co.krypt.krypton.exception.CryptoException) View(android.view.View) GetProfile(co.krypt.krypton.silo.IdentityService.GetProfile) Nullable(android.support.annotation.Nullable)

Example 12 with CryptoException

use of co.krypt.krypton.exception.CryptoException in project krypton-android by kryptco.

the class Log method fromSSHRequest.

public static Log fromSSHRequest(Pairing pairing, Request req, SignRequest signRequest, Body.SSH.Result res) {
    Log log = new Log();
    log.session = new Session();
    log.session.deviceName = pairing.workstationName;
    try {
        log.session.workstationPublicKeyDoubleHash = SHA256.digest(SHA256.digest(pairing.workstationPublicKey));
    } catch (CryptoException e) {
        log.session.workstationPublicKeyDoubleHash = new byte[] {};
        e.printStackTrace();
    }
    log.unixSeconds = req.unixSeconds;
    Body body = new Body();
    body.ssh = new Body.SSH();
    if (signRequest.hostNameVerified && signRequest.hostAuth.hostNames.length > 0) {
        Body.SSH.HostAuthorization hostAuthorization = new Body.SSH.HostAuthorization();
        hostAuthorization.host = signRequest.hostAuth.hostNames[0];
        hostAuthorization.publicKey = signRequest.hostAuth.hostKey;
        hostAuthorization.signature = signRequest.hostAuth.signature;
        body.ssh.hostAuthorization = hostAuthorization;
    }
    body.ssh.sessionData = signRequest.data;
    body.ssh.user = signRequest.user();
    body.ssh.result = res;
    log.body = body;
    return log;
}
Also used : CryptoException(co.krypt.krypton.exception.CryptoException) GitSignRequestBody(co.krypt.krypton.protocol.GitSignRequestBody)

Example 13 with CryptoException

use of co.krypt.krypton.exception.CryptoException in project krypton-android by kryptco.

the class Log method fromGitRequest.

public static Log fromGitRequest(Pairing pairing, Request req, GitSignRequest gitSignRequest, Body.GitSignatureResult res) {
    Log log = new Log();
    log.session = new Session();
    log.session.deviceName = pairing.workstationName;
    try {
        log.session.workstationPublicKeyDoubleHash = SHA256.digest(SHA256.digest(pairing.workstationPublicKey));
    } catch (CryptoException e) {
        log.session.workstationPublicKeyDoubleHash = new byte[] {};
        e.printStackTrace();
    }
    log.unixSeconds = req.unixSeconds;
    Body body = new Body();
    gitSignRequest.body.visit(new GitSignRequestBody.Visitor<Void, RuntimeException>() {

        @Override
        public Void visit(CommitInfo commit) throws RuntimeException {
            Body.GitCommitSignature gitCommitSignature = new Body.GitCommitSignature();
            gitCommitSignature.tree = commit.tree;
            gitCommitSignature.author = commit.author;
            gitCommitSignature.committer = commit.committer;
            gitCommitSignature.message = commit.message;
            gitCommitSignature.messageString = commit.validatedMessageStringOrError();
            if (commit.mergeParents != null) {
                gitCommitSignature.parents = commit.mergeParents.toArray(new String[] {});
            } else {
                gitCommitSignature.parents = new String[] {};
            }
            gitCommitSignature.result = res;
            body.gitCommit = gitCommitSignature;
            return null;
        }

        @Override
        public Void visit(TagInfo tag) throws RuntimeException {
            Body.GitTagSignature gitTagSignature = new Body.GitTagSignature();
            gitTagSignature.message = tag.message;
            gitTagSignature.messageString = tag.validatedMessageStringOrError();
            gitTagSignature.tag = tag.tag;
            gitTagSignature.tagger = tag.tagger;
            gitTagSignature.object = tag.object;
            gitTagSignature.type = tag.type;
            body.gitTag = gitTagSignature;
            return null;
        }
    });
    log.body = body;
    return log;
}
Also used : GitSignRequestBody(co.krypt.krypton.protocol.GitSignRequestBody) TagInfo(co.krypt.krypton.git.TagInfo) CommitInfo(co.krypt.krypton.git.CommitInfo) CryptoException(co.krypt.krypton.exception.CryptoException) GitSignRequestBody(co.krypt.krypton.protocol.GitSignRequestBody)

Example 14 with CryptoException

use of co.krypt.krypton.exception.CryptoException in project krypton-android by kryptco.

the class Silo method unpair.

public void unpair(Pairing pairing, boolean sendResponse) {
    if (sendResponse) {
        Response unpairResponse = new Response();
        unpairResponse.requestID = "";
        unpairResponse.unpairResponse = new UnpairResponse();
        try {
            send(pairing, unpairResponse);
        } catch (CryptoException | TransportException e) {
            e.printStackTrace();
        }
    }
    synchronized (pairingsLock) {
        pairingStorage.unpair(pairing);
        activePairingsByUUID.remove(pairing.uuid);
        SQSPoller poller = pollers.remove(pairing);
        if (poller != null) {
            poller.stop();
        }
        bluetoothTransport.remove(pairing);
    }
}
Also used : HostsResponse(co.krypt.krypton.protocol.HostsResponse) GitSignResponse(co.krypt.krypton.protocol.GitSignResponse) MeResponse(co.krypt.krypton.protocol.MeResponse) SignResponse(co.krypt.krypton.protocol.SignResponse) UnpairResponse(co.krypt.krypton.protocol.UnpairResponse) AckResponse(co.krypt.krypton.protocol.AckResponse) Response(co.krypt.krypton.protocol.Response) SQSPoller(co.krypt.krypton.transport.SQSPoller) CryptoException(co.krypt.krypton.exception.CryptoException) TransportException(co.krypt.krypton.exception.TransportException) UnpairResponse(co.krypt.krypton.protocol.UnpairResponse)

Example 15 with CryptoException

use of co.krypt.krypton.exception.CryptoException in project krypton-android by kryptco.

the class OnboardingVerifyEmailFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View rootView = inflater.inflate(R.layout.fragment_teams_onboarding_verify_email, container, false);
    Button cancelButton = rootView.findViewById(R.id.cancelButton);
    cancelButton.setOnClickListener(v -> {
        progress.reset();
        getActivity().finish();
    });
    ProgressBar progressBar = rootView.findViewById(R.id.progressBar);
    progressBar.setAlpha(0);
    Button changeButton = rootView.findViewById(R.id.changeButton);
    changeButton.setEnabled(false);
    Button resendButton = rootView.findViewById(R.id.resendButton);
    resendButton.setEnabled(false);
    ConstraintLayout checkYourEmailContainer = rootView.findViewById(R.id.checkYourEmailContainer);
    checkYourEmailContainer.setAlpha(0);
    AppCompatTextView teamName = rootView.findViewById(R.id.teamName);
    teamName.setText(progress.getTeamOnboardingData().name);
    emailEditText = rootView.findViewById(R.id.profileEmail);
    InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
    Runnable focusEmail = () -> {
        emailEditText.setEnabled(true);
        emailEditText.requestFocus();
        if (imm != null) {
            imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
        }
        progressBar.animate().alpha(0).setDuration(500).start();
    };
    focusEmail.run();
    Runnable requestEmailChallenge = () -> {
        emailEditText.setEnabled(false);
        emailEditText.clearFocus();
        if (imm != null) {
            imm.hideSoftInputFromWindow(emailEditText.getWindowToken(), 0);
        }
        progressBar.animate().alpha(1).setDuration(1000).start();
        final String email = emailEditText.getEditableText().toString();
        new Thread(() -> {
            MeStorage meStorage = Silo.shared(getContext()).meStorage();
            try {
                meStorage.setEmail(email);
            } catch (CryptoException e) {
                Error.shortToast(getContext(), "Failed to set email: " + e.getMessage());
                e.printStackTrace();
                return;
            }
            Profile me = meStorage.load();
            progress.updateTeamData((s, d) -> {
                if (s.equals(CreateStage.VERIFY_EMAIL) || s.equals(CreateStage.EMAIL_CHALLENGE_SENT)) {
                    d.creatorProfile = me;
                    Log.i(TAG, "requesting email challenge...");
                    try {
                        final Sigchain.NativeResult<JsonObject> result = TeamDataProvider.requestEmailChallenge(getContext(), email);
                        emailEditText.post(() -> {
                            if (result.success != null) {
                                Log.i(TAG, "request email challenge success");
                                progressBar.animate().alpha(0).setDuration(500).start();
                                checkYourEmailContainer.animate().alpha(1).setDuration(1000).start();
                                changeButton.setEnabled(true);
                                resendButton.setEnabled(true);
                            } else {
                                Log.i(TAG, "request email challenge failure: " + result.error);
                                Error.shortToast(getContext(), "Error sending email: " + result.error);
                                focusEmail.run();
                            }
                        });
                        if (result.success != null) {
                            return CreateStage.EMAIL_CHALLENGE_SENT;
                        } else {
                            return s;
                        }
                    } catch (Native.NotLinked notLinked) {
                        notLinked.printStackTrace();
                    }
                }
                return s;
            });
        }).start();
    };
    emailEditText.setOnEditorActionListener((v, i, ev) -> {
        requestEmailChallenge.run();
        return false;
    });
    emailEditText.setOnFocusChangeListener((view, b) -> {
        if (view.isEnabled() && !b) {
            requestEmailChallenge.run();
        }
    });
    resendButton.setOnClickListener(v -> {
        requestEmailChallenge.run();
    });
    changeButton.setOnClickListener(v -> {
        focusEmail.run();
    });
    Button submitButton = rootView.findViewById(R.id.submitButton);
    submitButton.setEnabled(false);
    submitButton.setAlpha(0);
    submitButton.setOnClickListener(v -> {
        FragmentManager fragmentManager = getFragmentManager();
        if (fragmentManager != null) {
            fragmentManager.beginTransaction().setCustomAnimations(R.anim.enter_from_right, R.anim.exit_to_left, R.anim.enter_from_right, R.anim.exit_to_left).replace(R.id.fragment_teams, new OnboardingLoadTeamFragment()).commitNowAllowingStateLoss();
        }
    });
    EventBus.getDefault().register(this);
    EventBus.getDefault().post(new IdentityService.GetProfile(getContext()));
    return rootView;
}
Also used : Sigchain(co.krypt.krypton.team.Sigchain) AppCompatTextView(android.support.v7.widget.AppCompatTextView) JsonObject(com.google.gson.JsonObject) InputMethodManager(android.view.inputmethod.InputMethodManager) View(android.view.View) AppCompatTextView(android.support.v7.widget.AppCompatTextView) Profile(co.krypt.krypton.protocol.Profile) ConstraintLayout(android.support.constraint.ConstraintLayout) Native(co.krypt.krypton.team.Native) FragmentManager(android.support.v4.app.FragmentManager) IdentityService(co.krypt.krypton.silo.IdentityService) Button(android.widget.Button) MeStorage(co.krypt.krypton.me.MeStorage) CryptoException(co.krypt.krypton.exception.CryptoException) ProgressBar(android.widget.ProgressBar)

Aggregations

CryptoException (co.krypt.krypton.exception.CryptoException)23 IOException (java.io.IOException)13 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)8 MeStorage (co.krypt.krypton.me.MeStorage)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 Sigchain (co.krypt.krypton.team.Sigchain)5 View (android.view.View)4 NoSuchProviderException (java.security.NoSuchProviderException)4 AppCompatTextView (android.support.v7.widget.AppCompatTextView)3 Button (android.widget.Button)3 Analytics (co.krypt.krypton.analytics.Analytics)3 SSHKeyPairI (co.krypt.krypton.crypto.SSHKeyPairI)3 KnownHost (co.krypt.krypton.knownhosts.KnownHost)3 Profile (co.krypt.krypton.protocol.Profile)3 InvalidKeyException (java.security.InvalidKeyException)3 KeyStore (java.security.KeyStore)3 KeyStoreException (java.security.KeyStoreException)3 CertificateException (java.security.cert.CertificateException)3 ArrayList (java.util.ArrayList)3 FragmentManager (android.support.v4.app.FragmentManager)2