2024-01-18 11:25:56 +08:00
|
|
|
|
|
|
|
|
|
|
import 'dart:convert';
|
|
|
|
|
|
|
2024-05-03 14:38:09 +08:00
|
|
|
|
import 'package:star_lock/tools/dateTool.dart';
|
|
|
|
|
|
|
2024-04-26 15:38:59 +08:00
|
|
|
|
import '../../app_settings/app_settings.dart';
|
2024-01-18 11:25:56 +08:00
|
|
|
|
import '../io_tool/io_tool.dart';
|
|
|
|
|
|
import '../sm4Encipher/sm4.dart';
|
|
|
|
|
|
import '../io_reply.dart';
|
|
|
|
|
|
import '../io_sender.dart';
|
|
|
|
|
|
import '../io_type.dart';
|
|
|
|
|
|
import 'package:crypto/crypto.dart' as crypto;
|
|
|
|
|
|
|
2024-10-15 14:24:35 +08:00
|
|
|
|
// 修改管理员密码
|
2024-01-18 11:25:56 +08:00
|
|
|
|
class ChangeAdministratorPasswordCommand extends SenderProtocol {
|
|
|
|
|
|
|
|
|
|
|
|
ChangeAdministratorPasswordCommand({
|
|
|
|
|
|
this.keyID,
|
|
|
|
|
|
this.userID,
|
|
|
|
|
|
this.pwdNo,
|
|
|
|
|
|
this.pwd,
|
|
|
|
|
|
this.useCountLimit,
|
|
|
|
|
|
this.token,
|
|
|
|
|
|
this.startTime,
|
|
|
|
|
|
this.endTime,
|
|
|
|
|
|
this.needAuthor,
|
|
|
|
|
|
this.signKey,
|
|
|
|
|
|
this.privateKey,
|
|
|
|
|
|
}) : super(CommandType.generalExtendedCommond);
|
|
|
|
|
|
|
2024-10-15 14:24:35 +08:00
|
|
|
|
String? keyID;
|
|
|
|
|
|
String? userID;
|
|
|
|
|
|
int? pwdNo;
|
|
|
|
|
|
String? pwd;
|
|
|
|
|
|
int? useCountLimit;
|
|
|
|
|
|
List<int>? token;
|
|
|
|
|
|
int? startTime;
|
|
|
|
|
|
int? endTime;
|
|
|
|
|
|
int? needAuthor;
|
|
|
|
|
|
List<int>? signKey;
|
|
|
|
|
|
List<int>? privateKey;
|
|
|
|
|
|
|
2024-05-03 14:38:09 +08:00
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
String toString() {
|
|
|
|
|
|
return 'ChangeAdministratorPasswordCommand{keyID: $keyID, userID: $userID,'
|
|
|
|
|
|
' pwdNo: $pwdNo, pwd: $pwd, useCountLimit: $useCountLimit, '
|
|
|
|
|
|
'token: $token, '
|
|
|
|
|
|
'startTime: ${DateTool().dateIntToYMDHNString(startTime)}, '
|
|
|
|
|
|
'endTime: ${DateTool().dateIntToYMDHNString(endTime)}, '
|
|
|
|
|
|
'needAuthor: $needAuthor, signKey: $signKey, privateKey: $privateKey}';
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-01-18 11:25:56 +08:00
|
|
|
|
@override
|
|
|
|
|
|
List<int> messageDetail() {
|
2024-10-15 14:24:35 +08:00
|
|
|
|
final List<int> data = <int>[];
|
|
|
|
|
|
List<int> subData = <int>[];
|
|
|
|
|
|
List<int> ebcData = <int>[];
|
2024-01-18 11:25:56 +08:00
|
|
|
|
|
|
|
|
|
|
// 指令类型
|
2024-05-03 18:31:15 +08:00
|
|
|
|
// int type = commandType!.typeValue;
|
|
|
|
|
|
// double typeDouble = type / 256;
|
|
|
|
|
|
// int type1 = typeDouble.toInt();
|
|
|
|
|
|
// int type2 = type % 256;
|
|
|
|
|
|
// data.add(type1);
|
|
|
|
|
|
// data.add(type2);
|
|
|
|
|
|
data.addAll(intChangList(commandType!.typeValue));
|
2024-01-18 11:25:56 +08:00
|
|
|
|
|
|
|
|
|
|
// 子命令类型
|
|
|
|
|
|
data.add(2);
|
|
|
|
|
|
|
|
|
|
|
|
// keyID 40
|
2024-10-15 14:24:35 +08:00
|
|
|
|
final int keyIDLength = utf8.encode(keyID!).length;
|
2024-01-18 11:25:56 +08:00
|
|
|
|
subData.addAll(utf8.encode(keyID!));
|
|
|
|
|
|
subData = getFixedLengthList(subData, 40 - keyIDLength);
|
|
|
|
|
|
|
|
|
|
|
|
//userID 20
|
2024-10-15 14:24:35 +08:00
|
|
|
|
final int userIDLength = utf8.encode(userID!).length;
|
2024-01-18 11:25:56 +08:00
|
|
|
|
subData.addAll(utf8.encode(userID!));
|
|
|
|
|
|
subData = getFixedLengthList(subData, 20 - userIDLength);
|
|
|
|
|
|
|
|
|
|
|
|
// PwdNo
|
2024-05-03 18:31:15 +08:00
|
|
|
|
subData.addAll(intChangList(pwdNo!));
|
2024-01-18 11:25:56 +08:00
|
|
|
|
|
|
|
|
|
|
// pwd 20
|
2024-10-15 14:24:35 +08:00
|
|
|
|
final int pwdLength = utf8.encode(pwd!).length;
|
2024-01-18 11:25:56 +08:00
|
|
|
|
subData.addAll(utf8.encode(pwd!));
|
|
|
|
|
|
subData = getFixedLengthList(subData, 20 - pwdLength);
|
|
|
|
|
|
|
|
|
|
|
|
// UseCountLimit
|
2024-05-03 18:31:15 +08:00
|
|
|
|
subData.addAll(intChangList(useCountLimit!));
|
2024-01-18 11:25:56 +08:00
|
|
|
|
|
|
|
|
|
|
// token
|
|
|
|
|
|
subData.addAll(token!);
|
|
|
|
|
|
|
|
|
|
|
|
// startTime 4
|
|
|
|
|
|
subData.add((startTime! & 0xff000000) >> 24);
|
|
|
|
|
|
subData.add((startTime! & 0xff0000) >> 16);
|
|
|
|
|
|
subData.add((startTime! & 0xff00) >> 8);
|
2024-10-15 14:24:35 +08:00
|
|
|
|
subData.add(startTime! & 0xff);
|
2024-01-18 11:25:56 +08:00
|
|
|
|
|
|
|
|
|
|
// endTime 4
|
|
|
|
|
|
subData.add((endTime! & 0xff000000) >> 24);
|
|
|
|
|
|
subData.add((endTime! & 0xff0000) >> 16);
|
|
|
|
|
|
subData.add((endTime! & 0xff00) >> 8);
|
2024-10-15 14:24:35 +08:00
|
|
|
|
subData.add(endTime! & 0xff);
|
2024-01-18 11:25:56 +08:00
|
|
|
|
|
|
|
|
|
|
if(needAuthor == 0){
|
|
|
|
|
|
//AuthCodeLen 1
|
|
|
|
|
|
subData.add(0);
|
|
|
|
|
|
} else {
|
2024-10-15 14:24:35 +08:00
|
|
|
|
final List<int> authCodeData = <int>[];
|
2024-01-18 11:25:56 +08:00
|
|
|
|
|
|
|
|
|
|
//KeyID
|
|
|
|
|
|
authCodeData.addAll(utf8.encode(keyID!));
|
|
|
|
|
|
|
|
|
|
|
|
//authUserID
|
|
|
|
|
|
authCodeData.addAll(utf8.encode(userID!));
|
|
|
|
|
|
|
|
|
|
|
|
//token 4 首次请求 Token 填 0,如果锁需要鉴权操作者身份,则会分配动态口令并在应答消息中返回,二次请求时带上。
|
|
|
|
|
|
authCodeData.addAll(token!);
|
|
|
|
|
|
|
|
|
|
|
|
authCodeData.addAll(signKey!);
|
|
|
|
|
|
|
|
|
|
|
|
// 把KeyID、authUserID、时间戳、公钥通过md5加密之后就是authCode
|
2024-10-15 14:24:35 +08:00
|
|
|
|
final crypto.Digest authCode = crypto.md5.convert(authCodeData);
|
2024-01-18 11:25:56 +08:00
|
|
|
|
|
|
|
|
|
|
subData.add(authCode.bytes.length);
|
|
|
|
|
|
subData.addAll(authCode.bytes);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
data.add(subData.length);
|
|
|
|
|
|
data.addAll(subData);
|
|
|
|
|
|
|
|
|
|
|
|
if ((data.length % 16) != 0) {
|
2024-10-15 14:24:35 +08:00
|
|
|
|
final int add = 16 - data.length % 16;
|
2024-01-18 11:25:56 +08:00
|
|
|
|
for (int i = 0; i < add; i++) {
|
|
|
|
|
|
data.add(0);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-04-19 18:13:34 +08:00
|
|
|
|
|
2024-05-03 14:38:09 +08:00
|
|
|
|
printLog(data);
|
2024-01-18 11:25:56 +08:00
|
|
|
|
// 拿到数据之后通过LockId进行SM4 ECB加密 key:544d485f633335373034383064613864
|
|
|
|
|
|
ebcData = SM4.encrypt(data, key: privateKey, mode: SM4CryptoMode.ECB);
|
|
|
|
|
|
return ebcData;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class ChangeAdministratorPasswordReply extends Reply {
|
|
|
|
|
|
ChangeAdministratorPasswordReply.parseData(CommandType commandType, List<int> dataDetail)
|
|
|
|
|
|
: super.parseData(commandType, dataDetail) {
|
|
|
|
|
|
data = dataDetail;
|
2024-10-15 14:24:35 +08:00
|
|
|
|
final int status = data[2];
|
2024-04-19 18:13:34 +08:00
|
|
|
|
errorWithStstus(status);
|
2024-01-18 11:25:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|