Search in sources :

Example 6 with SSHKeyPairI

use of co.krypt.krypton.crypto.SSHKeyPairI 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);
    }
}
Also used : Context(android.content.Context) KeyType(co.krypt.krypton.crypto.KeyType) SSHKeyPairI(co.krypt.krypton.crypto.SSHKeyPairI) Test(org.junit.Test)

Example 7 with SSHKeyPairI

use of co.krypt.krypton.crypto.SSHKeyPairI 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));
            }
        }
    }
}
Also used : Context(android.content.Context) KeyType(co.krypt.krypton.crypto.KeyType) SSHKeyPairI(co.krypt.krypton.crypto.SSHKeyPairI) RSAKeyManager(co.krypt.krypton.crypto.RSAKeyManager) Test(org.junit.Test)

Example 8 with SSHKeyPairI

use of co.krypt.krypton.crypto.SSHKeyPairI 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));
            }
        }
    }
}
Also used : Context(android.content.Context) KeyType(co.krypt.krypton.crypto.KeyType) SSHKeyPairI(co.krypt.krypton.crypto.SSHKeyPairI) RSAKeyManager(co.krypt.krypton.crypto.RSAKeyManager) Test(org.junit.Test)

Example 9 with SSHKeyPairI

use of co.krypt.krypton.crypto.SSHKeyPairI in project krypton-android by kryptco.

the class PGPublicKeySelfCertificationTest method keySigning_succeeds.

@Test
public void keySigning_succeeds() throws Exception {
    for (KeyType keyType : new KeyType[] { KeyType.RSA, KeyType.Ed25519 }) {
        SSHKeyPairI kp1 = KeyManager.loadOrGenerateKeyPair(InstrumentationRegistry.getTargetContext(), keyType, "test");
        PGPPublicKey pubkey = new PGPPublicKey(kp1, Collections.singletonList(new UserID("Kevin King", "kevin@krypt.co")));
        CertifiedPublicKey parsedPubkey = CertifiedPublicKey.parse(new DataInputStream(new ByteArrayInputStream(pubkey.serializedBytes())));
        Assert.assertTrue(pubkey.signedIdentities.size() == parsedPubkey.identities.size());
        Assert.assertFalse(pubkey.signedIdentities.get(0).signature.attributes.attributes.unhashedSubpackets.issuer.header.type.critical);
    }
}
Also used : KeyType(co.krypt.krypton.crypto.KeyType) ByteArrayInputStream(java.io.ByteArrayInputStream) UserID(co.krypt.krypton.pgp.UserID) CertifiedPublicKey(co.krypt.krypton.pgp.publickey.CertifiedPublicKey) SSHKeyPairI(co.krypt.krypton.crypto.SSHKeyPairI) PGPPublicKey(co.krypt.krypton.pgp.PGPPublicKey) DataInputStream(java.io.DataInputStream) Test(org.junit.Test)

Aggregations

SSHKeyPairI (co.krypt.krypton.crypto.SSHKeyPairI)9 KeyType (co.krypt.krypton.crypto.KeyType)6 Test (org.junit.Test)6 Context (android.content.Context)4 UserID (co.krypt.krypton.pgp.UserID)4 CryptoException (co.krypt.krypton.exception.CryptoException)3 PGPPublicKey (co.krypt.krypton.pgp.PGPPublicKey)3 IOException (java.io.IOException)3 Analytics (co.krypt.krypton.analytics.Analytics)2 RSAKeyManager (co.krypt.krypton.crypto.RSAKeyManager)2 MeStorage (co.krypt.krypton.me.MeStorage)2 Profile (co.krypt.krypton.protocol.Profile)2 Intent (android.content.Intent)1 Bundle (android.os.Bundle)1 Fragment (android.support.v4.app.Fragment)1 FragmentActivity (android.support.v4.app.FragmentActivity)1 Log (android.util.Log)1 RSASSHKeyPair (co.krypt.krypton.crypto.RSASSHKeyPair)1 MismatchedHostKeyException (co.krypt.krypton.exception.MismatchedHostKeyException)1 ProtocolException (co.krypt.krypton.exception.ProtocolException)1