fix: allanime openssl aes-256-ctr decryption#1650
fix: allanime openssl aes-256-ctr decryption#1650justchokingaround merged 7 commits intopystardust:masterfrom
Conversation
|
key is not likely to change soon, as it's hardcoded in the frontend bundle: |
|
LGTM, however we need to mention additional dependency as well. I will refactor it in next patch as I am out of station. |
Does the IV change though? If both are fixed (which'd be atupid, but we've seen worse), we can simplify the whole process to a single xor |
the IV is not fixed, it's the first 12 bytes of each encrypted blob, generated per-request |
|
Since this is verified as working by @Luuvydev and two randoms approving this PR, I'd prefer if this was merged today. |
Derisis13
left a comment
There was a problem hiding this comment.
Nice work on the reverse-engineering!
Please elaborate on my comments and see my suggestion on how to do the decryption more concisely and without temp files. Once these are over, I'll do some testing (I have some catching up to do). Any test cases that reliably need the decoding? (I'd also like list them in the PR template, because this is bound to stay)
| len="$(wc -c <"$tmp" | tr -d ' ')" | ||
| iv="$(dd if="$tmp" bs=1 count=12 2>/dev/null | od -A n -t x1 | tr -d ' \n')" | ||
| ct_len=$((len - 28)) | ||
| dd if="$tmp" bs=1 skip=12 count="$ct_len" 2>/dev/null >"$ct" |
There was a problem hiding this comment.
I really don't like the whole operation of splitting a string (or binary blob) by writing to a file and dd-ing from it. Firstly, dd can read from STDIN (it does that by default), which I'd prefer for speed's sake (I think it has been demonstrated that people run this script on the crappiest hardware).
Second, the ct_len variable seems one billion per cent redundant, not setting count to anything copies the entire content of the input from skip to EOF.
My proposed solution to save some lines:
blob_raw=$(printf '%s' "$blob" | openssl enc -d -base64 -A)
ctr="$(printf '%s' "$blob_raw" | dd bs=1 count=12 2>/dev/null | od -A n -t x1 | tr -d ' \n')00000002"
ciphertext="$(printf %s "$blob_raw" | dd bs=1 skip=12 2>/dev/null)"
plaintext="$(printf '%s' "$ciphertext" | openssl enc -d -aes-256-ctr -K "$key" -iv "$ctr" -nosalt -nopad 2>/dev/null)"seems much simpler for me and also significantly less steps (250% less lines!!! /j) and no file IO. I haven't tested it though, so it's probably wrong somewhere...
There was a problem hiding this comment.
shell variables can't hold raw binary data since $() strips null bytes, which corrupts the iv extraction. i kept one temp file for the decoded blob so that dd can read the binary from disk
There was a problem hiding this comment.
Oh wow... Well that's something worthy of a short comment
i just use lain, but anw the decryption applies to all animes anw, so use whatever you want, it doesn't matter |
|
Just tried it on termux: openssl is weird. They separated it into two packages: openssl and openssl-tool. The CLI utility is in openssl-tool. This needs to be documented in the readme, and maybe as a case in dep_ch if we want to minimize the obvious question of "I installed openssl but script asks for openssl" |
done |
Derisis13
left a comment
There was a problem hiding this comment.
You're clear for merging
Pull Request Template
Type of change
Description
ramble here
Checklist
-chistory and continue work-ddownloads work-ssyncplay works-qquality works-vvlc works-e(select episode) aka-r(range selection) works-Sselect index works--skipani-skip works--skip-titleani-skip title argument works--no-detachno detach works--exit-after-playauto exit after playing works--nextep-countdowncountdown to next ep works--duband regular (sub) mode both work-hhelp info is up to dateAdditional Testcases