Skip to content

Commit

Permalink
v9.28.10
Browse files Browse the repository at this point in the history
[会话管理]优化在保存会话时,主动删除旧的会话。
[会话管理]优化会话连表时极速定位时,上下键快速选择及回车键连接。
[VNC]增加加密连接,支持Ubuntu/Centos等gnome桌面内置桌面连接。
[VNC]修复连接非WoVNCServer时,会话参数不匹配时所导致的崩溃。

[Session Management] Optimize for actively deleting old sessions when saving them.
[Session Management] When optimizing session table connection for fast positioning, use up and down keys to quickly select and enter keys to connect.
[VNC] Add encrypted connections and support built-in desktop connections for gnome desktops such as Ubuntu/Centos.
[VNC] Fix crash caused by session parameter mismatch when connecting to non WoVNCServer.
  • Loading branch information
getwingm committed Sep 11, 2023
1 parent af38114 commit a4e80a3
Show file tree
Hide file tree
Showing 21 changed files with 691 additions and 285 deletions.
2 changes: 2 additions & 0 deletions kxutil/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ set(SOURCE_FILES
qkxlengthbodypacket.cpp
qkxkeepwakeup.cpp
qkxprocesslaunch.cpp
qkxopensslthreadcryptosafety.cpp
)

set(HEADER_FILES
Expand All @@ -54,6 +55,7 @@ set(HEADER_FILES
qkxlengthbodypacket.h
qkxkeepwakeup.h
qkxprocesslaunch.h
qkxopensslthreadcryptosafety.h
)

if(WIN32)
Expand Down
155 changes: 155 additions & 0 deletions kxutil/qkxopensslthreadcryptosafety.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
/*******************************************************************************************
*
* Copyright (C) 2023 Guangzhou AoYiDuo Network Technology Co.,Ltd. All Rights Reserved.
*
* Contact: http://www.aoyiduo.com
*
* this file is used under the terms of the GPLv3[GNU GENERAL PUBLIC LICENSE v3]
* more information follow the website: https://www.gnu.org/licenses/gpl-3.0.en.html
*
*******************************************************************************************/

#include "qkxopensslthreadcryptosafety.h"

#include <QCoreApplication>

#ifdef Q_OS_WIN
#include <windows.h>
#else
#include <unistd.h>
#include <sys/types.h>
#include <errno.h>
#endif

#include <openssl/err.h>
#include <openssl/ssl.h>
#include <openssl/x509.h>
#include <openssl/rand.h>


int THREAD_setup(void);

int THREAD_cleanup(void);

#if defined(WIN32)
#define MUTEX_TYPE HANDLE
#define MUTEX_SETUP(x) (x= CreateMutex(NULL, FALSE, NULL))
#define MUTEX_CLEANUP(x) (CloseHandle(x))
#define MUTEX_LOCK(x) (WaitForSingleObject((x), INFINITE))
#define MUTEX_UNLOCK(x) (ReleaseMutex(x))
#define THREAD_ID (GetCurrentThreadId())
#else
#define MUTEX_TYPE pthread_mutex_t
#define MUTEX_SETUP(x) (pthread_mutex_init(&(x), NULL))
#define MUTEX_CLEANUP(x) (pthread_mutex_destroy(&(x)))
#define MUTEX_LOCK(x) (pthread_mutex_lock(&(x)))
#define MUTEX_UNLOCK(x) (pthread_mutex_unlock(&(x)))
#define THREAD_ID (pthread_self())
#endif

static MUTEX_TYPE *mutex_buf = NULL;

struct CRYPTO_dynlock_value
{
MUTEX_TYPE mutex;
};

static void locking_function(int mode, int n, const char * file, int line)
{
if (mode & CRYPTO_LOCK){
MUTEX_LOCK(mutex_buf[n]);
} else {
MUTEX_UNLOCK(mutex_buf[n]);
}
}

static unsigned long id_function(void)
{
return ((unsigned long)THREAD_ID);
}

static struct CRYPTO_dynlock_value *dyn_create_function(const char *file, int line)
{
struct CRYPTO_dynlock_value *value = (struct CRYPTO_dynlock_value *)malloc(sizeof(struct CRYPTO_dynlock_value));
if (!value){
return NULL;
}
MUTEX_SETUP(value->mutex);
return value;
}

static void dyn_lock_function(int mode, struct CRYPTO_dynlock_value *l, const char *file, int line)
{
if (mode & CRYPTO_LOCK) {
MUTEX_LOCK(l->mutex);
}else{
MUTEX_UNLOCK(l->mutex);
}
}

static void dyn_destroy_function(struct CRYPTO_dynlock_value *l, const char *file, int line)
{
MUTEX_CLEANUP(l->mutex);
free(l);
}


int THREAD_setup(void)
{
int i;
mutex_buf = (MUTEX_TYPE *)malloc(CRYPTO_num_locks() * sizeof(MUTEX_TYPE));
if (!mutex_buf){
return 0;
}
for(i = 0; i < CRYPTO_num_locks(); i++){
MUTEX_SETUP(mutex_buf[i]);
}
CRYPTO_set_id_callback(id_function);
CRYPTO_set_locking_callback(locking_function);
CRYPTO_set_dynlock_create_callback(dyn_create_function);
CRYPTO_set_dynlock_lock_callback(dyn_lock_function);
CRYPTO_set_dynlock_destroy_callback(dyn_destroy_function);
return 1;
}

int THREAD_cleanup(void)
{
int i;
if (!mutex_buf){
return 0;
}
CRYPTO_set_id_callback(NULL);
CRYPTO_set_locking_callback(NULL);
CRYPTO_set_dynlock_create_callback(NULL);
CRYPTO_set_dynlock_lock_callback(NULL);
CRYPTO_set_dynlock_destroy_callback(NULL);
for(i = 0; i < CRYPTO_num_locks(); i++){
MUTEX_CLEANUP(mutex_buf[i]);
}
free(mutex_buf);
mutex_buf = NULL;
return 1;
}

bool QKxOpenSSLThreadCryptoSafety::init()
{
qFatal("openssl > 1.1, do not do this safety.\r\n < 1.1, the qt network had alreay do this and you should not do again");
static bool hasInit = false;
if(hasInit) {
return true;
}
int err = THREAD_setup();
hasInit = true;
return err > 0;
}

void QKxOpenSSLThreadCryptoSafety::cleanup()
{
static bool hasRelease = false;
if(hasRelease) {
return;
}
THREAD_cleanup();
hasRelease = true;
}

44 changes: 44 additions & 0 deletions kxutil/qkxopensslthreadcryptosafety.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*******************************************************************************************
*
* Copyright (C) 2023 Guangzhou AoYiDuo Network Technology Co.,Ltd. All Rights Reserved.
*
* Contact: http://www.aoyiduo.com
*
* this file is used under the terms of the GPLv3[GNU GENERAL PUBLIC LICENSE v3]
* more information follow the website: https://www.gnu.org/licenses/gpl-3.0.en.html
*
*******************************************************************************************/

#ifndef QKXOPENSSLTHREADCRYPTOSAFETY_H
#define QKXOPENSSLTHREADCRYPTOSAFETY_H

#include "qkxutil_share.h"

#include <QObject>


/***
*
*
*
*
* openssl > 1.1, do not do this safety.
* < 1.1, the qt network had alreay do this and you should not do again.
*
*
*
*
*
*
*
*
*/
// RSA Crypto need to init thread safety.
class KXUTIL_EXPORT QKxOpenSSLThreadCryptoSafety
{
public:
static bool init();
static void cleanup();
};

#endif // QKXOPENSSLTHREADCRYPTOSAFETY_H
41 changes: 39 additions & 2 deletions kxvnc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ endif()

add_definitions(-DQKXVNC_LIBRARY)

find_package(Qt5 COMPONENTS Core Gui Widgets REQUIRED)
find_package(Qt5 COMPONENTS Core Gui Network Widgets REQUIRED)

message("ZLIB_ROOT_DIR:${ZLIB_ROOT_DIR}")
message("OPENSSL_ROOT_DIR:${OPENSSL_ROOT_DIR}")
Expand Down Expand Up @@ -121,6 +121,16 @@ if(WIN32)
set_target_properties(jpeg_main PROPERTIES IMPORTED_LOCATION
${LIBJPEG_ROOT_DIR}/lib/turbojpeg-static.lib)
link_libraries(jpeg_main)

add_library(openssl_crypto STATIC IMPORTED)
set_target_properties(openssl_crypto PROPERTIES IMPORTED_LOCATION
${OPENSSL_ROOT_DIR}/lib/libcrypto.lib)
link_libraries(openssl_crypto)

add_library(openssl_ssl STATIC IMPORTED)
set_target_properties(openssl_ssl PROPERTIES IMPORTED_LOCATION
${OPENSSL_ROOT_DIR}/lib/libssl.lib)
link_libraries(openssl_ssl)
elseif(APPLE)
message("APPLE Here")
set(ZLIB_LIBRARY libz.a)
Expand Down Expand Up @@ -151,6 +161,15 @@ elseif(APPLE)
${LIBJPEG_ROOT_DIR}/lib/libturbojpeg.a)
link_libraries(jpeg_main pthread)

