Skip to content

Commit ff407e7

Browse files
ui,prefs: node auth settings improvements
- Added "More information" label to the preferences dialog, and open a link to our wiki with more information. - Allow to configure node auth settings from the GUI: When we added the authentication options (12b4cf3, 6556eed, f63d9dc) we allowed to configure auth options from the GUI, but only if the nodes already had the options configured. If the auth options received were empty, we simply disabled the auth options on the preferences dialog. Now we build the configuration in this scenario, and sent it back to the nodes. (cherry picked from commit 8c25c3f)
1 parent 03439f4 commit ff407e7

File tree

2 files changed

+105
-90
lines changed

2 files changed

+105
-90
lines changed

ui/opensnitch/dialogs/preferences.py

Lines changed: 51 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ def _load_node_config(self, addr):
444444
node_config['Server']['Address'] = self.comboNodeAddress.currentText()
445445
node_config['Server']['LogFile'] = self.comboNodeLogFile.currentText()
446446

447-
cfg = self._load_node_auth_config(node_config['Server'])
447+
cfg = self._save_node_auth_config(node_config['Server'])
448448
if cfg != None:
449449
node_config['Server'] = cfg
450450
else:
@@ -457,51 +457,67 @@ def _load_node_config(self, addr):
457457

458458
def _load_node_auth_settings(self, config):
459459
try:
460-
if config.get('Authentication') == None:
461-
self.toolBox.setItemEnabled(self.NODE_PAGE_AUTH, False)
460+
if config == None:
462461
return
462+
463463
auth = config.get('Authentication')
464-
authtype_idx = self.comboNodeAuthType.findData(auth['Type'])
464+
authtype_idx = 0
465+
if auth != None:
466+
if auth.get('Type') != None:
467+
authtype_idx = self.comboNodeAuthType.findData(auth['Type'])
468+
else:
469+
config['Authentication'] = {}
470+
auth = config.get('Authentication')
471+
465472
self.lineNodeCACertFile.setEnabled(authtype_idx >= 0)
466473
self.lineNodeServerCertFile.setEnabled(authtype_idx >= 0)
467474
self.lineNodeCertFile.setEnabled(authtype_idx >= 0)
468475
self.lineNodeCertKeyFile.setEnabled(authtype_idx >= 0)
469476

470477
tls = auth.get('TLSOptions')
471478
if tls != None and authtype_idx >= 0:
472-
self.lineNodeCACertFile.setText(tls['CACert'])
473-
self.lineNodeServerCertFile.setText(tls['ServerCert'])
474-
self.lineNodeCertFile.setText(tls['ClientCert'])
475-
self.lineNodeCertKeyFile.setText(tls['ClientKey'])
476-
self.checkNodeAuthSkipVerify.setChecked(tls['SkipVerify'])
477-
478-
clienttype_idx = self.comboNodeAuthVerifyType.findData(tls['ClientAuthType'])
479-
if clienttype_idx >= 0:
480-
self.comboNodeAuthVerifyType.setCurrentIndex(clienttype_idx)
481-
else:
482-
authtype_idx = 0
479+
if tls.get('CACert') != None:
480+
self.lineNodeCACertFile.setText(tls['CACert'])
481+
if tls.get('ServerCert') != None:
482+
self.lineNodeServerCertFile.setText(tls['ServerCert'])
483+
if tls.get('ClientCert') != None:
484+
self.lineNodeCertFile.setText(tls['ClientCert'])
485+
if tls.get('ClientKey') != None:
486+
self.lineNodeCertKeyFile.setText(tls['ClientKey'])
487+
if tls.get('SkipVerify') != None:
488+
self.checkNodeAuthSkipVerify.setChecked(tls['SkipVerify'])
489+
490+
if tls.get('ClientAuthType') != None:
491+
clienttype_idx = self.comboNodeAuthVerifyType.findData(tls['ClientAuthType'])
492+
if clienttype_idx >= 0:
493+
self.comboNodeAuthVerifyType.setCurrentIndex(clienttype_idx)
494+
483495
self.comboNodeAuthType.setCurrentIndex(authtype_idx)
484496
# signals are connected after this method is called
485497
self._cb_combo_node_auth_type_changed(authtype_idx)
486498
except Exception as e:
487-
print("[prefs] node auth options exception:", e)
499+
print("[prefs] load node auth options exception:", e)
488500
self._set_status_error(str(e))
489501

