at_client_sdk icon indicating copy to clipboard operation
at_client_sdk copied to clipboard

Synchronisation error - Invalid or corrupted pad block

Open ralfeus opened this issue 2 years ago • 1 comments

Describe the bug

Sometimes after key creation the synchronisation fails with following error:

I/flutter (30031): SEVERE|2022-10-11 02:54:02.704061|EncryptionUtil|Error while decrypting value: Invalid argument(s): Invalid or corrupted pad block
I/flutter (30031): SEVERE|2022-10-11 02:54:02.708559|NotificationServiceImpl|Failed to decryptData caused by
I/flutter (30031): Failed to decrypt @baboon9blue:@baboon9blue:shared_key@81bored7@81bored7 caused by
I/flutter (30031): Invalid argument(s): Invalid or corrupted pad block

No further indication of the error

Steps to reproduce

  1. Create a key and put it to local storage
  2. Have keys synchronized

Expected behavior

Keys are synchronised as they are

Screenshots

No response

Smartphones

  • Device: Emulator
  • OS: Android

Were you using an atApplication when the bug was found?

None

Additional context

No response

ralfeus avatar Oct 12 '22 05:10 ralfeus

Root cause of the issue:

On the sender side, a sharedKey (AES key) is generated and is encrypted with the receiver's public key and the resultant which is encryptedSharedKey is notified to the receiver's atsign. On the receiver side, when a notification related to sharedKey arrives, it is treated a SharedKey and SharedKeyDecryption is performed; which means the encryptedSharedKey is decrypted with the original sharedKey which leads to the corrupted pad block error.

Below is the screenshot which show the encryptedValue and the encryptedSharedKey has a same value.

image

sitaram-kalluri avatar Oct 18 '22 14:10 sitaram-kalluri

The issue is fixed and changes are merged to trunk branch

sitaram-kalluri avatar Oct 26 '22 04:10 sitaram-kalluri

The changes are published in v3.0.42. Hence marking the issue as fixed.

sitaram-kalluri avatar Oct 28 '22 06:10 sitaram-kalluri

Thanks @kalluriramkumar ... did you look into why the error message says Failed to decrypt @baboon9blue:@baboon9blue:shared_key@81bored7@81bored7 instead of Failed to decrypt @baboon9blue:shared_key@81bored7 ?

gkc avatar Oct 31 '22 02:10 gkc

Thanks @kalluriramkumar ... did you look into why the error message says Failed to decrypt @baboon9blue:@baboon9blue:shared_key@81bored7@81bored7 instead of Failed to decrypt @baboon9blue:shared_key@81bored7 ?

Yes, @gkc. In the update_verb_handler.dart, we prefix and append the sharedWith and sharedBy to the key before sending the notification. So, the key in the notification looks like "@‎bob:phone@alice"; when logging the key, we have an atKey.toString which will again add sharedWith and sharedBy to the key. Hence the atsign's are shown twice.

sitaram-kalluri avatar Oct 31 '22 02:10 sitaram-kalluri

Great - have you created a ticket to track fixing that bug?

gkc avatar Oct 31 '22 02:10 gkc

Great - have you created a ticket to track fixing that bug?

I remember seeing a similar bug. I will go through the bugs list. If there is no issue, will create one and update the git issue here.

sitaram-kalluri avatar Oct 31 '22 03:10 sitaram-kalluri

Thanks @kalluriramkumar ... did you look into why the error message says Failed to decrypt @baboon9blue:@baboon9blue:shared_key@81bored7@81bored7 instead of Failed to decrypt @baboon9blue:shared_key@81bored7 ?

Created a git issue to the bug: https://github.com/atsign-foundation/at_client_sdk/issues/772

sitaram-kalluri avatar Oct 31 '22 03:10 sitaram-kalluri

Closing this ticket as fixed. There is another issue with decryption reported by @ralfeus which I will be looking into this week

gkc avatar Feb 20 '23 13:02 gkc