fido_cable_handshake_handler_fuzzer.cc 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Copyright 2018 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include <stddef.h>
  5. #include <stdint.h>
  6. #include <array>
  7. #include "base/containers/span.h"
  8. #include "base/memory/ref_counted.h"
  9. #include "device/bluetooth/test/mock_bluetooth_adapter.h"
  10. #include "device/fido/cable/fido_cable_device.h"
  11. #include "device/fido/cable/fido_cable_handshake_handler.h"
  12. #include "device/fido/fido_constants.h"
  13. #include "testing/gmock/include/gmock/gmock.h"
  14. #include "testing/gtest/include/gtest/gtest.h"
  15. namespace {
  16. constexpr std::array<uint8_t, 32> kTestSessionPreKey = {{
  17. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  18. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  19. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  20. }};
  21. constexpr std::array<uint8_t, 8> kTestNonce = {{
  22. 0x15, 0x14, 0x13, 0x12, 0x11, 0x10, 0x09, 0x08,
  23. }};
  24. constexpr char kTestDeviceAddress[] = "Fake_Address";
  25. } // namespace
  26. extern "C" int LLVMFuzzerTestOneInput(const uint8_t* raw_data, size_t size) {
  27. auto data_span = base::make_span(raw_data, size);
  28. auto adapter =
  29. base::MakeRefCounted<::testing::NiceMock<device::MockBluetoothAdapter>>();
  30. device::FidoCableDevice test_cable_device(adapter.get(), kTestDeviceAddress);
  31. device::FidoCableV1HandshakeHandler handshake_handler_v1(
  32. &test_cable_device, kTestNonce, kTestSessionPreKey);
  33. handshake_handler_v1.ValidateAuthenticatorHandshakeMessage(data_span);
  34. return 0;
  35. }