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();
}
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;
}
}
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);
}
}
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());
}
}
}
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;
}
Aggregations