Search in sources :

Example 6 with CryptoException

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

the class EnterEmailFragment method next.

private void next() {
    Analytics analytics = new Analytics(getContext());
    String email = profileEmail.getText().toString();
    if (email == null || email.trim().equals("")) {
        analytics.postEvent("email", "skipped", null, null, false);
        email = Build.MODEL;
    } else {
        analytics.postEvent("email", "typed", null, null, false);
        email = email.trim();
    }
    analytics.publishEmailToTeamsIfNeeded(email);
    try {
        new MeStorage(getContext()).setEmail(email);
    } catch (CryptoException e) {
        e.printStackTrace();
        Error.shortToast(getContext(), "Failed to set email: " + e.getMessage());
        return;
    }
    final OnboardingProgress progress = new OnboardingProgress(getContext());
    progress.setStage(OnboardingStage.FIRST_PAIR);
    FirstPairFragment firstPairFragment = new FirstPairFragment();
    FragmentTransaction fragmentTransaction = getActivity().getSupportFragmentManager().beginTransaction();
    fragmentTransaction.setCustomAnimations(R.anim.enter_from_right, R.anim.exit_to_left).add(R.id.activity_onboarding, firstPairFragment).hide(this).show(firstPairFragment).commit();
}
Also used : FragmentTransaction(android.support.v4.app.FragmentTransaction) MeStorage(co.krypt.krypton.me.MeStorage) CryptoException(co.krypt.krypton.exception.CryptoException) Analytics(co.krypt.krypton.analytics.Analytics)

Example 7 with CryptoException

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

the class RSAKeyManager method keyExists.

public boolean keyExists(String tag) throws CryptoException {
    synchronized (lock) {
        try {
            KeyStore keyStore = KeyStore.getInstance("AndroidKeyStore");
            keyStore.load(null);
            KeyStore.Entry privateKeyEntry = keyStore.getEntry(tag, null);
            if (privateKeyEntry instanceof KeyStore.PrivateKeyEntry) {
                return true;
            }
        } catch (CertificateException e) {
            throw new CryptoException(e.getMessage());
        } catch (IOException e) {
            throw new CryptoException(e.getMessage());
        } catch (KeyStoreException e) {
            throw new CryptoException(e.getMessage());
        } catch (NoSuchAlgorithmException e) {
            throw new CryptoException(e.getMessage());
        } catch (ProviderException e) {
            throw new CryptoException(e.getMessage());
        } catch (UnrecoverableEntryException e) {
            throw new CryptoException(e.getMessage());
        } catch (UnsupportedOperationException e) {
            throw new CryptoException(e.getMessage());
        }
        return false;
    }
}
Also used : ProviderException(java.security.ProviderException) NoSuchProviderException(java.security.NoSuchProviderException) UnrecoverableEntryException(java.security.UnrecoverableEntryException) CertificateException(java.security.cert.CertificateException) IOException(java.io.IOException) KeyStoreException(java.security.KeyStoreException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) CryptoException(co.krypt.krypton.exception.CryptoException) KeyStore(java.security.KeyStore)

Example 8 with CryptoException

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

the class RSAKeyManager method deleteKeyPair.