490-
def _load_node_auth_config(self, config):
502+
def _save_node_auth_config(self, config):
491503
try:
492-
if config.get('Authentication') == None:
493-
self.toolBox.setItemEnabled(self.NODE_PAGE_AUTH, False)
494-
return
495504
auth = config.get('Authentication')
505+
if auth == None:
506+
auth = {}
507+
496508
auth['Type'] = self.NODE_AUTH[self.comboNodeAuthType.currentIndex()]
497509
tls = auth.get('TLSOptions')
498-
if tls != None:
499-
tls['CACert']= self.lineNodeCACertFile.text()
500-
tls['ServerCert'] = self.lineNodeServerCertFile.text()
501-
tls['ClientCert'] = self.lineNodeCertFile.text()
502-
tls['ClientKey'] = self.lineNodeCertKeyFile.text()
503-
tls['SkipVerify'] = self.checkNodeAuthSkipVerify.isChecked()
504-
tls['ClientAuthType'] = self.NODE_AUTH_VERIFY[self.comboNodeAuthVerifyType.currentIndex()]
510+
if tls == None:
511+
tls = {}
512+
513+
tls['CACert'] = self.lineNodeCACertFile.text()
514+
tls['ServerCert'] = self.lineNodeServerCertFile.text()
515+
tls['ClientCert'] = self.lineNodeCertFile.text()
516+
tls['ClientKey'] = self.lineNodeCertKeyFile.text()
517+
tls['SkipVerify'] = self.checkNodeAuthSkipVerify.isChecked()
518+
tls['ClientAuthType'] = self.NODE_AUTH_VERIFY[self.comboNodeAuthVerifyType.currentIndex()]
519+
auth['TLSOptions'] = tls
520+
config['Authentication'] = auth
505521

506522
return config
507523
except Exception as e:
@@ -544,6 +560,14 @@ def _reset_node_settings(self):
544560
self.checkNodeLogMicro.setChecked(False)
545561
self.labelNodeName.setText("")
546562
self.labelNodeVersion.setText("")
563+
self.comboNodeAuthType.setCurrentIndex(self.AUTH_SIMPLE)
564+
self.lineNodeCACertFile.setText("")
565+
self.lineNodeServerCertFile.setText("")
566+
self.lineNodeCertFile.setText("")
567+
self.lineNodeCertKeyFile.setText("")
568+
self.checkNodeAuthSkipVerify.setChecked(False)
569+
self.comboNodeAuthVerifyType.setCurrentIndex(0)
570+
self._cb_combo_node_auth_type_changed(0)
547571

548572
def _save_settings(self):
549573
self._reset_status_message()
@@ -739,38 +763,6 @@ def _save_node_config(self, notifObject, addr):
739763

740764
return None
741765

742-
def _save_node_auth_config(self, config):
743-
try:
744-
if config.get('Authentication') == None:
745-
self.toolBox.setItemEnabled(self.NODE_PAGE_AUTH, False)
746-
return
747-
748-
auth = config['Authentication']
749-
authtype_idx = self.comboNodeAuthType.findData(auth['Type'])
750-
self.lineNodeCACertFile.setEnabled(authtype_idx >= 0)
751-
self.lineNodeServerCertFile.setEnabled(authtype_idx >= 0)
752-
self.lineNodeCertFile.setEnabled(authtype_idx >= 0)
753-
self.lineNodeCertKeyFile.setEnabled(authtype_idx >= 0)
754-
755-
tls = auth.get('TLSOptions')
756-
if tls != None and authtype_idx >= 0:
757-
self.lineNodeCACertFile.setText(tls['CACert'])
758-
self.lineNodeServerCertFile.setText(tls['ServerCert'])
759-
self.lineNodeCertFile.setText(tls['ClientCert'])
760-
self.lineNodeCertKeyFile.setText(tls['ClientKey'])
761-
self.checkNodeAuthSkipVerify.setChecked(tls['SkipVerify'])
762-
763-
clienttype_idx = self.comboNodeAuthVerifyType.findData(tls['ClientAuthType'])
764-
if clienttype_idx >= 0:
765-
self.comboNodeAuthVerifyType.setCurrentIndex(clienttype_idx)
766-
else:
767-
authtype_idx = 0
768-
self.comboNodeAuthType.setCurrentIndex(authtype_idx)
769-
except Exception as e:
770-
print("[prefs] node auth options exception:", e)
771-
self._set_status_error(str(e))
772-
773-
774766
def _validate_certs(self):
775767
try:
776768
if self.comboAuthType.currentIndex() == PreferencesDialog.AUTH_SIMPLE:

ui/opensnitch/res/preferences.ui