add_library(openssl_crypto STATIC IMPORTED)
set_target_properties(openssl_crypto PROPERTIES IMPORTED_LOCATION ${OPENSSL_ROOT_DIR}/lib/libcrypto.dylib)
link_libraries(openssl_crypto)

add_library(openssl_ssl STATIC IMPORTED)
set_target_properties(openssl_ssl PROPERTIES IMPORTED_LOCATION
${OPENSSL_ROOT_DIR}/lib/libssl.dylib)
link_libraries(openssl_ssl)

find_library(COREAUDIO_LIBRARY CoreAudio REQUIRED)
find_library(AUDIOTOOLBOX_LIBRARY AudioToolbox REQUIRED)
find_library(AUDIOUNIT_LIBRARY AudioUnit REQUIRED)
Expand Down Expand Up @@ -191,6 +210,15 @@ elseif(ANDROID)
set_target_properties(jpeg_main PROPERTIES IMPORTED_LOCATION
${LIBJPEG_ROOT_DIR}/lib/libturbojpeg.so)
link_libraries(jpeg_main)

add_library(openssl_crypto SHARED IMPORTED)
set_target_properties(openssl_crypto PROPERTIES IMPORTED_LOCATION ${OPENSSL_ROOT_DIR}/lib/libcrypto.so)
link_libraries(openssl_crypto)

