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

remote adb had an error Error: Unrecognizable key format #1030

Open
lgleasain opened this issue Mar 17, 2019 · 7 comments
Open

remote adb had an error Error: Unrecognizable key format #1030

lgleasain opened this issue Mar 17, 2019 · 7 comments

Comments

@lgleasain
Copy link

What is the issue or idea you have?
I'm getting this message whenever I try to do a remote adb connect from two of my three machines. All other adb actions (IE: for local vm's etc.) work correctly on these machines.

I also did a search for past issues but am not seeing anything that seems to address this. This odd thing is that is works with one machine which appears to have the same version of ADB.

2019-03-17T20:18:42.437Z FTL/util:lifecycle 73913 [LGL34Ca18960] Remote ADB had an error Error: Unrecognizable public key format
at /Users/polyglotprogrammer/.nvm/versions/node/v8.15.1/lib/node_modules/stf/node_modules/adbkit/lib/adb/auth.js:69:23
at tryCatcher (/Users/polyglotprogrammer/.nvm/versions/node/v8.15.1/lib/node_modules/stf/node_modules/adbkit/node_modules/bluebird/js/main/util.js:26:23)
at Promise._resolveFromResolver (/Users/polyglotprogrammer/.nvm/versions/node/v8.15.1/lib/node_modules/stf/node_modules/adbkit/node_modules/bluebird/js/main/promise.js:476:31)
at new Promise (/Users/polyglotprogrammer/.nvm/versions/node/v8.15.1/lib/node_modules/stf/node_modules/adbkit/node_modules/bluebird/js/main/promise.js:69:37)
at Function.Auth.parsePublicKey (/Users/polyglotprogrammer/.nvm/versions/node/v8.15.1/lib/node_modules/stf/node_modules/adbkit/lib/adb/auth.js:62:12)
at Socket._handleAuthPacket (/Users/polyglotprogrammer/.nvm/versions/node/v8.15.1/lib/node_modules/stf/node_modules/adbkit/lib/adb/tcpusb/socket.js:168:21)
at /Users/polyglotprogrammer/.nvm/versions/node/v8.15.1/lib/node_modules/stf/node_modules/adbkit/lib/adb/tcpusb/socket.js:109:26
at tryCatcher (/Users/polyglotprogrammer/.nvm/versions/node/v8.15.1/lib/node_modules/stf/node_modules/adbkit/node_modules/bluebird/js/main/util.js:26:23)
at Function.Promise.attempt.Promise.try (/Users/polyglotprogrammer/.nvm/versions/node/v8.15.1/lib/node_modules/stf/node_modules/adbkit/node_modules/bluebird/js/main/method.js:31:24)
at Socket._handle (/Users/polyglotprogrammer/.nvm/versions/node/v8.15.1/lib/node_modules/stf/node_modules/adbkit/lib/adb/tcpusb/socket.js:95:26)
at emitOne (events.js:116:13)
at PacketReader.emit (events.js:211:7)
at PacketReader.tryRead (/Users/polyglotprogrammer/.nvm/versions/node/v8.15.1/lib/node_modules/stf/node_modules/adbkit/lib/adb/tcpusb/packetreader.js:45:16)
at emitNone (events.js:106:13)
at Socket.emit (events.js:208:7)
at emitReadable
(_stream_readable.js:513:10)
at emitReadable (_stream_readable.js:507:7)
at addChunk (_stream_readable.js:274:7)
at readableAddChunk (_stream_readable.js:250:11)
at Socket.Readable.push (_stream_readable.js:208:10)
at TCP.onread (net.js:601:20)

@koral--
Copy link
Member

koral-- commented Mar 17, 2019

This issue occurs when adb 1.0.40 (Version 28.0.2-5303910) from platform-tools 28.0.2 is used on client side. Workaround is to downgrade platform-tools to 28.0.1 (or older).

It looks like adb public key format has changed.

@darshansr
Copy link

yes using 1.0.40 adb version is giving too many problems from client side.
Please help us in resolving the adb compatibility issue. How can we use the latest version of adb without having above-mentioned error..........

@thinkhy
Copy link
Member

thinkhy commented Mar 26, 2019

@koral-- any detailed document for the new adb format? we would try to fix the problem

@koral--
Copy link
Member

koral-- commented Mar 26, 2019

I haven't analyzed those changes deeply, but here is some info:

Public key does not longer exists as a separate file.
adb keygen help in 28.0.2 says:

 keygen FILE
     generate adb public/private key; private key stored in FILE,

In 28.0.1 it was:

 keygen FILE
     generate adb public/private key; private key stored in FILE,
     public key stored in FILE.pub (existing files overwritten)

Changelog at https://developer.android.com/studio/releases/platform-tools says:

Fixes authentication—when the private key used for authentication does not match the public key—by calculating the public key from the private key, instead of assuming that they match.

Commit which seems to be relevant: aosp-mirror/platform_system_core@2dc4cab

@zr0827
Copy link

zr0827 commented Mar 27, 2019

Fix the re rule of parsing public key in https://github.com/openstf/adbkit/blob/7f1581016f1b1d4a8f4a45597f33ca09beed7332/src/adb/auth.coffee. Allow comment to be none because the comment part in adb pubkey has gone.

@shri-0509
Copy link

shri-0509 commented Mar 28, 2019

yes adb pubkey doesnt contain the host name, so parsing the pubkey fails using regular expression
/^((?:[A-Za-z0-9+/]{4})(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?)\0? (.)\s*$/

@denis99999
Copy link
Contributor

Hi,

I found a workaround (i.e. on an existing STF server) which works with any ADB versions, it consists to update the node_modules/adbkit/lib/adb/auth.js file

  • modify the regex in order to make optional the parsing of the last part of the public key (i.e. comment) with something like that:
    //RE = /^((?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?)\0? (.*)\s*$/;
    RE = /^((?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?)\0?(\s.*\s*)?$/;

  • modify the function which executes the regex with something like that:

  Auth.parsePublicKey = function(buffer) {
    return new Promise(function(resolve, reject) {
      var comment, match, struct;
      if (match = RE.exec(buffer)) {
        struct = new Buffer(match[1], 'base64');
        //comment = match[2];
        comment = typeof match[2] === 'undefined' ? 'localhost' : match[2];
        return resolve(readPublicKeyFromStruct(struct, comment));
      } else {
        return reject(new Error("Unrecognizable public key format"));
      }
    });
  };

Note this fix should be properly reported into the ADBKIT github project!

As mentionned in my post #1033, it exists a private ADB command pubkey which enables to generate the public key from the private key:
# adb pubkey ~/.android/adbkey > ~/.android/adbkey.pub

Thus, it is possible to add manually an ADB key into the STF user interface, you have just to provide a comment of your choice in the Device field of the form.

I tested this workaround with success using the latest ADB version 1.0.40 (28.0.2-5303910) and the ADB version 1.0.36!

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

7 participants