Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CryptographicException at SamFirm.KiesAuth.DecryptNonce(String inp) in KiesAuth.cs #15

Closed
redddflash opened this issue Dec 19, 2023 · 11 comments

Comments

@redddflash
Copy link

redddflash commented Dec 19, 2023

There seems to be a new issue since today (yesterday it was still working normally), see two examples below. It happens, no matter which region or model is used, or if you just want to check or download a firmware. Tested with version 0.3.6.6 and also with 0.3.6.5.

Maybe Samsung has again changed something in their server authentication?

D:\SamFirm>SamFirm_Reborn_0.3.6.6\SamFirm.exe -c -model SM-S918B -region EUX
========== SamFirm Firmware Update Check ==========

Checking firmware for SM-S918B/EUX/S918BXXS3BWKC/S918BOXM3BWJM/S918BXXU3BWJM/S918BXXS3BWKC

Unhandled Exception: System.Security.Cryptography.CryptographicException: Padding is invalid and cannot be removed.
   at System.Security.Cryptography.RijndaelManagedTransform.DecryptData(Byte[] inputBuffer, Int32 inputOffset, Int32 inputCount, Byte[]& outputBuffer, Int32 outputOffset, PaddingMode paddingMode, Boolean fLast)
   at System.Security.Cryptography.RijndaelManagedTransform.TransformFinalBlock(Byte[] inputBuffer, Int32 inputOffset, Int32 inputCount)
   at SamFirm.KiesAuth.DecryptNonce(String inp) in C:\Users\i_iva\Desktop\SamFirm_Reborn\KiesAuth.cs:line 26.
   at SamFirm.WebRequestExtension.GetResponseFUS(WebRequest wr) in C:\Users\i_iva\Desktop\SamFirm_Reborn\WebRequestExtension.cs:line 20.
   at SamFirm.Web.GenerateNonce() in C:\Users\i_iva\Desktop\SamFirm_Reborn\Web.cs:line 29.
   at SamFirm.Command.UpdateCheck(String model, String region, String pda, String csc, String phone, String data, Boolean BinaryNature, Boolean AutoFetch) in C:\Users\i_iva\Desktop\SamFirm_Reborn\Command.cs:line 68.
   at SamFirm.Command.UpdateCheck(String model, String region, String info, Boolean BinaryNature, Boolean AutoFetch) in C:\Users\i_iva\Desktop\SamFirm_Reborn\Command.cs:line 53.
   at SamFirm.Command.UpdateCheckAuto(String model, String region, Boolean BinaryNature) in C:\Users\i_iva\Desktop\SamFirm_Reborn\Command.cs:line 23.
   at SamFirm.CmdLine.DoCheck() in C:\Users\i_iva\Desktop\SamFirm_Reborn\CmdLine.cs:line 101.
   at SamFirm.CmdLine.ProcessAction() in C:\Users\i_iva\Desktop\SamFirm_Reborn\CmdLine.cs:line 44.
   at SamFirm.Program.Main(String[] args) in C:\Users\i_iva\Desktop\SamFirm_Reborn\Program.cs:line 21.

D:\SamFirm>SamFirm_Reborn_0.3.6.6\SamFirm.exe -c -model SM-G960F -region DBT
========== SamFirm Firmware Update Check ==========

Checking firmware for SM-G960F/DBT/G960FXXUHFVG4/G960FOXMHFVB4/G960FXXUHFVB4/G960FXXUHFVG4

