Matter increase CASE logs (#18351)

This commit is contained in:
s-hadinger 2023-04-06 19:28:43 +02:00 committed by GitHub
parent d8bdcebc78
commit 1a42320a16
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 1185 additions and 1037 deletions

View File

@ -322,11 +322,14 @@ class Matter_Commisioning_Context
return false
end
var sigma1 = matter.Sigma1().parse(msg.raw, msg.app_payload_idx)
tasmota.log(string.format("MTR: sigma1=%s", matter.inspect(sigma1)), 4)
self.initiatorEph_pub = sigma1.initiatorEphPubKey
# find session
var is_resumption = (sigma1.resumptionID != nil && sigma1.initiatorResumeMIC != nil)
tasmota.log(string.format("MTR: is_resumption=%i", is_resumption ? 1 : 0), 4)
is_resumption = false # quick fix TODO
# Check that it's a resumption
var session = msg.session
@ -433,6 +436,9 @@ class Matter_Commisioning_Context
tasmota.log("MTR: fabric="+matter.inspect(session._fabric), 4)
tasmota.log("MTR: no_private_key="+session._fabric.no_private_key.tohex(), 4)
tasmota.log("MTR: noc ="+session._fabric.noc.tohex(), 4)
if session._fabric.get_icac()
tasmota.log("MTR: icac ="+session._fabric.get_icac().tohex(), 4)
end
tasmota.log("MTR: root_ca_cert ="+session._fabric.root_ca_certificate.tohex(), 4)
# Compute Sigma2, p.162
@ -517,8 +523,8 @@ class Matter_Commisioning_Context
# compute TranscriptHash = Crypto_Hash(message = Msg1 || Msg2)
var TranscriptHash = crypto.SHA256().update(session.__Msg1).update(session.__Msg2).out()
tasmota.log("MTR: * session = " + str(session), 4)
tasmota.log("MTR: session.ipk_epoch_key " + str(session.get_ipk_epoch_key()), 4)
tasmota.log("MTR: session.fabric_compressed " + str(session.get_fabric_compressed()), 4)
tasmota.log("MTR: .ipk_epoch_key=" + str(session.get_ipk_epoch_key()), 4)
tasmota.log("MTR: .fabric_compr = " + str(session.get_fabric_compressed()), 4)
tasmota.log("MTR: * ipk_group_key = " + session.get_ipk_group_key().tohex(), 4)
tasmota.log("MTR: * TranscriptHash= " + TranscriptHash.tohex(), 4)
@ -549,9 +555,13 @@ class Matter_Commisioning_Context
end
var TBEData3TLV = matter.TLV.parse(TBEData3)
tasmota.log("MTR: * TBEData3TLV = " + str(TBEData3TLV), 4)
var initiatorNOC = TBEData3TLV.findsubval(1)
var initiatorICAC = TBEData3TLV.findsubval(2)
var ec_signature = TBEData3TLV.findsubval(3)
tasmota.log("MTR: * initiatorNOC = " + str(initiatorNOC), 4)
tasmota.log("MTR: * initiatorICAC = " + str(initiatorICAC), 4)
tasmota.log("MTR: * ec_signature = " + str(ec_signature), 4)
# Success = Crypto_VerifyChain(certificates = [TBEData3.initiatorNOC, TBEData3.initiatorICAC, TrustedRCAC]), when TBEData3.initiatorICAC is present
# TODO
var initiatorNOCTLV = matter.TLV.parse(initiatorNOC)
@ -567,10 +577,12 @@ class Matter_Commisioning_Context
sigma3_tbs.add_TLV(1, matter.TLV.B1, initiatorNOC)
sigma3_tbs.add_TLV(2, matter.TLV.B1, initiatorICAC)
sigma3_tbs.add_TLV(3, matter.TLV.B1, self.initiatorEph_pub)
sigma3_tbs.add_TLV(4, matter.TLV.B1, self.ResponderEph_pub)
sigma3_tbs.add_TLV(4, matter.TLV.B1, self.ResponderEph_pub)
tasmota.log("MTR: * sigma3_tbs = " + str(sigma3_tbs), 4)
var sigma3_tbs_raw = sigma3_tbs.tlv2raw()
tasmota.log("MTR: * sigma3_tbs_raw= " + sigma3_tbs_raw.tohex(), 4)
tasmota.log("MTR: * initiatorNOCPubKey = " + initiatorNOCPubKey.tohex(), 4)
tasmota.log("MTR: * initiatorNOCPubKey= " + initiatorNOCPubKey.tohex(), 4)
tasmota.log("MTR: * ec_signature = " + ec_signature.tohex(), 4)
tasmota.log("****************************************", 4)
@ -588,6 +600,10 @@ class Matter_Commisioning_Context
tasmota.log("MTR: Sigma3 verified, computing new keys", 3)
TranscriptHash = crypto.SHA256().update(session.__Msg1).update(session.__Msg2).update(sigma3.Msg3).out()
tasmota.log("MTR: * __Msg1 = " + session.__Msg1.tohex(), 4)
tasmota.log("MTR: * __Msg2 = " + session.__Msg2.tohex(), 4)
tasmota.log("MTR: * __Msg3 = " + sigma3.Msg3.tohex(), 4)
tasmota.log("MTR: * TranscriptHash = " + TranscriptHash.tohex(), 4)
# we can now free __Msg1 and __Msg2
session.__Msg1 = nil
session.__Msg2 = nil

View File

@ -168,8 +168,8 @@ class Matter_Sigma1
self.SLEEPY_IDLE_INTERVAL = initiatorSEDParams.findsubval(1)
self.SLEEPY_ACTIVE_INTERVAL = initiatorSEDParams.findsubval(2)
end
var resumptionID = val.findsub(6)
var initiatorResumeMIC = val.findsub(7)
self.resumptionID = val.findsubval(6)
self.initiatorResumeMIC = val.findsubval(7)
return self
end
end

View File

@ -503,7 +503,7 @@ extern const bclass be_class_Matter_Sigma1;
********************************************************************/
be_local_closure(Matter_Sigma1_parse, /* name */
be_nested_proto(
9, /* nstack */
8, /* nstack */
3, /* argc */
2, /* varg */
0, /* has upvals */
@ -511,7 +511,7 @@ be_local_closure(Matter_Sigma1_parse, /* name */
0, /* has sup protos */
NULL, /* no sub protos */
1, /* has constants */
( &(const bvalue[21]) { /* constants */
( &(const bvalue[23]) { /* constants */
/* K0 */ be_const_int(0),
/* K1 */ be_nested_str_weak(matter),
/* K2 */ be_nested_str_weak(TLV),
@ -533,10 +533,12 @@ be_local_closure(Matter_Sigma1_parse, /* name */
/* K18 */ be_nested_str_weak(SLEEPY_IDLE_INTERVAL),
/* K19 */ be_nested_str_weak(findsubval),
/* K20 */ be_nested_str_weak(SLEEPY_ACTIVE_INTERVAL),
/* K21 */ be_nested_str_weak(resumptionID),
/* K22 */ be_nested_str_weak(initiatorResumeMIC),
}),
be_str_weak(parse),
&be_const_str_solidified,
( &(const binstruction[58]) { /* code */
( &(const binstruction[60]) { /* code */
0x4C0C0000, // 0000 LDNIL R3
0x1C0C0403, // 0001 EQ R3 R2 R3
0x780E0000, // 0002 JMPF R3 #0004
@ -588,13 +590,15 @@ be_local_closure(Matter_Sigma1_parse, /* name */
0x581C000D, // 0030 LDCONST R7 K13
0x7C140400, // 0031 CALL R5 2
0x90022805, // 0032 SETMBR R0 K20 R5
0x8C140711, // 0033 GETMET R5 R3 K17
0x8C140713, // 0033 GETMET R5 R3 K19
0x541E0005, // 0034 LDINT R7 6
0x7C140400, // 0035 CALL R5 2
0x8C180711, // 0036 GETMET R6 R3 K17
0x54220006, // 0037 LDINT R8 7
0x7C180400, // 0038 CALL R6 2
0x80040000, // 0039 RET 1 R0
0x90022A05, // 0036 SETMBR R0 K21 R5
0x8C140713, // 0037 GETMET R5 R3 K19
0x541E0006, // 0038 LDINT R7 7
0x7C140400, // 0039 CALL R5 2
0x90022C05, // 003A SETMBR R0 K22 R5
0x80040000, // 003B RET 1 R0
})
)
);