public void deleteKeyPair(String tag) throws CryptoException {
    try {
        synchronized (lock) {
            KeyStore keyStore = KeyStore.getInstance("AndroidKeyStore");
            keyStore.load(null);
            keyStore.deleteEntry(tag);
        }
    } catch (CertificateException | NoSuchAlgorithmException | IOException | KeyStoreException e) {
        e.printStackTrace();
        throw new CryptoException(e);
    }
}
Also used : CertificateException(java.security.cert.CertificateException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IOException(java.io.IOException) KeyStoreException(java.security.KeyStoreException) CryptoException(co.krypt.krypton.exception.CryptoException) KeyStore(java.security.KeyStore)

Example 9 with CryptoException

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

the class RSAKeyManager method loadOrGenerateKeyPair.

public SSHKeyPairI loadOrGenerateKeyPair(String tag) throws CryptoException {
    synchronized (lock) {
        try {
            Long created;
            if (preferences.contains(SSH_KEYPAIR_CREATED_KEY + "." + tag)) {
                created = preferences.getLong(SSH_KEYPAIR_CREATED_KEY + "." + tag, 0);
            } else {
                created = PGPPublicKey.currentTimeBackdatedByClockSkewTolerance();
                preferences.edit().putLong(SSH_KEYPAIR_CREATED_KEY + "." + tag, created).apply();
            }
            KeyStore keyStore = KeyStore.getInstance("AndroidKeyStore");
            keyStore.load(null);
            KeyStore.Entry privateKeyEntry;
            try {
                // Exception java.lang.NullPointerException: chain == null
                // java.security.KeyStore$PrivateKeyEntry.<init> (KeyStore.java:1206)
                // java.security.KeyStoreSpi.engineGetEntry (KeyStoreSpi.java:374)
                // java.security.KeyStore.getEntry (KeyStore.java:645)
                // co.krypt.krypton.crypto.RSAKeyManager.loadOrGenerateKeyPair (RSAKeyManager.java:58)
                // co.krypt.krypton.crypto.KeyManager.loadOrGenerateKeyPair (KeyManager.java:16)
                // co.krypt.krypton.onboarding.GenerateFragment$3.run (GenerateFragment.java:105)
                // java.lang.Thread.run (Thread.java:818)
                privateKeyEntry = keyStore.getEntry(tag, null);
            } catch (NullPointerException npe) {
                throw new CryptoException(npe.getMessage());
            }
            if (privateKeyEntry instanceof KeyStore.PrivateKeyEntry) {
                return new RSASSHKeyPair(new KeyPair(((KeyStore.PrivateKeyEntry) privateKeyEntry).getCertificate().getPublicKey(), ((KeyStore.PrivateKeyEntry) privateKeyEntry).getPrivateKey()), created);
            } else {
                Log.w(LOG_TAG, "Not an instance of a PrivateKeyEntry");
            }
            KeyPair keyPair = null;
            KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance(KeyProperties.KEY_ALGORITHM_RSA, "AndroidKeyStore");
            keyPairGenerator.initialize(new KeyGenParameterSpec.Builder(tag, KeyProperties.PURPOSE_SIGN).setDigests(KeyProperties.DIGEST_SHA1, KeyProperties.DIGEST_SHA256, KeyProperties.DIGEST_SHA512).setSignaturePaddings(KeyProperties.SIGNATURE_PADDING_RSA_PKCS1).setKeySize(3072).setUserAuthenticationRequired(false).build());
            long genStart = System.currentTimeMillis();
            keyPair = keyPairGenerator.generateKeyPair();
            long genStop = System.currentTimeMillis();
            Log.i(LOG_TAG, "KeyGen took " + String.valueOf((genStop - genStart)));
            return new RSASSHKeyPair(keyPair, created);
        } catch (CertificateException | UnsupportedOperationException | UnrecoverableEntryException | ProviderException | NoSuchProviderException | NoSuchAlgorithmException | KeyStoreException | IOException | InvalidAlgorithmParameterException e) {
            throw new CryptoException(e.getMessage());
        }
    }
}
Also used : KeyPair(java.security.KeyPair) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) ProviderException(java.security.ProviderException) NoSuchProviderException(java.security.NoSuchProviderException) CertificateException(java.security.cert.CertificateException) KeyPairGenerator(java.security.KeyPairGenerator) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) KeyStoreException(java.security.KeyStoreException) IOException(java.io.IOException) KeyStore(java.security.KeyStore) UnrecoverableEntryException(java.security.UnrecoverableEntryException) CryptoException(co.krypt.krypton.exception.CryptoException) NoSuchProviderException(java.security.NoSuchProviderException)

Example 10 with CryptoException

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

the class OnboardingPinHostsFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View rootView = inflater.inflate(R.layout.fragment_teams_onboarding_pinhosts, container, false);
    RecyclerView knownHostsView = rootView.findViewById(R.id.pinnedHostsList);
    knownHostsView.setLayoutManager(new LinearLayoutManager(getContext()));
    knownHostsView.setAdapter(adapter);
    Button nextButton = rootView.findViewById(R.id.nextButton);
    nextButton.setOnClickListener(v -> {
        ArrayList<Sigchain.PinnedHost> selectedHosts = new ArrayList<>();
        List<Pair<KnownHost, AtomicBoolean>> hosts = adapter.getKnownHosts();
        for (Pair<KnownHost, AtomicBoolean> pair : hosts) {
            if (pair.second.get()) {
                try {
                    selectedHosts.add(new Sigchain.PinnedHost(pair.first.hostName, Base64.decode(pair.first.publicKey)));
                } catch (CryptoException e) {
                    e.printStackTrace();
                    FirebaseCrash.report(e);
                }
            }
        }
        CreateTeamProgress progress = new CreateTeamProgress(v.getContext());
        progress.updateTeamData((s, d) -> {
            d.pinnedHosts = selectedHosts.toArray(new Sigchain.PinnedHost[0]);
            return CreateStage.VERIFY_EMAIL;
        });
        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 OnboardingVerifyEmailFragment()).commitNowAllowingStateLoss();
        }
    });
    selectedHostsCountText = rootView.findViewById(R.id.selectedTextView);
    toggleAllButton = rootView.findViewById(R.id.selectAllButton);
    updateUI(adapter.getKnownHosts());
    return rootView;
}
Also used : Sigchain(co.krypt.krypton.team.Sigchain) ArrayList(java.util.ArrayList) KnownHost(co.krypt.krypton.knownhosts.KnownHost) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) View(android.view.View) AppCompatTextView(android.support.v7.widget.AppCompatTextView) RecyclerView(android.support.v7.widget.RecyclerView) FragmentManager(android.support.v4.app.FragmentManager) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AppCompatButton(android.support.v7.widget.AppCompatButton) Button(android.widget.Button) RecyclerView(android.support.v7.widget.RecyclerView) CryptoException(co.krypt.krypton.exception.CryptoException) Pair(android.util.Pair)

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