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
*/
2016-06-07 12:03:22 +02:00
# include "nm-default.h"
2012-12-09 19:38:32 -05:00
# include <ctype.h>
# include <string.h>
# 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 "wireless-security.h"
# include "helpers.h"
2016-06-07 12:03:22 +02:00
# include "nma-ui-utils.h"
# include "utils.h"
2012-12-09 19:38:32 -05:00
struct _EAPMethodTLS {
EAPMethod parent ;
2019-11-07 09:26:20 +13:00
GtkBuilder * builder ;
2019-10-15 12:25:48 +13:00
GtkFileChooserButton * ca_cert_button ;
GtkLabel * ca_cert_label ;
GtkCheckButton * ca_cert_not_required_check ;
2019-11-07 09:09:02 +13:00
GtkGrid * grid ;
2019-10-15 12:25:48 +13:00
GtkEntry * identity_entry ;
GtkLabel * identity_label ;
GtkFileChooserButton * private_key_button ;
GtkLabel * private_key_label ;
GtkEntry * private_key_password_entry ;
GtkLabel * private_key_password_label ;
GtkCheckButton * show_password_check ;
GtkFileChooserButton * user_cert_button ;
GtkLabel * user_cert_label ;
2019-11-07 10:20:34 +13:00
gboolean phase2 ;
2019-11-07 10:03:25 +13:00
const gchar * password_flags_name ;
2019-10-15 10:33:17 +13:00
WirelessSecurity * sec_parent ;
2016-06-07 12:03:22 +02:00
gboolean editing_connection ;
2012-12-09 19:38:32 -05:00
} ;
2019-11-07 09:26:20 +13:00
static void
destroy ( EAPMethod * parent )
{
EAPMethodTLS * self = ( EAPMethodTLS * ) parent ;
g_clear_object ( & self - > builder ) ;
}
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 ;
2019-10-15 12:25:48 +13:00
visible = gtk_toggle_button_get_active ( GTK_TOGGLE_BUTTON ( self - > show_password_check ) ) ;
gtk_entry_set_visibility ( self - > private_key_password_entry , visible ) ;
2012-12-09 19:38:32 -05:00
}
static gboolean
2016-06-07 12:03:22 +02:00
validate ( EAPMethod * parent , GError * * error )
2012-12-09 19:38:32 -05:00
{
2019-10-15 12:25:48 +13:00
EAPMethodTLS * self = ( EAPMethodTLS * ) parent ;
2012-12-09 19:38:32 -05:00
NMSetting8021xCKFormat format = NM_SETTING_802_1X_CK_FORMAT_UNKNOWN ;
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
2019-10-15 12:25:48 +13:00
identity = gtk_entry_get_text ( 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
2019-10-15 12:25:48 +13:00
if ( ! eap_method_validate_filepicker ( GTK_FILE_CHOOSER ( 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 ;
}
2019-10-15 12:25:48 +13:00
} else if ( eap_method_ca_cert_required ( GTK_TOGGLE_BUTTON ( self - > ca_cert_not_required_check ) ,
GTK_FILE_CHOOSER ( self - > ca_cert_button ) ) ) {
widget_set_error ( GTK_WIDGET ( self - > ca_cert_button ) ) ;
2016-06-07 16:53:04 +02:00
if ( ret ) {
2016-06-07 12:03:22 +02:00
g_set_error_literal ( error , NMA_ERROR , NMA_ERROR_GENERIC , _ ( " invalid EAP-TLS CA certificate: no certificate specified " ) ) ;
2016-06-07 16:53:04 +02:00
ret = FALSE ;
}
2014-08-13 13:46:03 +02:00
}
2012-12-09 19:38:32 -05:00
2019-10-15 12:25:48 +13:00
password = gtk_entry_get_text ( self - > private_key_password_entry ) ;
2012-12-09 19:38:32 -05:00
2019-10-15 12:25:48 +13:00
if ( ! eap_method_validate_filepicker ( GTK_FILE_CHOOSER ( 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 ) {
2019-10-15 12:25:48 +13:00
if ( ! eap_method_validate_filepicker ( GTK_FILE_CHOOSER ( 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
{
2019-10-15 12:25:48 +13:00
eap_method_ca_cert_not_required_toggled ( GTK_TOGGLE_BUTTON ( self - > ca_cert_not_required_check ) ,
GTK_FILE_CHOOSER ( self - > ca_cert_button ) ) ;
2019-10-15 15:19:35 +13:00
wireless_security_notify_changed ( self - > sec_parent ) ;
2016-06-07 12:03:22 +02:00
}
2012-12-09 19:38:32 -05:00
static void
add_to_size_group ( EAPMethod * parent , GtkSizeGroup * group )
{
2019-10-15 12:25:48 +13:00
EAPMethodTLS * self = ( EAPMethodTLS * ) parent ;
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
2016-06-07 12:03:22 +02:00
fill_connection ( EAPMethod * parent , NMConnection * connection , NMSettingSecretFlags flags )
2012-12-09 19:38:32 -05:00
{
2019-10-18 11:47:17 +13:00
EAPMethodTLS * self = ( EAPMethodTLS * ) parent ;
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 ;
g_autofree gchar * pk_filename = 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 ;
2012-12-09 19:38:32 -05:00
s_8021x = nm_connection_get_setting_802_1x ( connection ) ;
g_assert ( s_8021x ) ;
2019-11-07 10:20:34 +13:00
if ( self - > phase2 )
2012-12-09 19:38:32 -05:00
g_object_set ( s_8021x , NM_SETTING_802_1X_PHASE2_AUTH , " tls " , NULL ) ;
else
nm_setting_802_1x_add_eap_method ( s_8021x , " tls " ) ;
2019-10-18 11:47:17 +13:00
g_object_set ( s_8021x , NM_SETTING_802_1X_IDENTITY , gtk_entry_get_text ( self - > identity_entry ) , NULL ) ;
2012-12-09 19:38:32 -05:00
/* TLS private key */
2019-10-18 11:47:17 +13:00
password = gtk_entry_get_text ( self - > private_key_password_entry ) ;
2019-10-15 12:25:48 +13:00
2019-10-18 11:47:17 +13:00
pk_filename = gtk_file_chooser_get_filename ( GTK_FILE_CHOOSER ( self - > private_key_button ) ) ;
2012-12-09 19:38:32 -05:00
g_assert ( pk_filename ) ;
2019-11-07 10:20:34 +13:00
if ( self - > phase2 ) {
2019-09-12 10:54:37 +12:00
g_autoptr ( GError ) error = NULL ;
if ( ! nm_setting_802_1x_set_phase2_private_key ( s_8021x , pk_filename , password , NM_SETTING_802_1X_CK_SCHEME_PATH , & format , & error ) )
2012-12-09 19:38:32 -05:00
g_warning ( " Couldn't read phase2 private key '%s': %s " , pk_filename , error ? error - > message : " (unknown) " ) ;
} else {
2019-09-12 10:54:37 +12:00
g_autoptr ( GError ) error = NULL ;
if ( ! nm_setting_802_1x_set_private_key ( s_8021x , pk_filename , password , NM_SETTING_802_1X_CK_SCHEME_PATH , & format , & error ) )
2012-12-09 19:38:32 -05:00
g_warning ( " Couldn't read private key '%s': %s " , pk_filename , error ? error - > message : " (unknown) " ) ;
}
2016-06-07 12:03:22 +02:00
/* Save 802.1X password flags to the connection */
2019-10-18 11:47:17 +13:00
secret_flags = nma_utils_menu_to_secret_flags ( GTK_WIDGET ( self - > private_key_password_entry ) ) ;
2019-11-07 10:03:25 +13:00
nm_setting_set_secret_flags ( NM_SETTING ( s_8021x ) , self - > password_flags_name ,
2016-06-07 12:03:22 +02:00
secret_flags , NULL ) ;
/* Update secret flags and popup when editing the connection */
2019-10-18 11:47:17 +13:00
if ( self - > editing_connection ) {
nma_utils_update_password_storage ( GTK_WIDGET ( self - > private_key_password_entry ) , secret_flags ,
2019-11-07 10:03:25 +13:00
NM_SETTING ( s_8021x ) , self - > password_flags_name ) ;
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 ;
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 .
*/
2019-10-18 11:47:17 +13:00
cc_filename = gtk_file_chooser_get_filename ( GTK_FILE_CHOOSER ( self - > user_cert_button ) ) ;
2012-12-09 19:38:32 -05:00
g_assert ( cc_filename ) ;
format = NM_SETTING_802_1X_CK_FORMAT_UNKNOWN ;
2019-11-07 10:20:34 +13:00
if ( self - > phase2 ) {
2019-09-12 10:54:37 +12:00
g_autoptr ( GError ) error = NULL ;
if ( ! nm_setting_802_1x_set_phase2_client_cert ( s_8021x , cc_filename , NM_SETTING_802_1X_CK_SCHEME_PATH , & format , & error ) )
2012-12-09 19:38:32 -05:00
g_warning ( " Couldn't read phase2 client certificate '%s': %s " , cc_filename , error ? error - > message : " (unknown) " ) ;
} else {
2019-09-12 10:54:37 +12:00
g_autoptr ( GError ) error = NULL ;
if ( ! nm_setting_802_1x_set_client_cert ( s_8021x , cc_filename , NM_SETTING_802_1X_CK_SCHEME_PATH , & format , & error ) )
2012-12-09 19:38:32 -05:00
g_warning ( " Couldn't read client certificate '%s': %s " , cc_filename , error ? error - > message : " (unknown) " ) ;
}
}
/* TLS CA certificate */
2019-10-18 11:47:17 +13:00
ca_filename = gtk_file_chooser_get_filename ( GTK_FILE_CHOOSER ( self - > ca_cert_button ) ) ;
2012-12-09 19:38:32 -05:00
format = NM_SETTING_802_1X_CK_FORMAT_UNKNOWN ;
2019-11-07 10:20:34 +13:00
if ( self - > phase2 ) {
2019-09-12 10:54:37 +12:00
g_autoptr ( GError ) error = NULL ;
2012-12-09 19:38:32 -05:00
if ( ! nm_setting_802_1x_set_phase2_ca_cert ( s_8021x , ca_filename , NM_SETTING_802_1X_CK_SCHEME_PATH , & format , & error ) ) {
g_warning ( " Couldn't read phase2 CA certificate '%s': %s " , ca_filename , error ? error - > message : " (unknown) " ) ;
2016-06-07 12:03:22 +02:00
ca_cert_error = TRUE ;
2012-12-09 19:38:32 -05:00
}
} else {
2019-09-12 10:54:37 +12:00
g_autoptr ( GError ) error = NULL ;
2012-12-09 19:38:32 -05:00
if ( ! nm_setting_802_1x_set_ca_cert ( s_8021x , ca_filename , NM_SETTING_802_1X_CK_SCHEME_PATH , & format , & error ) ) {
g_warning ( " Couldn't read CA certificate '%s': %s " , ca_filename , error ? error - > message : " (unknown) " ) ;
2016-06-07 12:03:22 +02:00
ca_cert_error = TRUE ;
2012-12-09 19:38:32 -05:00
}
}
2016-06-07 12:03:22 +02:00
eap_method_ca_cert_ignore_set ( parent , connection , ca_filename , ca_cert_error ) ;
2012-12-09 19:38:32 -05:00
}
static void
private_key_picker_helper ( EAPMethod * parent , const char * filename , gboolean changed )
{
2019-10-15 12:25:48 +13:00
EAPMethodTLS * self = ( EAPMethodTLS * ) parent ;
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 ;
2019-10-15 12:25:48 +13:00
password = gtk_entry_get_text ( 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 ) {
2019-10-15 12:25:48 +13:00
gtk_file_chooser_unselect_all ( GTK_FILE_CHOOSER ( self - > user_cert_button ) ) ;
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 ;
GtkWidget * toplevel ;
GtkWindow * parent_window = NULL ;
2019-11-07 09:09:02 +13:00
toplevel = gtk_widget_get_toplevel ( GTK_WIDGET ( self - > grid ) ) ;
2012-12-09 19:38:32 -05:00
if ( gtk_widget_is_toplevel ( toplevel ) )
parent_window = GTK_WINDOW ( toplevel ) ;
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) " ) ) ;
2012-12-09 19:38:32 -05:00
gtk_dialog_run ( GTK_DIALOG ( dialog ) ) ;
gtk_widget_destroy ( dialog ) ;
}
}
static void
private_key_picker_file_set_cb ( GtkWidget * chooser , gpointer user_data )
{
EAPMethod * parent = ( EAPMethod * ) user_data ;
2019-09-12 11:40:48 +12:00
g_autofree gchar * filename = NULL ;
2012-12-09 19:38:32 -05:00
filename = gtk_file_chooser_get_filename ( GTK_FILE_CHOOSER ( chooser ) ) ;
if ( filename )
private_key_picker_helper ( parent , filename , TRUE ) ;
}
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 )
{
wireless_security_notify_changed ( self - > sec_parent ) ;
}
2012-12-09 19:38:32 -05:00
static void
2019-10-02 11:00:21 +13:00
setup_filepicker ( GtkFileChooserButton * button ,
2012-12-09 19:38:32 -05:00
const char * title ,
WirelessSecurity * ws_parent ,
EAPMethod * parent ,
NMSetting8021x * s_8021x ,
SchemeFunc scheme_func ,
PathFunc path_func ,
gboolean privkey ,
gboolean client_cert )
{
GtkFileFilter * filter ;
const char * filename = NULL ;
2019-10-02 11:00:21 +13:00
gtk_file_chooser_set_local_only ( GTK_FILE_CHOOSER ( button ) , TRUE ) ;
gtk_file_chooser_button_set_title ( button , title ) ;
2012-12-09 19:38:32 -05:00
if ( s_8021x & & path_func & & scheme_func ) {
if ( scheme_func ( s_8021x ) = = NM_SETTING_802_1X_CK_SCHEME_PATH ) {
filename = path_func ( s_8021x ) ;
if ( filename )
2019-10-02 11:00:21 +13:00
gtk_file_chooser_set_filename ( GTK_FILE_CHOOSER ( button ) , filename ) ;
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 ) {
2019-10-02 11:00:21 +13:00
g_signal_connect ( button , " selection-changed " ,
2012-12-09 19:38:32 -05:00
( GCallback ) private_key_picker_file_set_cb ,
parent ) ;
if ( filename )
private_key_picker_helper ( parent , filename , FALSE ) ;
}
2019-10-15 10:33:17 +13:00
g_signal_connect_swapped ( button , " selection-changed " , G_CALLBACK ( changed_cb ) , parent ) ;
2012-12-09 19:38:32 -05:00
filter = eap_method_default_file_chooser_filter_new ( privkey ) ;
2019-10-02 11:00:21 +13:00
gtk_file_chooser_add_filter ( GTK_FILE_CHOOSER ( 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
update_secrets ( EAPMethod * parent , NMConnection * connection )
{
2019-10-15 12:25:48 +13:00
EAPMethodTLS * self = ( EAPMethodTLS * ) parent ;
2012-12-09 19:38:32 -05:00
NMSetting8021x * s_8021x ;
HelperSecretFunc password_func ;
SchemeFunc scheme_func ;
PathFunc path_func ;
const char * filename ;
2019-11-07 10:20:34 +13:00
if ( self - > phase2 ) {
2012-12-09 19:38:32 -05:00
password_func = ( HelperSecretFunc ) nm_setting_802_1x_get_phase2_private_key_password ;
scheme_func = nm_setting_802_1x_get_phase2_private_key_scheme ;
path_func = nm_setting_802_1x_get_phase2_private_key_path ;
} else {
password_func = ( HelperSecretFunc ) nm_setting_802_1x_get_private_key_password ;
scheme_func = nm_setting_802_1x_get_private_key_scheme ;
path_func = nm_setting_802_1x_get_private_key_path ;
}
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 ,
password_func ) ;
/* Set the private key filepicker button path if we have a private key */
s_8021x = nm_connection_get_setting_802_1x ( connection ) ;
if ( s_8021x & & ( scheme_func ( s_8021x ) = = NM_SETTING_802_1X_CK_SCHEME_PATH ) ) {
filename = path_func ( s_8021x ) ;
2019-10-15 12:25:48 +13:00
if ( filename )
gtk_file_chooser_set_filename ( GTK_FILE_CHOOSER ( self - > private_key_button ) , filename ) ;
2012-12-09 19:38:32 -05:00
}
}
2019-11-07 09:09:02 +13:00
static GtkWidget *
get_widget ( EAPMethod * parent )
{
EAPMethodTLS * self = ( EAPMethodTLS * ) parent ;
return GTK_WIDGET ( self - > grid ) ;
}
static GtkWidget *
get_default_field ( EAPMethod * parent )
{
EAPMethodTLS * self = ( EAPMethodTLS * ) parent ;
return GTK_WIDGET ( self - > identity_entry ) ;
}
2019-11-07 10:03:25 +13:00
static const gchar *
get_password_flags_name ( EAPMethod * parent )
{
EAPMethodTLS * self = ( EAPMethodTLS * ) parent ;
return self - > password_flags_name ;
}
2019-11-07 10:20:34 +13:00
static gboolean
get_phase2 ( EAPMethod * parent )
{
EAPMethodTLS * self = ( EAPMethodTLS * ) parent ;
return self - > phase2 ;
}
2012-12-09 19:38:32 -05:00
EAPMethodTLS *
eap_method_tls_new ( WirelessSecurity * ws_parent ,
NMConnection * connection ,
gboolean phase2 ,
gboolean secrets_only )
{
2019-10-18 11:47:17 +13:00
EAPMethodTLS * self ;
2012-12-09 19:38:32 -05:00
EAPMethod * parent ;
NMSetting8021x * s_8021x = NULL ;
2016-06-07 12:03:22 +02:00
gboolean ca_not_required = FALSE ;
2019-11-07 09:26:20 +13:00
g_autoptr ( GError ) error = NULL ;
2012-12-09 19:38:32 -05:00
parent = eap_method_init ( sizeof ( EAPMethodTLS ) ,
validate ,
add_to_size_group ,
fill_connection ,
update_secrets ,
2019-11-07 09:09:02 +13:00
get_widget ,
get_default_field ,
2019-11-07 10:03:25 +13:00
get_password_flags_name ,
2019-11-07 10:20:34 +13:00
get_phase2 ,
destroy ) ;
2012-12-09 19:38:32 -05:00
if ( ! parent )
return NULL ;
2019-10-18 11:47:17 +13:00
self = ( EAPMethodTLS * ) parent ;
2019-11-07 10:20:34 +13:00
self - > phase2 = phase2 ;
2019-11-07 10:03:25 +13:00
self - > password_flags_name = phase2 ?
NM_SETTING_802_1X_PHASE2_PRIVATE_KEY_PASSWORD :
NM_SETTING_802_1X_PRIVATE_KEY_PASSWORD ;
2019-10-18 11:47:17 +13:00
self - > sec_parent = ws_parent ;
self - > editing_connection = secrets_only ? FALSE : TRUE ;
2019-11-07 09:26:20 +13:00
self - > builder = gtk_builder_new ( ) ;
if ( ! gtk_builder_add_from_resource ( self - > builder , " /org/gnome/ControlCenter/network/eap-method-tls.ui " , & error ) ) {
g_warning ( " Couldn't load UI builder resource: %s " , error - > message ) ;
return NULL ;
}
self - > ca_cert_button = GTK_FILE_CHOOSER_BUTTON ( gtk_builder_get_object ( self - > builder , " ca_cert_button " ) ) ;
self - > ca_cert_label = GTK_LABEL ( gtk_builder_get_object ( self - > builder , " ca_cert_label " ) ) ;
self - > ca_cert_not_required_check = GTK_CHECK_BUTTON ( gtk_builder_get_object ( self - > builder , " ca_cert_not_required_check " ) ) ;
self - > grid = GTK_GRID ( gtk_builder_get_object ( self - > builder , " grid " ) ) ;
self - > identity_entry = GTK_ENTRY ( gtk_builder_get_object ( self - > builder , " identity_entry " ) ) ;
self - > identity_label = GTK_LABEL ( gtk_builder_get_object ( self - > builder , " identity_label " ) ) ;
self - > private_key_button = GTK_FILE_CHOOSER_BUTTON ( gtk_builder_get_object ( self - > builder , " private_key_button " ) ) ;
self - > private_key_label = GTK_LABEL ( gtk_builder_get_object ( self - > builder , " private_key_label " ) ) ;
self - > private_key_password_entry = GTK_ENTRY ( gtk_builder_get_object ( self - > builder , " private_key_password_entry " ) ) ;
self - > private_key_password_label = GTK_LABEL ( gtk_builder_get_object ( self - > builder , " private_key_password_label " ) ) ;
self - > show_password_check = GTK_CHECK_BUTTON ( gtk_builder_get_object ( self - > builder , " show_password_check " ) ) ;
self - > user_cert_button = GTK_FILE_CHOOSER_BUTTON ( gtk_builder_get_object ( self - > builder , " user_cert_button " ) ) ;
self - > user_cert_label = GTK_LABEL ( gtk_builder_get_object ( self - > builder , " user_cert_label " ) ) ;
2019-10-15 12:25:48 +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 ) )
2019-10-18 11:47:17 +13:00
gtk_entry_set_text ( self - > identity_entry , nm_setting_802_1x_get_identity ( s_8021x ) ) ;
2012-12-09 19:38:32 -05:00
2019-10-18 11:47:17 +13:00
setup_filepicker ( self - > user_cert_button ,
2014-07-24 13:19:09 +02:00
_ ( " Choose your personal certificate " ) ,
2012-12-09 19:38:32 -05:00
ws_parent , parent , s_8021x ,
phase2 ? nm_setting_802_1x_get_phase2_client_cert_scheme : nm_setting_802_1x_get_client_cert_scheme ,
phase2 ? nm_setting_802_1x_get_phase2_client_cert_path : nm_setting_802_1x_get_client_cert_path ,
FALSE , TRUE ) ;
2019-10-18 11:47:17 +13:00
setup_filepicker ( self - > ca_cert_button ,
2014-07-24 13:19:09 +02:00
_ ( " Choose a Certificate Authority certificate " ) ,
2012-12-09 19:38:32 -05:00
ws_parent , parent , s_8021x ,
phase2 ? nm_setting_802_1x_get_phase2_ca_cert_scheme : nm_setting_802_1x_get_ca_cert_scheme ,
phase2 ? nm_setting_802_1x_get_phase2_ca_cert_path : nm_setting_802_1x_get_ca_cert_path ,
FALSE , FALSE ) ;
2019-10-18 11:47:17 +13:00
setup_filepicker ( self - > private_key_button ,
2014-07-24 13:19:09 +02:00
_ ( " Choose your private key " ) ,
2012-12-09 19:38:32 -05:00
ws_parent , parent , s_8021x ,
phase2 ? nm_setting_802_1x_get_phase2_private_key_scheme : nm_setting_802_1x_get_private_key_scheme ,
phase2 ? nm_setting_802_1x_get_phase2_private_key_path : nm_setting_802_1x_get_private_key_path ,
TRUE , FALSE ) ;
2019-10-15 12:25:48 +13:00
if ( connection & & eap_method_ca_cert_ignore_get ( parent , connection ) )
2019-10-18 11:47:17 +13:00
ca_not_required = ! gtk_file_chooser_get_filename ( GTK_FILE_CHOOSER ( self - > ca_cert_button ) ) ;
gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON ( 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 )
update_secrets ( parent , connection ) ;
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-11-07 10:03:25 +13:00
nma_utils_setup_password_storage ( GTK_WIDGET ( self - > private_key_password_entry ) , 0 , ( NMSetting * ) s_8021x , self - > password_flags_name ,
2016-06-07 12:03:22 +02:00
FALSE , secrets_only ) ;
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
if ( secrets_only ) {
2019-10-18 11:47:17 +13:00
gtk_widget_set_sensitive ( GTK_WIDGET ( self - > identity_entry ) , FALSE ) ;
gtk_widget_hide ( GTK_WIDGET ( self - > user_cert_label ) ) ;
gtk_widget_hide ( GTK_WIDGET ( self - > user_cert_button ) ) ;
gtk_widget_hide ( GTK_WIDGET ( self - > private_key_label ) ) ;
gtk_widget_hide ( GTK_WIDGET ( self - > private_key_button ) ) ;
gtk_widget_hide ( GTK_WIDGET ( self - > ca_cert_label ) ) ;
gtk_widget_hide ( GTK_WIDGET ( self - > ca_cert_button ) ) ;
gtk_widget_hide ( GTK_WIDGET ( self - > ca_cert_not_required_check ) ) ;
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
}