@bharper/atv-js 0.2.3
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.md +21 -0
- package/README.md +80 -0
- package/dist/airplay/auth.d.ts +24 -0
- package/dist/airplay/auth.d.ts.map +1 -0
- package/dist/airplay/auth.js +195 -0
- package/dist/airplay/auth.js.map +1 -0
- package/dist/bplist.d.ts +19 -0
- package/dist/bplist.d.ts.map +1 -0
- package/dist/bplist.js +141 -0
- package/dist/bplist.js.map +1 -0
- package/dist/companion/auth.d.ts +34 -0
- package/dist/companion/auth.d.ts.map +1 -0
- package/dist/companion/auth.js +119 -0
- package/dist/companion/auth.js.map +1 -0
- package/dist/companion/connection.d.ts +50 -0
- package/dist/companion/connection.d.ts.map +1 -0
- package/dist/companion/connection.js +170 -0
- package/dist/companion/connection.js.map +1 -0
- package/dist/companion/keyboard.d.ts +39 -0
- package/dist/companion/keyboard.d.ts.map +1 -0
- package/dist/companion/keyboard.js +127 -0
- package/dist/companion/keyboard.js.map +1 -0
- package/dist/companion/pairing_keepalive.d.ts +4 -0
- package/dist/companion/pairing_keepalive.d.ts.map +1 -0
- package/dist/companion/pairing_keepalive.js +68 -0
- package/dist/companion/pairing_keepalive.js.map +1 -0
- package/dist/companion/protocol.d.ts +64 -0
- package/dist/companion/protocol.d.ts.map +1 -0
- package/dist/companion/protocol.js +246 -0
- package/dist/companion/protocol.js.map +1 -0
- package/dist/companion/remote.d.ts +75 -0
- package/dist/companion/remote.d.ts.map +1 -0
- package/dist/companion/remote.js +142 -0
- package/dist/companion/remote.js.map +1 -0
- package/dist/crypto/chacha20.d.ts +27 -0
- package/dist/crypto/chacha20.d.ts.map +1 -0
- package/dist/crypto/chacha20.js +88 -0
- package/dist/crypto/chacha20.js.map +1 -0
- package/dist/crypto/hkdf.d.ts +6 -0
- package/dist/crypto/hkdf.d.ts.map +1 -0
- package/dist/crypto/hkdf.js +45 -0
- package/dist/crypto/hkdf.js.map +1 -0
- package/dist/index.d.ts +85 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +191 -0
- package/dist/index.js.map +1 -0
- package/dist/mdns.d.ts +20 -0
- package/dist/mdns.d.ts.map +1 -0
- package/dist/mdns.js +165 -0
- package/dist/mdns.js.map +1 -0
- package/dist/opack.d.ts +21 -0
- package/dist/opack.d.ts.map +1 -0
- package/dist/opack.js +350 -0
- package/dist/opack.js.map +1 -0
- package/dist/pairing/credentials.d.ts +23 -0
- package/dist/pairing/credentials.d.ts.map +1 -0
- package/dist/pairing/credentials.js +31 -0
- package/dist/pairing/credentials.js.map +1 -0
- package/dist/pairing/srp.d.ts +54 -0
- package/dist/pairing/srp.d.ts.map +1 -0
- package/dist/pairing/srp.js +221 -0
- package/dist/pairing/srp.js.map +1 -0
- package/dist/pairing/tlv.d.ts +26 -0
- package/dist/pairing/tlv.d.ts.map +1 -0
- package/dist/pairing/tlv.js +68 -0
- package/dist/pairing/tlv.js.map +1 -0
- package/examples/pair.ts +103 -0
- package/examples/remote.ts +212 -0
- package/package.json +33 -0
- package/src/airplay/auth.ts +207 -0
- package/src/bplist.ts +136 -0
- package/src/companion/auth.ts +141 -0
- package/src/companion/connection.ts +161 -0
- package/src/companion/keyboard.ts +155 -0
- package/src/companion/pairing_keepalive.ts +75 -0
- package/src/companion/protocol.ts +253 -0
- package/src/companion/remote.ts +151 -0
- package/src/crypto/chacha20.ts +93 -0
- package/src/crypto/hkdf.ts +18 -0
- package/src/index.ts +248 -0
- package/src/mdns.ts +198 -0
- package/src/opack.ts +299 -0
- package/src/pairing/credentials.ts +44 -0
- package/src/pairing/srp.ts +234 -0
- package/src/pairing/tlv.ts +64 -0
- package/tsconfig.json +19 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 Pierre Ståhl
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# atv-js
|
|
2
|
+
|
|
3
|
+
Apple TV control library in TypeScript: mDNS discovery, AirPlay/Companion pairing, remote control, and keyboard input.
|
|
4
|
+
|
|
5
|
+
**Important:** This repository is a partial conversion of the Python project `pyatv`. It is **not** a new, independent library. Only a required subset of `pyatv` functionality was converted, and that conversion was performed with LLM assistance.
|
|
6
|
+
|
|
7
|
+
## Status
|
|
8
|
+
|
|
9
|
+
- Partial port intended for specific internal use cases.
|
|
10
|
+
- APIs and behavior follow `pyatv` as closely as practical, but coverage is incomplete.
|
|
11
|
+
- Expect gaps versus `pyatv` and treat this as experimental.
|
|
12
|
+
|
|
13
|
+
## Scope (current)
|
|
14
|
+
|
|
15
|
+
- mDNS discovery of Apple TV devices
|
|
16
|
+
- AirPlay pairing
|
|
17
|
+
- Companion protocol pairing and pair-verify
|
|
18
|
+
- Remote control key events
|
|
19
|
+
- Keyboard input (text get/set, focus state)
|
|
20
|
+
|
|
21
|
+
## Install
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm install
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Build
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
npm run build
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Examples
|
|
34
|
+
|
|
35
|
+
Pairing:
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
npm run pair
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Remote control:
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
npm run remote
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Example sources:
|
|
48
|
+
|
|
49
|
+
- `examples/pair.ts`
|
|
50
|
+
- `examples/remote.ts`
|
|
51
|
+
|
|
52
|
+
## Public API (summary)
|
|
53
|
+
|
|
54
|
+
Exported from `src/index.ts`:
|
|
55
|
+
|
|
56
|
+
- `scan(timeout?: number)`
|
|
57
|
+
- `startAirPlayPairing(...)`, `finishAirPlayPairing(...)`
|
|
58
|
+
- `startCompanionPairing(...)`, `finishCompanionPairing(...)`
|
|
59
|
+
- `connect(...)`, `disconnect(...)`, `isConnected(...)`
|
|
60
|
+
- `sendKey(...)`, `sendKeyDown(...)`, `sendKeyUp(...)`
|
|
61
|
+
- `getKeyboardFocusState(...)`, `getText(...)`, `setText(...)`
|
|
62
|
+
- `parseCredentials(...)`, `serializeCredentials(...)`
|
|
63
|
+
|
|
64
|
+
For details, see `src/index.ts`.
|
|
65
|
+
|
|
66
|
+
## Origin
|
|
67
|
+
|
|
68
|
+
This codebase is derived from `pyatv` and intended to mirror a subset of its behavior in TypeScript. It should be treated as a **partial port** of `pyatv`, not a separate or competing implementation.
|
|
69
|
+
|
|
70
|
+
## Attribution
|
|
71
|
+
|
|
72
|
+
This project is not affiliated with or endorsed by the `pyatv` maintainers. If you need full Apple TV control functionality, stability, or upstream updates, use `pyatv` directly.
|
|
73
|
+
|
|
74
|
+
Upstream project:
|
|
75
|
+
|
|
76
|
+
- `pyatv` (https://pyatv.dev)
|
|
77
|
+
|
|
78
|
+
## License
|
|
79
|
+
|
|
80
|
+
This repository includes the MIT license from `pyatv` in `LICENSE.md`.
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AirPlay HTTP-based HAP pair-setup and pair-verify.
|
|
3
|
+
* Port of pyatv/protocols/airplay/auth/hap.py.
|
|
4
|
+
*/
|
|
5
|
+
import { SRPAuthHandler } from '../pairing/srp';
|
|
6
|
+
import { HapCredentials } from '../pairing/credentials';
|
|
7
|
+
export interface AirPlayPairingSession {
|
|
8
|
+
srp: SRPAuthHandler;
|
|
9
|
+
host: string;
|
|
10
|
+
port: number;
|
|
11
|
+
atvSalt: Buffer;
|
|
12
|
+
atvPubKey: Buffer;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Start AirPlay pairing: triggers PIN display on the Apple TV.
|
|
16
|
+
* Returns a session object to pass to finishAirPlayPairing.
|
|
17
|
+
*/
|
|
18
|
+
export declare function startAirPlayPairing(host: string, port: number): Promise<AirPlayPairingSession>;
|
|
19
|
+
/**
|
|
20
|
+
* Finish AirPlay pairing with the PIN shown on screen.
|
|
21
|
+
* Returns credentials for later connection.
|
|
22
|
+
*/
|
|
23
|
+
export declare function finishAirPlayPairing(session: AirPlayPairingSession, pin: string, displayName?: string): Promise<HapCredentials>;
|
|
24
|
+
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/airplay/auth.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAkCxD,MAAM,WAAW,qBAAqB;IACpC,GAAG,EAAE,cAAc,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;CACnB;AA2DD;;;GAGG;AACH,wBAAsB,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAyBpG;AAED;;;GAGG;AACH,wBAAsB,oBAAoB,CACxC,OAAO,EAAE,qBAAqB,EAC9B,GAAG,EAAE,MAAM,EACX,WAAW,CAAC,EAAE,MAAM,GACnB,OAAO,CAAC,cAAc,CAAC,CA6DzB"}
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* AirPlay HTTP-based HAP pair-setup and pair-verify.
|
|
4
|
+
* Port of pyatv/protocols/airplay/auth/hap.py.
|
|
5
|
+
*/
|
|
6
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
|
+
if (k2 === undefined) k2 = k;
|
|
8
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
9
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
10
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
11
|
+
}
|
|
12
|
+
Object.defineProperty(o, k2, desc);
|
|
13
|
+
}) : (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
o[k2] = m[k];
|
|
16
|
+
}));
|
|
17
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
18
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
19
|
+
}) : function(o, v) {
|
|
20
|
+
o["default"] = v;
|
|
21
|
+
});
|
|
22
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
23
|
+
var ownKeys = function(o) {
|
|
24
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
25
|
+
var ar = [];
|
|
26
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
27
|
+
return ar;
|
|
28
|
+
};
|
|
29
|
+
return ownKeys(o);
|
|
30
|
+
};
|
|
31
|
+
return function (mod) {
|
|
32
|
+
if (mod && mod.__esModule) return mod;
|
|
33
|
+
var result = {};
|
|
34
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
35
|
+
__setModuleDefault(result, mod);
|
|
36
|
+
return result;
|
|
37
|
+
};
|
|
38
|
+
})();
|
|
39
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
+
exports.startAirPlayPairing = startAirPlayPairing;
|
|
41
|
+
exports.finishAirPlayPairing = finishAirPlayPairing;
|
|
42
|
+
const http = __importStar(require("http"));
|
|
43
|
+
const srp_1 = require("../pairing/srp");
|
|
44
|
+
const tlv_1 = require("../pairing/tlv");
|
|
45
|
+
const AIRPLAY_HEADERS = {
|
|
46
|
+
'User-Agent': 'AirPlay/320.20',
|
|
47
|
+
'Connection': 'keep-alive',
|
|
48
|
+
'X-Apple-HKP': '3',
|
|
49
|
+
'Content-Type': 'application/octet-stream',
|
|
50
|
+
};
|
|
51
|
+
async function httpPost(host, port, path, body, agent) {
|
|
52
|
+
return new Promise((resolve, reject) => {
|
|
53
|
+
const headers = { ...AIRPLAY_HEADERS };
|
|
54
|
+
if (body) {
|
|
55
|
+
headers['Content-Length'] = body.length;
|
|
56
|
+
}
|
|
57
|
+
const req = http.request({ hostname: host, port, path, method: 'POST', headers, agent }, (res) => {
|
|
58
|
+
const chunks = [];
|
|
59
|
+
res.on('data', (chunk) => chunks.push(chunk));
|
|
60
|
+
res.on('end', () => resolve(Buffer.concat(chunks)));
|
|
61
|
+
});
|
|
62
|
+
req.on('error', reject);
|
|
63
|
+
if (body)
|
|
64
|
+
req.write(body);
|
|
65
|
+
req.end();
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
const AIRPLAY_AGENT_IDLE_MS = 2 * 60 * 1000;
|
|
69
|
+
const agentCache = new Map();
|
|
70
|
+
function agentKey(host, port) {
|
|
71
|
+
return `${host}:${port}`;
|
|
72
|
+
}
|
|
73
|
+
function touchAgent(entry) {
|
|
74
|
+
entry.lastUsed = Date.now();
|
|
75
|
+
if (entry.timer)
|
|
76
|
+
clearTimeout(entry.timer);
|
|
77
|
+
entry.timer = setTimeout(() => {
|
|
78
|
+
if (Date.now() - entry.lastUsed >= AIRPLAY_AGENT_IDLE_MS) {
|
|
79
|
+
entry.agent.destroy();
|
|
80
|
+
// Find and remove by identity
|
|
81
|
+
for (const [key, value] of agentCache) {
|
|
82
|
+
if (value === entry) {
|
|
83
|
+
agentCache.delete(key);
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}, AIRPLAY_AGENT_IDLE_MS);
|
|
89
|
+
entry.timer.unref();
|
|
90
|
+
}
|
|
91
|
+
function getPairingAgent(host, port) {
|
|
92
|
+
const key = agentKey(host, port);
|
|
93
|
+
const existing = agentCache.get(key);
|
|
94
|
+
if (existing) {
|
|
95
|
+
touchAgent(existing);
|
|
96
|
+
return existing.agent;
|
|
97
|
+
}
|
|
98
|
+
const agent = new http.Agent({ keepAlive: true, maxSockets: 1, maxFreeSockets: 1 });
|
|
99
|
+
agent.on('free', (socket) => {
|
|
100
|
+
socket.unref();
|
|
101
|
+
});
|
|
102
|
+
const entry = {
|
|
103
|
+
agent,
|
|
104
|
+
lastUsed: Date.now(),
|
|
105
|
+
timer: setTimeout(() => {
|
|
106
|
+
agent.destroy();
|
|
107
|
+
agentCache.delete(key);
|
|
108
|
+
}, AIRPLAY_AGENT_IDLE_MS),
|
|
109
|
+
};
|
|
110
|
+
entry.timer.unref();
|
|
111
|
+
agentCache.set(key, entry);
|
|
112
|
+
return agent;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Start AirPlay pairing: triggers PIN display on the Apple TV.
|
|
116
|
+
* Returns a session object to pass to finishAirPlayPairing.
|
|
117
|
+
*/
|
|
118
|
+
async function startAirPlayPairing(host, port) {
|
|
119
|
+
const srp = new srp_1.SRPAuthHandler();
|
|
120
|
+
srp.initialize();
|
|
121
|
+
const agent = getPairingAgent(host, port);
|
|
122
|
+
// Trigger PIN display
|
|
123
|
+
await httpPost(host, port, '/pair-pin-start', undefined, agent);
|
|
124
|
+
// Send pair-setup SeqNo 1
|
|
125
|
+
const tlvData = (0, tlv_1.writeTlv)(new Map([
|
|
126
|
+
[tlv_1.TlvValue.Method, Buffer.from([0x00])],
|
|
127
|
+
[tlv_1.TlvValue.SeqNo, Buffer.from([0x01])],
|
|
128
|
+
]));
|
|
129
|
+
const resp = await httpPost(host, port, '/pair-setup', tlvData, agent);
|
|
130
|
+
const pairingData = (0, tlv_1.readTlv)(resp);
|
|
131
|
+
const atvSalt = pairingData.get(tlv_1.TlvValue.Salt);
|
|
132
|
+
const atvPubKey = pairingData.get(tlv_1.TlvValue.PublicKey);
|
|
133
|
+
if (!atvSalt || !atvPubKey) {
|
|
134
|
+
throw new Error('Missing salt or public key in pair-setup response');
|
|
135
|
+
}
|
|
136
|
+
return { srp, host, port, atvSalt, atvPubKey };
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Finish AirPlay pairing with the PIN shown on screen.
|
|
140
|
+
* Returns credentials for later connection.
|
|
141
|
+
*/
|
|
142
|
+
async function finishAirPlayPairing(session, pin, displayName) {
|
|
143
|
+
const { srp, host, port, atvSalt, atvPubKey } = session;
|
|
144
|
+
const agent = getPairingAgent(host, port);
|
|
145
|
+
console.log('[DEBUG] ATV Salt:', atvSalt.toString('hex'));
|
|
146
|
+
console.log('[DEBUG] ATV PubKey length:', atvPubKey.length);
|
|
147
|
+
console.log('[DEBUG] PIN:', pin);
|
|
148
|
+
// SRP step 1: set PIN
|
|
149
|
+
srp.step1(pin.trim());
|
|
150
|
+
// SRP step 2: compute proof
|
|
151
|
+
const [pubKey, proof] = srp.step2(atvPubKey, atvSalt);
|
|
152
|
+
console.log('[DEBUG] Client PubKey length:', pubKey.length);
|
|
153
|
+
console.log('[DEBUG] Client Proof length:', proof.length);
|
|
154
|
+
// Send pair-setup SeqNo 3
|
|
155
|
+
const seq3Data = (0, tlv_1.writeTlv)(new Map([
|
|
156
|
+
[tlv_1.TlvValue.SeqNo, Buffer.from([0x03])],
|
|
157
|
+
[tlv_1.TlvValue.PublicKey, pubKey],
|
|
158
|
+
[tlv_1.TlvValue.Proof, proof],
|
|
159
|
+
]));
|
|
160
|
+
const seq3Resp = await httpPost(host, port, '/pair-setup', seq3Data, agent);
|
|
161
|
+
// Check for errors in SeqNo 3 response (wrong PIN, etc.)
|
|
162
|
+
const seq3Tlv = (0, tlv_1.readTlv)(seq3Resp);
|
|
163
|
+
console.log('[DEBUG] SeqNo 3 response TLV keys:', Array.from(seq3Tlv.keys()));
|
|
164
|
+
const errorCode = seq3Tlv.get(tlv_1.TlvValue.Error);
|
|
165
|
+
if (errorCode) {
|
|
166
|
+
const code = errorCode[0];
|
|
167
|
+
const errorMessages = {
|
|
168
|
+
1: 'Unknown error',
|
|
169
|
+
2: 'Authentication failed (wrong PIN?)',
|
|
170
|
+
3: 'Too many attempts, backoff required',
|
|
171
|
+
4: 'Unknown peer',
|
|
172
|
+
5: 'Max peers reached',
|
|
173
|
+
6: 'Max authentication attempts reached',
|
|
174
|
+
};
|
|
175
|
+
console.log('[DEBUG] Error code:', code);
|
|
176
|
+
console.log('[DEBUG] Full response hex:', seq3Resp.toString('hex'));
|
|
177
|
+
throw new Error(`Pairing failed: ${errorMessages[code] || `error code ${code}`}`);
|
|
178
|
+
}
|
|
179
|
+
// SRP step 3: sign and encrypt identity
|
|
180
|
+
const encrypted = srp.step3(displayName || undefined);
|
|
181
|
+
// Send pair-setup SeqNo 5
|
|
182
|
+
const seq5Data = (0, tlv_1.writeTlv)(new Map([
|
|
183
|
+
[tlv_1.TlvValue.SeqNo, Buffer.from([0x05])],
|
|
184
|
+
[tlv_1.TlvValue.EncryptedData, encrypted],
|
|
185
|
+
]));
|
|
186
|
+
const resp = await httpPost(host, port, '/pair-setup', seq5Data, agent);
|
|
187
|
+
const pairingData = (0, tlv_1.readTlv)(resp);
|
|
188
|
+
const encryptedResponse = pairingData.get(tlv_1.TlvValue.EncryptedData);
|
|
189
|
+
if (!encryptedResponse) {
|
|
190
|
+
throw new Error('Missing encrypted data in pair-setup step 4 response');
|
|
191
|
+
}
|
|
192
|
+
// SRP step 4: decrypt and extract credentials
|
|
193
|
+
return srp.step4(encryptedResponse);
|
|
194
|
+
}
|
|
195
|
+
//# sourceMappingURL=auth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../src/airplay/auth.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2GH,kDAyBC;AAMD,oDAiEC;AAzMD,2CAA6B;AAC7B,wCAAgD;AAEhD,wCAA6D;AAE7D,MAAM,eAAe,GAA2B;IAC9C,YAAY,EAAE,gBAAgB;IAC9B,YAAY,EAAE,YAAY;IAC1B,aAAa,EAAE,GAAG;IAClB,cAAc,EAAE,0BAA0B;CAC3C,CAAC;AAEF,KAAK,UAAU,QAAQ,CACrB,IAAY,EACZ,IAAY,EACZ,IAAY,EACZ,IAAa,EACb,KAAkB;IAElB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,MAAM,OAAO,GAAoC,EAAE,GAAG,eAAe,EAAE,CAAC;QACxE,IAAI,IAAI,EAAE,CAAC;YACT,OAAO,CAAC,gBAAgB,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC;QAC1C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IAAI,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC;IACxE,MAAM,WAAW,GAAG,IAAA,aAAO,EAAC,IAAI,CAAC,CAAC;IAElC,MAAM,iBAAiB,GAAG,WAAW,CAAC,GAAG,CAAC,cAAQ,CAAC,aAAa,CAAC,CAAC;IAClE,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACvB,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAC;IAC1E,CAAC;IAED,8CAA8C;IAC9C,OAAO,GAAG,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC;AACtC,CAAC"}
|
package/dist/bplist.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal binary plist support for RTI (Remote Text Input) NSKeyedArchiver payloads.
|
|
3
|
+
* Uses bplist-creator for encoding and bplist-parser for decoding.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Create an RTI "clear text" payload (NSKeyedArchiver encoded).
|
|
7
|
+
* Matches pyatv/protocols/companion/plist_payloads/rti_text_operations.py
|
|
8
|
+
*/
|
|
9
|
+
export declare function createRtiClearTextPayload(sessionUuid: Buffer): Buffer;
|
|
10
|
+
/**
|
|
11
|
+
* Create an RTI "input text" payload (NSKeyedArchiver encoded).
|
|
12
|
+
*/
|
|
13
|
+
export declare function createRtiInputTextPayload(sessionUuid: Buffer, text: string): Buffer;
|
|
14
|
+
/**
|
|
15
|
+
* Parse a binary plist buffer and extract properties by path.
|
|
16
|
+
* Matches pyatv/protocols/companion/keyed_archiver.py read_archive_properties().
|
|
17
|
+
*/
|
|
18
|
+
export declare function readArchiveProperties(archive: Buffer, ...paths: string[][]): (unknown | null)[];
|
|
19
|
+
//# sourceMappingURL=bplist.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bplist.d.ts","sourceRoot":"","sources":["../src/bplist.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAeH;;;GAGG;AACH,wBAAgB,yBAAyB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAqCrE;AAED;;GAEG;AACH,wBAAgB,yBAAyB,CAAC,WAAW,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAqCnF;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,KAAK,EAAE,MAAM,EAAE,EAAE,GAAG,CAAC,OAAO,GAAG,IAAI,CAAC,EAAE,CA4B/F"}
|
package/dist/bplist.js
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Minimal binary plist support for RTI (Remote Text Input) NSKeyedArchiver payloads.
|
|
4
|
+
* Uses bplist-creator for encoding and bplist-parser for decoding.
|
|
5
|
+
*/
|
|
6
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
7
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
8
|
+
};
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.createRtiClearTextPayload = createRtiClearTextPayload;
|
|
11
|
+
exports.createRtiInputTextPayload = createRtiInputTextPayload;
|
|
12
|
+
exports.readArchiveProperties = readArchiveProperties;
|
|
13
|
+
// @ts-ignore - no type definitions
|
|
14
|
+
const bplist_creator_1 = __importDefault(require("bplist-creator"));
|
|
15
|
+
// @ts-ignore - no type definitions
|
|
16
|
+
const bplist_parser_1 = __importDefault(require("bplist-parser"));
|
|
17
|
+
/** UID reference type for NSKeyedArchiver plists. */
|
|
18
|
+
class UID {
|
|
19
|
+
UID;
|
|
20
|
+
constructor(value) {
|
|
21
|
+
this.UID = value;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Create an RTI "clear text" payload (NSKeyedArchiver encoded).
|
|
26
|
+
* Matches pyatv/protocols/companion/plist_payloads/rti_text_operations.py
|
|
27
|
+
*/
|
|
28
|
+
function createRtiClearTextPayload(sessionUuid) {
|
|
29
|
+
return (0, bplist_creator_1.default)({
|
|
30
|
+
'$version': 100000,
|
|
31
|
+
'$archiver': 'RTIKeyedArchiver',
|
|
32
|
+
'$top': {
|
|
33
|
+
textOperations: new UID(1),
|
|
34
|
+
},
|
|
35
|
+
'$objects': [
|
|
36
|
+
'$null',
|
|
37
|
+
{
|
|
38
|
+
'$class': new UID(7),
|
|
39
|
+
targetSessionUUID: new UID(5),
|
|
40
|
+
keyboardOutput: new UID(2),
|
|
41
|
+
textToAssert: new UID(4),
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
'$class': new UID(3),
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
'$classname': 'TIKeyboardOutput',
|
|
48
|
+
'$classes': ['TIKeyboardOutput', 'NSObject'],
|
|
49
|
+
},
|
|
50
|
+
'', // empty text assertion = clear
|
|
51
|
+
{
|
|
52
|
+
'NS.uuidbytes': sessionUuid,
|
|
53
|
+
'$class': new UID(6),
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
'$classname': 'NSUUID',
|
|
57
|
+
'$classes': ['NSUUID', 'NSObject'],
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
'$classname': 'RTITextOperations',
|
|
61
|
+
'$classes': ['RTITextOperations', 'NSObject'],
|
|
62
|
+
},
|
|
63
|
+
],
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Create an RTI "input text" payload (NSKeyedArchiver encoded).
|
|
68
|
+
*/
|
|
69
|
+
function createRtiInputTextPayload(sessionUuid, text) {
|
|
70
|
+
return (0, bplist_creator_1.default)({
|
|
71
|
+
'$version': 100000,
|
|
72
|
+
'$archiver': 'RTIKeyedArchiver',
|
|
73
|
+
'$top': {
|
|
74
|
+
textOperations: new UID(1),
|
|
75
|
+
},
|
|
76
|
+
'$objects': [
|
|
77
|
+
'$null',
|
|
78
|
+
{
|
|
79
|
+
keyboardOutput: new UID(2),
|
|
80
|
+
'$class': new UID(7),
|
|
81
|
+
targetSessionUUID: new UID(5),
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
insertionText: new UID(3),
|
|
85
|
+
'$class': new UID(4),
|
|
86
|
+
},
|
|
87
|
+
text,
|
|
88
|
+
{
|
|
89
|
+
'$classname': 'TIKeyboardOutput',
|
|
90
|
+
'$classes': ['TIKeyboardOutput', 'NSObject'],
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
'NS.uuidbytes': sessionUuid,
|
|
94
|
+
'$class': new UID(6),
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
'$classname': 'NSUUID',
|
|
98
|
+
'$classes': ['NSUUID', 'NSObject'],
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
'$classname': 'RTITextOperations',
|
|
102
|
+
'$classes': ['RTITextOperations', 'NSObject'],
|
|
103
|
+
},
|
|
104
|
+
],
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Parse a binary plist buffer and extract properties by path.
|
|
109
|
+
* Matches pyatv/protocols/companion/keyed_archiver.py read_archive_properties().
|
|
110
|
+
*/
|
|
111
|
+
function readArchiveProperties(archive, ...paths) {
|
|
112
|
+
let parsed;
|
|
113
|
+
try {
|
|
114
|
+
parsed = bplist_parser_1.default.parseBuffer(archive);
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
return paths.map(() => null);
|
|
118
|
+
}
|
|
119
|
+
if (!parsed || !Array.isArray(parsed) || parsed.length < 1)
|
|
120
|
+
return paths.map(() => null);
|
|
121
|
+
const data = parsed[0];
|
|
122
|
+
const objects = data['$objects'];
|
|
123
|
+
const top = data['$top'];
|
|
124
|
+
return paths.map((path) => {
|
|
125
|
+
let element = top;
|
|
126
|
+
try {
|
|
127
|
+
for (const key of path) {
|
|
128
|
+
element = element[key];
|
|
129
|
+
// Resolve UID references
|
|
130
|
+
if (element && typeof element === 'object' && 'UID' in element) {
|
|
131
|
+
element = objects[element.UID];
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return element ?? null;
|
|
135
|
+
}
|
|
136
|
+
catch {
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
//# sourceMappingURL=bplist.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bplist.js","sourceRoot":"","sources":["../src/bplist.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;AAmBH,8DAqCC;AAKD,8DAqCC;AAMD,sDA4BC;AAlID,mCAAmC;AACnC,oEAA2C;AAC3C,mCAAmC;AACnC,kEAAyC;AAEzC,qDAAqD;AACrD,MAAM,GAAG;IACP,GAAG,CAAS;IACZ,YAAY,KAAa;QACvB,IAAI,CAAC,GAAG,GAAG,KAAK,CAAC;IACnB,CAAC;CACF;AAED;;;GAGG;AACH,SAAgB,yBAAyB,CAAC,WAAmB;IAC3D,OAAO,IAAA,wBAAa,EAAC;QACnB,UAAU,EAAE,MAAM;QAClB,WAAW,EAAE,kBAAkB;QAC/B,MAAM,EAAE;YACN,cAAc,EAAE,IAAI,GAAG,CAAC,CAAC,CAAC;SAC3B;QACD,UAAU,EAAE;YACV,OAAO;YACP;gBACE,QAAQ,EAAE,IAAI,GAAG,CAAC,CAAC,CAAC;gBACpB,iBAAiB,EAAE,IAAI,GAAG,CAAC,CAAC,CAAC;gBAC7B,cAAc,EAAE,IAAI,GAAG,CAAC,CAAC,CAAC;gBAC1B,YAAY,EAAE,IAAI,GAAG,CAAC,CAAC,CAAC;aACzB;YACD;gBACE,QAAQ,EAAE,IAAI,GAAG,CAAC,CAAC,CAAC;aACrB;YACD;gBACE,YAAY,EAAE,kBAAkB;gBAChC,UAAU,EAAE,CAAC,kBAAkB,EAAE,UAAU,CAAC;aAC7C;YACD,EAAE,EAAG,+BAA+B;YACpC;gBACE,cAAc,EAAE,WAAW;gBAC3B,QAAQ,EAAE,IA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
import { SRPAuthHandler } from '../pairing/srp';
|
|
6
|
+
import { HapCredentials } from '../pairing/credentials';
|
|
7
|
+
import { CompanionProtocol } from './protocol';
|
|
8
|
+
export declare const SRP_SALT = "";
|
|
9
|
+
export declare const SRP_OUTPUT_INFO = "ClientEncrypt-main";
|
|
10
|
+
export declare const SRP_INPUT_INFO = "ServerEncrypt-main";
|
|
11
|
+
/**
|
|
12
|
+
* Perform Companion pair-setup (initial pairing that requires PIN).
|
|
13
|
+
*/
|
|
14
|
+
export declare class CompanionPairSetupProcedure {
|
|
15
|
+
private protocol;
|
|
16
|
+
private srp;
|
|
17
|
+
private atvSalt;
|
|
18
|
+
private atvPubKey;
|
|
19
|
+
constructor(protocol: CompanionProtocol, srp: SRPAuthHandler);
|
|
20
|
+
startPairing(): Promise<void>;
|
|
21
|
+
finishPairing(pin: string, displayName?: string): Promise<HapCredentials>;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Verify Companion credentials and derive encryption keys.
|
|
25
|
+
*/
|
|
26
|
+
export declare class CompanionPairVerifyProcedure {
|
|
27
|
+
private protocol;
|
|
28
|
+
private srp;
|
|
29
|
+
private credentials;
|
|
30
|
+
constructor(protocol: CompanionProtocol, srp: SRPAuthHandler, credentials: HapCredentials);
|
|
31
|
+
verifyCredentials(): Promise<boolean>;
|
|
32
|
+
encryptionKeys(): [Buffer, Buffer];
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/companion/auth.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAExD,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAM/C,eAAO,MAAM,QAAQ,KAAK,CAAC;AAC3B,eAAO,MAAM,eAAe,uBAAuB,CAAC;AACpD,eAAO,MAAM,cAAc,uBAAuB,CAAC;AAcnD;;GAEG;AACH,qBAAa,2BAA2B;IACtC,OAAO,CAAC,QAAQ,CAAoB;IACpC,OAAO,CAAC,GAAG,CAAiB;IAC5B,OAAO,CAAC,OAAO,CAAuB;IACtC,OAAO,CAAC,SAAS,CAAuB;gBAE5B,QAAQ,EAAE,iBAAiB,EAAE,GAAG,EAAE,cAAc;IAKtD,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;IAiB7B,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;CAiChF;AAED;;GAEG;AACH,qBAAa,4BAA4B;IACvC,OAAO,CAAC,QAAQ,CAAoB;IACpC,OAAO,CAAC,GAAG,CAAiB;IAC5B,OAAO,CAAC,WAAW,CAAiB;gBAExB,QAAQ,EAAE,iBAAiB,EAAE,GAAG,EAAE,cAAc,EAAE,WAAW,EAAE,cAAc;IAMnF,iBAAiB,IAAI,OAAO,CAAC,OAAO,CAAC;IA2B3C,cAAc,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC;CAGnC"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Companion protocol pair-setup and pair-verify procedures.
|
|
4
|
+
* Port of pyatv/protocols/companion/auth.py.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.CompanionPairVerifyProcedure = exports.CompanionPairSetupProcedure = exports.SRP_INPUT_INFO = exports.SRP_OUTPUT_INFO = exports.SRP_SALT = void 0;
|
|
8
|
+
const tlv_1 = require("../pairing/tlv");
|
|
9
|
+
const connection_1 = require("./connection");
|
|
10
|
+
const PAIRING_DATA_KEY = '_pd';
|
|
11
|
+
// Companion encryption key derivation constants
|
|
12
|
+
exports.SRP_SALT = '';
|
|
13
|
+
exports.SRP_OUTPUT_INFO = 'ClientEncrypt-main';
|
|
14
|
+
exports.SRP_INPUT_INFO = 'ServerEncrypt-main';
|
|
15
|
+
function getPairingData(message) {
|
|
16
|
+
const pd = message[PAIRING_DATA_KEY];
|
|
17
|
+
if (!pd || !Buffer.isBuffer(pd)) {
|
|
18
|
+
throw new Error('No pairing data in message or unexpected type');
|
|
19
|
+
}
|
|
20
|
+
const tlv = (0, tlv_1.readTlv)(pd);
|
|
21
|
+
if (tlv.has(tlv_1.TlvValue.Error)) {
|
|
22
|
+
throw new Error(`Pairing error: ${tlv.get(tlv_1.TlvValue.Error).toString('hex')}`);
|
|
23
|
+
}
|
|
24
|
+
return tlv;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Perform Companion pair-setup (initial pairing that requires PIN).
|
|
28
|
+
*/
|
|
29
|
+
class CompanionPairSetupProcedure {
|
|
30
|
+
protocol;
|
|
31
|
+
srp;
|
|
32
|
+
atvSalt = null;
|
|
33
|
+
atvPubKey = null;
|
|
34
|
+
constructor(protocol, srp) {
|
|
35
|
+
this.protocol = protocol;
|
|
36
|
+
this.srp = srp;
|
|
37
|
+
}
|
|
38
|
+
async startPairing() {
|
|
39
|
+
this.srp.initialize();
|
|
40
|
+
await this.protocol.start();
|
|
41
|
+
const resp = await this.protocol.exchangeAuth(connection_1.FrameType.PS_Start, {
|
|
42
|
+
[PAIRING_DATA_KEY]: (0, tlv_1.writeTlv)(new Map([
|
|
43
|
+
[tlv_1.TlvValue.Method, Buffer.from([0x00])],
|
|
44
|
+
[tlv_1.TlvValue.SeqNo, Buffer.from([0x01])],
|
|
45
|
+
])),
|
|
46
|
+
_pwTy: 1,
|
|
47
|
+
});
|
|
48
|
+
const pairingData = getPairingData(resp);
|
|
49
|
+
this.atvSalt = pairingData.get(tlv_1.TlvValue.Salt);
|
|
50
|
+
this.atvPubKey = pairingData.get(tlv_1.TlvValue.PublicKey);
|
|
51
|
+
}
|
|
52
|
+
async finishPairing(pin, displayName) {
|
|
53
|
+
this.srp.step1(pin);
|
|
54
|
+
const [pubKey, proof] = this.srp.step2(this.atvPubKey, this.atvSalt);
|
|
55
|
+
// SeqNo 3: send proof
|
|
56
|
+
const resp3 = await this.protocol.exchangeAuth(connection_1.FrameType.PS_Next, {
|
|
57
|
+
[PAIRING_DATA_KEY]: (0, tlv_1.writeTlv)(new Map([
|
|
58
|
+
[tlv_1.TlvValue.SeqNo, Buffer.from([0x03])],
|
|
59
|
+
[tlv_1.TlvValue.PublicKey, pubKey],
|
|
60
|
+
[tlv_1.TlvValue.Proof, proof],
|
|
61
|
+
])),
|
|
62
|
+
_pwTy: 1,
|
|
63
|
+
});
|
|
64
|
+
// Verify server proof is present
|
|
65
|
+
getPairingData(resp3);
|
|
66
|
+
// SeqNo 5: send encrypted identity
|
|
67
|
+
const encrypted = this.srp.step3(displayName);
|
|
68
|
+
const resp5 = await this.protocol.exchangeAuth(connection_1.FrameType.PS_Next, {
|
|
69
|
+
[PAIRING_DATA_KEY]: (0, tlv_1.writeTlv)(new Map([
|
|
70
|
+
[tlv_1.TlvValue.SeqNo, Buffer.from([0x05])],
|
|
71
|
+
[tlv_1.TlvValue.EncryptedData, encrypted],
|
|
72
|
+
])),
|
|
73
|
+
_pwTy: 1,
|
|
74
|
+
});
|
|
75
|
+
const pairingData5 = getPairingData(resp5);
|
|
76
|
+
const encryptedData = pairingData5.get(tlv_1.TlvValue.EncryptedData);
|
|
77
|
+
return this.srp.step4(encryptedData);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
exports.CompanionPairSetupProcedure = CompanionPairSetupProcedure;
|
|
81
|
+
/**
|
|
82
|
+
* Verify Companion credentials and derive encryption keys.
|
|
83
|
+
*/
|
|
84
|
+
class CompanionPairVerifyProcedure {
|
|
85
|
+
protocol;
|
|
86
|
+
srp;
|
|
87
|
+
credentials;
|
|
88
|
+
constructor(protocol, srp, credentials) {
|
|
89
|
+
this.protocol = protocol;
|
|
90
|
+
this.srp = srp;
|
|
91
|
+
this.credentials = credentials;
|
|
92
|
+
}
|
|
93
|
+
async verifyCredentials() {
|
|
94
|
+
const [, publicKey] = this.srp.initialize();
|
|
95
|
+
const resp = await this.protocol.exchangeAuth(connection_1.FrameType.PV_Start, {
|
|
96
|
+
[PAIRING_DATA_KEY]: (0, tlv_1.writeTlv)(new Map([
|
|
97
|
+
[tlv_1.TlvValue.SeqNo, Buffer.from([0x01])],
|
|
98
|
+
[tlv_1.TlvValue.PublicKey, publicKey],
|
|
99
|
+
])),
|
|
100
|
+
_auTy: 4,
|
|
101
|
+
});
|
|
102
|
+
const pairingData = getPairingData(resp);
|
|
103
|
+
const serverPubKey = pairingData.get(tlv_1.TlvValue.PublicKey);
|
|
104
|
+
const encrypted = pairingData.get(tlv_1.TlvValue.EncryptedData);
|
|
105
|
+
const encryptedData = this.srp.verify1(this.credentials, serverPubKey, encrypted);
|
|
106
|
+
await this.protocol.exchangeAuth(connection_1.FrameType.PV_Next, {
|
|
107
|
+
[PAIRING_DATA_KEY]: (0, tlv_1.writeTlv)(new Map([
|
|
108
|
+
[tlv_1.TlvValue.SeqNo, Buffer.from([0x03])],
|
|
109
|
+
[tlv_1.TlvValue.EncryptedData, encryptedData],
|
|
110
|
+
])),
|
|
111
|
+
});
|
|
112
|
+
return true;
|
|
113
|
+
}
|
|
114
|
+
encryptionKeys() {
|
|
115
|
+
return this.srp.verify2(exports.SRP_SALT, exports.SRP_OUTPUT_INFO, exports.SRP_INPUT_INFO);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
exports.CompanionPairVerifyProcedure = CompanionPairVerifyProcedure;
|
|
119
|
+
//# sourceMappingURL=auth.js.map
|