2023-09-07 18:36:16 +08:00
|
|
|
|
|
|
|
|
|
|
//TODO:查询用户、指纹、密码、卡片数量(用于判断是否同步)
|
|
|
|
|
|
import 'dart:convert';
|
|
|
|
|
|
|
|
|
|
|
|
import '../io_reply.dart';
|
|
|
|
|
|
import '../io_sender.dart';
|
|
|
|
|
|
import '../io_tool/io_tool.dart';
|
|
|
|
|
|
import '../io_type.dart';
|
|
|
|
|
|
import '../sm4Encipher/sm4.dart';
|
|
|
|
|
|
import 'package:crypto/crypto.dart' as crypto;
|
|
|
|
|
|
|
|
|
|
|
|
class SenderCheckingUserInfoCountCommand extends SenderProtocol {
|
|
|
|
|
|
|
|
|
|
|
|
String? keyID;
|
|
|
|
|
|
String? userID;
|
|
|
|
|
|
int? role;
|
|
|
|
|
|
int? nowTime;
|
|
|
|
|
|
List<int>? token;
|
|
|
|
|
|
int? needAuthor;
|
|
|
|
|
|
List<int>? publicKey;
|
|
|
|
|
|
List<int>? privateKey;
|
|
|
|
|
|
|
|
|
|
|
|
SenderCheckingUserInfoCountCommand({
|
|
|
|
|
|
this.keyID,
|
|
|
|
|
|
this.userID,
|
|
|
|
|
|
this.role,
|
|
|
|
|
|
this.nowTime,
|
|
|
|
|
|
this.token,
|
|
|
|
|
|
this.needAuthor,
|
|
|
|
|
|
this.publicKey,
|
|
|
|
|
|
this.privateKey,
|
|
|
|
|
|
}) : super(CommandType.generalExtendedCommond);
|
|
|
|
|
|
|
2024-05-03 14:38:09 +08:00
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
String toString() {
|
|
|
|
|
|
return 'SenderCheckingUserInfoCountCommand{keyID: $keyID, userID: $userID,'
|
|
|
|
|
|
' role: $role, nowTime: $nowTime, token: $token, '
|
|
|
|
|
|
'needAuthor: $needAuthor, publicKey: $publicKey, privateKey: $privateKey}';
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-09-07 18:36:16 +08:00
|
|
|
|
@override
|
|
|
|
|
|
List<int> messageDetail() {
|
|
|
|
|
|
List<int> data = [];
|
|
|
|
|
|
List<int> subData = [];
|
|
|
|
|
|
List<int> ebcData = [];
|
|
|
|
|
|
|
|
|
|
|
|
// 指令类型
|
|
|
|
|
|
int type = commandType!.typeValue;
|
|
|
|
|
|
double typeDouble = type / 256;
|
|
|
|
|
|
int type1 = typeDouble.toInt();
|
|
|
|
|
|
int type2 = type % 256;
|
|
|
|
|
|
data.add(type1);
|
|
|
|
|
|
data.add(type2);
|
|
|
|
|
|
|
|
|
|
|
|
// 子命令类型
|
|
|
|
|
|
data.add(15);
|
|
|
|
|
|
|
|
|
|
|
|
// keyID 40
|
|
|
|
|
|
int keyIDLength = utf8.encode(keyID!).length;
|
|
|
|
|
|
subData.addAll(utf8.encode(keyID!));
|
|
|
|
|
|
subData = getFixedLengthList(subData, 40 - keyIDLength);
|
|
|
|
|
|
|
|
|
|
|
|
//userID 20
|
|
|
|
|
|
int userIDLength = utf8.encode(userID!).length;
|
|
|
|
|
|
subData.addAll(utf8.encode(userID!));
|
|
|
|
|
|
subData = getFixedLengthList(subData, 20 - userIDLength);
|
|
|
|
|
|
|
|
|
|
|
|
// Role
|
|
|
|
|
|
subData.add(role!);
|
|
|
|
|
|
|
|
|
|
|
|
// time
|
|
|
|
|
|
subData.add((nowTime! & 0xff000000) >> 24);
|
|
|
|
|
|
subData.add((nowTime! & 0xff0000) >> 16);
|
|
|
|
|
|
subData.add((nowTime! & 0xff00) >> 8);
|
|
|
|
|
|
subData.add((nowTime! & 0xff));
|
|
|
|
|
|
|
|
|
|
|
|
// token
|
|
|
|
|
|
// subData.addAll(token!);
|
|
|
|
|
|
|
|
|
|
|
|
if(needAuthor == 0){
|
|
|
|
|
|
//AuthCodeLen 1
|
|
|
|
|
|
subData.add(0);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
List<int> authCodeData = [];
|
|
|
|
|
|
|
|
|
|
|
|
//authUserID
|
|
|
|
|
|
authCodeData.addAll(utf8.encode(userID!));
|
|
|
|
|
|
|
|
|
|
|
|
//KeyID
|
|
|
|
|
|
authCodeData.addAll(utf8.encode(keyID!));
|
|
|
|
|
|
|
|
|
|
|
|
//token 4 首次请求 Token 填 0,如果锁需要鉴权操作者身份,则会分配动态口令并在应答消息中返回,二次请求时带上。
|
|
|
|
|
|
authCodeData.addAll(token!);
|
|
|
|
|
|
|
|
|
|
|
|
authCodeData.addAll(publicKey!);
|
|
|
|
|
|
|
|
|
|
|
|
// 把KeyID、authUserID、时间戳、公钥通过md5加密之后就是authCode
|
|
|
|
|
|
var authCode = crypto.md5.convert(authCodeData);
|
|
|
|
|
|
|
|
|
|
|
|
subData.add(authCode.bytes.length);
|
|
|
|
|
|
subData.addAll(authCode.bytes);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
data.add(subData.length);
|
|
|
|
|
|
data.addAll(subData);
|
|
|
|
|
|
|
|
|
|
|
|
if ((data.length % 16) != 0) {
|
|
|
|
|
|
int add = (16 - data.length % 16);
|
|
|
|
|
|
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);
|
2023-09-07 18:36:16 +08:00
|
|
|
|
// 拿到数据之后通过LockId进行SM4 ECB加密 key:544d485f633335373034383064613864
|
|
|
|
|
|
ebcData = SM4.encrypt(data, key: privateKey, mode: SM4CryptoMode.ECB);
|
|
|
|
|
|
return ebcData;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class SenderCheckingUserInfoCountReply extends Reply {
|
|
|
|
|
|
SenderCheckingUserInfoCountReply.parseData(CommandType commandType, List<int> dataDetail)
|
|
|
|
|
|
: super.parseData(commandType, dataDetail) {
|
|
|
|
|
|
data = dataDetail;
|
2024-04-19 18:13:34 +08:00
|
|
|
|
int status = data[2];
|
|
|
|
|
|
errorWithStstus(status);
|
2023-09-07 18:36:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|