Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into custom-socket-io
Browse files Browse the repository at this point in the history
  • Loading branch information
tobydox committed Mar 4, 2022
2 parents 1c7fd8c + a7671ad commit b36c293
Show file tree
Hide file tree
Showing 14 changed files with 215 additions and 53 deletions.
116 changes: 83 additions & 33 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ option(WITH_24BPP "Allow 24 bpp" ON)
option(WITH_IPv6 "Enable IPv6 Support" ON)
option(WITH_WEBSOCKETS "Build with websockets support" ON)
option(WITH_SASL "Build with SASL support" ON)
option(WITH_EXAMPLES "Build examples" ON)
option(WITH_TESTS "Build tests" ON)



Expand Down Expand Up @@ -210,6 +212,7 @@ check_function_exists(strerror LIBVNCSERVER_HAVE_STRERROR)
check_function_exists(strstr LIBVNCSERVER_HAVE_STRSTR)

check_symbol_exists(htobe64 "endian.h" LIBVNCSERVER_HAVE_HTOBE64)
check_symbol_exists(htobe64 "sys/endian.h" LIBVNCSERVER_HAVE_HTOBE64)
check_symbol_exists(OSSwapHostToBigInt64 "libkern/OSByteOrder.h" LIBVNCSERVER_HAVE_OSSWAPHOSTTOBIGINT64)

if(WITH_THREADS AND Threads_FOUND)
Expand Down Expand Up @@ -604,26 +607,28 @@ if(FFMPEG_FOUND)
)
endif(FFMPEG_FOUND)


foreach(e ${LIBVNCSERVER_EXAMPLES})
add_executable(examples_${e} ${LIBVNCSRVEXAMPLE_DIR}/${e}.c)
set_target_properties(examples_${e} PROPERTIES OUTPUT_NAME ${e})
set_target_properties(examples_${e} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/examples)
target_link_libraries(examples_${e} vncserver ${CMAKE_THREAD_LIBS_INIT} ${CARBON_LIBRARY} ${IOKIT_LIBRARY} ${IOSURFACE_LIBRARY})
endforeach(e ${LIBVNCSERVER_EXAMPLES})

foreach(e ${LIBVNCCLIENT_EXAMPLES})
add_executable(client_examples_${e} ${LIBVNCCLIEXAMPLE_DIR}/${e}.c ${LIBVNCCLIEXAMPLE_DIR}/${${e}_EXTRA_SOURCES} )
set_target_properties(client_examples_${e} PROPERTIES OUTPUT_NAME ${e})
set_target_properties(client_examples_${e} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/client_examples)
target_link_libraries(client_examples_${e} vncclient ${CMAKE_THREAD_LIBS_INIT} ${SDL2_LIBRARY} ${GTK2_LIBRARIES} ${FFMPEG_LIBRARIES})
endforeach(e ${LIBVNCCLIENT_EXAMPLES})

if(WITH_EXAMPLES)
foreach(e ${LIBVNCSERVER_EXAMPLES})
add_executable(examples_${e} ${LIBVNCSRVEXAMPLE_DIR}/${e}.c)
set_target_properties(examples_${e} PROPERTIES OUTPUT_NAME ${e})
set_target_properties(examples_${e} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/examples)
target_link_libraries(examples_${e} vncserver ${CMAKE_THREAD_LIBS_INIT} ${CARBON_LIBRARY} ${IOKIT_LIBRARY} ${IOSURFACE_LIBRARY})
endforeach(e ${LIBVNCSERVER_EXAMPLES})

foreach(e ${LIBVNCCLIENT_EXAMPLES})
add_executable(client_examples_${e} ${LIBVNCCLIEXAMPLE_DIR}/${e}.c ${LIBVNCCLIEXAMPLE_DIR}/${${e}_EXTRA_SOURCES} )
set_target_properties(client_examples_${e} PROPERTIES OUTPUT_NAME ${e})
set_target_properties(client_examples_${e} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/client_examples)
target_link_libraries(client_examples_${e} vncclient ${CMAKE_THREAD_LIBS_INIT} ${SDL2_LIBRARY} ${GTK2_LIBRARIES} ${FFMPEG_LIBRARIES})
endforeach(e ${LIBVNCCLIENT_EXAMPLES})
endif(WITH_EXAMPLES)

#
# them tests
#

if(WITH_TESTS)

if(UNIX)
set(ADDITIONAL_TEST_LIBS m)
endif(UNIX)
Expand Down Expand Up @@ -695,6 +700,8 @@ if(LIBVNCSERVER_WITH_WEBSOCKETS)
add_test(NAME wstest COMMAND test_wstest)
endif(LIBVNCSERVER_WITH_WEBSOCKETS)

endif(WITH_TESTS)