Unhandled Exception: System.Security.Cryptography.CryptographicException: Padding is invalid and cannot be removed.
   at System.Security.Cryptography.RijndaelManagedTransform.DecryptData(Byte[] inputBuffer, Int32 inputOffset, Int32 inputCount, Byte[]& outputBuffer, Int32 outputOffset, PaddingMode paddingMode, Boolean fLast)
   at System.Security.Cryptography.RijndaelManagedTransform.TransformFinalBlock(Byte[] inputBuffer, Int32 inputOffset, Int32 inputCount)
   at SamFirm.KiesAuth.DecryptNonce(String inp) in C:\Users\i_iva\Desktop\SamFirm_Reborn\KiesAuth.cs:line 26.
   at SamFirm.WebRequestExtension.GetResponseFUS(WebRequest wr) in C:\Users\i_iva\Desktop\SamFirm_Reborn\WebRequestExtension.cs:line 20.
   at SamFirm.Web.GenerateNonce() in C:\Users\i_iva\Desktop\SamFirm_Reborn\Web.cs:line 29.
   at SamFirm.Command.UpdateCheck(String model, String region, String pda, String csc, String phone, String data, Boolean BinaryNature, Boolean AutoFetch) in C:\Users\i_iva\Desktop\SamFirm_Reborn\Command.cs:line 68.
   at SamFirm.Command.UpdateCheck(String model, String region, String info, Boolean BinaryNature, Boolean AutoFetch) in C:\Users\i_iva\Desktop\SamFirm_Reborn\Command.cs:line 53.
   at SamFirm.Command.UpdateCheckAuto(String model, String region, Boolean BinaryNature) in C:\Users\i_iva\Desktop\SamFirm_Reborn\Command.cs:line 23.
   at SamFirm.CmdLine.DoCheck() in C:\Users\i_iva\Desktop\SamFirm_Reborn\CmdLine.cs:line 101.
   at SamFirm.CmdLine.ProcessAction() in C:\Users\i_iva\Desktop\SamFirm_Reborn\CmdLine.cs:line 44.
   at SamFirm.Program.Main(String[] args) in C:\Users\i_iva\Desktop\SamFirm_Reborn\Program.cs:line 21.
@tungtata
Copy link

Samsung just fix the encrypt key and iv so now nonce still got but can not decrypted. Waiting for someone fix it

@ivanmeler
Copy link
Owner

Just as i was working on imporvements.. they change encryption method..
working on it but this might take some time

@chenxiaolong
Copy link
Contributor

Switching to the new keys alone isn't sufficient. (They can be found from the same places as the old keys. There's only a tiny bit of obfuscation in the form of two string replacement calls.)

From initial testing, it looks like all of these conditions are necessary:

  • New fixed key and flexible key suffixes (reverse engineered)
  • Passing additional fields to /NF_DownloadBinaryInform.do
    • CLIENT_PRODUCT must exist. The value doesn't seem to matter.
      • If this condition isn't met, the server fails with HTTP 500 and returns an HTML response.
    • CLIENT_VERSION must exist. The value doesn't seem to matter, but must be non-empty.
      • If this condition isn't met, the server fails with HTTP 500 and returns an HTML response.
    • DEVICE_IMEI_PUSH must be set to the target device's IMEI or if the device doesn't have a modem, the serial number.
      • Invalid IMEIs/serials don't work. Using a valid serial to download firmware for a different device doesn't work. Using a valid serial to download firmware for a different CSC of the same model doesn't work either (unless the same firmware version also exists for the device's original CSC).
      • If this condition isn't met, the server returns a FUS XML response with error code 408.

I'm not sure if it's possible to download arbitrary firmware anymore. I tried various things, like pretending to be old Smart Switch version, with no luck.

@tungtata
Copy link

Switching to the new keys alone isn't sufficient. (They can be found from the same places as the old keys. There's only a tiny bit of obfuscation in the form of two string replacement calls.)

From initial testing, it looks like all of these conditions are necessary:

  • New fixed key and flexible key suffixes (reverse engineered)

  • Passing additional fields to /NF_DownloadBinaryInform.do

    • CLIENT_PRODUCT must exist. The value doesn't seem to matter.

      • If this condition isn't met, the server fails with HTTP 500 and returns an HTML response.
    • CLIENT_VERSION must exist. The value doesn't seem to matter, but must be non-empty.

      • If this condition isn't met, the server fails with HTTP 500 and returns an HTML response.
    • DEVICE_IMEI_PUSH must be set to the target device's IMEI or if the device doesn't have a modem, the serial number.

      • Invalid IMEIs/serials don't work. Using a valid serial to download firmware for a different device doesn't work. Using a valid serial to download firmware for a different CSC of the same model doesn't work either (unless the same firmware version also exists for the device's original CSC).
      • If this condition isn't met, the server returns a FUS XML response with error code 408.

I'm not sure if it's possible to download arbitrary firmware anymore. I tried various things, like pretending to be old Smart Switch version, with no luck.

Did you got new key of the nonce encrypt?

