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

fix verifying wii dev signatures #10984

Merged
merged 1 commit into from Aug 17, 2022
Merged

Conversation

shuffle2
Copy link
Contributor

@shuffle2 shuffle2 commented Aug 15, 2022

allows verifying dev-signed discs and wads

also fixes a memleak because mbedtls_rsa_free wasn't called before.

Source/Core/Core/IOS/IOSC.cpp Outdated Show resolved Hide resolved
Source/Core/Core/IOS/IOS.h Outdated Show resolved Hide resolved
Source/Core/Core/IOS/IOSC.cpp Outdated Show resolved Hide resolved
allows verifying dev-signed discs and wads
@JosJuice JosJuice merged commit 86d760b into dolphin-emu:master Aug 17, 2022
11 checks passed
@Shizmob
Copy link
Contributor

Shizmob commented Aug 22, 2022

Update on this: the non-verifying signatures I've encountered actually do have correct PKCS#1 v1.5 padding, but they're of block type 2 (public-key padding) instead of the usual and recommended 1 (private-key padding). Possibly because apparently the dev keys are supposed to be known to developers anyway?

Either way, I've implemented the type 2 padding checks in my own tooling and all the signatures seem to verify correctly.

@shuffle2
Copy link
Contributor Author

shuffle2 commented Aug 22, 2022

Good point! I should have looked into it a bit more :) I've seen this elsewhere as well - dev sigs encrypt the hash using d=0x10001, e={big num}. i.e. it is technically encrypted and not signed.

afaict mbedtls makes this quite annoying since it requires "private" rsa operations to have both d and e set in the context. So just setting d=e then retrying with mbedtls_rsa_pkcs1_decrypt (which checks the "type 2" format) fails because the rsa context is missing some fields. It seems like using mbedtls to "properly" check the padding would require dolphin embedding the dev e (which people can use to sign things 🙂), otherwise dolphin could implement it's own check...but eh.

fwiw in python you should just be able to use this https://www.pycryptodome.org/src/cipher/pkcs1_v1_5

@Shizmob
Copy link
Contributor

Shizmob commented Aug 23, 2022

Yeah, it's a bit of a mess! I opted to not use the PyCrypto PKCS#1 primitives because they have (correct, mind you) opinions about when you should use RSA encrypt versus decrypt operations, and about unpadding stuff properly (both of which the Wii at various points of course, can violate :>).

It seems mbedtls sadly doesn't cater out-of-the-box to non-standard use-cases like this either nor is its padding API usable by itself, which is a bummer...

@shuffle2 shuffle2 deleted the verifydev branch October 21, 2022 22:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
5 participants