-
Notifications
You must be signed in to change notification settings - Fork 14
/
packet-matter-common.cpp
963 lines (785 loc) · 31.1 KB
/
packet-matter-common.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
/*
* Copyright (c) 2023 Project CHIP Authors.
*
* Use of this source code is governed by a BSD-style
* license that can be found in the LICENSE file or at
* https://opensource.org/license/bsd-3-clause
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <glib.h>
#include "config.h"
#include <epan/packet.h>
#include <Matter/Core/MatterCore.h>
#include <Matter/Protocols/MatterProfiles.h>
#include <Matter/Protocols/common/CommonProfile.h>
#include <Matter/Protocols/security/MatterCASE.h>
#include <Matter/Support/MatterNames.h>
#include <Matter/Support/CodeUtils.h>
#include <Matter/Support/ErrorStr.h>
#include "packet-matter.h"
#include "TLVDissector.h"
#include "MatterMessageTracker.h"
using namespace matter;
using namespace matter::TLV;
using namespace matter::Profiles;
using namespace matter::Profiles::Common;
using namespace matter::Profiles::Security;
extern void AssociateWithIMSubscription(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree _U_, MatterMessageRecord *msgRec);
static int proto_MatterCommon = -1;
static int ett_MatterCommon = -1;
static int hf_StatusReport_ProfileId = -1;
static int hf_StatusReport_StatusCode = -1;
static int hf_StatusReport_TLV = -1;
static int hf_StatusReport_IsError = -1;
//static int ett_PBKDFParamRequest = -1;
//static int hf_PBKDFParamRequest = -1;
static int hf_PBKDFParamRequest_initiatorRandom = -1;
static int hf_PBKDFParamRequest_localSessionId = -1;
static int hf_PBKDFParamRequest_passcodeId = -1;
static int hf_PBKDFParamRequest_hasPbkdfParams = -1;
static int hf_PBKDFParamResponse_responderRandom = -1;
static int hf_PBKDFParamResponse_pbkdfIterationCount = -1;
static int hf_PBKDFParamResponse_pbkdfSaltLength = -1;
static int hf_PBKDFParamResponse_pbkdfSalt = -1;
static int hf_Pake1_pA = -1;
static int hf_Pake2_pB = -1;
static int hf_Pake2_cB = -1;
static int hf_Pake3_cA = -1;
static int hf_Session_destinationId = -1;
static int hf_Session_ephPublicKey = -1;
static int hf_Session_encrypted = -1;
static int
DissectStatusReport(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree _U_, const MatterMessageInfo& msgInfo)
{
MATTER_ERROR err = MATTER_NO_ERROR;
proto_item *isErrorItem;
uint16_t generalCode;
uint32_t profileId;
uint16_t statusCode;
const char *profileName = NULL;
const char *statusReportStr = NULL;
int parsePoint = 0;
bool isError;
proto_item_append_text(proto_tree_get_parent(tree), ": Status Report");
// General code
generalCode = tvb_get_letohs(tvb, parsePoint);
statusReportStr = matter::StatusReportStr(kMatterProfile_General, generalCode);
proto_tree_add_uint_format_value(tree, hf_StatusReport_StatusCode, tvb, parsePoint, 2, generalCode, "%s", statusReportStr);
parsePoint += 2;
profileId = tvb_get_letohl(tvb, parsePoint);
profileName = GetProtocolName(profileId);
proto_tree_add_uint_format_value(tree, hf_StatusReport_ProfileId, tvb, parsePoint, 4, profileId,
(profileName != NULL) ? "%08X (%s)" : "%08X", profileId, profileName);
parsePoint += 4;
statusCode = tvb_get_letohs(tvb, parsePoint);
statusReportStr = matter::StatusReportStr(profileId, statusCode);
proto_tree_add_uint_format_value(tree, hf_StatusReport_StatusCode, tvb, parsePoint, 2, statusCode, "%s", statusReportStr);
parsePoint += 2;
isError = (statusCode != General::kStatus_SUCCESS);
col_prepend_fstr(pinfo->cinfo, COL_INFO, "StatusReport (%s) ", (isError) ? "ERROR" : "SUCCESS");
if (parsePoint < msgInfo.payloadLen) {
const uint8_t *msgData = (const uint8_t *)tvb_memdup(pinfo->pool, tvb, parsePoint, msgInfo.payloadLen - parsePoint);
TLVDissector tlvDissector;
tlvDissector.Init(msgData, msgInfo.payloadLen - parsePoint, parsePoint);
err = tlvDissector.Next();
SuccessOrExit(err);
err = tlvDissector.AddGenericTLVItem(tree, hf_StatusReport_TLV, tvb, false);
SuccessOrExit(err);
}
isErrorItem = proto_tree_add_boolean(tree, hf_StatusReport_IsError, tvb, 0, 0, isError);
PROTO_ITEM_SET_HIDDEN(isErrorItem);
AssociateWithIMSubscription(tvb, pinfo, tree, msgInfo.msgRec);
exit:
return msgInfo.payloadLen;
}
static int
DissectStandaloneAck(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree _U_, const MatterMessageInfo& msgInfo)
{
proto_item_append_text(proto_tree_get_parent(tree), ": StandaloneAck");
if ((msgInfo.exchHeader & kMatterExchangeFlag_AckId) != 0) {
col_prepend_fstr(pinfo->cinfo, COL_INFO, "StandAloneACK ");
}
else {
col_prepend_fstr(pinfo->cinfo, COL_INFO, "Null ");
}
AssociateWithIMSubscription(tvb, pinfo, tree, msgInfo.msgRec);
return 1;
}
/**
* Dissect PASE PBKDF Request message.
pbkdfparamreq-struct => STRUCTURE [ tag-order ]
{
initiatorRandom [1] : OCTET STRING [ length 32 ],
initiatorSessionId [2] : UNSIGNED INTEGER [ range 16-bits ],
passcodeId [3] : UNSIGNED INTEGER [ length 16-bits ],
hasPBKDFParameters [4] : BOOLEAN,
initiatorMRPParams [5, optional] : mrp-parameter-struct
}
mrp-parameter-struct => STRUCTURE [ tag-order ]
{
MRP_RETRY_INTERVAL_IDLE [1, optional] : UNSIGNED INTEGER [ range 16-bits ],
MRP_RETRY_INTERVAL_ACTIVE [2, optional] : UNSIGNED INTEGER [ range 16-bits ]
}
*/
static int
DissectPBKDFParamRequest(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree _U_, const MatterMessageInfo& msgInfo)
{
MATTER_ERROR err = MATTER_NO_ERROR;
int parsePoint = 0;
const uint8_t *msgData = (const uint8_t *)tvb_memdup(pinfo->pool, tvb, parsePoint, msgInfo.payloadLen - parsePoint);
TLVDissector tlvDissector;
//proto_tree *subTree;
proto_item_append_text(proto_tree_get_parent(tree), ": PASE PBKDF Param Request");
tlvDissector.Init(msgData, msgInfo.payloadLen - parsePoint, parsePoint);
tlvDissector.ImplicitProfileId = kMatterProfile_Common;
err = tlvDissector.Next();
SuccessOrExit(err);
//err = tlvDissector.AddSubTreeItem(tree, hf_PBKDFParamRequest, ett_PBKDFParamRequest, tvb, subTree);
//SuccessOrExit(err);
err = tlvDissector.EnterContainer();
SuccessOrExit(err);
while (true) {
err = tlvDissector.Next();
if (err == MATTER_END_OF_TLV)
break;
SuccessOrExit(err);
uint64_t tag = tlvDissector.GetTag();
TLVType type = tlvDissector.GetType();
VerifyOrExit(IsContextTag(tag), err = MATTER_ERROR_UNEXPECTED_TLV_ELEMENT);
switch (TagNumFromTag(tag)) {
case 1:
VerifyOrExit(type == kTLVType_ByteString, err = MATTER_ERROR_UNEXPECTED_TLV_ELEMENT);
err = tlvDissector.AddTypedItem(tree, hf_PBKDFParamRequest_initiatorRandom, tvb);
SuccessOrExit(err);
break;
case 2:
VerifyOrExit(type == kTLVType_UnsignedInteger, err = MATTER_ERROR_UNEXPECTED_TLV_ELEMENT);
err = tlvDissector.AddTypedItem(tree, hf_PBKDFParamRequest_localSessionId, tvb);
SuccessOrExit(err);
break;
case 3:
VerifyOrExit(type == kTLVType_UnsignedInteger, err = MATTER_ERROR_UNEXPECTED_TLV_ELEMENT);
err = tlvDissector.AddTypedItem(tree, hf_PBKDFParamRequest_passcodeId, tvb);
SuccessOrExit(err);
break;
case 4:
VerifyOrExit(type == kTLVType_Boolean, err = MATTER_ERROR_UNEXPECTED_TLV_ELEMENT);
err = tlvDissector.AddTypedItem(tree, hf_PBKDFParamRequest_hasPbkdfParams, tvb);
SuccessOrExit(err);
break;
case 5:
// TODO: add support for mrp-parameter-struct
break;
default:
ExitNow(err = MATTER_ERROR_UNEXPECTED_TLV_ELEMENT);
}
}
err = tlvDissector.ExitContainer();
SuccessOrExit(err);
exit:
return err;
}
/**
* Dissect PASE PBKDF Parameter Response message.
pbkdfparamresp-struct => STRUCTURE [ tag-order ]
{
initiatorRandom [1] : OCTET STRING [ length 32 ],
responderRandom [2] : OCTET STRING [ length 32 ],
responderSessionId [3] : UNSIGNED INTEGER [ range 16-bits ],
pbkdf_parameters [4] : Crypto_PBKDFParameterSet,
responderMRPParams [5, optional] : mrp-parameter-struct
}
Crypto_PBKDFParameterSet => STRUCTURE [ tag-order ]
{
iterations [1] : UNSIGNED INTEGER [ range 32-bits ],
salt [2] : OCTET STRING [ length 16..32 ],
}
mrp-parameter-struct => STRUCTURE [ tag-order ]
{
MRP_RETRY_INTERVAL_IDLE [1, optional] : UNSIGNED INTEGER [ range 16-bits ],
MRP_RETRY_INTERVAL_ACTIVE [2, optional] : UNSIGNED INTEGER [ range 16-bits ]
}
*/
static int
DissectPBKDFParamResponse(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree _U_, const MatterMessageInfo& msgInfo)
{
MATTER_ERROR err = MATTER_NO_ERROR;
int parsePoint = 0;
const uint8_t *msgData = (const uint8_t *)tvb_memdup(pinfo->pool, tvb, parsePoint, msgInfo.payloadLen - parsePoint);
TLVDissector tlvDissector;
proto_item_append_text(proto_tree_get_parent(tree), ": PASE PBKDF Param Response");
tlvDissector.Init(msgData, msgInfo.payloadLen - parsePoint, parsePoint);
tlvDissector.ImplicitProfileId = kMatterProfile_Common;
err = tlvDissector.Next();
SuccessOrExit(err);
err = tlvDissector.EnterContainer();
SuccessOrExit(err);
while (true) {
err = tlvDissector.Next();
if (err == MATTER_END_OF_TLV)
break;
SuccessOrExit(err);
uint64_t tag = tlvDissector.GetTag();
TLVType type = tlvDissector.GetType();
VerifyOrExit(IsContextTag(tag), err = MATTER_ERROR_UNEXPECTED_TLV_ELEMENT);
switch (TagNumFromTag(tag)) {
case 1:
VerifyOrExit(type == kTLVType_ByteString, err = MATTER_ERROR_UNEXPECTED_TLV_ELEMENT);
err = tlvDissector.AddTypedItem(tree, hf_PBKDFParamRequest_initiatorRandom, tvb);
SuccessOrExit(err);
break;
case 2:
VerifyOrExit(type == kTLVType_ByteString, err = MATTER_ERROR_UNEXPECTED_TLV_ELEMENT);
err = tlvDissector.AddTypedItem(tree, hf_PBKDFParamResponse_responderRandom, tvb);
SuccessOrExit(err);
break;
case 3:
VerifyOrExit(type == kTLVType_UnsignedInteger, err = MATTER_ERROR_UNEXPECTED_TLV_ELEMENT);
err = tlvDissector.AddTypedItem(tree, hf_PBKDFParamRequest_localSessionId, tvb);
SuccessOrExit(err);
break;
case 4:
// TODO: add support for Crypto_PBKDFParameterSet
break;
case 5:
// TODO: add support for mrp-parameter-struct
break;
default:
ExitNow(err = MATTER_ERROR_UNEXPECTED_TLV_ELEMENT);
}
}
err = tlvDissector.ExitContainer();
SuccessOrExit(err);
exit:
return err;
}
/**
* Dissect PASE Pake1 Message.
pake-1-struct => STRUCTURE [ tag-order ]
{
pA [1] : OCTET STRING [ length CRYPTO_PUBLIC_KEY_SIZE_BYTES ],
}
*/
static int
DissectPasePake1(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree _U_, const MatterMessageInfo& msgInfo)
{
MATTER_ERROR err = MATTER_NO_ERROR;
int parsePoint = 0;
const uint8_t *msgData = (const uint8_t *)tvb_memdup(pinfo->pool, tvb, parsePoint, msgInfo.payloadLen - parsePoint);
TLVDissector tlvDissector;
proto_item_append_text(proto_tree_get_parent(tree), ": PASE Pake1");
tlvDissector.Init(msgData, msgInfo.payloadLen - parsePoint, parsePoint);
tlvDissector.ImplicitProfileId = kMatterProfile_Common;
err = tlvDissector.Next();
SuccessOrExit(err);
err = tlvDissector.EnterContainer();
SuccessOrExit(err);
while (true) {
err = tlvDissector.Next();
if (err == MATTER_END_OF_TLV)
break;
SuccessOrExit(err);
uint64_t tag = tlvDissector.GetTag();
TLVType type = tlvDissector.GetType();
VerifyOrExit(IsContextTag(tag), err = MATTER_ERROR_UNEXPECTED_TLV_ELEMENT);
switch (TagNumFromTag(tag)) {
case 1:
VerifyOrExit(type == kTLVType_ByteString, err = MATTER_ERROR_UNEXPECTED_TLV_ELEMENT);
err = tlvDissector.AddTypedItem(tree, hf_Pake1_pA, tvb);
SuccessOrExit(err);
break;
default:
ExitNow(err = MATTER_ERROR_UNEXPECTED_TLV_ELEMENT);
}
}
err = tlvDissector.ExitContainer();
SuccessOrExit(err);
exit:
return err;
}
/**
* Dissect PASE Pake2 message.
pake-2-struct => STRUCTURE [ tag-order ]
{
pB [1] : OCTET STRING [ length CRYPTO_PUBLIC_KEY_SIZE_BYTES ],
cB [2] : OCTET STRING [ length CRYPTO_HASH_LEN_BYTES],
}
*/
static int
DissectPasePake2(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree _U_, const MatterMessageInfo& msgInfo)
{
MATTER_ERROR err = MATTER_NO_ERROR;
int parsePoint = 0;
const uint8_t *msgData = (const uint8_t *)tvb_memdup(pinfo->pool, tvb, parsePoint, msgInfo.payloadLen - parsePoint);
TLVDissector tlvDissector;
proto_item_append_text(proto_tree_get_parent(tree), ": PASE Pake2");
tlvDissector.Init(msgData, msgInfo.payloadLen - parsePoint, parsePoint);
tlvDissector.ImplicitProfileId = kMatterProfile_Common;
err = tlvDissector.Next();
SuccessOrExit(err);
err = tlvDissector.EnterContainer();
SuccessOrExit(err);
while (true) {
err = tlvDissector.Next();
if (err == MATTER_END_OF_TLV)
break;
SuccessOrExit(err);
uint64_t tag = tlvDissector.GetTag();
TLVType type = tlvDissector.GetType();
VerifyOrExit(IsContextTag(tag), err = MATTER_ERROR_UNEXPECTED_TLV_ELEMENT);
switch (TagNumFromTag(tag)) {
case 1:
VerifyOrExit(type == kTLVType_ByteString, err = MATTER_ERROR_UNEXPECTED_TLV_ELEMENT);
err = tlvDissector.AddTypedItem(tree, hf_Pake2_pB, tvb);
SuccessOrExit(err);
break;
case 2:
VerifyOrExit(type == kTLVType_ByteString, err = MATTER_ERROR_UNEXPECTED_TLV_ELEMENT);
err = tlvDissector.AddTypedItem(tree, hf_Pake2_cB, tvb);
SuccessOrExit(err);
break;
default:
ExitNow(err = MATTER_ERROR_UNEXPECTED_TLV_ELEMENT);
}
}
err = tlvDissector.ExitContainer();
SuccessOrExit(err);
exit:
return err;
}
/**
* Dissect PASE Pake3 message.
pake-3-struct => STRUCTURE [ tag-order ]
{
cA [1] : OCTET STRING [length CRYPTO_HASH_LEN_BYTES],
}
*/
static int
DissectPasePake3(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree _U_, const MatterMessageInfo& msgInfo)
{
MATTER_ERROR err = MATTER_NO_ERROR;
int parsePoint = 0;
const uint8_t *msgData = (const uint8_t *)tvb_memdup(pinfo->pool, tvb, parsePoint, msgInfo.payloadLen - parsePoint);
TLVDissector tlvDissector;
proto_item_append_text(proto_tree_get_parent(tree), ": PASE Pake3");
tlvDissector.Init(msgData, msgInfo.payloadLen - parsePoint, parsePoint);
tlvDissector.ImplicitProfileId = kMatterProfile_Common;
err = tlvDissector.Next();
SuccessOrExit(err);
err = tlvDissector.EnterContainer();
SuccessOrExit(err);
while (true) {
err = tlvDissector.Next();
if (err == MATTER_END_OF_TLV)
break;
SuccessOrExit(err);
uint64_t tag = tlvDissector.GetTag();
TLVType type = tlvDissector.GetType();
VerifyOrExit(IsContextTag(tag), err = MATTER_ERROR_UNEXPECTED_TLV_ELEMENT);
switch (TagNumFromTag(tag)) {
case 1:
VerifyOrExit(type == kTLVType_ByteString, err = MATTER_ERROR_UNEXPECTED_TLV_ELEMENT);
err = tlvDissector.AddTypedItem(tree, hf_Pake3_cA, tvb);
SuccessOrExit(err);
break;
default:
ExitNow(err = MATTER_ERROR_UNEXPECTED_TLV_ELEMENT);
}
}
err = tlvDissector.ExitContainer();
SuccessOrExit(err);
exit:
return err;
}
/**
sigma-error-enum => UNSIGNED INTEGER [ range 8bits ] {
NoSharedTrustRoots = 0x01,
InvalidParameter = 0x02,
}
*/
static int
DissectPasePakeError(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree _U_, const MatterMessageInfo& msgInfo)
{
col_prepend_fstr(pinfo->cinfo, COL_INFO, "PASE Spake2 Err ");
proto_item_append_text(proto_tree_get_parent(tree), ": PASE Spake2 Error");
return 1;
}
/**
* Dissect CASE Sigma1 message.
sigma-1-struct => STRUCTURE [ tag-order ]
{
initiatorRandom [1] : OCTET STRING [ length 32 ],
initiatorSessionId [2] : UNSIGNED INTEGER [ range 16-bits ],
destinationId [3] : destination-identifier,
initiatorEphPubKey [4] : ec-pub-key,
initiatorMRPParams [5, optional] : mrp-parameter-struct,
resumptionID [6, optional] : OCTET STRING [ length 16 ],
initiatorResumeMIC [7, optional] : OCTET STRING [ length CRYPTO_AEAD_MIC_LENGTH_BYTES ]
}
*/
static int
DissectCaseSigma1(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree _U_, const MatterMessageInfo& msgInfo)
{
MATTER_ERROR err = MATTER_NO_ERROR;
int parsePoint = 0;
const uint8_t *msgData = (const uint8_t *)tvb_memdup(pinfo->pool, tvb, parsePoint, msgInfo.payloadLen - parsePoint);
TLVDissector tlvDissector;
proto_item_append_text(proto_tree_get_parent(tree), ": CASE Sigma1");
tlvDissector.Init(msgData, msgInfo.payloadLen - parsePoint, parsePoint);
tlvDissector.ImplicitProfileId = kMatterProfile_Common;
err = tlvDissector.Next();
SuccessOrExit(err);
err = tlvDissector.EnterContainer();
SuccessOrExit(err);
while (true) {
err = tlvDissector.Next();
if (err == MATTER_END_OF_TLV)
break;
SuccessOrExit(err);
uint64_t tag = tlvDissector.GetTag();
TLVType type = tlvDissector.GetType();
VerifyOrExit(IsContextTag(tag), err = MATTER_ERROR_UNEXPECTED_TLV_ELEMENT);
switch (TagNumFromTag(tag)) {
case CASE::Sigma1::kTag_InitiatorRandom:
VerifyOrExit(type == kTLVType_ByteString, err = MATTER_ERROR_UNEXPECTED_TLV_ELEMENT);
err = tlvDissector.AddTypedItem(tree, hf_PBKDFParamRequest_initiatorRandom, tvb);
SuccessOrExit(err);
break;
case CASE::Sigma1::kTag_InitiatorSessionId:
VerifyOrExit(type == kTLVType_UnsignedInteger, err = MATTER_ERROR_UNEXPECTED_TLV_ELEMENT);
err = tlvDissector.AddTypedItem(tree, hf_PBKDFParamRequest_localSessionId, tvb);
SuccessOrExit(err);
break;
case CASE::Sigma1::kTag_DestinationId:
VerifyOrExit(type == kTLVType_ByteString, err = MATTER_ERROR_UNEXPECTED_TLV_ELEMENT);
err = tlvDissector.AddTypedItem(tree, hf_Session_destinationId, tvb);
SuccessOrExit(err);
break;
case CASE::Sigma1::kTag_InitiatorEphPubKey:
VerifyOrExit(type == kTLVType_ByteString, err = MATTER_ERROR_UNEXPECTED_TLV_ELEMENT);
err = tlvDissector.AddTypedItem(tree, hf_Session_ephPublicKey, tvb);
SuccessOrExit(err);
break;
case CASE::Sigma1::kTag_InitiatorSleepyParams:
case CASE::Sigma1::kTag_ResumptionId:
case CASE::Sigma1::kTag_InitiatorResumeMic:
// TODO: add support for optional fields
err = tlvDissector.AddGenericTLVItem(tree, hf_StatusReport_TLV, tvb, false);
SuccessOrExit(err);
break;
default:
ExitNow(err = MATTER_ERROR_UNEXPECTED_TLV_ELEMENT);
}
}
err = tlvDissector.ExitContainer();
SuccessOrExit(err);
exit:
return err;
}
/**
* Dissect CASE Sigma2 message.
sigma-2-struct => STRUCTURE [ tag-order ]
{
responderRandom [1] : OCTET STRING [ length 32 ],
responderSessionId [2] : UNSIGNED INTEGER [ range 16-bits ],
responderEphPubKey [3] : ec-pub-key,
encrypted2 [4] : OCTET STRING,
responderMRPParams [5, optional] : mrp-parameter-struct
}
*/
static int
DissectCaseSigma2(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree _U_, const MatterMessageInfo& msgInfo)
{
MATTER_ERROR err = MATTER_NO_ERROR;
int parsePoint = 0;
const uint8_t *msgData = (const uint8_t *)tvb_memdup(pinfo->pool, tvb, parsePoint, msgInfo.payloadLen - parsePoint);
TLVDissector tlvDissector;
proto_item_append_text(proto_tree_get_parent(tree), ": CASE Sigma2");
tlvDissector.Init(msgData, msgInfo.payloadLen - parsePoint, parsePoint);
tlvDissector.ImplicitProfileId = kMatterProfile_Common;
err = tlvDissector.Next();
SuccessOrExit(err);
err = tlvDissector.EnterContainer();
SuccessOrExit(err);
while (true) {
err = tlvDissector.Next();
if (err == MATTER_END_OF_TLV)
break;
SuccessOrExit(err);
uint64_t tag = tlvDissector.GetTag();
TLVType type = tlvDissector.GetType();
VerifyOrExit(IsContextTag(tag), err = MATTER_ERROR_UNEXPECTED_TLV_ELEMENT);
switch (TagNumFromTag(tag)) {
case CASE::Sigma2::kTag_ResponderRandom:
VerifyOrExit(type == kTLVType_ByteString, err = MATTER_ERROR_UNEXPECTED_TLV_ELEMENT);
err = tlvDissector.AddTypedItem(tree, hf_PBKDFParamResponse_responderRandom, tvb);
SuccessOrExit(err);
break;
case CASE::Sigma2::kTag_ResponderSessionId:
VerifyOrExit(type == kTLVType_UnsignedInteger, err = MATTER_ERROR_UNEXPECTED_TLV_ELEMENT);
err = tlvDissector.AddTypedItem(tree, hf_PBKDFParamRequest_localSessionId, tvb);
SuccessOrExit(err);
break;
case CASE::Sigma2::kTag_ResponderEphPubKey:
VerifyOrExit(type == kTLVType_ByteString, err = MATTER_ERROR_UNEXPECTED_TLV_ELEMENT);
err = tlvDissector.AddTypedItem(tree, hf_Session_ephPublicKey, tvb);
SuccessOrExit(err);
break;
case CASE::Sigma2::kTag_Encrypted2:
VerifyOrExit(type == kTLVType_ByteString, err = MATTER_ERROR_UNEXPECTED_TLV_ELEMENT);
err = tlvDissector.AddTypedItem(tree, hf_Session_encrypted, tvb);
SuccessOrExit(err);
break;
case CASE::Sigma2::kTag_ResponderSleepyParams:
// TODO: add support for optional fields
err = tlvDissector.AddGenericTLVItem(tree, hf_StatusReport_TLV, tvb, false);
SuccessOrExit(err);
break;
default:
ExitNow(err = MATTER_ERROR_UNEXPECTED_TLV_ELEMENT);
}
}
err = tlvDissector.ExitContainer();
SuccessOrExit(err);
exit:
return err;
}
/**
* Dissect CASE Sigma1 message.
sigma-3-struct => STRUCTURE [ tag-order ]
{
encrypted3 [1] : OCTET STRING,
}
*/
static int
DissectCaseSigma3(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree _U_, const MatterMessageInfo& msgInfo)
{
MATTER_ERROR err = MATTER_NO_ERROR;
int parsePoint = 0;
const uint8_t *msgData = (const uint8_t *)tvb_memdup(pinfo->pool, tvb, parsePoint, msgInfo.payloadLen - parsePoint);
TLVDissector tlvDissector;
proto_item_append_text(proto_tree_get_parent(tree), ": CASE Sigma3");
tlvDissector.Init(msgData, msgInfo.payloadLen - parsePoint, parsePoint);
tlvDissector.ImplicitProfileId = kMatterProfile_Common;
err = tlvDissector.Next();
SuccessOrExit(err);
err = tlvDissector.EnterContainer();
SuccessOrExit(err);
while (true) {
err = tlvDissector.Next();
if (err == MATTER_END_OF_TLV)
break;
SuccessOrExit(err);
uint64_t tag = tlvDissector.GetTag();
TLVType type = tlvDissector.GetType();
VerifyOrExit(IsContextTag(tag), err = MATTER_ERROR_UNEXPECTED_TLV_ELEMENT);
switch (TagNumFromTag(tag)) {
case CASE::Sigma3::kTag_Encrypted3:
VerifyOrExit(type == kTLVType_ByteString, err = MATTER_ERROR_UNEXPECTED_TLV_ELEMENT);
err = tlvDissector.AddTypedItem(tree, hf_Session_encrypted, tvb);
SuccessOrExit(err);
break;
default:
ExitNow(err = MATTER_ERROR_UNEXPECTED_TLV_ELEMENT);
}
}
err = tlvDissector.ExitContainer();
SuccessOrExit(err);
exit:
return err;
}
/**
* Dissect CASE Sigma2 resume message.
sigma-2-resume-struct => STRUCTURE [ tag-order ]
{
resumptionID [1] : OCTET STRING [ length 16 ],
sigma2ResumeMIC [2] : OCTET STRING [ length 16 ],
responderSessionID [3] : UNSIGNED INTEGER [ range 16-bits ],
responderMRPParams [4, optional] : <<Glossary_of_params_MRP, mrp-parameter-struct>>
}
*/
static int
DissectCaseSigma2Resume(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree _U_, const MatterMessageInfo& msgInfo)
{
MATTER_ERROR err = MATTER_NO_ERROR;
int parsePoint = 0;
const uint8_t *msgData = (const uint8_t *)tvb_memdup(pinfo->pool, tvb, parsePoint, msgInfo.payloadLen - parsePoint);
TLVDissector tlvDissector;
proto_item_append_text(proto_tree_get_parent(tree), ": CASE Sigma2 Resume");
tlvDissector.Init(msgData, msgInfo.payloadLen - parsePoint, parsePoint);
tlvDissector.ImplicitProfileId = kMatterProfile_Common;
err = tlvDissector.Next();
SuccessOrExit(err);
err = tlvDissector.EnterContainer();
SuccessOrExit(err);
while (true) {
err = tlvDissector.Next();
if (err == MATTER_END_OF_TLV)
break;
SuccessOrExit(err);
uint64_t tag = tlvDissector.GetTag();
VerifyOrExit(IsContextTag(tag), err = MATTER_ERROR_UNEXPECTED_TLV_ELEMENT);
err = tlvDissector.AddGenericTLVItem(tree, hf_StatusReport_TLV, tvb, false);
SuccessOrExit(err);
/*
TLVType type = tlvDissector.GetType();
switch (TagNumFromTag(tag)) {
// TODO: add support for parsing specific CASEResume fields
case 1:
case 2:
case 3:
case 4:
break;
default:
ExitNow(err = MATTER_ERROR_UNEXPECTED_TLV_ELEMENT);
}
*/
}
err = tlvDissector.ExitContainer();
SuccessOrExit(err);
exit:
return err;
}
static int
DissectMatterCommon(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree _U_, void *data _U_)
{
const MatterMessageInfo& msgInfo = *(const MatterMessageInfo *)data;
proto_item *top = proto_tree_add_item(tree, proto_MatterCommon, tvb, 0, -1, ENC_NA);
proto_tree *common_tree = proto_item_add_subtree(top, ett_MatterCommon);
switch (msgInfo.msgType) {
case kMsgType_StatusReport:
return DissectStatusReport(tvb, pinfo, common_tree, msgInfo);
case kMsgType_StandaloneAck:
return DissectStandaloneAck(tvb, pinfo, common_tree, msgInfo);
// Dissect PASE Messages
case kMsgType_PBKDFParamRequest:
return DissectPBKDFParamRequest(tvb, pinfo, common_tree, msgInfo);
case kMsgType_PBKDFParamResponse:
return DissectPBKDFParamResponse(tvb, pinfo, common_tree, msgInfo);
case kMsgType_PASE_Spake2p1:
return DissectPasePake1(tvb, pinfo, common_tree, msgInfo);
case kMsgType_PASE_Spake2p2:
return DissectPasePake2(tvb, pinfo, common_tree, msgInfo);
case kMsgType_PASE_Spake2p3:
return DissectPasePake3(tvb, pinfo, common_tree, msgInfo);
case kMsgType_PASE_Spake2pError:
return DissectPasePakeError(tvb, pinfo, common_tree, msgInfo);
// Dissect CASE Messages
case kMsgType_CASE_Sigma1:
return DissectCaseSigma1(tvb, pinfo, common_tree, msgInfo);
case kMsgType_CASE_Sigma2:
return DissectCaseSigma2(tvb, pinfo, common_tree, msgInfo);
case kMsgType_CASE_Sigma3:
return DissectCaseSigma3(tvb, pinfo, common_tree, msgInfo);
case kMsgType_CASE_Sigma2_Resume:
return DissectCaseSigma2Resume(tvb, pinfo, common_tree, msgInfo);
default:
return 0;
}
}
void
proto_register_matter_common(void)
{
static hf_register_info hf[] = {
{ &hf_StatusReport_ProfileId,
{ "Status Profile Id", "matter.status_report.profile_id",
FT_UINT32, BASE_HEX, NULL, 0x0, NULL, HFILL }
},
{ &hf_StatusReport_StatusCode,
{ "Status Code", "matter.status_report.status_code",
FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }
},
{ &hf_StatusReport_TLV,
{ "TLV", "matter.status_report.tlv",
FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }
},
{ &hf_StatusReport_IsError,
{ "Is Error", "matter.status_report.is_error",
FT_BOOLEAN, BASE_NONE, NULL, 0x0, NULL, HFILL }
},
/*
{ &hf_PBKDFParamRequest,
{ "PASE PBKDF Param Request", "matter.pase.pbkdf_param_req",
FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }
},
*/
{ &hf_PBKDFParamRequest_initiatorRandom,
{ "Initiator Random", "matter.pase.initiator_random",
FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }
},
{ &hf_PBKDFParamRequest_localSessionId,
{ "Local Session ID", "matter.pase.local_session_id",
FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }
},
{ &hf_PBKDFParamRequest_passcodeId,
{ "Passcode ID", "matter.pase.passcode_id",
FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }
},
{ &hf_PBKDFParamRequest_hasPbkdfParams,
{ "Has PBKDF Parameters", "matter.pase.has_pbkdf_params",
FT_BOOLEAN, BASE_NONE, NULL, 0x0, NULL, HFILL }
},
{ &hf_PBKDFParamResponse_responderRandom,
{ "Responder Random", "matter.pase.responder_random",
FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }
},
{ &hf_PBKDFParamResponse_pbkdfIterationCount,
{ "PBKDF Iterations", "matter.pase.pbkdf_interation_count",
FT_UINT64, BASE_DEC, NULL, 0x0, NULL, HFILL }
},
{ &hf_PBKDFParamResponse_pbkdfSaltLength,
{ "PBKDF Salt Length", "matter.pase.pbkdf_salt_length",
FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }
},
{ &hf_PBKDFParamResponse_pbkdfSalt,
{ "PBKDF Salt", "matter.pase.salt",
FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }
},
{ &hf_Pake1_pA,
{ "pA", "matter.pase.pake1.pA",
FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }
},
{ &hf_Pake2_pB,
{ "pB", "matter.pase.pake2.pB",
FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }
},
{ &hf_Pake2_cB,
{ "cB", "matter.pase.pake2.cB",
FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }
},
{ &hf_Pake3_cA,
{ "cA", "matter.pase.pake3.cA",
FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }
},
{ &hf_Session_destinationId,
{ "Destination Node ID", "matter.session.destination_id",
FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }
},
{ &hf_Session_ephPublicKey,
{ "Ephemeral public key", "matter.session.eph_public_key",
FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }
},
{ &hf_Session_encrypted,
{ "Encrypted", "matter.session.encrypted",
FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }
},
};
static gint *ett[] = {
&ett_MatterCommon,
};
proto_MatterCommon = proto_register_protocol(
"Matter Secure Channel Protocol",
"Matter-Common",
"matter-common"
);
proto_register_field_array(proto_MatterCommon, hf, array_length(hf));
proto_register_subtree_array(ett, array_length(ett));
}
void
proto_reg_handoff_matter_common(void)
{
static dissector_handle_t matter_common_handle;
matter_common_handle = create_dissector_handle(DissectMatterCommon, proto_MatterCommon);
dissector_add_uint("matter.profile_id", kMatterProfile_Common, matter_common_handle);
}