Compare commits

...

3 Commits

Author SHA1 Message Date
Andri Yngvason fce9a2eb69 Add config parameter for RSA private key file 2023-09-10 17:19:25 +00:00
Andri Yngvason 31e19757d1 main: Use 1 client cleanup function 2023-09-03 18:25:59 +00:00
Andri Yngvason 0b6229df5b Add non-tls authentication 2023-08-24 10:29:09 +00:00
2 changed files with 46 additions and 35 deletions

View File

@ -23,6 +23,7 @@
X(bool, enable_auth) \
X(string, private_key_file) \
X(string, certificate_file) \
X(string, rsa_private_key_file) \
X(string, username) \
X(string, password) \
X(string, address) \

View File

@ -740,11 +740,27 @@ int init_nvnc(struct wayvnc* self, const char* addr, uint16_t port,
nvnc_set_name(self->nvnc, "WayVNC");
if (self->cfg.enable_auth &&
nvnc_enable_auth(self->nvnc, self->cfg.private_key_file,
self->cfg.certificate_file, on_auth, self) < 0) {
nvnc_log(NVNC_LOG_ERROR, "Failed to enable authentication");
goto failure;
if (self->cfg.enable_auth) {
if (self->cfg.rsa_private_key_file) {
if (nvnc_enable_auth2(self->nvnc, on_auth, self) < 0) {
nvnc_log(NVNC_LOG_ERROR, "Failed to enable RSA authentication");
goto failure;
}
if (nvnc_set_rsa_creds(self->nvnc, self->cfg.rsa_private_key_file) < 0) {
nvnc_log(NVNC_LOG_ERROR, "Failed to load RSA credentials");
goto failure;
}
}
if (self->cfg.private_key_file) {
int r = nvnc_enable_auth(self->nvnc, self->cfg.private_key_file,
self->cfg.certificate_file, on_auth, self);
if (r < 0) {
nvnc_log(NVNC_LOG_ERROR, "Failed to enable TLS authentication");
goto failure;
}
}
}
if (self->pointer_manager)
@ -1036,6 +1052,30 @@ static struct wayvnc_client* client_create(struct wayvnc* wayvnc,
static void client_destroy(void* obj)
{
struct wayvnc_client* self = obj;
struct nvnc* nvnc = nvnc_client_get_server(self->nvnc_client);
struct wayvnc* wayvnc = nvnc_get_userdata(nvnc);
if (self->seat)
self->seat->occupancy--;
wayvnc->nr_clients--;
nvnc_log(NVNC_LOG_DEBUG, "Client disconnected, new client count: %d",
wayvnc->nr_clients);
struct ctl_server_client_info info = {
.id = self->id,
.hostname = nvnc_client_get_hostname(self->nvnc_client),
.username = nvnc_client_get_auth_username(self->nvnc_client),
.seat = self->seat->name,
};
ctl_server_event_disconnected(wayvnc->ctl, &info, wayvnc->nr_clients);
if (wayvnc->nr_clients == 0) {
nvnc_log(NVNC_LOG_INFO, "Stopping screen capture");
screencopy_stop(&wayvnc->screencopy);
stop_performance_ticker(wayvnc);
}
if (self->keyboard.virtual_keyboard) {
zwp_virtual_keyboard_v1_destroy(
@ -1052,35 +1092,6 @@ static void client_destroy(void* obj)
free(self);
}
static void on_nvnc_client_cleanup(struct nvnc_client* client)
{
struct wayvnc_client* wayvnc_client = nvnc_get_userdata(client);
struct nvnc* nvnc = nvnc_client_get_server(client);
struct wayvnc* self = nvnc_get_userdata(nvnc);
if (wayvnc_client->seat)
wayvnc_client->seat->occupancy--;
self->nr_clients--;
nvnc_log(NVNC_LOG_DEBUG, "Client disconnected, new client count: %d",
self->nr_clients);
struct ctl_server_client_info info = {
.id = wayvnc_client->id,
.hostname = nvnc_client_get_hostname(client),
.username = nvnc_client_get_auth_username(client),
.seat = wayvnc_client->seat->name,
};
ctl_server_event_disconnected(self->ctl, &info, self->nr_clients);
if (self->nr_clients == 0) {
nvnc_log(NVNC_LOG_INFO, "Stopping screen capture");
screencopy_stop(&self->screencopy);
stop_performance_ticker(self);
}
}
static void on_nvnc_client_new(struct nvnc_client* client)
{
struct nvnc* nvnc = nvnc_client_get_server(client);
@ -1096,7 +1107,6 @@ static void on_nvnc_client_new(struct nvnc_client* client)
wayvnc_start_capture_immediate(self);
}
self->nr_clients++;
nvnc_set_client_cleanup_fn(client, on_nvnc_client_cleanup);
nvnc_log(NVNC_LOG_DEBUG, "Client connected, new client count: %d",
self->nr_clients);