Files
RetroArch/network/tls_log.c
Anthony Schemel abd42c0993 net/tls: show an on-screen notice for refused and unverified connections (#19712)
A refused certificate or a connection made with verification disabled
now shows an on-screen notice alongside the log line: the refusal names
the 'TLS Certificate Verification' setting, the disabled notice says
connections are not being checked. Background tasks can connect many
times a minute, so each notice shows once a session, guarded by an
atomic since the hooks run on connection threads. Optional mode stays
log-only.

The BearSSL backend now reports a handshake that ended on the
certificate through ssl_socket_log_verify_fail, as the built-in client
and mbedTLS do, and ships the weak no-op hooks.

samples/network/tls_retro/verify_hook_test.sh checks that a refused
certificate reaches the hook on each backend; it runs in the built-in
client's local server matrix and in the mbedTLS and BearSSL lanes.
2026-10-09 11:35:31 +02:00

82 lines
3.4 KiB
C

/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
* Copyright (C) 2011-2017 - Daniel De Matteis
*
* RetroArch 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 Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch 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 RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include <string.h>
#include <net/net_socket_ssl.h>
#include <retro_atomic.h>
#include "../msg_hash.h"
#include "../runloop.h"
#include "../verbosity.h"
/* The log line comes on every connection; the on-screen notice once a
* session, since a background task can connect many times a minute.
* The hooks run on connection threads, so the once is an atomic. */
static retro_atomic_int_t tls_notice_fail_shown;
static retro_atomic_int_t tls_notice_disabled_shown;
static void tls_notice_once(retro_atomic_int_t *shown, enum msg_hash_enums msg)
{
const char *str;
if (!retro_atomic_cas_int(shown, 0, 1))
return;
str = msg_hash_to_str(msg);
runloop_msg_queue_push(str, strlen(str), 1, 300, false, NULL,
MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_WARNING);
}
/* Strong overrides of the weak logging hooks declared in net_socket_ssl.h.
* Routing TLS verification outcomes into the RetroArch log lives here, on the
* RA side, so verbosity.h never has to be pulled into vendored libretro-common
* (which ships with every libretro core and may be built standalone). */
void ssl_socket_log_verify_fail(int mode_required, const char *domain,
const char *verify_info)
{
if (mode_required)
{
RARCH_ERR("[TLS] Cert verification failed for %s: %s\n",
domain ? domain : "(unknown)",
verify_info ? verify_info : "");
/* mbedTLS reports a certificate outside its validity period as
* MBEDTLS_X509_BADCERT_EXPIRED / _FUTURE. On a device whose clock
* is unset or years off, every server looks that way. Say so,
* since the mbedTLS text alone reads like a server problem. */
if ( verify_info
&& ( strstr(verify_info, "expired")
|| strstr(verify_info, "future")))
RARCH_ERR("[TLS] The certificate's validity period does not "
"contain the current system time. If this happens for "
"every server, check the date and time on this device. "
"Setting 'TLS Certificate Verification' to 'Optional' "
"restores connectivity without a fix, at the cost of "
"certificate checking.\n");
tls_notice_once(&tls_notice_fail_shown, MSG_TLS_VERIFY_FAILED);
}
else
RARCH_WARN("[TLS] Cert verification soft-failed for %s: %s\n",
domain ? domain : "(unknown)",
verify_info ? verify_info : "");
}
void ssl_socket_log_verify_disabled(const char *domain)
{
(void)domain;
RARCH_WARN("[TLS] Certificate verification disabled - connections vulnerable to MITM.\n");
tls_notice_once(&tls_notice_disabled_shown, MSG_TLS_VERIFY_DISABLED);
}