|
36 | 36 | static rfbBool rfbTLSInitialized = FALSE; |
37 | 37 | static int rfbTLSExpectedFingerprintIndex = -1; |
38 | 38 | static int rfbTLSClientIndex = -1; |
| 39 | +static int rfbTLSCertDecisionIndex = -1; |
39 | 40 |
|
40 | 41 | // Locking callbacks are only initialized if we have mutex support. |
41 | 42 | #if defined(LIBVNCSERVER_HAVE_LIBPTHREAD) || defined(LIBVNCSERVER_HAVE_WIN32THREADS) |
@@ -158,6 +159,7 @@ InitializeTLS(void) |
158 | 159 |
|
159 | 160 | rfbTLSExpectedFingerprintIndex = SSL_get_ex_new_index(0, "rfbTLSExpectedFingerprintIndex", NULL, NULL, NULL); |
160 | 161 | rfbTLSClientIndex = SSL_get_ex_new_index(0, "rfbTLSClientIndex", NULL, NULL, NULL); |
| 162 | + rfbTLSCertDecisionIndex = SSL_get_ex_new_index(0, "rfbTLSCertDecisionIndex", NULL, NULL, NULL); |
161 | 163 |
|
162 | 164 | rfbClientLog("OpenSSL version %s initialized.\n", SSLeay_version(SSLEAY_VERSION)); |
163 | 165 | rfbTLSInitialized = TRUE; |
@@ -307,13 +309,18 @@ static int cert_verify_callback(int preverify_ok, X509_STORE_CTX *ctx) { |
307 | 309 | SSL *ssl = X509_STORE_CTX_get_ex_data(ctx, SSL_get_ex_data_X509_STORE_CTX_idx()); |
308 | 310 | const unsigned char *expected_fingerprint = SSL_get_ex_data(ssl, rfbTLSExpectedFingerprintIndex); |
309 | 311 |
|
| 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 | + |
310 | 315 | 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)) { |
312 | 317 | // accept |
313 | 318 | verify = 1; |
314 | 319 | } else { |
315 | 320 | // ask user |
316 | 321 | 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); |
317 | 324 | } |
318 | 325 |
|
319 | 326 | if(verify) { |
|
0 commit comments