Stepan Salenikovich | 7a1e71c | 2015-05-07 11:14:48 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 Savoir-Faire Linux Inc. |
| 3 | * Author: Stepan Salenikovich <stepan.salenikovich@savoirfairelinux.com> |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 3 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | * |
| 19 | * Additional permission under GNU GPL version 3 section 7: |
| 20 | * |
| 21 | * If you modify this program, or any covered work, by linking or |
| 22 | * combining it with the OpenSSL project's OpenSSL library (or a |
| 23 | * modified version of that library), containing parts covered by the |
| 24 | * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc. |
| 25 | * grants you additional permission to convey the resulting work. |
| 26 | * Corresponding Source for a non-source form of such a combination |
| 27 | * shall include the source code for the parts of OpenSSL used as well |
| 28 | * as that of the covered work. |
| 29 | */ |
| 30 | |
| 31 | #include "accountsecuritytab.h" |
| 32 | |
| 33 | #include <gtk/gtk.h> |
| 34 | #include <account.h> |
| 35 | #include "models/activeitemproxymodel.h" |
| 36 | #include "models/gtkqsortfiltertreemodel.h" |
| 37 | #include "models/gtkqtreemodel.h" |
| 38 | #include "utils/models.h" |
| 39 | #include <certificate.h> |
| 40 | #include <ciphermodel.h> |
| 41 | #include <QtCore/QItemSelectionModel> |
| 42 | |
| 43 | struct _AccountSecurityTab |
| 44 | { |
| 45 | GtkBox parent; |
| 46 | }; |
| 47 | |
| 48 | struct _AccountSecurityTabClass |
| 49 | { |
| 50 | GtkBoxClass parent_class; |
| 51 | }; |
| 52 | |
| 53 | typedef struct _AccountSecurityTabPrivate AccountSecurityTabPrivate; |
| 54 | |
| 55 | struct _AccountSecurityTabPrivate |
| 56 | { |
| 57 | Account *account; |
| 58 | GtkWidget *checkbutton_use_srtp; |
| 59 | GtkWidget *box_key_exchange; |
| 60 | GtkWidget *combobox_key_exchange; |
| 61 | GtkWidget *checkbutton_srtp_fallback; |
| 62 | GtkWidget *checkbutton_use_tls; |
| 63 | GtkWidget *grid_tls_settings_0; |
| 64 | GtkWidget *filechooserbutton_ca_list; |
| 65 | /* TODO: add when implemented |
| 66 | GtkWidget *button_view_ca; |
| 67 | GtkWidget *button_view_certificate; |
| 68 | */ |
| 69 | GtkWidget *filechooserbutton_certificate; |
| 70 | GtkWidget *filechooserbutton_private_key; |
| 71 | GtkWidget *entry_password; |
| 72 | GtkWidget *grid_tls_settings_1; |
| 73 | GtkWidget *combobox_tls_protocol_method; |
| 74 | GtkWidget *entry_tls_server_name; |
| 75 | GtkWidget *adjustment_tls_timeout; |
| 76 | GtkWidget *buttonbox_cipher_list; |
| 77 | GtkWidget *radiobutton_use_default_ciphers; |
| 78 | GtkWidget *radiobutton_custom_ciphers; |
| 79 | GtkWidget *revealer_cipher_list; |
| 80 | GtkWidget *treeview_cipher_list; |
| 81 | GtkWidget *checkbutton_verify_certs_server; |
| 82 | GtkWidget *checkbutton_verify_certs_client; |
| 83 | GtkWidget *checkbutton_require_incoming_tls_certs; |
| 84 | |
| 85 | QMetaObject::Connection account_updated; |
| 86 | QMetaObject::Connection key_exchange_selection; |
| 87 | QMetaObject::Connection tls_method_selection; |
| 88 | |
| 89 | ActiveItemProxyModel *qmodel_key_exchange; |
| 90 | }; |
| 91 | |
| 92 | G_DEFINE_TYPE_WITH_PRIVATE(AccountSecurityTab, account_security_tab, GTK_TYPE_BOX); |
| 93 | |
| 94 | #define ACCOUNT_SECURITY_TAB_GET_PRIVATE(obj) \ |
| 95 | (G_TYPE_INSTANCE_GET_PRIVATE ((obj), ACCOUNT_SECURITY_TAB_TYPE, \ |
| 96 | AccountSecurityTabPrivate)) |
| 97 | |
| 98 | static void |
| 99 | account_security_tab_dispose(GObject *object) |
| 100 | { |
| 101 | AccountSecurityTab *view = ACCOUNT_SECURITY_TAB(object); |
| 102 | AccountSecurityTabPrivate *priv = ACCOUNT_SECURITY_TAB_GET_PRIVATE(view); |
| 103 | |
| 104 | QObject::disconnect(priv->account_updated); |
| 105 | QObject::disconnect(priv->key_exchange_selection); |
| 106 | QObject::disconnect(priv->tls_method_selection); |
| 107 | |
| 108 | G_OBJECT_CLASS(account_security_tab_parent_class)->dispose(object); |
| 109 | } |
| 110 | |
| 111 | static void |
| 112 | account_security_tab_finalize(GObject *object) |
| 113 | { |
| 114 | AccountSecurityTab *view = ACCOUNT_SECURITY_TAB(object); |
| 115 | AccountSecurityTabPrivate *priv = ACCOUNT_SECURITY_TAB_GET_PRIVATE(view); |
| 116 | |
| 117 | delete priv->qmodel_key_exchange; |
| 118 | |
| 119 | G_OBJECT_CLASS(account_security_tab_parent_class)->finalize(object); |
| 120 | } |
| 121 | |
| 122 | static void |
| 123 | account_security_tab_init(AccountSecurityTab *view) |
| 124 | { |
| 125 | gtk_widget_init_template(GTK_WIDGET(view)); |
| 126 | } |
| 127 | |
| 128 | static void |
| 129 | account_security_tab_class_init(AccountSecurityTabClass *klass) |
| 130 | { |
| 131 | G_OBJECT_CLASS(klass)->dispose = account_security_tab_dispose; |
| 132 | G_OBJECT_CLASS(klass)->finalize = account_security_tab_finalize; |
| 133 | |
| 134 | gtk_widget_class_set_template_from_resource(GTK_WIDGET_CLASS (klass), |
| 135 | "/cx/ring/RingGnome/accountsecuritytab.ui"); |
| 136 | |
| 137 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountSecurityTab, checkbutton_use_srtp); |
| 138 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountSecurityTab, box_key_exchange); |
| 139 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountSecurityTab, combobox_key_exchange); |
| 140 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountSecurityTab, checkbutton_srtp_fallback); |
| 141 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountSecurityTab, checkbutton_use_tls); |
| 142 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountSecurityTab, grid_tls_settings_0); |
| 143 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountSecurityTab, filechooserbutton_ca_list); |
| 144 | /* TODO: add when implemented |
| 145 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountSecurityTab, button_view_ca); |
| 146 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountSecurityTab, button_view_certificate); |
| 147 | */ |
| 148 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountSecurityTab, filechooserbutton_certificate); |
| 149 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountSecurityTab, filechooserbutton_private_key); |
| 150 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountSecurityTab, entry_password); |
| 151 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountSecurityTab, grid_tls_settings_1); |
| 152 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountSecurityTab, combobox_tls_protocol_method); |
| 153 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountSecurityTab, entry_tls_server_name); |
| 154 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountSecurityTab, adjustment_tls_timeout); |
| 155 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountSecurityTab, buttonbox_cipher_list); |
| 156 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountSecurityTab, radiobutton_use_default_ciphers); |
| 157 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountSecurityTab, radiobutton_custom_ciphers); |
| 158 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountSecurityTab, revealer_cipher_list); |
| 159 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountSecurityTab, treeview_cipher_list); |
| 160 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountSecurityTab, checkbutton_verify_certs_server); |
| 161 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountSecurityTab, checkbutton_verify_certs_client); |
| 162 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountSecurityTab, checkbutton_require_incoming_tls_certs); |
| 163 | } |
| 164 | |
| 165 | static void |
| 166 | use_srtp_toggled(GtkToggleButton *toggle_button, AccountSecurityTab *self) |
| 167 | { |
| 168 | g_return_if_fail(IS_ACCOUNT_SECURITY_TAB(self)); |
| 169 | AccountSecurityTabPrivate *priv = ACCOUNT_SECURITY_TAB_GET_PRIVATE(self); |
| 170 | |
| 171 | gboolean use_srtp = gtk_toggle_button_get_active(toggle_button); |
| 172 | |
| 173 | priv->account->setSrtpEnabled(use_srtp); |
| 174 | priv->account->keyExchangeModel()->enableSRTP(use_srtp); |
| 175 | |
| 176 | /* the other options are not relevant if SRTP is not active */ |
| 177 | gtk_widget_set_sensitive(priv->box_key_exchange, priv->account->isSrtpEnabled()); |
| 178 | gtk_widget_set_sensitive(priv->checkbutton_srtp_fallback, priv->account->isSrtpEnabled()); |
| 179 | } |
| 180 | |
| 181 | static void |
| 182 | use_rtp_fallback_toggled(GtkToggleButton *toggle_button, AccountSecurityTab *self) |
| 183 | { |
| 184 | g_return_if_fail(IS_ACCOUNT_SECURITY_TAB(self)); |
| 185 | AccountSecurityTabPrivate *priv = ACCOUNT_SECURITY_TAB_GET_PRIVATE(self); |
| 186 | |
| 187 | gboolean use_rtp_fallback = gtk_toggle_button_get_active(toggle_button); |
| 188 | |
| 189 | priv->account->setSrtpRtpFallback(use_rtp_fallback); |
| 190 | } |
| 191 | |
| 192 | static void |
| 193 | use_tls_toggled(GtkToggleButton *toggle_button, AccountSecurityTab *self) |
| 194 | { |
| 195 | g_return_if_fail(IS_ACCOUNT_SECURITY_TAB(self)); |
| 196 | AccountSecurityTabPrivate *priv = ACCOUNT_SECURITY_TAB_GET_PRIVATE(self); |
| 197 | |
| 198 | gboolean use_tls = gtk_toggle_button_get_active(toggle_button); |
| 199 | |
| 200 | priv->account->setTlsEnabled(use_tls); |
| 201 | |
| 202 | /* disable the other tls options if no tls */ |
| 203 | gtk_widget_set_sensitive(priv->grid_tls_settings_0, priv->account->isTlsEnabled()); |
| 204 | gtk_widget_set_sensitive(priv->grid_tls_settings_1, priv->account->isTlsEnabled()); |
| 205 | gtk_widget_set_sensitive(priv->buttonbox_cipher_list, priv->account->isTlsEnabled()); |
| 206 | gtk_widget_set_sensitive(priv->treeview_cipher_list, priv->account->isTlsEnabled()); |
| 207 | gtk_widget_set_sensitive(priv->checkbutton_verify_certs_server, priv->account->isTlsEnabled()); |
| 208 | gtk_widget_set_sensitive(priv->checkbutton_verify_certs_client, priv->account->isTlsEnabled()); |
| 209 | gtk_widget_set_sensitive(priv->checkbutton_require_incoming_tls_certs, priv->account->isTlsEnabled()); |
| 210 | } |
| 211 | |
| 212 | static void |
| 213 | tls_server_name_changed(GtkEntry *entry, AccountSecurityTab *self) |
| 214 | { |
| 215 | g_return_if_fail(IS_ACCOUNT_SECURITY_TAB(self)); |
| 216 | AccountSecurityTabPrivate *priv = ACCOUNT_SECURITY_TAB_GET_PRIVATE(self); |
| 217 | |
| 218 | priv->account->setTlsServerName(gtk_entry_get_text(entry)); |
| 219 | } |
| 220 | |
| 221 | static void |
| 222 | tls_timeout_changed(GtkAdjustment *adjustment, AccountSecurityTab *self) |
| 223 | { |
| 224 | g_return_if_fail(IS_ACCOUNT_SECURITY_TAB(self)); |
| 225 | AccountSecurityTabPrivate *priv = ACCOUNT_SECURITY_TAB_GET_PRIVATE(self); |
| 226 | |
| 227 | int timeout = (int)gtk_adjustment_get_value(GTK_ADJUSTMENT(adjustment)); |
| 228 | priv->account->setTlsNegotiationTimeoutSec(timeout); |
| 229 | } |
| 230 | |
| 231 | static void |
| 232 | use_default_ciphers_toggled(GtkToggleButton *toggle_button, AccountSecurityTab *self) |
| 233 | { |
| 234 | g_return_if_fail(IS_ACCOUNT_SECURITY_TAB(self)); |
| 235 | AccountSecurityTabPrivate *priv = ACCOUNT_SECURITY_TAB_GET_PRIVATE(self); |
| 236 | |
| 237 | gboolean use_default_ciphers = gtk_toggle_button_get_active(toggle_button); |
| 238 | |
| 239 | priv->account->cipherModel()->setUseDefault(use_default_ciphers); |
| 240 | |
| 241 | /* hide the cipher list if we're using the default ones */ |
| 242 | gtk_revealer_set_reveal_child(GTK_REVEALER(priv->revealer_cipher_list), !use_default_ciphers); |
| 243 | } |
| 244 | |
| 245 | static void |
| 246 | cipher_enable_toggled(GtkCellRendererToggle *renderer, gchar *path, AccountSecurityTab *self) |
| 247 | { |
| 248 | g_return_if_fail(IS_ACCOUNT_SECURITY_TAB(self)); |
| 249 | AccountSecurityTabPrivate *priv = ACCOUNT_SECURITY_TAB_GET_PRIVATE(self); |
| 250 | |
| 251 | /* we want to set it to the opposite of the current value */ |
| 252 | gboolean toggle = !gtk_cell_renderer_toggle_get_active(renderer); |
| 253 | |
| 254 | /* get iter which was clicked */ |
| 255 | GtkTreePath *tree_path = gtk_tree_path_new_from_string(path); |
| 256 | GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(priv->treeview_cipher_list)); |
| 257 | GtkTreeIter iter; |
| 258 | gtk_tree_model_get_iter(model, &iter, tree_path); |
| 259 | |
| 260 | /* get qmodelindex from iter and set the model data */ |
| 261 | QModelIndex idx = gtk_q_tree_model_get_source_idx(GTK_Q_TREE_MODEL(model), &iter); |
| 262 | if (idx.isValid()) |
| 263 | priv->account->cipherModel()->setData(idx, toggle ? Qt::Checked : Qt::Unchecked, Qt::CheckStateRole); |
| 264 | } |
| 265 | |
| 266 | static void |
| 267 | render_check_state(G_GNUC_UNUSED GtkCellLayout *cell_layout, |
| 268 | GtkCellRenderer *cell, |
| 269 | GtkTreeModel *model, |
| 270 | GtkTreeIter *iter, |
| 271 | G_GNUC_UNUSED gpointer data) |
| 272 | { |
| 273 | QModelIndex idx; |
| 274 | if (GTK_IS_Q_TREE_MODEL(model)) |
| 275 | idx = gtk_q_tree_model_get_source_idx(GTK_Q_TREE_MODEL(model), iter); |
| 276 | else if (GTK_IS_Q_SORT_FILTER_TREE_MODEL(model)) |
| 277 | idx = gtk_q_sort_filter_tree_model_get_source_idx(GTK_Q_SORT_FILTER_TREE_MODEL(model), iter); |
| 278 | |
| 279 | gboolean checked = FALSE; |
| 280 | |
| 281 | if (idx.isValid()) { |
| 282 | checked = idx.data(Qt::CheckStateRole).value<int>() == Qt::Checked ? TRUE : FALSE; |
| 283 | } |
| 284 | |
| 285 | g_object_set(G_OBJECT(cell), "active", checked, NULL); |
| 286 | } |
| 287 | |
| 288 | static void |
| 289 | verify_certs_server_toggled(GtkToggleButton *toggle_button, AccountSecurityTab *self) |
| 290 | { |
| 291 | g_return_if_fail(IS_ACCOUNT_SECURITY_TAB(self)); |
| 292 | AccountSecurityTabPrivate *priv = ACCOUNT_SECURITY_TAB_GET_PRIVATE(self); |
| 293 | |
| 294 | gboolean verify_certs = gtk_toggle_button_get_active(toggle_button); |
| 295 | |
| 296 | priv->account->setTlsVerifyServer(verify_certs); |
| 297 | } |
| 298 | |
| 299 | static void |
| 300 | verify_certs_client_toggled(GtkToggleButton *toggle_button, AccountSecurityTab *self) |
| 301 | { |
| 302 | g_return_if_fail(IS_ACCOUNT_SECURITY_TAB(self)); |
| 303 | AccountSecurityTabPrivate *priv = ACCOUNT_SECURITY_TAB_GET_PRIVATE(self); |
| 304 | |
| 305 | gboolean verify_certs = gtk_toggle_button_get_active(toggle_button); |
| 306 | |
| 307 | priv->account->setTlsVerifyClient(verify_certs); |
| 308 | } |
| 309 | |
| 310 | static void |
| 311 | require_incoming_certs_toggled(GtkToggleButton *toggle_button, AccountSecurityTab *self) |
| 312 | { |
| 313 | g_return_if_fail(IS_ACCOUNT_SECURITY_TAB(self)); |
| 314 | AccountSecurityTabPrivate *priv = ACCOUNT_SECURITY_TAB_GET_PRIVATE(self); |
| 315 | |
| 316 | gboolean require = gtk_toggle_button_get_active(toggle_button); |
| 317 | |
| 318 | priv->account->setTlsRequireClientCertificate(require); |
| 319 | } |
| 320 | |
| 321 | static void |
| 322 | ca_cert_file_set(GtkFileChooser *file_chooser, AccountSecurityTab *self) |
| 323 | { |
| 324 | g_return_if_fail(IS_ACCOUNT_SECURITY_TAB(self)); |
| 325 | AccountSecurityTabPrivate *priv = ACCOUNT_SECURITY_TAB_GET_PRIVATE(self); |
| 326 | |
| 327 | gchar *filename = gtk_file_chooser_get_filename(file_chooser); |
| 328 | priv->account->setTlsCaListCertificate(filename); |
| 329 | g_free(filename); |
| 330 | } |
| 331 | |
| 332 | static void |
| 333 | user_cert_file_set(GtkFileChooser *file_chooser, AccountSecurityTab *self) |
| 334 | { |
| 335 | g_return_if_fail(IS_ACCOUNT_SECURITY_TAB(self)); |
| 336 | AccountSecurityTabPrivate *priv = ACCOUNT_SECURITY_TAB_GET_PRIVATE(self); |
| 337 | |
| 338 | gchar *filename = gtk_file_chooser_get_filename(file_chooser); |
| 339 | priv->account->setTlsCertificate(filename); |
| 340 | g_free(filename); |
| 341 | } |
| 342 | |
| 343 | static void |
| 344 | private_key_file_set(GtkFileChooser *file_chooser, AccountSecurityTab *self) |
| 345 | { |
| 346 | g_return_if_fail(IS_ACCOUNT_SECURITY_TAB(self)); |
| 347 | AccountSecurityTabPrivate *priv = ACCOUNT_SECURITY_TAB_GET_PRIVATE(self); |
| 348 | |
| 349 | gchar *filename = gtk_file_chooser_get_filename(file_chooser); |
| 350 | priv->account->setTlsPrivateKeyCertificate(filename); |
| 351 | g_free(filename); |
| 352 | } |
| 353 | |
| 354 | static void |
| 355 | build_tab_view(AccountSecurityTab *self) |
| 356 | { |
| 357 | g_return_if_fail(IS_ACCOUNT_SECURITY_TAB(self)); |
| 358 | AccountSecurityTabPrivate *priv = ACCOUNT_SECURITY_TAB_GET_PRIVATE(self); |
| 359 | |
| 360 | gboolean not_ring = priv->account->protocol() != Account::Protocol::RING; |
| 361 | |
| 362 | /* SRTP */ |
| 363 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->checkbutton_use_srtp), |
| 364 | priv->account->isSrtpEnabled()); |
| 365 | /* disable options if SRTP is off or if its a RING account */ |
| 366 | gtk_widget_set_sensitive(priv->checkbutton_use_srtp, not_ring); |
| 367 | gtk_widget_set_sensitive(priv->box_key_exchange, |
| 368 | priv->account->isSrtpEnabled() && not_ring); |
| 369 | gtk_widget_set_sensitive(priv->checkbutton_srtp_fallback, |
| 370 | priv->account->isSrtpEnabled() && not_ring); |
| 371 | g_signal_connect(priv->checkbutton_use_srtp, "toggled", G_CALLBACK(use_srtp_toggled), self); |
| 372 | |
| 373 | /* encryption key exchange type */ |
| 374 | priv->key_exchange_selection = gtk_combo_box_set_qmodel( |
| 375 | GTK_COMBO_BOX(priv->combobox_key_exchange), |
| 376 | (QAbstractItemModel *)priv->account->keyExchangeModel(), |
| 377 | priv->account->keyExchangeModel()->selectionModel()); |
| 378 | |
| 379 | /* SRTP fallback */ |
| 380 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->checkbutton_srtp_fallback), |
| 381 | priv->account->isSrtpRtpFallback()); |
| 382 | g_signal_connect(priv->checkbutton_srtp_fallback, "toggled", G_CALLBACK(use_rtp_fallback_toggled), self); |
| 383 | |
| 384 | /* use TLS */ |
| 385 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->checkbutton_use_tls), |
| 386 | priv->account->isTlsEnabled()); |
| 387 | |
| 388 | /* disable certain options if TLS is off, or if its a RING account*/ |
| 389 | gtk_widget_set_sensitive(priv->checkbutton_use_tls, not_ring); |
| 390 | gtk_widget_set_sensitive(priv->grid_tls_settings_0, |
| 391 | priv->account->isTlsEnabled()); |
| 392 | gtk_widget_set_sensitive(priv->grid_tls_settings_1, |
| 393 | priv->account->isTlsEnabled() && not_ring); |
| 394 | gtk_widget_set_sensitive(priv->buttonbox_cipher_list, |
| 395 | priv->account->isTlsEnabled() && not_ring); |
| 396 | gtk_widget_set_sensitive(priv->treeview_cipher_list, |
| 397 | priv->account->isTlsEnabled() && not_ring); |
| 398 | gtk_widget_set_sensitive(priv->checkbutton_verify_certs_server, |
| 399 | priv->account->isTlsEnabled() && not_ring); |
| 400 | gtk_widget_set_sensitive(priv->checkbutton_verify_certs_client, |
| 401 | priv->account->isTlsEnabled() && not_ring); |
| 402 | gtk_widget_set_sensitive(priv->checkbutton_require_incoming_tls_certs, |
| 403 | priv->account->isTlsEnabled() && not_ring); |
| 404 | g_signal_connect(priv->checkbutton_use_tls, "toggled", G_CALLBACK(use_tls_toggled), self); |
| 405 | |
| 406 | /* CA certificate */ |
| 407 | Certificate *ca_cert = priv->account->tlsCaListCertificate(); |
| 408 | if (ca_cert) { |
| 409 | gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(priv->filechooserbutton_ca_list), |
| 410 | ca_cert->path().toDisplayString().toUtf8().constData()); |
| 411 | } |
| 412 | g_signal_connect(priv->filechooserbutton_ca_list, "file-set", G_CALLBACK(ca_cert_file_set), self); |
| 413 | |
| 414 | /* user certificate */ |
| 415 | Certificate *user_cert = priv->account->tlsCertificate(); |
| 416 | if (user_cert) { |
| 417 | gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(priv->filechooserbutton_certificate), |
| 418 | user_cert->path().toDisplayString().toUtf8().constData()); |
| 419 | } |
Stepan Salenikovich | d890ad7 | 2015-05-20 10:17:48 -0400 | [diff] [blame] | 420 | g_signal_connect(priv->filechooserbutton_certificate, "file-set", G_CALLBACK(user_cert_file_set), self); |
Stepan Salenikovich | 7a1e71c | 2015-05-07 11:14:48 -0400 | [diff] [blame] | 421 | |
| 422 | /* private key */ |
| 423 | Certificate *private_key = priv->account->tlsPrivateKeyCertificate(); |
| 424 | if (private_key) { |
| 425 | gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(priv->filechooserbutton_private_key), |
| 426 | private_key->path().toDisplayString().toUtf8().constData()); |
| 427 | } |
Stepan Salenikovich | d890ad7 | 2015-05-20 10:17:48 -0400 | [diff] [blame] | 428 | g_signal_connect(priv->filechooserbutton_private_key, "file-set", G_CALLBACK(private_key_file_set), self); |
Stepan Salenikovich | 7a1e71c | 2015-05-07 11:14:48 -0400 | [diff] [blame] | 429 | |
| 430 | /* password */ |
| 431 | if (private_key && private_key->requirePrivateKeyPassword()) { |
| 432 | gtk_entry_set_text(GTK_ENTRY(priv->entry_password), |
| 433 | priv->account->tlsPassword().toUtf8().constData()); |
| 434 | gtk_widget_set_sensitive(priv->entry_password, TRUE); |
| 435 | } else { |
| 436 | /* private key not chosen, or password not required, so disactivate the entry */ |
| 437 | gtk_widget_set_sensitive(priv->entry_password, FALSE); |
| 438 | } |
| 439 | |
| 440 | /* TLS protocol method */ |
| 441 | priv->tls_method_selection = gtk_combo_box_set_qmodel(GTK_COMBO_BOX(priv->combobox_tls_protocol_method), |
| 442 | (QAbstractItemModel *)priv->account->tlsMethodModel(), |
| 443 | priv->account->tlsMethodModel()->selectionModel()); |
| 444 | |
| 445 | /* outgoing TLS server */ |
| 446 | gtk_entry_set_text(GTK_ENTRY(priv->entry_tls_server_name), |
| 447 | priv->account->tlsServerName().toUtf8().constData()); |
| 448 | g_signal_connect(priv->entry_tls_server_name, "changed", G_CALLBACK(tls_server_name_changed), self); |
| 449 | |
| 450 | |
| 451 | /* TLS nego timeout */ |
| 452 | gtk_adjustment_set_value(GTK_ADJUSTMENT(priv->adjustment_tls_timeout), |
| 453 | priv->account->tlsNegotiationTimeoutSec()); |
| 454 | g_signal_connect(priv->adjustment_tls_timeout, "value-changed", G_CALLBACK(tls_timeout_changed), self); |
| 455 | |
| 456 | /* cipher default or custom */ |
| 457 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->radiobutton_use_default_ciphers), |
| 458 | priv->account->cipherModel()->useDefault()); |
| 459 | /* hide the cipher list if we're using the default ones */ |
| 460 | gtk_revealer_set_reveal_child(GTK_REVEALER(priv->revealer_cipher_list), |
| 461 | !priv->account->cipherModel()->useDefault()); |
| 462 | g_signal_connect(priv->radiobutton_use_default_ciphers, |
| 463 | "toggled", G_CALLBACK(use_default_ciphers_toggled), self); |
| 464 | |
| 465 | /* cipher list */ |
| 466 | GtkQTreeModel *cipher_model = gtk_q_tree_model_new( |
| 467 | (QAbstractItemModel *)priv->account->cipherModel(), |
| 468 | 2, |
| 469 | Qt::CheckStateRole, G_TYPE_BOOLEAN, |
| 470 | Qt::DisplayRole, G_TYPE_STRING); |
| 471 | gtk_tree_view_set_model(GTK_TREE_VIEW(priv->treeview_cipher_list), |
| 472 | GTK_TREE_MODEL(cipher_model)); |
| 473 | gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(priv->treeview_cipher_list), |
| 474 | FALSE); |
| 475 | |
| 476 | GtkCellRenderer *renderer = gtk_cell_renderer_toggle_new(); |
| 477 | GtkTreeViewColumn *column = gtk_tree_view_column_new_with_attributes( |
| 478 | "Enabled", renderer, NULL); |
| 479 | gtk_tree_view_append_column(GTK_TREE_VIEW(priv->treeview_cipher_list), column); |
| 480 | |
| 481 | /* we have to use a custom data function here because Qt::Checked and Qt::Unchecked |
| 482 | * are not the same as true/false as there is an intermediate state */ |
| 483 | gtk_tree_view_column_set_cell_data_func(column, |
| 484 | renderer, |
| 485 | (GtkTreeCellDataFunc)render_check_state, |
| 486 | NULL, NULL); |
| 487 | |
| 488 | g_signal_connect(renderer, "toggled", G_CALLBACK(cipher_enable_toggled), self); |
| 489 | |
| 490 | renderer = gtk_cell_renderer_text_new(); |
| 491 | column = gtk_tree_view_column_new_with_attributes("Cipher", renderer, "text", 1, NULL); |
| 492 | gtk_tree_view_append_column(GTK_TREE_VIEW(priv->treeview_cipher_list), column); |
| 493 | |
| 494 | /* server certs */ |
| 495 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->checkbutton_verify_certs_server), |
| 496 | priv->account->isTlsVerifyServer()); |
Stepan Salenikovich | 226df01 | 2015-07-08 16:09:39 -0400 | [diff] [blame] | 497 | g_signal_connect(priv->checkbutton_verify_certs_server, |
Stepan Salenikovich | 7a1e71c | 2015-05-07 11:14:48 -0400 | [diff] [blame] | 498 | "toggled", G_CALLBACK(verify_certs_server_toggled), self); |
| 499 | |
| 500 | /* client certs */ |
| 501 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->checkbutton_verify_certs_client), |
| 502 | priv->account->isTlsVerifyClient()); |
| 503 | g_signal_connect(priv->checkbutton_verify_certs_client, |
| 504 | "toggled", G_CALLBACK(verify_certs_client_toggled), self); |
| 505 | |
| 506 | /* incoming certs */ |
| 507 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->checkbutton_require_incoming_tls_certs), |
| 508 | priv->account->isTlsRequireClientCertificate()); |
| 509 | g_signal_connect(priv->checkbutton_require_incoming_tls_certs, |
| 510 | "toggled", G_CALLBACK(require_incoming_certs_toggled), self); |
| 511 | |
| 512 | /* update account UI if model is updated */ |
| 513 | priv->account_updated = QObject::connect( |
| 514 | priv->account, |
| 515 | &Account::changed, |
| 516 | [=] () { |
| 517 | /* SRTP */ |
| 518 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->checkbutton_use_srtp), |
| 519 | priv->account->isSrtpEnabled()); |
| 520 | |
| 521 | /* SRTP fallback */ |
| 522 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->checkbutton_srtp_fallback), |
| 523 | priv->account->isSrtpRtpFallback()); |
| 524 | /* use TLS */ |
| 525 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->checkbutton_use_tls), |
| 526 | priv->account->isTlsEnabled()); |
| 527 | |
| 528 | /* CA certificate */ |
| 529 | Certificate *ca_cert = priv->account->tlsCaListCertificate(); |
| 530 | if (ca_cert) { |
| 531 | gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(priv->filechooserbutton_ca_list), |
| 532 | ca_cert->path().toDisplayString().toUtf8().constData()); |
| 533 | } |
| 534 | |
| 535 | /* user certificate */ |
| 536 | Certificate *user_cert = priv->account->tlsCertificate(); |
| 537 | if (user_cert) { |
| 538 | gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(priv->filechooserbutton_certificate), |
| 539 | user_cert->path().toDisplayString().toUtf8().constData()); |
| 540 | } |
| 541 | |
| 542 | /* private key */ |
| 543 | Certificate *private_key = priv->account->tlsPrivateKeyCertificate(); |
| 544 | if (private_key) { |
| 545 | gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(priv->filechooserbutton_private_key), |
| 546 | private_key->path().toDisplayString().toUtf8().constData()); |
| 547 | } |
| 548 | |
| 549 | /* password */ |
| 550 | if (private_key && private_key->requirePrivateKeyPassword()) { |
| 551 | gtk_entry_set_text(GTK_ENTRY(priv->entry_password), |
| 552 | priv->account->tlsPassword().toUtf8().constData()); |
| 553 | gtk_widget_set_sensitive(priv->entry_password, TRUE); |
| 554 | } else { |
| 555 | /* private key not chosen, or password not required, so disactivate the entry */ |
| 556 | gtk_widget_set_sensitive(priv->entry_password, FALSE); |
| 557 | } |
| 558 | |
| 559 | /* outgoing TLS server */ |
| 560 | gtk_entry_set_text(GTK_ENTRY(priv->entry_tls_server_name), |
| 561 | priv->account->tlsServerName().toUtf8().constData()); |
| 562 | |
| 563 | /* TLS nego timeout */ |
| 564 | gtk_adjustment_set_value(GTK_ADJUSTMENT(priv->adjustment_tls_timeout), |
| 565 | priv->account->tlsNegotiationTimeoutSec()); |
| 566 | |
| 567 | /* cipher default or custom */ |
| 568 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->radiobutton_use_default_ciphers), |
| 569 | priv->account->cipherModel()->useDefault()); |
| 570 | |
| 571 | /* server certs */ |
| 572 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->checkbutton_verify_certs_server), |
| 573 | priv->account->isTlsVerifyServer()); |
| 574 | |
| 575 | /* client certs */ |
| 576 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->checkbutton_verify_certs_client), |
| 577 | priv->account->isTlsVerifyClient()); |
| 578 | |
| 579 | /* incoming certs */ |
| 580 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->checkbutton_require_incoming_tls_certs), |
| 581 | priv->account->isTlsRequireClientCertificate()); |
| 582 | } |
| 583 | ); |
| 584 | } |
| 585 | |
| 586 | GtkWidget * |
| 587 | account_security_tab_new(Account *account) |
| 588 | { |
| 589 | g_return_val_if_fail(account != NULL, NULL); |
| 590 | |
| 591 | gpointer view = g_object_new(ACCOUNT_SECURITY_TAB_TYPE, NULL); |
| 592 | |
| 593 | AccountSecurityTabPrivate *priv = ACCOUNT_SECURITY_TAB_GET_PRIVATE(view); |
| 594 | priv->account = account; |
| 595 | |
| 596 | build_tab_view(ACCOUNT_SECURITY_TAB(view)); |
| 597 | |
| 598 | return (GtkWidget *)view; |
| 599 | } |