Stf: remote adb had an error Error: Unrecognizable key format

Created on 17 Mar 2019  路  7Comments  路  Source: openstf/stf

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)

Most helpful comment

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 pubkeywhich 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!

All 7 comments

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.

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..........

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

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鈥攚hen the private key used for authentication does not match the public key鈥攂y calculating the public key from the private key, instead of assuming that they match.

Commit which seems to be relevant: https://github.com/aosp-mirror/platform_system_core/commit/2dc4cabe0639c71014d729dd92eff19289429c89

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.

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*$/

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 pubkeywhich 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!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jc5055 picture jc5055  路  6Comments

luoxi001713 picture luoxi001713  路  5Comments

vovinio picture vovinio  路  5Comments

Sunraych picture Sunraych  路  4Comments

ghost picture ghost  路  7Comments