Lines changed: 54 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -901,6 +901,32 @@ Use ; to define multiple screens: 1;1.5 etc...</string>
901901
</item>
902902
</widget>
903903
</item>
904+
<item row="1" column="0">
905+
<widget class="QLabel" name="label_24">
906+
<property name="toolTip">
907+
<string>&lt;p&gt;Simple: no authentication&lt;/p&gt;
908+
&lt;p&gt;TLS simple/mutual: use SSL certificates to authenticate nodes.&lt;/p&gt;
909+
&lt;p&gt;Visit the wiki for more information.&lt;/p&gt;</string>
910+
</property>
911+
<property name="text">
912+
<string>Authentication type</string>
913+
</property>
914+
</widget>
915+
</item>
916+
<item row="3" column="0" colspan="2">
917+
<widget class="QLineEdit" name="lineCertFile">
918+
<property name="placeholderText">
919+
<string>Absolute path to the cert file</string>
920+
</property>
921+
</widget>
922+
</item>
923+
<item row="4" column="0" colspan="2">
924+
<widget class="QLineEdit" name="lineCertKeyFile">
925+
<property name="placeholderText">
926+
<string>Absolute path to the cert key file</string>
927+
</property>
928+
</widget>
929+
</item>
904930
<item row="1" column="1">
905931
<widget class="QComboBox" name="comboAuthType">
906932
<item>
@@ -920,10 +946,10 @@ Use ; to define multiple screens: 1;1.5 etc...</string>
920946
</item>
921947
</widget>
922948
</item>
923-
<item row="3" column="0" colspan="2">
924-
<widget class="QLineEdit" name="lineCertFile">
949+
<item row="2" column="0" colspan="2">
950+
<widget class="QLineEdit" name="lineCACertFile">
925951
<property name="placeholderText">
926-
<string>Absolute path to the cert file</string>
952+
<string>Absolute path to the CA cert file</string>
927953
</property>
928954
</widget>
929955
</item>
@@ -937,29 +963,22 @@ Use ; to define multiple screens: 1;1.5 etc...</string>
937963
</property>
938964
</widget>
939965
</item>
940-
<item row="4" column="0" colspan="2">
941-
<widget class="QLineEdit" name="lineCertKeyFile">
942-
<property name="placeholderText">
943-
<string>Absolute path to the cert key file</string>
944-
</property>
945-
</widget>
946-
</item>
947-
<item row="1" column="0">
948-
<widget class="QLabel" name="label_24">
949-
<property name="toolTip">
950-
<string>&lt;p&gt;Simple: no authentication&lt;/p&gt;
951-
&lt;p&gt;TLS simple/mutual: use SSL certificates to authenticate nodes.&lt;/p&gt;
952-
&lt;p&gt;Visit the wiki for more information.&lt;/p&gt;</string>
966+
<item row="5" column="0" colspan="2">
967+
<widget class="QLabel" name="label_28">
968+
<property name="sizePolicy">
969+
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
970+
<horstretch>0</horstretch>
971+
<verstretch>0</verstretch>
972+
</sizepolicy>
953973
</property>
954974
<property name="text">
955-
<string>Authentication type</string>
975+
<string>&lt;a href=&quot;https://github.com/evilsocket/opensnitch/wiki/Nodes-authentication#nodes-authentication-added-in-v161&quot;&gt;More information&lt;/a&gt;</string>
956976
</property>
957-
</widget>
958-
</item>
959-
<item row="2" column="0" colspan="2">
960-
<widget class="QLineEdit" name="lineCACertFile">
961-
<property name="placeholderText">
962-
<string>Absolute path to the CA cert file</string>
977+
<property name="openExternalLinks">
978+
<bool>true</bool>
979+
</property>
980+
<property name="textInteractionFlags">
981+
<set>Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse</set>
963982
</property>
964983
</widget>
965984
</item>
@@ -970,8 +989,8 @@ Use ; to define multiple screens: 1;1.5 etc...</string>
970989
<rect>
971990
<x>0</x>
972991
<y>0</y>
973-
<width>586</width>
974-
<height>301</height>
992+
<width>321</width>
993+
<height>112</height>
975994
</rect>
976995
</property>
977996
<attribute name="label">
@@ -1066,8 +1085,8 @@ Use ; to define multiple screens: 1;1.5 etc...</string>
10661085
<rect>
10671086
<x>0</x>
10681087
<y>0</y>
1069-
<width>586</width>
1070-
<height>301</height>
1088+
<width>219</width>
1089+
<height>115</height>
10711090
</rect>
10721091
</property>
10731092
<attribute name="label">
@@ -1487,7 +1506,8 @@ Temporary rules will still be valid, and you can use them when prompted to allow
14871506
<string>reject</string>
14881507
</property>
14891508
<property name="icon">
1490-
<iconset theme="window-close"/>
1509+
<iconset theme="window-close">
1510+
<normaloff>.</normaloff>.</iconset>
14911511
</property>
14921512
</item>
14931513
</widget>
@@ -1567,8 +1587,8 @@ Temporary rules will still be valid, and you can use them when prompted to allow
15671587
<rect>
15681588
<x>0</x>
15691589
<y>0</y>
1570-
<width>586</width>
1571-
<height>260</height>
1590+
<width>376</width>
1591+
<height>118</height>
15721592
</rect>
15731593
</property>
15741594
<attribute name="label">
@@ -1821,7 +1841,10 @@ Temporary rules will still be valid, and you can use them when prompted to allow
18211841
<item row="9" column="0">
18221842
<widget class="QLabel" name="label_26">
18231843
<property name="text">
1824-
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;a href=&quot;https://github.com/evilsocket/opensnitch/wiki/Nodes-authentication#nodes-authentication-added-in-v161&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#0000ff;&quot;&gt;More information&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
1844+
<string>&lt;a href=&quot;https://github.com/evilsocket/opensnitch/wiki/Nodes-authentication#nodes-authentication-added-in-v161&quot;&gt;More information&lt;/a&gt;</string>
1845+
</property>
1846+
<property name="openExternalLinks">
1847+
<bool>true</bool>
18251848
</property>
18261849
<property name="textInteractionFlags">
18271850
<set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse</set>

0 commit comments

Comments
 (0)