@chenxiaolong
Copy link
Contributor

I won't post the actual keys, but you can run this to extract the keys from publicly available sources: https://gist.github.com/chenxiaolong/62282271bfd8af198b75fc9cce201333

@tungtata
Copy link

this script works on Mac only right?

@chenxiaolong
Copy link
Contributor

No, it should work anywhere where Python is installed (I personally use Linux).

@tungtata
Copy link

I tried on Windows and got this error
image
I am sorry because I don't works with py much

@chenxiaolong
Copy link
Contributor

I tried on Windows and got this error image I am sorry because I don't works with py much

Thanks, looks like I'm relying on syntax that's only accepted in newer versions of Python. I've updated the script to fix this (replaced 'ASCII' with "ASCII").

@tungtata
Copy link

how can I have your private contact bro? like telegram or whatsapp?

corsicanu added a commit to corsicanu/hadesFirm that referenced this issue Dec 21, 2023
- more info on chenxiaolong/samfusdl@1ad29ed https://github.com/chenxiaolong/samfusdl/releases/tag/v0.1.8 ivanmeler#15 (comment) zacharee/SamloaderKotlin#116 zacharee/SamloaderKotlin@e0766d7

Co-authored-by: Andrew Gunnerson <accounts+github@chiller3.com>
Co-authored-by: Zachary Wander <zachary.wander@gmail.com>
Co-authored-by: Anan Jaser <ananjaser@gmail.com>
Signed-off-by: corsicanu <me@corsicanu.ro>
corsicanu added a commit that referenced this issue Dec 21, 2023
- more info on chenxiaolong/samfusdl@1ad29ed https://github.com/chenxiaolong/samfusdl/releases/tag/v0.1.8 #15 (comment) zacharee/SamloaderKotlin#116 zacharee/SamloaderKotlin@e0766d7

Co-authored-by: Andrew Gunnerson <accounts+github@chiller3.com>
Co-authored-by: Zachary Wander <zachary.wander@gmail.com>
Co-authored-by: Anan Jaser <ananjaser@gmail.com>
Signed-off-by: corsicanu <me@corsicanu.ro>
@ivanmeler
Copy link
Owner

fixed in new release, will be released in hour or so

salvogiangri added a commit to salvogiangri/UN1CA that referenced this issue Dec 27, 2023
salvogiangri added a commit to salvogiangri/UN1CA that referenced this issue Dec 28, 2023
salvogiangri added a commit to Mesa-Labs-Archive/proprietary_vendor_samsung_a52sxq that referenced this issue Dec 28, 2023
salvogiangri added a commit to Mesa-Labs-Archive/proprietary_vendor_samsung_m52xq that referenced this issue Dec 28, 2023
salvogiangri added a commit to Mesa-Labs-Archive/proprietary_vendor_samsung_a54x that referenced this issue Dec 28, 2023
salvogiangri added a commit to Mesa-Labs-Archive/proprietary_vendor_samsung_a54x that referenced this issue Dec 28, 2023
salvogiangri added a commit to Mesa-Labs-Archive/proprietary_vendor_samsung_m52xq that referenced this issue Dec 28, 2023
Simon1511 pushed a commit to Simon1511/samsung-sm7325-fw that referenced this issue Jan 4, 2024
Simon1511 pushed a commit to Simon1511/samsung-sm7325-fw that referenced this issue Jan 4, 2024
Simon1511 pushed a commit to Simon1511/a52q-a72q-fw that referenced this issue Jan 4, 2024
Simon1511 pushed a commit to Simon1511/a52q-a72q-fw that referenced this issue Jan 4, 2024
Simon1511 pushed a commit to Simon1511/samsung-sm7325-fw that referenced this issue Jan 4, 2024
ShaDisNX255 pushed a commit to ShaDisNX255/proprietary_vendor_samsung_a52q that referenced this issue Jan 4, 2024
ShaDisNX255 added a commit to ShaDisNX255/proprietary_vendor_samsung_a52q that referenced this issue Jan 4, 2024
salvogiangri added a commit to Mesa-Labs-Archive/proprietary_vendor_samsung_m52xq that referenced this issue Jan 5, 2024
ata-kaner pushed a commit to ata-kaner/samsung-kona-firmware that referenced this issue May 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants