powered by Jive Software

Smack 4.4.3: OMEMO media sharing has problem when upgraded to use smack-4.4.3-alpha3

aTalk implements omemo media sharing based on source from the smack pull request. The feature was working well when it is using smack-4.4.3-alpha2. However when aTalk upgrades to use smack-4.4.0-alpha3, it throws the following exception.

The problem only shows up on Note-5 (API-21); it is working fine on Note-10 (API-28).
What can be the cause and how to resolve it?
Any help/advice is much appreciated.

New update: If HttpFileUploadManager#uploadFile() is made to catch and ignore the IllegalStateException, then the file send has no problem. Also there is no problem in sending unencrypted file.

========= aTalk omemo media sharing exception on Note-5 (API-21) ===========
10-31 14:49:12.707 2344-2344/org.atalk.android E/(ChatFragment.java:2222)#onPostExecute: Failed to send file.
    java.lang.IllegalStateException: GCM cipher cannot be reused for encryption
        at org.bouncycastle.crypto.modes.GCMBlockCipher.checkStatus(Unknown Source)
        at org.bouncycastle.crypto.modes.GCMBlockCipher.doFinal(Unknown Source)
        at org.bouncycastle.jcajce.provider.symmetric.util.BaseBlockCipher$AEADGenericBlockCipher.doFinal(Unknown Source)
        at org.bouncycastle.jcajce.provider.symmetric.util.BaseBlockCipher.engineDoFinal(Unknown Source)
        at javax.crypto.Cipher.doFinal(Cipher.java:1278)
        at javax.crypto.CipherInputStream.close(CipherInputStream.java:190)
        at java.io.BufferedInputStream.close(BufferedInputStream.java:141)
        at org.jivesoftware.smackx.httpfileupload.HttpFileUploadManager.uploadFile(HttpFileUploadManager.java:526)
        at org.jivesoftware.smackx.httpfileupload.HttpFileUploadManager.uploadFileEncrypted(HttpFileUploadManager.java:342)
        at org.atalk.android.gui.chat.MetaContactChatTransport.httpFileUpload(MetaContactChatTransport.java:658)
        at org.atalk.android.gui.chat.MetaContactChatTransport.sendFile(MetaContactChatTransport.java:632)
        at org.atalk.android.gui.chat.MetaContactChatTransport.sendFile(MetaContactChatTransport.java:591)
        at org.atalk.android.gui.chat.ChatFragment$SendFile.doInBackground(ChatFragment.java:2182)
        at org.atalk.android.gui.chat.ChatFragment$SendFile.doInBackground(ChatFragment.java:2126)
        at android.os.AsyncTask$2.call(AsyncTask.java:288)
        at java.util.concurrent.FutureTask.run(FutureTask.java:237)
        at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
        at java.lang.Thread.run(Thread.java:818)