119 lines
3.3 KiB
Dart
119 lines
3.3 KiB
Dart
|
||
import 'dart:convert';
|
||
|
||
import 'package:crypto/crypto.dart' as crypto;
|
||
|
||
import '../io_reply.dart';
|
||
import '../io_sender.dart';
|
||
import '../io_tool/io_tool.dart';
|
||
import '../io_type.dart';
|
||
import '../sm4Encipher/sm4.dart';
|
||
|
||
class UpdataLockFingerprintListCommand extends SenderProtocol {
|
||
UpdataLockFingerprintListCommand({
|
||
this.lockID,
|
||
this.keyID,
|
||
this.userID,
|
||
this.page,
|
||
this.countReq,
|
||
this.token,
|
||
this.needAuthor,
|
||
this.signKey,
|
||
this.privateKey
|
||
}) : super(CommandType.updataLockFingerprintList);
|
||
|
||
String? lockID;
|
||
String? keyID;
|
||
String? userID;
|
||
int? page;
|
||
int? countReq;
|
||
List<int>? token;
|
||
int? needAuthor;
|
||
List<int>? signKey;
|
||
List<int>? privateKey;
|
||
|
||
@override
|
||
String toString() {
|
||
return 'UpdataLockPasswordListCommand{lockID: $lockID, keyID:$keyID userID: $userID, '
|
||
'page:$page countReq: $countReq, token: $token, '
|
||
'signKey: $signKey, privateKey: $privateKey}';
|
||
}
|
||
|
||
@override
|
||
List<int> messageDetail() {
|
||
List<int> data = <int>[];
|
||
List<int> ebcData = <int>[];
|
||
|
||
// 指令类型
|
||
final int type = commandType!.typeValue;
|
||
final double typeDouble = type / 256;
|
||
final int type1 = typeDouble.toInt();
|
||
final int type2 = type % 256;
|
||
data.add(type1);
|
||
data.add(type2);
|
||
|
||
// 锁id 40
|
||
final int lockIDLength = utf8.encode(lockID!).length;
|
||
data.addAll(utf8.encode(lockID!));
|
||
data = getFixedLengthList(data, 40 - lockIDLength);
|
||
|
||
//userID 要接受钥匙的用户的useid 20
|
||
final int userIDLength = utf8.encode(userID!).length;
|
||
data.addAll(utf8.encode(userID!));
|
||
data = getFixedLengthList(data, 20 - userIDLength);
|
||
|
||
// page
|
||
data.add(page!);
|
||
|
||
// countReq
|
||
data.add(countReq!);
|
||
|
||
// token 长度4 首次请求 Token 填 0,如果锁需要鉴权 操作者身份,则会分配动态口令并在应答消息中返回,二次请求时带上。 当token失效或者第一次发送的时候token为0
|
||
data.addAll(token!);
|
||
|
||
if(needAuthor == 0){
|
||
//AuthCodeLen 1
|
||
data.add(0);
|
||
} else {
|
||
final List<int> authCodeData = <int>[];
|
||
//KeyID
|
||
authCodeData.addAll(utf8.encode(lockID!));
|
||
|
||
//UserID
|
||
authCodeData.addAll(utf8.encode(userID!));
|
||
|
||
//token 4 首次请求 Token 填 0,如果锁需要鉴权操作者身份,则会分配动态口令并在应答消息中返回,二次请求时带上。
|
||
authCodeData.addAll(token!);
|
||
|
||
authCodeData.addAll(signKey!);
|
||
|
||
// 把KeyID、authUserID、时间戳、公钥通过md5加密之后就是authCode
|
||
final crypto.Digest authCode = crypto.md5.convert(authCodeData);
|
||
|
||
data.add(authCode.bytes.length);
|
||
data.addAll(authCode.bytes);
|
||
}
|
||
|
||
if ((data.length % 16) != 0) {
|
||
final int add = 16 - data.length % 16;
|
||
for (int i = 0; i < add; i++) {
|
||
data.add(0);
|
||
}
|
||
}
|
||
|
||
printLog(data);
|
||
// 拿到数据之后通过LockId进行SM4 ECB加密 key:544d485f633335373034383064613864
|
||
ebcData = SM4.encrypt(data, key: privateKey, mode: SM4CryptoMode.ECB);
|
||
return ebcData;
|
||
}
|
||
}
|
||
|
||
class UpdataLockFingerprintListReply extends Reply {
|
||
UpdataLockFingerprintListReply.parseData(CommandType commandType, List<int> dataDetail)
|
||
: super.parseData(commandType, dataDetail) {
|
||
data = dataDetail;
|
||
|
||
final int status = data[2];
|
||
errorWithStstus(status);
|
||
}
|
||
} |