@yume-chan/adb 2.6.2 → 3.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +1 -1
- package/esm/adb.d.ts +18 -15
- package/esm/adb.d.ts.map +1 -1
- package/esm/adb.js +18 -11
- package/esm/adb.js.map +1 -1
- package/esm/banner.d.ts +1 -1
- package/esm/banner.d.ts.map +1 -1
- package/esm/banner.js.map +1 -1
- package/esm/daemon/auth/authenticator.d.ts +28 -0
- package/esm/daemon/auth/authenticator.d.ts.map +1 -0
- package/esm/daemon/auth/authenticator.js +108 -0
- package/esm/daemon/auth/authenticator.js.map +1 -0
- package/esm/daemon/auth/index.d.ts +5 -0
- package/esm/daemon/auth/index.d.ts.map +1 -0
- package/esm/daemon/auth/index.js +5 -0
- package/esm/daemon/auth/index.js.map +1 -0
- package/esm/daemon/auth/packet-processor.d.ts +42 -0
- package/esm/daemon/auth/packet-processor.d.ts.map +1 -0
- package/esm/daemon/auth/packet-processor.js +129 -0
- package/esm/daemon/auth/packet-processor.js.map +1 -0
- package/esm/daemon/auth/public-key.d.ts +8 -0
- package/esm/daemon/auth/public-key.d.ts.map +1 -0
- package/esm/daemon/auth/public-key.js +74 -0
- package/esm/daemon/auth/public-key.js.map +1 -0
- package/esm/daemon/auth/type.d.ts +5 -0
- package/esm/daemon/auth/type.d.ts.map +1 -0
- package/esm/daemon/auth/type.js +2 -0
- package/esm/daemon/auth/type.js.map +1 -0
- package/esm/daemon/crypto.d.ts +6 -5
- package/esm/daemon/crypto.d.ts.map +1 -1
- package/esm/daemon/crypto.js +23 -72
- package/esm/daemon/crypto.js.map +1 -1
- package/esm/daemon/dispatcher.d.ts +3 -3
- package/esm/daemon/dispatcher.d.ts.map +1 -1
- package/esm/daemon/dispatcher.js +11 -4
- package/esm/daemon/dispatcher.js.map +1 -1
- package/esm/daemon/index.d.ts +1 -1
- package/esm/daemon/index.d.ts.map +1 -1
- package/esm/daemon/index.js +1 -1
- package/esm/daemon/index.js.map +1 -1
- package/esm/daemon/socket.d.ts +3 -3
- package/esm/daemon/socket.d.ts.map +1 -1
- package/esm/daemon/transport.d.ts +13 -65
- package/esm/daemon/transport.d.ts.map +1 -1
- package/esm/daemon/transport.js +18 -140
- package/esm/daemon/transport.js.map +1 -1
- package/esm/device-observer.d.ts +2 -3
- package/esm/device-observer.d.ts.map +1 -1
- package/esm/features-value.d.ts +40 -0
- package/esm/features-value.d.ts.map +1 -0
- package/esm/features-value.js +46 -0
- package/esm/features-value.js.map +1 -0
- package/esm/features.d.ts +4 -12
- package/esm/features.d.ts.map +1 -1
- package/esm/features.js +27 -13
- package/esm/features.js.map +1 -1
- package/esm/index.d.ts +1 -1
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +1 -1
- package/esm/index.js.map +1 -1
- package/esm/server/client.d.ts +7 -7
- package/esm/server/client.d.ts.map +1 -1
- package/esm/server/client.js +69 -86
- package/esm/server/client.js.map +1 -1
- package/esm/server/commands/wireless.js +1 -1
- package/esm/server/commands/wireless.js.map +1 -1
- package/esm/server/{stream.d.ts → data-connection.d.ts} +5 -5
- package/esm/server/data-connection.d.ts.map +1 -0
- package/esm/server/{stream.js → data-connection.js} +4 -4
- package/esm/server/data-connection.js.map +1 -0
- package/esm/server/index.d.ts +1 -1
- package/esm/server/index.d.ts.map +1 -1
- package/esm/server/index.js +1 -1
- package/esm/server/index.js.map +1 -1
- package/esm/server/observer.d.ts.map +1 -1
- package/esm/server/observer.js +14 -13
- package/esm/server/observer.js.map +1 -1
- package/esm/server/transport.d.ts +4 -6
- package/esm/server/transport.d.ts.map +1 -1
- package/esm/server/transport.js +9 -24
- package/esm/server/transport.js.map +1 -1
- package/esm/service/framebuffer.d.ts.map +1 -0
- package/esm/service/framebuffer.js.map +1 -0
- package/esm/{commands → service}/index.d.ts +1 -2
- package/esm/service/index.d.ts.map +1 -0
- package/esm/{commands → service}/index.js +1 -2
- package/esm/service/index.js.map +1 -0
- package/esm/{commands → service}/power.d.ts +4 -2
- package/esm/service/power.d.ts.map +1 -0
- package/esm/{commands → service}/power.js +11 -5
- package/esm/service/power.js.map +1 -0
- package/esm/service/reverse/error.d.ts +14 -0
- package/esm/service/reverse/error.d.ts.map +1 -0
- package/esm/service/reverse/error.js +21 -0
- package/esm/service/reverse/error.js.map +1 -0
- package/esm/service/reverse/index.d.ts +3 -0
- package/esm/service/reverse/index.d.ts.map +1 -0
- package/esm/service/reverse/index.js +4 -0
- package/esm/service/reverse/index.js.map +1 -0
- package/esm/service/reverse/response.d.ts +2 -0
- package/esm/service/reverse/response.d.ts.map +1 -0
- package/esm/service/reverse/response.js +30 -0
- package/esm/service/reverse/response.js.map +1 -0
- package/esm/service/reverse/service.d.ts +59 -0
- package/esm/service/reverse/service.d.ts.map +1 -0
- package/esm/{commands/reverse.js → service/reverse/service.js} +16 -45
- package/esm/service/reverse/service.js.map +1 -0
- package/esm/{commands → service}/subprocess/index.d.ts +1 -0
- package/esm/service/subprocess/index.d.ts.map +1 -0
- package/esm/{commands → service}/subprocess/index.js +1 -0
- package/esm/service/subprocess/index.js.map +1 -0
- package/esm/service/subprocess/none/index.d.ts.map +1 -0
- package/esm/service/subprocess/none/index.js.map +1 -0
- package/esm/{commands → service}/subprocess/none/process.d.ts +2 -2
- package/esm/service/subprocess/none/process.d.ts.map +1 -0
- package/esm/service/subprocess/none/process.js.map +1 -0
- package/esm/{commands → service}/subprocess/none/pty.d.ts +4 -4
- package/esm/service/subprocess/none/pty.d.ts.map +1 -0
- package/esm/{commands → service}/subprocess/none/pty.js +1 -1
- package/esm/service/subprocess/none/pty.js.map +1 -0
- package/esm/service/subprocess/none/service.d.ts +10 -0
- package/esm/service/subprocess/none/service.d.ts.map +1 -0
- package/esm/service/subprocess/none/service.js +44 -0
- package/esm/service/subprocess/none/service.js.map +1 -0
- package/esm/service/subprocess/none/spawner.d.ts +15 -0
- package/esm/service/subprocess/none/spawner.d.ts.map +1 -0
- package/esm/service/subprocess/none/spawner.js +31 -0
- package/esm/service/subprocess/none/spawner.js.map +1 -0
- package/esm/{commands → service}/subprocess/pty.d.ts +1 -1
- package/esm/service/subprocess/pty.d.ts.map +1 -0
- package/esm/{commands → service}/subprocess/pty.js.map +1 -1
- package/esm/service/subprocess/service.d.ts.map +1 -0
- package/esm/{commands → service}/subprocess/service.js +1 -1
- package/esm/service/subprocess/service.js.map +1 -0
- package/esm/service/subprocess/shell/index.d.ts +5 -0
- package/esm/{commands/subprocess/none → service/subprocess/shell}/index.d.ts.map +1 -1
- package/esm/service/subprocess/shell/index.js +6 -0
- package/esm/{commands/subprocess/none → service/subprocess/shell}/index.js.map +1 -1
- package/esm/{commands → service}/subprocess/shell/process.d.ts +2 -2
- package/esm/service/subprocess/shell/process.d.ts.map +1 -0
- package/esm/{commands → service}/subprocess/shell/process.js +4 -6
- package/esm/service/subprocess/shell/process.js.map +1 -0
- package/esm/{commands → service}/subprocess/shell/pty.d.ts +4 -4
- package/esm/service/subprocess/shell/pty.d.ts.map +1 -0
- package/esm/{commands → service}/subprocess/shell/pty.js +11 -9
- package/esm/service/subprocess/shell/pty.js.map +1 -0
- package/esm/service/subprocess/shell/service.d.ts +34 -0
- package/esm/service/subprocess/shell/service.d.ts.map +1 -0
- package/esm/service/subprocess/shell/service.js +52 -0
- package/esm/service/subprocess/shell/service.js.map +1 -0
- package/esm/service/subprocess/shell/shared.d.ts +2 -0
- package/esm/service/subprocess/shell/shared.d.ts.map +1 -0
- package/esm/{commands → service}/subprocess/shell/shared.js +2 -0
- package/esm/service/subprocess/shell/shared.js.map +1 -0
- package/esm/{commands → service}/subprocess/shell/spawner.d.ts +3 -7
- package/esm/service/subprocess/shell/spawner.d.ts.map +1 -0
- package/esm/service/subprocess/shell/spawner.js +45 -0
- package/esm/service/subprocess/shell/spawner.js.map +1 -0
- package/esm/service/subprocess/types.d.ts +14 -0
- package/esm/service/subprocess/types.d.ts.map +1 -0
- package/esm/service/subprocess/types.js +2 -0
- package/esm/service/subprocess/types.js.map +1 -0
- package/esm/service/subprocess/utils.d.ts +39 -0
- package/esm/service/subprocess/utils.d.ts.map +1 -0
- package/esm/service/subprocess/utils.js +142 -0
- package/esm/service/subprocess/utils.js.map +1 -0
- package/esm/service/sync/android.d.ts +34 -0
- package/esm/service/sync/android.d.ts.map +1 -0
- package/esm/service/sync/android.js +34 -0
- package/esm/service/sync/android.js.map +1 -0
- package/esm/service/sync/compression/compression.d.ts +17 -0
- package/esm/service/sync/compression/compression.d.ts.map +1 -0
- package/esm/service/sync/compression/compression.js +92 -0
- package/esm/service/sync/compression/compression.js.map +1 -0
- package/esm/service/sync/compression/format-ns.d.ts +5 -0
- package/esm/service/sync/compression/format-ns.d.ts.map +1 -0
- package/esm/service/sync/compression/format-ns.js +5 -0
- package/esm/service/sync/compression/format-ns.js.map +1 -0
- package/esm/service/sync/compression/format.d.ts +4 -0
- package/esm/service/sync/compression/format.d.ts.map +1 -0
- package/esm/service/sync/compression/format.js +3 -0
- package/esm/service/sync/compression/format.js.map +1 -0
- package/esm/service/sync/compression/index.d.ts +2 -0
- package/esm/service/sync/compression/index.d.ts.map +1 -0
- package/esm/service/sync/compression/index.js +2 -0
- package/esm/service/sync/compression/index.js.map +1 -0
- package/esm/service/sync/id/common.d.ts +17 -0
- package/esm/service/sync/id/common.d.ts.map +1 -0
- package/esm/service/sync/id/common.js +29 -0
- package/esm/service/sync/id/common.js.map +1 -0
- package/esm/service/sync/id/index.d.ts +4 -0
- package/esm/service/sync/id/index.d.ts.map +1 -0
- package/esm/service/sync/id/index.js +6 -0
- package/esm/service/sync/id/index.js.map +1 -0
- package/esm/service/sync/id/request.d.ts +7 -0
- package/esm/service/sync/id/request.d.ts.map +1 -0
- package/esm/service/sync/id/request.js +9 -0
- package/esm/service/sync/id/request.js.map +1 -0
- package/esm/service/sync/id/response.d.ts +6 -0
- package/esm/service/sync/id/response.d.ts.map +1 -0
- package/esm/service/sync/id/response.js +8 -0
- package/esm/service/sync/id/response.js.map +1 -0
- package/esm/service/sync/index-ns.d.ts +7 -0
- package/esm/service/sync/index-ns.d.ts.map +1 -0
- package/esm/service/sync/index-ns.js +7 -0
- package/esm/service/sync/index-ns.js.map +1 -0
- package/esm/service/sync/index.d.ts +3 -0
- package/esm/service/sync/index.d.ts.map +1 -0
- package/esm/service/sync/index.js +3 -0
- package/esm/service/sync/index.js.map +1 -0
- package/esm/service/sync/request/index.d.ts +5 -0
- package/esm/service/sync/request/index.d.ts.map +1 -0
- package/esm/service/sync/request/index.js +5 -0
- package/esm/service/sync/request/index.js.map +1 -0
- package/esm/{commands/sync → service/sync/request}/list.d.ts +21 -19
- package/esm/service/sync/request/list.d.ts.map +1 -0
- package/esm/service/sync/request/list.js +77 -0
- package/esm/service/sync/request/list.js.map +1 -0
- package/esm/service/sync/request/pull.d.ts +12 -0
- package/esm/service/sync/request/pull.d.ts.map +1 -0
- package/esm/service/sync/request/pull.js +28 -0
- package/esm/service/sync/request/pull.js.map +1 -0
- package/esm/service/sync/request/push.d.ts +54 -0
- package/esm/service/sync/request/push.d.ts.map +1 -0
- package/esm/service/sync/request/push.js +95 -0
- package/esm/service/sync/request/push.js.map +1 -0
- package/esm/{commands/sync → service/sync/request}/stat.d.ts +40 -50
- package/esm/service/sync/request/stat.d.ts.map +1 -0
- package/esm/service/sync/request/stat.js +89 -0
- package/esm/service/sync/request/stat.js.map +1 -0
- package/esm/service/sync/service.d.ts +123 -0
- package/esm/service/sync/service.d.ts.map +1 -0
- package/esm/service/sync/service.js +170 -0
- package/esm/service/sync/service.js.map +1 -0
- package/esm/service/sync/socket-pool.d.ts +11 -0
- package/esm/service/sync/socket-pool.d.ts.map +1 -0
- package/esm/service/sync/socket-pool.js +80 -0
- package/esm/service/sync/socket-pool.js.map +1 -0
- package/esm/service/sync/socket.d.ts +40 -0
- package/esm/service/sync/socket.d.ts.map +1 -0
- package/esm/service/sync/socket.js +153 -0
- package/esm/service/sync/socket.js.map +1 -0
- package/esm/{commands → service}/tcpip.d.ts +4 -2
- package/esm/service/tcpip.d.ts.map +1 -0
- package/esm/{commands → service}/tcpip.js +10 -7
- package/esm/service/tcpip.js.map +1 -0
- package/esm/utils/array-buffer.d.ts.map +1 -1
- package/esm/utils/array-buffer.js +2 -3
- package/esm/utils/array-buffer.js.map +1 -1
- package/esm/utils/base64.d.ts.map +1 -1
- package/esm/utils/base64.js +22 -10
- package/esm/utils/base64.js.map +1 -1
- package/esm/utils/index.d.ts +1 -0
- package/esm/utils/index.d.ts.map +1 -1
- package/esm/utils/index.js +1 -0
- package/esm/utils/index.js.map +1 -1
- package/esm/utils/md5.d.ts +8 -0
- package/esm/utils/md5.d.ts.map +1 -0
- package/esm/utils/md5.js +149 -0
- package/esm/utils/md5.js.map +1 -0
- package/package.json +9 -9
- package/src/adb.ts +44 -35
- package/src/banner.ts +2 -1
- package/src/daemon/auth/authenticator.ts +186 -0
- package/src/daemon/auth/index.ts +4 -0
- package/src/daemon/auth/packet-processor.ts +212 -0
- package/src/daemon/auth/public-key.ts +112 -0
- package/src/daemon/auth/type.ts +5 -0
- package/src/daemon/crypto.ts +36 -101
- package/src/daemon/dispatcher.ts +15 -8
- package/src/daemon/index.ts +1 -1
- package/src/daemon/socket.ts +3 -3
- package/src/daemon/transport.ts +35 -253
- package/src/device-observer.ts +3 -3
- package/src/features-value.ts +47 -0
- package/src/features.ts +31 -14
- package/src/index.ts +1 -1
- package/src/server/client.ts +94 -93
- package/src/server/commands/wireless.ts +1 -1
- package/src/server/{stream.ts → data-connection.ts} +4 -4
- package/src/server/index.ts +1 -1
- package/src/server/observer.ts +21 -19
- package/src/server/transport.ts +13 -34
- package/src/{commands → service}/index.ts +1 -2
- package/src/{commands → service}/power.ts +14 -5
- package/src/service/reverse/error.ts +35 -0
- package/src/service/reverse/index.ts +3 -0
- package/src/service/reverse/response.ts +38 -0
- package/src/{commands/reverse.ts → service/reverse/service.ts} +32 -72
- package/src/{commands → service}/subprocess/index.ts +1 -0
- package/src/{commands → service}/subprocess/none/process.ts +3 -3
- package/src/{commands → service}/subprocess/none/pty.ts +5 -5
- package/src/service/subprocess/none/service.ts +57 -0
- package/src/service/subprocess/none/spawner.ts +81 -0
- package/src/{commands → service}/subprocess/pty.ts +1 -1
- package/src/{commands → service}/subprocess/service.ts +1 -1
- package/src/{commands → service}/subprocess/shell/index.ts +1 -1
- package/src/{commands → service}/subprocess/shell/process.ts +6 -7
- package/src/{commands → service}/subprocess/shell/pty.ts +15 -13
- package/src/service/subprocess/shell/service.ts +75 -0
- package/src/{commands → service}/subprocess/shell/shared.ts +5 -0
- package/src/service/subprocess/shell/spawner.ts +109 -0
- package/src/service/subprocess/types.ts +19 -0
- package/src/service/subprocess/utils.ts +166 -0
- package/src/service/sync/android.ts +43 -0
- package/src/service/sync/compression/compression.ts +126 -0
- package/src/service/sync/compression/format-ns.ts +4 -0
- package/src/service/sync/compression/format.ts +5 -0
- package/src/service/sync/compression/index.ts +1 -0
- package/src/service/sync/id/common.ts +33 -0
- package/src/service/sync/id/index.ts +7 -0
- package/src/service/sync/id/request.ts +12 -0
- package/src/service/sync/id/response.ts +11 -0
- package/src/service/sync/index-ns.ts +6 -0
- package/src/service/sync/index.ts +2 -0
- package/src/service/sync/request/index.ts +4 -0
- package/src/service/sync/request/list.ts +110 -0
- package/src/service/sync/request/pull.ts +49 -0
- package/src/service/sync/request/push.ts +184 -0
- package/src/service/sync/request/stat.ts +127 -0
- package/src/service/sync/service.ts +255 -0
- package/src/service/sync/socket-pool.ts +97 -0
- package/src/service/sync/socket.ts +201 -0
- package/src/{commands → service}/tcpip.ts +13 -7
- package/src/utils/array-buffer.ts +2 -3
- package/src/utils/base64.ts +24 -10
- package/src/utils/index.ts +1 -0
- package/src/utils/md5.ts +185 -0
- package/yume-chan-adb-3.0.0-beta.0.tgz +0 -0
- package/CHANGELOG.md +0 -257
- package/esm/commands/base.d.ts +0 -8
- package/esm/commands/base.d.ts.map +0 -1
- package/esm/commands/base.js +0 -12
- package/esm/commands/base.js.map +0 -1
- package/esm/commands/framebuffer.d.ts.map +0 -1
- package/esm/commands/framebuffer.js.map +0 -1
- package/esm/commands/index.d.ts.map +0 -1
- package/esm/commands/index.js.map +0 -1
- package/esm/commands/power.d.ts.map +0 -1
- package/esm/commands/power.js.map +0 -1
- package/esm/commands/reverse.d.ts +0 -48
- package/esm/commands/reverse.d.ts.map +0 -1
- package/esm/commands/reverse.js.map +0 -1
- package/esm/commands/subprocess/index.d.ts.map +0 -1
- package/esm/commands/subprocess/index.js.map +0 -1
- package/esm/commands/subprocess/none/process.d.ts.map +0 -1
- package/esm/commands/subprocess/none/process.js.map +0 -1
- package/esm/commands/subprocess/none/pty.d.ts.map +0 -1
- package/esm/commands/subprocess/none/pty.js.map +0 -1
- package/esm/commands/subprocess/none/service.d.ts +0 -10
- package/esm/commands/subprocess/none/service.d.ts.map +0 -1
- package/esm/commands/subprocess/none/service.js +0 -34
- package/esm/commands/subprocess/none/service.js.map +0 -1
- package/esm/commands/subprocess/none/spawner.d.ts +0 -19
- package/esm/commands/subprocess/none/spawner.d.ts.map +0 -1
- package/esm/commands/subprocess/none/spawner.js +0 -26
- package/esm/commands/subprocess/none/spawner.js.map +0 -1
- package/esm/commands/subprocess/pty.d.ts.map +0 -1
- package/esm/commands/subprocess/service.d.ts.map +0 -1
- package/esm/commands/subprocess/service.js.map +0 -1
- package/esm/commands/subprocess/shell/index.d.ts +0 -6
- package/esm/commands/subprocess/shell/index.d.ts.map +0 -1
- package/esm/commands/subprocess/shell/index.js +0 -6
- package/esm/commands/subprocess/shell/index.js.map +0 -1
- package/esm/commands/subprocess/shell/process.d.ts.map +0 -1
- package/esm/commands/subprocess/shell/process.js.map +0 -1
- package/esm/commands/subprocess/shell/pty.d.ts.map +0 -1
- package/esm/commands/subprocess/shell/pty.js.map +0 -1
- package/esm/commands/subprocess/shell/service.d.ts +0 -14
- package/esm/commands/subprocess/shell/service.d.ts.map +0 -1
- package/esm/commands/subprocess/shell/service.js +0 -41
- package/esm/commands/subprocess/shell/service.js.map +0 -1
- package/esm/commands/subprocess/shell/shared.d.ts +0 -19
- package/esm/commands/subprocess/shell/shared.d.ts.map +0 -1
- package/esm/commands/subprocess/shell/shared.js.map +0 -1
- package/esm/commands/subprocess/shell/spawner.d.ts.map +0 -1
- package/esm/commands/subprocess/shell/spawner.js +0 -38
- package/esm/commands/subprocess/shell/spawner.js.map +0 -1
- package/esm/commands/subprocess/utils.d.ts +0 -3
- package/esm/commands/subprocess/utils.d.ts.map +0 -1
- package/esm/commands/subprocess/utils.js +0 -56
- package/esm/commands/subprocess/utils.js.map +0 -1
- package/esm/commands/sync/index.d.ts +0 -9
- package/esm/commands/sync/index.d.ts.map +0 -1
- package/esm/commands/sync/index.js +0 -9
- package/esm/commands/sync/index.js.map +0 -1
- package/esm/commands/sync/list.d.ts.map +0 -1
- package/esm/commands/sync/list.js +0 -64
- package/esm/commands/sync/list.js.map +0 -1
- package/esm/commands/sync/pull.d.ts +0 -12
- package/esm/commands/sync/pull.d.ts.map +0 -1
- package/esm/commands/sync/pull.js +0 -33
- package/esm/commands/sync/pull.js.map +0 -1
- package/esm/commands/sync/push.d.ts +0 -61
- package/esm/commands/sync/push.d.ts.map +0 -1
- package/esm/commands/sync/push.js +0 -83
- package/esm/commands/sync/push.js.map +0 -1
- package/esm/commands/sync/request.d.ts +0 -24
- package/esm/commands/sync/request.d.ts.map +0 -1
- package/esm/commands/sync/request.js +0 -32
- package/esm/commands/sync/request.js.map +0 -1
- package/esm/commands/sync/response.d.ts +0 -28
- package/esm/commands/sync/response.d.ts.map +0 -1
- package/esm/commands/sync/response.js +0 -81
- package/esm/commands/sync/response.js.map +0 -1
- package/esm/commands/sync/socket.d.ts +0 -22
- package/esm/commands/sync/socket.d.ts.map +0 -1
- package/esm/commands/sync/socket.js +0 -78
- package/esm/commands/sync/socket.js.map +0 -1
- package/esm/commands/sync/stat.d.ts.map +0 -1
- package/esm/commands/sync/stat.js +0 -121
- package/esm/commands/sync/stat.js.map +0 -1
- package/esm/commands/sync/sync.d.ts +0 -82
- package/esm/commands/sync/sync.d.ts.map +0 -1
- package/esm/commands/sync/sync.js +0 -138
- package/esm/commands/sync/sync.js.map +0 -1
- package/esm/commands/tcpip.d.ts.map +0 -1
- package/esm/commands/tcpip.js.map +0 -1
- package/esm/daemon/auth.d.ts +0 -54
- package/esm/daemon/auth.d.ts.map +0 -1
- package/esm/daemon/auth.js +0 -104
- package/esm/daemon/auth.js.map +0 -1
- package/esm/server/stream.d.ts.map +0 -1
- package/esm/server/stream.js.map +0 -1
- package/src/commands/base.ts +0 -15
- package/src/commands/subprocess/none/service.ts +0 -45
- package/src/commands/subprocess/none/spawner.ts +0 -68
- package/src/commands/subprocess/shell/service.ts +0 -58
- package/src/commands/subprocess/shell/spawner.ts +0 -90
- package/src/commands/subprocess/utils.ts +0 -61
- package/src/commands/sync/index.ts +0 -8
- package/src/commands/sync/list.ts +0 -99
- package/src/commands/sync/pull.ts +0 -55
- package/src/commands/sync/push.ts +0 -172
- package/src/commands/sync/request.ts +0 -53
- package/src/commands/sync/response.ts +0 -105
- package/src/commands/sync/socket.ts +0 -109
- package/src/commands/sync/stat.ts +0 -177
- package/src/commands/sync/sync.ts +0 -175
- package/src/daemon/auth.ts +0 -203
- package/tsconfig.build.tsbuildinfo +0 -1
- /package/esm/{commands → service}/framebuffer.d.ts +0 -0
- /package/esm/{commands → service}/framebuffer.js +0 -0
- /package/esm/{commands → service}/subprocess/none/index.d.ts +0 -0
- /package/esm/{commands → service}/subprocess/none/index.js +0 -0
- /package/esm/{commands → service}/subprocess/none/process.js +0 -0
- /package/esm/{commands → service}/subprocess/pty.js +0 -0
- /package/esm/{commands → service}/subprocess/service.d.ts +0 -0
- /package/src/{commands → service}/framebuffer.ts +0 -0
- /package/src/{commands → service}/subprocess/none/index.ts +0 -0
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import type { MaybePromiseLike } from "@yume-chan/async";
|
|
2
|
+
import { EmptyUint8Array, encodeUtf8 } from "@yume-chan/struct";
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
calculateBase64EncodedLength,
|
|
6
|
+
encodeBase64,
|
|
7
|
+
} from "../../utils/base64.js";
|
|
8
|
+
import { rsaSign } from "../crypto.js";
|
|
9
|
+
import type { AdbPacketData } from "../packet.js";
|
|
10
|
+
import { AdbCommand } from "../packet.js";
|
|
11
|
+
|
|
12
|
+
import type { AdbDaemonAuthProcessor } from "./authenticator.js";
|
|
13
|
+
import {
|
|
14
|
+
adbGeneratePublicKey,
|
|
15
|
+
adbGetPublicKeyFingerprint,
|
|
16
|
+
adbGetPublicKeySize,
|
|
17
|
+
} from "./public-key.js";
|
|
18
|
+
import type { AdbPrivateKey } from "./type.js";
|
|
19
|
+
|
|
20
|
+
export type MaybeError<T> = T | Error;
|
|
21
|
+
|
|
22
|
+
export type AdbKeyIterable =
|
|
23
|
+
| Iterable<MaybeError<AdbPrivateKey>>
|
|
24
|
+
| AsyncIterable<MaybeError<AdbPrivateKey>>;
|
|
25
|
+
|
|
26
|
+
export interface AdbCredentialManager {
|
|
27
|
+
/**
|
|
28
|
+
* Generates and stores a RSA private key with modulus length `2048` and public exponent `65537`.
|
|
29
|
+
*/
|
|
30
|
+
generateKey(): MaybePromiseLike<AdbPrivateKey>;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Synchronously or asynchronously iterates through all stored RSA private keys.
|
|
34
|
+
*
|
|
35
|
+
* Each call to `iterateKeys` must return a different iterator that iterate through all stored keys.
|
|
36
|
+
*/
|
|
37
|
+
iterateKeys(): AdbKeyIterable;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface AdbKeyInfo {
|
|
41
|
+
fingerprint: string;
|
|
42
|
+
name: string | undefined;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export const AdbDaemonAuthType = {
|
|
46
|
+
Token: 1,
|
|
47
|
+
Signature: 2,
|
|
48
|
+
PublicKey: 3,
|
|
49
|
+
} as const;
|
|
50
|
+
|
|
51
|
+
export type AdbDaemonAuthType =
|
|
52
|
+
(typeof AdbDaemonAuthType)[keyof typeof AdbDaemonAuthType];
|
|
53
|
+
|
|
54
|
+
export interface AdbDaemonDefaultAuthProcessorInit {
|
|
55
|
+
credentialManager: AdbCredentialManager;
|
|
56
|
+
onKeyLoadError?: ((error: Error) => void) | undefined;
|
|
57
|
+
onSignatureAuthentication?: ((key: AdbKeyInfo) => void) | undefined;
|
|
58
|
+
onSignatureRejected?: ((key: AdbKeyInfo) => void) | undefined;
|
|
59
|
+
onPublicKeyAuthentication?: ((key: AdbKeyInfo) => void) | undefined;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export class AdbDaemonDefaultAuthProcessor implements AdbDaemonAuthProcessor {
|
|
63
|
+
#credentialManager: AdbCredentialManager;
|
|
64
|
+
#onKeyLoadError: ((error: Error) => void) | undefined;
|
|
65
|
+
#onSignatureAuthentication: ((key: AdbKeyInfo) => void) | undefined;
|
|
66
|
+
#onSignatureRejected: ((key: AdbKeyInfo) => void) | undefined;
|
|
67
|
+
#onPublicKeyAuthentication: ((key: AdbKeyInfo) => void) | undefined;
|
|
68
|
+
|
|
69
|
+
#iterator:
|
|
70
|
+
| Iterator<MaybeError<AdbPrivateKey>, void, void>
|
|
71
|
+
| AsyncIterator<MaybeError<AdbPrivateKey>, void, void>
|
|
72
|
+
| undefined;
|
|
73
|
+
|
|
74
|
+
#prevKeyInfo: AdbKeyInfo | undefined;
|
|
75
|
+
#firstKey: AdbPrivateKey | undefined;
|
|
76
|
+
|
|
77
|
+
constructor(init: AdbDaemonDefaultAuthProcessorInit) {
|
|
78
|
+
this.#credentialManager = init.credentialManager;
|
|
79
|
+
this.#onKeyLoadError = init.onKeyLoadError;
|
|
80
|
+
this.#onSignatureAuthentication = init.onSignatureAuthentication;
|
|
81
|
+
this.#onSignatureRejected = init.onSignatureRejected;
|
|
82
|
+
this.#onPublicKeyAuthentication = init.onPublicKeyAuthentication;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Gets the next available private key.
|
|
87
|
+
* @returns The next available private key, or `undefined` if no more key is available
|
|
88
|
+
*/
|
|
89
|
+
async #getNextKey() {
|
|
90
|
+
if (!this.#iterator) {
|
|
91
|
+
const iterable = this.#credentialManager.iterateKeys();
|
|
92
|
+
if (Symbol.iterator in iterable) {
|
|
93
|
+
this.#iterator = iterable[Symbol.iterator]();
|
|
94
|
+
} else if (Symbol.asyncIterator in iterable) {
|
|
95
|
+
this.#iterator = iterable[Symbol.asyncIterator]();
|
|
96
|
+
} else {
|
|
97
|
+
throw new Error("`iterateKeys` doesn't return an iterator");
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
while (true) {
|
|
102
|
+
const { done, value } = await this.#iterator.next();
|
|
103
|
+
if (done) {
|
|
104
|
+
return undefined;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (value instanceof Error) {
|
|
108
|
+
// Report the error, then continue calling `next`
|
|
109
|
+
this.#onKeyLoadError?.(value);
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return value;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Tries to sign the challenge using the next private key.
|
|
119
|
+
*
|
|
120
|
+
* @param challenge The data to sign
|
|
121
|
+
* @returns An `AdbPacket` containing the response, or `undefined` if no key is available
|
|
122
|
+
*/
|
|
123
|
+
async #sign(challenge: Uint8Array): Promise<AdbPacketData | undefined> {
|
|
124
|
+
const key = await this.#getNextKey();
|
|
125
|
+
if (!key) {
|
|
126
|
+
return undefined;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (!this.#firstKey) {
|
|
130
|
+
this.#firstKey = key;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// A new challenge implies the previous signature was rejected.
|
|
134
|
+
if (this.#prevKeyInfo) {
|
|
135
|
+
this.#onSignatureRejected?.(this.#prevKeyInfo);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const fingerprint = adbGetPublicKeyFingerprint(key);
|
|
139
|
+
this.#prevKeyInfo = { fingerprint, name: key.name };
|
|
140
|
+
this.#onSignatureAuthentication?.(this.#prevKeyInfo);
|
|
141
|
+
|
|
142
|
+
return {
|
|
143
|
+
command: AdbCommand.Auth,
|
|
144
|
+
arg0: AdbDaemonAuthType.Signature,
|
|
145
|
+
arg1: 0,
|
|
146
|
+
payload: rsaSign(key, challenge),
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
async process(packet: AdbPacketData): Promise<AdbPacketData> {
|
|
151
|
+
if (packet.arg0 !== AdbDaemonAuthType.Token) {
|
|
152
|
+
throw new Error("Unsupported authentication packet");
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const signature = await this.#sign(packet.payload);
|
|
156
|
+
if (signature) {
|
|
157
|
+
return signature;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
let key = this.#firstKey;
|
|
161
|
+
if (!key) {
|
|
162
|
+
key = await this.#credentialManager.generateKey();
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const publicKeyLength = adbGetPublicKeySize();
|
|
166
|
+
const [publicKeyBase64Length] =
|
|
167
|
+
calculateBase64EncodedLength(publicKeyLength);
|
|
168
|
+
|
|
169
|
+
const nameBuffer = key.name?.length
|
|
170
|
+
? encodeUtf8(key.name)
|
|
171
|
+
: EmptyUint8Array;
|
|
172
|
+
const publicKeyBuffer = new Uint8Array(
|
|
173
|
+
publicKeyBase64Length +
|
|
174
|
+
(nameBuffer.length ? nameBuffer.length + 1 : 0) + // Space character + name
|
|
175
|
+
1, // Null character
|
|
176
|
+
);
|
|
177
|
+
|
|
178
|
+
adbGeneratePublicKey(key, publicKeyBuffer);
|
|
179
|
+
const fingerprint = adbGetPublicKeyFingerprint(
|
|
180
|
+
publicKeyBuffer.subarray(0, publicKeyLength),
|
|
181
|
+
);
|
|
182
|
+
|
|
183
|
+
encodeBase64(
|
|
184
|
+
publicKeyBuffer.subarray(0, publicKeyLength),
|
|
185
|
+
publicKeyBuffer,
|
|
186
|
+
);
|
|
187
|
+
|
|
188
|
+
if (nameBuffer.length) {
|
|
189
|
+
publicKeyBuffer[publicKeyBase64Length] = 0x20;
|
|
190
|
+
publicKeyBuffer.set(nameBuffer, publicKeyBase64Length + 1);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
this.#onPublicKeyAuthentication?.({
|
|
194
|
+
fingerprint,
|
|
195
|
+
name: key.name,
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
return {
|
|
199
|
+
command: AdbCommand.Auth,
|
|
200
|
+
arg0: AdbDaemonAuthType.PublicKey,
|
|
201
|
+
arg1: 0,
|
|
202
|
+
payload: publicKeyBuffer,
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
async close(): Promise<undefined> {
|
|
207
|
+
await this.#iterator?.return?.();
|
|
208
|
+
|
|
209
|
+
this.#iterator = undefined;
|
|
210
|
+
this.#firstKey = undefined;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { md5Digest } from "../../utils/md5.js";
|
|
2
|
+
import type { SimpleRsaPrivateKey } from "../crypto.js";
|
|
3
|
+
import { modInverse, setBigUint } from "../crypto.js";
|
|
4
|
+
|
|
5
|
+
import type { AdbPrivateKey } from "./type.js";
|
|
6
|
+
|
|
7
|
+
const ModulusLengthInBytes = 2048 / 8;
|
|
8
|
+
const ModulusLengthInWords = ModulusLengthInBytes / 4;
|
|
9
|
+
|
|
10
|
+
export function adbGetPublicKeySize() {
|
|
11
|
+
return 4 + 4 + ModulusLengthInBytes + ModulusLengthInBytes + 4;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function adbGeneratePublicKey(
|
|
15
|
+
privateKey: SimpleRsaPrivateKey,
|
|
16
|
+
): Uint8Array<ArrayBuffer>;
|
|
17
|
+
export function adbGeneratePublicKey(
|
|
18
|
+
privateKey: SimpleRsaPrivateKey,
|
|
19
|
+
output: Uint8Array,
|
|
20
|
+
): number;
|
|
21
|
+
export function adbGeneratePublicKey(
|
|
22
|
+
privateKey: SimpleRsaPrivateKey,
|
|
23
|
+
output?: Uint8Array,
|
|
24
|
+
): Uint8Array | number {
|
|
25
|
+
// cspell: ignore: mincrypt
|
|
26
|
+
// Android 6 and earlier has its own encryption library called mincrypt
|
|
27
|
+
// This is the RSA public key format used by mincrypt:
|
|
28
|
+
// https://android.googlesource.com/platform/system/core/+/bb0c180e62703c2068a1b2c9f8ba6d634bf1553c/include/mincrypt/rsa.h#46
|
|
29
|
+
// `n0inv` and `rr` are pre-calculated to speed up RSA operations
|
|
30
|
+
|
|
31
|
+
// Android 7 switched its encryption library to BoringSSL, but still keeps the key format:
|
|
32
|
+
// https://android.googlesource.com/platform/system/core.git/+/91784040db2b9273687f88d8b95f729d4a61ecc2/libcrypto_utils/android_pubkey.cpp#38
|
|
33
|
+
// Except when reading a key, `n0inv` and `rr` are ignored (they are still populated when generating a key):
|
|
34
|
+
// https://android.googlesource.com/platform/system/core.git/+/91784040db2b9273687f88d8b95f729d4a61ecc2/libcrypto_utils/android_pubkey.cpp#55
|
|
35
|
+
|
|
36
|
+
// The public key is a struct (in little endian) of:
|
|
37
|
+
//
|
|
38
|
+
// [
|
|
39
|
+
// modulusLengthInWords, // 32-bit integer, a "word" is 32-bit so it must be 2048 / 8 / 4
|
|
40
|
+
// // (the comment in Android source code is incorrect saying "This must be ANDROID_PUBKEY_MODULUS_SIZE")
|
|
41
|
+
// n0inv, // 32-bit integer, the modular inverse of (lower 32 bits of `n`)
|
|
42
|
+
// modulus, // `n`
|
|
43
|
+
// rr, // Montgomery parameter R^2
|
|
44
|
+
// exponent, // 32-bit integer, must be 3 or 65537
|
|
45
|
+
// ]
|
|
46
|
+
|
|
47
|
+
let outputType: "Uint8Array" | "number";
|
|
48
|
+
const outputLength = adbGetPublicKeySize();
|
|
49
|
+
if (!output) {
|
|
50
|
+
output = new Uint8Array(outputLength);
|
|
51
|
+
outputType = "Uint8Array";
|
|
52
|
+
} else {
|
|
53
|
+
if (output.length < outputLength) {
|
|
54
|
+
throw new TypeError("output buffer is too small");
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
outputType = "number";
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const outputView = new DataView(
|
|
61
|
+
output.buffer,
|
|
62
|
+
output.byteOffset,
|
|
63
|
+
output.length,
|
|
64
|
+
);
|
|
65
|
+
let outputOffset = 0;
|
|
66
|
+
|
|
67
|
+
// modulusLengthInWords
|
|
68
|
+
outputView.setUint32(outputOffset, ModulusLengthInWords, true);
|
|
69
|
+
outputOffset += 4;
|
|
70
|
+
|
|
71
|
+
// extract `n` from private key
|
|
72
|
+
const { n } = privateKey;
|
|
73
|
+
|
|
74
|
+
// Calculate `n0inv`
|
|
75
|
+
const n0inv = -modInverse(Number(n % 2n ** 32n), 2 ** 32);
|
|
76
|
+
outputView.setInt32(outputOffset, n0inv, true);
|
|
77
|
+
outputOffset += 4;
|
|
78
|
+
|
|
79
|
+
// Write `n` (a.k.a. `modulus`)
|
|
80
|
+
setBigUint(output, outputOffset, ModulusLengthInBytes, n, true);
|
|
81
|
+
outputOffset += ModulusLengthInBytes;
|
|
82
|
+
|
|
83
|
+
// Calculate rr = (2 ** (rsa_size)) ** 2 % n
|
|
84
|
+
const rr = 2n ** 4096n % n;
|
|
85
|
+
setBigUint(output, outputOffset, ModulusLengthInBytes, rr, true);
|
|
86
|
+
outputOffset += ModulusLengthInBytes;
|
|
87
|
+
|
|
88
|
+
// exponent
|
|
89
|
+
outputView.setUint32(outputOffset, 65537, true);
|
|
90
|
+
|
|
91
|
+
if (outputType === "Uint8Array") {
|
|
92
|
+
return output;
|
|
93
|
+
} else {
|
|
94
|
+
return outputLength;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// https://cs.android.com/android/platform/superproject/main/+/main:frameworks/base/services/core/java/com/android/server/adb/AdbDebuggingManager.java;l=1419;drc=61197364367c9e404c7da6900658f1b16c42d0da
|
|
99
|
+
export function adbGetPublicKeyFingerprint(privateKey: AdbPrivateKey): string;
|
|
100
|
+
export function adbGetPublicKeyFingerprint(publicKey: Uint8Array): string;
|
|
101
|
+
export function adbGetPublicKeyFingerprint(
|
|
102
|
+
key: AdbPrivateKey | Uint8Array,
|
|
103
|
+
): string {
|
|
104
|
+
if ("d" in key) {
|
|
105
|
+
key = adbGeneratePublicKey(key);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const md5 = md5Digest(key);
|
|
109
|
+
return Array.from(md5, (byte) => byte.toString(16).padStart(2, "0")).join(
|
|
110
|
+
":",
|
|
111
|
+
);
|
|
112
|
+
}
|
package/src/daemon/crypto.ts
CHANGED
|
@@ -48,11 +48,14 @@ export function setBigUint(
|
|
|
48
48
|
littleEndian?: boolean,
|
|
49
49
|
) {
|
|
50
50
|
if (littleEndian) {
|
|
51
|
+
const end = byteOffset + length;
|
|
51
52
|
while (value > 0n) {
|
|
52
53
|
setInt64LittleEndian(array, byteOffset, value);
|
|
53
54
|
byteOffset += 8;
|
|
54
55
|
value >>= 64n;
|
|
55
56
|
}
|
|
57
|
+
// Clear the trailing bytes
|
|
58
|
+
array.subarray(byteOffset, end).fill(0);
|
|
56
59
|
} else {
|
|
57
60
|
let position = byteOffset + length - 8;
|
|
58
61
|
while (value > 0n) {
|
|
@@ -60,9 +63,16 @@ export function setBigUint(
|
|
|
60
63
|
position -= 8;
|
|
61
64
|
value >>= 64n;
|
|
62
65
|
}
|
|
66
|
+
// Clear the leading bytes
|
|
67
|
+
array.subarray(byteOffset, position + 8).fill(0);
|
|
63
68
|
}
|
|
64
69
|
}
|
|
65
70
|
|
|
71
|
+
export interface SimpleRsaPrivateKey {
|
|
72
|
+
n: bigint;
|
|
73
|
+
d: bigint;
|
|
74
|
+
}
|
|
75
|
+
|
|
66
76
|
// These values are correct only if
|
|
67
77
|
// modulus length is 2048 and
|
|
68
78
|
// public exponent (e) is 65537
|
|
@@ -89,10 +99,16 @@ const RsaPrivateKeyNLength = 2048 / 8;
|
|
|
89
99
|
const RsaPrivateKeyDOffset = 303;
|
|
90
100
|
const RsaPrivateKeyDLength = 2048 / 8;
|
|
91
101
|
|
|
92
|
-
export function rsaParsePrivateKey(key: Uint8Array):
|
|
102
|
+
export function rsaParsePrivateKey(key: Uint8Array): SimpleRsaPrivateKey {
|
|
103
|
+
if (key.length < RsaPrivateKeyDOffset + RsaPrivateKeyDLength) {
|
|
104
|
+
throw new Error(
|
|
105
|
+
"RSA private key is too short. Expecting a PKCS#8 formatted RSA private key with modulus length 2048 bits and public exponent 65537.",
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
|
|
93
109
|
const n = getBigUint(key, RsaPrivateKeyNOffset, RsaPrivateKeyNLength);
|
|
94
110
|
const d = getBigUint(key, RsaPrivateKeyDOffset, RsaPrivateKeyDLength);
|
|
95
|
-
return
|
|
111
|
+
return { n, d };
|
|
96
112
|
}
|
|
97
113
|
|
|
98
114
|
function nonNegativeMod(m: number, d: number) {
|
|
@@ -133,97 +149,6 @@ export function modInverse(a: number, m: number) {
|
|
|
133
149
|
return nonNegativeMod(y, m);
|
|
134
150
|
}
|
|
135
151
|
|
|
136
|
-
const ModulusLengthInBytes = 2048 / 8;
|
|
137
|
-
const ModulusLengthInWords = ModulusLengthInBytes / 4;
|
|
138
|
-
|
|
139
|
-
export function adbGetPublicKeySize() {
|
|
140
|
-
return 4 + 4 + ModulusLengthInBytes + ModulusLengthInBytes + 4;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
export function adbGeneratePublicKey(
|
|
144
|
-
privateKey: Uint8Array,
|
|
145
|
-
): Uint8Array<ArrayBuffer>;
|
|
146
|
-
export function adbGeneratePublicKey(
|
|
147
|
-
privateKey: Uint8Array,
|
|
148
|
-
output: Uint8Array,
|
|
149
|
-
): number;
|
|
150
|
-
export function adbGeneratePublicKey(
|
|
151
|
-
privateKey: Uint8Array,
|
|
152
|
-
output?: Uint8Array,
|
|
153
|
-
): Uint8Array | number {
|
|
154
|
-
// cspell: ignore: mincrypt
|
|
155
|
-
// Android 6 and earlier has its own encryption library called mincrypt
|
|
156
|
-
// This is the RSA public key format used by mincrypt:
|
|
157
|
-
// https://android.googlesource.com/platform/system/core/+/bb0c180e62703c2068a1b2c9f8ba6d634bf1553c/include/mincrypt/rsa.h#46
|
|
158
|
-
// `n0inv` and `rr` are pre-calculated to speed up RSA operations
|
|
159
|
-
|
|
160
|
-
// Android 7 switched its encryption library to BoringSSL, but still keeps the key format:
|
|
161
|
-
// https://android.googlesource.com/platform/system/core.git/+/91784040db2b9273687f88d8b95f729d4a61ecc2/libcrypto_utils/android_pubkey.cpp#38
|
|
162
|
-
// Except when reading a key, `n0inv` and `rr` are ignored (they are still populated when generating a key):
|
|
163
|
-
// https://android.googlesource.com/platform/system/core.git/+/91784040db2b9273687f88d8b95f729d4a61ecc2/libcrypto_utils/android_pubkey.cpp#55
|
|
164
|
-
|
|
165
|
-
// The public key is a struct (in little endian) of:
|
|
166
|
-
//
|
|
167
|
-
// [
|
|
168
|
-
// modulusLengthInWords, // 32-bit integer, a "word" is 32-bit so it must be 2048 / 8 / 4
|
|
169
|
-
// // (the comment in Android source code is incorrect saying "This must be ANDROID_PUBKEY_MODULUS_SIZE")
|
|
170
|
-
// n0inv, // 32-bit integer, the modular inverse of (lower 32 bits of `n`)
|
|
171
|
-
// modulus, // `n`
|
|
172
|
-
// rr, // Montgomery parameter R^2
|
|
173
|
-
// exponent, // 32-bit integer, must be 3 or 65537
|
|
174
|
-
// ]
|
|
175
|
-
|
|
176
|
-
let outputType: "Uint8Array" | "number";
|
|
177
|
-
const outputLength = adbGetPublicKeySize();
|
|
178
|
-
if (!output) {
|
|
179
|
-
output = new Uint8Array(outputLength);
|
|
180
|
-
outputType = "Uint8Array";
|
|
181
|
-
} else {
|
|
182
|
-
if (output.length < outputLength) {
|
|
183
|
-
throw new TypeError("output buffer is too small");
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
outputType = "number";
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
const outputView = new DataView(
|
|
190
|
-
output.buffer,
|
|
191
|
-
output.byteOffset,
|
|
192
|
-
output.length,
|
|
193
|
-
);
|
|
194
|
-
let outputOffset = 0;
|
|
195
|
-
|
|
196
|
-
// modulusLengthInWords
|
|
197
|
-
outputView.setUint32(outputOffset, ModulusLengthInWords, true);
|
|
198
|
-
outputOffset += 4;
|
|
199
|
-
|
|
200
|
-
// extract `n` from private key
|
|
201
|
-
const [n] = rsaParsePrivateKey(privateKey);
|
|
202
|
-
|
|
203
|
-
// Calculate `n0inv`
|
|
204
|
-
const n0inv = -modInverse(Number(n % 2n ** 32n), 2 ** 32);
|
|
205
|
-
outputView.setInt32(outputOffset, n0inv, true);
|
|
206
|
-
outputOffset += 4;
|
|
207
|
-
|
|
208
|
-
// Write `n` (a.k.a. `modulus`)
|
|
209
|
-
setBigUint(output, outputOffset, ModulusLengthInBytes, n, true);
|
|
210
|
-
outputOffset += ModulusLengthInBytes;
|
|
211
|
-
|
|
212
|
-
// Calculate rr = (2 ** (rsa_size)) ** 2 % n
|
|
213
|
-
const rr = 2n ** 4096n % n;
|
|
214
|
-
setBigUint(output, outputOffset, ModulusLengthInBytes, rr, true);
|
|
215
|
-
outputOffset += ModulusLengthInBytes;
|
|
216
|
-
|
|
217
|
-
// exponent
|
|
218
|
-
outputView.setUint32(outputOffset, 65537, true);
|
|
219
|
-
|
|
220
|
-
if (outputType === "Uint8Array") {
|
|
221
|
-
return output;
|
|
222
|
-
} else {
|
|
223
|
-
return outputLength;
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
|
|
227
152
|
/**
|
|
228
153
|
* Modular exponentiation.
|
|
229
154
|
*
|
|
@@ -282,17 +207,27 @@ export const SHA1_DIGEST_INFO = new Uint8Array([
|
|
|
282
207
|
SHA1_DIGEST_LENGTH,
|
|
283
208
|
]);
|
|
284
209
|
|
|
285
|
-
//
|
|
286
|
-
//
|
|
287
|
-
//
|
|
288
|
-
//
|
|
289
|
-
//
|
|
290
|
-
//
|
|
210
|
+
// Standard `RSASSA-PKCS1-v1_5` algorithm will hash the given data
|
|
211
|
+
// and sign the hash
|
|
212
|
+
// https://datatracker.ietf.org/doc/html/rfc8017#section-8.2
|
|
213
|
+
//
|
|
214
|
+
// But ADB authentication passes 20 bytes of random value to
|
|
215
|
+
// OpenSSL's `RSA_sign` method which treat the input as a hash
|
|
216
|
+
// https://docs.openssl.org/1.0.2/man3/RSA_sign/
|
|
217
|
+
//
|
|
218
|
+
// Since it's non-standard and not supported by Web Crypto API,
|
|
219
|
+
// we need to implement the signing by ourself
|
|
291
220
|
export function rsaSign(
|
|
292
|
-
privateKey:
|
|
221
|
+
privateKey: SimpleRsaPrivateKey,
|
|
293
222
|
data: Uint8Array,
|
|
294
223
|
): Uint8Array<ArrayBuffer> {
|
|
295
|
-
|
|
224
|
+
if (data.length !== SHA1_DIGEST_LENGTH) {
|
|
225
|
+
throw new Error(
|
|
226
|
+
`rsaSign expects ${SHA1_DIGEST_LENGTH} bytes (SHA-1 digest length) of data but got ${data.length} bytes`,
|
|
227
|
+
);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
const { n, d } = privateKey;
|
|
296
231
|
|
|
297
232
|
// PKCS#1 padding
|
|
298
233
|
const padded = new Uint8Array(256);
|
package/src/daemon/dispatcher.ts
CHANGED
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
} from "@yume-chan/stream-extra";
|
|
20
20
|
import { EmptyUint8Array, decodeUtf8, encodeUtf8 } from "@yume-chan/struct";
|
|
21
21
|
|
|
22
|
-
import type {
|
|
22
|
+
import type { Adb, Closeable } from "../adb.js";
|
|
23
23
|
|
|
24
24
|
import type { AdbPacketData, AdbPacketInit } from "./packet.js";
|
|
25
25
|
import { AdbCommand, calculateChecksum } from "./packet.js";
|
|
@@ -114,7 +114,7 @@ export class AdbPacketDispatcher implements Closeable {
|
|
|
114
114
|
|
|
115
115
|
readonly #incomingSocketHandlers = new Map<
|
|
116
116
|
string,
|
|
117
|
-
|
|
117
|
+
Adb.IncomingSocketHandler
|
|
118
118
|
>();
|
|
119
119
|
readonly #readAbortController = new AbortController();
|
|
120
120
|
|
|
@@ -146,13 +146,20 @@ export class AdbPacketDispatcher implements Closeable {
|
|
|
146
146
|
this.#handleOkay(packet);
|
|
147
147
|
break;
|
|
148
148
|
case AdbCommand.Open:
|
|
149
|
-
await
|
|
149
|
+
// Don't await
|
|
150
|
+
// The handler may take a long time to accept the socket,
|
|
151
|
+
// don't block other sockets' packet processing.
|
|
152
|
+
this.#handleOpen(packet).catch((e) => {
|
|
153
|
+
// Propagate fatal errors to consumer
|
|
154
|
+
controller.error(e);
|
|
155
|
+
});
|
|
150
156
|
break;
|
|
151
157
|
case AdbCommand.Write:
|
|
152
|
-
// Don't await
|
|
153
|
-
//
|
|
154
|
-
//
|
|
158
|
+
// Don't await
|
|
159
|
+
// The socket might be stalled because of backpressure,
|
|
160
|
+
// don't block other sockets' packet processing.
|
|
155
161
|
this.#handleWrite(packet).catch((e) => {
|
|
162
|
+
// Propagate fatal errors to consumer
|
|
156
163
|
controller.error(e);
|
|
157
164
|
});
|
|
158
165
|
break;
|
|
@@ -392,7 +399,7 @@ export class AdbPacketDispatcher implements Closeable {
|
|
|
392
399
|
await Promise.race(promises);
|
|
393
400
|
}
|
|
394
401
|
|
|
395
|
-
async createSocket(service: string): Promise<
|
|
402
|
+
async createSocket(service: string): Promise<Adb.Socket> {
|
|
396
403
|
if (this.options.appendNullToServiceString) {
|
|
397
404
|
service += "\0";
|
|
398
405
|
}
|
|
@@ -421,7 +428,7 @@ export class AdbPacketDispatcher implements Closeable {
|
|
|
421
428
|
return controller.socket;
|
|
422
429
|
}
|
|
423
430
|
|
|
424
|
-
addReverseTunnel(service: string, handler:
|
|
431
|
+
addReverseTunnel(service: string, handler: Adb.IncomingSocketHandler) {
|
|
425
432
|
this.#incomingSocketHandlers.set(service, handler);
|
|
426
433
|
}
|
|
427
434
|
|
package/src/daemon/index.ts
CHANGED
package/src/daemon/socket.ts
CHANGED
|
@@ -9,7 +9,7 @@ import type {
|
|
|
9
9
|
import { MaybeConsumable, PushReadableStream } from "@yume-chan/stream-extra";
|
|
10
10
|
import { EmptyUint8Array } from "@yume-chan/struct";
|
|
11
11
|
|
|
12
|
-
import type {
|
|
12
|
+
import type { Adb } from "../adb.js";
|
|
13
13
|
|
|
14
14
|
import type { AdbPacketDispatcher } from "./dispatcher.js";
|
|
15
15
|
import { AdbCommand } from "./packet.js";
|
|
@@ -34,7 +34,7 @@ export interface AdbDaemonSocketInit extends AdbDaemonSocketInfo {
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
export class AdbDaemonSocketController
|
|
37
|
-
implements AdbDaemonSocketInfo,
|
|
37
|
+
implements AdbDaemonSocketInfo, Adb.Socket, Disposable
|
|
38
38
|
{
|
|
39
39
|
readonly #dispatcher!: AdbPacketDispatcher;
|
|
40
40
|
|
|
@@ -177,7 +177,7 @@ export class AdbDaemonSocketController
|
|
|
177
177
|
/**
|
|
178
178
|
* A duplex stream representing a socket to ADB daemon.
|
|
179
179
|
*/
|
|
180
|
-
export class AdbDaemonSocket implements AdbDaemonSocketInfo,
|
|
180
|
+
export class AdbDaemonSocket implements AdbDaemonSocketInfo, Adb.Socket {
|
|
181
181
|
readonly #controller: AdbDaemonSocketController;
|
|
182
182
|
|
|
183
183
|
get localId(): number {
|