#
# this gets the libraries needed by TARGET in "-libx -liby ..." form
#
Expand Down Expand Up @@ -724,22 +731,65 @@ get_link_libraries(PRIVATE_LIBS vncclient)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libvncclient.pc.cmakein ${CMAKE_CURRENT_BINARY_DIR}/libvncclient.pc @ONLY)

if(LIBVNCSERVER_INSTALL)
install(TARGETS vncserver DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(TARGETS vncclient DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(FILES
rfb/keysym.h
rfb/threading.h
rfb/rfb.h
rfb/rfbclient.h
${CMAKE_CURRENT_BINARY_DIR}/rfb/rfbconfig.h
rfb/rfbproto.h
rfb/rfbregion.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/rfb
)

install(FILES
${CMAKE_CURRENT_BINARY_DIR}/libvncserver.pc
${CMAKE_CURRENT_BINARY_DIR}/libvncclient.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
)
set(INSTALL_HEADER_FILES
rfb/keysym.h
rfb/threading.h
rfb/rfb.h
rfb/rfbclient.h
${CMAKE_CURRENT_BINARY_DIR}/rfb/rfbconfig.h
rfb/rfbproto.h
rfb/rfbregion.h
)

set_property(TARGET vncclient PROPERTY PUBLIC_HEADER ${INSTALL_HEADER_FILES})
set_property(TARGET vncserver PROPERTY PUBLIC_HEADER ${INSTALL_HEADER_FILES})
if(WIN32)
INSTALL(TARGETS vncclient vncserver
EXPORT LibVNCServerTargets
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
LIBRARY DESTINATION "${CMAKE_INSTALL_BINDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/rfb
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
else()
INSTALL(TARGETS vncclient vncserver
EXPORT LibVNCServerTargets
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/rfb
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
endif()

# Install cmake configure files
install(EXPORT LibVNCServerTargets
NAMESPACE
"LibVNCServer::"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/LibVNCServer"
)

include(CMakePackageConfigHelpers)
configure_package_config_file(
${PROJECT_SOURCE_DIR}/cmake/Modules/LibVNCServerConfig.cmake.in
${CMAKE_BINARY_DIR}/LibVNCServerConfig.cmake
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/LibVNCServer"
)
# Install cmake version configure file
write_basic_package_version_file(
"${CMAKE_BINARY_DIR}/LibVNCServerConfigVersion.cmake"
VERSION ${PARA_VERSION}
COMPATIBILITY AnyNewerVersion)
install(FILES
"${CMAKE_BINARY_DIR}/LibVNCServerConfigVersion.cmake"
"${CMAKE_BINARY_DIR}/LibVNCServerConfig.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/LibVNCServer")


install(FILES
${CMAKE_CURRENT_BINARY_DIR}/libvncserver.pc
${CMAKE_CURRENT_BINARY_DIR}/libvncclient.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
)
endif()
17 changes: 17 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Pull Requests

* Make sure you only include relevant changes in your commit(s). In particular, don't re-format
whole source files as those indentation changes add a lot of unrelated changes to your commit.

* Make your commits as [atomic as possible](https://www.freshconsulting.com/atomic-commits/).
* Fundamental question 1: what could we need to revert later?
* Fundamental question 2: what could we need to cherry-pick?
* Fundamental question 3: is there an _and_ in the commit message? -> split it!

* Adhere to the commit message [guidelines](https://chris.beams.io/posts/git-commit/):
* Start with the module you are changing, ended with a ':'. Common ones used here are "CMake:"
or "examples:" or "libvncclient:", but there are more! A good way to find common module
descriptions is to look into the git history of the project.
* Keep the commit message short and in the form of "When applied, this commit will ' `<your commit message>`
* Do _not_ end the subject line with a '.'.
* Example: `warpdrive: increase fuel capacity to 100k`
27 changes: 26 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![Build Status](https://travis-ci.org/LibVNC/libvncserver.svg?branch=master)](https://travis-ci.org/LibVNC/libvncserver)
[![Build Status](https://app.travis-ci.com/LibVNC/libvncserver.svg?branch=master)](https://app.travis-ci.com/LibVNC/libvncserver)
[![Build status](https://ci.appveyor.com/api/projects/status/fao6m1md3q4g2bwn/branch/master?svg=true)](https://ci.appveyor.com/project/bk138/libvncserver/branch/master)
[![Help making this possible](https://img.shields.io/badge/liberapay-donate-yellow.png)](https://liberapay.com/LibVNC/donate) [![Join the chat at https://gitter.im/LibVNC/libvncserver](https://badges.gitter.im/LibVNC/libvncserver.svg)](https://gitter.im/LibVNC/libvncserver?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

Expand Down Expand Up @@ -40,6 +40,7 @@ RFB Protocol Support Status
|Apple ARD | 30 | ||
|TLS | 18 | ||
|VeNCrypt | 19 | ||
|UltraVNC MSLogonII | 113 | ||

## [Encodings](https://github.com/rfbproto/rfbproto/blob/master/rfbproto.rst#76encodings)

Expand Down Expand Up @@ -131,6 +132,30 @@ In case you prefer to learn LibVNCServer by example, have a look at the servers

For LibVNCClient, examples can be found in [client_examples](client_examples).

Incorporating LibVNCServer/LibVNCClient into your build system
--------------------------------------------------------------

The install process installs [pkg-config](https://www.freedesktop.org/wiki/Software/pkg-config/)
.pc files for LibVNCServer as well as LibVNCClient which you can use in your build
system via the usual `pkg-config --cflags libvncserver` et al.

If using CMake, LibVNCServer versions > 0.9.13 provide CMake configure files so
in your project's CMakeLists.txt, you can say:

```cmake
find_package(LibVNCServer)
if(LibVNCServer_FOUND)
# libs and headers location are now accessible via properties, but you only
# need to add the respective export target to your project's target_link_libraries,
# cmake will automatically add libs and headers
# eg: add client (YOUR_PROJECT_TARGET being a placeholder for your real target -
# it must be defined by add_executable or add_library):
target_link_libraries(YOUR_PROJECT_TARGET LibVNCServer::vncclient)
# add server:
target_link_libraries(YOUR_PROJECT_TARGET LibVNCServer::vncserver)
endif()
```

Using Websockets
----------------

Expand Down
8 changes: 8 additions & 0 deletions cmake/Modules/LibVNCServerConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@PACKAGE_INIT@

include("${CMAKE_CURRENT_LIST_DIR}/LibVNCServerTargets.cmake")
check_required_components(
vncclient
vncserver
)

60 changes: 59 additions & 1 deletion libvncclient/rfbproto.c
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ ReadSupportedSecurityType(rfbClient* client, uint32_t *result, rfbBool subAuth)
#ifdef LIBVNCSERVER_HAVE_SASL
tAuth[loop]==rfbSASL ||
#endif /* LIBVNCSERVER_HAVE_SASL */
(tAuth[loop]==rfbARD && client->GetCredential))
((tAuth[loop]==rfbARD || tAuth[loop]==rfbUltraMSLogonII) && client->GetCredential))
{
if (!subAuth && client->clientAuthSchemes)
{
Expand Down Expand Up @@ -685,6 +685,60 @@ rfbPowM64(uint64_t b, uint64_t e, uint64_t m)
return r;
}

static rfbBool
HandleUltraMSLogonIIAuth(rfbClient *client)
{
uint8_t gen[8], mod[8], resp[8], pub[8], priv[8];
uint8_t username[256], password[64], key[8];
rfbCredential *cred;

if (!ReadFromRFBServer(client, (char *)gen, sizeof(gen))) return FALSE;
if (!ReadFromRFBServer(client, (char *)mod, sizeof(mod))) return FALSE;
if (!ReadFromRFBServer(client, (char *)resp, sizeof(resp))) return FALSE;

if(!dh_generate_keypair(priv, pub, gen, sizeof(gen), mod, sizeof(priv))) {
rfbClientErr("HandleUltraMSLogonIIAuth: generating keypair failed\n");
return FALSE;
}

if(!dh_compute_shared_key(key, priv, resp, mod, sizeof(key))) {
rfbClientErr("HandleUltraMSLogonIIAuth: creating shared key failed\n");
return FALSE;
}

if (!client->GetCredential)
{
rfbClientLog("GetCredential callback is not set.\n");
return FALSE;
}
rfbClientLog("WARNING! MSLogon security type has very low password encryption! "\
"Use it only with SSH tunnel or trusted network.\n");
cred = client->GetCredential(client, rfbCredentialTypeUser);
if (!cred)
{
rfbClientLog("Reading credential failed\n");
return FALSE;
}

memset(username, 0, sizeof(username));
strncpy((char *)username, cred->userCredential.username, sizeof(username)-1);
memset(password, 0, sizeof(password));
strncpy((char *)password, cred->userCredential.password, sizeof(password)-1);
FreeUserCredential(cred);

rfbClientEncryptBytes2(username, sizeof(username), (unsigned char *)key);
rfbClientEncryptBytes2(password, sizeof(password), (unsigned char *)key);

if (!WriteToRFBServer(client, (char *)pub, sizeof(pub))) return FALSE;
if (!WriteToRFBServer(client, (char *)username, sizeof(username))) return FALSE;
if (!WriteToRFBServer(client, (char *)password, sizeof(password))) return FALSE;

/* Handle the SecurityResult message */
if (!rfbHandleAuthResult(client)) return FALSE;

return TRUE;
}

static rfbBool
HandleMSLogonAuth(rfbClient *client)
{
Expand Down Expand Up @@ -1008,6 +1062,10 @@ InitialiseRFBConnection(rfbClient* client)
break;
#endif /* LIBVNCSERVER_HAVE_SASL */

case rfbUltraMSLogonII:
if (!HandleUltraMSLogonIIAuth(client)) return FALSE;
break;

case rfbMSLogon:
if (!HandleMSLogonAuth(client)) return FALSE;
break;
Expand Down
4 changes: 2 additions & 2 deletions libvncclient/tls_openssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,8 @@ open_ssl_connection (rfbClient *client, int sockfd, rfbBool anonTLS, rfbCredenti
SSL_CTX_set1_param(ssl_ctx, param);
SSL_CTX_set_cipher_list(ssl_ctx, "ALL");
} else { /* anonTLS here */
/* Need ADH cipher for anonTLS, see https://github.com/LibVNC/libvncserver/issues/347#issuecomment-597477103 */
SSL_CTX_set_cipher_list(ssl_ctx, "ADH");
/* Need anonymous ciphers for anonTLS, see https://github.com/LibVNC/libvncserver/issues/347#issuecomment-597477103 */
SSL_CTX_set_cipher_list(ssl_ctx, "aNULL");
#if OPENSSL_VERSION_NUMBER >= 0x10100000L && !defined LIBRESSL_VERSION_NUMBER
/*
See https://www.openssl.org/docs/man1.1.0/man3/SSL_set_security_level.html
Expand Down
4 changes: 2 additions & 2 deletions libvncserver/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ rfbUnregisterProtocolExtension(rfbProtocolExtension* extension)
rfbUnregisterProtocolExtension(extension->next);
}

rfbProtocolExtension* rfbGetExtensionIterator()
rfbProtocolExtension* rfbGetExtensionIterator(void)
{
if (! extMutex_initialized) {
INIT_MUTEX(extMutex);
Expand All @@ -156,7 +156,7 @@ rfbProtocolExtension* rfbGetExtensionIterator()
return rfbExtensionHead;
}

void rfbReleaseExtensionIterator()
void rfbReleaseExtensionIterator(void)
{
UNLOCK(extMutex);
}
Expand Down
4 changes: 3 additions & 1 deletion libvncserver/rfbssl_gnutls.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ int rfbssl_init(rfbClientPtr cl)
if (!(keyfile = cl->screen->sslkeyfile))
keyfile = cl->screen->sslcertfile;

if (NULL == (ctx = rfbssl_init_global(keyfile, cl->screen->sslcertfile))) {
if (!cl->screen->sslcertfile || !cl->screen->sslcertfile[0]) {
rfbErr("SSL connection but no cert specified\n");
} else if (NULL == (ctx = rfbssl_init_global(keyfile, cl->screen->sslcertfile))) {
/* */
} else if (GNUTLS_E_SUCCESS != (ret = rfbssl_init_session(ctx, cl->sock))) {
/* */
Expand Down
4 changes: 2 additions & 2 deletions libvncserver/tightvnc-filetransfer/rfbtightserver.c
Original file line number Diff line number Diff line change
Expand Up @@ -536,13 +536,13 @@ static rfbSecurityHandler tightVncSecurityHandler = {
NULL
};

void rfbRegisterTightVNCFileTransferExtension() {
void rfbRegisterTightVNCFileTransferExtension(void) {
rfbRegisterProtocolExtension(&tightVncFileTransferExtension);
rfbRegisterSecurityHandler(&tightVncSecurityHandler);
}

void
rfbUnregisterTightVNCFileTransferExtension() {
rfbUnregisterTightVNCFileTransferExtension(void) {
rfbUnregisterProtocolExtension(&tightVncFileTransferExtension);
rfbUnregisterSecurityHandler(&tightVncSecurityHandler);
}
Expand Down
6 changes: 0 additions & 6 deletions libvncserver/websockets.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,6 @@
/* errno */
#include <errno.h>

#ifdef LIBVNCSERVER_HAVE_ENDIAN_H
#include <endian.h>
#elif LIBVNCSERVER_HAVE_SYS_ENDIAN_H
#include <sys/endian.h>
#endif

#ifdef LIBVNCSERVER_HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
Expand Down
6 changes: 6 additions & 0 deletions libvncserver/ws_decode.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@

#else

#ifdef LIBVNCSERVER_HAVE_ENDIAN_H
#include <endian.h>
#elif LIBVNCSERVER_HAVE_SYS_ENDIAN_H
#include <sys/endian.h>
#endif

#define WS_NTOH64(n) htobe64(n)
#define WS_NTOH32(n) htobe32(n)
#define WS_NTOH16(n) htobe16(n)
Expand Down
Loading

0 comments on commit b36c293

Please sign in to comment.