kovmarci86 / android-secure-preferences

Secure AES Encryiption decorated Android SharedPreferences implementation.
38 stars 16 forks source link

crash during decoding #10

Open tprochazka opened 11 years ago

tprochazka commented 11 years ago

I have now found this crash in my app

java.lang.ArrayIndexOutOfBoundsException: src.length=16 srcPos=0 dst.length=32 dstPos=32 length=5
            at java.lang.System.arraycopy(Native Method)
            at com.android.org.bouncycastle.crypto.paddings.PaddedBufferedBlockCipher.doFinal(PaddedBufferedBlockCipher.java:288)
            at com.android.org.bouncycastle.jce.provider.JCEBlockCipher$BufferedGenericBlockCipher.doFinal(JCEBlockCipher.java:1045)
            at com.android.org.bouncycastle.jce.provider.JCEBlockCipher.engineDoFinal(JCEBlockCipher.java:693)
            at javax.crypto.Cipher.doFinal(Cipher.java:1111)
            at edu.gmu.tec.scout.utilities.Encryption.decrypt(Encryption.java:94)
            at com.github.kovmarci86.android.secure.preferences.encryption.EncryptionHelper.createDecodedObjectStream(EncryptionHelper.java:101)
            at com.github.kovmarci86.android.secure.preferences.encryption.EncryptionHelper.readDecoded(EncryptionHelper.java:88)
            at com.github.kovmarci86.android.secure.preferences.encryption.EncryptionHelper.readAndDecodeTemplate(EncryptionHelper.java:44)
            at com.github.kovmarci86.android.secure.preferences.SecureSharedPreferences.getString(SecureSharedPreferences.java:74)
            at cz.idc.letenky.service.AppSettingsService.getUserLogin(AppSettingsService.java:50)
            at cz.idc.letenky.service.AppSettingsService.isUserLoggedIn(AppSettingsService.java:46)

Maybe encrypted data was corrupted accidently and now is not possible decrypt them, but it should by handled and better would be return default value in this situation than app crash. And log error to the logcat.

tprochazka commented 11 years ago

So data is not corrupted, if I run application again everything works correctly. It was only some accidental problem, but try ... catch should help.

tprochazka commented 10 years ago

And another accident crash

java.lang.RuntimeException: error:0606506D:digital envelope routines:EVP_DecryptFinal_ex:wrong final block length
            at org.apache.harmony.xnet.provider.jsse.NativeCrypto.EVP_CipherFinal_ex(Native Method)
            at org.apache.harmony.xnet.provider.jsse.OpenSSLCipher.doFinalInternal(OpenSSLCipher.java:398)
            at org.apache.harmony.xnet.provider.jsse.OpenSSLCipher.engineDoFinal(OpenSSLCipher.java:434)
            at javax.crypto.Cipher.doFinal(Cipher.java:1111)
            at edu.gmu.tec.scout.utilities.Encryption.decrypt(Encryption.java:94)
            at com.github.kovmarci86.android.secure.preferences.encryption.EncryptionHelper.createDecodedObjectStream(EncryptionHelper.java:101)
            at com.github.kovmarci86.android.secure.preferences.encryption.EncryptionHelper.readDecoded(EncryptionHelper.java:88)
            at com.github.kovmarci86.android.secure.preferences.encryption.EncryptionHelper.readAndDecodeTemplate(EncryptionHelper.java:44)
            at com.github.kovmarci86.android.secure.preferences.SecureSharedPreferences.getString(SecureSharedPreferences.java:74)
DanielNovak commented 10 years ago

Here is another one, crashed during getting a string

Unhandled exception java.lang.RuntimeException: error:0607B083:digital envelope routines:EVP_CipherInit_ex:no cipher set
java.lang.RuntimeException: error:0607B083:digital envelope routines:EVP_CipherInit_ex:no cipher set
        at com.android.org.conscrypt.NativeCrypto.EVP_CipherInit_ex(Native Method)
        at com.android.org.conscrypt.OpenSSLCipher.reset(OpenSSLCipher.java:391)
        at com.android.org.conscrypt.OpenSSLCipher.doFinalInternal(OpenSSLCipher.java:434)
        at com.android.org.conscrypt.OpenSSLCipher.engineDoFinal(OpenSSLCipher.java:456)
        at javax.crypto.Cipher.doFinal(Cipher.java:1204)
        at edu.gmu.tec.scout.utilities.Encryption.decrypt(Encryption.java:94)
        at com.github.kovmarci86.android.secure.preferences.encryption.EncryptionHelper.createDecodedObjectStream(EncryptionHelper.java:101)
        at com.github.kovmarci86.android.secure.preferences.encryption.EncryptionHelper.readDecoded(EncryptionHelper.java:88)
        at com.github.kovmarci86.android.secure.preferences.encryption.EncryptionHelper.readAndDecodeTemplate(EncryptionHelper.java:44)
        at com.github.kovmarci86.android.secure.preferences.SecureSharedPreferences.getString(SecureSharedPreferences.java:74)
tprochazka commented 10 years ago

I think the problem is that encoding/decoding are not thread safe.

tprochazka commented 9 years ago

I fixed it here https://github.com/tprochazka/android-secure-preferences/commit/fb073e8c61c0a78d3afece4e4731fbd23bfccec0

This small changes fixed all the problems. Now I'm using my fork on several project without any problems.