use of co.krypt.krypton.crypto.KeyType in project krypton-android by kryptco.
the class KeyManagerInstrumentedTest method keyGenerationAndDeletion_succeed.
@Test
public void keyGenerationAndDeletion_succeed() throws Exception {
final Context context = InstrumentationRegistry.getTargetContext();
for (KeyType type : SUPPORTED_KEY_TYPES) {
KeyManager.deleteKeyPair(context, type, "test");
SSHKeyPairI kp1 = KeyManager.loadOrGenerateKeyPair(InstrumentationRegistry.getTargetContext(), type, "test");
Log.i("TEST", kp1.publicKeyDERBase64());
KeyManager.deleteKeyPair(context, type, "test");
}
}
use of co.krypt.krypton.crypto.KeyType 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();
}
use of co.krypt.krypton.crypto.KeyType in project krypton-android by kryptco.
the class KeyManagerInstrumentedTest method keyGeneration_isIdempotent.
@Test
public void keyGeneration_isIdempotent() throws Exception {
final Context context = InstrumentationRegistry.getTargetContext();
for (KeyType type : SUPPORTED_KEY_TYPES) {
SSHKeyPairI key1 = KeyManager.loadOrGenerateKeyPair(context, type, "test");
SSHKeyPairI key2 = KeyManager.loadOrGenerateKeyPair(context, type, "test");
assertEquals(key1, key2);
}
}
use of co.krypt.krypton.crypto.KeyType in project krypton-android by kryptco.
the class KeyManagerInstrumentedTest method signTamperAndVerify_fails.
@Test
public void signTamperAndVerify_fails() throws Exception {
final Context context = InstrumentationRegistry.getTargetContext();
for (KeyType type : SUPPORTED_KEY_TYPES) {
for (SSHKeyPairI key : new SSHKeyPairI[] { KeyManager.loadOrGenerateKeyPair(context, type, "test"), new RSAKeyManager(context).loadOrGenerateNoDigestKeyPair("testnodigest") }) {
byte[] data = SecureRandom.getSeed(32);
for (String digest : SUPPORTED_DIGESTS) {
byte[] signature = key.signDigest(digest, data);
signature[signature.length - 1] ^= 0x01;
assertTrue(!key.verifyDigest(digest, signature, data));
}
}
}
}
use of co.krypt.krypton.crypto.KeyType in project krypton-android by kryptco.
the class KeyManagerInstrumentedTest method signAndVerify_succeed.
@Test
public void signAndVerify_succeed() throws Exception {
final Context context = InstrumentationRegistry.getTargetContext();
for (KeyType type : SUPPORTED_KEY_TYPES) {
for (SSHKeyPairI key : new SSHKeyPairI[] { KeyManager.loadOrGenerateKeyPair(context, type, "test"), new RSAKeyManager(context).loadOrGenerateNoDigestKeyPair("testnodigest") }) {
byte[] data = SecureRandom.getSeed(32);
for (String digest : SUPPORTED_DIGESTS) {
byte[] signature = key.signDigest(digest, data);
assertTrue(key.verifyDigest(digest, signature, data));
}
}
}
}
Aggregations