@yume-chan/adb 2.6.2 → 3.0.0-beta.1
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 +11 -10
- package/esm/server/client.d.ts.map +1 -1
- package/esm/server/client.js +82 -98
- 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 +36 -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 +11 -15
- 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 +50 -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 +7 -7
- 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 +112 -104
- 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 +85 -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 +13 -17
- 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 +113 -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/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,186 @@
|
|
|
1
|
+
import type { MaybePromiseLike } from "@yume-chan/async";
|
|
2
|
+
import { PromiseResolver } from "@yume-chan/async";
|
|
3
|
+
import type { WritableStreamDefaultWriter } from "@yume-chan/stream-extra";
|
|
4
|
+
import {
|
|
5
|
+
AbortController,
|
|
6
|
+
Consumable,
|
|
7
|
+
WritableStream,
|
|
8
|
+
} from "@yume-chan/stream-extra";
|
|
9
|
+
import { decodeUtf8, encodeUtf8 } from "@yume-chan/struct";
|
|
10
|
+
|
|
11
|
+
import { AdbDeviceFeatures, AdbFeature } from "../../features.js";
|
|
12
|
+
import type { AdbPacketData, AdbPacketInit } from "../packet.js";
|
|
13
|
+
import { AdbCommand, calculateChecksum } from "../packet.js";
|
|
14
|
+
import type { AdbDaemonTransportInit } from "../transport.js";
|
|
15
|
+
import {
|
|
16
|
+
ADB_DAEMON_DEFAULT_INITIAL_PAYLOAD_SIZE,
|
|
17
|
+
AdbDaemonTransport,
|
|
18
|
+
} from "../transport.js";
|
|
19
|
+
|
|
20
|
+
import type { AdbDaemonDefaultAuthProcessorInit } from "./packet-processor.js";
|
|
21
|
+
import { AdbDaemonDefaultAuthProcessor } from "./packet-processor.js";
|
|
22
|
+
|
|
23
|
+
export interface AdbDaemonAuthProcessor {
|
|
24
|
+
process(packet: AdbPacketData): Promise<AdbPacketData>;
|
|
25
|
+
|
|
26
|
+
close?(): MaybePromiseLike<undefined>;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export type AdbDaemonAuthenticateOptions = Pick<
|
|
30
|
+
AdbDaemonTransportInit,
|
|
31
|
+
| "serial"
|
|
32
|
+
| "connection"
|
|
33
|
+
| "features"
|
|
34
|
+
| "preserveConnection"
|
|
35
|
+
| "readTimeLimit"
|
|
36
|
+
> & {
|
|
37
|
+
/**
|
|
38
|
+
* The number of bytes the device can send before receiving an ack packet.
|
|
39
|
+
*
|
|
40
|
+
* Android 14 added the Delayed Acknowledgement feature to improve performance,
|
|
41
|
+
* especially for high-latency connections like ADB over Wi-Fi.
|
|
42
|
+
*
|
|
43
|
+
* Unlike {@linkcode AdbDaemonTransportInit.initialDelayedAckBytes},
|
|
44
|
+
* setting this parameter to 0 or a negative number will disable Delayed Ack.
|
|
45
|
+
*/
|
|
46
|
+
initialDelayedAckBytes?: number | undefined;
|
|
47
|
+
} & (AdbDaemonDefaultAuthProcessorInit | { processor: AdbDaemonAuthProcessor });
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Send a packet during authentication stage
|
|
51
|
+
* @param writer Writer to send packet to
|
|
52
|
+
* @param packet The packet to send. Note: this object will be modified.
|
|
53
|
+
*/
|
|
54
|
+
function sendPacket(
|
|
55
|
+
writer: WritableStreamDefaultWriter<Consumable<AdbPacketInit>>,
|
|
56
|
+
packet: AdbPacketData,
|
|
57
|
+
): Promise<void> {
|
|
58
|
+
// Always send checksum in auth steps
|
|
59
|
+
// Because we don't know if the device needs it or not.
|
|
60
|
+
(packet as AdbPacketInit).checksum = calculateChecksum(packet.payload);
|
|
61
|
+
(packet as AdbPacketInit).magic = packet.command ^ 0xffffffff;
|
|
62
|
+
return Consumable.WritableStream.write(writer, packet as AdbPacketInit);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Authenticates an `AdbDaemonConnection` using an `AdbDaemonAuthProcessor`.
|
|
67
|
+
*/
|
|
68
|
+
export async function adbDaemonAuthenticate({
|
|
69
|
+
serial,
|
|
70
|
+
connection,
|
|
71
|
+
features = AdbDeviceFeatures,
|
|
72
|
+
initialDelayedAckBytes = ADB_DAEMON_DEFAULT_INITIAL_PAYLOAD_SIZE,
|
|
73
|
+
preserveConnection,
|
|
74
|
+
readTimeLimit,
|
|
75
|
+
...processorInit
|
|
76
|
+
}: AdbDaemonAuthenticateOptions) {
|
|
77
|
+
const processor =
|
|
78
|
+
"processor" in processorInit
|
|
79
|
+
? processorInit.processor
|
|
80
|
+
: new AdbDaemonDefaultAuthProcessor(processorInit);
|
|
81
|
+
|
|
82
|
+
// Initially, set to highest-supported version and payload size.
|
|
83
|
+
let version = 0x01000001;
|
|
84
|
+
// Android 4: 4K, Android 7: 256K, Android 9: 1M
|
|
85
|
+
let maxPayloadSize = 1024 * 1024;
|
|
86
|
+
|
|
87
|
+
const resolver = new PromiseResolver<string>();
|
|
88
|
+
|
|
89
|
+
const abortController = new AbortController();
|
|
90
|
+
|
|
91
|
+
const writer = connection.writable.getWriter();
|
|
92
|
+
|
|
93
|
+
const pipe = connection.readable
|
|
94
|
+
.pipeTo(
|
|
95
|
+
new WritableStream({
|
|
96
|
+
write: async (packet) => {
|
|
97
|
+
// Here is similar to `AdbPacketDispatcher`,
|
|
98
|
+
// But the received packet types and send packet processing are different.
|
|
99
|
+
switch (packet.command) {
|
|
100
|
+
case AdbCommand.Connect:
|
|
101
|
+
version = Math.min(version, packet.arg0);
|
|
102
|
+
maxPayloadSize = Math.min(
|
|
103
|
+
maxPayloadSize,
|
|
104
|
+
packet.arg1,
|
|
105
|
+
);
|
|
106
|
+
resolver.resolve(decodeUtf8(packet.payload));
|
|
107
|
+
break;
|
|
108
|
+
case AdbCommand.Auth: {
|
|
109
|
+
await sendPacket(
|
|
110
|
+
writer,
|
|
111
|
+
await processor.process(packet),
|
|
112
|
+
);
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
default:
|
|
116
|
+
// Maybe the previous ADB client exited without reading all packets,
|
|
117
|
+
// so they are still waiting in OS internal buffer.
|
|
118
|
+
// Just ignore them.
|
|
119
|
+
// Because a `Connect` packet will reset the device,
|
|
120
|
+
// Eventually there will be `Connect` and `Auth` response packets.
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
}),
|
|
125
|
+
{
|
|
126
|
+
// Don't cancel the source ReadableStream on AbortSignal abort.
|
|
127
|
+
preventCancel: true,
|
|
128
|
+
signal: abortController.signal,
|
|
129
|
+
},
|
|
130
|
+
)
|
|
131
|
+
.then(
|
|
132
|
+
async () => {
|
|
133
|
+
await processor.close?.();
|
|
134
|
+
|
|
135
|
+
// If `resolver` is already settled, call `reject` won't do anything.
|
|
136
|
+
resolver.reject(new Error("Connection closed unexpectedly"));
|
|
137
|
+
},
|
|
138
|
+
async (e) => {
|
|
139
|
+
await processor.close?.();
|
|
140
|
+
|
|
141
|
+
resolver.reject(e);
|
|
142
|
+
},
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
if (initialDelayedAckBytes <= 0) {
|
|
146
|
+
// Disable delayed ack by not sending this feature to the device
|
|
147
|
+
features = features.filter(
|
|
148
|
+
(feature) => feature !== AdbFeature.DelayedAck,
|
|
149
|
+
);
|
|
150
|
+
initialDelayedAckBytes = 0;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
let banner: string;
|
|
154
|
+
try {
|
|
155
|
+
await sendPacket(writer, {
|
|
156
|
+
command: AdbCommand.Connect,
|
|
157
|
+
arg0: version,
|
|
158
|
+
arg1: maxPayloadSize,
|
|
159
|
+
// The terminating `;` is required in formal definition
|
|
160
|
+
// But ADB daemon (all versions) can still work without it
|
|
161
|
+
payload: encodeUtf8(`host::features=${features.join(",")}`),
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
banner = await resolver.promise;
|
|
165
|
+
} finally {
|
|
166
|
+
// When failed, release locks on `connection` so the caller can try again.
|
|
167
|
+
// When success, also release locks so `AdbPacketDispatcher` can use them.
|
|
168
|
+
abortController.abort();
|
|
169
|
+
writer.releaseLock();
|
|
170
|
+
|
|
171
|
+
// Wait until pipe stops (`ReadableStream` lock released)
|
|
172
|
+
await pipe;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
return new AdbDaemonTransport({
|
|
176
|
+
serial,
|
|
177
|
+
connection,
|
|
178
|
+
version,
|
|
179
|
+
maxPayloadSize,
|
|
180
|
+
banner,
|
|
181
|
+
features,
|
|
182
|
+
initialDelayedAckBytes,
|
|
183
|
+
preserveConnection,
|
|
184
|
+
readTimeLimit,
|
|
185
|
+
});
|
|
186
|
+
}
|
|
@@ -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
|
+
}
|