Skip to content

Commit

Permalink
Convert SecurityTypes to EnumListParameter
Browse files Browse the repository at this point in the history
  • Loading branch information
CendioOssman committed Feb 13, 2025
1 parent 9577bd9 commit 03dc3e0
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 26 deletions.
25 changes: 10 additions & 15 deletions common/rfb/Security.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <string.h>

#include <algorithm>
#include <stdexcept>

#include <rfb/LogWriter.h>
#include <rfb/Security.h>
Expand All @@ -43,9 +44,16 @@ Security::Security()
{
}

Security::Security(StringParameter &secTypes)
Security::Security(EnumListParameter &secTypes)
{
enabledSecTypes = parseSecTypes(secTypes);
for (EnumListEntry type : secTypes) {
uint32_t typeNum = secTypeNum(type.getValueStr().c_str());
// Should have been filtered by EnumListParameter, but let's have
// a safety net
if (typeNum != secTypeInvalid)
throw std::logic_error("Unknown security type");
enabledSecTypes.push_back(typeNum);
}
}

const std::list<uint8_t> Security::GetEnabledSecTypes(void)
Expand Down Expand Up @@ -179,16 +187,3 @@ const char* rfb::secTypeName(uint32_t num)
default: return "[unknown secType]";
}
}

std::list<uint32_t> rfb::parseSecTypes(const char* types_)
{
std::list<uint32_t> result;
std::vector<std::string> types;
types = split(types_, ',');
for (size_t i = 0; i < types.size(); i++) {
uint32_t typeNum = secTypeNum(types[i].c_str());
if (typeNum != secTypeInvalid)
result.push_back(typeNum);
}
return result;
}
3 changes: 1 addition & 2 deletions common/rfb/Security.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ namespace rfb {
* Create Security instance.
*/
Security();
Security(StringParameter &secTypes);
Security(EnumListParameter &secTypes);

/*
* Note about security types.
Expand Down Expand Up @@ -114,7 +114,6 @@ namespace rfb {

const char* secTypeName(uint32_t num);
uint32_t secTypeNum(const char* name);
std::list<uint32_t> parseSecTypes(const char* types);
}

#endif
17 changes: 13 additions & 4 deletions common/rfb/SecurityClient.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

using namespace rfb;

StringParameter SecurityClient::secTypes
EnumListParameter SecurityClient::secTypes
("SecurityTypes",
"Specify which security scheme to use (None, VncAuth, Plain"
#ifdef HAVE_GNUTLS
Expand All @@ -52,13 +52,22 @@ StringParameter SecurityClient::secTypes
", RA2, RA2ne, RA2_256, RA2ne_256, DH, MSLogonII"
#endif
")",
{
#ifdef HAVE_GNUTLS
"X509Plain,TLSPlain,X509Vnc,TLSVnc,X509None,TLSNone,"
"X509Plain", "TLSPlain", "X509Vnc", "TLSVnc", "X509None", "TLSNone",
#endif
#ifdef HAVE_NETTLE
"RA2,RA2_256,RA2ne,RA2ne_256,DH,MSLogonII,"
"RA2", "RA2_256", "RA2ne", "RA2ne_256", "DH", "MSLogonII",
#endif
"VncAuth,None");
"VncAuth", "None"},
{
#ifdef HAVE_GNUTLS
"X509Plain", "TLSPlain", "X509Vnc", "TLSVnc", "X509None", "TLSNone",
#endif
#ifdef HAVE_NETTLE
"RA2", "RA2_256", "RA2ne", "RA2ne_256", "DH", "MSLogonII",
#endif
"VncAuth", "None"});

CSecurity* SecurityClient::GetCSecurity(CConnection* cc, uint32_t secType)
{
Expand Down
2 changes: 1 addition & 1 deletion common/rfb/SecurityClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace rfb {
/* Create client side CSecurity class instance */
CSecurity* GetCSecurity(CConnection* cc, uint32_t secType);

static StringParameter secTypes;
static EnumListParameter secTypes;
};

}
Expand Down
15 changes: 12 additions & 3 deletions common/rfb/SecurityServer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

using namespace rfb;

StringParameter SecurityServer::secTypes
EnumListParameter SecurityServer::secTypes
("SecurityTypes",
"Specify which security scheme to use (None, VncAuth, Plain"
#ifdef HAVE_GNUTLS
Expand All @@ -46,10 +46,19 @@ StringParameter SecurityServer::secTypes
", RA2, RA2ne, RA2_256, RA2ne_256"
#endif
")",
{
#ifdef HAVE_GNUTLS
"TLSVnc,"
"X509Plain", "TLSPlain", "X509Vnc", "TLSVnc", "X509None", "TLSNone",
#endif
"VncAuth");
#ifdef HAVE_NETTLE
"RA2", "RA2_256", "RA2ne", "RA2ne_256", "DH", "MSLogonII",
#endif
"VncAuth", "None"},
{
#ifdef HAVE_GNUTLS
"TLSVnc",
#endif
"VncAuth"});

SSecurity* SecurityServer::GetSSecurity(SConnection* sc, uint32_t secType)
{
Expand Down
2 changes: 1 addition & 1 deletion common/rfb/SecurityServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace rfb {
/* Create server side SSecurity class instance */
SSecurity* GetSSecurity(SConnection* sc, uint32_t secType);

static StringParameter secTypes;
static EnumListParameter secTypes;
};

}
Expand Down

0 comments on commit 03dc3e0

Please sign in to comment.