Merge lp:~pete-woods/indicator-network/keyring-support into lp:indicator-network
- keyring-support
- Merge into trunk
Proposed by
Pete Woods
Status: | Merged |
---|---|
Approved by: | Pete Woods |
Approved revision: | no longer in the source branch. |
Merged at revision: | 566 |
Proposed branch: | lp:~pete-woods/indicator-network/keyring-support |
Merge into: | lp:indicator-network |
Prerequisite: | lp:~pete-woods/indicator-network/pptp-ui |
Diff against target: |
1247 lines (+631/-129) 22 files modified
CMakeLists.txt (+12/-0) debian/control (+1/-0) src/CMakeLists.txt (+2/-0) src/agent/CMakeLists.txt (+61/-0) src/agent/CredentialStore.cpp (+29/-0) src/agent/CredentialStore.h (+44/-0) src/agent/KeyringCredentialStore.cpp (+154/-0) src/agent/KeyringCredentialStore.h (+44/-0) src/agent/SecretAgent.cpp (+162/-13) src/agent/SecretAgent.h (+43/-13) src/agent/SecretRequest.cpp (+16/-12) src/agent/SecretRequest.h (+2/-0) src/agent/agent-main.cpp (+11/-13) src/indicator/CMakeLists.txt (+3/-37) src/indicator/factory.cpp (+0/-7) src/indicator/factory.h (+0/-2) src/indicator/nmofono/vpn/vpn-manager.cpp (+1/-1) src/notify-cpp/CMakeLists.txt (+1/-0) src/util/CMakeLists.txt (+8/-0) tests/unit/CMakeLists.txt (+1/-1) tests/unit/secret-agent/secret-agent-main.cpp (+10/-4) tests/unit/secret-agent/test-secret-agent.cpp (+26/-26) |
To merge this branch: | bzr merge lp:~pete-woods/indicator-network/keyring-support |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Indicator Applet Developers | Pending | ||
PS Jenkins bot | continuous-integration | Pending | |
Review via email: mp+286029@code.launchpad.net |
Commit message
Add keyring support to secret agent (requires libsecret)
Description of the change
Add keyring support to secret agent (requires libsecret)
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'CMakeLists.txt' | |||
2 | --- CMakeLists.txt 2015-08-03 13:27:40 +0000 | |||
3 | +++ CMakeLists.txt 2016-02-23 09:05:39 +0000 | |||
4 | @@ -60,6 +60,18 @@ | |||
5 | 60 | ) | 60 | ) |
6 | 61 | include_directories(${OFONO_INCLUDE_DIRS}) | 61 | include_directories(${OFONO_INCLUDE_DIRS}) |
7 | 62 | 62 | ||
8 | 63 | pkg_check_modules( | ||
9 | 64 | NETWORKMANAGER REQUIRED | ||
10 | 65 | NetworkManager | ||
11 | 66 | ) | ||
12 | 67 | include_directories(${NETWORKMANAGER_INCLUDE_DIRS}) | ||
13 | 68 | |||
14 | 69 | pkg_check_modules( | ||
15 | 70 | LIBSECRET REQUIRED | ||
16 | 71 | libsecret-1 | ||
17 | 72 | ) | ||
18 | 73 | include_directories(${LIBSECRET_INCLUDE_DIRS}) | ||
19 | 74 | |||
20 | 63 | find_package(Qt5Core REQUIRED) | 75 | find_package(Qt5Core REQUIRED) |
21 | 64 | include_directories(${Qt5Core_INCLUDE_DIRS}) | 76 | include_directories(${Qt5Core_INCLUDE_DIRS}) |
22 | 65 | 77 | ||
23 | 66 | 78 | ||
24 | === modified file 'debian/control' | |||
25 | --- debian/control 2016-02-23 09:05:39 +0000 | |||
26 | +++ debian/control 2016-02-23 09:05:39 +0000 | |||
27 | @@ -17,6 +17,7 @@ | |||
28 | 17 | libqofono-qt5-0, | 17 | libqofono-qt5-0, |
29 | 18 | libqtdbusmock1-dev (>= 0.4), | 18 | libqtdbusmock1-dev (>= 0.4), |
30 | 19 | libqtdbustest1-dev, | 19 | libqtdbustest1-dev, |
31 | 20 | libsecret-1-dev, | ||
32 | 20 | liburl-dispatcher1-dev, | 21 | liburl-dispatcher1-dev, |
33 | 21 | libunity-api-dev, | 22 | libunity-api-dev, |
34 | 22 | network-manager-dev, | 23 | network-manager-dev, |
35 | 23 | 24 | ||
36 | === modified file 'src/CMakeLists.txt' | |||
37 | --- src/CMakeLists.txt 2015-07-28 08:26:51 +0000 | |||
38 | +++ src/CMakeLists.txt 2016-02-23 09:05:39 +0000 | |||
39 | @@ -1,6 +1,7 @@ | |||
40 | 1 | 1 | ||
41 | 2 | add_subdirectory(connectivity-api) | 2 | add_subdirectory(connectivity-api) |
42 | 3 | 3 | ||
43 | 4 | add_subdirectory(agent) | ||
44 | 4 | add_subdirectory(indicator) | 5 | add_subdirectory(indicator) |
45 | 5 | add_subdirectory(menumodel-cpp) | 6 | add_subdirectory(menumodel-cpp) |
46 | 6 | add_subdirectory(qdbus-stubs) | 7 | add_subdirectory(qdbus-stubs) |
47 | @@ -8,3 +9,4 @@ | |||
48 | 8 | add_subdirectory(notify-cpp) | 9 | add_subdirectory(notify-cpp) |
49 | 9 | add_subdirectory(sniffer) | 10 | add_subdirectory(sniffer) |
50 | 10 | add_subdirectory(url-dispatcher-cpp) | 11 | add_subdirectory(url-dispatcher-cpp) |
51 | 12 | add_subdirectory(util) | ||
52 | 11 | 13 | ||
53 | === renamed directory 'src/indicator/agent' => 'src/agent' | |||
54 | === added file 'src/agent/CMakeLists.txt' | |||
55 | --- src/agent/CMakeLists.txt 1970-01-01 00:00:00 +0000 | |||
56 | +++ src/agent/CMakeLists.txt 2016-02-23 09:05:39 +0000 | |||
57 | @@ -0,0 +1,61 @@ | |||
58 | 1 | |||
59 | 2 | include_directories("${CMAKE_SOURCE_DIR}/src") | ||
60 | 3 | include_directories("${CMAKE_BINARY_DIR}/src/qdbus-stubs") | ||
61 | 4 | include_directories("${CMAKE_SOURCE_DIR}/src/qdbus-stubs") | ||
62 | 5 | |||
63 | 6 | set(AGENT_SOURCES | ||
64 | 7 | CredentialStore.cpp | ||
65 | 8 | KeyringCredentialStore.cpp | ||
66 | 9 | SecretAgent.cpp | ||
67 | 10 | SecretRequest.cpp | ||
68 | 11 | PasswordMenu.cpp | ||
69 | 12 | ) | ||
70 | 13 | |||
71 | 14 | qt5_add_dbus_adaptor( | ||
72 | 15 | AGENT_SOURCES | ||
73 | 16 | "${DATA_DIR}/nm-secret-agent.xml" | ||
74 | 17 | "agent/SecretAgentInclude.h" | ||
75 | 18 | "agent::SecretAgent" | ||
76 | 19 | SecretAgentAdaptor | ||
77 | 20 | ) | ||
78 | 21 | |||
79 | 22 | add_library( | ||
80 | 23 | agent-static | ||
81 | 24 | STATIC | ||
82 | 25 | ${AGENT_SOURCES} | ||
83 | 26 | ) | ||
84 | 27 | |||
85 | 28 | target_link_libraries( | ||
86 | 29 | agent-static | ||
87 | 30 | notify_cpp | ||
88 | 31 | util | ||
89 | 32 | Qt5::Core | ||
90 | 33 | Qt5::DBus | ||
91 | 34 | ${LIBSECRET_LDFLAGS} | ||
92 | 35 | ) | ||
93 | 36 | |||
94 | 37 | ########################### | ||
95 | 38 | # Executables | ||
96 | 39 | ########################### | ||
97 | 40 | |||
98 | 41 | add_executable( | ||
99 | 42 | indicator-network-secret-agent | ||
100 | 43 | agent-main.cpp | ||
101 | 44 | ) | ||
102 | 45 | |||
103 | 46 | target_link_libraries( | ||
104 | 47 | indicator-network-secret-agent | ||
105 | 48 | agent-static | ||
106 | 49 | Qt5::Core | ||
107 | 50 | Qt5::DBus | ||
108 | 51 | ) | ||
109 | 52 | |||
110 | 53 | ########################### | ||
111 | 54 | # Installation | ||
112 | 55 | ########################### | ||
113 | 56 | |||
114 | 57 | install( | ||
115 | 58 | TARGETS | ||
116 | 59 | indicator-network-secret-agent | ||
117 | 60 | RUNTIME DESTINATION "${CMAKE_INSTALL_LIBEXECDIR}/indicator-network/" | ||
118 | 61 | ) | ||
119 | 0 | 62 | ||
120 | === added file 'src/agent/CredentialStore.cpp' | |||
121 | --- src/agent/CredentialStore.cpp 1970-01-01 00:00:00 +0000 | |||
122 | +++ src/agent/CredentialStore.cpp 2016-02-23 09:05:39 +0000 | |||
123 | @@ -0,0 +1,29 @@ | |||
124 | 1 | /* | ||
125 | 2 | * Copyright (C) 2016 Canonical, Ltd. | ||
126 | 3 | * | ||
127 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
128 | 5 | * under the terms of the GNU General Public License version 3, as published | ||
129 | 6 | * by the Free Software Foundation. | ||
130 | 7 | * | ||
131 | 8 | * This program is distributed in the hope that it will be useful, but | ||
132 | 9 | * WITHOUT ANY WARRANTY; without even the implied warranties of | ||
133 | 10 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
134 | 11 | * PURPOSE. See the GNU General Public License for more details. | ||
135 | 12 | * | ||
136 | 13 | * You should have received a copy of the GNU General Public License along | ||
137 | 14 | * with this program. If not, see <http://www.gnu.org/licenses/>. | ||
138 | 15 | * | ||
139 | 16 | * Author: Pete Woods <pete.woods@canonical.com> | ||
140 | 17 | */ | ||
141 | 18 | |||
142 | 19 | #include <agent/CredentialStore.h> | ||
143 | 20 | |||
144 | 21 | namespace agent { | ||
145 | 22 | |||
146 | 23 | CredentialStore::CredentialStore() { | ||
147 | 24 | } | ||
148 | 25 | |||
149 | 26 | CredentialStore::~CredentialStore() { | ||
150 | 27 | } | ||
151 | 28 | |||
152 | 29 | } | ||
153 | 0 | 30 | ||
154 | === added file 'src/agent/CredentialStore.h' | |||
155 | --- src/agent/CredentialStore.h 1970-01-01 00:00:00 +0000 | |||
156 | +++ src/agent/CredentialStore.h 2016-02-23 09:05:39 +0000 | |||
157 | @@ -0,0 +1,44 @@ | |||
158 | 1 | /* | ||
159 | 2 | * Copyright (C) 2016 Canonical, Ltd. | ||
160 | 3 | * | ||
161 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
162 | 5 | * under the terms of the GNU General Public License version 3, as published | ||
163 | 6 | * by the Free Software Foundation. | ||
164 | 7 | * | ||
165 | 8 | * This program is distributed in the hope that it will be useful, but | ||
166 | 9 | * WITHOUT ANY WARRANTY; without even the implied warranties of | ||
167 | 10 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
168 | 11 | * PURPOSE. See the GNU General Public License for more details. | ||
169 | 12 | * | ||
170 | 13 | * You should have received a copy of the GNU General Public License along | ||
171 | 14 | * with this program. If not, see <http://www.gnu.org/licenses/>. | ||
172 | 15 | * | ||
173 | 16 | * Author: Pete Woods <pete.woods@canonical.com> | ||
174 | 17 | */ | ||
175 | 18 | |||
176 | 19 | #pragma once | ||
177 | 20 | |||
178 | 21 | #include <unity/util/DefinesPtrs.h> | ||
179 | 22 | |||
180 | 23 | #include <QMap> | ||
181 | 24 | #include <QString> | ||
182 | 25 | |||
183 | 26 | namespace agent { | ||
184 | 27 | |||
185 | 28 | class CredentialStore { | ||
186 | 29 | public: | ||
187 | 30 | UNITY_DEFINES_PTRS(CredentialStore); | ||
188 | 31 | |||
189 | 32 | CredentialStore(); | ||
190 | 33 | |||
191 | 34 | virtual ~CredentialStore(); | ||
192 | 35 | |||
193 | 36 | virtual void save(const QString& uuid, const QString& settingName, const QString& settingKey, | ||
194 | 37 | const QString& displayName, const QString& secret) = 0; | ||
195 | 38 | |||
196 | 39 | virtual QMap<QString, QString> get(const QString& uuid, const QString& settingName) = 0; | ||
197 | 40 | |||
198 | 41 | virtual void clear(const QString& uuid) = 0; | ||
199 | 42 | }; | ||
200 | 43 | |||
201 | 44 | } | ||
202 | 0 | 45 | ||
203 | === added file 'src/agent/KeyringCredentialStore.cpp' | |||
204 | --- src/agent/KeyringCredentialStore.cpp 1970-01-01 00:00:00 +0000 | |||
205 | +++ src/agent/KeyringCredentialStore.cpp 2016-02-23 09:05:39 +0000 | |||
206 | @@ -0,0 +1,154 @@ | |||
207 | 1 | /* | ||
208 | 2 | * Copyright (C) 2016 Canonical, Ltd. | ||
209 | 3 | * | ||
210 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
211 | 5 | * under the terms of the GNU General Public License version 3, as published | ||
212 | 6 | * by the Free Software Foundation. | ||
213 | 7 | * | ||
214 | 8 | * This program is distributed in the hope that it will be useful, but | ||
215 | 9 | * WITHOUT ANY WARRANTY; without even the implied warranties of | ||
216 | 10 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
217 | 11 | * PURPOSE. See the GNU General Public License for more details. | ||
218 | 12 | * | ||
219 | 13 | * You should have received a copy of the GNU General Public License along | ||
220 | 14 | * with this program. If not, see <http://www.gnu.org/licenses/>. | ||
221 | 15 | * | ||
222 | 16 | * Author: Pete Woods <pete.woods@canonical.com> | ||
223 | 17 | */ | ||
224 | 18 | |||
225 | 19 | #include <agent/KeyringCredentialStore.h> | ||
226 | 20 | |||
227 | 21 | #include <libsecret/secret.h> | ||
228 | 22 | #include <QDebug> | ||
229 | 23 | |||
230 | 24 | #define KEYRING_UUID_TAG "connection-uuid" | ||
231 | 25 | #define KEYRING_SN_TAG "setting-name" | ||
232 | 26 | #define KEYRING_SK_TAG "setting-key" | ||
233 | 27 | |||
234 | 28 | static const SecretSchema network_manager_secret_schema = { | ||
235 | 29 | "org.freedesktop.NetworkManager.Connection", | ||
236 | 30 | SECRET_SCHEMA_DONT_MATCH_NAME, | ||
237 | 31 | { | ||
238 | 32 | {KEYRING_UUID_TAG, SECRET_SCHEMA_ATTRIBUTE_STRING}, | ||
239 | 33 | {KEYRING_SN_TAG, SECRET_SCHEMA_ATTRIBUTE_STRING}, | ||
240 | 34 | {KEYRING_SK_TAG, SECRET_SCHEMA_ATTRIBUTE_STRING}, | ||
241 | 35 | {NULL, (SecretSchemaAttributeType) 0}, | ||
242 | 36 | }, | ||
243 | 37 | // The below junk prevents compilation warnings for | ||
244 | 38 | // the uninitialised reserved values | ||
245 | 39 | 0, | ||
246 | 40 | (gpointer) 0, | ||
247 | 41 | (gpointer) 0, | ||
248 | 42 | (gpointer) 0, | ||
249 | 43 | (gpointer) 0, | ||
250 | 44 | (gpointer) 0, | ||
251 | 45 | (gpointer) 0, | ||
252 | 46 | (gpointer) 0 | ||
253 | 47 | }; | ||
254 | 48 | |||
255 | 49 | using namespace std; | ||
256 | 50 | |||
257 | 51 | namespace agent { | ||
258 | 52 | |||
259 | 53 | KeyringCredentialStore::KeyringCredentialStore() { | ||
260 | 54 | } | ||
261 | 55 | |||
262 | 56 | KeyringCredentialStore::~KeyringCredentialStore() { | ||
263 | 57 | } | ||
264 | 58 | |||
265 | 59 | void KeyringCredentialStore::save(const QString& uuid, | ||
266 | 60 | const QString& settingName, const QString& settingKey, | ||
267 | 61 | const QString& displayName, const QString& secret) { | ||
268 | 62 | shared_ptr<GHashTable> attrs( | ||
269 | 63 | secret_attributes_build(&network_manager_secret_schema, | ||
270 | 64 | KEYRING_UUID_TAG, uuid.toUtf8().constData(), | ||
271 | 65 | KEYRING_SN_TAG, settingName.toUtf8().constData(), | ||
272 | 66 | KEYRING_SK_TAG, settingKey.toUtf8().constData(), | ||
273 | 67 | NULL), &g_hash_table_unref); | ||
274 | 68 | |||
275 | 69 | GError* error = NULL; | ||
276 | 70 | if (!secret_password_storev_sync(&network_manager_secret_schema, | ||
277 | 71 | attrs.get(), | ||
278 | 72 | NULL, | ||
279 | 73 | displayName.toUtf8().constData(), | ||
280 | 74 | secret.toUtf8().constData(), | ||
281 | 75 | NULL, &error)) { | ||
282 | 76 | QString message; | ||
283 | 77 | if (error != NULL) { | ||
284 | 78 | if (error->message) { | ||
285 | 79 | message = QString::fromUtf8(error->message); | ||
286 | 80 | } | ||
287 | 81 | g_error_free(error); | ||
288 | 82 | } | ||
289 | 83 | qCritical() << __PRETTY_FUNCTION__ << message; | ||
290 | 84 | } | ||
291 | 85 | } | ||
292 | 86 | |||
293 | 87 | QMap<QString, QString> KeyringCredentialStore::get(const QString& uuid, const QString& settingName) { | ||
294 | 88 | QMap<QString, QString> result; | ||
295 | 89 | |||
296 | 90 | shared_ptr<GHashTable> attrs(secret_attributes_build( | ||
297 | 91 | &network_manager_secret_schema, | ||
298 | 92 | KEYRING_UUID_TAG, uuid.toUtf8().constData(), | ||
299 | 93 | KEYRING_SN_TAG, settingName.toUtf8().constData(), | ||
300 | 94 | NULL), &g_hash_table_unref); | ||
301 | 95 | |||
302 | 96 | GError* error = NULL; | ||
303 | 97 | shared_ptr<GList> list(secret_service_search_sync(NULL, | ||
304 | 98 | &network_manager_secret_schema, attrs.get(), | ||
305 | 99 | (SecretSearchFlags) (SECRET_SEARCH_ALL | SECRET_SEARCH_UNLOCK | ||
306 | 100 | | SECRET_SEARCH_LOAD_SECRETS), NULL, &error), [](GList* list) { | ||
307 | 101 | g_list_free_full (list, g_object_unref); | ||
308 | 102 | }); | ||
309 | 103 | |||
310 | 104 | if (list == NULL) { | ||
311 | 105 | if (error != NULL) { | ||
312 | 106 | string errorMessage; | ||
313 | 107 | if (error->message) { | ||
314 | 108 | errorMessage = error->message; | ||
315 | 109 | } | ||
316 | 110 | g_error_free(error); | ||
317 | 111 | throw domain_error(errorMessage); | ||
318 | 112 | } | ||
319 | 113 | |||
320 | 114 | return result; | ||
321 | 115 | } | ||
322 | 116 | |||
323 | 117 | for (GList* iter = list.get(); iter != NULL; iter = g_list_next(iter)) { | ||
324 | 118 | SecretItem *item = (SecretItem *) iter->data; | ||
325 | 119 | shared_ptr<SecretValue> secret(secret_item_get_secret(item), &secret_value_unref); | ||
326 | 120 | if (secret) { | ||
327 | 121 | shared_ptr<GHashTable> attributes(secret_item_get_attributes(item), &g_hash_table_unref); | ||
328 | 122 | const char *keyName = (const char *) g_hash_table_lookup(attributes.get(), | ||
329 | 123 | KEYRING_SK_TAG); | ||
330 | 124 | if (!keyName) { | ||
331 | 125 | continue; | ||
332 | 126 | } | ||
333 | 127 | |||
334 | 128 | QString keyString = QString::fromUtf8(keyName); | ||
335 | 129 | QString secretString = QString::fromUtf8(secret_value_get(secret.get(), NULL)); | ||
336 | 130 | |||
337 | 131 | result[keyString] = secretString; | ||
338 | 132 | } | ||
339 | 133 | } | ||
340 | 134 | |||
341 | 135 | return result; | ||
342 | 136 | } | ||
343 | 137 | |||
344 | 138 | void KeyringCredentialStore::clear(const QString& uuid) { | ||
345 | 139 | GError *error = NULL; | ||
346 | 140 | if (!secret_password_clear_sync(&network_manager_secret_schema, NULL, &error, | ||
347 | 141 | KEYRING_UUID_TAG, uuid.toUtf8().constData(), | ||
348 | 142 | NULL)) { | ||
349 | 143 | if (error != NULL) { | ||
350 | 144 | QString message; | ||
351 | 145 | if (error->message) { | ||
352 | 146 | message = QString::fromUtf8(error->message); | ||
353 | 147 | } | ||
354 | 148 | g_error_free(error); | ||
355 | 149 | qCritical() << __PRETTY_FUNCTION__ << message; | ||
356 | 150 | } | ||
357 | 151 | } | ||
358 | 152 | } | ||
359 | 153 | |||
360 | 154 | } | ||
361 | 0 | 155 | ||
362 | === added file 'src/agent/KeyringCredentialStore.h' | |||
363 | --- src/agent/KeyringCredentialStore.h 1970-01-01 00:00:00 +0000 | |||
364 | +++ src/agent/KeyringCredentialStore.h 2016-02-23 09:05:39 +0000 | |||
365 | @@ -0,0 +1,44 @@ | |||
366 | 1 | /* | ||
367 | 2 | * Copyright (C) 2016 Canonical, Ltd. | ||
368 | 3 | * | ||
369 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
370 | 5 | * under the terms of the GNU General Public License version 3, as published | ||
371 | 6 | * by the Free Software Foundation. | ||
372 | 7 | * | ||
373 | 8 | * This program is distributed in the hope that it will be useful, but | ||
374 | 9 | * WITHOUT ANY WARRANTY; without even the implied warranties of | ||
375 | 10 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
376 | 11 | * PURPOSE. See the GNU General Public License for more details. | ||
377 | 12 | * | ||
378 | 13 | * You should have received a copy of the GNU General Public License along | ||
379 | 14 | * with this program. If not, see <http://www.gnu.org/licenses/>. | ||
380 | 15 | * | ||
381 | 16 | * Author: Pete Woods <pete.woods@canonical.com> | ||
382 | 17 | */ | ||
383 | 18 | |||
384 | 19 | #pragma once | ||
385 | 20 | |||
386 | 21 | #include <agent/CredentialStore.h> | ||
387 | 22 | |||
388 | 23 | #include <QList> | ||
389 | 24 | #include <QPair> | ||
390 | 25 | #include <QString> | ||
391 | 26 | |||
392 | 27 | namespace agent { | ||
393 | 28 | |||
394 | 29 | class KeyringCredentialStore: public CredentialStore { | ||
395 | 30 | public: | ||
396 | 31 | KeyringCredentialStore(); | ||
397 | 32 | |||
398 | 33 | ~KeyringCredentialStore(); | ||
399 | 34 | |||
400 | 35 | void save(const QString& uuid, const QString& settingName, | ||
401 | 36 | const QString& settingKey, const QString& displayName, | ||
402 | 37 | const QString& secret) override; | ||
403 | 38 | |||
404 | 39 | QMap<QString, QString> get(const QString& uuid, const QString& settingName) override; | ||
405 | 40 | |||
406 | 41 | void clear(const QString& uuid) override; | ||
407 | 42 | }; | ||
408 | 43 | |||
409 | 44 | } | ||
410 | 0 | 45 | ||
411 | === modified file 'src/agent/SecretAgent.cpp' | |||
412 | --- src/indicator/agent/SecretAgent.cpp 2015-11-20 13:14:50 +0000 | |||
413 | +++ src/agent/SecretAgent.cpp 2016-02-23 09:05:39 +0000 | |||
414 | @@ -25,6 +25,13 @@ | |||
415 | 25 | #include <NetworkManager.h> | 25 | #include <NetworkManager.h> |
416 | 26 | #include <stdexcept> | 26 | #include <stdexcept> |
417 | 27 | 27 | ||
418 | 28 | #define NM_SECRET_AGENT_CAPABILITY_NONE 0 | ||
419 | 29 | |||
420 | 30 | #define NM_SECRET_AGENT_GET_SECRETS_FLAG_NONE 0 | ||
421 | 31 | #define NM_SECRET_AGENT_GET_SECRETS_FLAG_ALLOW_INTERACTION 1 | ||
422 | 32 | #define NM_SECRET_AGENT_GET_SECRETS_FLAG_REQUEST_NEW 2 | ||
423 | 33 | #define NM_SECRET_AGENT_GET_SECRETS_FLAG_USER_REQUESTED 4 | ||
424 | 34 | |||
425 | 28 | using namespace std; | 35 | using namespace std; |
426 | 29 | 36 | ||
427 | 30 | namespace agent | 37 | namespace agent |
428 | @@ -34,16 +41,85 @@ | |||
429 | 34 | Q_OBJECT | 41 | Q_OBJECT |
430 | 35 | 42 | ||
431 | 36 | public: | 43 | public: |
433 | 37 | Priv(notify::NotificationManager::SPtr notificationManager, const QDBusConnection &systemConnection, | 44 | Priv(notify::NotificationManager::SPtr notificationManager, |
434 | 45 | agent::CredentialStore::SPtr credentialStore, | ||
435 | 46 | const QDBusConnection &systemConnection, | ||
436 | 38 | const QDBusConnection &sessionConnection) : | 47 | const QDBusConnection &sessionConnection) : |
437 | 39 | m_systemConnection(systemConnection), | 48 | m_systemConnection(systemConnection), |
438 | 40 | m_sessionConnection(sessionConnection), | 49 | m_sessionConnection(sessionConnection), |
439 | 41 | m_managerWatcher(NM_DBUS_SERVICE, m_systemConnection), | 50 | m_managerWatcher(NM_DBUS_SERVICE, m_systemConnection), |
440 | 42 | m_agentManager(NM_DBUS_SERVICE, NM_DBUS_PATH_AGENT_MANAGER, m_systemConnection), | 51 | m_agentManager(NM_DBUS_SERVICE, NM_DBUS_PATH_AGENT_MANAGER, m_systemConnection), |
441 | 43 | m_notifications(notificationManager), | 52 | m_notifications(notificationManager), |
442 | 53 | m_credentialStore(credentialStore), | ||
443 | 44 | m_request(nullptr) { | 54 | m_request(nullptr) { |
444 | 45 | } | 55 | } |
445 | 46 | 56 | ||
446 | 57 | void saveSecret(const QString& id, const QString& uuid, | ||
447 | 58 | const QString& settingName, const QString& settingKey, | ||
448 | 59 | const QString& secret, const QString& inputDisplayName = | ||
449 | 60 | QString()) { | ||
450 | 61 | |||
451 | 62 | // TODO: Don't save always-ask or system-owned secrets | ||
452 | 63 | |||
453 | 64 | QString displayName(inputDisplayName); | ||
454 | 65 | if (displayName.isEmpty()) { | ||
455 | 66 | static const QString DISPLAY_NAME("Network secret for %s/%s/%s"); | ||
456 | 67 | displayName = DISPLAY_NAME.arg(id, settingName, settingKey); | ||
457 | 68 | } | ||
458 | 69 | |||
459 | 70 | m_credentialStore->save(uuid, settingName, settingKey, displayName, secret); | ||
460 | 71 | } | ||
461 | 72 | |||
462 | 73 | static bool isSecret(const QString& settingName, const QString& key) { | ||
463 | 74 | static const QMap<QString, QSet<QString>> KNOWN_SECRETS{ | ||
464 | 75 | {QString::fromUtf8(NM_802_1X_SETTING_NAME), {NM_802_1X_PASSWORD, NM_802_1X_PRIVATE_KEY_PASSWORD, | ||
465 | 76 | NM_802_1X_PHASE2_PRIVATE_KEY_PASSWORD, NM_802_1X_PIN}}, | ||
466 | 77 | {QString::fromUtf8(NM_ADSL_SETTING_NAME), {NM_ADSL_PASSWORD}}, | ||
467 | 78 | {QString::fromUtf8(NM_CDMA_SETTING_NAME), {NM_CDMA_PASSWORD}}, | ||
468 | 79 | {QString::fromUtf8(NM_GSM_SETTING_NAME), {NM_GSM_PASSWORD, NM_GSM_PIN}}, | ||
469 | 80 | {QString::fromUtf8(NM_PPPOE_SETTING_NAME), {NM_PPPOE_PASSWORD}}, | ||
470 | 81 | {QString::fromUtf8(NM_WIRELESS_SECURITY_SETTING_NAME), {NM_WIRELESS_SECURITY_WEP_KEY0, | ||
471 | 82 | NM_WIRELESS_SECURITY_WEP_KEY1, NM_WIRELESS_SECURITY_WEP_KEY2, NM_WIRELESS_SECURITY_WEP_KEY3, | ||
472 | 83 | NM_WIRELESS_SECURITY_PSK, NM_WIRELESS_SECURITY_LEAP_PASSWORD}} | ||
473 | 84 | }; | ||
474 | 85 | auto it = KNOWN_SECRETS.constFind(settingName); | ||
475 | 86 | if (it != KNOWN_SECRETS.constEnd()) { | ||
476 | 87 | if (it->contains(key)) { | ||
477 | 88 | return true; | ||
478 | 89 | } | ||
479 | 90 | } | ||
480 | 91 | return false; | ||
481 | 92 | } | ||
482 | 93 | |||
483 | 94 | void saveSettings(const QString& id, const QString& uuid, | ||
484 | 95 | const QString& settingName, const QVariantMap& setting) { | ||
485 | 96 | |||
486 | 97 | QMapIterator<QString, QVariant> iter(setting); | ||
487 | 98 | while (iter.hasNext()) { | ||
488 | 99 | iter.next(); | ||
489 | 100 | if (isSecret(settingName, iter.key())) { | ||
490 | 101 | saveSecret(id, uuid, settingName, iter.key(), | ||
491 | 102 | iter.value().toString()); | ||
492 | 103 | } | ||
493 | 104 | } | ||
494 | 105 | } | ||
495 | 106 | |||
496 | 107 | void saveVpnSettings(const QString& id, const QString& uuid, | ||
497 | 108 | const QString& settingName, const QVariantMap& setting) { | ||
498 | 109 | static const QString DISPLAY_NAME{"VPN %1 secret for %2/%3/%4"}; | ||
499 | 110 | |||
500 | 111 | QString serviceType = setting[NM_VPN_SERVICE_TYPE].toString(); | ||
501 | 112 | QStringMap secrets; | ||
502 | 113 | auto dbusArgument = qvariant_cast<QDBusArgument>(setting[NM_VPN_SECRETS]); | ||
503 | 114 | dbusArgument >> secrets; | ||
504 | 115 | QMapIterator<QString, QString> iter(secrets); | ||
505 | 116 | while(iter.hasNext()) { | ||
506 | 117 | iter.next(); | ||
507 | 118 | saveSecret(id, uuid, settingName, iter.key(), iter.value(), | ||
508 | 119 | DISPLAY_NAME.arg(iter.key(), id, serviceType, NM_VPN_SETTING_NAME)); | ||
509 | 120 | } | ||
510 | 121 | } | ||
511 | 122 | |||
512 | 47 | public Q_SLOTS: | 123 | public Q_SLOTS: |
513 | 48 | void serviceOwnerChanged(const QString &name, const QString &oldOwner, | 124 | void serviceOwnerChanged(const QString &name, const QString &oldOwner, |
514 | 49 | const QString &newOwner) | 125 | const QString &newOwner) |
515 | @@ -53,7 +129,7 @@ | |||
516 | 53 | if (!newOwner.isEmpty()) { | 129 | if (!newOwner.isEmpty()) { |
517 | 54 | auto reply = m_agentManager.RegisterWithCapabilities( | 130 | auto reply = m_agentManager.RegisterWithCapabilities( |
518 | 55 | "com.canonical.indicator.SecretAgent", | 131 | "com.canonical.indicator.SecretAgent", |
520 | 56 | 0 /*NM_SECRET_AGENT_CAPABILITY_NONE*/); | 132 | NM_SECRET_AGENT_CAPABILITY_NONE); |
521 | 57 | reply.waitForFinished(); | 133 | reply.waitForFinished(); |
522 | 58 | if (reply.isError()) { | 134 | if (reply.isError()) { |
523 | 59 | qCritical() << __PRETTY_FUNCTION__ << reply.error().message(); | 135 | qCritical() << __PRETTY_FUNCTION__ << reply.error().message(); |
524 | @@ -72,13 +148,16 @@ | |||
525 | 72 | 148 | ||
526 | 73 | notify::NotificationManager::SPtr m_notifications; | 149 | notify::NotificationManager::SPtr m_notifications; |
527 | 74 | 150 | ||
528 | 151 | CredentialStore::SPtr m_credentialStore; | ||
529 | 152 | |||
530 | 75 | std::shared_ptr<SecretRequest> m_request; | 153 | std::shared_ptr<SecretRequest> m_request; |
531 | 76 | }; | 154 | }; |
532 | 77 | 155 | ||
533 | 78 | SecretAgent::SecretAgent(notify::NotificationManager::SPtr notificationManager, | 156 | SecretAgent::SecretAgent(notify::NotificationManager::SPtr notificationManager, |
535 | 79 | const QDBusConnection &systemConnection, | 157 | agent::CredentialStore::SPtr credentialStore, |
536 | 158 | const QDBusConnection &systemConnection, | ||
537 | 80 | const QDBusConnection &sessionConnection, QObject *parent) : | 159 | const QDBusConnection &sessionConnection, QObject *parent) : |
539 | 81 | QObject(parent), d(new Priv(notificationManager, systemConnection, sessionConnection)) | 160 | QObject(parent), d(new Priv(notificationManager, credentialStore, systemConnection, sessionConnection)) |
540 | 82 | { | 161 | { |
541 | 83 | // Memory managed by Qt | 162 | // Memory managed by Qt |
542 | 84 | new SecretAgentAdaptor(this); | 163 | new SecretAgentAdaptor(this); |
543 | @@ -94,7 +173,7 @@ | |||
544 | 94 | 173 | ||
545 | 95 | auto reply = d->m_agentManager.RegisterWithCapabilities( | 174 | auto reply = d->m_agentManager.RegisterWithCapabilities( |
546 | 96 | "com.canonical.indicator.SecretAgent", | 175 | "com.canonical.indicator.SecretAgent", |
548 | 97 | 0 /*NM_SECRET_AGENT_CAPABILITY_NONE*/); | 176 | NM_SECRET_AGENT_CAPABILITY_NONE); |
549 | 98 | reply.waitForFinished(); | 177 | reply.waitForFinished(); |
550 | 99 | if (reply.isError()) { | 178 | if (reply.isError()) { |
551 | 100 | qCritical() << __PRETTY_FUNCTION__ << reply.error().message(); | 179 | qCritical() << __PRETTY_FUNCTION__ << reply.error().message(); |
552 | @@ -153,13 +232,66 @@ | |||
553 | 153 | 232 | ||
554 | 154 | setDelayedReply(true); | 233 | setDelayedReply(true); |
555 | 155 | 234 | ||
557 | 156 | if (flags != 0 && settingName == "802-11-wireless-security") { | 235 | qDebug() << __PRETTY_FUNCTION__ << connectionPath.path() << settingName << hints << flags; |
558 | 236 | |||
559 | 237 | // If we want a WiFi secret, and | ||
560 | 238 | if (settingName == NM_WIRELESS_SECURITY_SETTING_NAME && | ||
561 | 239 | ((flags & NM_SECRET_AGENT_GET_SECRETS_FLAG_ALLOW_INTERACTION) > 0) && | ||
562 | 240 | ( | ||
563 | 241 | ((flags & NM_SECRET_AGENT_GET_SECRETS_FLAG_REQUEST_NEW) > 0) || | ||
564 | 242 | ((flags & NM_SECRET_AGENT_GET_SECRETS_FLAG_USER_REQUESTED) > 0) | ||
565 | 243 | )) { | ||
566 | 244 | qDebug() << __PRETTY_FUNCTION__ << "Requesting secret from user"; | ||
567 | 157 | d->m_request.reset(new SecretRequest(*this, connection, | 245 | d->m_request.reset(new SecretRequest(*this, connection, |
568 | 158 | connectionPath, settingName, hints, flags, message())); | 246 | connectionPath, settingName, hints, flags, message())); |
569 | 247 | } else if (((flags == NM_SECRET_AGENT_GET_SECRETS_FLAG_NONE) || | ||
570 | 248 | (flags == NM_SECRET_AGENT_GET_SECRETS_FLAG_USER_REQUESTED))) { | ||
571 | 249 | qDebug() << __PRETTY_FUNCTION__ << "Retrieving secret from keyring"; | ||
572 | 250 | |||
573 | 251 | bool isVpn = (settingName == NM_VPN_SETTING_NAME); | ||
574 | 252 | |||
575 | 253 | QString uuid = connection[NM_CONNECTION_SETTING_NAME][NM_CONNECTION_UUID].toString(); | ||
576 | 254 | |||
577 | 255 | QStringMap secrets; | ||
578 | 256 | |||
579 | 257 | try { | ||
580 | 258 | secrets = d->m_credentialStore->get(uuid, settingName); | ||
581 | 259 | } catch (domain_error& e) { | ||
582 | 260 | d->m_systemConnection.send( | ||
583 | 261 | message().createErrorReply( | ||
584 | 262 | "org.freedesktop.NetworkManager.SecretAgent.InternalError", | ||
585 | 263 | e.what())); | ||
586 | 264 | return QVariantDictMap(); | ||
587 | 265 | } | ||
588 | 266 | |||
589 | 267 | if (secrets.isEmpty()) { | ||
590 | 268 | d->m_systemConnection.send( | ||
591 | 269 | message().createErrorReply( | ||
592 | 270 | "org.freedesktop.NetworkManager.SecretAgent.NoSecrets", | ||
593 | 271 | "No secrets found for this connection.")); | ||
594 | 272 | return QVariantDictMap(); | ||
595 | 273 | } | ||
596 | 274 | |||
597 | 275 | QVariantDictMap newConnection; | ||
598 | 276 | |||
599 | 277 | if (isVpn) { | ||
600 | 278 | newConnection[settingName][NM_VPN_SECRETS] = QVariant::fromValue( | ||
601 | 279 | secrets); | ||
602 | 280 | } else { | ||
603 | 281 | QMapIterator<QString, QString> it(secrets); | ||
604 | 282 | while (it.hasNext()) { | ||
605 | 283 | it.next(); | ||
606 | 284 | newConnection[settingName][it.key()] = it.value(); | ||
607 | 285 | } | ||
608 | 286 | } | ||
609 | 287 | |||
610 | 288 | d->m_systemConnection.send( | ||
611 | 289 | message().createReply(QVariant::fromValue(newConnection))); | ||
612 | 159 | } else { | 290 | } else { |
613 | 291 | qDebug() << __PRETTY_FUNCTION__ << "Can't get secrets for this connection"; | ||
614 | 160 | d->m_systemConnection.send( | 292 | d->m_systemConnection.send( |
617 | 161 | message().createErrorReply(QDBusError::InternalError, | 293 | message().createErrorReply("org.freedesktop.NetworkManager.SecretAgent.NoSecrets", |
618 | 162 | "No password found for this connection.")); | 294 | "No secrets found for this connection.")); |
619 | 163 | } | 295 | } |
620 | 164 | 296 | ||
621 | 165 | return QVariantDictMap(); | 297 | return QVariantDictMap(); |
622 | @@ -168,7 +300,7 @@ | |||
623 | 168 | void SecretAgent::FinishGetSecrets(SecretRequest &request, bool error) { | 300 | void SecretAgent::FinishGetSecrets(SecretRequest &request, bool error) { |
624 | 169 | if (error) { | 301 | if (error) { |
625 | 170 | d->m_systemConnection.send( | 302 | d->m_systemConnection.send( |
627 | 171 | request.message().createErrorReply(QDBusError::InternalError, | 303 | request.message().createErrorReply("org.freedesktop.NetworkManager.SecretAgent.NoSecrets", |
628 | 172 | "No password found for this connection.")); | 304 | "No password found for this connection.")); |
629 | 173 | } else { | 305 | } else { |
630 | 174 | d->m_systemConnection.send( | 306 | d->m_systemConnection.send( |
631 | @@ -181,21 +313,38 @@ | |||
632 | 181 | 313 | ||
633 | 182 | void SecretAgent::CancelGetSecrets(const QDBusObjectPath &connectionPath, | 314 | void SecretAgent::CancelGetSecrets(const QDBusObjectPath &connectionPath, |
634 | 183 | const QString &settingName) { | 315 | const QString &settingName) { |
635 | 184 | Q_UNUSED(connectionPath); | ||
636 | 185 | Q_UNUSED(settingName); | 316 | Q_UNUSED(settingName); |
638 | 186 | d->m_request.reset(); | 317 | |
639 | 318 | if (d->m_request && d->m_request->connectionPath() == connectionPath) { | ||
640 | 319 | d->m_request.reset(); | ||
641 | 320 | } | ||
642 | 187 | } | 321 | } |
643 | 188 | 322 | ||
644 | 189 | void SecretAgent::DeleteSecrets(const QVariantDictMap &connection, | 323 | void SecretAgent::DeleteSecrets(const QVariantDictMap &connection, |
645 | 190 | const QDBusObjectPath &connectionPath) { | 324 | const QDBusObjectPath &connectionPath) { |
646 | 191 | Q_UNUSED(connection); | ||
647 | 192 | Q_UNUSED(connectionPath); | 325 | Q_UNUSED(connectionPath); |
648 | 326 | |||
649 | 327 | QString uuid = connection[NM_CONNECTION_SETTING_NAME][NM_CONNECTION_UUID].toString(); | ||
650 | 328 | d->m_credentialStore->clear(uuid); | ||
651 | 193 | } | 329 | } |
652 | 194 | 330 | ||
653 | 195 | void SecretAgent::SaveSecrets(const QVariantDictMap &connection, | 331 | void SecretAgent::SaveSecrets(const QVariantDictMap &connection, |
654 | 196 | const QDBusObjectPath &connectionPath) { | 332 | const QDBusObjectPath &connectionPath) { |
655 | 197 | Q_UNUSED(connection); | ||
656 | 198 | Q_UNUSED(connectionPath); | 333 | Q_UNUSED(connectionPath); |
657 | 334 | |||
658 | 335 | QString id = connection[NM_CONNECTION_SETTING_NAME][NM_CONNECTION_ID].toString(); | ||
659 | 336 | QString uuid = connection[NM_CONNECTION_SETTING_NAME][NM_CONNECTION_UUID].toString(); | ||
660 | 337 | QString type = connection[NM_CONNECTION_SETTING_NAME][NM_CONNECTION_TYPE].toString(); | ||
661 | 338 | |||
662 | 339 | if (type == NM_VPN_SETTING_NAME) { | ||
663 | 340 | d->saveVpnSettings(id, uuid, NM_VPN_SETTING_NAME, connection[NM_VPN_SETTING_NAME]); | ||
664 | 341 | } else { | ||
665 | 342 | QMapIterator<QString, QVariantMap> iter(connection); | ||
666 | 343 | while (iter.hasNext()) { | ||
667 | 344 | iter.next(); | ||
668 | 345 | d->saveSettings(id, uuid, iter.key(), iter.value()); | ||
669 | 346 | } | ||
670 | 347 | } | ||
671 | 199 | } | 348 | } |
672 | 200 | 349 | ||
673 | 201 | notify::NotificationManager::SPtr SecretAgent::notifications() { | 350 | notify::NotificationManager::SPtr SecretAgent::notifications() { |
674 | 202 | 351 | ||
675 | === modified file 'src/agent/SecretAgent.h' | |||
676 | --- src/indicator/agent/SecretAgent.h 2015-08-03 13:27:40 +0000 | |||
677 | +++ src/agent/SecretAgent.h 2016-02-23 09:05:39 +0000 | |||
678 | @@ -19,6 +19,7 @@ | |||
679 | 19 | #pragma once | 19 | #pragma once |
680 | 20 | 20 | ||
681 | 21 | #include <dbus-types.h> | 21 | #include <dbus-types.h> |
682 | 22 | #include <agent/CredentialStore.h> | ||
683 | 22 | 23 | ||
684 | 23 | #include <memory> | 24 | #include <memory> |
685 | 24 | 25 | ||
686 | @@ -48,21 +49,50 @@ | |||
687 | 48 | typedef std::shared_ptr<SecretAgent> Ptr; | 49 | typedef std::shared_ptr<SecretAgent> Ptr; |
688 | 49 | typedef std::unique_ptr<SecretAgent> UPtr; | 50 | typedef std::unique_ptr<SecretAgent> UPtr; |
689 | 50 | 51 | ||
703 | 51 | static constexpr char const* CONNECTION_SETTING_NAME = "connection"; | 52 | static constexpr char const* NM_CONNECTION_SETTING_NAME = "connection"; |
704 | 52 | static constexpr char const* WIRELESS_SECURITY_SETTING_NAME = "802-11-wireless-security"; | 53 | |
705 | 53 | 54 | static constexpr char const* NM_CONNECTION_ID = "id"; | |
706 | 54 | static constexpr char const* CONNECTION_ID = "id"; | 55 | static constexpr char const* NM_CONNECTION_UUID = "uuid"; |
707 | 55 | 56 | static constexpr char const* NM_CONNECTION_TYPE = "type"; | |
708 | 56 | static constexpr char const* WIRELESS_SECURITY_PSK = "psk"; | 57 | |
709 | 57 | static constexpr char const* WIRELESS_SECURITY_WEP_KEY0 = "wep-key0"; | 58 | static constexpr char const* NM_ADSL_SETTING_NAME = "adsl"; |
710 | 58 | 59 | static constexpr char const* NM_ADSL_PASSWORD = "password"; | |
711 | 59 | static constexpr char const* WIRELESS_SECURITY_KEY_MGMT = "key-mgmt"; | 60 | |
712 | 60 | 61 | static constexpr char const* NM_GSM_SETTING_NAME = "gsm"; | |
713 | 61 | static constexpr char const* KEY_MGMT_WPA_NONE = "wpa-none"; | 62 | static constexpr char const* NM_GSM_PASSWORD = "password"; |
714 | 62 | static constexpr char const* KEY_MGMT_WPA_PSK = "wpa-psk"; | 63 | static constexpr char const* NM_GSM_PIN = "pin"; |
715 | 63 | static constexpr char const* KEY_MGMT_NONE = "none"; | 64 | |
716 | 65 | static constexpr char const* NM_802_1X_SETTING_NAME = "802-1x"; | ||
717 | 66 | static constexpr char const* NM_802_1X_PASSWORD = "password"; | ||
718 | 67 | static constexpr char const* NM_802_1X_PRIVATE_KEY_PASSWORD = "private-key-password"; | ||
719 | 68 | static constexpr char const* NM_802_1X_PHASE2_PRIVATE_KEY_PASSWORD = "phase2-private-key-password"; | ||
720 | 69 | static constexpr char const* NM_802_1X_PIN = "pin"; | ||
721 | 70 | |||
722 | 71 | static constexpr char const* NM_CDMA_SETTING_NAME = "cdma"; | ||
723 | 72 | static constexpr char const* NM_CDMA_PASSWORD = "password"; | ||
724 | 73 | |||
725 | 74 | static constexpr char const* NM_PPPOE_SETTING_NAME = "pppoe"; | ||
726 | 75 | static constexpr char const* NM_PPPOE_PASSWORD = "password"; | ||
727 | 76 | |||
728 | 77 | static constexpr char const* NM_VPN_SETTING_NAME = "vpn"; | ||
729 | 78 | static constexpr char const* NM_VPN_SERVICE_TYPE = "service-type"; | ||
730 | 79 | static constexpr char const* NM_VPN_SECRETS = "secrets"; | ||
731 | 80 | |||
732 | 81 | static constexpr char const* NM_WIRELESS_SECURITY_SETTING_NAME = "802-11-wireless-security"; | ||
733 | 82 | static constexpr char const* NM_WIRELESS_SECURITY_KEY_MGMT = "key-mgmt"; | ||
734 | 83 | static constexpr char const* NM_WIRELESS_SECURITY_WEP_KEY0 = "wep-key0"; | ||
735 | 84 | static constexpr char const* NM_WIRELESS_SECURITY_WEP_KEY1 = "wep-key1"; | ||
736 | 85 | static constexpr char const* NM_WIRELESS_SECURITY_WEP_KEY2 = "wep-key2"; | ||
737 | 86 | static constexpr char const* NM_WIRELESS_SECURITY_WEP_KEY3 = "wep-key3"; | ||
738 | 87 | static constexpr char const* NM_WIRELESS_SECURITY_PSK = "psk"; | ||
739 | 88 | static constexpr char const* NM_WIRELESS_SECURITY_LEAP_PASSWORD = "leap-password"; | ||
740 | 89 | |||
741 | 90 | static constexpr char const* NM_KEY_MGMT_WPA_NONE = "wpa-none"; | ||
742 | 91 | static constexpr char const* NM_KEY_MGMT_WPA_PSK = "wpa-psk"; | ||
743 | 92 | static constexpr char const* NM_KEY_MGMT_NONE = "none"; | ||
744 | 64 | 93 | ||
745 | 65 | explicit SecretAgent(std::shared_ptr<notify::NotificationManager> notificationManager, | 94 | explicit SecretAgent(std::shared_ptr<notify::NotificationManager> notificationManager, |
746 | 95 | CredentialStore::SPtr credentialStore, | ||
747 | 66 | const QDBusConnection &systemConnection, | 96 | const QDBusConnection &systemConnection, |
748 | 67 | const QDBusConnection &sessionConnection, QObject *parent = 0); | 97 | const QDBusConnection &sessionConnection, QObject *parent = 0); |
749 | 68 | 98 | ||
750 | 69 | 99 | ||
751 | === modified file 'src/agent/SecretRequest.cpp' | |||
752 | --- src/indicator/agent/SecretRequest.cpp 2015-08-03 13:27:40 +0000 | |||
753 | +++ src/agent/SecretRequest.cpp 2016-02-23 09:05:39 +0000 | |||
754 | @@ -52,24 +52,24 @@ | |||
755 | 52 | 52 | ||
756 | 53 | notificationHints["x-canonical-private-menu-model"] = menuModelPaths; | 53 | notificationHints["x-canonical-private-menu-model"] = menuModelPaths; |
757 | 54 | 54 | ||
759 | 55 | const QVariantMap &conn = m_connection[SecretAgent::CONNECTION_SETTING_NAME]; | 55 | const QVariantMap &conn = m_connection[SecretAgent::NM_CONNECTION_SETTING_NAME]; |
760 | 56 | 56 | ||
761 | 57 | auto wirelessSecurity = m_connection.find(m_settingName); | 57 | auto wirelessSecurity = m_connection.find(m_settingName); |
762 | 58 | QString keyMgmt( | 58 | QString keyMgmt( |
764 | 59 | wirelessSecurity->value(SecretAgent::WIRELESS_SECURITY_KEY_MGMT).toString()); | 59 | wirelessSecurity->value(SecretAgent::NM_WIRELESS_SECURITY_KEY_MGMT).toString()); |
765 | 60 | 60 | ||
766 | 61 | QString title(_("Connect to “%1”")); | 61 | QString title(_("Connect to “%1”")); |
767 | 62 | 62 | ||
768 | 63 | QString subject; | 63 | QString subject; |
771 | 64 | if (keyMgmt == SecretAgent::KEY_MGMT_WPA_NONE | 64 | if (keyMgmt == SecretAgent::NM_KEY_MGMT_WPA_NONE |
772 | 65 | || keyMgmt == SecretAgent::KEY_MGMT_WPA_PSK) { | 65 | || keyMgmt == SecretAgent::NM_KEY_MGMT_WPA_PSK) { |
773 | 66 | subject = _("WPA"); | 66 | subject = _("WPA"); |
775 | 67 | } else if (keyMgmt == SecretAgent::KEY_MGMT_NONE) { | 67 | } else if (keyMgmt == SecretAgent::NM_KEY_MGMT_NONE) { |
776 | 68 | subject = _("WEP"); | 68 | subject = _("WEP"); |
777 | 69 | } | 69 | } |
778 | 70 | 70 | ||
779 | 71 | m_notification = m_secretAgent.notifications()->notify( | 71 | m_notification = m_secretAgent.notifications()->notify( |
781 | 72 | title.arg(conn[SecretAgent::CONNECTION_ID].toString()), subject, | 72 | title.arg(conn[SecretAgent::NM_CONNECTION_ID].toString()), subject, |
782 | 73 | "wifi-full-secure", | 73 | "wifi-full-secure", |
783 | 74 | QStringList() << "connect_id" << _("Connect") << "cancel_id" | 74 | QStringList() << "connect_id" << _("Connect") << "cancel_id" |
784 | 75 | << _("Cancel"), notificationHints, 0); | 75 | << _("Cancel"), notificationHints, 0); |
785 | @@ -101,13 +101,13 @@ | |||
786 | 101 | 101 | ||
787 | 102 | auto wirelessSecurity = m_connection.find(m_settingName); | 102 | auto wirelessSecurity = m_connection.find(m_settingName); |
788 | 103 | QString keyMgmt( | 103 | QString keyMgmt( |
790 | 104 | wirelessSecurity->value(SecretAgent::WIRELESS_SECURITY_KEY_MGMT).toString()); | 104 | wirelessSecurity->value(SecretAgent::NM_WIRELESS_SECURITY_KEY_MGMT).toString()); |
791 | 105 | 105 | ||
797 | 106 | if (keyMgmt == SecretAgent::KEY_MGMT_WPA_NONE | 106 | if (keyMgmt == SecretAgent::NM_KEY_MGMT_WPA_NONE |
798 | 107 | || keyMgmt == SecretAgent::KEY_MGMT_WPA_PSK) { | 107 | || keyMgmt == SecretAgent::NM_KEY_MGMT_WPA_PSK) { |
799 | 108 | wirelessSecurity->insert(SecretAgent::WIRELESS_SECURITY_PSK, key); | 108 | wirelessSecurity->insert(SecretAgent::NM_WIRELESS_SECURITY_PSK, key); |
800 | 109 | } else if (keyMgmt == SecretAgent::KEY_MGMT_NONE) { | 109 | } else if (keyMgmt == SecretAgent::NM_KEY_MGMT_NONE) { |
801 | 110 | wirelessSecurity->insert(SecretAgent::WIRELESS_SECURITY_WEP_KEY0, key); | 110 | wirelessSecurity->insert(SecretAgent::NM_WIRELESS_SECURITY_WEP_KEY0, key); |
802 | 111 | } | 111 | } |
803 | 112 | 112 | ||
804 | 113 | m_secretAgent.FinishGetSecrets(*this, false); | 113 | m_secretAgent.FinishGetSecrets(*this, false); |
805 | @@ -130,4 +130,8 @@ | |||
806 | 130 | return m_message; | 130 | return m_message; |
807 | 131 | } | 131 | } |
808 | 132 | 132 | ||
809 | 133 | const QDBusObjectPath & SecretRequest::connectionPath() const { | ||
810 | 134 | return m_connectionPath; | ||
811 | 135 | } | ||
812 | 136 | |||
813 | 133 | } | 137 | } |
814 | 134 | 138 | ||
815 | === modified file 'src/agent/SecretRequest.h' | |||
816 | --- src/indicator/agent/SecretRequest.h 2015-08-03 13:27:40 +0000 | |||
817 | +++ src/agent/SecretRequest.h 2016-02-23 09:05:39 +0000 | |||
818 | @@ -51,6 +51,8 @@ | |||
819 | 51 | 51 | ||
820 | 52 | const QDBusMessage & message() const; | 52 | const QDBusMessage & message() const; |
821 | 53 | 53 | ||
822 | 54 | const QDBusObjectPath & connectionPath() const; | ||
823 | 55 | |||
824 | 54 | protected: | 56 | protected: |
825 | 55 | notify::Notification::UPtr m_notification; | 57 | notify::Notification::UPtr m_notification; |
826 | 56 | 58 | ||
827 | 57 | 59 | ||
828 | === renamed file 'src/indicator/agent-main.cpp' => 'src/agent/agent-main.cpp' | |||
829 | --- src/indicator/agent-main.cpp 2015-11-20 13:14:50 +0000 | |||
830 | +++ src/agent/agent-main.cpp 2016-02-23 09:05:39 +0000 | |||
831 | @@ -17,7 +17,9 @@ | |||
832 | 17 | * Antti Kaijanmäki <antti.kaijanmaki@canonical.com> | 17 | * Antti Kaijanmäki <antti.kaijanmaki@canonical.com> |
833 | 18 | */ | 18 | */ |
834 | 19 | 19 | ||
836 | 20 | #include <factory.h> | 20 | #include <notify-cpp/notification-manager.h> |
837 | 21 | #include <agent/KeyringCredentialStore.h> | ||
838 | 22 | #include <agent/SecretAgent.h> | ||
839 | 21 | #include <util/unix-signal-handler.h> | 23 | #include <util/unix-signal-handler.h> |
840 | 22 | #include <dbus-types.h> | 24 | #include <dbus-types.h> |
841 | 23 | 25 | ||
842 | @@ -32,7 +34,6 @@ | |||
843 | 32 | #include <config.h> | 34 | #include <config.h> |
844 | 33 | 35 | ||
845 | 34 | using namespace std; | 36 | using namespace std; |
846 | 35 | using namespace connectivity_service; | ||
847 | 36 | 37 | ||
848 | 37 | int | 38 | int |
849 | 38 | main(int argc, char **argv) | 39 | main(int argc, char **argv) |
850 | @@ -42,23 +43,20 @@ | |||
851 | 42 | Variant::registerMetaTypes(); | 43 | Variant::registerMetaTypes(); |
852 | 43 | std::srand(std::time(0)); | 44 | std::srand(std::time(0)); |
853 | 44 | 45 | ||
854 | 45 | util::UnixSignalHandler handler([]{ | ||
855 | 46 | QCoreApplication::exit(0); | ||
856 | 47 | }); | ||
857 | 48 | handler.setupUnixSignalHandlers(); | ||
858 | 49 | |||
859 | 50 | bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); | 46 | bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); |
860 | 51 | setlocale(LC_ALL, ""); | 47 | setlocale(LC_ALL, ""); |
861 | 52 | bindtextdomain(GETTEXT_PACKAGE, LOCALE_DIR); | 48 | bindtextdomain(GETTEXT_PACKAGE, LOCALE_DIR); |
862 | 53 | textdomain(GETTEXT_PACKAGE); | 49 | textdomain(GETTEXT_PACKAGE); |
863 | 54 | 50 | ||
868 | 55 | if (argc == 2 && QString("--print-address") == argv[1]) | 51 | util::UnixSignalHandler handler([]{ |
869 | 56 | { | 52 | QCoreApplication::exit(0); |
870 | 57 | qDebug() << QDBusConnection::systemBus().baseService(); | 53 | }); |
871 | 58 | } | 54 | handler.setupUnixSignalHandlers(); |
872 | 59 | 55 | ||
875 | 60 | Factory factory; | 56 | auto agent = make_unique<agent::SecretAgent>( |
876 | 61 | auto secretAgent = factory.newSecretAgent(); | 57 | make_shared<notify::NotificationManager>(GETTEXT_PACKAGE), |
877 | 58 | make_shared<agent::KeyringCredentialStore>(), | ||
878 | 59 | QDBusConnection::systemBus(), QDBusConnection::sessionBus()); | ||
879 | 62 | 60 | ||
880 | 63 | return app.exec(); | 61 | return app.exec(); |
881 | 64 | } | 62 | } |
882 | 65 | 63 | ||
883 | === modified file 'src/indicator/CMakeLists.txt' | |||
884 | --- src/indicator/CMakeLists.txt 2016-01-14 11:40:59 +0000 | |||
885 | +++ src/indicator/CMakeLists.txt 2016-02-23 09:05:39 +0000 | |||
886 | @@ -1,11 +1,5 @@ | |||
887 | 1 | 1 | ||
888 | 2 | pkg_check_modules( | 2 | pkg_check_modules( |
889 | 3 | NETWORKMANAGER REQUIRED | ||
890 | 4 | NetworkManager | ||
891 | 5 | ) | ||
892 | 6 | include_directories(${NETWORKMANAGER_INCLUDE_DIRS}) | ||
893 | 7 | |||
894 | 8 | pkg_check_modules( | ||
895 | 9 | QOFONO REQUIRED | 3 | QOFONO REQUIRED |
896 | 10 | qofono-qt5 | 4 | qofono-qt5 |
897 | 11 | ) | 5 | ) |
898 | @@ -43,10 +37,6 @@ | |||
899 | 43 | nmofono/vpn/vpn-connection.cpp | 37 | nmofono/vpn/vpn-connection.cpp |
900 | 44 | nmofono/vpn/vpn-manager.cpp | 38 | nmofono/vpn/vpn-manager.cpp |
901 | 45 | 39 | ||
902 | 46 | agent/SecretAgent.cpp | ||
903 | 47 | agent/SecretRequest.cpp | ||
904 | 48 | agent/PasswordMenu.cpp | ||
905 | 49 | |||
906 | 50 | factory.cpp | 40 | factory.cpp |
907 | 51 | indicator-menu.cpp | 41 | indicator-menu.cpp |
908 | 52 | icons.cpp | 42 | icons.cpp |
909 | @@ -71,9 +61,6 @@ | |||
910 | 71 | menuitems/wifi-link-item.cpp | 61 | menuitems/wifi-link-item.cpp |
911 | 72 | menuitems/wwan-link-item.cpp | 62 | menuitems/wwan-link-item.cpp |
912 | 73 | menuitems/modem-info-item.cpp | 63 | menuitems/modem-info-item.cpp |
913 | 74 | |||
914 | 75 | util/dbus-utils.cpp | ||
915 | 76 | util/unix-signal-handler.cpp | ||
916 | 77 | ) | 64 | ) |
917 | 78 | 65 | ||
918 | 79 | qt5_add_dbus_adaptor( | 66 | qt5_add_dbus_adaptor( |
919 | @@ -116,14 +103,6 @@ | |||
920 | 116 | PptpAdaptor | 103 | PptpAdaptor |
921 | 117 | ) | 104 | ) |
922 | 118 | 105 | ||
923 | 119 | qt5_add_dbus_adaptor( | ||
924 | 120 | NETWORK_SERVICE_SOURCES | ||
925 | 121 | "${DATA_DIR}/nm-secret-agent.xml" | ||
926 | 122 | "agent/SecretAgentInclude.h" | ||
927 | 123 | "agent::SecretAgent" | ||
928 | 124 | SecretAgentAdaptor | ||
929 | 125 | ) | ||
930 | 126 | |||
931 | 127 | add_library( | 106 | add_library( |
932 | 128 | indicator-network-service-static | 107 | indicator-network-service-static |
933 | 129 | STATIC | 108 | STATIC |
934 | @@ -137,9 +116,9 @@ | |||
935 | 137 | url_dispatcher_cpp | 116 | url_dispatcher_cpp |
936 | 138 | qdbus-stubs | 117 | qdbus-stubs |
937 | 139 | qpowerd | 118 | qpowerd |
941 | 140 | ${DBUSCPP_LIBRARIES} | 119 | util |
942 | 141 | ${GLIB_LIBRARIES} | 120 | ${GLIB_LDFLAGS} |
943 | 142 | ${QOFONO_LIBRARIES} | 121 | ${QOFONO_LDFLAGS} |
944 | 143 | Qt5::Core | 122 | Qt5::Core |
945 | 144 | Qt5::DBus | 123 | Qt5::DBus |
946 | 145 | ) | 124 | ) |
947 | @@ -160,18 +139,6 @@ | |||
948 | 160 | Qt5::DBus | 139 | Qt5::DBus |
949 | 161 | ) | 140 | ) |
950 | 162 | 141 | ||
951 | 163 | add_executable( | ||
952 | 164 | indicator-network-secret-agent | ||
953 | 165 | agent-main.cpp | ||
954 | 166 | ) | ||
955 | 167 | |||
956 | 168 | target_link_libraries( | ||
957 | 169 | indicator-network-secret-agent | ||
958 | 170 | indicator-network-service-static | ||
959 | 171 | Qt5::Core | ||
960 | 172 | Qt5::DBus | ||
961 | 173 | ) | ||
962 | 174 | |||
963 | 175 | ########################### | 142 | ########################### |
964 | 176 | # Installation | 143 | # Installation |
965 | 177 | ########################### | 144 | ########################### |
966 | @@ -179,6 +146,5 @@ | |||
967 | 179 | install( | 146 | install( |
968 | 180 | TARGETS | 147 | TARGETS |
969 | 181 | indicator-network-service | 148 | indicator-network-service |
970 | 182 | indicator-network-secret-agent | ||
971 | 183 | RUNTIME DESTINATION "${CMAKE_INSTALL_LIBEXECDIR}/indicator-network/" | 149 | RUNTIME DESTINATION "${CMAKE_INSTALL_LIBEXECDIR}/indicator-network/" |
972 | 184 | ) | 150 | ) |
973 | 185 | 151 | ||
974 | === modified file 'src/indicator/factory.cpp' | |||
975 | --- src/indicator/factory.cpp 2015-12-11 14:58:11 +0000 | |||
976 | +++ src/indicator/factory.cpp 2016-02-23 09:05:39 +0000 | |||
977 | @@ -221,13 +221,6 @@ | |||
978 | 221 | return make_unique<BusName>(name, acquired, lost, d->singletonSessionBus()); | 221 | return make_unique<BusName>(name, acquired, lost, d->singletonSessionBus()); |
979 | 222 | } | 222 | } |
980 | 223 | 223 | ||
981 | 224 | agent::SecretAgent::UPtr Factory::newSecretAgent() | ||
982 | 225 | { | ||
983 | 226 | return make_unique<agent::SecretAgent>(d->singletonNotificationManager(), | ||
984 | 227 | QDBusConnection::systemBus(), | ||
985 | 228 | QDBusConnection::sessionBus()); | ||
986 | 229 | } | ||
987 | 230 | |||
988 | 231 | VpnStatusNotifier::UPtr Factory::newVpnStatusNotifier() | 224 | VpnStatusNotifier::UPtr Factory::newVpnStatusNotifier() |
989 | 232 | { | 225 | { |
990 | 233 | return make_unique<VpnStatusNotifier>(d->singletonActiveConnectionManager(), | 226 | return make_unique<VpnStatusNotifier>(d->singletonActiveConnectionManager(), |
991 | 234 | 227 | ||
992 | === modified file 'src/indicator/factory.h' | |||
993 | --- src/indicator/factory.h 2015-12-11 14:58:11 +0000 | |||
994 | +++ src/indicator/factory.h 2016-02-23 09:05:39 +0000 | |||
995 | @@ -31,7 +31,6 @@ | |||
996 | 31 | #include <sections/wifi-section.h> | 31 | #include <sections/wifi-section.h> |
997 | 32 | #include <sections/wwan-section.h> | 32 | #include <sections/wwan-section.h> |
998 | 33 | #include <menuitems/switch-item.h> | 33 | #include <menuitems/switch-item.h> |
999 | 34 | #include <agent/SecretAgent.h> | ||
1000 | 35 | 34 | ||
1001 | 36 | #include <memory> | 35 | #include <memory> |
1002 | 37 | 36 | ||
1003 | @@ -77,7 +76,6 @@ | |||
1004 | 77 | std::function<void(std::string)> acquired, | 76 | std::function<void(std::string)> acquired, |
1005 | 78 | std::function<void(std::string)> lost); | 77 | std::function<void(std::string)> lost); |
1006 | 79 | 78 | ||
1007 | 80 | virtual agent::SecretAgent::UPtr newSecretAgent(); | ||
1008 | 81 | 79 | ||
1009 | 82 | virtual VpnStatusNotifier::UPtr newVpnStatusNotifier(); | 80 | virtual VpnStatusNotifier::UPtr newVpnStatusNotifier(); |
1010 | 83 | }; | 81 | }; |
1011 | 84 | 82 | ||
1012 | === modified file 'src/indicator/nmofono/vpn/vpn-manager.cpp' | |||
1013 | --- src/indicator/nmofono/vpn/vpn-manager.cpp 2016-01-14 11:40:59 +0000 | |||
1014 | +++ src/indicator/nmofono/vpn/vpn-manager.cpp 2016-02-23 09:05:39 +0000 | |||
1015 | @@ -251,7 +251,7 @@ | |||
1016 | 251 | {"type", "vpn"}, | 251 | {"type", "vpn"}, |
1017 | 252 | {"id", d->newConnectionName()}, | 252 | {"id", d->newConnectionName()}, |
1018 | 253 | {"uuid", uuid}, | 253 | {"uuid", uuid}, |
1020 | 254 | {"autoconnect", "false"} | 254 | {"autoconnect", false} |
1021 | 255 | 255 | ||
1022 | 256 | }; | 256 | }; |
1023 | 257 | connection["vpn"] = QVariantMap | 257 | connection["vpn"] = QVariantMap |
1024 | 258 | 258 | ||
1025 | === modified file 'src/notify-cpp/CMakeLists.txt' | |||
1026 | --- src/notify-cpp/CMakeLists.txt 2015-08-03 13:27:40 +0000 | |||
1027 | +++ src/notify-cpp/CMakeLists.txt 2016-02-23 09:05:39 +0000 | |||
1028 | @@ -11,5 +11,6 @@ | |||
1029 | 11 | add_library(notify_cpp STATIC ${NOTIFY_CPP_SOURCES}) | 11 | add_library(notify_cpp STATIC ${NOTIFY_CPP_SOURCES}) |
1030 | 12 | target_link_libraries( | 12 | target_link_libraries( |
1031 | 13 | notify_cpp | 13 | notify_cpp |
1032 | 14 | menumodel_cpp | ||
1033 | 14 | qdbus-stubs | 15 | qdbus-stubs |
1034 | 15 | ) | 16 | ) |
1035 | 16 | 17 | ||
1036 | === renamed directory 'src/indicator/util' => 'src/util' | |||
1037 | === added file 'src/util/CMakeLists.txt' | |||
1038 | --- src/util/CMakeLists.txt 1970-01-01 00:00:00 +0000 | |||
1039 | +++ src/util/CMakeLists.txt 2016-02-23 09:05:39 +0000 | |||
1040 | @@ -0,0 +1,8 @@ | |||
1041 | 1 | include_directories("${CMAKE_SOURCE_DIR}/src/") | ||
1042 | 2 | |||
1043 | 3 | set(UTIL_SOURCES | ||
1044 | 4 | dbus-utils.cpp | ||
1045 | 5 | unix-signal-handler.cpp | ||
1046 | 6 | ) | ||
1047 | 7 | |||
1048 | 8 | add_library(util STATIC ${UTIL_SOURCES}) | ||
1049 | 0 | 9 | ||
1050 | === modified file 'tests/unit/CMakeLists.txt' | |||
1051 | --- tests/unit/CMakeLists.txt 2015-11-20 11:21:59 +0000 | |||
1052 | +++ tests/unit/CMakeLists.txt 2016-02-23 09:05:39 +0000 | |||
1053 | @@ -27,7 +27,7 @@ | |||
1054 | 27 | 27 | ||
1055 | 28 | target_link_libraries( | 28 | target_link_libraries( |
1056 | 29 | secret-agent-test-bin | 29 | secret-agent-test-bin |
1058 | 30 | indicator-network-service-static | 30 | agent-static |
1059 | 31 | ) | 31 | ) |
1060 | 32 | 32 | ||
1061 | 33 | ################### | 33 | ################### |
1062 | 34 | 34 | ||
1063 | === modified file 'tests/unit/secret-agent/secret-agent-main.cpp' | |||
1064 | --- tests/unit/secret-agent/secret-agent-main.cpp 2015-04-21 10:59:52 +0000 | |||
1065 | +++ tests/unit/secret-agent/secret-agent-main.cpp 2016-02-23 09:05:39 +0000 | |||
1066 | @@ -19,19 +19,23 @@ | |||
1067 | 19 | #include <config.h> | 19 | #include <config.h> |
1068 | 20 | #include <libintl.h> | 20 | #include <libintl.h> |
1069 | 21 | #include <config.h> | 21 | #include <config.h> |
1070 | 22 | #include <factory.h> | ||
1071 | 23 | #include <dbus-types.h> | 22 | #include <dbus-types.h> |
1072 | 23 | #include <notify-cpp/notification-manager.h> | ||
1073 | 24 | #include <agent/KeyringCredentialStore.h> | ||
1074 | 25 | #include <agent/SecretAgent.h> | ||
1075 | 24 | #include <util/unix-signal-handler.h> | 26 | #include <util/unix-signal-handler.h> |
1076 | 25 | 27 | ||
1077 | 26 | #include <QCoreApplication> | 28 | #include <QCoreApplication> |
1078 | 29 | #include <QDBusConnection> | ||
1079 | 27 | #include <iostream> | 30 | #include <iostream> |
1080 | 31 | #include <memory> | ||
1081 | 28 | 32 | ||
1082 | 29 | using namespace std; | 33 | using namespace std; |
1083 | 30 | 34 | ||
1084 | 31 | |||
1085 | 32 | int main(int argc, char *argv[]) { | 35 | int main(int argc, char *argv[]) { |
1086 | 33 | QCoreApplication application(argc, argv); | 36 | QCoreApplication application(argc, argv); |
1087 | 34 | DBusTypes::registerMetaTypes(); | 37 | DBusTypes::registerMetaTypes(); |
1088 | 38 | Variant::registerMetaTypes(); | ||
1089 | 35 | 39 | ||
1090 | 36 | setlocale(LC_ALL, ""); | 40 | setlocale(LC_ALL, ""); |
1091 | 37 | bindtextdomain(GETTEXT_PACKAGE, LOCALE_DIR); | 41 | bindtextdomain(GETTEXT_PACKAGE, LOCALE_DIR); |
1092 | @@ -43,8 +47,10 @@ | |||
1093 | 43 | }); | 47 | }); |
1094 | 44 | handler.setupUnixSignalHandlers(); | 48 | handler.setupUnixSignalHandlers(); |
1095 | 45 | 49 | ||
1098 | 46 | Factory factory; | 50 | auto secretAgent = make_unique<agent::SecretAgent>( |
1099 | 47 | auto secretAgent = factory.newSecretAgent(); | 51 | make_shared<notify::NotificationManager>(GETTEXT_PACKAGE), |
1100 | 52 | make_shared<agent::KeyringCredentialStore>(), | ||
1101 | 53 | QDBusConnection::systemBus(), QDBusConnection::sessionBus()); | ||
1102 | 48 | 54 | ||
1103 | 49 | if (argc == 2 && QString("--print-address") == argv[1]) { | 55 | if (argc == 2 && QString("--print-address") == argv[1]) { |
1104 | 50 | cout << QDBusConnection::systemBus().baseService().toStdString() | 56 | cout << QDBusConnection::systemBus().baseService().toStdString() |
1105 | 51 | 57 | ||
1106 | === modified file 'tests/unit/secret-agent/test-secret-agent.cpp' | |||
1107 | --- tests/unit/secret-agent/test-secret-agent.cpp 2015-11-20 11:21:59 +0000 | |||
1108 | +++ tests/unit/secret-agent/test-secret-agent.cpp 2016-02-23 09:05:39 +0000 | |||
1109 | @@ -78,16 +78,16 @@ | |||
1110 | 78 | 78 | ||
1111 | 79 | QVariantDictMap connection(const QString &keyManagement) { | 79 | QVariantDictMap connection(const QString &keyManagement) { |
1112 | 80 | QVariantMap wirelessSecurity; | 80 | QVariantMap wirelessSecurity; |
1114 | 81 | wirelessSecurity[SecretAgent::WIRELESS_SECURITY_KEY_MGMT] = | 81 | wirelessSecurity[SecretAgent::NM_WIRELESS_SECURITY_KEY_MGMT] = |
1115 | 82 | keyManagement; | 82 | keyManagement; |
1116 | 83 | 83 | ||
1117 | 84 | QVariantMap conn; | 84 | QVariantMap conn; |
1119 | 85 | conn[SecretAgent::CONNECTION_ID] = "the ssid"; | 85 | conn[SecretAgent::NM_CONNECTION_ID] = "the ssid"; |
1120 | 86 | 86 | ||
1121 | 87 | QVariantDictMap connection; | 87 | QVariantDictMap connection; |
1123 | 88 | connection[SecretAgent::WIRELESS_SECURITY_SETTING_NAME] = | 88 | connection[SecretAgent::NM_WIRELESS_SECURITY_SETTING_NAME] = |
1124 | 89 | wirelessSecurity; | 89 | wirelessSecurity; |
1126 | 90 | connection[SecretAgent::CONNECTION_SETTING_NAME] = conn; | 90 | connection[SecretAgent::NM_CONNECTION_SETTING_NAME] = conn; |
1127 | 91 | 91 | ||
1128 | 92 | return connection; | 92 | return connection; |
1129 | 93 | } | 93 | } |
1130 | @@ -96,17 +96,17 @@ | |||
1131 | 96 | const QString &keyName, const QString &password) { | 96 | const QString &keyName, const QString &password) { |
1132 | 97 | 97 | ||
1133 | 98 | QVariantMap wirelessSecurity; | 98 | QVariantMap wirelessSecurity; |
1135 | 99 | wirelessSecurity[SecretAgent::WIRELESS_SECURITY_KEY_MGMT] = | 99 | wirelessSecurity[SecretAgent::NM_WIRELESS_SECURITY_KEY_MGMT] = |
1136 | 100 | keyManagement; | 100 | keyManagement; |
1137 | 101 | wirelessSecurity[keyName] = password; | 101 | wirelessSecurity[keyName] = password; |
1138 | 102 | 102 | ||
1139 | 103 | QVariantMap conn; | 103 | QVariantMap conn; |
1141 | 104 | conn[SecretAgent::CONNECTION_ID] = "the ssid"; | 104 | conn[SecretAgent::NM_CONNECTION_ID] = "the ssid"; |
1142 | 105 | 105 | ||
1143 | 106 | QVariantDictMap connection; | 106 | QVariantDictMap connection; |
1145 | 107 | connection[SecretAgent::WIRELESS_SECURITY_SETTING_NAME] = | 107 | connection[SecretAgent::NM_WIRELESS_SECURITY_SETTING_NAME] = |
1146 | 108 | wirelessSecurity; | 108 | wirelessSecurity; |
1148 | 109 | connection[SecretAgent::CONNECTION_SETTING_NAME] = conn; | 109 | connection[SecretAgent::NM_CONNECTION_SETTING_NAME] = conn; |
1149 | 110 | 110 | ||
1150 | 111 | return connection; | 111 | return connection; |
1151 | 112 | } | 112 | } |
1152 | @@ -166,7 +166,7 @@ | |||
1153 | 166 | QDBusPendingReply<QVariantDictMap> reply( | 166 | QDBusPendingReply<QVariantDictMap> reply( |
1154 | 167 | agentInterface->GetSecrets(connection(GetParam().keyManagement), | 167 | agentInterface->GetSecrets(connection(GetParam().keyManagement), |
1155 | 168 | QDBusObjectPath("/connection/foo"), | 168 | QDBusObjectPath("/connection/foo"), |
1157 | 169 | SecretAgent::WIRELESS_SECURITY_SETTING_NAME, QStringList(), | 169 | SecretAgent::NM_WIRELESS_SECURITY_SETTING_NAME, QStringList(), |
1158 | 170 | 5)); | 170 | 5)); |
1159 | 171 | 171 | ||
1160 | 172 | QSignalSpy notificationSpy(notificationsInterface.data(), | 172 | QSignalSpy notificationSpy(notificationsInterface.data(), |
1161 | @@ -230,21 +230,21 @@ | |||
1162 | 230 | } | 230 | } |
1163 | 231 | 231 | ||
1164 | 232 | INSTANTIATE_TEST_CASE_P(WpaPsk, TestSecretAgentGetSecrets, | 232 | INSTANTIATE_TEST_CASE_P(WpaPsk, TestSecretAgentGetSecrets, |
1167 | 233 | Values(TestSecretAgentParams( { SecretAgent::KEY_MGMT_WPA_PSK, | 233 | Values(TestSecretAgentParams( { SecretAgent::NM_KEY_MGMT_WPA_PSK, |
1168 | 234 | SecretAgent::WIRELESS_SECURITY_PSK, "hard-coded-password" }))); | 234 | SecretAgent::NM_WIRELESS_SECURITY_PSK, "hard-coded-password" }))); |
1169 | 235 | 235 | ||
1170 | 236 | INSTANTIATE_TEST_CASE_P(WpaPskLongPassword, TestSecretAgentGetSecrets, | 236 | INSTANTIATE_TEST_CASE_P(WpaPskLongPassword, TestSecretAgentGetSecrets, |
1173 | 237 | Values(TestSecretAgentParams( { SecretAgent::KEY_MGMT_WPA_PSK, | 237 | Values(TestSecretAgentParams( { SecretAgent::NM_KEY_MGMT_WPA_PSK, |
1174 | 238 | SecretAgent::WIRELESS_SECURITY_PSK, "123456789012345678901234567890123456789012345678901234" }))); | 238 | SecretAgent::NM_WIRELESS_SECURITY_PSK, "123456789012345678901234567890123456789012345678901234" }))); |
1175 | 239 | 239 | ||
1176 | 240 | INSTANTIATE_TEST_CASE_P(WpaNone, TestSecretAgentGetSecrets, | 240 | INSTANTIATE_TEST_CASE_P(WpaNone, TestSecretAgentGetSecrets, |
1179 | 241 | Values(TestSecretAgentParams( { SecretAgent::KEY_MGMT_WPA_NONE, | 241 | Values(TestSecretAgentParams( { SecretAgent::NM_KEY_MGMT_WPA_NONE, |
1180 | 242 | SecretAgent::WIRELESS_SECURITY_PSK, "hard-coded-password" }))); | 242 | SecretAgent::NM_WIRELESS_SECURITY_PSK, "hard-coded-password" }))); |
1181 | 243 | 243 | ||
1182 | 244 | INSTANTIATE_TEST_CASE_P(None, TestSecretAgentGetSecrets, | 244 | INSTANTIATE_TEST_CASE_P(None, TestSecretAgentGetSecrets, |
1183 | 245 | Values( | 245 | Values( |
1186 | 246 | TestSecretAgentParams( { SecretAgent::KEY_MGMT_NONE, | 246 | TestSecretAgentParams( { SecretAgent::NM_KEY_MGMT_NONE, |
1187 | 247 | SecretAgent::WIRELESS_SECURITY_WEP_KEY0, | 247 | SecretAgent::NM_WIRELESS_SECURITY_WEP_KEY0, |
1188 | 248 | "hard-coded-password" }))); | 248 | "hard-coded-password" }))); |
1189 | 249 | 249 | ||
1190 | 250 | class TestSecretAgent: public TestSecretAgentCommon, public Test { | 250 | class TestSecretAgent: public TestSecretAgentCommon, public Test { |
1191 | @@ -254,9 +254,9 @@ | |||
1192 | 254 | 254 | ||
1193 | 255 | QDBusPendingReply<QVariantDictMap> reply( | 255 | QDBusPendingReply<QVariantDictMap> reply( |
1194 | 256 | agentInterface->GetSecrets( | 256 | agentInterface->GetSecrets( |
1196 | 257 | connection(SecretAgent::KEY_MGMT_WPA_PSK), | 257 | connection(SecretAgent::NM_KEY_MGMT_WPA_PSK), |
1197 | 258 | QDBusObjectPath("/connection/foo"), | 258 | QDBusObjectPath("/connection/foo"), |
1199 | 259 | SecretAgent::WIRELESS_SECURITY_SETTING_NAME, QStringList(), | 259 | SecretAgent::NM_WIRELESS_SECURITY_SETTING_NAME, QStringList(), |
1200 | 260 | 0)); | 260 | 0)); |
1201 | 261 | reply.waitForFinished(); | 261 | reply.waitForFinished(); |
1202 | 262 | 262 | ||
1203 | @@ -272,9 +272,9 @@ | |||
1204 | 272 | QSignalSpy notificationSpy(notificationsInterface.data(), SIGNAL(MethodCalled(const QString &, const QVariantList &))); | 272 | QSignalSpy notificationSpy(notificationsInterface.data(), SIGNAL(MethodCalled(const QString &, const QVariantList &))); |
1205 | 273 | 273 | ||
1206 | 274 | agentInterface->GetSecrets( | 274 | agentInterface->GetSecrets( |
1208 | 275 | connection(SecretAgent::KEY_MGMT_WPA_PSK), | 275 | connection(SecretAgent::NM_KEY_MGMT_WPA_PSK), |
1209 | 276 | QDBusObjectPath("/connection/foo"), | 276 | QDBusObjectPath("/connection/foo"), |
1211 | 277 | SecretAgent::WIRELESS_SECURITY_SETTING_NAME, QStringList(), | 277 | SecretAgent::NM_WIRELESS_SECURITY_SETTING_NAME, QStringList(), |
1212 | 278 | 5); | 278 | 5); |
1213 | 279 | 279 | ||
1214 | 280 | notificationSpy.wait(); | 280 | notificationSpy.wait(); |
1215 | @@ -286,7 +286,7 @@ | |||
1216 | 286 | notificationSpy.clear(); | 286 | notificationSpy.clear(); |
1217 | 287 | 287 | ||
1218 | 288 | agentInterface->CancelGetSecrets(QDBusObjectPath("/connection/foo"), | 288 | agentInterface->CancelGetSecrets(QDBusObjectPath("/connection/foo"), |
1220 | 289 | SecretAgent::WIRELESS_SECURITY_SETTING_NAME); | 289 | SecretAgent::NM_WIRELESS_SECURITY_SETTING_NAME); |
1221 | 290 | 290 | ||
1222 | 291 | notificationSpy.wait(); | 291 | notificationSpy.wait(); |
1223 | 292 | 292 | ||
1224 | @@ -301,9 +301,9 @@ | |||
1225 | 301 | QSignalSpy notificationSpy(notificationsInterface.data(), SIGNAL(MethodCalled(const QString &, const QVariantList &))); | 301 | QSignalSpy notificationSpy(notificationsInterface.data(), SIGNAL(MethodCalled(const QString &, const QVariantList &))); |
1226 | 302 | 302 | ||
1227 | 303 | agentInterface->GetSecrets( | 303 | agentInterface->GetSecrets( |
1229 | 304 | connection(SecretAgent::KEY_MGMT_WPA_PSK), | 304 | connection(SecretAgent::NM_KEY_MGMT_WPA_PSK), |
1230 | 305 | QDBusObjectPath("/connection/foo"), | 305 | QDBusObjectPath("/connection/foo"), |
1232 | 306 | SecretAgent::WIRELESS_SECURITY_SETTING_NAME, QStringList(), | 306 | SecretAgent::NM_WIRELESS_SECURITY_SETTING_NAME, QStringList(), |
1233 | 307 | 5); | 307 | 5); |
1234 | 308 | 308 | ||
1235 | 309 | notificationSpy.wait(); | 309 | notificationSpy.wait(); |
1236 | @@ -315,9 +315,9 @@ | |||
1237 | 315 | notificationSpy.clear(); | 315 | notificationSpy.clear(); |
1238 | 316 | 316 | ||
1239 | 317 | agentInterface->GetSecrets( | 317 | agentInterface->GetSecrets( |
1241 | 318 | connection(SecretAgent::KEY_MGMT_WPA_PSK), | 318 | connection(SecretAgent::NM_KEY_MGMT_WPA_PSK), |
1242 | 319 | QDBusObjectPath("/connection/foo2"), | 319 | QDBusObjectPath("/connection/foo2"), |
1244 | 320 | SecretAgent::WIRELESS_SECURITY_SETTING_NAME, QStringList(), | 320 | SecretAgent::NM_WIRELESS_SECURITY_SETTING_NAME, QStringList(), |
1245 | 321 | 5); | 321 | 5); |
1246 | 322 | 322 | ||
1247 | 323 | notificationSpy.wait(); | 323 | notificationSpy.wait(); |