Search in sources :

Example 6 with Profile

use of co.krypt.krypton.protocol.Profile in project krypton-android by kryptco.

the class TeamOnboardingActivity method onNewIntent.

@Override
protected void onNewIntent(Intent intent) {
    try {
        if (TeamDataProvider.getTeamHomeData(this).success != null) {
            Toast.makeText(getApplicationContext(), "You must leave your current team before joining another.", Toast.LENGTH_SHORT).show();
            startActivity(new Intent(getApplicationContext(), MainActivity.class));
            finish();
        }
    } catch (Native.NotLinked notLinked) {
        notLinked.printStackTrace();
        startActivity(new Intent(getApplicationContext(), MainActivity.class));
        finish();
        return;
    }
    if (intent.getAction() != null && intent.getAction().equals("android.intent.action.VIEW") && intent.getData() != null) {
        Uri data = intent.getData();
        if ((data.getScheme().equals("krypton") && data.getHost().equals("verify_email")) || (data.getScheme().equals("https") && data.getHost().equals("krypt.co") && data.getPath().equals("/app/verify_email.html"))) {
            final String nonce;
            // Handle https:// link
            String queryParam = data.getQueryParameter("nonce");
            if (queryParam != null) {
                nonce = queryParam;
            } else {
                // Handle krypton:// link
                nonce = data.getLastPathSegment();
            }
            Log.i(TAG, "received VERIFY_EMAIL intent");
            CreateTeamProgress createTeamProgress = new CreateTeamProgress(this);
            JoinTeamProgress joinTeamProgress = new JoinTeamProgress(this);
            if (createTeamProgress.inProgress()) {
                createTeamProgress.updateTeamData((s, d) -> {
                    d.emailChallengeNonce = nonce;
                    return CreateStage.LOAD_TEAM;
                });
                getSupportFragmentManager().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()).commitAllowingStateLoss();
            } else if (joinTeamProgress.inProgress()) {
                joinTeamProgress.updateTeamData((s, d) -> {
                    d.emailChallengeNonce = nonce;
                    if (s.equals(JoinStage.CHALLENGE_EMAIL_SENT)) {
                        return s;
                    } else if (s.equals(JoinStage.INPERSON_CHALLENGE_EMAIL_SENT)) {
                        return s;
                    } else if (s.equals(JoinStage.VERIFY_EMAIL)) {
                        // Allows clicking on an old verification link before sending a new challenge in case email is rate limited
                        return JoinStage.CHALLENGE_EMAIL_SENT;
                    }
                    return JoinStage.NONE;
                });
                getSupportFragmentManager().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, joinTeamProgress.currentStage().getFragment()).commitAllowingStateLoss();
            } else {
                Toast.makeText(getApplicationContext(), "Begin joining a team before verifying your email.", Toast.LENGTH_SHORT).show();
                startActivity(new Intent(getApplicationContext(), MainActivity.class));
                finish();
                return;
            }
        } else if (data.getScheme().equals("krypton") && data.getHost().equals("join_team")) {
            Log.i(TAG, "received JOIN_TEAM intent");
            new CreateTeamProgress(this).reset();
            JoinTeamProgress progress = new JoinTeamProgress(getApplicationContext());
            progress.updateTeamData((s, d) -> {
                try {
                    Sigchain.NativeResult<Sigchain.TeamHomeData> teamData = TeamDataProvider.getTeamHomeData(getApplicationContext());
                    if (s.equals(JoinStage.NONE)) {
                        s = JoinStage.DECRYPT_INVITE;
                        d.inviteLink = data.toString();
                    } else {
                    // continue current onboarding
                    }
                } catch (Native.NotLinked notLinked) {
                    notLinked.printStackTrace();
                    return s;
                }
                Profile me = Silo.shared(getBaseContext()).meStorage().load();
                if (me == null) {
                    Toast.makeText(getApplicationContext(), "Welcome to Krypton! Let's generate your key pair before joining the team.", Toast.LENGTH_LONG).show();
                    startActivity(new Intent(getApplicationContext(), MainActivity.class));
                    finish();
                    return s;
                }
                getSupportFragmentManager().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, s.getFragment()).commitAllowingStateLoss();
                return s;
            });
        }
    }
}
Also used : Context(android.content.Context) Rect(android.graphics.Rect) Bundle(android.os.Bundle) Uri(android.net.Uri) CreateStage(co.krypt.krypton.team.onboarding.create.CreateStage) Intent(android.content.Intent) Services(co.krypt.krypton.utils.Services) InputMethodManager(android.view.inputmethod.InputMethodManager) MotionEvent(android.view.MotionEvent) Toast(android.widget.Toast) View(android.view.View) JoinStage(co.krypt.krypton.team.onboarding.join.JoinStage) R(co.krypt.krypton.R) Native(co.krypt.krypton.team.Native) Log(android.util.Log) TeamDataProvider(co.krypt.krypton.team.TeamDataProvider) Fragment(android.support.v4.app.Fragment) Silo(co.krypt.krypton.silo.Silo) JoinTeamProgress(co.krypt.krypton.team.onboarding.join.JoinTeamProgress) OnboardingCreateFragment(co.krypt.krypton.team.onboarding.create.OnboardingCreateFragment) CrashReporting(co.krypt.krypton.utils.CrashReporting) Sigchain(co.krypt.krypton.team.Sigchain) FragmentActivity(android.support.v4.app.FragmentActivity) OnboardingLoadTeamFragment(co.krypt.krypton.team.onboarding.create.OnboardingLoadTeamFragment) CreateTeamProgress(co.krypt.krypton.team.onboarding.create.CreateTeamProgress) MainActivity(co.krypt.kryptonite.MainActivity) Profile(co.krypt.krypton.protocol.Profile) EditText(android.widget.EditText) Sigchain(co.krypt.krypton.team.Sigchain) JoinTeamProgress(co.krypt.krypton.team.onboarding.join.JoinTeamProgress) Intent(android.content.Intent) MainActivity(co.krypt.kryptonite.MainActivity) Uri(android.net.Uri) Profile(co.krypt.krypton.protocol.Profile) Native(co.krypt.krypton.team.Native) OnboardingLoadTeamFragment(co.krypt.krypton.team.onboarding.create.OnboardingLoadTeamFragment) CreateTeamProgress(co.krypt.krypton.team.onboarding.create.CreateTeamProgress)

