Search in sources :

Example 21 with CryptoException

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

the class EdSSHKeyPair method signDigestAppendingPubkey.

@Override
public byte[] signDigestAppendingPubkey(byte[] data, String algo) throws CryptoException {
    try {
        ByteArrayOutputStream dataWithPubkey = new ByteArrayOutputStream();
        dataWithPubkey.write(data);
        dataWithPubkey.write(SSHWire.encode(publicKeySSHWireFormat()));
        byte[] signaturePayload = dataWithPubkey.toByteArray();
        return signDigest(signaturePayload);
    } catch (IOException | SignatureException | InvalidKeyException e) {
        e.printStackTrace();
        throw new CryptoException(e);
    }
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) SignatureException(java.security.SignatureException) InvalidKeyException(java.security.InvalidKeyException) CryptoException(co.krypt.krypton.exception.CryptoException)

Example 22 with CryptoException

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

the class RSAKeyManager method loadOrGenerateNoDigestKeyPair.

/*
    For backwards compatibility testing
     */
@Deprecated
public SSHKeyPairI loadOrGenerateNoDigestKeyPair(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 new RSASSHKeyPair(new KeyPair(((KeyStore.PrivateKeyEntry) privateKeyEntry).getCertificate().getPublicKey(), ((KeyStore.PrivateKeyEntry) privateKeyEntry).getPrivateKey()), 0);
            } 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_NONE).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, 0);
        } catch (CertificateException e) {
            throw new CryptoException(e.getMessage());
        } catch (InvalidAlgorithmParameterException 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 (NoSuchProviderException 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());
        }
    }
}
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) IOException(java.io.IOException) KeyStoreException(java.security.KeyStoreException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) KeyStore(java.security.KeyStore) UnrecoverableEntryException(java.security.UnrecoverableEntryException) CryptoException(co.krypt.krypton.exception.CryptoException) NoSuchProviderException(java.security.NoSuchProviderException)

Example 23 with CryptoException

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

the class Pairing method seal.

public byte[] seal(byte[] message) throws CryptoException {
    byte[] nonce = SecureRandom.getSeed(Sodium.crypto_box_noncebytes());
    byte[] sealed = new byte[message.length + Sodium.crypto_box_macbytes()];
    if (0 != Sodium.crypto_box_easy(sealed, message, message.length, nonce, workstationPublicKey, enclaveSecretKey)) {
        throw new SodiumException("crypto_box_easy failed");
    }
    ByteArrayOutputStream nonceAndSealed = new ByteArrayOutputStream();
    try {
        nonceAndSealed.write(nonce);
        nonceAndSealed.write(sealed);
    } catch (IOException e) {
        throw new CryptoException(e.getMessage());
    }
    return nonceAndSealed.toByteArray();
}
Also used : SodiumException(co.krypt.krypton.exception.SodiumException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) CryptoException(co.krypt.krypton.exception.CryptoException)

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