Post
Topic
Board Web Wallets
Re: Blocktrail.com | Wallet | Explorer | API
by
rubensayshi
on 10/02/2016, 12:42:51 UTC
I might have found another bug with your signed message verification.

The following sign message was recently posted

Code:
-----BEGIN BITCOIN SIGNED MESSAGE-----
This is harizen from bitcointalk.org. Today is February 1,2016.
-----BEGIN BITCOIN SIGNATURE-----
1BzFQocxr7QABTpwGz6o9Dsb6tPpBqbWZ8
HyEuQEIIi5KS0dqyCaIWh6a5A3wIMFqkSEehuNa7jOUZTSyLa08czuASi5RUcj78hPI5PMNec0w6XhzflMbFNcM
-----END BITCOIN SIGNATURE-----

and electrum's GUI just did nothing when I tried to verify it, so I tried to verify it via blocktrail and it passed with OK, signature is valid!.

Its not though, its missing a "=" at the end,

Code:
$ bitcoin-cli verifymessage "1BzFQocxr7QABTpwGz6o9Dsb6tPpBqbWZ8" "HyEuQEIIi5KS0dqyCaIWh6a5A3wIMFqkSEehuNa7jOUZTSyLa08czuASi5RUcj78hPI5PMNec0w6XhzflMbFNcM" "This is harizen from bitcointalk.org. Today is February 1,2016."
error: {"code":-5,"message":"Malformed base64 encoding"}
$ bitcoin-cli verifymessage "1BzFQocxr7QABTpwGz6o9Dsb6tPpBqbWZ8" "HyEuQEIIi5KS0dqyCaIWh6a5A3wIMFqkSEehuNa7jOUZTSyLa08czuASi5RUcj78hPI5PMNec0w6XhzflMbFNcM=" "This is harizen from bitcointalk.org. Today is February 1,2016."
true

hey, thanks for getting in touch! this could have been a pretty serious bug, but luckily it's not ;-)

the signature is 'base64' encoded which officially should have a trailing '=' if the last 'group' of bytes is only 2 bytes and act as a 'padding' to explicitly declare that you intended the last 'group' to miss 1 byte (base64 is chunked in 3 bytes per 'group') and a trailing '==' when the last 'group' is only 1 byte.
the javascript implementation of base64 actually silently asumes that if you don't have a trailing '=' but the last 'group' is only 2 bytes that it's supposed to be 2 bytes and doesn't error over it.

so when decoded (in javascript) from base64 into binary (or hex) "HyEuQEIIi5KS0dqyCaIWh6a5A3wIMFqkSEehuNa7jOUZTSyLa08czuASi5RUcj78hPI5PMNec0w6Xhz flMbFNcM" and "HyEuQEIIi5KS0dqyCaIWh6a5A3wIMFqkSEehuNa7jOUZTSyLa08czuASi5RUcj78hPI5PMNec0w6Xhz flMbFNcM=" both result in the same data.