system, remote-desktop: Add CcEncryptionFingerprintDialog widget

So that we can reuse the same widget in both Desktop Sharing and
Remote Login pages.
This commit is contained in:
Felipe Borges 2024-02-26 14:56:49 +01:00 committed by Ray Strode
parent 71f9073c9a
commit aee53419f5
7 changed files with 197 additions and 101 deletions

View file

@ -39,6 +39,7 @@ sources = files(
'region/cc-format-chooser.c',
'region/cc-format-preview.c',
'remote-desktop/cc-desktop-sharing-page.c',
'remote-desktop/cc-encryption-fingerprint-dialog.c',
'remote-desktop/cc-gnome-remote-desktop.c',
'remote-desktop/cc-remote-desktop-page.c',
'remote-desktop/cc-tls-certificate.c',

View file

@ -21,6 +21,7 @@
#define G_LOG_DOMAIN "cc-desktop-sharing-page"
#include "cc-desktop-sharing-page.h"
#include "cc-encryption-fingerprint-dialog.h"
#include "cc-gnome-remote-desktop.h"
#include "cc-hostname.h"
#include "cc-list-row.h"
@ -41,9 +42,6 @@
#include <gdk/wayland/gdkwayland.h>
#endif
#define GCR_API_SUBJECT_TO_CHANGE
#include <gcr/gcr.h>
#include <pwd.h>
#include <pwquality.h>
#include <unistd.h>
@ -65,9 +63,7 @@ struct _CcDesktopSharingPage {
GtkWidget *password_entry;
GtkWidget *verify_encryption_button;
GtkWidget *fingerprint_dialog;
GtkWidget *fingerprint_left_label;
GtkWidget *fingerprint_right_label;
CcEncryptionFingerprintDialog *fingerprint_dialog;
guint desktop_sharing_name_watch;
guint store_credentials_id;
@ -82,54 +78,16 @@ G_DEFINE_TYPE (CcDesktopSharingPage, cc_desktop_sharing_page, ADW_TYPE_BIN)
static void
on_verify_encryption_button_clicked (CcDesktopSharingPage *self)
{
g_autoptr(GByteArray) der = NULL;
g_autoptr(GcrCertificate) gcr_cert = NULL;
g_autofree char *fingerprint = NULL;
g_auto(GStrv) fingerprintv = NULL;
g_autofree char *left_string = NULL;
g_autofree char *right_string = NULL;
GtkNative *native;
g_return_if_fail (self->certificate);
g_object_get (self->certificate, "certificate", &der, NULL);
gcr_cert = gcr_simple_certificate_new (der->data, der->len);
if (!gcr_cert)
{
g_warning ("Failed to load GCR TLS certificate representation");
return;
}
fingerprint = gcr_certificate_get_fingerprint_hex (gcr_cert, G_CHECKSUM_SHA256);
fingerprintv = g_strsplit (fingerprint, " ", -1);
g_return_if_fail (g_strv_length (fingerprintv) == 32);
left_string = g_strdup_printf (
"%s:%s:%s:%s\n"
"%s:%s:%s:%s\n"
"%s:%s:%s:%s\n"
"%s:%s:%s:%s\n",
fingerprintv[0], fingerprintv[1], fingerprintv[2], fingerprintv[3],
fingerprintv[8], fingerprintv[9], fingerprintv[10], fingerprintv[11],
fingerprintv[16], fingerprintv[17], fingerprintv[18], fingerprintv[19],
fingerprintv[24], fingerprintv[25], fingerprintv[26], fingerprintv[27]);
right_string = g_strdup_printf (
"%s:%s:%s:%s\n"
"%s:%s:%s:%s\n"
"%s:%s:%s:%s\n"
"%s:%s:%s:%s\n",
fingerprintv[4], fingerprintv[5], fingerprintv[6], fingerprintv[7],
fingerprintv[12], fingerprintv[13], fingerprintv[14], fingerprintv[15],
fingerprintv[20], fingerprintv[21], fingerprintv[22], fingerprintv[23],
fingerprintv[28], fingerprintv[29], fingerprintv[30], fingerprintv[31]);
gtk_label_set_label (GTK_LABEL (self->fingerprint_left_label), left_string);
gtk_label_set_label (GTK_LABEL (self->fingerprint_right_label), right_string);
if (!self->fingerprint_dialog)
self->fingerprint_dialog = g_object_new (CC_TYPE_ENCRYPTION_FINGERPRINT_DIALOG, NULL);
native = gtk_widget_get_native (GTK_WIDGET (self));
gtk_window_set_transient_for (GTK_WINDOW (self->fingerprint_dialog), GTK_WINDOW (native));
cc_encryption_fingerprint_dialog_set_certificate (self->fingerprint_dialog, self->certificate);
gtk_window_present (GTK_WINDOW (self->fingerprint_dialog));
}
@ -567,6 +525,7 @@ cc_desktop_sharing_page_dispose (GObject *object)
g_cancellable_cancel (self->cancellable);
g_clear_object (&self->cancellable);
g_clear_pointer ((GtkWindow **) &self->fingerprint_dialog, gtk_window_destroy);
g_clear_handle_id (&self->store_credentials_id, g_source_remove);
g_clear_object (&self->rdp_settings);
@ -593,10 +552,6 @@ cc_desktop_sharing_page_class_init (CcDesktopSharingPageClass * klass)
gtk_widget_class_bind_template_child (widget_class, CcDesktopSharingPage, address_label);
gtk_widget_class_bind_template_child (widget_class, CcDesktopSharingPage, verify_encryption_button);
gtk_widget_class_bind_template_child (widget_class, CcDesktopSharingPage, fingerprint_dialog);
gtk_widget_class_bind_template_child (widget_class, CcDesktopSharingPage, fingerprint_left_label);
gtk_widget_class_bind_template_child (widget_class, CcDesktopSharingPage, fingerprint_right_label);
gtk_widget_class_bind_template_callback (widget_class, on_address_copy_clicked);
gtk_widget_class_bind_template_callback (widget_class, on_username_copy_clicked);
gtk_widget_class_bind_template_callback (widget_class, on_password_copy_clicked);

View file

@ -124,54 +124,4 @@
</object>
</child>
</template>
<object class="AdwWindow" id="fingerprint_dialog">
<property name="default-width">360</property>
<property name="default-height">360</property>
<property name="hide-on-close">True</property>
<property name="modal">True</property>
<child>
<object class="GtkBox">
<property name="orientation">vertical</property>
<child>
<object class="GtkWindowControls">
<property name="halign">end</property>
<property name="side">end</property>
</object>
</child>
<child>
<object class="AdwStatusPage">
<property name="title" translatable="yes">Encryption Fingerprint</property>
<property name="description" translatable="yes">The encryption fingerprint can be seen in connecting clients and should be identical</property>
<property name="vexpand">True</property>
<child>
<object class="GtkBox">
<property name="orientation">horizontal</property>
<property name="halign">center</property>
<style>
<class name="tls-cert-verification" />
</style>
<child>
<object class="GtkLabel" id="fingerprint_left_label">
<style>
<class name="tls-cert-fingerprint" />
</style>
</object>
</child>
<child>
<object class="GtkLabel" id="fingerprint_right_label">
<style>
<class name="tls-cert-fingerprint" />
</style>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</interface>

View file

@ -0,0 +1,101 @@
/*
* Copyright 2024 Red Hat, Inc
*
* This program 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 Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#include "cc-encryption-fingerprint-dialog.h"
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
struct _CcEncryptionFingerprintDialog {
AdwWindow parent_instance;
GtkLabel *fingerprint_left_label;
GtkLabel *fingerprint_right_label;
};
G_DEFINE_TYPE (CcEncryptionFingerprintDialog, cc_encryption_fingerprint_dialog, ADW_TYPE_WINDOW)
static void
cc_encryption_fingerprint_dialog_class_init (CcEncryptionFingerprintDialogClass *klass)
{
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/control-center/system/remote-desktop/cc-encryption-fingerprint-dialog.ui");
gtk_widget_class_bind_template_child (widget_class, CcEncryptionFingerprintDialog, fingerprint_left_label);
gtk_widget_class_bind_template_child (widget_class, CcEncryptionFingerprintDialog, fingerprint_right_label);
}
static void
cc_encryption_fingerprint_dialog_init (CcEncryptionFingerprintDialog *self)
{
gtk_widget_init_template (GTK_WIDGET (self));
}
void
cc_encryption_fingerprint_dialog_set_certificate (CcEncryptionFingerprintDialog *self,
GTlsCertificate *certificate)
{
g_autoptr(GByteArray) der = NULL;
g_autoptr(GcrCertificate) gcr_cert = NULL;
g_autofree char *fingerprint = NULL;
g_auto(GStrv) fingerprintv = NULL;
g_autofree char *left_string = NULL;
g_autofree char *right_string = NULL;
g_return_if_fail (self);
g_return_if_fail (certificate);
g_object_get (certificate, "certificate", &der, NULL);
gcr_cert = gcr_simple_certificate_new (der->data, der->len);
if (!gcr_cert)
{
g_warning ("Failed to load GCR TLS certificate representation");
return;
}
fingerprint = gcr_certificate_get_fingerprint_hex (gcr_cert, G_CHECKSUM_SHA256);
fingerprintv = g_strsplit (fingerprint, " ", -1);
g_return_if_fail (g_strv_length (fingerprintv) == 32);
left_string = g_strdup_printf (
"%s:%s:%s:%s\n"
"%s:%s:%s:%s\n"
"%s:%s:%s:%s\n"
"%s:%s:%s:%s\n",
fingerprintv[0], fingerprintv[1], fingerprintv[2], fingerprintv[3],
fingerprintv[8], fingerprintv[9], fingerprintv[10], fingerprintv[11],
fingerprintv[16], fingerprintv[17], fingerprintv[18], fingerprintv[19],
fingerprintv[24], fingerprintv[25], fingerprintv[26], fingerprintv[27]);
right_string = g_strdup_printf (
"%s:%s:%s:%s\n"
"%s:%s:%s:%s\n"
"%s:%s:%s:%s\n"
"%s:%s:%s:%s\n",
fingerprintv[4], fingerprintv[5], fingerprintv[6], fingerprintv[7],
fingerprintv[12], fingerprintv[13], fingerprintv[14], fingerprintv[15],
fingerprintv[20], fingerprintv[21], fingerprintv[22], fingerprintv[23],
fingerprintv[28], fingerprintv[29], fingerprintv[30], fingerprintv[31]);
gtk_label_set_label (GTK_LABEL (self->fingerprint_left_label), left_string);
gtk_label_set_label (GTK_LABEL (self->fingerprint_right_label), right_string);
}

View file

@ -0,0 +1,36 @@
/*
* Copyright 2024 Red Hat, Inc
*
* This program 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 Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#pragma once
#include <adwaita.h>
#define GCR_API_SUBJECT_TO_CHANGE
#include <gcr/gcr.h>
G_BEGIN_DECLS
#define CC_TYPE_ENCRYPTION_FINGERPRINT_DIALOG (cc_encryption_fingerprint_dialog_get_type ())
G_DECLARE_FINAL_TYPE (CcEncryptionFingerprintDialog, cc_encryption_fingerprint_dialog, CC, ENCRYPTION_FINGERPRINT_DIALOG, AdwWindow)
void cc_encryption_fingerprint_dialog_set_certificate (CcEncryptionFingerprintDialog *self,
GTlsCertificate *certificate);
G_END_DECLS

View file

@ -0,0 +1,52 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<template class="CcEncryptionFingerprintDialog" parent="AdwWindow">
<property name="default-width">360</property>
<property name="default-height">360</property>
<property name="hide-on-close">True</property>
<property name="modal">True</property>
<child>
<object class="GtkBox">
<property name="orientation">vertical</property>
<child>
<object class="GtkWindowControls">
<property name="halign">end</property>
<property name="side">end</property>
</object>
</child>
<child>
<object class="AdwStatusPage">
<property name="title" translatable="yes">Encryption Fingerprint</property>
<property name="description" translatable="yes">The encryption fingerprint can be seen in connecting clients and should be identical</property>
<property name="vexpand">True</property>
<child>
<object class="GtkBox">
<property name="orientation">horizontal</property>
<property name="halign">center</property>
<style>
<class name="tls-cert-verification" />
</style>
<child>
<object class="GtkLabel" id="fingerprint_left_label">
<style>
<class name="tls-cert-fingerprint" />
</style>
</object>
</child>
<child>
<object class="GtkLabel" id="fingerprint_right_label">
<style>
<class name="tls-cert-fingerprint" />
</style>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
</template>
</interface>

View file

@ -13,6 +13,7 @@
<file preprocess="xml-stripblanks">region/cc-region-page.ui</file>
<file preprocess="xml-stripblanks">region/cc-format-chooser.ui</file>
<file preprocess="xml-stripblanks">region/cc-format-preview.ui</file>
<file preprocess="xml-stripblanks">remote-desktop/cc-encryption-fingerprint-dialog.ui</file>
<file preprocess="xml-stripblanks">remote-desktop/cc-remote-desktop-page.ui</file>
<file preprocess="xml-stripblanks">remote-desktop/cc-desktop-sharing-page.ui</file>
<file>remote-desktop/remote-desktop.css</file>