From 66d0eadfa5904004064af3e253ed5bf89bf58fe9 Mon Sep 17 00:00:00 2001 From: Richard Hughes Date: Sun, 10 Jan 2021 19:55:24 +0000 Subject: [PATCH] Show a console warning if the system clock is not set If the date is wrong, the SSL certificate may not be in a valid date range and the user gets a rather unhelpful 'SSL handshake failed' error message. Detect the most common case and show a warning when starting fwupdmgr. Fixes https://github.com/fwupd/fwupd/issues/2723 --- src/fu-util.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/fu-util.c b/src/fu-util.c index 05f429bf6..1d0684786 100644 --- a/src/fu-util.c +++ b/src/fu-util.c @@ -2702,6 +2702,7 @@ main (int argc, char *argv[]) gboolean verbose = FALSE; gboolean version = FALSE; g_autoptr(FuUtilPrivate) priv = g_new0 (FuUtilPrivate, 1); + g_autoptr(GDateTime) dt_now = g_date_time_new_now_utc (); g_autoptr(GError) error = NULL; g_autoptr(GError) error_polkit = NULL; g_autoptr(GPtrArray) cmd_array = fu_util_cmd_array_new (); @@ -3045,6 +3046,17 @@ main (int argc, char *argv[]) g_setenv ("DISABLE_SSL_STRICT", "1", TRUE); } + /* this doesn't have to be precise (e.g. using the build-year) as we just + * want to check the clock is not set to the default of 1970-01-01... */ + if (g_date_time_get_year (dt_now) < 2021) { + g_autofree gchar *fmt = NULL; + /* TRANSLATORS: this is a prefix on the console */ + fmt = fu_util_term_format (_("WARNING:"), FU_UTIL_TERM_COLOR_RED); + /* TRANSLATORS: try to help */ + g_printerr ("%s %s\n", fmt, _("The system clock has not been set " + "correctly and downloading files may fail.")); + } + /* non-TTY consoles cannot answer questions */ if (isatty (fileno (stdout)) == 0) { is_interactive = FALSE;