Skip to content

Commit f2a118f

Browse files
committed
libvncclient: tls_openssl: fix asking user multiple times when IPv6 address used
1 parent bafc59f commit f2a118f

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/libvncclient/tls_openssl.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
static rfbBool rfbTLSInitialized = FALSE;
3737
static int rfbTLSExpectedFingerprintIndex = -1;
3838
static int rfbTLSClientIndex = -1;
39+
static int rfbTLSCertDecisionIndex = -1;
3940

4041
// Locking callbacks are only initialized if we have mutex support.
4142
#if defined(LIBVNCSERVER_HAVE_LIBPTHREAD) || defined(LIBVNCSERVER_HAVE_WIN32THREADS)
@@ -158,6 +159,7 @@ InitializeTLS(void)
158159

159160
rfbTLSExpectedFingerprintIndex = SSL_get_ex_new_index(0, "rfbTLSExpectedFingerprintIndex", NULL, NULL, NULL);
160161
rfbTLSClientIndex = SSL_get_ex_new_index(0, "rfbTLSClientIndex", NULL, NULL, NULL);
162+
rfbTLSCertDecisionIndex = SSL_get_ex_new_index(0, "rfbTLSCertDecisionIndex", NULL, NULL, NULL);
161163

162164
rfbClientLog("OpenSSL version %s initialized.\n", SSLeay_version(SSLEAY_VERSION));
163165
rfbTLSInitialized = TRUE;
@@ -307,13 +309,18 @@ static int cert_verify_callback(int preverify_ok, X509_STORE_CTX *ctx) {
307309
SSL *ssl = X509_STORE_CTX_get_ex_data(ctx, SSL_get_ex_data_X509_STORE_CTX_idx());
308310
const unsigned char *expected_fingerprint = SSL_get_ex_data(ssl, rfbTLSExpectedFingerprintIndex);
309311

312+
// Check if we already have a cached user decision for this certificate
313+
int cached_decision = (int)(intptr_t)SSL_get_ex_data(ssl, rfbTLSCertDecisionIndex);
314+
310315
int verify;
311-
if (expected_fingerprint && memcmp(remote_fingerprint, expected_fingerprint, 32) == 0) {
316+
if (cached_decision || (expected_fingerprint && memcmp(remote_fingerprint, expected_fingerprint, 32) == 0)) {
312317
// accept
313318
verify = 1;
314319
} else {
315320
// ask user
316321
verify = cert_fingerprint_mismatch_callback(SSL_get_ex_data(ssl, rfbTLSClientIndex), X509_STORE_CTX_get_current_cert(ctx));
322+
// Cache the user decision to avoid prompting the user multiple times
323+
SSL_set_ex_data(ssl, rfbTLSCertDecisionIndex, (void*)(intptr_t)verify);
317324
}
318325

319326
if(verify) {

0 commit comments

Comments
 (0)