rename enroll -> pair

This commit is contained in:
Patrick Nicolas
2024-11-26 23:59:35 +01:00
parent 967f48700b
commit 954b5a7038
11 changed files with 66 additions and 65 deletions
+2 -2
View File
@@ -127,7 +127,7 @@ void wivrn_session::handshake(T address, bool tcp_only, crypto::key & headset_ke
pin = pin_enter(control.get_fd());
[[fallthrough]];
case to_headset::crypto_handshake::crypto_state::client_already_known: {
case to_headset::crypto_handshake::crypto_state::client_already_paired: {
spdlog::info("Using pin \"{}\"", pin);
crypto::key server_key = crypto::key::from_public_key(crypto_handshake.public_key);
@@ -149,7 +149,7 @@ void wivrn_session::handshake(T address, bool tcp_only, crypto::key & headset_ke
break;
}
case to_headset::crypto_handshake::crypto_state::enroll_disabled:
case to_headset::crypto_handshake::crypto_state::pairing_disabled:
spdlog::info("Pairing is disabled on server");
throw std::runtime_error(_("Pairing is disabled on server"));
}
+3 -2
View File
@@ -26,6 +26,7 @@
#include <openssl/aes.h>
#include <optional>
#include <span>
#include <string>
#include <variant>
#include <vector>
#include <vulkan/vulkan_core.h>
@@ -273,8 +274,8 @@ struct crypto_handshake
{
encryption_disabled,
pin_needed,
client_already_known,
enroll_disabled,
client_already_paired,
pairing_disabled,
};
std::string public_key; // In PEM format
+4 -4
View File
@@ -264,10 +264,10 @@ main_window::main_window()
connect(server_interface, &wivrn_server::pinChanged, this, &main_window::on_pin_changed);
on_pin_changed(server_interface->pin());
connect(server_interface, &wivrn_server::enrollEnabledChanged, ui->button_cancel_pairing, &QWidget::setVisible);
connect(server_interface, &wivrn_server::enrollEnabledChanged, ui->button_pair_headset, &QWidget::setHidden);
connect(ui->button_cancel_pairing, &QPushButton::clicked, server_interface, &wivrn_server::disable_enroll_headset);
connect(ui->button_pair_headset, &QPushButton::clicked, server_interface, &wivrn_server::enroll_headset);
connect(server_interface, &wivrn_server::pairingEnabledChanged, ui->button_cancel_pairing, &QWidget::setVisible);
connect(server_interface, &wivrn_server::pairingEnabledChanged, ui->button_pair_headset, &QWidget::setHidden);
connect(ui->button_cancel_pairing, &QPushButton::clicked, server_interface, &wivrn_server::disable_pairing);
connect(ui->button_pair_headset, &QPushButton::clicked, server_interface, &wivrn_server::enable_pairing);
connect(ui->button_start, &QPushButton::clicked, this, &main_window::start_server);
connect(ui->button_stop, &QPushButton::clicked, this, &main_window::stop_server);
+6 -6
View File
@@ -129,9 +129,9 @@ void wivrn_server::on_server_properties_changed(const QString & interface_name,
knownKeysChanged(m_knownKeys);
}
if (changed_properties.contains("EnrollEnabled"))
if (changed_properties.contains("PairingEnabled"))
{
enrollEnabledChanged(m_isEnrollEnabled = changed_properties["EnrollEnabled"].toBool());
pairingEnabledChanged(m_isPairingEnabled = changed_properties["PairingEnabled"].toBool());
}
if (changed_properties.contains("EncryptionEnabled"))
@@ -252,14 +252,14 @@ void wivrn_server::rename_key(QString public_key, QString name)
server_interface->RenameKey(public_key, name);
}
QString wivrn_server::enroll_headset(int timeout_secs)
QString wivrn_server::enable_pairing(int timeout_secs)
{
return server_interface->EnrollHeadset(timeout_secs).value();
return server_interface->EnablePairing(timeout_secs).value();
}
void wivrn_server::disable_enroll_headset()
void wivrn_server::disable_pairing()
{
server_interface->DisableEnrollHeadset();
server_interface->DisablePairing();
}
QString wivrn_server::hostname()
+7 -7
View File
@@ -58,12 +58,12 @@ public:
// Authentication
Q_PROPERTY(QString pin READ pin NOTIFY pinChanged)
Q_PROPERTY(HeadsetKeys knownKeys READ knownKeys NOTIFY knownKeysChanged)
Q_PROPERTY(bool enrollEnabled READ isEnrollEnabled NOTIFY enrollEnabledChanged)
Q_PROPERTY(bool pairingEnabled READ isPairingEnabled NOTIFY pairingEnabledChanged)
Q_PROPERTY(bool encryptionEnabled READ isEncryptionEnabled NOTIFY encryptionEnabledChanged)
void revoke_key(QString public_key);
void rename_key(QString public_key, QString name);
QString enroll_headset(int timeout_secs = 120);
void disable_enroll_headset();
QString enable_pairing(int timeout_secs = 120);
void disable_pairing();
// Headset information, valid only if HeadsetConnected is true
Q_PROPERTY(QSize recommendedEyeSize READ recommendedEyeSize NOTIFY recommendedEyeSizeChanged)
@@ -110,9 +110,9 @@ public:
return m_knownKeys;
}
bool isEnrollEnabled() const
bool isPairingEnabled() const
{
return m_isEnrollEnabled;
return m_isPairingEnabled;
}
bool isEncryptionEnabled() const
@@ -203,7 +203,7 @@ private:
QString m_pin{};
HeadsetKeys m_knownKeys;
bool m_isEnrollEnabled{};
bool m_isPairingEnabled{};
bool m_isEncryptionEnabled{};
QSize m_recommendedEyeSize{};
@@ -225,7 +225,7 @@ Q_SIGNALS:
void headsetConnectedChanged(bool);
void pinChanged(QString);
void knownKeysChanged(HeadsetKeys);
void enrollEnabledChanged(bool);
void pairingEnabledChanged(bool);
void encryptionEnabledChanged(bool);
void recommendedEyeSizeChanged(QSize);
+3 -3
View File
@@ -403,8 +403,8 @@ void wizard::on_page_changed(int id)
setButtonLayout({QWizard::Stretch, QWizard::BackButton, QWizard::NextButton, QWizard::CustomButton1, QWizard::CancelButton});
on_headset_connected_changed(server->isHeadsetConnected());
if (not server->isEnrollEnabled())
server->enroll_headset(-1);
if (not server->isPairingEnabled())
server->enable_pairing(-1);
return;
@@ -458,7 +458,7 @@ void wizard::retranslate()
wizard::~wizard()
{
server->disable_enroll_headset();
server->disable_pairing();
delete ui;
ui = nullptr;
+3 -3
View File
@@ -35,11 +35,11 @@
<arg type="s" name="PublicKey"/>
<arg type="s" name="Name"/>
</method>
<method name="EnrollHeadset">
<method name="EnablePairing">
<arg type="i" name="TimeoutSecs"/>
<arg type="s" name="Pin" direction="out"/>
</method>
<method name="DisableEnrollHeadset"/>
<method name="DisablePairing"/>
<property name="HeadsetConnected" type="b" access="read"/>
<property name="SteamCommand" type="s" access="read"/>
@@ -70,7 +70,7 @@
<annotation name="org.qtproject.QtDBus.QtTypeName" value="QList&lt;std::pair&lt;QString,QString&gt;&gt;"/>
<!-- first: name, second: public key -->
</property>
<property name="EnrollEnabled" type="b" access="read"/>
<property name="PairingEnabled" type="b" access="read"/>
<property name="EncryptionEnabled" type="b" access="read"/>
</interface>
</node>
+5 -5
View File
@@ -180,21 +180,21 @@ void wivrn::wivrn_connection::init(std::stop_token stop_token, std::function<voi
if (not is_public_key_known)
{
control.send(to_headset::crypto_handshake{
.state = to_headset::crypto_handshake::crypto_state::enroll_disabled,
.state = to_headset::crypto_handshake::crypto_state::pairing_disabled,
});
throw std::runtime_error("Client not known and enroll is disabled");
throw std::runtime_error("Client not known and pairing is disabled");
}
[[fallthrough]];
case encryption_state::enroll:
case encryption_state::pairing:
// Generate an ephemeral key pair just for exchanging the AES key
crypto::key server_key = crypto::key::generate_x448_keypair();
control.send(to_headset::crypto_handshake{
.public_key = server_key.public_key(),
.state = is_public_key_known
? to_headset::crypto_handshake::crypto_state::client_already_known
? to_headset::crypto_handshake::crypto_state::client_already_paired
: to_headset::crypto_handshake::crypto_state::pin_needed,
});
@@ -234,7 +234,7 @@ void wivrn::wivrn_connection::init(std::stop_token stop_token, std::function<voi
active = true;
if (state == encryption_state::enroll and not is_public_key_known)
if (state == encryption_state::pairing and not is_public_key_known)
wivrn::add_known_key({
.public_key = clean_key(headset_key.public_key()),
.name = crypto_handshake.name,
+1 -1
View File
@@ -39,7 +39,7 @@ public:
{
disabled,
enabled,
enroll,
pairing,
};
private:
+18 -18
View File
@@ -209,7 +209,7 @@ bool avahi_publish;
guint listener_watch;
wivrn_connection::encryption_state enc_state = wivrn_connection::encryption_state::enabled;
guint enroll_timeout;
guint pairing_timeout;
std::string pin;
NotifyNotification * pin_notification;
@@ -448,7 +448,7 @@ gboolean headset_connected_success(void *)
assert(connection_thread);
connection_thread.reset();
if (enc_state == wivrn_connection::encryption_state::enroll)
if (enc_state == wivrn_connection::encryption_state::pairing)
set_encryption_state(wivrn_connection::encryption_state::enabled);
init_cleanup_functions();
@@ -546,7 +546,7 @@ void set_encryption_state(wivrn_connection::encryption_state new_enc_state)
case wivrn_connection::encryption_state::disabled:
pin = "";
std::cerr << "Encryption is disabled" << std::endl;
wivrn_server_set_enroll_enabled(dbus_server, false);
wivrn_server_set_pairing_enabled(dbus_server, false);
wivrn_server_set_encryption_enabled(dbus_server, false);
notify_notification_set_timeout(pin_notification, NOTIFY_EXPIRES_NEVER);
@@ -558,11 +558,11 @@ void set_encryption_state(wivrn_connection::encryption_state new_enc_state)
if (enc_state != wivrn_connection::encryption_state::enabled)
std::cerr << "Headset pairing is disabled" << std::endl;
wivrn_server_set_enroll_enabled(dbus_server, false);
wivrn_server_set_pairing_enabled(dbus_server, false);
wivrn_server_set_encryption_enabled(dbus_server, true);
break;
case wivrn_connection::encryption_state::enroll:
case wivrn_connection::encryption_state::pairing:
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<> distrib(0, 999999);
@@ -571,7 +571,7 @@ void set_encryption_state(wivrn_connection::encryption_state new_enc_state)
snprintf(buffer, 7, "%06d", distrib(gen));
pin = buffer;
std::cerr << "To pair a new headset use PIN code: " << pin << std::endl;
wivrn_server_set_enroll_enabled(dbus_server, true);
wivrn_server_set_pairing_enabled(dbus_server, true);
wivrn_server_set_encryption_enabled(dbus_server, true);
// Desktop notification
@@ -641,12 +641,12 @@ gboolean on_handle_rename_key(WivrnServer * skeleton, GDBusMethodInvocation * in
return G_SOURCE_CONTINUE;
}
gboolean on_handle_enroll_headset(WivrnServer * skeleton, GDBusMethodInvocation * invocation, gpointer user_data)
gboolean on_handle_enable_pairing(WivrnServer * skeleton, GDBusMethodInvocation * invocation, gpointer user_data)
{
set_encryption_state(wivrn_connection::encryption_state::enroll);
set_encryption_state(wivrn_connection::encryption_state::pairing);
if (enroll_timeout)
g_source_remove(enroll_timeout);
if (pairing_timeout)
g_source_remove(pairing_timeout);
int timeout_secs;
GVariant * args = g_dbus_method_invocation_get_parameters(invocation);
@@ -654,8 +654,8 @@ gboolean on_handle_enroll_headset(WivrnServer * skeleton, GDBusMethodInvocation
if (timeout_secs > 0)
{
enroll_timeout = g_timeout_add(timeout_secs * 1000, [](void *) {
enroll_timeout = 0;
pairing_timeout = g_timeout_add(timeout_secs * 1000, [](void *) {
pairing_timeout = 0;
set_encryption_state(wivrn_connection::encryption_state::enabled);
return G_SOURCE_REMOVE; }, nullptr);
}
@@ -664,7 +664,7 @@ gboolean on_handle_enroll_headset(WivrnServer * skeleton, GDBusMethodInvocation
return G_SOURCE_CONTINUE;
}
gboolean on_handle_disable_enroll_headset(WivrnServer * skeleton, GDBusMethodInvocation * invocation, gpointer user_data)
gboolean on_handle_disable_pairing(WivrnServer * skeleton, GDBusMethodInvocation * invocation, gpointer user_data)
{
set_encryption_state(wivrn_connection::encryption_state::enabled);
g_dbus_method_invocation_return_value(invocation, nullptr);
@@ -782,13 +782,13 @@ void on_name_acquired(GDBusConnection * connection, const gchar * name, gpointer
if (enc_state != wivrn_connection::encryption_state::disabled)
{
g_signal_connect(dbus_server,
"handle-enroll-headset",
G_CALLBACK(on_handle_enroll_headset),
"handle-enable-pairing",
G_CALLBACK(on_handle_enable_pairing),
NULL);
g_signal_connect(dbus_server,
"handle-disable-enroll-headset",
G_CALLBACK(on_handle_disable_enroll_headset),
"handle-disable-pairing",
G_CALLBACK(on_handle_disable_pairing),
NULL);
}
@@ -811,7 +811,7 @@ void on_name_acquired(GDBusConnection * connection, const gchar * name, gpointer
NULL);
if (enc_state != wivrn_connection::encryption_state::disabled and known_keys().empty())
set_encryption_state(wivrn_connection::encryption_state::enroll);
set_encryption_state(wivrn_connection::encryption_state::pairing);
else
set_encryption_state(enc_state);
}
+14 -14
View File
@@ -77,18 +77,18 @@ sd_bus_message_ptr get_property(const sd_bus_ptr & bus, const char * member, con
return sd_bus_message_ptr(msg);
}
void enroll(int duration)
void pair(int duration)
{
if (duration == 0)
{
call_method(get_user_bus(),
"DisableEnrollHeadset",
"DisablePairing",
"");
}
else
{
auto pin_msg = call_method(get_user_bus(),
"EnrollHeadset",
"EnablePairing",
"i",
duration * 60);
@@ -101,7 +101,7 @@ void enroll(int duration)
}
}
void list_enrolled(bool show_keys)
void list_paired(bool show_keys)
{
auto msg = get_property(get_user_bus(),
"KnownKeys",
@@ -109,7 +109,7 @@ void list_enrolled(bool show_keys)
int ret = sd_bus_message_enter_container(msg.get(), 'a', "(ss)");
if (ret < 0)
throw std::system_error(-ret, std::system_category(), "Failed to get enrolled headsets");
throw std::system_error(-ret, std::system_category(), "Failed to get paired headsets");
std::vector<std::pair<std::string, std::string>> values;
while (true)
@@ -120,7 +120,7 @@ void list_enrolled(bool show_keys)
if (ret == 0)
break;
if (ret < 0)
throw std::system_error(-ret, std::system_category(), "Failed to get enrolled headset details");
throw std::system_error(-ret, std::system_category(), "Failed to get paired headset details");
values.emplace_back(name, key);
}
@@ -131,7 +131,7 @@ void list_enrolled(bool show_keys)
width = std::max(width, name.length());
width += 1;
}
std::cout << "Enrolled headsets:" << std::endl;
std::cout << "Paired headsets:" << std::endl;
for (const auto & [name, key]: values)
{
if (width > 0)
@@ -163,11 +163,11 @@ int main(int argc, char ** argv)
app.require_subcommand(1);
int enroll_duration;
auto enroll_command = app.add_subcommand("enroll", "Allow a new headset to connect")
->callback([&]() { return enroll(enroll_duration); });
auto duration = enroll_command
->add_option("--duration,-d", enroll_duration, "Duration in minutes to allow new connections")
int pairing_duration;
auto pair_command = app.add_subcommand("pair", "Allow a new headset to connect")
->callback([&]() { return pair(pairing_duration); });
auto duration = pair_command
->add_option("--duration,-d", pairing_duration, "Duration in minutes to allow new connections")
->transform(CLI::Validator([](std::string & input) {
if (input.starts_with("-"))
throw CLI::ValidationError("duration must be positive");
@@ -181,8 +181,8 @@ int main(int argc, char ** argv)
->option_text("INT|unlimited");
bool show_keys = false;
auto list_command = app.add_subcommand("list-enrolled", "List headsets allowed to connect")
->callback([&]() { list_enrolled(show_keys); });
auto list_command = app.add_subcommand("list-paired", "List headsets allowed to connect")
->callback([&]() { list_paired(show_keys); });
list_command->add_flag("--keys, -k", show_keys, "Show public keys");