add_library(openssl_ssl SHARED IMPORTED)
set_target_properties(openssl_ssl PROPERTIES IMPORTED_LOCATION
${OPENSSL_ROOT_DIR}/lib/libssl.so)
link_libraries(openssl_ssl)
else()
message("other")
set(ZLIB_LIBRARY libz.a)
Expand Down Expand Up @@ -220,11 +248,20 @@ else()
set_target_properties(jpeg_main PROPERTIES IMPORTED_LOCATION
${LIBJPEG_ROOT_DIR}/lib/libturbojpeg.a)
link_libraries(jpeg_main pthread)

add_library(openssl_crypto SHARED IMPORTED)
set_target_properties(openssl_crypto PROPERTIES IMPORTED_LOCATION ${OPENSSL_ROOT_DIR}/lib/libcrypto.so)
link_libraries(openssl_crypto)

add_library(openssl_ssl SHARED IMPORTED)
set_target_properties(openssl_ssl PROPERTIES IMPORTED_LOCATION
${OPENSSL_ROOT_DIR}/lib/libssl.so)
link_libraries(openssl_ssl)
endif()

add_library(${PROJECT_NAME} SHARED ${SOURCE_FILES} ${HEADER_FILES} ${OTHER_FILES})
target_compile_definitions(${PROJECT_NAME} PRIVATE $<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:QT_QML_DEBUG>)
target_link_libraries(${PROJECT_NAME} Qt5::Core Qt5::Gui Qt5::Widgets)
target_link_libraries(${PROJECT_NAME} Qt5::Core Qt5::Network Qt5::Gui Qt5::Widgets)

install(TARGETS ${PROJECT_NAME}
RUNTIME DESTINATION ${RUNTIME_OUTPUT_DIRECTORY}
Expand Down
7 changes: 6 additions & 1 deletion kxvnc/qkxreader.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,15 @@
#define QKXREADER_H

#include <QByteArray>
#include <QObject>

class QKxReader
class QKxReader : public QObject
{
public:
explicit QKxReader(QObject *parent = nullptr)
: QObject(parent){

}
virtual QByteArray readArray(int timeout = 10000) = 0;
virtual qint32 readInt32(int timeout = 10000) = 0;
virtual quint32 readUint32(int timeout = 10000) = 0;
Expand Down
Loading

0 comments on commit a4e80a3

Please sign in to comment.