44 """ |
44 """ |
45 super(HgUserConfigDialog, self).__init__(parent) |
45 super(HgUserConfigDialog, self).__init__(parent) |
46 self.setupUi(self) |
46 self.setupUi(self) |
47 |
47 |
48 self.__version = version |
48 self.__version = version |
|
49 |
|
50 self.__minimumProtocols = { |
|
51 "tls1.0": self.tr("TLS 1.0"), |
|
52 "tls1.1": self.tr("TLS 1.1"), |
|
53 "tls1.2": self.tr("TLS 1.2"), |
|
54 } |
49 |
55 |
50 self.lfUserCachePicker.setMode(E5PathPickerModes.DirectoryMode) |
56 self.lfUserCachePicker.setMode(E5PathPickerModes.DirectoryMode) |
51 if Globals.isLinuxPlatform(): |
57 if Globals.isLinuxPlatform(): |
52 self.lfUserCachePicker.setDefaultDirectory(os.path.expanduser( |
58 self.lfUserCachePicker.setDefaultDirectory(os.path.expanduser( |
53 "~/.cache/largefiles")) |
59 "~/.cache/largefiles")) |
64 |
70 |
65 self.protocolAddButton.setIcon(UI.PixmapCache.getIcon("plus.png")) |
71 self.protocolAddButton.setIcon(UI.PixmapCache.getIcon("plus.png")) |
66 self.protocolDeleteButton.setIcon(UI.PixmapCache.getIcon("minus.png")) |
72 self.protocolDeleteButton.setIcon(UI.PixmapCache.getIcon("minus.png")) |
67 self.protocolEditButton.setIcon(UI.PixmapCache.getIcon("edit.png")) |
73 self.protocolEditButton.setIcon(UI.PixmapCache.getIcon("edit.png")) |
68 |
74 |
69 self.minimumProtocolComboBox.addItem("", "") |
75 self.minimumProtocolComboBox.addItem(self.tr("Default"), "") |
70 self.minimumProtocolComboBox.addItem(self.tr("TLS 1.0"), "tls1.0") |
76 for protocol in sorted(self.__minimumProtocols.keys()): |
71 self.minimumProtocolComboBox.addItem(self.tr("TLS 1.1"), "tls1.1") |
77 self.minimumProtocolComboBox.addItem( |
72 self.minimumProtocolComboBox.addItem(self.tr("TLS 1.2"), "tls1.2") |
78 self.__minimumProtocols[protocol], protocol) |
|
79 |
|
80 self.fingerprintsList.headerItem().setText( |
|
81 self.fingerprintsList.columnCount(), "") |
|
82 self.protocolsList.headerItem().setText( |
|
83 self.protocolsList.columnCount(), "") |
73 |
84 |
74 if self.__version < (3, 9, 0): |
85 if self.__version < (3, 9, 0): |
75 self.disableTls10WarningCheckBox.setEnabled(False) |
86 self.disableTls10WarningCheckBox.setEnabled(False) |
76 self.minimumProtocolComboBox.setEnabled(False) |
87 self.minimumProtocolComboBox.setEnabled(False) |
77 self.minimumProtcolGroupBox.setEnabled(False) |
88 self.minimumProtcolGroupBox.setEnabled(False) |
224 fingerprint |
236 fingerprint |
225 else: |
237 else: |
226 if "hostfingerprints" in self.__config: |
238 if "hostfingerprints" in self.__config: |
227 del self.__config["hostfingerprints"] |
239 del self.__config["hostfingerprints"] |
228 else: |
240 else: |
229 # TODO: add support for disabletls10warning = true |
|
230 # TODO: add support for minimumprotocol = (tls1.0, tls1.1, tls1.2) |
|
231 # TODO: add support for <hostname>:minimumprotocol = ... |
|
232 |
|
233 # |
241 # |
234 # delete hostfingerprints section |
242 # delete hostfingerprints section |
235 # |
243 # |
236 if "hostfingerprints" in self.__config: |
244 if "hostfingerprints" in self.__config: |
237 del self.__config["hostfingerprints"] |
245 del self.__config["hostfingerprints"] |
238 |
246 |
239 # |
247 # |
240 # hostsecurity section |
248 # hostsecurity section |
241 # |
249 # |
|
250 if "hostsecurity" not in self.__config: |
|
251 self.__config["hostsecurity"] = {} |
|
252 |
242 if self.fingerprintsList.topLevelItemCount() > 0: |
253 if self.fingerprintsList.topLevelItemCount() > 0: |
243 if "hostsecurity" not in self.__config: |
|
244 self.__config["hostsecurity"] = {} |
|
245 self.__clearFingerprints() |
254 self.__clearFingerprints() |
246 fingerprints = self.__assembleFingerprints() |
255 fingerprints = self.__assembleFingerprints() |
247 for host in fingerprints: |
256 for host in fingerprints: |
248 key = "{0}:fingerprints".format(host) |
257 key = "{0}:fingerprints".format(host) |
249 self.__config["hostsecurity"][key] = \ |
258 self.__config["hostsecurity"][key] = \ |
250 ", ".join(fingerprints[host]) |
259 ", ".join(fingerprints[host]) |
251 else: |
260 else: |
252 if "hostsecurity" in self.__config: |
261 self.__clearFingerprints() |
253 self.__clearFingerprints() |
262 |
254 if len(self.__config.options("hostsecurity")) == 0: |
263 if self.disableTls10WarningCheckBox.isChecked(): |
255 del self.__config["hostsecurity"] |
264 disabletls10warning = "true" |
|
265 else: |
|
266 disabletls10warning = "false" |
|
267 self.__config["hostsecurity"]["disabletls10warning"] = \ |
|
268 disabletls10warning |
|
269 |
|
270 if self.minimumProtocolComboBox.currentIndex() == 0: |
|
271 self.__config.remove_option("hostsecurity", "minimumprotocol") |
|
272 else: |
|
273 minimumProtocol = self.minimumProtocolComboBox.itemData( |
|
274 self.minimumProtocolComboBox.currentIndex()) |
|
275 self.__config["hostsecurity"]["minimumprotocol"] = \ |
|
276 minimumProtocol |
|
277 |
|
278 if self.protocolsList.topLevelItemCount() > 0: |
|
279 self.__clearMinimumProtocols() |
|
280 minimumProtocols = self.__assembleMinimumProtocols() |
|
281 for host in minimumProtocols: |
|
282 key = "{0}:minimumprotocol".format(host) |
|
283 self.__config["hostsecurity"][key] = minimumProtocols[host] |
|
284 else: |
|
285 self.__clearMinimumProtocols() |
|
286 |
|
287 if len(self.__config.options("hostsecurity")) == 0: |
|
288 del self.__config["hostsecurity"] |
256 ################################################################### |
289 ################################################################### |
257 |
290 |
258 cfgFile = getConfigPath() |
291 cfgFile = getConfigPath() |
259 with open(cfgFile, "w") as configFile: |
292 with open(cfgFile, "w") as configFile: |
260 self.__config.write(configFile) |
293 self.__config.write(configFile) |
261 |
|
262 def __clearFingerprints(self): |
|
263 """ |
|
264 Private method to clear the fingerprints from the hostsecurity section. |
|
265 """ |
|
266 if "hostsecurity" in self.__config: |
|
267 for key in self.__config.options("hostsecurity"): |
|
268 if key.endswith(":fingerprints"): |
|
269 self.__config.remove_option("hostsecurity", key) |
|
270 |
|
271 def __assembleFingerprints(self): |
|
272 """ |
|
273 Private method to assemble a list of host fingerprints. |
|
274 |
|
275 @return dictionary with list of fingerprints per host |
|
276 @rtype dict with str as key and list of str as value |
|
277 """ |
|
278 hostFingerprints = {} |
|
279 for row in range(self.fingerprintsList.topLevelItemCount()): |
|
280 itm = self.fingerprintsList.topLevelItem(row) |
|
281 host = itm.text(0) |
|
282 fingerprint = itm.text(1) |
|
283 if host in hostFingerprints: |
|
284 hostFingerprints[host].append(fingerprint) |
|
285 else: |
|
286 hostFingerprints[host] = [fingerprint] |
|
287 return hostFingerprints |
|
288 |
294 |
289 def readUserConfig(self): |
295 def readUserConfig(self): |
290 """ |
296 """ |
291 Public method to read the user configuration file. |
297 Public method to read the user configuration file. |
292 """ |
298 """ |
389 continue |
394 continue |
390 QTreeWidgetItem(self.fingerprintsList, [ |
395 QTreeWidgetItem(self.fingerprintsList, [ |
391 host, |
396 host, |
392 fingerprint.replace("\\", "").strip() |
397 fingerprint.replace("\\", "").strip() |
393 ]) |
398 ]) |
394 self.__finalizeFingerprintsColumns() |
399 |
395 # TODO: add support for disabletls10warning = true |
400 elif key == "disabletls10warning": |
396 # TODO: add support for minimumprotocol = (tls1.0, tls1.1, tls1.2) |
401 self.disableTls10WarningCheckBox.setChecked( |
397 # TODO: add support for <hostname>:minimumprotocol = ... |
402 self.__config.getboolean( |
|
403 "hostsecurity", "disabletls10warning")) |
|
404 |
|
405 elif key == "minimumprotocol": |
|
406 minimumProtocol = self.__config["hostsecurity"][key] |
|
407 index = self.minimumProtocolComboBox.findData( |
|
408 minimumProtocol) |
|
409 if index == -1: |
|
410 index = 0 |
|
411 self.minimumProtocolComboBox.setCurrentIndex(index) |
|
412 |
|
413 elif key.endswith(":minimumprotocol"): |
|
414 host = key.replace(":minimumprotocol", "") |
|
415 protocol = self.__config["hostsecurity"][key].strip() |
|
416 if protocol in self.__minimumProtocols: |
|
417 itm = QTreeWidgetItem(self.protocolsList, [ |
|
418 host, |
|
419 self.__minimumProtocols[protocol] |
|
420 ]) |
|
421 itm.setData(1, Qt.UserRole, protocol) |
|
422 |
|
423 self.__finalizeFingerprintsColumns() |
|
424 self.__finalizeProtocolsColumns() |
398 |
425 |
399 @pyqtSlot() |
426 @pyqtSlot() |
400 def accept(self): |
427 def accept(self): |
401 """ |
428 """ |
402 Public slot to accept the dialog. |
429 Public slot to accept the dialog. |
429 self.proxyPasswordEdit.clear() |
456 self.proxyPasswordEdit.clear() |
430 self.proxyBypassEdit.clear() |
457 self.proxyBypassEdit.clear() |
431 |
458 |
432 self.fingerprintsList.clear() |
459 self.fingerprintsList.clear() |
433 self.__updateFingerprintsButtons() |
460 self.__updateFingerprintsButtons() |
|
461 |
|
462 self.protocolsList.clear() |
|
463 self.__updateProtocolsButtons() |
434 |
464 |
435 ####################################################################### |
465 ####################################################################### |
436 ## Methods and slots for the host fingerprint handling below |
466 ## Methods and slots for the host fingerprint handling below |
437 ####################################################################### |
467 ####################################################################### |
|
468 |
|
469 def __clearFingerprints(self): |
|
470 """ |
|
471 Private method to clear the fingerprints from the hostsecurity section. |
|
472 """ |
|
473 if "hostsecurity" in self.__config: |
|
474 for key in self.__config.options("hostsecurity"): |
|
475 if key.endswith(":fingerprints"): |
|
476 self.__config.remove_option("hostsecurity", key) |
|
477 |
|
478 def __assembleFingerprints(self): |
|
479 """ |
|
480 Private method to assemble a list of host fingerprints. |
|
481 |
|
482 @return dictionary with list of fingerprints per host |
|
483 @rtype dict with str as key and list of str as value |
|
484 """ |
|
485 hostFingerprints = {} |
|
486 for row in range(self.fingerprintsList.topLevelItemCount()): |
|
487 itm = self.fingerprintsList.topLevelItem(row) |
|
488 host = itm.text(0) |
|
489 fingerprint = itm.text(1) |
|
490 if host in hostFingerprints: |
|
491 hostFingerprints[host].append(fingerprint) |
|
492 else: |
|
493 hostFingerprints[host] = [fingerprint] |
|
494 return hostFingerprints |
438 |
495 |
439 @pyqtSlot(QTreeWidgetItem, QTreeWidgetItem) |
496 @pyqtSlot(QTreeWidgetItem, QTreeWidgetItem) |
440 def on_fingerprintsList_currentItemChanged(self, current, previous): |
497 def on_fingerprintsList_currentItemChanged(self, current, previous): |
441 """ |
498 """ |
442 Private slot handling a change of the current fingerprints item. |
499 Private slot handling a change of the current fingerprints item. |
512 enable = self.fingerprintsList.currentItem() is not None |
569 enable = self.fingerprintsList.currentItem() is not None |
513 self.fpDeleteButton.setEnabled(enable) |
570 self.fpDeleteButton.setEnabled(enable) |
514 self.fpEditButton.setEnabled(enable) |
571 self.fpEditButton.setEnabled(enable) |
515 |
572 |
516 ####################################################################### |
573 ####################################################################### |
|
574 ## Methods and slots for the host minimum protocol handling below |
|
575 ####################################################################### |
|
576 |
|
577 def __clearMinimumProtocols(self): |
|
578 """ |
|
579 Private method to clear the minimum protocols from the hostsecurity |
|
580 section. |
|
581 """ |
|
582 if "hostsecurity" in self.__config: |
|
583 for key in self.__config.options("hostsecurity"): |
|
584 if key.endswith(":minimumprotocol"): |
|
585 self.__config.remove_option("hostsecurity", key) |
|
586 |
|
587 def __assembleMinimumProtocols(self): |
|
588 """ |
|
589 Private method to assemble a list of host minimum protocols. |
|
590 |
|
591 @return dictionary with list of minimum protocol per host |
|
592 @rtype dict with str as key and str as value |
|
593 """ |
|
594 minimumProtocols = {} |
|
595 for row in range(self.protocolsList.topLevelItemCount()): |
|
596 itm = self.protocolsList.topLevelItem(row) |
|
597 host = itm.text(0) |
|
598 minimumProtocol = itm.data(1, Qt.UserRole) |
|
599 minimumProtocols[host] = minimumProtocol |
|
600 return minimumProtocols |
|
601 |
|
602 @pyqtSlot(QTreeWidgetItem, QTreeWidgetItem) |
|
603 def on_protocolsList_currentItemChanged(self, current, previous): |
|
604 """ |
|
605 Private slot handling a change of the current minimum protocol item. |
|
606 |
|
607 @param current reference to the current item |
|
608 @type QTreeWidgetItem |
|
609 @param previous reference to the previous current item |
|
610 @type QTreeWidgetItem |
|
611 """ |
|
612 self.__updateProtocolsButtons() |
|
613 |
|
614 @pyqtSlot() |
|
615 def on_protocolAddButton_clicked(self): |
|
616 """ |
|
617 Slot documentation goes here. |
|
618 """ |
|
619 # TODO: not implemented yet |
|
620 raise NotImplementedError |
|
621 |
|
622 @pyqtSlot() |
|
623 def on_protocolDeleteButton_clicked(self): |
|
624 """ |
|
625 Slot documentation goes here. |
|
626 """ |
|
627 # TODO: not implemented yet |
|
628 raise NotImplementedError |
|
629 |
|
630 @pyqtSlot() |
|
631 def on_protocolEditButton_clicked(self): |
|
632 """ |
|
633 Slot documentation goes here. |
|
634 """ |
|
635 # TODO: not implemented yet |
|
636 raise NotImplementedError |
|
637 |
|
638 def __finalizeProtocolsColumns(self): |
|
639 """ |
|
640 Private method to resize and sort the host fingerprints columns. |
|
641 """ |
|
642 for col in range(self.protocolsList.columnCount()): |
|
643 self.protocolsList.resizeColumnToContents(col) |
|
644 self.protocolsList.sortItems(0, Qt.AscendingOrder) |
|
645 |
|
646 def __updateProtocolsButtons(self): |
|
647 """ |
|
648 Private slot to update the host minimum protocol edit buttons. |
|
649 """ |
|
650 enable = self.protocolsList.currentItem() is not None |
|
651 self.protocolDeleteButton.setEnabled(enable) |
|
652 self.protocolEditButton.setEnabled(enable) |
|
653 |
|
654 ####################################################################### |
517 ## Slot to edit the user configuration in an editor below |
655 ## Slot to edit the user configuration in an editor below |
518 ####################################################################### |
656 ####################################################################### |
519 |
657 |
520 @pyqtSlot() |
658 @pyqtSlot() |
521 def on_editorButton_clicked(self): |
659 def on_editorButton_clicked(self): |
557 self.__clearDialog() |
695 self.__clearDialog() |
558 self.readUserConfig() |
696 self.readUserConfig() |
559 return True |
697 return True |
560 |
698 |
561 return False |
699 return False |
562 |
|
563 @pyqtSlot(QTreeWidgetItem, QTreeWidgetItem) |
|
564 def on_protocolsList_currentItemChanged(self, current, previous): |
|
565 """ |
|
566 Slot documentation goes here. |
|
567 |
|
568 @param current DESCRIPTION |
|
569 @type QTreeWidgetItem |
|
570 @param previous DESCRIPTION |
|
571 @type QTreeWidgetItem |
|
572 """ |
|
573 # TODO: not implemented yet |
|
574 return |
|
575 |
|
576 @pyqtSlot() |
|
577 def on_protocolAddButton_clicked(self): |
|
578 """ |
|
579 Slot documentation goes here. |
|
580 """ |
|
581 # TODO: not implemented yet |
|
582 raise NotImplementedError |
|
583 |
|
584 @pyqtSlot() |
|
585 def on_protocolDeleteButton_clicked(self): |
|
586 """ |
|
587 Slot documentation goes here. |
|
588 """ |
|
589 # TODO: not implemented yet |
|
590 raise NotImplementedError |
|
591 |
|
592 @pyqtSlot() |
|
593 def on_protocolEditButton_clicked(self): |
|
594 """ |
|
595 Slot documentation goes here. |
|
596 """ |
|
597 # TODO: not implemented yet |
|
598 raise NotImplementedError |
|