Check the PIN when pairing

This commit is contained in:
Guillaume Meunier
2024-12-01 17:25:28 +01:00
parent 6e6cc3cf68
commit fe10178add
8 changed files with 161 additions and 8 deletions
+1
View File
@@ -32,6 +32,7 @@ add_library(wivrn-common-base STATIC
add_library(wivrn-common STATIC
crypto.cpp
smp.cpp
secrets.cpp
wivrn_sockets.cpp
utils/xdg_base_directory.cpp
+23 -2
View File
@@ -32,6 +32,7 @@
#include <vulkan/vulkan_core.h>
#include <openxr/openxr.h>
#include "smp.h"
#include "wivrn_serialization_types.h"
namespace wivrn
@@ -105,6 +106,16 @@ struct crypto_handshake
std::string name;
};
struct pin_check_1
{
crypto::smp::msg1 message;
};
struct pin_check_3
{
crypto::smp::msg3 message;
};
struct headset_info_packet
{
uint32_t recommended_eye_width;
@@ -262,7 +273,7 @@ struct battery
bool charging;
};
using packets = std::variant<crypto_handshake, headset_info_packet, feedback, audio_data, handshake, tracking, trackings, hand_tracking, inputs, timesync_response, battery>;
using packets = std::variant<crypto_handshake, pin_check_1, pin_check_3, headset_info_packet, feedback, audio_data, handshake, tracking, trackings, hand_tracking, inputs, timesync_response, battery>;
} // namespace from_headset
namespace to_headset
@@ -282,6 +293,16 @@ struct crypto_handshake
crypto_state state;
};
struct pin_check_2
{
crypto::smp::msg2 message;
};
struct pin_check_4
{
crypto::smp::msg4 message;
};
struct handshake
{
// -1 if stream socket should not be used
@@ -426,6 +447,6 @@ struct tracking_control
std::array<bool, size_t(id::last) + 1> enabled;
};
using packets = std::variant<crypto_handshake, handshake, audio_stream_description, video_stream_description, audio_data, video_stream_data_shard, haptics, timesync_query, tracking_control>;
using packets = std::variant<crypto_handshake, pin_check_2, pin_check_4, handshake, audio_stream_description, video_stream_description, audio_data, video_stream_data_shard, haptics, timesync_query, tracking_control>;
} // namespace to_headset
} // namespace wivrn
+30
View File
@@ -21,6 +21,7 @@
#include "boost/pfr/core.hpp"
#include "boost/pfr/tuple_size.hpp"
#include "smp.h"
#include <array>
#include <boost/pfr.hpp>
#include <chrono>
@@ -903,6 +904,35 @@ struct serialization_traits<data_holder>
}
};
template <>
struct serialization_traits<crypto::bignum>
{
static constexpr void type_hash(details::hash_context & h)
{
h.feed("bignum");
}
static void serialize(const crypto::bignum & value, serialization_packet & packet)
{
serialization_traits<std::string>::serialize(value.to_data(), packet);
}
static crypto::bignum deserialize(deserialization_packet & packet)
{
return crypto::bignum::from_data(serialization_traits<std::string>::deserialize(packet));
}
static bool consteval is_trivially_serializable()
{
return false;
}
static size_t size(const crypto::bignum & value)
{
return 2 + value.data_size();
}
};
template <typename T>
constexpr uint64_t serialization_type_hash(int revision)
{