Compare commits
3 Commits
httpblackl
...
configchec
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
98c83cc94e | ||
|
|
a4e6343be7 | ||
|
|
2af6bbc866 |
2
.gitmodules
vendored
2
.gitmodules
vendored
@@ -1,4 +1,4 @@
|
|||||||
[submodule "kasmweb"]
|
[submodule "kasmweb"]
|
||||||
path = kasmweb
|
path = kasmweb
|
||||||
url = https://github.com/kasmtech/noVNC.git
|
url = https://github.com/kasmtech/noVNC.git
|
||||||
branch = master
|
branch = bugfix/KASM-2053_video_quality
|
||||||
|
|||||||
@@ -1,82 +0,0 @@
|
|||||||
/* Copyright (C) 2021 Kasm
|
|
||||||
*
|
|
||||||
* This is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This software is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this software; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
|
||||||
* USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
|
||||||
#include <config.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <arpa/inet.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <netinet/tcp.h>
|
|
||||||
#include <netdb.h>
|
|
||||||
#include <pthread.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <time.h>
|
|
||||||
|
|
||||||
#include <map>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#include <network/Blacklist.h>
|
|
||||||
#include <rfb/Blacklist.h>
|
|
||||||
|
|
||||||
static std::map<std::string, unsigned> hits;
|
|
||||||
static std::map<std::string, time_t> blacklist;
|
|
||||||
|
|
||||||
static pthread_mutex_t hitmutex = PTHREAD_MUTEX_INITIALIZER;
|
|
||||||
static pthread_mutex_t blmutex = PTHREAD_MUTEX_INITIALIZER;
|
|
||||||
|
|
||||||
unsigned char bl_isBlacklisted(const char *addr) {
|
|
||||||
const unsigned char count = blacklist.count(addr);
|
|
||||||
if (!count)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
const time_t now = time(NULL);
|
|
||||||
const unsigned timeout = rfb::Blacklist::initialTimeout;
|
|
||||||
|
|
||||||
if (pthread_mutex_lock(&blmutex))
|
|
||||||
abort();
|
|
||||||
|
|
||||||
if (now - timeout > blacklist[addr]) {
|
|
||||||
blacklist.erase(addr);
|
|
||||||
pthread_mutex_unlock(&blmutex);
|
|
||||||
|
|
||||||
if (pthread_mutex_lock(&hitmutex))
|
|
||||||
abort();
|
|
||||||
hits.erase(addr);
|
|
||||||
pthread_mutex_unlock(&hitmutex);
|
|
||||||
return 0;
|
|
||||||
} else {
|
|
||||||
blacklist[addr] = now;
|
|
||||||
pthread_mutex_unlock(&blmutex);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void bl_addFailure(const char *addr) {
|
|
||||||
if (pthread_mutex_lock(&hitmutex))
|
|
||||||
abort();
|
|
||||||
const unsigned num = ++hits[addr];
|
|
||||||
pthread_mutex_unlock(&hitmutex);
|
|
||||||
|
|
||||||
if (num >= (unsigned) rfb::Blacklist::threshold) {
|
|
||||||
if (pthread_mutex_lock(&blmutex))
|
|
||||||
abort();
|
|
||||||
blacklist[addr] = time(NULL);
|
|
||||||
pthread_mutex_unlock(&blmutex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
/* Copyright (C) 2021 Kasm
|
|
||||||
*
|
|
||||||
* This is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This software is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this software; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
|
||||||
* USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef __NETWORK_BLACKLIST_H__
|
|
||||||
#define __NETWORK_BLACKLIST_H__
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
unsigned char bl_isBlacklisted(const char *);
|
|
||||||
void bl_addFailure(const char *);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
} // extern C
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // __NETWORK_TCP_SOCKET_H__
|
|
||||||
@@ -2,7 +2,6 @@ include_directories(${CMAKE_SOURCE_DIR}/common ${CMAKE_SOURCE_DIR}/unix/kasmvncp
|
|||||||
|
|
||||||
set(NETWORK_SOURCES
|
set(NETWORK_SOURCES
|
||||||
GetAPIMessager.cxx
|
GetAPIMessager.cxx
|
||||||
Blacklist.cxx
|
|
||||||
Socket.cxx
|
Socket.cxx
|
||||||
TcpSocket.cxx
|
TcpSocket.cxx
|
||||||
websocket.c
|
websocket.c
|
||||||
|
|||||||
@@ -32,7 +32,6 @@
|
|||||||
#include <openssl/sha.h> /* sha1 hash */
|
#include <openssl/sha.h> /* sha1 hash */
|
||||||
#include "websocket.h"
|
#include "websocket.h"
|
||||||
#include "kasmpasswd.h"
|
#include "kasmpasswd.h"
|
||||||
#include <network/Blacklist.h>
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Global state
|
* Global state
|
||||||
@@ -1204,7 +1203,7 @@ nope:
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ws_ctx_t *do_handshake(int sock, const char *ip) {
|
ws_ctx_t *do_handshake(int sock) {
|
||||||
char handshake[4096], response[4096], sha1[29], trailer[17];
|
char handshake[4096], response[4096], sha1[29], trailer[17];
|
||||||
char *scheme, *pre;
|
char *scheme, *pre;
|
||||||
headers_t *headers;
|
headers_t *headers;
|
||||||
@@ -1272,20 +1271,10 @@ ws_ctx_t *do_handshake(int sock, const char *ip) {
|
|||||||
usleep(10);
|
usleep(10);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bl_isBlacklisted(ip)) {
|
|
||||||
wserr("IP %s is blacklisted, dropping\n", ip);
|
|
||||||
sprintf(response, "HTTP/1.1 401 Forbidden\r\n"
|
|
||||||
"\r\n");
|
|
||||||
ws_send(ws_ctx, response, strlen(response));
|
|
||||||
free_ws_ctx(ws_ctx);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned char owner = 0;
|
unsigned char owner = 0;
|
||||||
if (!settings.disablebasicauth) {
|
if (!settings.disablebasicauth) {
|
||||||
const char *hdr = strstr(handshake, "Authorization: Basic ");
|
const char *hdr = strstr(handshake, "Authorization: Basic ");
|
||||||
if (!hdr) {
|
if (!hdr) {
|
||||||
bl_addFailure(ip);
|
|
||||||
handler_emsg("BasicAuth required, but client didn't send any. 401 Unauth\n");
|
handler_emsg("BasicAuth required, but client didn't send any. 401 Unauth\n");
|
||||||
sprintf(response, "HTTP/1.1 401 Unauthorized\r\n"
|
sprintf(response, "HTTP/1.1 401 Unauthorized\r\n"
|
||||||
"WWW-Authenticate: Basic realm=\"Websockify\"\r\n"
|
"WWW-Authenticate: Basic realm=\"Websockify\"\r\n"
|
||||||
@@ -1299,7 +1288,6 @@ ws_ctx_t *do_handshake(int sock, const char *ip) {
|
|||||||
const char *end = strchr(hdr, '\r');
|
const char *end = strchr(hdr, '\r');
|
||||||
if (!end || end - hdr > 256) {
|
if (!end || end - hdr > 256) {
|
||||||
handler_emsg("Client sent invalid BasicAuth, dropping connection\n");
|
handler_emsg("Client sent invalid BasicAuth, dropping connection\n");
|
||||||
bl_addFailure(ip);
|
|
||||||
free_ws_ctx(ws_ctx);
|
free_ws_ctx(ws_ctx);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -1369,7 +1357,6 @@ ws_ctx_t *do_handshake(int sock, const char *ip) {
|
|||||||
|
|
||||||
if (len <= 0 || strcmp(authbuf, response)) {
|
if (len <= 0 || strcmp(authbuf, response)) {
|
||||||
handler_emsg("BasicAuth user/pw did not match\n");
|
handler_emsg("BasicAuth user/pw did not match\n");
|
||||||
bl_addFailure(ip);
|
|
||||||
sprintf(response, "HTTP/1.1 401 Forbidden\r\n"
|
sprintf(response, "HTTP/1.1 401 Forbidden\r\n"
|
||||||
"\r\n");
|
"\r\n");
|
||||||
ws_send(ws_ctx, response, strlen(response));
|
ws_send(ws_ctx, response, strlen(response));
|
||||||
@@ -1458,7 +1445,7 @@ void *subthread(void *ptr) {
|
|||||||
|
|
||||||
ws_ctx_t *ws_ctx;
|
ws_ctx_t *ws_ctx;
|
||||||
|
|
||||||
ws_ctx = do_handshake(csock, pass->ip);
|
ws_ctx = do_handshake(csock);
|
||||||
if (ws_ctx == NULL) {
|
if (ws_ctx == NULL) {
|
||||||
handler_msg("No connection after handshake\n");
|
handler_msg("No connection after handshake\n");
|
||||||
goto out; // Child process exits
|
goto out; // Child process exits
|
||||||
|
|||||||
@@ -211,7 +211,7 @@ void ConnParams::setEncodings(int nEncodings, const rdr::S32* encodings)
|
|||||||
break;
|
break;
|
||||||
case pseudoEncodingPreferBandwidth:
|
case pseudoEncodingPreferBandwidth:
|
||||||
if (!rfb::Server::ignoreClientSettingsKasm && canChangeSettings)
|
if (!rfb::Server::ignoreClientSettingsKasm && canChangeSettings)
|
||||||
Server::preferBandwidth.setParam();
|
Server::preferBandwidth.setParam(true);
|
||||||
break;
|
break;
|
||||||
case pseudoEncodingMaxVideoResolution:
|
case pseudoEncodingMaxVideoResolution:
|
||||||
if (!rfb::Server::ignoreClientSettingsKasm && canChangeSettings)
|
if (!rfb::Server::ignoreClientSettingsKasm && canChangeSettings)
|
||||||
|
|||||||
@@ -356,6 +356,13 @@ void EncodeManager::doUpdate(bool allowLossy, const Region& changed_,
|
|||||||
if (conn->cp.kasmPassed[ConnParams::KASM_MAX_VIDEO_RESOLUTION])
|
if (conn->cp.kasmPassed[ConnParams::KASM_MAX_VIDEO_RESOLUTION])
|
||||||
updateMaxVideoRes(&maxVideoX, &maxVideoY);
|
updateMaxVideoRes(&maxVideoX, &maxVideoY);
|
||||||
|
|
||||||
|
// The dynamic quality params may have changed
|
||||||
|
if (Server::dynamicQualityMax && Server::dynamicQualityMax <= 9 &&
|
||||||
|
Server::dynamicQualityMax > Server::dynamicQualityMin) {
|
||||||
|
dynamicQualityMin = Server::dynamicQualityMin;
|
||||||
|
dynamicQualityOff = Server::dynamicQualityMax - Server::dynamicQualityMin;
|
||||||
|
}
|
||||||
|
|
||||||
prepareEncoders(allowLossy);
|
prepareEncoders(allowLossy);
|
||||||
|
|
||||||
changed = changed_;
|
changed = changed_;
|
||||||
|
|||||||
2
kasmweb
2
kasmweb
Submodule kasmweb updated: 9383783efd...1adce75ee1
Reference in New Issue
Block a user