GCC Code Coverage Report


Directory: ./
File: panels/system/remote-desktop/cc-encryption-fingerprint-dialog.c
Date: 2024-05-03 09:46:52
Exec Total Coverage
Lines: 0 41 0.0%
Functions: 0 7 0.0%
Branches: 0 27 0.0%

Line Branch Exec Source
1 /*
2 * Copyright 2024 Red Hat, Inc
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * SPDX-License-Identifier: GPL-3.0-or-later
18 */
19
20 #include "cc-encryption-fingerprint-dialog.h"
21
22 #ifdef HAVE_CONFIG_H
23 # include "config.h"
24 #endif
25
26 struct _CcEncryptionFingerprintDialog {
27 AdwDialog parent_instance;
28
29 GtkLabel *fingerprint_left_label;
30 GtkLabel *fingerprint_right_label;
31 };
32
33 G_DEFINE_TYPE (CcEncryptionFingerprintDialog, cc_encryption_fingerprint_dialog, ADW_TYPE_DIALOG)
34
35 static void
36 cc_encryption_fingerprint_dialog_class_init (CcEncryptionFingerprintDialogClass *klass)
37 {
38 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
39
40 gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/control-center/system/remote-desktop/cc-encryption-fingerprint-dialog.ui");
41
42 gtk_widget_class_bind_template_child (widget_class, CcEncryptionFingerprintDialog, fingerprint_left_label);
43 gtk_widget_class_bind_template_child (widget_class, CcEncryptionFingerprintDialog, fingerprint_right_label);
44 }
45
46 static void
47 cc_encryption_fingerprint_dialog_init (CcEncryptionFingerprintDialog *self)
48 {
49 gtk_widget_init_template (GTK_WIDGET (self));
50 }
51
52 void
53 cc_encryption_fingerprint_dialog_set_fingerprint (CcEncryptionFingerprintDialog *self,
54 const gchar *fingerprint,
55 const gchar *separator)
56 {
57 g_auto(GStrv) fingerprintv = NULL;
58 g_autofree char *left_string = NULL;
59 g_autofree char *right_string = NULL;
60
61 fingerprintv = g_strsplit (fingerprint, separator, -1);
62 g_return_if_fail (g_strv_length (fingerprintv) == 32);
63
64 left_string = g_strdup_printf (
65 "%s:%s:%s:%s\n"
66 "%s:%s:%s:%s\n"
67 "%s:%s:%s:%s\n"
68 "%s:%s:%s:%s\n",
69 fingerprintv[0], fingerprintv[1], fingerprintv[2], fingerprintv[3],
70 fingerprintv[8], fingerprintv[9], fingerprintv[10], fingerprintv[11],
71 fingerprintv[16], fingerprintv[17], fingerprintv[18], fingerprintv[19],
72 fingerprintv[24], fingerprintv[25], fingerprintv[26], fingerprintv[27]);
73
74 right_string = g_strdup_printf (
75 "%s:%s:%s:%s\n"
76 "%s:%s:%s:%s\n"
77 "%s:%s:%s:%s\n"
78 "%s:%s:%s:%s\n",
79 fingerprintv[4], fingerprintv[5], fingerprintv[6], fingerprintv[7],
80 fingerprintv[12], fingerprintv[13], fingerprintv[14], fingerprintv[15],
81 fingerprintv[20], fingerprintv[21], fingerprintv[22], fingerprintv[23],
82 fingerprintv[28], fingerprintv[29], fingerprintv[30], fingerprintv[31]);
83
84 gtk_label_set_label (GTK_LABEL (self->fingerprint_left_label), left_string);
85 gtk_label_set_label (GTK_LABEL (self->fingerprint_right_label), right_string);
86 }
87
88 void
89 cc_encryption_fingerprint_dialog_set_certificate (CcEncryptionFingerprintDialog *self,
90 GTlsCertificate *certificate)
91 {
92 g_autofree char *fingerprint = NULL;
93 g_autoptr(GByteArray) der = NULL;
94 g_autoptr(GcrCertificate) gcr_cert = NULL;
95 g_return_if_fail (self);
96 g_return_if_fail (certificate);
97
98 g_object_get (certificate, "certificate", &der, NULL);
99 gcr_cert = gcr_simple_certificate_new (der->data, der->len);
100 if (!gcr_cert)
101 {
102 g_warning ("Failed to load GCR TLS certificate representation");
103 return;
104 }
105
106 fingerprint = gcr_certificate_get_fingerprint_hex (gcr_cert, G_CHECKSUM_SHA256);
107 cc_encryption_fingerprint_dialog_set_fingerprint (self, fingerprint, " ");
108 }
109