Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Vindicus999
2025-06-17 11:13:25 +00:00
3 changed files with 18 additions and 2 deletions
+6
View File
@@ -19,6 +19,7 @@
#include "wivrn_client.h" #include "wivrn_client.h"
#include "hardware.h" #include "hardware.h"
#include "protocol_version.h"
#include "secrets.h" #include "secrets.h"
#include "smp.h" #include "smp.h"
#include "spdlog/common.h" #include "spdlog/common.h"
@@ -99,6 +100,7 @@ void wivrn_session::handshake(T address, bool tcp_only, crypto::key & headset_ke
}; };
send_control(from_headset::crypto_handshake{ send_control(from_headset::crypto_handshake{
.protocol_version = wivrn::protocol_version,
.public_key = headset_keypair.public_key(), .public_key = headset_keypair.public_key(),
.name = model_name(), .name = model_name(),
}); });
@@ -178,6 +180,10 @@ void wivrn_session::handshake(T address, bool tcp_only, crypto::key & headset_ke
case to_headset::crypto_handshake::crypto_state::pairing_disabled: case to_headset::crypto_handshake::crypto_state::pairing_disabled:
spdlog::info("Pairing is disabled on server"); spdlog::info("Pairing is disabled on server");
throw std::runtime_error(_("Pairing is disabled on server")); throw std::runtime_error(_("Pairing is disabled on server"));
case to_headset::crypto_handshake::crypto_state::incompatible_version:
spdlog::error("Incompatible protocol versions");
throw std::runtime_error(_("Incompatible server version"));
} }
// may be on control socket if forced TCP // may be on control socket if forced TCP
+3 -2
View File
@@ -34,7 +34,6 @@
#include "smp.h" #include "smp.h"
#include "wivrn_serialization_types.h" #include "wivrn_serialization_types.h"
#include "xr/pico_eye_types.h"
namespace wivrn namespace wivrn
{ {
@@ -42,7 +41,7 @@ namespace wivrn
// Default port for server to listen, both TCP and UDP // Default port for server to listen, both TCP and UDP
static const int default_port = 9757; static const int default_port = 9757;
static constexpr int protocol_revision = 2; static constexpr int protocol_revision = 0;
enum class device_id : uint8_t enum class device_id : uint8_t
{ {
@@ -165,6 +164,7 @@ namespace from_headset
{ {
struct crypto_handshake struct crypto_handshake
{ {
uint64_t protocol_version;
std::string public_key; // In PEM format std::string public_key; // In PEM format
std::string name; std::string name;
}; };
@@ -441,6 +441,7 @@ struct crypto_handshake
pin_needed, pin_needed,
client_already_paired, client_already_paired,
pairing_disabled, pairing_disabled,
incompatible_version,
}; };
std::string public_key; // In PEM format std::string public_key; // In PEM format
+9
View File
@@ -19,6 +19,7 @@
#include "wivrn_connection.h" #include "wivrn_connection.h"
#include "configuration.h" #include "configuration.h"
#include "protocol_version.h"
#include "secrets.h" #include "secrets.h"
#include "smp.h" #include "smp.h"
#include "wivrn_ipc.h" #include "wivrn_ipc.h"
@@ -169,6 +170,14 @@ void wivrn::wivrn_connection::init(std::stop_token stop_token, std::function<voi
// Wait for client to send handshake packet // Wait for client to send handshake packet
auto crypto_handshake = std::get<from_headset::crypto_handshake>(receive(10s).first); auto crypto_handshake = std::get<from_headset::crypto_handshake>(receive(10s).first);
if (crypto_handshake.protocol_version != wivrn::protocol_version)
{
control.send(to_headset::crypto_handshake{
.state = to_headset::crypto_handshake::crypto_state::incompatible_version,
});
throw std::runtime_error("Incompatible protocol version");
}
crypto::key headset_key = crypto::key::from_public_key(crypto_handshake.public_key); crypto::key headset_key = crypto::key::from_public_key(crypto_handshake.public_key);
bool is_public_key_known = std::ranges::any_of( bool is_public_key_known = std::ranges::any_of(
wivrn::known_keys(), wivrn::known_keys(),