|
1
|
|
|
from PyQt5.QtWidgets import QDialog, QFileDialog |
|
2
|
|
|
|
|
3
|
|
|
from uaclient.connection_ui import Ui_ConnectionDialog |
|
4
|
|
|
from uawidgets.utils import trycatchslot |
|
5
|
|
|
|
|
6
|
|
|
|
|
7
|
|
|
class ConnectionDialog(QDialog): |
|
8
|
|
|
def __init__(self, parent, uri): |
|
9
|
|
|
QDialog.__init__(self) |
|
10
|
|
|
self.ui = Ui_ConnectionDialog() |
|
11
|
|
|
self.ui.setupUi(self) |
|
12
|
|
|
|
|
13
|
|
|
self.uaclient = parent.uaclient |
|
14
|
|
|
self.uri = uri |
|
15
|
|
|
self.parent = parent |
|
16
|
|
|
|
|
17
|
|
|
self.ui.modeComboBox.addItem("None") |
|
18
|
|
|
self.ui.modeComboBox.addItem("Sign") |
|
19
|
|
|
self.ui.modeComboBox.addItem("SignAndEncrypt") |
|
20
|
|
|
|
|
21
|
|
|
self.ui.policyComboBox.addItem("None") |
|
22
|
|
|
self.ui.policyComboBox.addItem("Basic128Rsa15") |
|
23
|
|
|
self.ui.policyComboBox.addItem("Basic256") |
|
24
|
|
|
|
|
25
|
|
|
self.ui.closeButton.clicked.connect(self.accept) |
|
26
|
|
|
self.ui.certificateButton.clicked.connect(self.get_certificate) |
|
27
|
|
|
self.ui.privateKeyButton.clicked.connect(self.get_private_key) |
|
28
|
|
|
self.ui.queryButton.clicked.connect(self.query) |
|
29
|
|
|
|
|
30
|
|
|
@trycatchslot |
|
31
|
|
|
def query(self): |
|
32
|
|
|
self.ui.modeComboBox.clear() |
|
33
|
|
|
self.ui.policyComboBox.clear() |
|
34
|
|
|
endpoints = self.parent.uaclient.get_endpoints(self.uri) |
|
35
|
|
|
modes = [] |
|
36
|
|
|
policies = [] |
|
37
|
|
|
for edp in endpoints: |
|
38
|
|
|
mode = edp.SecurityMode.name |
|
39
|
|
|
if mode not in modes: |
|
40
|
|
|
self.ui.modeComboBox.addItem(mode) |
|
41
|
|
|
modes.append(mode) |
|
42
|
|
|
policy = edp.SecurityPolicyUri.split("#")[1] |
|
43
|
|
|
if policy not in policies: |
|
44
|
|
|
self.ui.policyComboBox.addItem(policy) |
|
45
|
|
|
policies.append(policy) |
|
46
|
|
|
|
|
47
|
|
|
@property |
|
48
|
|
|
def security_mode(self): |
|
49
|
|
|
text = self.ui.modeComboBox.currentText() |
|
50
|
|
|
if text == "None": |
|
51
|
|
|
return None |
|
52
|
|
|
return text |
|
53
|
|
|
|
|
54
|
|
|
@security_mode.setter |
|
55
|
|
|
def security_mode(self, value): |
|
56
|
|
|
self.ui.modeComboBox.setCurrentText(value) |
|
57
|
|
|
|
|
58
|
|
|
@property |
|
59
|
|
|
def security_policy(self): |
|
60
|
|
|
text = self.ui.policyComboBox.currentText() |
|
61
|
|
|
if text == "None": |
|
62
|
|
|
return None |
|
63
|
|
|
return text |
|
64
|
|
|
|
|
65
|
|
|
@security_policy.setter |
|
66
|
|
|
def security_policy(self, value): |
|
67
|
|
|
self.ui.policyComboBox.setCurrentText(value) |
|
68
|
|
|
|
|
69
|
|
|
@property |
|
70
|
|
|
def certificate_path(self): |
|
71
|
|
|
return self.ui.certificateLabel.text() |
|
72
|
|
|
|
|
73
|
|
|
@certificate_path.setter |
|
74
|
|
|
def certificate_path(self, value): |
|
75
|
|
|
self.ui.certificateLabel.setText(value) |
|
76
|
|
|
|
|
77
|
|
|
@property |
|
78
|
|
|
def private_key_path(self): |
|
79
|
|
|
return self.ui.privateKeyLabel.text() |
|
80
|
|
|
|
|
81
|
|
|
@private_key_path.setter |
|
82
|
|
|
def private_key_path(self, value): |
|
83
|
|
|
self.ui.privateKeyLabel.setText(value) |
|
84
|
|
|
|
|
85
|
|
|
def get_certificate(self): |
|
86
|
|
|
path, ok = QFileDialog.getOpenFileName(self, "Select certificate", self.certificate_path, "Certificate (*.der)") |
|
87
|
|
|
if ok: |
|
88
|
|
|
self.ui.certificateLabel.setText(path) |
|
89
|
|
|
|
|
90
|
|
|
def get_private_key(self): |
|
91
|
|
|
path, ok = QFileDialog.getOpenFileName(self, "Select private key", self.private_key_path, "Private key (*.pem)") |
|
92
|
|
|
if ok: |
|
93
|
|
|
self.ui.privateKeyLabel.setText(path) |
|
94
|
|
|
|
|
95
|
|
|
|
|
96
|
|
|
|