jerson / flutter-rsa

RSA for flutter made with golang for fast performance with support for android, ios, macos, linux, windows, web and hover
https://pub.dev/packages/fast_rsa
MIT License
72 stars 23 forks source link

`RSA.decryptPrivateKey()` no result #65

Open Arley011 opened 6 months ago

Arley011 commented 6 months ago

Sometimes I face the issue that my code just gets stuck on RSA.decryptPrivateKey() call and never continues. For me it looks like this MR caused this problem. It looks like there is an unhandled error in c++ code which is not sent through the port. And since onExit and onError callbacks of Isolate.spawn() were removed, method never returns anything. Moreover, it started happening after upgrading plugin from 3.5.1 to 3.6.1

Could you please inspect code of the RSA.decryptPrivateKey() method to check for errors handling? Sorry, for now I cannot provide the actual key-password pair to reproduce this issue. It happens rarely (I use key returned from the BE) and I added more logs to the code. So if you won't find anything suspicious in c++ code, I hope I will catch the data and will be able to provide an example to reproduce the issue.

Arley011 commented 6 months ago

Now I can verify that it happens occasionally... I just caught this issue while decrypting next private key with password Start321!:

-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: AES-256-CBC,F08085974E11F135907434BC74C9FF20

Xh1BdcvqpcMltewbPNT5FNmEqecKnNJIvDrmepkh7HNbCFwzrdVgFlce3K6IHD5Z
HViwXzdyN1w/SbkQJyHfy0eakScbFJS7wExw+i2VrwdIi5ETk/Md7Q43YwvJBGwT
P7/nMVXA+u+A2/VVESDA0zrQ+R/+kNPIa0Iqis76RIY3ozuJAgYaBx/10xBclu9n
Zrn9EpmkXspfJY7riqfSm4d8ATvjvWsss0UPS10D3hey9UEr22lfZcws/Qu1kZjn
sTwXdzUQYDU3kDzvKYU5lOrB246thx60krFBZ9zqyxhmMh12Hm+XOo5NkcbbQjmV
+7yE7E4uUTTwyPAf+f2/82j+WCat23MV77Lc+F3nX3pg5kvidyDy0MFRfI0uEpZb
Dqv9trAMhAh/PDO+yK8ZojAvY+LssVXrB0/YWmLXvk4wddM6yEEIJkbhJyJqZKu0
OYDBsC9SDPoa4tfV9WowpwZI6PmwfbswznUD3Rcs61pvuShY/auP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9+Rj+80rln7Y0+UVJVPrgMX5KQ1SLQs0AYgQyj
-----END RSA PRIVATE KEY-----

RSA.decryptPrivateKey() never returned neither result nor error. After that I restarted the app and the same private key was successfully decrypted...

Arley011 commented 6 months ago

Actually, looks like this issue doesn't relate to the exact method or parameters. The problem is that on app startup library fails to initialize. I get this sporadically when starting the app from xCode:

Знімок екрана 2024-03-13 о 15 20 32 Знімок екрана 2024-03-13 о 15 21 04 Знімок екрана 2024-03-14 о 10 07 07

Not quite descriptive.. But at least it is clear that library fails to start when application starts.

Arley011 commented 6 months ago

I am surprised that nobody else posted this problem before. Looks like critical bug 🤔

Arley011 commented 6 months ago

@jerson, I would appreciate if you could check it as soon as possible.

jerson commented 6 months ago

Hi @Arley011 thanks for report this issue I'm really busy these days but maybe I can take some time this weekend for this

jerson commented 2 months ago

the change is gonna be reverted in https://github.com/jerson/flutter-rsa/pull/72

Arley011 commented 1 month ago

the change is gonna be reverted in #72

@jerson, unfortunately, the issue still exists in 3.6.3