Example 7 with Profile

use of co.krypt.krypton.protocol.Profile in project krypton-android by kryptco.

the class MeFragment method onEmailChanged.

private void onEmailChanged(String email) {
    Profile me = Silo.shared(getContext()).meStorage().load();
    if (me == null) {
        me = new Profile(email, null, null, null);
    }
    me.email = email;
    Silo.shared(getContext()).meStorage().set(me);
    new Analytics(getContext()).publishEmailToTeamsIfNeeded(email);
}
Also used : Profile(co.krypt.krypton.protocol.Profile) Analytics(co.krypt.krypton.analytics.Analytics)

Example 8 with Profile

use of co.krypt.krypton.protocol.Profile in project krypton-android by kryptco.

the class MeStorage method setEmail.

public void setEmail(String email) throws CryptoException {
    synchronized (lock) {
        if (!Email.verifyEmailPattern.matcher(email).matches()) {
            return;
        }
        Profile me = loadWithUserID(UserID.parse(" <" + email + ">"));
        if (me == null) {
            me = new Profile();
        }
        me.email = email;
        set(me);
    }
}
Also used : Profile(co.krypt.krypton.protocol.Profile)

Example 9 with Profile

use of co.krypt.krypton.protocol.Profile in project krypton-android by kryptco.

the class EnterEmailFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View root = inflater.inflate(R.layout.fragment_enter_email, container, false);
    nextButton = (Button) root.findViewById(R.id.nextButton);
    nextButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            next();
        }
    });
    profileEmail = (EditText) root.findViewById(R.id.profileEmail);
    profileEmail.setOnEditorActionListener(new TextView.OnEditorActionListener() {

        @Override
        public boolean onEditorAction(TextView v, int keyCode, KeyEvent event) {
            v.clearFocus();
            InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
            return false;
        }
    });
    profileEmail.addTextChangedListener(new TextWatcher() {

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            onEmailChanged();
        }
    });
    Profile me = new MeStorage(getContext()).load();
    if (me != null && me.email != null) {
        profileEmail.setText(me.email);
    } else {
        profileEmail.setText("");
    }
    return root;
}
Also used : InputMethodManager(android.view.inputmethod.InputMethodManager) TextView(android.widget.TextView) View(android.view.View) Profile(co.krypt.krypton.protocol.Profile) KeyEvent(android.view.KeyEvent) MeStorage(co.krypt.krypton.me.MeStorage) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) TextView(android.widget.TextView)

Example 10 with Profile

use of co.krypt.krypton.protocol.Profile in project krypton-android by kryptco.

the class GenerateFragment method next.

