2020-01-24 22:30:07 +00:00
|
|
|
/*
|
2024-04-07 12:28:37 +00:00
|
|
|
* Copyright (c) 2019 - 2024 Andri Yngvason
|
2020-01-24 22:30:07 +00:00
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
|
|
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
|
|
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
|
|
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
|
|
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
|
|
|
|
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
|
|
* PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2019-12-30 17:22:19 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <pixman.h>
|
2020-04-03 22:31:16 +00:00
|
|
|
#include <zlib.h>
|
2019-12-30 17:22:19 +00:00
|
|
|
|
|
|
|
#include "rfb-proto.h"
|
|
|
|
#include "sys/queue.h"
|
|
|
|
|
|
|
|
#include "neatvnc.h"
|
2020-01-25 15:35:14 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
2023-09-05 20:31:09 +00:00
|
|
|
#ifdef HAVE_CRYPTO
|
|
|
|
#include "crypto.h"
|
|
|
|
#endif
|
|
|
|
|
2020-01-25 15:35:14 +00:00
|
|
|
#ifdef ENABLE_TLS
|
|
|
|
#include <gnutls/gnutls.h>
|
|
|
|
#endif
|
2019-12-30 17:22:19 +00:00
|
|
|
|
|
|
|
#define MAX_ENCODINGS 32
|
|
|
|
#define MAX_OUTGOING_FRAMES 4
|
|
|
|
#define MSG_BUFFER_SIZE 4096
|
2020-09-23 02:37:42 +00:00
|
|
|
#define MAX_CUT_TEXT_SIZE 10000000
|
2019-12-30 17:22:19 +00:00
|
|
|
|
|
|
|
enum nvnc_client_state {
|
|
|
|
VNC_CLIENT_STATE_ERROR = -1,
|
|
|
|
VNC_CLIENT_STATE_WAITING_FOR_VERSION = 0,
|
|
|
|
VNC_CLIENT_STATE_WAITING_FOR_SECURITY,
|
2020-01-25 15:35:14 +00:00
|
|
|
#ifdef ENABLE_TLS
|
|
|
|
VNC_CLIENT_STATE_WAITING_FOR_VENCRYPT_VERSION,
|
|
|
|
VNC_CLIENT_STATE_WAITING_FOR_VENCRYPT_SUBTYPE,
|
|
|
|
VNC_CLIENT_STATE_WAITING_FOR_VENCRYPT_PLAIN_AUTH,
|
2023-08-13 12:15:32 +00:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_CRYPTO
|
|
|
|
VNC_CLIENT_STATE_WAITING_FOR_APPLE_DH_RESPONSE,
|
2023-08-24 10:13:52 +00:00
|
|
|
VNC_CLIENT_STATE_WAITING_FOR_RSA_AES_PUBLIC_KEY,
|
|
|
|
VNC_CLIENT_STATE_WAITING_FOR_RSA_AES_CHALLENGE,
|
|
|
|
VNC_CLIENT_STATE_WAITING_FOR_RSA_AES_CLIENT_HASH,
|
|
|
|
VNC_CLIENT_STATE_WAITING_FOR_RSA_AES_CREDENTIALS,
|
2020-01-25 15:35:14 +00:00
|
|
|
#endif
|
2019-12-30 17:22:19 +00:00
|
|
|
VNC_CLIENT_STATE_WAITING_FOR_INIT,
|
|
|
|
VNC_CLIENT_STATE_READY,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct nvnc;
|
2020-01-25 15:35:14 +00:00
|
|
|
struct stream;
|
2020-03-16 20:09:22 +00:00
|
|
|
struct aml_handler;
|
2020-04-07 22:21:11 +00:00
|
|
|
struct aml_idle;
|
2020-04-12 18:16:19 +00:00
|
|
|
struct nvnc_display;
|
2023-08-13 12:15:32 +00:00
|
|
|
struct crypto_key;
|
2023-08-24 10:13:52 +00:00
|
|
|
struct crypto_rsa_pub_key;
|
|
|
|
struct crypto_rsa_priv_key;
|
2019-12-30 17:22:19 +00:00
|
|
|
|
|
|
|
struct nvnc_common {
|
|
|
|
void* userdata;
|
2021-09-04 17:05:30 +00:00
|
|
|
nvnc_cleanup_fn cleanup_fn;
|
2019-12-30 17:22:19 +00:00
|
|
|
};
|
|
|
|
|
2020-09-23 02:37:42 +00:00
|
|
|
struct cut_text {
|
|
|
|
char* buffer;
|
|
|
|
size_t length;
|
|
|
|
size_t index;
|
|
|
|
};
|
|
|
|
|
2019-12-30 17:22:19 +00:00
|
|
|
struct nvnc_client {
|
|
|
|
struct nvnc_common common;
|
|
|
|
int ref;
|
2020-01-25 15:35:14 +00:00
|
|
|
struct stream* net_stream;
|
2022-10-31 16:08:23 +00:00
|
|
|
char username[256];
|
2019-12-30 17:22:19 +00:00
|
|
|
struct nvnc* server;
|
|
|
|
enum nvnc_client_state state;
|
2020-01-24 22:28:37 +00:00
|
|
|
bool has_pixfmt;
|
2019-12-30 17:22:19 +00:00
|
|
|
struct rfb_pixel_format pixfmt;
|
|
|
|
enum rfb_encodings encodings[MAX_ENCODINGS + 1];
|
|
|
|
size_t n_encodings;
|
|
|
|
LIST_ENTRY(nvnc_client) link;
|
|
|
|
struct pixman_region16 damage;
|
|
|
|
int n_pending_requests;
|
|
|
|
bool is_updating;
|
2021-08-29 14:41:57 +00:00
|
|
|
struct nvnc_fb* current_fb;
|
2019-12-30 17:22:19 +00:00
|
|
|
nvnc_client_fn cleanup_fn;
|
|
|
|
size_t buffer_index;
|
|
|
|
size_t buffer_len;
|
|
|
|
uint8_t msg_buffer[MSG_BUFFER_SIZE];
|
2020-07-19 11:54:39 +00:00
|
|
|
uint32_t known_width;
|
|
|
|
uint32_t known_height;
|
2020-09-23 02:37:42 +00:00
|
|
|
struct cut_text cut_text;
|
2023-10-01 10:56:42 +00:00
|
|
|
bool is_ext_notified;
|
2021-12-09 22:48:31 +00:00
|
|
|
struct encoder* encoder;
|
2024-02-02 22:09:57 +00:00
|
|
|
struct encoder* zrle_encoder;
|
|
|
|
struct encoder* tight_encoder;
|
2022-02-06 15:43:45 +00:00
|
|
|
uint32_t cursor_seq;
|
2022-07-10 12:41:18 +00:00
|
|
|
int quality;
|
2024-02-02 22:24:01 +00:00
|
|
|
bool formats_changed;
|
2024-04-07 12:28:37 +00:00
|
|
|
enum nvnc_keyboard_led_state led_state;
|
|
|
|
enum nvnc_keyboard_led_state pending_led_state;
|
2023-08-13 12:15:32 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_CRYPTO
|
|
|
|
struct crypto_key* apple_dh_secret;
|
2023-08-24 10:13:52 +00:00
|
|
|
|
|
|
|
struct {
|
2023-09-05 20:31:09 +00:00
|
|
|
enum crypto_hash_type hash_type;
|
|
|
|
enum crypto_cipher_type cipher_type;
|
|
|
|
size_t challenge_len;
|
|
|
|
uint8_t challenge[32];
|
|
|
|
struct crypto_rsa_pub_key* pub;
|
2023-08-24 10:13:52 +00:00
|
|
|
} rsa;
|
2023-08-13 12:15:32 +00:00
|
|
|
#endif
|
2019-12-30 17:22:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
LIST_HEAD(nvnc_client_list, nvnc_client);
|
|
|
|
|
2023-04-06 21:02:01 +00:00
|
|
|
enum nvnc__socket_type {
|
|
|
|
NVNC__SOCKET_TCP,
|
|
|
|
NVNC__SOCKET_UNIX,
|
|
|
|
NVNC__SOCKET_WEBSOCKET,
|
2024-06-01 23:21:02 +00:00
|
|
|
NVNC__SOCKET_FROM_FD,
|
2023-04-06 21:02:01 +00:00
|
|
|
};
|
|
|
|
|
2019-12-30 17:22:19 +00:00
|
|
|
struct nvnc {
|
|
|
|
struct nvnc_common common;
|
2020-01-25 15:35:14 +00:00
|
|
|
int fd;
|
2023-04-06 21:02:01 +00:00
|
|
|
enum nvnc__socket_type socket_type;
|
2020-03-16 20:09:22 +00:00
|
|
|
struct aml_handler* poll_handle;
|
2019-12-30 17:22:19 +00:00
|
|
|
struct nvnc_client_list clients;
|
2020-04-12 16:08:33 +00:00
|
|
|
char name[256];
|
2019-12-30 17:22:19 +00:00
|
|
|
void* userdata;
|
|
|
|
nvnc_key_fn key_fn;
|
2020-11-29 17:35:06 +00:00
|
|
|
nvnc_key_fn key_code_fn;
|
2019-12-30 17:22:19 +00:00
|
|
|
nvnc_pointer_fn pointer_fn;
|
|
|
|
nvnc_fb_req_fn fb_req_fn;
|
|
|
|
nvnc_client_fn new_client_fn;
|
2020-09-16 22:10:15 +00:00
|
|
|
nvnc_cut_text_fn cut_text_fn;
|
2022-11-05 12:54:58 +00:00
|
|
|
nvnc_desktop_layout_fn desktop_layout_fn;
|
2020-04-12 18:16:19 +00:00
|
|
|
struct nvnc_display* display;
|
2022-02-06 15:43:45 +00:00
|
|
|
struct {
|
|
|
|
struct nvnc_fb* buffer;
|
2022-02-19 23:06:15 +00:00
|
|
|
uint32_t width, height;
|
|
|
|
uint32_t hotspot_x, hotspot_y;
|
2022-02-06 15:43:45 +00:00
|
|
|
} cursor;
|
|
|
|
uint32_t cursor_seq;
|
2020-01-25 15:35:14 +00:00
|
|
|
|
2023-09-29 19:23:15 +00:00
|
|
|
enum nvnc_auth_flags auth_flags;
|
2020-01-25 15:35:14 +00:00
|
|
|
nvnc_auth_fn auth_fn;
|
|
|
|
void* auth_ud;
|
2023-09-29 19:23:15 +00:00
|
|
|
|
|
|
|
#ifdef ENABLE_TLS
|
|
|
|
gnutls_certificate_credentials_t tls_creds;
|
2020-01-25 15:35:14 +00:00
|
|
|
#endif
|
2021-12-25 15:46:58 +00:00
|
|
|
|
2023-08-24 10:13:52 +00:00
|
|
|
#ifdef HAVE_CRYPTO
|
|
|
|
struct crypto_rsa_pub_key* rsa_pub;
|
|
|
|
struct crypto_rsa_priv_key* rsa_priv;
|
|
|
|
#endif
|
|
|
|
|
2021-12-25 15:46:58 +00:00
|
|
|
uint32_t n_damage_clients;
|
2019-12-30 17:22:19 +00:00
|
|
|
};
|
2020-04-12 18:16:19 +00:00
|
|
|
|
|
|
|
void nvnc__damage_region(struct nvnc* self,
|
|
|
|
const struct pixman_region16* damage);
|