2012-12-09 19:38:32 -05:00
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* NetworkManager Applet -- allow user control over networking
*
* Dan Williams < dcbw @ redhat . com >
*
* 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 2 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 , write to the Free Software Foundation , Inc . ,
* 51 Franklin Street , Fifth Floor , Boston , MA 02110 - 1301 USA .
*
2016-06-07 12:03:22 +02:00
* Copyright 2007 - 2014 Red Hat , Inc .
2012-12-09 19:38:32 -05:00
*/
2019-11-12 09:53:18 +13:00
# include <glib/gi18n.h>
2012-12-09 19:38:32 -05:00
# include "eap-method.h"
2019-11-07 10:10:21 +13:00
# include "eap-method-tls.h"
2012-12-09 19:38:32 -05:00
# include "helpers.h"
2016-06-07 12:03:22 +02:00
# include "nma-ui-utils.h"
2019-11-12 10:08:14 +13:00
# include "ui-helpers.h"
2021-11-29 10:37:01 -03:00
# include "ws-file-chooser-button.h"
2012-12-09 19:38:32 -05:00
struct _EAPMethodTLS {
2019-11-07 11:35:25 +13:00
GtkGrid parent ;
2012-12-09 19:38:32 -05:00
2021-11-29 10:37:01 -03:00
WsFileChooserButton * ca_cert_button ;
2019-10-15 12:25:48 +13:00
GtkLabel * ca_cert_label ;
GtkCheckButton * ca_cert_not_required_check ;
GtkEntry * identity_entry ;
GtkLabel * identity_label ;
2021-11-29 10:37:01 -03:00
WsFileChooserButton * private_key_button ;
2019-10-15 12:25:48 +13:00
GtkLabel * private_key_label ;
GtkEntry * private_key_password_entry ;
GtkLabel * private_key_password_label ;
GtkCheckButton * show_password_check ;
2021-11-29 10:37:01 -03:00
WsFileChooserButton * user_cert_button ;
2019-10-15 12:25:48 +13:00
GtkLabel * user_cert_label ;
2019-12-02 17:10:24 +13:00
gchar * username ;
gchar * password ;
gboolean show_password ;
2012-12-09 19:38:32 -05:00
} ;
2019-11-07 10:21:54 +13:00
static void eap_method_iface_init ( EAPMethodInterface * ) ;
2019-11-07 11:35:25 +13:00
G_DEFINE_TYPE_WITH_CODE ( EAPMethodTLS , eap_method_tls , GTK_TYPE_GRID ,
2019-11-07 10:21:54 +13:00
G_IMPLEMENT_INTERFACE ( eap_method_get_type ( ) , eap_method_iface_init ) )
2019-12-02 17:10:24 +13:00
static void
eap_method_tls_dispose ( GObject * object )
{
EAPMethodTLS * self = EAP_METHOD_TLS ( object ) ;
g_clear_pointer ( & self - > username , g_free ) ;
g_clear_pointer ( & self - > password , g_free ) ;
G_OBJECT_CLASS ( eap_method_tls_parent_class ) - > dispose ( object ) ;
}
2012-12-09 19:38:32 -05:00
static void
2019-10-15 11:15:30 +13:00
show_toggled_cb ( EAPMethodTLS * self )
2012-12-09 19:38:32 -05:00
{
gboolean visible ;
2021-11-29 10:37:01 -03:00
visible = gtk_check_button_get_active ( GTK_CHECK_BUTTON ( self - > show_password_check ) ) ;
2019-10-15 12:25:48 +13:00
gtk_entry_set_visibility ( self - > private_key_password_entry , visible ) ;
2012-12-09 19:38:32 -05:00
}
static gboolean
2019-11-07 10:21:54 +13:00
validate ( EAPMethod * method , GError * * error )
2012-12-09 19:38:32 -05:00
{
2019-11-07 10:21:54 +13:00
EAPMethodTLS * self = EAP_METHOD_TLS ( method ) ;
2012-12-09 19:38:32 -05:00
NMSetting8021xCKFormat format = NM_SETTING_802_1X_CK_FORMAT_UNKNOWN ;
2021-01-14 17:17:42 +01:00
NMSettingSecretFlags secret_flags ;
2012-12-09 19:38:32 -05:00
const char * password , * identity ;
2019-09-12 10:54:37 +12:00
g_autoptr ( GError ) ca_cert_error = NULL ;
g_autoptr ( GError ) private_key_error = NULL ;
g_autoptr ( GError ) user_cert_error = NULL ;
2014-08-13 13:46:03 +02:00
gboolean ret = TRUE ;
2012-12-09 19:38:32 -05:00
2021-11-29 10:37:01 -03:00
identity = gtk_editable_get_text ( GTK_EDITABLE ( self - > identity_entry ) ) ;
2014-08-07 18:32:34 +02:00
if ( ! identity | | ! strlen ( identity ) ) {
2019-10-15 12:25:48 +13:00
widget_set_error ( GTK_WIDGET ( self - > identity_entry ) ) ;
2016-06-07 12:03:22 +02:00
g_set_error_literal ( error , NMA_ERROR , NMA_ERROR_GENERIC , _ ( " missing EAP-TLS identity " ) ) ;
2014-08-13 13:46:03 +02:00
ret = FALSE ;
} else {
2019-10-15 12:25:48 +13:00
widget_unset_error ( GTK_WIDGET ( self - > identity_entry ) ) ;
2014-08-07 18:32:34 +02:00
}
2012-12-09 19:38:32 -05:00
2021-11-29 10:37:01 -03:00
if ( ! eap_method_validate_filepicker ( ws_file_chooser_button_get_filechooser ( self - > ca_cert_button ) ,
2019-10-02 11:00:21 +13:00
TYPE_CA_CERT , NULL , NULL , & ca_cert_error ) ) {
2019-10-15 12:25:48 +13:00
widget_set_error ( GTK_WIDGET ( self - > ca_cert_button ) ) ;
2016-06-07 16:53:04 +02:00
if ( ret ) {
2019-09-12 10:54:37 +12:00
g_set_error ( error , NMA_ERROR , NMA_ERROR_GENERIC , _ ( " invalid EAP-TLS CA certificate: %s " ) , ca_cert_error - > message ) ;
2016-06-07 16:53:04 +02:00
ret = FALSE ;
}
2021-11-29 10:37:01 -03:00
} else if ( ! gtk_check_button_get_active ( GTK_CHECK_BUTTON ( self - > ca_cert_not_required_check ) ) ) {
g_autoptr ( GFile ) file = NULL ;
2019-11-12 12:00:25 +13:00
2021-11-29 10:37:01 -03:00
file = ws_file_chooser_button_get_file ( self - > ca_cert_button ) ;
if ( file = = NULL ) {
2019-11-12 12:00:25 +13:00
widget_set_error ( GTK_WIDGET ( self - > ca_cert_button ) ) ;
2019-12-03 15:22:38 +13:00
if ( ret ) {
g_set_error_literal ( error , NMA_ERROR , NMA_ERROR_GENERIC , _ ( " invalid EAP-TLS CA certificate: no certificate specified " ) ) ;
ret = FALSE ;
}
2016-06-07 16:53:04 +02:00
}
2014-08-13 13:46:03 +02:00
}
2012-12-09 19:38:32 -05:00
2021-11-29 10:37:01 -03:00
password = gtk_editable_get_text ( GTK_EDITABLE ( self - > private_key_password_entry ) ) ;
2021-01-14 17:17:42 +01:00
secret_flags = nma_utils_menu_to_secret_flags ( GTK_WIDGET ( self - > private_key_password_entry ) ) ;
if ( secret_flags & NM_SETTING_SECRET_FLAG_NOT_SAVED )
password = NULL ;
2012-12-09 19:38:32 -05:00
2021-11-29 10:37:01 -03:00
if ( ! eap_method_validate_filepicker ( ws_file_chooser_button_get_filechooser ( self - > private_key_button ) ,
2012-12-09 19:38:32 -05:00
TYPE_PRIVATE_KEY ,
password ,
2016-06-07 12:03:22 +02:00
& format ,
2019-09-12 10:54:37 +12:00
& private_key_error ) ) {
2016-06-07 16:53:04 +02:00
if ( ret ) {
2019-09-12 10:54:37 +12:00
g_set_error ( error , NMA_ERROR , NMA_ERROR_GENERIC , _ ( " invalid EAP-TLS private-key: %s " ) , private_key_error - > message ) ;
2016-06-07 16:53:04 +02:00
ret = FALSE ;
}
2019-10-15 12:25:48 +13:00
widget_set_error ( GTK_WIDGET ( self - > private_key_button ) ) ;
2014-08-13 13:46:03 +02:00
}
2012-12-09 19:38:32 -05:00
if ( format ! = NM_SETTING_802_1X_CK_FORMAT_PKCS12 ) {
2021-11-29 10:37:01 -03:00
if ( ! eap_method_validate_filepicker ( ws_file_chooser_button_get_filechooser ( self - > user_cert_button ) ,
2019-10-02 11:00:21 +13:00
TYPE_CLIENT_CERT , NULL , NULL , & user_cert_error ) ) {
2016-06-07 16:53:04 +02:00
if ( ret ) {
2019-09-12 10:54:37 +12:00
g_set_error ( error , NMA_ERROR , NMA_ERROR_GENERIC , _ ( " invalid EAP-TLS user-certificate: %s " ) , user_cert_error - > message ) ;
2016-06-07 16:53:04 +02:00
ret = FALSE ;
}
2019-10-15 12:25:48 +13:00
widget_set_error ( GTK_WIDGET ( self - > user_cert_button ) ) ;
2014-08-13 13:46:03 +02:00
}
2012-12-09 19:38:32 -05:00
}
2014-08-13 13:46:03 +02:00
return ret ;
2012-12-09 19:38:32 -05:00
}
2016-06-07 12:03:22 +02:00
static void
2019-10-15 11:15:30 +13:00
ca_cert_not_required_toggled ( EAPMethodTLS * self )
2016-06-07 12:03:22 +02:00
{
2021-11-29 10:37:01 -03:00
eap_method_ca_cert_not_required_toggled ( self - > ca_cert_not_required_check ,
ws_file_chooser_button_get_filechooser ( self - > ca_cert_button ) ) ;
2019-11-12 11:20:40 +13:00
eap_method_emit_changed ( EAP_METHOD ( self ) ) ;
2016-06-07 12:03:22 +02:00
}
2012-12-09 19:38:32 -05:00
static void
2019-11-07 10:21:54 +13:00
add_to_size_group ( EAPMethod * method , GtkSizeGroup * group )
2012-12-09 19:38:32 -05:00
{
2019-11-07 10:21:54 +13:00
EAPMethodTLS * self = EAP_METHOD_TLS ( method ) ;
2019-10-15 12:25:48 +13:00
gtk_size_group_add_widget ( group , GTK_WIDGET ( self - > ca_cert_not_required_check ) ) ;
gtk_size_group_add_widget ( group , GTK_WIDGET ( self - > identity_label ) ) ;
gtk_size_group_add_widget ( group , GTK_WIDGET ( self - > user_cert_label ) ) ;
gtk_size_group_add_widget ( group , GTK_WIDGET ( self - > ca_cert_label ) ) ;
gtk_size_group_add_widget ( group , GTK_WIDGET ( self - > private_key_label ) ) ;
gtk_size_group_add_widget ( group , GTK_WIDGET ( self - > private_key_password_label ) ) ;
2012-12-09 19:38:32 -05:00
}
static void
2019-11-07 10:21:54 +13:00
fill_connection ( EAPMethod * method , NMConnection * connection , NMSettingSecretFlags flags )
2012-12-09 19:38:32 -05:00
{
2019-11-07 10:21:54 +13:00
EAPMethodTLS * self = EAP_METHOD_TLS ( method ) ;
2012-12-09 19:38:32 -05:00
NMSetting8021xCKFormat format = NM_SETTING_802_1X_CK_FORMAT_UNKNOWN ;
NMSetting8021x * s_8021x ;
2016-06-07 12:03:22 +02:00
NMSettingSecretFlags secret_flags ;
2019-09-12 11:40:48 +12:00
g_autofree gchar * ca_filename = NULL ;
2021-11-29 10:37:01 -03:00
g_autoptr ( GFile ) ca_file = NULL ;
2019-09-12 11:40:48 +12:00
g_autofree gchar * pk_filename = NULL ;
2021-11-29 10:37:01 -03:00
g_autoptr ( GFile ) pk_file = NULL ;
2012-12-09 19:38:32 -05:00
const char * password = NULL ;
2016-06-07 12:03:22 +02:00
gboolean ca_cert_error = FALSE ;
2019-12-03 14:16:22 +13:00
g_autoptr ( GError ) error = NULL ;
g_autoptr ( GError ) error2 = NULL ;
2012-12-09 19:38:32 -05:00
s_8021x = nm_connection_get_setting_802_1x ( connection ) ;
g_assert ( s_8021x ) ;
2019-12-03 14:16:22 +13:00
nm_setting_802_1x_add_eap_method ( s_8021x , " tls " ) ;
2012-12-09 19:38:32 -05:00
2021-11-29 10:37:01 -03:00
g_object_set ( s_8021x , NM_SETTING_802_1X_IDENTITY , gtk_editable_get_text ( GTK_EDITABLE ( self - > identity_entry ) ) , NULL ) ;
2012-12-09 19:38:32 -05:00
/* TLS private key */
2021-11-29 10:37:01 -03:00
password = gtk_editable_get_text ( GTK_EDITABLE ( self - > private_key_password_entry ) ) ;
2021-01-14 17:14:22 +01:00
secret_flags = nma_utils_menu_to_secret_flags ( GTK_WIDGET ( self - > private_key_password_entry ) ) ;
if ( secret_flags & NM_SETTING_SECRET_FLAG_NOT_SAVED )
password = NULL ;
2019-10-15 12:25:48 +13:00
2021-11-29 10:37:01 -03:00
pk_file = ws_file_chooser_button_get_file ( self - > private_key_button ) ;
g_assert ( pk_file ) ;
pk_filename = g_file_get_path ( pk_file ) ;
2012-12-09 19:38:32 -05:00
2019-12-03 14:16:22 +13:00
if ( ! nm_setting_802_1x_set_private_key ( s_8021x , pk_filename , password , NM_SETTING_802_1X_CK_SCHEME_PATH , & format , & error ) )
g_warning ( " Couldn't read private key '%s': %s " , pk_filename , error ? error - > message : " (unknown) " ) ;
2012-12-09 19:38:32 -05:00
2016-06-07 12:03:22 +02:00
/* Save 802.1X password flags to the connection */
2019-12-03 14:16:22 +13:00
nm_setting_set_secret_flags ( NM_SETTING ( s_8021x ) , NM_SETTING_802_1X_PRIVATE_KEY_PASSWORD ,
2016-06-07 12:03:22 +02:00
secret_flags , NULL ) ;
/* Update secret flags and popup when editing the connection */
2019-12-03 14:16:22 +13:00
nma_utils_update_password_storage ( GTK_WIDGET ( self - > private_key_password_entry ) , secret_flags ,
NM_SETTING ( s_8021x ) , NM_SETTING_802_1X_PRIVATE_KEY_PASSWORD ) ;
2012-12-09 19:38:32 -05:00
/* TLS client certificate */
if ( format ! = NM_SETTING_802_1X_CK_FORMAT_PKCS12 ) {
2019-09-12 11:40:48 +12:00
g_autofree gchar * cc_filename = NULL ;
2021-11-29 10:37:01 -03:00
g_autoptr ( GFile ) cc_file = NULL ;
2019-12-03 14:16:22 +13:00
g_autoptr ( GError ) error = NULL ;
2019-09-12 11:40:48 +12:00
2012-12-09 19:38:32 -05:00
/* If the key is pkcs#12 nm_setting_802_1x_set_private_key() already
* set the client certificate for us .
*/
2021-11-29 10:37:01 -03:00
cc_file = ws_file_chooser_button_get_file ( self - > private_key_button ) ;
g_assert ( cc_file ) ;
cc_filename = g_file_get_path ( cc_file ) ;
2012-12-09 19:38:32 -05:00
format = NM_SETTING_802_1X_CK_FORMAT_UNKNOWN ;
2019-12-03 14:16:22 +13:00
if ( ! nm_setting_802_1x_set_client_cert ( s_8021x , cc_filename , NM_SETTING_802_1X_CK_SCHEME_PATH , & format , & error ) )
g_warning ( " Couldn't read client certificate '%s': %s " , cc_filename , error ? error - > message : " (unknown) " ) ;
2012-12-09 19:38:32 -05:00
}
/* TLS CA certificate */
2021-11-29 10:37:01 -03:00
ca_file = ws_file_chooser_button_get_file ( self - > private_key_button ) ;
ca_filename = ca_file ? g_file_get_path ( ca_file ) : NULL ;
2012-12-09 19:38:32 -05:00
format = NM_SETTING_802_1X_CK_FORMAT_UNKNOWN ;
2019-12-03 14:16:22 +13:00
if ( ! nm_setting_802_1x_set_ca_cert ( s_8021x , ca_filename , NM_SETTING_802_1X_CK_SCHEME_PATH , & format , & error2 ) ) {
g_warning ( " Couldn't read CA certificate '%s': %s " , ca_filename , error2 ? error2 - > message : " (unknown) " ) ;
ca_cert_error = TRUE ;
2012-12-09 19:38:32 -05:00
}
2019-11-07 10:21:54 +13:00
eap_method_ca_cert_ignore_set ( method , connection , ca_filename , ca_cert_error ) ;
2012-12-09 19:38:32 -05:00
}
static void
2019-11-07 10:21:54 +13:00
private_key_picker_helper ( EAPMethodTLS * self , const char * filename , gboolean changed )
2012-12-09 19:38:32 -05:00
{
2019-09-12 11:53:42 +12:00
g_autoptr ( NMSetting8021x ) setting = NULL ;
2012-12-09 19:38:32 -05:00
NMSetting8021xCKFormat cert_format = NM_SETTING_802_1X_CK_FORMAT_UNKNOWN ;
const char * password ;
2021-11-29 10:37:01 -03:00
password = gtk_editable_get_text ( GTK_EDITABLE ( self - > private_key_password_entry ) ) ;
2012-12-09 19:38:32 -05:00
setting = ( NMSetting8021x * ) nm_setting_802_1x_new ( ) ;
nm_setting_802_1x_set_private_key ( setting , filename , password , NM_SETTING_802_1X_CK_SCHEME_PATH , & cert_format , NULL ) ;
/* With PKCS#12, the client cert must be the same as the private key */
if ( cert_format = = NM_SETTING_802_1X_CK_FORMAT_PKCS12 ) {
2021-11-29 10:37:01 -03:00
ws_file_chooser_button_set_file ( self - > user_cert_button , NULL ) ;
2019-10-15 12:25:48 +13:00
gtk_widget_set_sensitive ( GTK_WIDGET ( self - > user_cert_button ) , FALSE ) ;
2012-12-09 19:38:32 -05:00
} else if ( changed )
2019-10-15 12:25:48 +13:00
gtk_widget_set_sensitive ( GTK_WIDGET ( self - > user_cert_button ) , TRUE ) ;
2012-12-09 19:38:32 -05:00
/* Warn the user if the private key is unencrypted */
if ( ! eap_method_is_encrypted_private_key ( filename ) ) {
GtkWidget * dialog ;
2021-11-29 10:37:01 -03:00
GtkNative * native ;
2012-12-09 19:38:32 -05:00
GtkWindow * parent_window = NULL ;
2021-11-29 10:37:01 -03:00
native = gtk_widget_get_native ( GTK_WIDGET ( self ) ) ;
if ( GTK_IS_WINDOW ( native ) )
parent_window = GTK_WINDOW ( native ) ;
2012-12-09 19:38:32 -05:00
dialog = gtk_message_dialog_new ( parent_window ,
GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT ,
GTK_MESSAGE_WARNING ,
GTK_BUTTONS_OK ,
" %s " ,
_ ( " Unencrypted private keys are insecure " ) ) ;
gtk_message_dialog_format_secondary_text ( GTK_MESSAGE_DIALOG ( dialog ) ,
" %s " ,
2017-03-13 14:22:09 +01:00
_ ( " The selected private key does not appear to be protected by a password. This could allow your security credentials to be compromised. Please select a password-protected private key. \n \n (You can password-protect your private key with openssl) " ) ) ;
2021-11-29 10:37:01 -03:00
gtk_window_present ( GTK_WINDOW ( dialog ) ) ;
2012-12-09 19:38:32 -05:00
}
}
static void
2021-11-29 10:37:01 -03:00
private_key_picker_file_set_cb ( WsFileChooserButton * chooser , gpointer user_data )
2012-12-09 19:38:32 -05:00
{
2019-11-07 10:21:54 +13:00
EAPMethodTLS * self = user_data ;
2021-11-29 10:37:01 -03:00
g_autoptr ( GFile ) file = NULL ;
2019-09-12 11:40:48 +12:00
g_autofree gchar * filename = NULL ;
2012-12-09 19:38:32 -05:00
2021-11-29 10:37:01 -03:00
file = ws_file_chooser_button_get_file ( chooser ) ;
filename = file ? g_file_get_path ( file ) : NULL ;
2012-12-09 19:38:32 -05:00
if ( filename )
2019-11-07 10:21:54 +13:00
private_key_picker_helper ( self , filename , TRUE ) ;
2012-12-09 19:38:32 -05:00
}
static void reset_filter ( GtkWidget * widget , GParamSpec * spec , gpointer user_data )
{
if ( ! gtk_file_chooser_get_filter ( GTK_FILE_CHOOSER ( widget ) ) ) {
g_signal_handlers_block_by_func ( widget , reset_filter , user_data ) ;
gtk_file_chooser_set_filter ( GTK_FILE_CHOOSER ( widget ) , GTK_FILE_FILTER ( user_data ) ) ;
g_signal_handlers_unblock_by_func ( widget , reset_filter , user_data ) ;
}
}
typedef const char * ( * PathFunc ) ( NMSetting8021x * setting ) ;
typedef NMSetting8021xCKScheme ( * SchemeFunc ) ( NMSetting8021x * setting ) ;
2019-10-15 10:33:17 +13:00
static void
changed_cb ( EAPMethodTLS * self )
{
2019-11-12 11:20:40 +13:00
eap_method_emit_changed ( EAP_METHOD ( self ) ) ;
2019-10-15 10:33:17 +13:00
}
2012-12-09 19:38:32 -05:00
static void
2019-11-07 10:21:54 +13:00
setup_filepicker ( EAPMethodTLS * self ,
2021-11-29 10:37:01 -03:00
WsFileChooserButton * button ,
2012-12-09 19:38:32 -05:00
const char * title ,
NMSetting8021x * s_8021x ,
SchemeFunc scheme_func ,
PathFunc path_func ,
gboolean privkey ,
gboolean client_cert )
{
GtkFileFilter * filter ;
const char * filename = NULL ;
if ( s_8021x & & path_func & & scheme_func ) {
if ( scheme_func ( s_8021x ) = = NM_SETTING_802_1X_CK_SCHEME_PATH ) {
filename = path_func ( s_8021x ) ;
2021-11-29 10:37:01 -03:00
if ( filename ) {
g_autoptr ( GFile ) file = g_file_new_for_path ( filename ) ;
ws_file_chooser_button_set_file ( button , file ) ;
}
2012-12-09 19:38:32 -05:00
}
}
/* Connect a special handler for private keys to intercept PKCS#12 key types
* and desensitize the user cert button .
*/
if ( privkey ) {
2021-11-29 10:37:01 -03:00
g_signal_connect ( button , " notify::file " ,
G_CALLBACK ( private_key_picker_file_set_cb ) ,
2019-11-07 10:21:54 +13:00
self ) ;
2012-12-09 19:38:32 -05:00
if ( filename )
2019-11-07 10:21:54 +13:00
private_key_picker_helper ( self , filename , FALSE ) ;
2012-12-09 19:38:32 -05:00
}
2021-11-29 10:37:01 -03:00
g_signal_connect_swapped ( button , " notify::file " , G_CALLBACK ( changed_cb ) , self ) ;
2012-12-09 19:38:32 -05:00
filter = eap_method_default_file_chooser_filter_new ( privkey ) ;
2021-11-29 10:37:01 -03:00
gtk_file_chooser_add_filter ( ws_file_chooser_button_get_filechooser ( button ) , filter ) ;
2012-12-09 19:38:32 -05:00
/* For some reason, GTK+ calls set_current_filter (..., NULL) from
* gtkfilechooserdefault . c : : show_and_select_files_finished_loading ( ) on our
* dialog ; so force - reset the filter to what we want it to be whenever
* it gets cleared .
*/
if ( client_cert )
2019-10-02 11:00:21 +13:00
g_signal_connect ( button , " notify::filter " , ( GCallback ) reset_filter , filter ) ;
2012-12-09 19:38:32 -05:00
}
static void
2019-11-07 10:21:54 +13:00
update_secrets ( EAPMethod * method , NMConnection * connection )
2012-12-09 19:38:32 -05:00
{
2019-11-07 10:21:54 +13:00
EAPMethodTLS * self = EAP_METHOD_TLS ( method ) ;
2012-12-09 19:38:32 -05:00
NMSetting8021x * s_8021x ;
const char * filename ;
helper_fill_secret_entry ( connection ,
2019-10-15 12:25:48 +13:00
self - > private_key_password_entry ,
2012-12-09 19:38:32 -05:00
NM_TYPE_SETTING_802_1X ,
2019-12-03 14:16:22 +13:00
( HelperSecretFunc ) nm_setting_802_1x_get_private_key_password ) ;
2012-12-09 19:38:32 -05:00
/* Set the private key filepicker button path if we have a private key */
s_8021x = nm_connection_get_setting_802_1x ( connection ) ;
2019-12-03 14:16:22 +13:00
if ( s_8021x & & ( nm_setting_802_1x_get_private_key_scheme ( s_8021x ) = = NM_SETTING_802_1X_CK_SCHEME_PATH ) ) {
filename = nm_setting_802_1x_get_private_key_path ( s_8021x ) ;
2021-11-29 10:37:01 -03:00
if ( filename ) {
g_autoptr ( GFile ) file = g_file_new_for_path ( filename ) ;
ws_file_chooser_button_set_file ( self - > private_key_button , file ) ;
}
2012-12-09 19:38:32 -05:00
}
}
2019-11-07 09:09:02 +13:00
static GtkWidget *
2019-11-07 10:21:54 +13:00
get_default_field ( EAPMethod * method )
2019-11-07 09:09:02 +13:00
{
2019-11-07 10:21:54 +13:00
EAPMethodTLS * self = EAP_METHOD_TLS ( method ) ;
2019-11-07 09:09:02 +13:00
return GTK_WIDGET ( self - > identity_entry ) ;
}
2019-11-07 10:03:25 +13:00
static const gchar *
2019-11-07 10:21:54 +13:00
get_password_flags_name ( EAPMethod * method )
2019-11-07 10:03:25 +13:00
{
2019-12-03 14:16:22 +13:00
return NM_SETTING_802_1X_PRIVATE_KEY_PASSWORD ;
2019-11-07 10:20:34 +13:00
}
2019-12-02 17:10:24 +13:00
static const gchar *
get_username ( EAPMethod * method )
{
EAPMethodTLS * self = EAP_METHOD_TLS ( method ) ;
return self - > username ;
}
static void
set_username ( EAPMethod * method , const gchar * username )
{
EAPMethodTLS * self = EAP_METHOD_TLS ( method ) ;
g_free ( self - > username ) ;
self - > username = g_strdup ( username ) ;
}
static const gchar *
get_password ( EAPMethod * method )
{
EAPMethodTLS * self = EAP_METHOD_TLS ( method ) ;
return self - > password ;
}
static void
set_password ( EAPMethod * method , const gchar * password )
{
EAPMethodTLS * self = EAP_METHOD_TLS ( method ) ;
g_free ( self - > password ) ;
self - > password = g_strdup ( password ) ;
}
static const gboolean
get_show_password ( EAPMethod * method )
{
EAPMethodTLS * self = EAP_METHOD_TLS ( method ) ;
return self - > show_password ;
}
static void
set_show_password ( EAPMethod * method , gboolean show_password )
{
EAPMethodTLS * self = EAP_METHOD_TLS ( method ) ;
self - > show_password = show_password ;
}
2019-11-07 10:21:54 +13:00
static void
eap_method_tls_init ( EAPMethodTLS * self )
{
2019-11-07 11:35:25 +13:00
gtk_widget_init_template ( GTK_WIDGET ( self ) ) ;
2019-12-02 17:10:24 +13:00
self - > username = g_strdup ( " " ) ;
self - > password = g_strdup ( " " ) ;
2019-11-07 10:21:54 +13:00
}
static void
eap_method_tls_class_init ( EAPMethodTLSClass * klass )
{
2019-12-02 17:10:24 +13:00
GObjectClass * object_class = G_OBJECT_CLASS ( klass ) ;
2019-11-07 11:35:25 +13:00
GtkWidgetClass * widget_class = GTK_WIDGET_CLASS ( klass ) ;
2019-12-02 17:10:24 +13:00
object_class - > dispose = eap_method_tls_dispose ;
2021-11-29 10:37:01 -03:00
g_type_ensure ( WS_TYPE_FILE_CHOOSER_BUTTON ) ;
2022-01-20 00:02:02 -03:00
gtk_widget_class_set_template_from_resource ( widget_class , " /org/gnome/Settings/network/eap-method-tls.ui " ) ;
2019-11-07 11:35:25 +13:00
gtk_widget_class_bind_template_child ( widget_class , EAPMethodTLS , ca_cert_button ) ;
gtk_widget_class_bind_template_child ( widget_class , EAPMethodTLS , ca_cert_label ) ;
gtk_widget_class_bind_template_child ( widget_class , EAPMethodTLS , ca_cert_not_required_check ) ;
gtk_widget_class_bind_template_child ( widget_class , EAPMethodTLS , identity_entry ) ;
gtk_widget_class_bind_template_child ( widget_class , EAPMethodTLS , identity_label ) ;
gtk_widget_class_bind_template_child ( widget_class , EAPMethodTLS , private_key_button ) ;
gtk_widget_class_bind_template_child ( widget_class , EAPMethodTLS , private_key_label ) ;
gtk_widget_class_bind_template_child ( widget_class , EAPMethodTLS , private_key_password_entry ) ;
gtk_widget_class_bind_template_child ( widget_class , EAPMethodTLS , private_key_password_label ) ;
gtk_widget_class_bind_template_child ( widget_class , EAPMethodTLS , show_password_check ) ;
gtk_widget_class_bind_template_child ( widget_class , EAPMethodTLS , user_cert_button ) ;
gtk_widget_class_bind_template_child ( widget_class , EAPMethodTLS , user_cert_label ) ;
2019-11-07 10:21:54 +13:00
}
static void
eap_method_iface_init ( EAPMethodInterface * iface )
{
iface - > validate = validate ;
iface - > add_to_size_group = add_to_size_group ;
iface - > fill_connection = fill_connection ;
iface - > update_secrets = update_secrets ;
iface - > get_default_field = get_default_field ;
iface - > get_password_flags_name = get_password_flags_name ;
2019-12-02 17:10:24 +13:00
iface - > get_username = get_username ;
iface - > set_username = set_username ;
iface - > get_password = get_password ;
iface - > set_password = set_password ;
iface - > get_show_password = get_show_password ;
iface - > set_show_password = set_show_password ;
2019-11-07 10:21:54 +13:00
}
2012-12-09 19:38:32 -05:00
EAPMethodTLS *
2019-12-03 14:16:22 +13:00
eap_method_tls_new ( NMConnection * connection )
2012-12-09 19:38:32 -05:00
{
2019-10-18 11:47:17 +13:00
EAPMethodTLS * self ;
2012-12-09 19:38:32 -05:00
NMSetting8021x * s_8021x = NULL ;
2016-06-07 12:03:22 +02:00
gboolean ca_not_required = FALSE ;
2012-12-09 19:38:32 -05:00
2019-11-07 10:21:54 +13:00
self = g_object_new ( eap_method_tls_get_type ( ) , NULL ) ;
2019-10-18 11:47:17 +13:00
2012-12-09 19:38:32 -05:00
if ( connection )
s_8021x = nm_connection_get_setting_802_1x ( connection ) ;
2019-10-18 11:47:17 +13:00
g_signal_connect_swapped ( self - > ca_cert_not_required_check , " toggled " , G_CALLBACK ( ca_cert_not_required_toggled ) , self ) ;
2016-06-07 12:03:22 +02:00
2019-10-18 11:47:17 +13:00
g_signal_connect_swapped ( self - > identity_entry , " changed " , G_CALLBACK ( changed_cb ) , self ) ;
2012-12-09 19:38:32 -05:00
if ( s_8021x & & nm_setting_802_1x_get_identity ( s_8021x ) )
2021-11-29 10:37:01 -03:00
gtk_editable_set_text ( GTK_EDITABLE ( self - > identity_entry ) , nm_setting_802_1x_get_identity ( s_8021x ) ) ;
2012-12-09 19:38:32 -05:00
2019-11-07 10:21:54 +13:00
setup_filepicker ( self ,
self - > user_cert_button ,
2014-07-24 13:19:09 +02:00
_ ( " Choose your personal certificate " ) ,
2019-12-02 15:57:54 +13:00
s_8021x ,
2019-12-03 14:16:22 +13:00
nm_setting_802_1x_get_client_cert_scheme ,
nm_setting_802_1x_get_client_cert_path ,
2012-12-09 19:38:32 -05:00
FALSE , TRUE ) ;
2019-11-07 10:21:54 +13:00
setup_filepicker ( self ,
self - > ca_cert_button ,
2014-07-24 13:19:09 +02:00
_ ( " Choose a Certificate Authority certificate " ) ,
2019-12-02 15:57:54 +13:00
s_8021x ,
2019-12-03 14:16:22 +13:00
nm_setting_802_1x_get_ca_cert_scheme ,
nm_setting_802_1x_get_ca_cert_path ,
2012-12-09 19:38:32 -05:00
FALSE , FALSE ) ;
2019-11-07 10:21:54 +13:00
setup_filepicker ( self ,
self - > private_key_button ,
2014-07-24 13:19:09 +02:00
_ ( " Choose your private key " ) ,
2019-12-02 15:57:54 +13:00
s_8021x ,
2019-12-03 14:16:22 +13:00
nm_setting_802_1x_get_private_key_scheme ,
nm_setting_802_1x_get_private_key_path ,
2012-12-09 19:38:32 -05:00
TRUE , FALSE ) ;
2021-11-29 10:37:01 -03:00
if ( connection & & eap_method_ca_cert_ignore_get ( EAP_METHOD ( self ) , connection ) ) {
g_autoptr ( GFile ) file = ws_file_chooser_button_get_file ( self - > ca_cert_button ) ;
ca_not_required = ! file ;
}
gtk_check_button_set_active ( self - > ca_cert_not_required_check , ca_not_required ) ;
2016-06-07 12:03:22 +02:00
2012-12-09 19:38:32 -05:00
/* Fill secrets, if any */
if ( connection )
2019-11-07 10:21:54 +13:00
update_secrets ( EAP_METHOD ( self ) , connection ) ;
2012-12-09 19:38:32 -05:00
2019-10-18 11:47:17 +13:00
g_signal_connect_swapped ( self - > private_key_password_entry , " changed " , G_CALLBACK ( changed_cb ) , self ) ;
2012-12-09 19:38:32 -05:00
2016-06-07 12:03:22 +02:00
/* Create password-storage popup menu for password entry under entry's secondary icon */
2019-12-03 14:16:22 +13:00
nma_utils_setup_password_storage ( GTK_WIDGET ( self - > private_key_password_entry ) , 0 , ( NMSetting * ) s_8021x , NM_SETTING_802_1X_PRIVATE_KEY_PASSWORD ,
FALSE , FALSE ) ;
2016-06-07 12:03:22 +02:00
2019-10-18 11:47:17 +13:00
g_signal_connect_swapped ( self - > show_password_check , " toggled " , G_CALLBACK ( show_toggled_cb ) , self ) ;
2012-12-09 19:38:32 -05:00
2019-10-18 11:47:17 +13:00
return self ;
2012-12-09 19:38:32 -05:00
}