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

Cannot extracts the signature input from official TP-Link images with your shell script #5

Open
bamstwn opened this issue Apr 28, 2018 · 5 comments

Comments

@bamstwn
Copy link

bamstwn commented Apr 28, 2018

I try to extracts the signature input from official TP-Link images with your shell script but it says "unable to load Public Key", what's wrong? I use TD-W8980v1 image when try.

@xdarklight
Copy link
Owner

can you please share the exact steps you are using to reproduce this (including the version of the TD-W8980 v1 image)?

@bamstwn
Copy link
Author

bamstwn commented May 15, 2018

  1. I copied public key to a file named tp-link_pubkey.bin.ms_publickeyblob
BgIAAACkAABSU0ExAAQAAAEAAQD54+t3X+bMvuKUfm03w6prR+S+BRjefof9XuPFVew1mftBLi4IPmBc8fb5XJXSusmDXHa/SmSaH4dvNWE5xUuvzc9p2sWxczWEvGqAi4rNk82WtKn4JUgJoalOBOwLavO2ilq4MIcBNi4bYJ6s0vU243zlgFW7p29IsA64d3LY6Q==
  1. run this code with terminal ./extract-sign.sh TD-W8980v1.bin
#!/bin/sh
IMG="${1}"

for i in ${IMG} ; do
  echo "--- $i ---"

  if [ -f "$i" ]; then
    # get signature as hex string from image file (one hex
    # value per line) and reverse all lines
    sig=$(xxd -s +208 -l 128 -c 1 -plain "$i" | tac)

    # convert hex string to binary and let openssl extract
    # the signed content
    echo -n $sig | xxd -revert -plain | openssl rsautl \
              -hexdump -verify -pubin \
              -inkey tp-link_pubkey.bin.ms_publickeyblob \
              -keyform MS\ PUBLICKEYBLOB
  fi
done
  1. result
--- TD-W8980v1.bin ---
unable to load Public Key

@xdarklight
Copy link
Owner

the documentation states that the given public key is base64 encoded:

[...] contains the base64 encoded public key of the pair [...]

so please base64-decode the public key and save the decoded (binary) result as tp-link_pubkey.bin.ms_publickeyblob

@bamstwn
Copy link
Author

bamstwn commented May 22, 2018

OK, run base64-decode with base64 -d < pub.b64 > tp-link_pubkey.bin.ms_publickeyblob.
Decode (binary) results like this:

image

Run this code again ./extract-sign.sh TD-W8980v1.bin
Result:

--- TD-W8980v1.bin ---
RSA operation error
3074271432:error:0407006A:rsa routines:RSA_padding_check_PKCS1_type_1:block type is not 01:rsa_pk1.c:100:
3074271432:error:04067072:rsa routines:RSA_EAY_PUBLIC_DECRYPT:padding check failed:rsa_eay.c:721:

@leksmax
Copy link

leksmax commented Mar 18, 2019

i have same error with tplink 850v2 cannot extract signature

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

3 participants