From 2020 two factor authentication will be required. I recommend using OTP Auth for this.

Add authenticate requests

parent c9bb7ff3
......@@ -98,6 +98,12 @@ const commandHandler = handler => async argv => {
process.exit();
};
yargs.command('authenticate', 'Authenticate', yargs => {}, commandHandler(async (client, argv) => {
const data = await client.authenticate();
console.log(data);
}));
yargs.command('getprop <prop>', 'Get an ACP property', yargs => {
yargs.positional('prop', {
describe: 'The name of the ACP property',
......
......@@ -139,4 +139,24 @@ export default class Client {
const reply_header = await Message.parseRaw(this.receiveMessageHeader());
return await this.receive(reply_header.body_size);
}
async authenticate() {
let payload = {
state: 1,
username: 'admin',
};
const message = Message.composeAuthCommand(4, this.password, CFLBinaryPList.compose(payload));
await this.send(message);
const response = await this.session.receiveMessage();
const data = CFLBinaryPList.parse(response.body);
if (response.error_code !== 0) {
console.log('Authenticate error code', response.error_code);
return;
}
return data;
}
}
......@@ -160,63 +160,51 @@ export default class Message {
}
static composeEchoCommand(flags, password, payload) {
const message = new Message(0x00030001, flags, 0, 1, 0, generateACPHeaderKey(password), payload);
return message.composeRawPacket();
return new Message(0x00030001, flags, 0, 1, 0, generateACPHeaderKey(password), payload);
}
static composeFlashPrimaryCommand(flags, password, payload) {
const message = new Message(0x00030001, flags, 0, 3, 0, generateACPHeaderKey(password), payload);
return message.composeRawPacket();
return new Message(0x00030001, flags, 0, 3, 0, generateACPHeaderKey(password), payload);
}
static composeFlashSecondaryCommand(flags, password, payload) {
const message = new Message(0x00030001, flags, 0, 5, 0, generateACPHeaderKey(password), payload);
return message.composeRawPacket();
return new Message(0x00030001, flags, 0, 5, 0, generateACPHeaderKey(password), payload);
}
static composeFlashBootloaderCommand(flags, password, payload) {
const message = new Message(0x00030001, flags, 0, 6, 0, generateACPHeaderKey(password), payload);
return message.composeRawPacket();
return new Message(0x00030001, flags, 0, 6, 0, generateACPHeaderKey(password), payload);
}
static composeGetPropCommand(flags, password, payload) {
const message = new Message(0x00030001, flags, 0, 0x14, 0, generateACPHeaderKey(password), payload);
return message.composeRawPacket();
return new Message(0x00030001, flags, 0, 0x14, 0, generateACPHeaderKey(password), payload);
}
static composeSetPropCommand(flags, password, payload) {
const message = new Message(0x00030001, flags, 0, 0x15, 0, generateACPHeaderKey(password), payload);
return message.composeRawPacket();
return new Message(0x00030001, flags, 0, 0x15, 0, generateACPHeaderKey(password), payload);
}
static composePerformCommand(flags, password, payload) {
const message = new Message(0x00030001, flags, 0, 0x16, 0, generateACPHeaderKey(password), payload);
return message.composeRawPacket();
return new Message(0x00030001, flags, 0, 0x16, 0, generateACPHeaderKey(password), payload);
}
static composeMonitorCommand(flags, password, payload) {
const message = new Message(0x00030001, flags, 0, 0x18, 0, generateACPHeaderKey(password), payload);
return message.composeRawPacket();
return new Message(0x00030001, flags, 0, 0x18, 0, generateACPHeaderKey(password), payload);
}
static composeRPCCommand(flags, password, payload) {
const message = new Message(0x00030001, flags, 0, 0x19, 0, generateACPHeaderKey(password), payload);
return message.composeRawPacket();
return new Message(0x00030001, flags, 0, 0x19, 0, generateACPHeaderKey(password), payload);
}
static composeAuthCommand(flags, password, payload) {
const message = new Message(0x00030001, flags, 0, 0x1a, 0, generateACPHeaderKey(password), payload);
return message.composeRawPacket();
return new Message(0x00030001, flags, 0, 0x1a, 0, generateACPHeaderKey(password), payload);
}
static composeFeatCommand(flags, payload) {
const message = new Message(0x00030001, flags, 0, 0x1b, 0, generateACPHeaderKey(''), payload);
return message.composeRawPacket();
return new Message(0x00030001, flags, 0, 0x1b, 0, generateACPHeaderKey(''), payload);
}
static composeMessageEx(version, flags, unused, command, error_code, password, payload, payload_size) {
const message = new Message(version, flags, unused, command, error_code, generateACPHeaderKey(password), payload, payload_size);
return message.composeRawPacket();
return new Message(version, flags, unused, command, error_code, generateACPHeaderKey(password), payload, payload_size);
}
composeRawPacket() {
......
......@@ -81,6 +81,10 @@ export default class Session {
}
send(data) {
if (data instanceof Message) {
data = data.composeRawPacket();
}
if (!Buffer.isBuffer(data)) {
data = Buffer.from(data, 'binary');
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment