/
gquic-protocol.pac
2151 lines (1998 loc) · 61.3 KB
/
gquic-protocol.pac
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
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Copyright (c) 2017-2019, Corelight Inc. and GQUIC Protocol Analyzer contributors
# All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause
# For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
# Google QUIC docs: https://www.chromium.org/quic
# Wire format spec: https://github.com/quicwg/base-drafts/blob/master/draft-ietf-quic-transport.md
# Parses GQUIC Versions Q039-Q046
# All long packets start the same: with flags, version, and a CID
type GQUIC_Packet(is_orig: bool) = record {
flags: PublicFlags(is_orig);
content: case flags.packet_type of {
REGULAR -> reg_pkt: RegularPacket(flags, is_orig);
OLDER -> old_pkt: OldPacket(flags, is_orig);
default -> nil_pkt: empty;
};
# Unencrypted search determines whether the packet is a client hello
unencrypted_search: case flags.hello_length of {
true -> search: UnencryptedSearch(flags, is_orig);
false -> stop: empty;
default -> stopx: empty;
};
frames: bytestring &restofdata &transient;
} &byteorder = bigendian;
# List of Public Flags and byte breakdown
type PublicFlags(is_orig: bool) = record {
byte: uint8;
}
&let {
length = sourcedata.length();
hello_length: bool = HelloLength(length, is_orig);
# These flags are for version Q046
is_long: bool = (byte & 0x80) == 0x80;
fixed_bit: bool = (byte & 0x40) == 0x40;
type_initial: bool = (byte & 0x30) == 0x00;
type_0rtt: bool = (byte & 0x30) == 0x10;
type_handshake: bool = (byte & 0x30) == 0x20;
type_retry: bool = (byte & 0x30) == 0x30;
pkt_num_size: uint8 = (byte & 0x03);
# These flags are for versions before Q046
# Clients may set the nonce bit in the header even though there is no
# nonce in the message. See:
# https://groups.google.com/a/chromium.org/forum/#!topic/proto-quic/kQVDZal_iwo
have_version: bool = (byte & 0x01) == 0x01;
have_nonce: bool = (byte & 0x04) == 0x04 && ! is_orig;
have_conn_id: bool = (byte & 0x08) == 0x08;
pkt_num_size_old: uint8 = (byte & 0x30);
packet_type: int = (fixed_bit ? REGULAR :
OLDER);
cid_exists: bool = CIDCheck(is_orig, is_long);
} &exportsourcedata;
type OldPacket(flags: PublicFlags, is_orig: bool) = record {
cid: ConnectionIDOld(flags);
version: case flags.have_version of {
true -> version_val: uint8[4];
false -> version_nil: empty;
};
nonce: case flags.have_nonce of {
true -> nonce_val: uint8[32];
false -> nonce_nil: empty;
};
pkt_num_bytes: case flags.pkt_num_size_old of {
0x00 -> pkt_num_bytes1: uint8[1];
0x10 -> pkt_num_bytes2: uint8[2];
0x20 -> pkt_num_bytes4: uint8[4];
0x30 -> pkt_num_bytes6: uint8[6];
default -> pkt_num_bytesx: empty; # not possible, all 4 cases handled
};
} &byteorder = bigendian; # NOTE: versions before Q039 are little-endian
type ConnectionIDOld(flags: PublicFlags) = record {
present: case flags.have_conn_id of {
true -> bytes: uint8[8];
false -> nil: empty;
};
};
type RegularPacket(flags: PublicFlags, is_orig: bool) = record {
version: case flags.is_long of {
true -> version_val: bytestring &length=4;
false -> version_nil: empty;
};
dcil_scil: case flags.is_long of {
true -> conn_id: uint8;
false -> short: empty;
};
cid: ConnectionID(flags);
# Determine the number of packet bytes needed to display the packet number
pkt_num_bytes: case flags.pkt_num_size of {
0x00 -> pkt_num_bytes1: uint8[1];
0x01 -> pkt_num_bytes2: uint8[2];
0x02 -> pkt_num_bytes3: uint8[3];
0x03 -> pkt_num_bytes4: uint8[4];
default -> pkt_num_bytesx: empty; # not possible, all 4 cases handled
};
};
type ConnectionID(flags: PublicFlags) = record {
present: case flags.cid_exists of {
true -> bytes: uint8[8];
false -> nil: empty;
};
};
# This sets up the parts to look for the CHLO
type UnencryptedSearch(flags: PublicFlags, is_orig: bool) = record {
msg_auth_hash: uint8[12];
stream: StreamID(flags);
sid: SId(stream);
extra: NewerVersions(stream);
offset: StreamOffset(stream);
data_len: DataLength(stream);
expected_string: HelloCheck(flags, is_orig);
build_hello: TypeHello(flags, is_orig, expected_string);
};
type StreamID(flags: PublicFlags) = record {
byte: uint8;
}&let{
streams: bool = (byte & 0x80) == 0x80;
extra_bit: bool = (byte & 0x40) == 0x40;
data_length: bool = (byte & 0x20) == 0x20;
offset_length: int = (byte & 0x1c);
fin_bit: bool = (byte & 0x01) == 0x01;
};
type SId(stream: StreamID) = record {
is_stream: case stream.streams of {
true -> id: uint8;
false -> nil: empty;
};
};
type NewerVersions(stream: StreamID) = record {
extra_space: case stream.extra_bit of {
true -> plus_six: uint8[7];
false -> none: empty;
};
};
type DataLength(stream: StreamID) = record {
len: case stream.data_length of {
true -> yes: uint16;
false -> no: empty;
};
};
type StreamOffset(stream: StreamID) = record {
offset_type: case stream.offset_length of {
0x00 -> pkt_offset_bytes0: empty;
0x04 -> pkt_offset_bytes2: uint8[2];
0x08 -> pkt_offset_bytes3: uint8[3];
0x0c -> pkt_offset_bytes4: uint8[4];
0x10 -> pkt_offset_bytes5: uint8[5];
0x14 -> pkt_offset_bytes6: uint8[6];
0x18 -> pkt_offset_bytes7: uint8[7];
0x1c -> pkt_offset_bytes8: uint8[8];
default -> pkt_offset_bytesx: empty;
};
};
# Looks for CHLO or REJ in the next four bytes
type HelloCheck(flags: PublicFlags, is_orig: bool) = record {
hello_string: bytestring &length=4;
}&let{
hello_check: bool = ((hello_string[0] == 0x43) && (hello_string[1] == 0x48) && (hello_string[2] == 0x4c) && (hello_string[3] == 0x4f));
rej_check: bool = ((hello_string[0] == 0x52) && (hello_string[1] == 0x45) && (hello_string[2] == 0x4a) && (hello_string[3] == 0x00));
};
# Confirms the existence of the Client Hello
type TypeHello(flags: PublicFlags, is_orig: bool, expected_string: HelloCheck) = record {
client: case expected_string.hello_check of {
true -> yes: HelloPacket(flags, is_orig);
false -> no: empty;
};
server: case expected_string.rej_check of {
true -> rej: RejPacket(flags, is_orig);
false -> none: empty;
};
};
# The HelloPacket may or may not have all these possible tags
type HelloPacket(flags: PublicFlags, is_orig: bool) = record {
tag_number: uint16 &byteorder = littleendian;
zero_pading: uint16;
other_tags: TagFinder(tag_number); # This is the important type which finds which tags exist
pad: ExtractPAD(other_tags, tag_number, p_tag_offset);
sni: ExtractSNI(other_tags, tag_number, p_tag_offset);
stk: ExtractSTK(other_tags, tag_number, p_tag_offset);
sno: ExtractSNO(other_tags, tag_number, p_tag_offset);
ver: ExtractVER(other_tags, tag_number, p_tag_offset);
ccs: ExtractCCS(other_tags, tag_number, p_tag_offset);
nonc: ExtractNONC(other_tags, tag_number, p_tag_offset);
mspc: ExtractMSPC(other_tags, tag_number, p_tag_offset);
aead: ExtractAEAD(other_tags, tag_number, p_tag_offset);
uaid: ExtractUAID(other_tags, tag_number, p_tag_offset);
scid: ExtractSCID(other_tags, tag_number, p_tag_offset);
tcid: ExtractTCID(other_tags, tag_number, p_tag_offset);
pdmd: ExtractPDMD(other_tags, tag_number, p_tag_offset);
smhl: ExtractSMHL(other_tags, tag_number, p_tag_offset);
icsl: ExtractICSL(other_tags, tag_number, p_tag_offset);
ctim: ExtractCTIM(other_tags, tag_number, p_tag_offset);
nonp: ExtractNONP(other_tags, tag_number, p_tag_offset);
pubs: ExtractPUBS(other_tags, tag_number, p_tag_offset);
mids: ExtractMIDS(other_tags, tag_number, p_tag_offset);
scls: ExtractSCLS(other_tags, tag_number, p_tag_offset);
kexs: ExtractKEXS(other_tags, tag_number, p_tag_offset);
xlct: ExtractXLCT(other_tags, tag_number, p_tag_offset);
csct: ExtractCSCT(other_tags, tag_number, p_tag_offset);
copt: ExtractCOPT(other_tags, tag_number, p_tag_offset);
ccrt: ExtractCCRT(other_tags, tag_number, p_tag_offset);
irtt: ExtractIRTT(other_tags, tag_number, p_tag_offset);
cetv: ExtractCETV(other_tags, tag_number, p_tag_offset);
cfcw: ExtractCFCW(other_tags, tag_number, p_tag_offset);
sfcw: ExtractSFCW(other_tags, tag_number, p_tag_offset);
} &let{
p_tag_offset=0;
};
type RejPacket(flags: PublicFlags, is_orig: bool) = record {
tag_number: uint16 &byteorder = littleendian;
zero_pading: uint16;
other_tags: TagFinder(tag_number); # This is the important type which finds which tags exist
stk: ExtractSTK(other_tags, tag_number, p_tag_offset);
sno: ExtractSNO(other_tags, tag_number, p_tag_offset);
svid: ExtractSVID(other_tags, tag_number, p_tag_offset);
prof: ExtractPROF(other_tags, tag_number, p_tag_offset);
scfg: ExtractSCFG(other_tags, tag_number, p_tag_offset);
rrej: ExtractRREJ(other_tags, tag_number, p_tag_offset);
sttl: ExtractSTTL(other_tags, tag_number, p_tag_offset);
csct: ExtractCSCT(other_tags, tag_number, p_tag_offset);
} &let{
p_tag_offset=0;
};
type RejPacketSCFG() = record {
tag: bytestring &length=4;
tag_number: uint32 &byteorder = littleendian;
other_tags: TagFinder(tag_number); # This is the important type which finds which tags exist
ver: ExtractVER(other_tags, tag_number, p_tag_offset);
aead: ExtractAEAD(other_tags, tag_number, p_tag_offset);
scid: ExtractSCID(other_tags, tag_number, p_tag_offset);
pdmd: ExtractPDMD(other_tags, tag_number, p_tag_offset);
tbkp: ExtractTBKP(other_tags, tag_number, p_tag_offset);
pubs: ExtractPUBS(other_tags, tag_number, p_tag_offset);
kexs: ExtractKEXS(other_tags, tag_number, p_tag_offset);
obit: ExtractOBIT(other_tags, tag_number, p_tag_offset);
expy: ExtractEXPY(other_tags, tag_number, p_tag_offset);
} &let{
p_tag_offset=0;
};
# Each of these types are either bytestrings of a certain length or
# is an empty type, meaning it does not exist
type ExtractPAD(other_tags: TagFinder, tag_number: uint16, p_tag_offset: uint32) = record {
exists: case other_tags.pad_check of {
true -> collect: bytestring &length=(find_pad_length(other_tags.seek_tags, tag_number, p_tag_offset));
false -> blank: empty;
};
};
type ExtractSNI(other_tags: TagFinder, tag_number: uint16, p_tag_offset: uint32) = record {
exists: case other_tags.sni_check of {
true -> collect: bytestring &length=(find_sni_length(other_tags.seek_tags, tag_number, p_tag_offset));
false -> blank: empty;
};
};
type ExtractSTK(other_tags: TagFinder, tag_number: uint16, p_tag_offset: uint32) = record {
exists: case other_tags.stk_check of {
true -> collect: bytestring &length=(find_stk_length(other_tags.seek_tags, tag_number, p_tag_offset));
false -> blank: empty;
};
};
type ExtractSNO(other_tags: TagFinder, tag_number: uint16, p_tag_offset: uint32) = record {
exists: case other_tags.sno_check of {
true -> collect: bytestring &length=(find_sno_length(other_tags.seek_tags, tag_number, p_tag_offset));
false -> blank: empty;
};
};
type ExtractVER(other_tags: TagFinder, tag_number: uint16, p_tag_offset: uint32) = record {
exists: case other_tags.ver_check of {
true -> collect: bytestring &length=(find_ver_length(other_tags.seek_tags, tag_number, p_tag_offset));
false -> blank: empty;
};
};
type ExtractCCS(other_tags: TagFinder, tag_number: uint16, p_tag_offset: uint32) = record {
exists: case other_tags.ccs_check of {
true -> collect: bytestring &length=(find_ccs_length(other_tags.seek_tags, tag_number, p_tag_offset));
false -> blank: empty;
};
};
type ExtractCRT(other_tags: TagFinder, tag_number: uint16, p_tag_offset: uint32) = record {
exists: case other_tags.crt_check of {
true -> collect: bytestring &length=(find_crt_length(other_tags.seek_tags, tag_number, p_tag_offset));
false -> blank: empty;
};
};
type ExtractNONC(other_tags: TagFinder, tag_number: uint16, p_tag_offset: uint32) = record {
exists: case other_tags.nonc_check of {
true -> collect: bytestring &length=(find_nonc_length(other_tags.seek_tags, tag_number, p_tag_offset));
false -> blank: empty;
};
};
type ExtractMSPC(other_tags: TagFinder, tag_number: uint16, p_tag_offset: uint32) = record {
exists: case other_tags.mspc_check of {
true -> collect: bytestring &length=(find_mspc_length(other_tags.seek_tags, tag_number, p_tag_offset));
false -> blank: empty;
};
};
type ExtractAEAD(other_tags: TagFinder, tag_number: uint16, p_tag_offset: uint32) = record {
exists: case other_tags.aead_check of {
true -> collect: bytestring &length=(find_aead_length(other_tags.seek_tags, tag_number, p_tag_offset));
false -> blank: empty;
};
};
type ExtractUAID(other_tags: TagFinder, tag_number: uint16, p_tag_offset: uint32) = record {
exists: case other_tags.uaid_check of {
true -> collect: bytestring &length=(find_uaid_length(other_tags.seek_tags, tag_number, p_tag_offset));
false -> blank: empty;
};
};
type ExtractSCID(other_tags: TagFinder, tag_number: uint16, p_tag_offset: uint32) = record {
exists: case other_tags.scid_check of {
true -> collect: bytestring &length=(find_scid_length(other_tags.seek_tags, tag_number, p_tag_offset));
false -> blank: empty;
};
};
type ExtractTCID(other_tags: TagFinder, tag_number: uint16, p_tag_offset: uint32) = record {
exists: case other_tags.tcid_check of {
true -> collect: bytestring &length=(find_tcid_length(other_tags.seek_tags, tag_number, p_tag_offset));
false -> blank: empty;
};
};
type ExtractPDMD(other_tags: TagFinder, tag_number: uint16, p_tag_offset: uint32) = record {
exists: case other_tags.pdmd_check of {
true -> collect: bytestring &length=(find_pdmd_length(other_tags.seek_tags, tag_number, p_tag_offset));
false -> blank: empty;
};
};
type ExtractSMHL(other_tags: TagFinder, tag_number: uint16, p_tag_offset: uint32) = record {
exists: case other_tags.smhl_check of {
true -> collect: bytestring &length=(find_smhl_length(other_tags.seek_tags, tag_number, p_tag_offset));
false -> blank: empty;
};
};
type ExtractICSL(other_tags: TagFinder, tag_number: uint16, p_tag_offset: uint32) = record {
exists: case other_tags.icsl_check of {
true -> collect: bytestring &length=(find_icsl_length(other_tags.seek_tags, tag_number, p_tag_offset));
false -> blank: empty;
};
};
type ExtractNONP(other_tags: TagFinder, tag_number: uint16, p_tag_offset: uint32) = record {
exists: case other_tags.nonp_check of {
true -> collect: bytestring &length=(find_nonp_length(other_tags.seek_tags, tag_number, p_tag_offset));
false -> blank: empty;
};
};
type ExtractPUBS(other_tags: TagFinder, tag_number: uint16, p_tag_offset: uint32) = record {
exists: case other_tags.pubs_check of {
true -> collect: bytestring &length=(find_pubs_length(other_tags.seek_tags, tag_number, p_tag_offset));
false -> blank: empty;
};
};
type ExtractMIDS(other_tags: TagFinder, tag_number: uint16, p_tag_offset: uint32) = record {
exists: case other_tags.mids_check of {
true -> collect: bytestring &length=(find_mids_length(other_tags.seek_tags, tag_number, p_tag_offset));
false -> blank: empty;
};
};
type ExtractSCLS(other_tags: TagFinder, tag_number: uint16, p_tag_offset: uint32) = record {
exists: case other_tags.scls_check of {
true -> collect: bytestring &length=(find_scls_length(other_tags.seek_tags, tag_number, p_tag_offset));
false -> blank: empty;
};
};
type ExtractKEXS(other_tags: TagFinder, tag_number: uint16, p_tag_offset: uint32) = record {
exists: case other_tags.kexs_check of {
true -> collect: bytestring &length=(find_kexs_length(other_tags.seek_tags, tag_number, p_tag_offset));
false -> blank: empty;
};
};
type ExtractXLCT(other_tags: TagFinder, tag_number: uint16, p_tag_offset: uint32) = record {
exists: case other_tags.xlct_check of {
true -> collect: bytestring &length=(find_xlct_length(other_tags.seek_tags, tag_number, p_tag_offset));
false -> blank: empty;
};
};
type ExtractCSCT(other_tags: TagFinder, tag_number: uint16, p_tag_offset: uint32) = record {
exists: case other_tags.csct_check of {
true -> collect: bytestring &length=(find_csct_length(other_tags.seek_tags, tag_number, p_tag_offset));
false -> blank: empty;
};
};
type ExtractCOPT(other_tags: TagFinder, tag_number: uint16, p_tag_offset: uint32) = record {
exists: case other_tags.copt_check of {
true -> collect: bytestring &length=(find_copt_length(other_tags.seek_tags, tag_number, p_tag_offset));
false -> blank: empty;
};
};
type ExtractCCRT(other_tags: TagFinder, tag_number: uint16, p_tag_offset: uint32) = record {
exists: case other_tags.ccrt_check of {
true -> collect: bytestring &length=(find_ccrt_length(other_tags.seek_tags, tag_number, p_tag_offset));
false -> blank: empty;
};
};
type ExtractIRTT(other_tags: TagFinder, tag_number: uint16, p_tag_offset: uint32) = record {
exists: case other_tags.irtt_check of {
true -> collect: bytestring &length=(find_irtt_length(other_tags.seek_tags, tag_number, p_tag_offset));
false -> blank: empty;
};
};
type ExtractCFCW(other_tags: TagFinder, tag_number: uint16, p_tag_offset: uint32) = record {
exists: case other_tags.cfcw_check of {
true -> collect: bytestring &length=(find_cfcw_length(other_tags.seek_tags, tag_number, p_tag_offset));
false -> blank: empty;
};
};
type ExtractSFCW(other_tags: TagFinder, tag_number: uint16, p_tag_offset: uint32) = record {
exists: case other_tags.sfcw_check of {
true -> collect: bytestring &length=(find_sfcw_length(other_tags.seek_tags, tag_number, p_tag_offset));
false -> blank: empty;
};
};
type ExtractPROF(other_tags: TagFinder, tag_number: uint16, p_tag_offset: uint32) = record {
exists: case other_tags.prof_check of {
true -> collect: bytestring &length=(find_prof_length(other_tags.seek_tags, tag_number, p_tag_offset));
false -> blank: empty;
};
};
type ExtractSCFG(other_tags: TagFinder, tag_number: uint16, p_tag_offset: uint32) = record {
exists: case other_tags.scfg_check of {
true -> collect: RejPacketSCFG;
#bytestring &length=(find_scfg_length(other_tags.seek_tags, tag_number, p_tag_offset));
#RejPacketSCFG;
false -> blank: empty;
};
};
type ExtractRREJ(other_tags: TagFinder, tag_number: uint16, p_tag_offset: uint32) = record {
exists: case other_tags.rrej_check of {
true -> collect: bytestring &length=(find_rrej_length(other_tags.seek_tags, tag_number, p_tag_offset));
false -> blank: empty;
};
};
type ExtractOBIT(other_tags: TagFinder, tag_number: uint16, p_tag_offset: uint32) = record {
exists: case other_tags.obit_check of {
true -> collect: bytestring &length=(find_obit_length(other_tags.seek_tags, tag_number, p_tag_offset));
false -> blank: empty;
};
};
type ExtractEXPY(other_tags: TagFinder, tag_number: uint16, p_tag_offset: uint32) = record {
exists: case other_tags.expy_check of {
true -> collect: bytestring &length=(find_expy_length(other_tags.seek_tags, tag_number, p_tag_offset));
false -> blank: empty;
};
};
type ExtractSRBF(other_tags: TagFinder, tag_number: uint16, p_tag_offset: uint32) = record {
exists: case other_tags.srbf_check of {
true -> collect: bytestring &length=(find_srbf_length(other_tags.seek_tags, tag_number, p_tag_offset));
false -> blank: empty;
};
};
type ExtractCETV(other_tags: TagFinder, tag_number: uint16, p_tag_offset: uint32) = record {
exists: case other_tags.cetv_check of {
true -> collect: bytestring &length=(find_cetv_length(other_tags.seek_tags, tag_number, p_tag_offset));
false -> blank: empty;
};
};
type ExtractCTIM(other_tags: TagFinder, tag_number: uint16, p_tag_offset: uint32) = record {
exists: case other_tags.ctim_check of {
true -> collect: bytestring &length=(find_ctim_length(other_tags.seek_tags, tag_number, p_tag_offset));
false -> blank: empty;
};
};
type ExtractFHOL(other_tags: TagFinder, tag_number: uint16, p_tag_offset: uint32) = record {
exists: case other_tags.fhol_check of {
true -> collect: bytestring &length=(find_fhol_length(other_tags.seek_tags, tag_number, p_tag_offset));
false -> blank: empty;
};
};
type ExtractSTTL(other_tags: TagFinder, tag_number: uint16, p_tag_offset: uint32) = record {
exists: case other_tags.sttl_check of {
true -> collect: bytestring &length=(find_sttl_length(other_tags.seek_tags, tag_number, p_tag_offset));
false -> blank: empty;
};
};
type ExtractTBKP(other_tags: TagFinder, tag_number: uint16, p_tag_offset: uint32) = record {
exists: case other_tags.tbkp_check of {
true -> collect: bytestring &length=(find_tbkp_length(other_tags.seek_tags, tag_number, p_tag_offset));
false -> blank: empty;
};
};
type ExtractSVID(other_tags: TagFinder, tag_number: uint16, p_tag_offset: uint32) = record {
exists: case other_tags.svid_check of {
true -> collect: bytestring &length=(find_svid_length(other_tags.seek_tags, tag_number, p_tag_offset));
false -> blank: empty;
};
};
# This important type uses many booleans to deterine the existence of tags
type TagFinder(tag_number: uint16) = record {
seek_tags: bytestring &length=((8*tag_number));
} &let {
pad_check: bool = PAD_check(seek_tags, tag_number);
sni_check: bool = SNI_check(seek_tags, tag_number);
stk_check: bool = STK_check(seek_tags, tag_number);
sno_check: bool = SNO_check(seek_tags, tag_number);
ver_check: bool = VER_check(seek_tags, tag_number);
ccs_check: bool = CCS_check(seek_tags, tag_number);
crt_check: bool = CRT_check(seek_tags, tag_number);
nonc_check: bool = NONC_check(seek_tags, tag_number);
mspc_check: bool = MSPC_check(seek_tags, tag_number);
aead_check: bool = AEAD_check(seek_tags, tag_number);
uaid_check: bool = UAID_check(seek_tags, tag_number);
scid_check: bool = SCID_check(seek_tags, tag_number);
tcid_check: bool = TCID_check(seek_tags, tag_number);
pdmd_check: bool = PDMD_check(seek_tags, tag_number);
smhl_check: bool = SMHL_check(seek_tags, tag_number);
icsl_check: bool = ICSL_check(seek_tags, tag_number);
nonp_check: bool = NONP_check(seek_tags, tag_number);
pubs_check: bool = PUBS_check(seek_tags, tag_number);
mids_check: bool = MIDS_check(seek_tags, tag_number);
scls_check: bool = SCLS_check(seek_tags, tag_number);
kexs_check: bool = KEXS_check(seek_tags, tag_number);
xlct_check: bool = XLCT_check(seek_tags, tag_number);
csct_check: bool = CSCT_check(seek_tags, tag_number);
copt_check: bool = COPT_check(seek_tags, tag_number);
ccrt_check: bool = CCRT_check(seek_tags, tag_number);
irtt_check: bool = IRTT_check(seek_tags, tag_number);
cfcw_check: bool = CFCW_check(seek_tags, tag_number);
sfcw_check: bool = SFCW_check(seek_tags, tag_number);
prof_check: bool = PROF_check(seek_tags, tag_number);
scfg_check: bool = SCFG_check(seek_tags, tag_number);
rrej_check: bool = RREJ_check(seek_tags, tag_number);
obit_check: bool = OBIT_check(seek_tags, tag_number);
expy_check: bool = EXPY_check(seek_tags, tag_number);
srbf_check: bool = SRBF_check(seek_tags, tag_number);
cetv_check: bool = CETV_check(seek_tags, tag_number);
ctim_check: bool = CTIM_check(seek_tags, tag_number);
fhol_check: bool = FHOL_check(seek_tags, tag_number);
sttl_check: bool = STTL_check(seek_tags, tag_number);
tbkp_check: bool = TBKP_check(seek_tags, tag_number);
svid_check: bool = SVID_check(seek_tags, tag_number);
};
# This function determines the length of a packet
function HelloLength(length: uint16, is_orig: bool): bool
%{
if ((length >= 60))
{
return true;
}
else
{
return false;
}
%}
function CIDCheck(is_orig: bool, is_long: bool): bool
%{
if (is_orig == true)
return true;
else
{
if (is_long == true)
{
return true;
}
else
return false;
}
%}
# The following pairs of functions determine if a particular tag exists by iterating through the bytestring
# and checking for the bytes of the tag of the check function. The second function determines the length
# of the tag, assuming the tag exists.
function PAD_check(other_tags: bytestring, tag_number: uint16) : bool
%{
for ( int i = 0; i < tag_number; i++ )
{
if (other_tags[i*8] == 0x50 && other_tags[(i*8)+1] == 0x41 && other_tags[(i*8)+2] == 0x44)
{
return true;
}
}
return false;
%}
function find_pad_length(other_tags: bytestring, tag_number: uint16, p_tag_offset: uint32) : uint16
%{
for ( int i = 0; i < tag_number; i++ )
{
if ((other_tags[i*8] == 0x50) && (other_tags[(i*8)+1] == 0x41) && (other_tags[(i*8)+2] == 0x44))
{
if (i < 1)
{
return (other_tags[(i*8)+4]-(p_tag_offset-(256*other_tags[5])));
}
else
{
if (other_tags[(i*8)+5] == other_tags[(i*8)-3])
{
return (other_tags[(i*8)+4]-other_tags[(i*8)-4]);
}
if (other_tags[(i*8)+5] > other_tags[(i*8)-3])
{
return (256-other_tags[(i*8)-4]+other_tags[(i*8)+4]);
}
}
}
}
return 0x00;
%}
function SNI_check(other_tags: bytestring, tag_number: uint16) : bool
%{
for ( int i = 0; i < tag_number; i++ )
{
if (other_tags[i*8] == 0x53 && other_tags[(i*8)+1] == 0x4e && other_tags[(i*8)+2] == 0x49)
{
return true;
}
}
return false;
%}
function find_sni_length(other_tags: bytestring, tag_number: uint16, p_tag_offset: uint32) : uint16
%{
for ( int i = 0; i < tag_number; i++ )
{
if ((other_tags[i*8] == 0x53) && (other_tags[(i*8)+1] == 0x4e) && (other_tags[(i*8)+2] == 0x49))
{
if (i < 1)
{
return (other_tags[(i*8)+4]-(p_tag_offset-(256*other_tags[5])));
}
else
{
if (other_tags[(i*8)+5] == other_tags[(i*8)-3])
{
return (other_tags[(i*8)+4]-other_tags[(i*8)-4]);
}
if (other_tags[(i*8)+5] > other_tags[(i*8)-3])
{
return (256-other_tags[(i*8)-4]+other_tags[(i*8)+4]);
}
}
}
}
return 0x00;
%}
function STK_check(other_tags: bytestring, tag_number: uint16) : bool
%{
for ( int i = 0; i < tag_number; i++ )
{
if (other_tags[i*8] == 0x53 && other_tags[(i*8)+1] == 0x54 && other_tags[(i*8)+2] == 0x4b)
{
return true;
}
}
return false;
%}
function find_stk_length(other_tags: bytestring, tag_number: uint16, p_tag_offset: uint32) : uint16
%{
for ( int i = 0; i < tag_number; i++ )
{
if ((other_tags[i*8] == 0x53) && (other_tags[(i*8)+1] == 0x54) && (other_tags[(i*8)+2] == 0x4b))
{
if (i < 1) //(other_tags[(i*8)+5] == other_tags[(i*8)-3])
{
return (other_tags[(i*8)+4]-(p_tag_offset-(256*other_tags[5])));
}
else
{
if (other_tags[(i*8)+5] == other_tags[(i*8)-3])
{
return (other_tags[(i*8)+4]-other_tags[(i*8)-4]);
}
if (other_tags[(i*8)+5] > other_tags[(i*8)-3])
{
return (256-other_tags[(i*8)-4]+other_tags[(i*8)+4]);
}
}
}
}
return 0x00;
%}
function SNO_check(other_tags: bytestring, tag_number: uint16) : bool
%{
for ( int i = 0; i < tag_number; i++ )
{
if (other_tags[i*8] == 0x53 && other_tags[(i*8)+1] == 0x4e && other_tags[(i*8)+2] == 0x4f)
{
return true;
}
}
return false;
%}
function find_sno_length(other_tags: bytestring, tag_number: uint16, p_tag_offset: uint32) : uint16
%{
for ( int i = 0; i < tag_number; i++ )
{
if ((other_tags[i*8] == 0x53) && (other_tags[(i*8)+1] == 0x4e) && (other_tags[(i*8)+2] == 0x4f))
{
if (i < 1)
{
return (other_tags[(i*8)+4]-(p_tag_offset-(256*other_tags[5])));
}
else
{
if (other_tags[(i*8)+5] == other_tags[(i*8)-3])
{
return (other_tags[(i*8)+4]-other_tags[(i*8)-4]);
}
if (other_tags[(i*8)+5] > other_tags[(i*8)-3])
{
return (256-other_tags[(i*8)-4]+other_tags[(i*8)+4]);
}
}
}
}
return 0x00;
%}
function VER_check(other_tags: bytestring, tag_number: uint16) : bool
%{
for ( int i = 0; i < tag_number; i++ )
{
if (other_tags[i*8] == 0x56 && other_tags[(i*8)+1] == 0x45 && other_tags[(i*8)+2] == 0x52)
{
return true;
}
}
return false;
%}
function find_ver_length(other_tags: bytestring, tag_number: uint16, p_tag_offset: uint32) : uint16
%{
for ( int i = 0; i < tag_number; i++ )
{
if (other_tags[i*8] == 0x56 && other_tags[(i*8)+1] == 0x45 && other_tags[(i*8)+2] == 0x52)
{
if (i < 1)
{
return ((other_tags[4])-(p_tag_offset-(256*other_tags[5])));
}
else
{
if (other_tags[(i*8)+5] == other_tags[(i*8)-3])
{
return (other_tags[(i*8)+4]-other_tags[(i*8)-4]);
}
if (other_tags[(i*8)+5] > other_tags[(i*8)-3])
{
return (256-other_tags[(i*8)-4]+other_tags[(i*8)+4]);
}
}
}
}
return 0x00;
%}
function CCS_check(other_tags: bytestring, tag_number: uint16) : bool
%{
for ( int i = 0; i < tag_number-2; i++ )
{
if (other_tags[i*8] == 0x43 && other_tags[(i*8)+1] == 0x43 && other_tags[(i*8)+2] == 0x53)
{
return true;
}
}
return false;
%}
function find_ccs_length(other_tags: bytestring, tag_number: uint16, p_tag_offset: uint32) : uint16
%{
for ( int i = 0; i < tag_number; i++ )
{
if (other_tags[i*8] == 0x43 && other_tags[(i*8)+1] == 0x43 && other_tags[(i*8)+2] == 0x53)
{
if (i < 1)
{
return ((other_tags[4])-(p_tag_offset-(256*other_tags[5])));
}
else
{
if (other_tags[(i*8)+5] == other_tags[(i*8)-3])
{
return (other_tags[(i*8)+4]-other_tags[(i*8)-4]);
}
if (other_tags[(i*8)+5] > other_tags[(i*8)-3])
{
return (256-other_tags[(i*8)-4]+other_tags[(i*8)+4]);
}
}
}
}
return 0x00;
%}
function CRT_check(other_tags: bytestring, tag_number: uint16) : bool
%{
for ( int i = 0; i < tag_number-2; i++ )
{
if (other_tags[i*8] == 0x43 && other_tags[(i*8)+1] == 0x52 && other_tags[(i*8)+2] == 0x54)
{
return true;
}
}
return false;
%}
function find_crt_length(other_tags: bytestring, tag_number: uint16, p_tag_offset: uint32) : uint16
%{
for ( int i = 0; i < tag_number; i++ )
{
if (other_tags[i*8] == 0x43 && other_tags[(i*8)+1] == 0x52 && other_tags[(i*8)+2] == 0x54)
{
if (i < 1)
{
return ((other_tags[4])-(p_tag_offset-(256*other_tags[5])));
}
else
{
if (other_tags[(i*8)+5] == other_tags[(i*8)-3])
{
return (other_tags[(i*8)+4]-other_tags[(i*8)-4]);
}
if (other_tags[(i*8)+5] > other_tags[(i*8)-3])
{
return (256-other_tags[(i*8)-4]+other_tags[(i*8)+4]);
}
}
}
}
return 0x00;
%}
function NONC_check(other_tags: bytestring, tag_number: uint16) : bool
%{
for ( int i = 0; i < tag_number; i++ )
{
if (other_tags[i*8] == 0x4e && other_tags[(i*8)+1] == 0x4f && other_tags[(i*8)+2] == 0x4e && other_tags[(i*8)+3] == 0x43)
{
return true;
}
}
return false;
%}
function find_nonc_length(other_tags: bytestring, tag_number: uint16, p_tag_offset: uint32) : uint16
%{
for ( int i = 0; i < tag_number; i++ )
{
if (other_tags[i*8] == 0x4e && other_tags[(i*8)+1] == 0x4f && other_tags[(i*8)+2] == 0x4e && other_tags[(i*8)+3] == 0x43)
{
if (i < 1)
{
return ((other_tags[4])-(p_tag_offset-(256*other_tags[5])));
}
else
{
if (other_tags[(i*8)+5] == other_tags[(i*8)-3])
{
return (other_tags[(i*8)+4]-other_tags[(i*8)-4]);
}
if (other_tags[(i*8)+5] > other_tags[(i*8)-3])
{
return (256-other_tags[(i*8)-4]+other_tags[(i*8)+4]);
}
}
}
}
return 0x00;
%}
function MSPC_check(other_tags: bytestring, tag_number: uint16) : bool
%{
for ( int i = 0; i < tag_number; i++ )
{
if (other_tags[i*8] == 0x4d && other_tags[(i*8)+1] == 0x53 && other_tags[(i*8)+2] == 0x50 && other_tags[(i*8)+3] == 0x43)
{
return true;
}
}
return false;
%}
function find_mspc_length(other_tags: bytestring, tag_number: uint16, p_tag_offset: uint32) : uint16
%{
for ( int i = 0; i < tag_number; i++ )
{
if (other_tags[i*8] == 0x4d && other_tags[(i*8)+1] == 0x53 && other_tags[(i*8)+2] == 0x50 && other_tags[(i*8)+3] == 0x43)
{
if (i < 1)
{
return ((other_tags[4])-(p_tag_offset-(256*other_tags[5])));
}
else
{
if (other_tags[(i*8)+5] == other_tags[(i*8)-3])
{
return (other_tags[(i*8)+4]-other_tags[(i*8)-4]);
}
if (other_tags[(i*8)+5] > other_tags[(i*8)-3])
{
return (256-other_tags[(i*8)-4]+other_tags[(i*8)+4]);
}
}
}
}
return 0x00;
%}
function AEAD_check(other_tags: bytestring, tag_number: uint16) : bool
%{
for ( int i = 0; i < tag_number; i++ )
{
if (other_tags[i*8] == 0x41 && other_tags[(i*8)+1] == 0x45 && other_tags[(i*8)+2] == 0x41 && other_tags[(i*8)+3] == 0x44)
{
return true;
}
}
return false;
%}
function find_aead_length(other_tags: bytestring, tag_number: uint16, p_tag_offset: uint32) : uint16
%{
for ( int i = 0; i < tag_number; i++ )
{
if (other_tags[i*8] == 0x41 && other_tags[(i*8)+1] == 0x45 && other_tags[(i*8)+2] == 0x41 && other_tags[(i*8)+3] == 0x44)
{
if (i < 1)
{
return ((other_tags[4])-(p_tag_offset-(256*other_tags[5])));
}
else
{
if (other_tags[(i*8)+5] == other_tags[(i*8)-3])
{
return (other_tags[(i*8)+4]-other_tags[(i*8)-4]);
}
if (other_tags[(i*8)+5] > other_tags[(i*8)-3])
{
return (256-other_tags[(i*8)-4]+other_tags[(i*8)+4]);
}
}