Skip to content

Commit 643bb4c

Browse files
committed
libvncclient: prepare security type selection for ARD auth variants
1 parent 687954c commit 643bb4c

1 file changed

Lines changed: 44 additions & 13 deletions

File tree

src/libvncclient/rfbclient.c

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,28 @@ rfbClientLogProc rfbClientErr=rfbDefaultClientLog;
102102

103103
rfbClientProtocolExtension* rfbClientExtensions = NULL;
104104

105+
static rfbBool
106+
SupportsARDAuthScheme(uint8_t authScheme)
107+
{
108+
switch (authScheme) {
109+
case rfbARDAuthDH:
110+
return TRUE;
111+
#if defined(__APPLE__)
112+
case rfbARDAuthKerberosGSSAPI:
113+
return TRUE;
114+
#if defined(__has_include)
115+
#if __has_include(<openssl/bn.h>)
116+
case rfbARDAuthRSASRP:
117+
case rfbARDAuthDirectSRP:
118+
return TRUE;
119+
#endif
120+
#endif
121+
#endif
122+
default:
123+
return FALSE;
124+
}
125+
}
126+
105127
void rfbClientRegisterExtension(rfbClientProtocolExtension* e)
106128
{
107129
e->next = rfbClientExtensions;
@@ -465,12 +487,14 @@ ReadSupportedSecurityType(rfbClient* client, uint32_t *result, rfbBool subAuth)
465487
{
466488
uint8_t count=0;
467489
uint8_t loop=0;
468-
uint8_t flag=0;
490+
uint8_t selectedLoop=0;
469491
rfbBool extAuthHandler;
470492
uint8_t tAuth[256];
471493
char buf1[500],buf2[10];
472494
uint32_t authScheme;
473495
rfbClientProtocolExtension* e;
496+
rfbBool selected=FALSE;
497+
int selectedPriority=-1;
474498

475499
if (!ReadFromRFBServer(client, (char *)&count, 1)) return FALSE;
476500

@@ -500,7 +524,6 @@ ReadSupportedSecurityType(rfbClient* client, uint32_t *result, rfbBool subAuth)
500524
break;
501525
}
502526

503-
if (flag) continue;
504527
extAuthHandler=FALSE;
505528
for (e = rfbClientExtensions; e; e = e->next) {
506529
if (!e->handleAuthentication) continue;
@@ -519,7 +542,8 @@ ReadSupportedSecurityType(rfbClient* client, uint32_t *result, rfbBool subAuth)
519542
#ifdef LIBVNCSERVER_HAVE_SASL
520543
tAuth[loop]==rfbSASL ||
521544
#endif /* LIBVNCSERVER_HAVE_SASL */
522-
((tAuth[loop]==rfbARD || tAuth[loop]==rfbUltraMSLogonII) && client->GetCredential))
545+
(((SupportsARDAuthScheme(tAuth[loop])) ||
546+
tAuth[loop]==rfbUltraMSLogonII) && client->GetCredential))
523547
{
524548
if (!subAuth && client->clientAuthSchemes)
525549
{
@@ -528,22 +552,23 @@ ReadSupportedSecurityType(rfbClient* client, uint32_t *result, rfbBool subAuth)
528552
{
529553
if (client->clientAuthSchemes[i]==(uint32_t)tAuth[loop])
530554
{
531-
flag++;
532-
authScheme=tAuth[loop];
555+
if (!selected || selectedPriority < 0 || i < selectedPriority) {
556+
selected=TRUE;
557+
selectedPriority=i;
558+
selectedLoop=loop;
559+
authScheme=tAuth[loop];
560+
}
533561
break;
534562
}
535563
}
536564
}
537565
else
538566
{
539-
flag++;
540-
authScheme=tAuth[loop];
541-
}
542-
if (flag)
543-
{
544-
rfbClientLog("Selecting security type %d (%d/%d in the list)\n", authScheme, loop, count);
545-
/* send back a single byte indicating which security type to use */
546-
if (!WriteToRFBServer(client, (char *)&tAuth[loop], 1)) return FALSE;
567+
if (!selected) {
568+
selected=TRUE;
569+
selectedLoop=loop;
570+
authScheme=tAuth[loop];
571+
}
547572
}
548573
}
549574
}
@@ -560,10 +585,16 @@ ReadSupportedSecurityType(rfbClient* client, uint32_t *result, rfbBool subAuth)
560585
buf1);
561586
return FALSE;
562587
}
588+
rfbClientLog("Selecting security type %d (%d/%d in the list)\n", authScheme, selectedLoop, count);
589+
if (authScheme != rfbARDAuthDirectSRP) {
590+
uint8_t selectedType = (uint8_t)authScheme;
591+
if (!WriteToRFBServer(client, (char *)&selectedType, 1)) return FALSE;
592+
}
563593
*result = authScheme;
564594
return TRUE;
565595
}
566596

597+
567598
static rfbBool
568599
HandleVncAuth(rfbClient *client)
569600
{

0 commit comments

Comments
 (0)