private void next() {
    KeyType keyType = null;
    if (keyTypeButton.getText().equals(getString(R.string.ed25519_key_type))) {
        keyType = KeyType.Ed25519;
    } else if (keyTypeButton.getText().equals(getString(R.string.rsa_key_type))) {
        keyType = KeyType.RSA;
    } else {
        keyType = KeyType.RSA;
    }
    final KeyType finalKeyType = keyType;
    final FragmentActivity context = getActivity();
    final OnboardingProgress progress = new OnboardingProgress(getContext());
    progress.setStage(OnboardingStage.GENERATING);
    new Analytics(context).postEvent("onboard", "generate tapped", null, null, false);
    final long startMillis = System.currentTimeMillis();
    final GeneratingFragment generatingFragment = new GeneratingFragment();
    getActivity().getSupportFragmentManager().beginTransaction().setCustomAnimations(R.anim.enter_from_right, R.anim.exit_to_left).replace(R.id.activity_onboarding, generatingFragment).commit();
    final Fragment self = this;
    new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                final long start = System.currentTimeMillis();
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                SSHKeyPairI pair = KeyManager.loadOrGenerateKeyPair(context, finalKeyType, KeyManager.ME_TAG);
                new MeStorage(context).set(new Profile("", pair.publicKeySSHWireFormat(), null, null));
                final long genTime = System.currentTimeMillis() - start;
                new Analytics(context).postEvent("keypair", "generate", null, (int) (genTime / 1000), false);
                if (genTime < 5000) {
                    try {
                        Thread.sleep(5000 - genTime);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                generatingFragment.onGenerate();
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                progress.setStage(OnboardingStage.ENTER_EMAIL);
                EnterEmailFragment enterEmailFragment = new EnterEmailFragment();
                final FragmentActivity activity = context;
                if (activity != null && !activity.isDestroyed() && !activity.isFinishing()) {
                    activity.getSupportFragmentManager().beginTransaction().setCustomAnimations(R.anim.enter_from_right, R.anim.exit_to_left).hide(generatingFragment).add(R.id.activity_onboarding, enterEmailFragment).show(enterEmailFragment).commitAllowingStateLoss();
                }
            } catch (InvalidKeyException | IOException | CryptoException | UnsupportedOperationException | IllegalArgumentException e) {
                e.printStackTrace();
                progress.reset();
                final FragmentActivity activity = context;
                if (activity != null && !activity.isDestroyed() && !activity.isFinishing()) {
                    GenerateFragment generateFragment = new GenerateFragment();
                    if (finalKeyType == KeyType.RSA) {
                        Bundle args = new Bundle();
                        args.putString(DEFAULT_KEY_TYPE_KEY, activity.getString(R.string.ed25519_key_type));
                        generateFragment.setArguments(args);
                        activity.runOnUiThread(new Runnable() {

                            @Override
                            public void run() {
                                Toast.makeText(activity, "Error generating rsa key, try again to generate an ed25519 key.", Toast.LENGTH_LONG).show();
                            }
                        });
                    }
                    activity.getSupportFragmentManager().beginTransaction().setCustomAnimations(R.anim.enter_from_right, R.anim.exit_to_left).replace(R.id.activity_onboarding, generateFragment).commitAllowingStateLoss();
                }
            }
        }
    }).start();
}
Also used : KeyType(co.krypt.krypton.crypto.KeyType) Bundle(android.os.Bundle) SSHKeyPairI(co.krypt.krypton.crypto.SSHKeyPairI) IOException(java.io.IOException) InvalidKeyException(java.security.InvalidKeyException) Fragment(android.support.v4.app.Fragment) Analytics(co.krypt.krypton.analytics.Analytics) Profile(co.krypt.krypton.protocol.Profile) FragmentActivity(android.support.v4.app.FragmentActivity) MeStorage(co.krypt.krypton.me.MeStorage) CryptoException(co.krypt.krypton.exception.CryptoException)

Aggregations

Profile (co.krypt.krypton.protocol.Profile)10 View (android.view.View)5 MeStorage (co.krypt.krypton.me.MeStorage)5 InputMethodManager (android.view.inputmethod.InputMethodManager)4 CryptoException (co.krypt.krypton.exception.CryptoException)4 Native (co.krypt.krypton.team.Native)4 Sigchain (co.krypt.krypton.team.Sigchain)4 Intent (android.content.Intent)2 Bundle (android.os.Bundle)2 Fragment (android.support.v4.app.Fragment)2 FragmentActivity (android.support.v4.app.FragmentActivity)2 AppCompatTextView (android.support.v7.widget.AppCompatTextView)2 Editable (android.text.Editable)2 TextWatcher (android.text.TextWatcher)2 Button (android.widget.Button)2 ProgressBar (android.widget.ProgressBar)2 Analytics (co.krypt.krypton.analytics.Analytics)2 SSHKeyPairI (co.krypt.krypton.crypto.SSHKeyPairI)2 JsonObject (com.google.gson.JsonObject)2 Context (android.content.Context)1