diff --git a/fuzz_test.go b/fuzz_test.go new file mode 100644 index 000000000..4061e6d43 --- /dev/null +++ b/fuzz_test.go @@ -0,0 +1,92 @@ +// SPDX-FileCopyrightText: 2023 The Pion community +// SPDX-License-Identifier: MIT +package dtls + +import "testing" + +func FuzzUnmarshalBinary(f *testing.F) { + TestResumeClient := []byte{ + 0xfe, 0x01, 0x1e, 0xff, 0x81, 0x03, 0x01, 0x01, 0x01, 0x73, 0x65, 0x72, 0x69, 0x61, 0x6c, 0x69, 0x7a, 0x65, 0x64, 0x53, + 0x74, 0x61, 0x74, 0x65, 0x01, 0xff, 0x82, 0x01, 0x01, 0x01, 0x01, 0x01, 0x4c, 0x6f, 0x63, 0x61, 0x6c, 0x45, 0x70, 0x6f, + 0x63, 0x68, 0x01, 0x01, 0x01, 0x01, 0x01, 0x52, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x45, 0x70, 0x6f, 0x63, 0x68, 0x01, 0x01, + 0x00, 0x01, 0x01, 0x4c, 0x6f, 0x63, 0x61, 0x6c, 0x52, 0x61, 0x6e, 0x64, 0x6f, 0x6d, 0x01, 0xff, 0x84, 0x01, 0x01, 0x01, + 0x52, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x52, 0x61, 0x6e, 0x64, 0x6f, 0x6d, 0x01, 0xff, 0x84, 0x01, 0x01, 0x01, 0x43, 0x69, + 0x70, 0x68, 0x65, 0x72, 0x53, 0x75, 0x69, 0x74, 0x65, 0x49, 0x44, 0x01, 0x01, 0x01, 0x01, 0x01, 0x4d, 0x61, 0x73, 0x74, + 0x65, 0x72, 0x53, 0x65, 0x63, 0x72, 0x65, 0x74, 0x01, 0x01, 0x01, 0x01, 0x01, 0x53, 0x65, 0x71, 0x75, 0x65, 0x6e, 0x63, + 0x65, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x01, 0x01, 0x01, 0x01, 0x15, 0x53, 0x52, 0x54, 0x50, 0x50, 0x72, 0x6f, 0x74, + 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x50, 0x72, 0x6f, 0x66, 0x69, 0x6c, 0x65, 0x01, 0x01, 0x01, 0x01, 0x10, 0x50, 0x65, + 0x65, 0x72, 0x43, 0x65, 0x72, 0x74, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x65, 0x73, 0x01, 0xff, 0x86, 0x01, 0x01, 0x01, + 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x48, 0x69, 0x6e, 0x74, 0x01, 0x01, 0x01, 0x01, 0x01, 0x53, 0x65, 0x73, + 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x44, 0x01, 0x01, 0x01, 0x01, 0x11, 0x4c, 0x6f, 0x63, 0x61, 0x6c, 0x43, 0x6f, 0x6e, 0x6e, + 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x44, 0x01, 0x01, 0x01, 0x01, 0x12, 0x52, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x43, + 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x44, 0x01, 0x01, 0x01, 0x01, 0x01, 0x49, 0x73, 0x43, 0x6c, + 0x69, 0x65, 0x6e, 0x74, 0x01, 0x01, 0x01, 0x01, 0x01, 0x19, 0xff, 0x83, 0x01, 0x01, 0x01, 0x01, 0x5b, 0x33, 0x32, 0x5d, + 0x75, 0x69, 0x6e, 0x74, 0x38, 0x01, 0xff, 0x84, 0x01, 0x01, 0x01, 0x01, 0x40, 0x01, 0x01, 0x17, 0xff, 0x85, 0x01, 0x01, + 0x01, 0x01, 0x5b, 0x5d, 0x5b, 0x5d, 0x75, 0x69, 0x6e, 0x74, 0x38, 0x01, 0xff, 0x86, 0x01, 0x01, 0x01, 0x01, 0x01, 0xfe, + 0x01, 0x5e, 0xff, 0x82, 0x01, 0x01, 0x01, 0x01, 0x01, 0x20, 0x65, 0x26, 0x4d, 0xff, 0xd0, 0x6c, 0x64, 0xff, 0xd4, 0x3f, + 0x4c, 0x3d, 0xff, 0xcb, 0xff, 0xc9, 0x30, 0x64, 0xff, 0xaa, 0x3a, 0x1a, 0x77, 0xff, 0x92, 0xff, 0xa0, 0x4e, 0x6d, 0xff, + 0xfd, 0xff, 0x97, 0xff, 0x9a, 0x23, 0xff, 0xfc, 0x15, 0xff, 0xa9, 0x65, 0xff, 0xf9, 0xff, 0xa3, 0x01, 0x20, 0x65, 0x26, + 0x4d, 0xff, 0xd0, 0xff, 0xf7, 0x77, 0x46, 0x75, 0xff, 0xd0, 0x59, 0x4c, 0x50, 0xff, 0xf2, 0xff, 0xd7, 0x16, 0x41, 0x45, + 0x5e, 0xff, 0xff, 0xff, 0xd1, 0x5e, 0x13, 0x34, 0xff, 0xdf, 0xff, 0xb8, 0xff, 0x92, 0xff, 0xe8, 0xff, 0x9e, 0xff, 0x80, + 0x2c, 0xff, 0x80, 0xff, 0xf8, 0x01, 0xfe, 0xc0, 0x2b, 0x01, 0x30, 0xc3, 0xd2, 0x7a, 0xec, 0x1a, 0xc0, 0xae, 0xf6, 0x6f, + 0xde, 0x7c, 0x69, 0x45, 0x53, 0x9c, 0xd0, 0xe9, 0x3c, 0x31, 0x95, 0x53, 0x48, 0x68, 0xc7, 0xf0, 0x4d, 0x01, 0x46, 0xf6, + 0x36, 0x44, 0x1d, 0x6a, 0x8c, 0x17, 0x2d, 0x8e, 0x64, 0x98, 0x8b, 0x62, 0xdd, 0xf6, 0xf8, 0x01, 0x97, 0x55, 0x29, 0x01, + 0x01, 0x01, 0x01, 0xfe, 0x01, 0xb7, 0x30, 0x82, 0x01, 0xb3, 0x30, 0x82, 0x01, 0x59, 0xa0, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x11, 0x01, 0x25, 0x79, 0xf8, 0xd3, 0x4b, 0x01, 0x01, 0xbb, 0x75, 0x95, 0x01, 0xcc, 0x78, 0xae, 0x87, 0xeb, 0x30, 0x01, + 0x01, 0x01, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x01, 0x01, 0x01, 0x30, 0x1b, 0x31, 0x19, 0x30, 0x17, 0x01, 0x01, 0x55, 0x01, + 0x01, 0x13, 0x10, 0x73, 0x65, 0x6c, 0x66, 0x2d, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x64, 0x20, 0x63, 0x65, 0x72, 0x74, 0x30, + 0x1e, 0x17, 0x01, 0x32, 0x33, 0x31, 0x30, 0x31, 0x31, 0x30, 0x37, 0x32, 0x35, 0x30, 0x34, 0x5a, 0x17, 0x01, 0x32, 0x33, + 0x31, 0x31, 0x31, 0x31, 0x30, 0x37, 0x32, 0x35, 0x30, 0x34, 0x5a, 0x30, 0x1b, 0x31, 0x19, 0x30, 0x17, 0x01, 0x01, 0x55, + 0x01, 0x01, 0x13, 0x10, 0x73, 0x65, 0x6c, 0x66, 0x2d, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x64, 0x20, 0x63, 0x65, 0x72, 0x74, + 0x30, 0x59, 0x30, 0x13, 0x01, 0x01, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x01, 0x01, 0x01, 0x01, 0x2a, 0x86, 0x48, 0xce, 0x3d, + 0x01, 0x01, 0x01, 0x01, 0x42, 0x01, 0x01, 0xe1, 0xc7, 0x5a, 0x7f, 0xe6, 0x2f, 0xc1, 0xbb, 0x2d, 0x5a, 0xf8, 0x23, 0x59, + 0x17, 0x12, 0x22, 0x9d, 0x91, 0xe1, 0x19, 0x6f, 0xa4, 0x89, 0x23, 0x01, 0x83, 0x80, 0x31, 0x41, 0x4d, 0xda, 0xf8, 0xc8, + 0xf2, 0xf4, 0x40, 0x52, 0xee, 0x74, 0x12, 0x1b, 0xdf, 0x4f, 0xd8, 0x14, 0x49, 0xf6, 0x81, 0x52, 0xce, 0xed, 0x23, 0xe7, + 0x49, 0x51, 0xed, 0x9b, 0xca, 0x4b, 0xd8, 0x65, 0xa5, 0x7f, 0x82, 0xa3, 0x7e, 0x30, 0x7c, 0x30, 0x01, 0x01, 0x01, 0x55, + 0x1d, 0x01, 0x01, 0x01, 0xff, 0x01, 0x01, 0x01, 0x01, 0x01, 0x84, 0x30, 0x1d, 0x01, 0x01, 0x55, 0x1d, 0x25, 0x01, 0x16, + 0x30, 0x14, 0x01, 0x01, 0x2b, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x2b, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x30, 0x01, 0x01, 0x01, 0x55, 0x1d, 0x13, 0x01, 0x01, 0xff, 0x01, 0x01, 0x30, 0x01, 0x01, 0x01, 0xff, 0x30, + 0x1d, 0x01, 0x01, 0x55, 0x1d, 0x01, 0x01, 0x16, 0x01, 0x14, 0x6e, 0x65, 0xf7, 0xe1, 0x38, 0x2b, 0x01, 0xb8, 0x3e, 0xc4, + 0xf9, 0xe3, 0x72, 0xab, 0x5f, 0xd9, 0x8c, 0x01, 0xb6, 0x23, 0x30, 0x1b, 0x01, 0x01, 0x55, 0x1d, 0x11, 0x01, 0x14, 0x30, + 0x12, 0x82, 0x10, 0x73, 0x65, 0x6c, 0x66, 0x2d, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x64, 0x20, 0x63, 0x65, 0x72, 0x74, 0x30, + 0x01, 0x01, 0x01, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x01, 0x01, 0x01, 0x01, 0x48, 0x01, 0x30, 0x45, 0x01, 0x21, 0x01, 0xd0, + 0xca, 0x12, 0x9c, 0x25, 0x7f, 0x3f, 0x11, 0x77, 0xdc, 0x26, 0x69, 0x9f, 0xe0, 0xb2, 0xb8, 0x35, 0x78, 0xf5, 0x88, 0x64, + 0x8e, 0xc5, 0xc5, 0xdb, 0xf1, 0xb8, 0x49, 0x15, 0xea, 0x67, 0xe6, 0x01, 0x20, 0x41, 0x40, 0xc3, 0xde, 0xca, 0x13, 0x9b, + 0xe8, 0x10, 0x3c, 0xb6, 0xba, 0xf6, 0x01, 0xee, 0x8c, 0xa6, 0xf1, 0xda, 0x01, 0xab, 0x01, 0xe8, 0x12, 0x92, 0x35, 0x43, + 0xca, 0xf8, 0xec, 0xde, 0x01, 0x01, 0x01, 0x01, + } + TestResumeServer := []byte{ + 0xfe, 0x01, 0x1e, 0xff, 0x81, 0x01, 0x01, 0x01, 0x01, 0x73, 0x65, 0x72, 0x69, 0x61, 0x6c, 0x69, 0x7a, 0x65, 0x64, 0x53, + 0x74, 0x61, 0x74, 0x65, 0x01, 0xff, 0x82, 0x01, 0x01, 0x01, 0x01, 0x01, 0x4c, 0x6f, 0x63, 0x61, 0x6c, 0x45, 0x70, 0x6f, + 0x63, 0x68, 0x01, 0x01, 0x01, 0x01, 0x01, 0x52, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x45, 0x70, 0x6f, 0x63, 0x68, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x4c, 0x6f, 0x63, 0x61, 0x6c, 0x52, 0x61, 0x6e, 0x64, 0x6f, 0x6d, 0x01, 0xff, 0x84, 0x01, 0x01, 0x01, + 0x52, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x52, 0x61, 0x6e, 0x64, 0x6f, 0x6d, 0x01, 0xff, 0x84, 0x01, 0x01, 0x01, 0x43, 0x69, + 0x70, 0x68, 0x65, 0x72, 0x53, 0x75, 0x69, 0x74, 0x65, 0x49, 0x44, 0x01, 0x01, 0x01, 0x01, 0x01, 0x4d, 0x61, 0x73, 0x74, + 0x65, 0x72, 0x53, 0x65, 0x63, 0x72, 0x65, 0x74, 0x01, 0x01, 0x01, 0x01, 0x01, 0x53, 0x65, 0x71, 0x75, 0x65, 0x6e, 0x63, + 0x65, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x01, 0x01, 0x01, 0x01, 0x15, 0x53, 0x52, 0x54, 0x50, 0x50, 0x72, 0x6f, 0x74, + 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x50, 0x72, 0x6f, 0x66, 0x69, 0x6c, 0x65, 0x01, 0x01, 0x01, 0x01, 0x10, 0x50, 0x65, + 0x65, 0x72, 0x43, 0x65, 0x72, 0x74, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x65, 0x73, 0x01, 0xff, 0x86, 0x01, 0x01, 0x01, + 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x48, 0x69, 0x6e, 0x74, 0x01, 0x01, 0x01, 0x01, 0x01, 0x53, 0x65, 0x73, + 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x44, 0x01, 0x01, 0x01, 0x01, 0x11, 0x4c, 0x6f, 0x63, 0x61, 0x6c, 0x43, 0x6f, 0x6e, 0x6e, + 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x44, 0x01, 0x01, 0x01, 0x01, 0x12, 0x52, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x43, + 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x44, 0x01, 0x01, 0x01, 0x01, 0x01, 0x49, 0x73, 0x43, 0x6c, + 0x69, 0x65, 0x6e, 0x74, 0x01, 0x01, 0x01, 0x01, 0x01, 0x19, 0xff, 0x83, 0x01, 0x01, 0x01, 0x01, 0x5b, 0x33, 0x32, 0x5d, + 0x75, 0x69, 0x6e, 0x74, 0x38, 0x01, 0xff, 0x84, 0x01, 0x01, 0x01, 0x01, 0x40, 0x01, 0x01, 0x17, 0xff, 0x85, 0x01, 0x01, + 0x01, 0x01, 0x5b, 0x5d, 0x5b, 0x5d, 0x75, 0x69, 0x6e, 0x74, 0x38, 0x01, 0xff, 0x86, 0x01, 0x01, 0x01, 0x01, 0x01, 0xff, + 0x9d, 0xff, 0x82, 0x01, 0x01, 0x01, 0x01, 0x01, 0x20, 0x65, 0x26, 0x4d, 0xff, 0xe1, 0xff, 0xc4, 0x4b, 0xff, 0xc7, 0x1a, + 0x27, 0xff, 0xae, 0x11, 0xff, 0xeb, 0x2f, 0xff, 0x91, 0x6b, 0x5a, 0x1a, 0x4f, 0x36, 0x67, 0xff, 0xf2, 0x4d, 0x50, 0xff, + 0xfa, 0x49, 0xff, 0xbe, 0xff, 0xe1, 0x19, 0xff, 0xa1, 0xff, 0xfe, 0xff, 0xf5, 0x7d, 0x01, 0x20, 0x65, 0x26, 0x4d, 0xff, + 0xe1, 0xff, 0xd0, 0xff, 0xe8, 0xff, 0xda, 0xff, 0x85, 0x40, 0xff, 0xbc, 0x43, 0x73, 0x2e, 0x3d, 0xff, 0xad, 0x1b, 0x35, + 0x5a, 0xff, 0xa3, 0x7b, 0x7f, 0xff, 0xba, 0xff, 0xdb, 0x72, 0x67, 0x3a, 0x5b, 0xff, 0xa1, 0xff, 0x98, 0x4c, 0x65, 0xff, + 0xda, 0x01, 0xfe, 0xc0, 0x2b, 0x01, 0x30, 0x79, 0x8d, 0xe7, 0xfc, 0x2a, 0x8f, 0x92, 0x7f, 0x5b, 0x8a, 0x5c, 0x42, 0xa0, + 0x47, 0x45, 0x76, 0xea, 0x35, 0xec, 0xd9, 0x95, 0x3d, 0x92, 0x75, 0x01, 0xf5, 0x43, 0x77, 0x50, 0x39, 0xeb, 0xa0, 0x72, + 0xef, 0x34, 0x38, 0x72, 0xcb, 0x79, 0xe2, 0xe3, 0x19, 0x3b, 0x6b, 0x2e, 0x45, 0x13, 0x11, 0x01, 0x01, 0x01, + } + f.Add(TestResumeClient) + f.Add(TestResumeServer) + + f.Fuzz(func(t *testing.T, data []byte) { + deserialized := &State{} + _ = deserialized.UnmarshalBinary(data) + }) +} diff --git a/pkg/protocol/extension/fuzz_test.go b/pkg/protocol/extension/fuzz_test.go new file mode 100644 index 000000000..31536a2f2 --- /dev/null +++ b/pkg/protocol/extension/fuzz_test.go @@ -0,0 +1,19 @@ +// SPDX-FileCopyrightText: 2023 The Pion community +// SPDX-License-Identifier: MIT + +package extension + +import "testing" + +func FuzzUnmarshal(f *testing.F) { + f.Add([]byte{0x00}) + f.Add([]byte{1, 6, 8, 3, 88, 12, 2, 47}) + f.Add([]byte{0x0, 0xa, 0x0, 0x4, 0x0, 0x2, 0x0, 0x1d}) + f.Add([]byte{0x00, 0x0b, 0x00, 0x02, 0x01, 0x00}) + f.Add([]byte{0x00, 0x0d, 0x00, 0x08, 0x00, 0x06, 0x04, 0x03, 0x05, 0x03, 0x06, 0x03}) + f.Add([]byte{0x00, 0x0e, 0x00, 0x05, 0x00, 0x02, 0x00, 0x01, 0x00}) + + f.Fuzz(func(t *testing.T, data []byte) { + _, _ = Unmarshal(data) + }) +} diff --git a/pkg/protocol/handshake/fuzz_test.go b/pkg/protocol/handshake/fuzz_test.go index 837459f85..441d0ef04 100644 --- a/pkg/protocol/handshake/fuzz_test.go +++ b/pkg/protocol/handshake/fuzz_test.go @@ -8,17 +8,64 @@ import ( ) func FuzzDtlsHandshake(f *testing.F) { + rawCertificateRequest := []byte{ + 0x02, 0x01, 0x40, 0x00, 0x0C, 0x04, 0x03, 0x04, 0x01, 0x05, 0x03, + 0x05, 0x01, 0x06, 0x01, 0x02, 0x01, 0x00, 0x06, 0x00, 0x04, 0x74, 0x65, 0x73, 0x74, + } + rawCertificateVerify := []byte{ + 0x04, 0x03, 0x00, 0x47, 0x30, 0x45, 0x02, 0x20, 0x6b, 0x63, 0x17, 0xad, 0xbe, 0xb7, 0x7b, 0x0f, + 0x86, 0x73, 0x39, 0x1e, 0xba, 0xb3, 0x50, 0x9c, 0xce, 0x9c, 0xe4, 0x8b, 0xe5, 0x13, 0x07, 0x59, + 0x18, 0x1f, 0xe5, 0xa0, 0x2b, 0xca, 0xa6, 0xad, 0x02, 0x21, 0x00, 0xd3, 0xb5, 0x01, 0xbe, 0x87, + 0x6c, 0x04, 0xa1, 0xdc, 0x28, 0xaa, 0x5f, 0xf7, 0x1e, 0x9c, 0xc0, 0x1e, 0x00, 0x2c, 0xe5, 0x94, + 0xbb, 0x03, 0x0e, 0xf1, 0xcb, 0x28, 0x22, 0x33, 0x23, 0x88, 0xad, + } + rawClientHello := []byte{ + 0xfe, 0xfd, 0xb6, 0x2f, 0xce, 0x5c, 0x42, 0x54, 0xff, 0x86, 0xe1, 0x24, 0x41, 0x91, 0x42, + 0x62, 0x15, 0xad, 0x16, 0xc9, 0x15, 0x8d, 0x95, 0x71, 0x8a, 0xbb, 0x22, 0xd7, 0x47, 0xec, + 0xd8, 0x3d, 0xdc, 0x4b, 0x00, 0x14, 0xe6, 0x14, 0x3a, 0x1b, 0x04, 0xea, 0x9e, 0x7a, 0x14, + 0xd6, 0x6c, 0x57, 0xd0, 0x0e, 0x32, 0x85, 0x76, 0x18, 0xde, 0xd8, 0x00, 0x04, 0xc0, 0x2b, + 0xc0, 0x0a, 0x01, 0x00, 0x00, 0x08, 0x00, 0x0a, 0x00, 0x04, 0x00, 0x02, 0x00, 0x1d, + } + rawClientKeyExchange := []byte{ + 0x20, 0x26, 0x78, 0x4a, 0x78, 0x70, 0xc1, 0xf9, 0x71, 0xea, 0x50, 0x4a, 0xb5, 0xbb, 0x00, 0x76, + 0x02, 0x05, 0xda, 0xf7, 0xd0, 0x3f, 0xe3, 0xf7, 0x4e, 0x8a, 0x14, 0x6f, 0xb7, 0xe0, 0xc0, 0xff, + 0x54, + } + rawFinished := []byte{ + 0x01, 0x01, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, + } + rawHelloVerifyRequest := []byte{ + 0xfe, 0xff, 0x14, 0x25, 0xfb, 0xee, 0xb3, 0x7c, 0x95, 0xcf, 0x00, + 0xeb, 0xad, 0xe2, 0xef, 0xc7, 0xfd, 0xbb, 0xed, 0xf7, 0x1f, 0x6c, 0xcd, + } + rawServerHello := []byte{ + 0xfe, 0xfd, 0x21, 0x63, 0x32, 0x21, 0x81, 0x0e, 0x98, 0x6c, + 0x85, 0x3d, 0xa4, 0x39, 0xaf, 0x5f, 0xd6, 0x5c, 0xcc, 0x20, + 0x7f, 0x7c, 0x78, 0xf1, 0x5f, 0x7e, 0x1c, 0xb7, 0xa1, 0x1e, + 0xcf, 0x63, 0x84, 0x28, 0x00, 0xc0, 0x2b, 0x00, 0x00, 0x00, + } + rawServerKeyExchange := []byte{ + 0x03, 0x00, 0x1d, 0x41, 0x04, 0x0c, 0xb9, 0xa3, 0xb9, 0x90, 0x71, 0x35, 0x4a, 0x08, 0x66, 0xaf, + 0xd6, 0x88, 0x58, 0x29, 0x69, 0x98, 0xf1, 0x87, 0x0f, 0xb5, 0xa8, 0xcd, 0x92, 0xf6, 0x2b, 0x08, + 0x0c, 0xd4, 0x16, 0x5b, 0xcc, 0x81, 0xf2, 0x58, 0x91, 0x8e, 0x62, 0xdf, 0xc1, 0xec, 0x72, 0xe8, + 0x47, 0x24, 0x42, 0x96, 0xb8, 0x7b, 0xee, 0xe7, 0x0d, 0xdc, 0x44, 0xec, 0xf3, 0x97, 0x6b, 0x1b, + 0x45, 0x28, 0xac, 0x3f, 0x35, 0x02, 0x03, 0x00, 0x47, 0x30, 0x45, 0x02, 0x21, 0x00, 0xb2, 0x0b, + 0x22, 0x95, 0x3d, 0x56, 0x57, 0x6a, 0x3f, 0x85, 0x30, 0x6f, 0x55, 0xc3, 0xf4, 0x24, 0x1b, 0x21, + 0x07, 0xe5, 0xdf, 0xba, 0x24, 0x02, 0x68, 0x95, 0x1f, 0x6e, 0x13, 0xbd, 0x9f, 0xaa, 0x02, 0x20, + 0x49, 0x9c, 0x9d, 0xdf, 0x84, 0x60, 0x33, 0x27, 0x96, 0x9e, 0x58, 0x6d, 0x72, 0x13, 0xe7, 0x3a, + 0xe8, 0xdf, 0x43, 0x75, 0xc7, 0xb9, 0x37, 0x6e, 0x90, 0xe5, 0x3b, 0x81, 0xd4, 0xda, 0x68, 0xcd, + } + f.Add(rawCertificateRequest) + f.Add(rawCertificateVerify) + f.Add(rawClientHello) + f.Add(rawClientKeyExchange) + f.Add(rawFinished) + f.Add(rawHelloVerifyRequest) + f.Add(rawServerHello) + f.Add(rawServerKeyExchange) + f.Fuzz(func(t *testing.T, data []byte) { h := &Handshake{} - if err := h.Unmarshal(data); err != nil { - return - } - buf, err := h.Marshal() - if err != nil { - t.Fatal(err) - } - if len(buf) == 0 { - t.Fatal("Zero buff") - } + _ = h.Unmarshal(data) }) } diff --git a/pkg/protocol/recordlayer/fuzz_test.go b/pkg/protocol/recordlayer/fuzz_test.go index 716b5c8a2..f9cb4e942 100644 --- a/pkg/protocol/recordlayer/fuzz_test.go +++ b/pkg/protocol/recordlayer/fuzz_test.go @@ -4,39 +4,33 @@ package recordlayer import ( - "reflect" "testing" ) -func headerMismatch(a, b Header) bool { - // Ignoring content length for now. - a.ContentLen = b.ContentLen - return !reflect.DeepEqual(a, b) -} - func FuzzRecordLayer(f *testing.F) { + Data := []byte{ + 0x14, 0xfe, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, 0x01, 0x01, + } + f.Add(Data) + f.Fuzz(func(t *testing.T, data []byte) { var r RecordLayer - if err := r.Unmarshal(data); err != nil { - return - } - - buf, err := r.Marshal() - if err != nil { - return - } - - if len(buf) == 0 { - t.Fatal("Zero buff") - } + _ = r.Unmarshal(data) + }) +} - var nr RecordLayer - if err = nr.Unmarshal(data); err != nil { - t.Fatal(err) - } +func FuzzUnpackDatagram(f *testing.F) { + Datasingle := []byte{ + 0x14, 0xfe, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, 0x01, 0x01, + } + Datamulti := []byte{ + 0x14, 0xfe, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, 0x01, 0x01, + 0x14, 0xfe, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x01, 0x01, + } + f.Add(Datasingle) + f.Add(Datamulti) - if headerMismatch(nr.Header, r.Header) { - t.Fatalf("Header mismatch: %+v != %+v", nr.Header, r.Header) - } + f.Fuzz(func(t *testing.T, data []byte) { + _, _ = UnpackDatagram(data) }) }