device: renew dhcp leases on awake for software devices
[NetworkManager.git] / libnm-core / nm-setting-wireless-security.c
1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2
3 /*
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301 USA.
18  *
19  * Copyright 2007 - 2014 Red Hat, Inc.
20  * Copyright 2007 - 2008 Novell, Inc.
21  */
22
23 #include "nm-default.h"
24
25 #include <string.h>
26
27 #include "nm-setting-wireless-security.h"
28 #include "nm-setting-8021x.h"
29 #include "nm-utils.h"
30 #include "nm-utils-private.h"
31 #include "nm-setting-private.h"
32 #include "nm-setting-wireless.h"
33
34 /**
35  * SECTION:nm-setting-wireless-security
36  * @short_description: Describes connection properties for Wi-Fi networks that
37  * use WEP, LEAP, WPA or WPA2/RSN security
38  *
39  * The #NMSettingWirelessSecurity object is a #NMSetting subclass that describes
40  * properties necessary for connection to encrypted Wi-Fi networks.
41  *
42  * It's a good idea to read up on wpa_supplicant configuration before using this
43  * setting extensively, since most of the options here correspond closely with
44  * the relevant wpa_supplicant configuration options.  To get a better overview
45  * of how Wi-Fi security works, you may want to get copies of the following books.
46  *
47  *  802.11 Wireless Networks: The Definitive Guide, Second Edition
48  *       Author: Matthew Gast
49  *       ISBN: 978-0596100520
50  *
51  *  Cisco Wireless LAN Security
52  *       Authors: Krishna Sankar, Sri Sundaralingam, Darrin Miller, and Andrew Balinsky
53  *       ISBN: 978-1587051548
54  **/
55
56 G_DEFINE_TYPE_WITH_CODE (NMSettingWirelessSecurity, nm_setting_wireless_security, NM_TYPE_SETTING,
57                          _nm_register_setting (WIRELESS_SECURITY, 2))
58 NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_WIRELESS_SECURITY)
59
60 #define NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_WIRELESS_SECURITY, NMSettingWirelessSecurityPrivate))
61
62 typedef struct {
63         char *key_mgmt;
64         char *auth_alg;
65         GSList *proto; /* GSList of strings */
66         GSList *pairwise; /* GSList of strings */
67         GSList *group; /* GSList of strings */
68
69         /* LEAP */
70         char *leap_username;
71         char *leap_password;
72         NMSettingSecretFlags leap_password_flags;
73
74         /* WEP */
75         char *wep_key0;
76         char *wep_key1;
77         char *wep_key2;
78         char *wep_key3;
79         NMSettingSecretFlags wep_key_flags;
80         NMWepKeyType wep_key_type;
81         guint32 wep_tx_keyidx;
82
83         /* WPA-PSK */
84         char *psk;
85         NMSettingSecretFlags psk_flags;
86 } NMSettingWirelessSecurityPrivate;
87
88 enum {
89         PROP_0,
90         PROP_KEY_MGMT,
91         PROP_WEP_TX_KEYIDX,
92         PROP_AUTH_ALG,
93         PROP_PROTO,
94         PROP_PAIRWISE,
95         PROP_GROUP,
96         PROP_LEAP_USERNAME,
97         PROP_WEP_KEY0,
98         PROP_WEP_KEY1,
99         PROP_WEP_KEY2,
100         PROP_WEP_KEY3,
101         PROP_WEP_KEY_FLAGS,
102         PROP_WEP_KEY_TYPE,
103         PROP_PSK,
104         PROP_PSK_FLAGS,
105         PROP_LEAP_PASSWORD,
106         PROP_LEAP_PASSWORD_FLAGS,
107
108         LAST_PROP
109 };
110
111 /**
112  * nm_setting_wireless_security_new:
113  *
114  * Creates a new #NMSettingWirelessSecurity object with default values.
115  *
116  * Returns: (transfer full): the new empty #NMSettingWirelessSecurity object
117  **/
118 NMSetting *
119 nm_setting_wireless_security_new (void)
120 {
121         return (NMSetting *) g_object_new (NM_TYPE_SETTING_WIRELESS_SECURITY, NULL);
122 }
123
124 /**
125  * nm_setting_wireless_security_get_key_mgmt:
126  * @setting: the #NMSettingWirelessSecurity
127  *
128  * Returns: the #NMSettingWirelessSecurity:key-mgmt property of the setting
129  **/
130 const char *
131 nm_setting_wireless_security_get_key_mgmt (NMSettingWirelessSecurity *setting)
132 {
133         g_return_val_if_fail (NM_IS_SETTING_WIRELESS_SECURITY (setting), NULL);
134
135         return NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE (setting)->key_mgmt;
136 }
137
138 /**
139  * nm_setting_wireless_security_get_num_protos:
140  * @setting: the #NMSettingWirelessSecurity
141  *
142  * Returns: the number of security protocols this connection allows when
143  * connecting to secure Wi-Fi networks
144  **/
145 guint32
146 nm_setting_wireless_security_get_num_protos (NMSettingWirelessSecurity *setting)
147 {
148         g_return_val_if_fail (NM_IS_SETTING_WIRELESS_SECURITY (setting), 0);
149
150         return g_slist_length (NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE (setting)->proto);
151 }
152
153 /**
154  * nm_setting_wireless_security_get_proto:
155  * @setting: the #NMSettingWirelessSecurity
156  * @i: an index into the protocol list
157  *
158  * Returns: the protocol at index @i
159  **/
160 const char *
161 nm_setting_wireless_security_get_proto (NMSettingWirelessSecurity *setting, guint32 i)
162 {
163         NMSettingWirelessSecurityPrivate *priv;
164
165         g_return_val_if_fail (NM_IS_SETTING_WIRELESS_SECURITY (setting), NULL);
166
167         priv = NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE (setting);
168         g_return_val_if_fail (i <= g_slist_length (priv->proto), NULL);
169
170         return (const char *) g_slist_nth_data (priv->proto, i);
171 }
172
173 /**
174  * nm_setting_wireless_security_add_proto:
175  * @setting: the #NMSettingWirelessSecurity
176  * @proto: the protocol to add, one of "wpa" or "rsn"
177  *
178  * Adds a Wi-Fi security protocol (one of "wpa" or "rsn") to the allowed list;
179  * only protocols in this list will be used when finding and connecting to
180  * the Wi-Fi network specified by this connection.  For example, if the
181  * protocol list contains only "wpa" but the access point for the SSID specified
182  * by this connection only supports WPA2/RSN, the connection cannot be used
183  * with the access point.
184  *
185  * Returns: %TRUE if the protocol was new and and was added to the allowed
186  * protocol list, or %FALSE if it was already in the list
187  **/
188 gboolean
189 nm_setting_wireless_security_add_proto (NMSettingWirelessSecurity *setting, const char *proto)
190 {
191         NMSettingWirelessSecurityPrivate *priv;
192         GSList *iter;
193
194         g_return_val_if_fail (NM_IS_SETTING_WIRELESS_SECURITY (setting), FALSE);
195         g_return_val_if_fail (proto != NULL, FALSE);
196
197         priv = NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE (setting);
198         for (iter = priv->proto; iter; iter = g_slist_next (iter)) {
199                 if (strcasecmp (proto, (char *) iter->data) == 0)
200                         return FALSE;
201         }
202
203         priv->proto = g_slist_append (priv->proto, g_ascii_strdown (proto, -1));
204         g_object_notify (G_OBJECT (setting), NM_SETTING_WIRELESS_SECURITY_PROTO);
205         return TRUE;
206 }
207
208 /**
209  * nm_setting_wireless_security_remove_proto:
210  * @setting: the #NMSettingWirelessSecurity
211  * @i: index of the protocol to remove
212  *
213  * Removes a protocol from the allowed protocol list.
214  **/
215 void
216 nm_setting_wireless_security_remove_proto (NMSettingWirelessSecurity *setting, guint32 i)
217 {
218         NMSettingWirelessSecurityPrivate *priv;
219         GSList *elt;
220
221         g_return_if_fail (NM_IS_SETTING_WIRELESS_SECURITY (setting));
222
223         priv = NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE (setting);
224         elt = g_slist_nth (priv->proto, i);
225         g_return_if_fail (elt != NULL);
226
227         g_free (elt->data);
228         priv->proto = g_slist_delete_link (priv->proto, elt);
229         g_object_notify (G_OBJECT (setting), NM_SETTING_WIRELESS_SECURITY_PROTO);
230 }
231
232 /**
233  * nm_setting_wireless_security_remove_proto_by_value:
234  * @setting: the #NMSettingWirelessSecurity
235  * @proto: the protocol to remove, one of "wpa" or "rsn"
236  *
237  * Removes a protocol from the allowed protocol list.
238  *
239  * Returns: %TRUE if the protocol was found and removed; %FALSE it it was not.
240  **/
241 gboolean
242 nm_setting_wireless_security_remove_proto_by_value (NMSettingWirelessSecurity *setting,
243                                                     const char *proto)
244 {
245         NMSettingWirelessSecurityPrivate *priv;
246         GSList *iter;
247
248         g_return_val_if_fail (NM_IS_SETTING_WIRELESS_SECURITY (setting), FALSE);
249         g_return_val_if_fail (proto != NULL, FALSE);
250
251         priv = NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE (setting);
252         for (iter = priv->proto; iter; iter = g_slist_next (iter)) {
253                 if (strcasecmp (proto, (char *) iter->data) == 0) {
254                         priv->proto = g_slist_delete_link (priv->proto, iter);
255                         g_object_notify (G_OBJECT (setting), NM_SETTING_WIRELESS_SECURITY_PROTO);
256                         return TRUE;
257                 }
258         }
259         return FALSE;
260 }
261
262 /**
263  * nm_setting_wireless_security_clear_protos:
264  * @setting: the #NMSettingWirelessSecurity
265  *
266  * Removes all protocols from the allowed list.  If there are no protocols
267  * specified then all protocols are allowed.
268  **/
269 void
270 nm_setting_wireless_security_clear_protos (NMSettingWirelessSecurity *setting)
271 {
272         NMSettingWirelessSecurityPrivate *priv;
273
274         g_return_if_fail (NM_IS_SETTING_WIRELESS_SECURITY (setting));
275
276         priv = NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE (setting);
277         g_slist_free_full (priv->proto, g_free);
278         priv->proto = NULL;
279         g_object_notify (G_OBJECT (setting), NM_SETTING_WIRELESS_SECURITY_PROTO);
280 }
281
282 /**
283  * nm_setting_wireless_security_get_num_pairwise:
284  * @setting: the #NMSettingWirelessSecurity
285  *
286  * Returns: the number of pairwise encryption algorithms in the allowed list
287  **/
288 guint32
289 nm_setting_wireless_security_get_num_pairwise (NMSettingWirelessSecurity *setting)
290 {
291         g_return_val_if_fail (NM_IS_SETTING_WIRELESS_SECURITY (setting), 0);
292
293         return g_slist_length (NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE (setting)->pairwise);
294 }
295
296 /**
297  * nm_setting_wireless_security_get_pairwise:
298  * @setting: the #NMSettingWirelessSecurity
299  * @i: index of an item in the allowed pairwise encryption algorithm list
300  *
301  * Returns the allowed pairwise encryption algorithm from allowed algorithm
302  * list.
303  *
304  * Returns: the pairwise encryption algorithm at index @i
305  **/
306 const char *
307 nm_setting_wireless_security_get_pairwise (NMSettingWirelessSecurity *setting, guint32 i)
308 {
309         NMSettingWirelessSecurityPrivate *priv;
310
311         g_return_val_if_fail (NM_IS_SETTING_WIRELESS_SECURITY (setting), NULL);
312
313         priv = NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE (setting);
314         g_return_val_if_fail (i <= g_slist_length (priv->pairwise), NULL);
315
316         return (const char *) g_slist_nth_data (priv->pairwise, i);
317 }
318
319 /**
320  * nm_setting_wireless_security_add_pairwise:
321  * @setting: the #NMSettingWirelessSecurity
322  * @pairwise: the encryption algorithm to add, one of "tkip" or "ccmp"
323  *
324  * Adds an encryption algorithm to the list of allowed pairwise encryption
325  * algorithms.  If the list is not empty, then only access points that support
326  * one or more of the encryption algorithms in the list will be considered
327  * compatible with this connection.
328  *
329  * Returns: %TRUE if the algorithm was added to the list, %FALSE if it was
330  * already in the list
331  **/
332 gboolean
333 nm_setting_wireless_security_add_pairwise (NMSettingWirelessSecurity *setting, const char *pairwise)
334 {
335         NMSettingWirelessSecurityPrivate *priv;
336         GSList *iter;
337
338         g_return_val_if_fail (NM_IS_SETTING_WIRELESS_SECURITY (setting), FALSE);
339         g_return_val_if_fail (pairwise != NULL, FALSE);
340
341         priv = NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE (setting);
342         for (iter = priv->pairwise; iter; iter = g_slist_next (iter)) {
343                 if (strcasecmp (pairwise, (char *) iter->data) == 0)
344                         return FALSE;
345         }
346
347         priv->pairwise = g_slist_append (priv->pairwise, g_ascii_strdown (pairwise, -1));
348         g_object_notify (G_OBJECT (setting), NM_SETTING_WIRELESS_SECURITY_PAIRWISE);
349         return TRUE;
350 }
351
352 /**
353  * nm_setting_wireless_security_remove_pairwise:
354  * @setting: the #NMSettingWirelessSecurity
355  * @i: the index of an item in the allowed pairwise encryption algorithm list
356  *
357  * Removes an encryption algorithm from the allowed pairwise encryption
358  * algorithm list.
359  **/
360 void
361 nm_setting_wireless_security_remove_pairwise (NMSettingWirelessSecurity *setting, guint32 i)
362 {
363         NMSettingWirelessSecurityPrivate *priv;
364         GSList *elt;
365
366         g_return_if_fail (NM_IS_SETTING_WIRELESS_SECURITY (setting));
367
368         priv = NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE (setting);
369         elt = g_slist_nth (priv->pairwise, i);
370         g_return_if_fail (elt != NULL);
371
372         g_free (elt->data);
373         priv->pairwise = g_slist_delete_link (priv->pairwise, elt);
374         g_object_notify (G_OBJECT (setting), NM_SETTING_WIRELESS_SECURITY_PAIRWISE);
375 }
376
377 /**
378  * nm_setting_wireless_security_remove_pairwise_by_value:
379  * @setting: the #NMSettingWirelessSecurity
380  * @pairwise: the encryption algorithm to remove, one of "tkip" or "ccmp"
381  *
382  * Removes an encryption algorithm from the allowed pairwise encryption
383  * algorithm list.
384  *
385  * Returns: %TRUE if the encryption algorith was found and removed; %FALSE it it was not.
386  **/
387 gboolean
388 nm_setting_wireless_security_remove_pairwise_by_value (NMSettingWirelessSecurity *setting,
389                                                        const char *pairwise)
390 {
391         NMSettingWirelessSecurityPrivate *priv;
392         GSList *iter;
393
394         g_return_val_if_fail (NM_IS_SETTING_WIRELESS_SECURITY (setting), FALSE);
395         g_return_val_if_fail (pairwise != NULL, FALSE);
396
397         priv = NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE (setting);
398         for (iter = priv->pairwise; iter; iter = g_slist_next (iter)) {
399                 if (strcasecmp (pairwise, (char *) iter->data) == 0) {
400                         priv->pairwise = g_slist_delete_link (priv->pairwise, iter);
401                         g_object_notify (G_OBJECT (setting), NM_SETTING_WIRELESS_SECURITY_PAIRWISE);
402                         return TRUE;
403                 }
404         }
405         return FALSE;
406 }
407
408 /**
409  * nm_setting_wireless_security_clear_pairwise:
410  * @setting: the #NMSettingWirelessSecurity
411  *
412  * Removes all algorithms from the allowed list.  If there are no algorithms
413  * specified then all pairwise encryption algorithms are allowed.
414  **/
415 void
416 nm_setting_wireless_security_clear_pairwise (NMSettingWirelessSecurity *setting)
417 {
418         NMSettingWirelessSecurityPrivate *priv;
419
420         g_return_if_fail (NM_IS_SETTING_WIRELESS_SECURITY (setting));
421
422         priv = NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE (setting);
423         g_slist_free_full (priv->pairwise, g_free);
424         priv->pairwise = NULL;
425         g_object_notify (G_OBJECT (setting), NM_SETTING_WIRELESS_SECURITY_PAIRWISE);
426 }
427
428 /**
429  * nm_setting_wireless_security_get_num_groups:
430  * @setting: the #NMSettingWirelessSecurity
431  *
432  * Returns: the number of groupwise encryption algorithms in the allowed list
433  **/
434 guint32
435 nm_setting_wireless_security_get_num_groups (NMSettingWirelessSecurity *setting)
436 {
437         g_return_val_if_fail (NM_IS_SETTING_WIRELESS_SECURITY (setting), 0);
438
439         return g_slist_length (NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE (setting)->group);
440 }
441
442 /**
443  * nm_setting_wireless_security_get_group:
444  * @setting: the #NMSettingWirelessSecurity
445  * @i: index of an item in the allowed groupwise encryption algorithm list
446  *
447  * Returns the allowed groupwise encryption algorithm from allowed algorithm
448  * list.
449  *
450  * Returns: the groupwise encryption algorithm at index @i
451  **/
452 const char *
453 nm_setting_wireless_security_get_group (NMSettingWirelessSecurity *setting, guint32 i)
454 {
455         NMSettingWirelessSecurityPrivate *priv;
456
457         g_return_val_if_fail (NM_IS_SETTING_WIRELESS_SECURITY (setting), NULL);
458
459         priv = NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE (setting);
460         g_return_val_if_fail (i <= g_slist_length (priv->group), NULL);
461
462         return (const char *) g_slist_nth_data (priv->group, i);
463 }
464
465 /**
466  * nm_setting_wireless_security_add_group:
467  * @setting: the #NMSettingWirelessSecurity
468  * @group: the encryption algorithm to add, one of "wep40", "wep104",
469  * "tkip", or "ccmp"
470  *
471  * Adds an encryption algorithm to the list of allowed groupwise encryption
472  * algorithms.  If the list is not empty, then only access points that support
473  * one or more of the encryption algorithms in the list will be considered
474  * compatible with this connection.
475  *
476  * Returns: %TRUE if the algorithm was added to the list, %FALSE if it was
477  * already in the list
478  **/
479 gboolean
480 nm_setting_wireless_security_add_group (NMSettingWirelessSecurity *setting, const char *group)
481 {
482         NMSettingWirelessSecurityPrivate *priv;
483         GSList *iter;
484
485         g_return_val_if_fail (NM_IS_SETTING_WIRELESS_SECURITY (setting), FALSE);
486         g_return_val_if_fail (group != NULL, FALSE);
487
488         priv = NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE (setting);
489         for (iter = priv->group; iter; iter = g_slist_next (iter)) {
490                 if (strcasecmp (group, (char *) iter->data) == 0)
491                         return FALSE;
492         }
493
494         priv->group = g_slist_append (priv->group, g_ascii_strdown (group, -1));
495         g_object_notify (G_OBJECT (setting), NM_SETTING_WIRELESS_SECURITY_GROUP);
496         return TRUE;
497 }
498
499 /**
500  * nm_setting_wireless_security_remove_group:
501  * @setting: the #NMSettingWirelessSecurity
502  * @i: the index of an item in the allowed groupwise encryption algorithm list
503  *
504  * Removes an encryption algorithm from the allowed groupwise encryption
505  * algorithm list.
506  **/
507 void
508 nm_setting_wireless_security_remove_group (NMSettingWirelessSecurity *setting, guint32 i)
509 {
510         NMSettingWirelessSecurityPrivate *priv;
511         GSList *elt;
512
513         g_return_if_fail (NM_IS_SETTING_WIRELESS_SECURITY (setting));
514
515         priv = NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE (setting);
516         elt = g_slist_nth (priv->group, i);
517         g_return_if_fail (elt != NULL);
518
519         g_free (elt->data);
520         priv->group = g_slist_delete_link (priv->group, elt);
521         g_object_notify (G_OBJECT (setting), NM_SETTING_WIRELESS_SECURITY_GROUP);
522 }
523
524 /**
525  * nm_setting_wireless_security_remove_group_by_value:
526  * @setting: the #NMSettingWirelessSecurity
527  * @group: the encryption algorithm to remove, one of "wep40", "wep104",
528  * "tkip", or "ccmp"
529  *
530  * Removes an encryption algorithm from the allowed groupwise encryption
531  * algorithm list.
532  *
533  * Returns: %TRUE if the algorithm was found and removed; %FALSE it it was not.
534  **/
535 gboolean
536 nm_setting_wireless_security_remove_group_by_value (NMSettingWirelessSecurity *setting,
537                                                     const char *group)
538 {
539         NMSettingWirelessSecurityPrivate *priv;
540         GSList *iter;
541
542         g_return_val_if_fail (NM_IS_SETTING_WIRELESS_SECURITY (setting), FALSE);
543         g_return_val_if_fail (group != NULL, FALSE);
544
545         priv = NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE (setting);
546         for (iter = priv->group; iter; iter = g_slist_next (iter)) {
547                 if (strcasecmp (group, (char *) iter->data) == 0) {
548                         priv->group = g_slist_delete_link (priv->group, iter);
549                         g_object_notify (G_OBJECT (setting), NM_SETTING_WIRELESS_SECURITY_GROUP);
550                         return TRUE;
551                 }
552         }
553         return FALSE;
554 }
555
556 /**
557  * nm_setting_wireless_security_clear_groups:
558  * @setting: the #NMSettingWirelessSecurity
559  *
560  * Removes all algorithms from the allowed list.  If there are no algorithms
561  * specified then all groupwise encryption algorithms are allowed.
562  **/
563 void
564 nm_setting_wireless_security_clear_groups (NMSettingWirelessSecurity *setting)
565 {
566         NMSettingWirelessSecurityPrivate *priv;
567
568         g_return_if_fail (NM_IS_SETTING_WIRELESS_SECURITY (setting));
569
570         priv = NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE (setting);
571         g_slist_free_full (priv->group, g_free);
572         priv->group = NULL;
573         g_object_notify (G_OBJECT (setting), NM_SETTING_WIRELESS_SECURITY_GROUP);
574 }
575
576 /**
577  * nm_setting_wireless_security_get_psk:
578  * @setting: the #NMSettingWirelessSecurity
579  *
580  * Returns: the #NMSettingWirelessSecurity:psk property of the setting
581  **/
582 const char *
583 nm_setting_wireless_security_get_psk (NMSettingWirelessSecurity *setting)
584 {
585         g_return_val_if_fail (NM_IS_SETTING_WIRELESS_SECURITY (setting), NULL);
586
587         return NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE (setting)->psk;
588 }
589
590 /**
591  * nm_setting_wireless_security_get_psk_flags:
592  * @setting: the #NMSettingWirelessSecurity
593  *
594  * Returns: the #NMSettingSecretFlags pertaining to the
595  * #NMSettingWirelessSecurity:psk
596  **/
597 NMSettingSecretFlags
598 nm_setting_wireless_security_get_psk_flags (NMSettingWirelessSecurity *setting)
599 {
600         g_return_val_if_fail (NM_IS_SETTING_WIRELESS_SECURITY (setting), NM_SETTING_SECRET_FLAG_NONE);
601
602         return NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE (setting)->psk_flags;
603 }
604
605 /**
606  * nm_setting_wireless_security_get_leap_username:
607  * @setting: the #NMSettingWirelessSecurity
608  *
609  * Returns: the #NMSettingWirelessSecurity:leap-username property of the setting
610  **/
611 const char *
612 nm_setting_wireless_security_get_leap_username (NMSettingWirelessSecurity *setting)
613 {
614         g_return_val_if_fail (NM_IS_SETTING_WIRELESS_SECURITY (setting), NULL);
615
616         return NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE (setting)->leap_username;
617 }
618
619 /**
620  * nm_setting_wireless_security_get_leap_password:
621  * @setting: the #NMSettingWirelessSecurity
622  *
623  * Returns: the #NMSettingWirelessSecurity:leap-password property of the setting
624  **/
625 const char *
626 nm_setting_wireless_security_get_leap_password (NMSettingWirelessSecurity *setting)
627 {
628         g_return_val_if_fail (NM_IS_SETTING_WIRELESS_SECURITY (setting), NULL);
629
630         return NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE (setting)->leap_password;
631 }
632
633 /**
634  * nm_setting_wireless_security_get_leap_password_flags:
635  * @setting: the #NMSettingWirelessSecurity
636  *
637  * Returns: the #NMSettingSecretFlags pertaining to the
638  * #NMSettingWirelessSecurity:leap-password
639  **/
640 NMSettingSecretFlags
641 nm_setting_wireless_security_get_leap_password_flags (NMSettingWirelessSecurity *setting)
642 {
643         g_return_val_if_fail (NM_IS_SETTING_WIRELESS_SECURITY (setting), NM_SETTING_SECRET_FLAG_NONE);
644
645         return NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE (setting)->leap_password_flags;
646 }
647
648 /**
649  * nm_setting_wireless_security_get_wep_key:
650  * @setting: the #NMSettingWirelessSecurity
651  * @idx: the WEP key index (0..3 inclusive)
652  *
653  * Returns: the WEP key at the given index
654  **/
655 const char *
656 nm_setting_wireless_security_get_wep_key (NMSettingWirelessSecurity *setting, guint32 idx)
657 {
658         NMSettingWirelessSecurityPrivate *priv;
659
660         g_return_val_if_fail (NM_IS_SETTING_WIRELESS_SECURITY (setting), NULL);
661         g_return_val_if_fail (idx < 4, NULL);
662
663         priv = NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE (setting);
664         if (idx == 0)
665                 return priv->wep_key0;
666         else if (idx == 1)
667                 return priv->wep_key1;
668         else if (idx == 2)
669                 return priv->wep_key2;
670         else if (idx == 3)
671                 return priv->wep_key3;
672
673         g_assert_not_reached ();
674         return NULL;
675 }
676
677 /**
678  * nm_setting_wireless_security_set_wep_key:
679  * @setting: the #NMSettingWirelessSecurity
680  * @idx: the index of the key (0..3 inclusive)
681  * @key: the WEP key as a string, in either hexadecimal, ASCII, or passphrase
682  * form as determiend by the value of the #NMSettingWirelessSecurity:wep-key-type
683  * property.
684  *
685  * Sets a WEP key in the given index.
686  **/
687 void
688 nm_setting_wireless_security_set_wep_key (NMSettingWirelessSecurity *setting, guint32 idx, const char *key)
689 {
690         NMSettingWirelessSecurityPrivate *priv;
691
692         g_return_if_fail (NM_IS_SETTING_WIRELESS_SECURITY (setting));
693         g_return_if_fail (idx < 4);
694
695         priv = NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE (setting);
696         switch (idx) {
697         case 0:
698                 g_free (priv->wep_key0);
699                 priv->wep_key0 = g_strdup (key);
700                 g_object_notify (G_OBJECT (setting), NM_SETTING_WIRELESS_SECURITY_WEP_KEY0);
701                 break;
702         case 1:
703                 g_free (priv->wep_key1);
704                 priv->wep_key1 = g_strdup (key);
705                 g_object_notify (G_OBJECT (setting), NM_SETTING_WIRELESS_SECURITY_WEP_KEY1);
706                 break;
707         case 2:
708                 g_free (priv->wep_key2);
709                 priv->wep_key2 = g_strdup (key);
710                 g_object_notify (G_OBJECT (setting), NM_SETTING_WIRELESS_SECURITY_WEP_KEY2);
711                 break;
712         case 3:
713                 g_free (priv->wep_key3);
714                 priv->wep_key3 = g_strdup (key);
715                 g_object_notify (G_OBJECT (setting), NM_SETTING_WIRELESS_SECURITY_WEP_KEY3);
716                 break;
717         default:
718                 g_assert_not_reached ();
719         }
720 }
721
722 /**
723  * nm_setting_wireless_security_get_wep_tx_keyidx:
724  * @setting: the #NMSettingWirelessSecurity
725  *
726  * Returns: the #NMSettingWirelessSecurity:wep-tx-keyidx property of the setting
727  **/
728 guint32
729 nm_setting_wireless_security_get_wep_tx_keyidx (NMSettingWirelessSecurity *setting)
730 {
731         g_return_val_if_fail (NM_IS_SETTING_WIRELESS_SECURITY (setting), 0);
732
733         return NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE (setting)->wep_tx_keyidx;
734 }
735
736 /**
737  * nm_setting_wireless_security_get_auth_alg:
738  * @setting: the #NMSettingWirelessSecurity
739  *
740  * Returns: the #NMSettingWirelessSecurity:auth-alg property of the setting
741  **/
742 const char *
743 nm_setting_wireless_security_get_auth_alg (NMSettingWirelessSecurity *setting)
744 {
745         g_return_val_if_fail (NM_IS_SETTING_WIRELESS_SECURITY (setting), NULL);
746
747         return NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE (setting)->auth_alg;
748 }
749
750 /**
751  * nm_setting_wireless_security_get_wep_key_flags:
752  * @setting: the #NMSettingWirelessSecurity
753  *
754  * Returns: the #NMSettingSecretFlags pertaining to the all WEP keys
755  **/
756 NMSettingSecretFlags
757 nm_setting_wireless_security_get_wep_key_flags (NMSettingWirelessSecurity *setting)
758 {
759         g_return_val_if_fail (NM_IS_SETTING_WIRELESS_SECURITY (setting), NM_SETTING_SECRET_FLAG_NONE);
760
761         return NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE (setting)->wep_key_flags;
762 }
763
764 /**
765  * nm_setting_wireless_security_get_wep_key_type:
766  * @setting: the #NMSettingWirelessSecurity
767  *
768  * Returns: the #NMSettingWirelessSecurity:wep-key-type property of the setting
769  **/
770 NMWepKeyType
771 nm_setting_wireless_security_get_wep_key_type (NMSettingWirelessSecurity *setting)
772 {
773         g_return_val_if_fail (NM_IS_SETTING_WIRELESS_SECURITY (setting), 0);
774
775         return NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE (setting)->wep_key_type;
776 }
777
778 static GPtrArray *
779 need_secrets (NMSetting *setting)
780 {
781         NMSettingWirelessSecurity *self = NM_SETTING_WIRELESS_SECURITY (setting);
782         NMSettingWirelessSecurityPrivate *priv = NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE (self);
783         GPtrArray *secrets;
784
785         secrets = g_ptr_array_sized_new (4);
786
787         g_assert (priv->key_mgmt);
788
789         /* Static WEP */
790         if (strcmp (priv->key_mgmt, "none") == 0) {
791                 if ((priv->wep_tx_keyidx == 0) && !nm_utils_wep_key_valid (priv->wep_key0, priv->wep_key_type)) {
792                         g_ptr_array_add (secrets, NM_SETTING_WIRELESS_SECURITY_WEP_KEY0);
793                         return secrets;
794                 }
795                 if ((priv->wep_tx_keyidx == 1) && !nm_utils_wep_key_valid (priv->wep_key1, priv->wep_key_type)) {
796                         g_ptr_array_add (secrets, NM_SETTING_WIRELESS_SECURITY_WEP_KEY1);
797                         return secrets;
798                 }
799                 if ((priv->wep_tx_keyidx == 2) && !nm_utils_wep_key_valid (priv->wep_key2, priv->wep_key_type)) {
800                         g_ptr_array_add (secrets, NM_SETTING_WIRELESS_SECURITY_WEP_KEY2);
801                         return secrets;
802                 }
803                 if ((priv->wep_tx_keyidx == 3) && !nm_utils_wep_key_valid (priv->wep_key3, priv->wep_key_type)) {
804                         g_ptr_array_add (secrets, NM_SETTING_WIRELESS_SECURITY_WEP_KEY3);
805                         return secrets;
806                 }
807                 goto no_secrets;
808         }
809
810         /* WPA-PSK infrastructure and adhoc */
811         if (   (strcmp (priv->key_mgmt, "wpa-none") == 0)
812             || (strcmp (priv->key_mgmt, "wpa-psk") == 0)) {
813                 if (!nm_utils_wpa_psk_valid (priv->psk)) {
814                         g_ptr_array_add (secrets, NM_SETTING_WIRELESS_SECURITY_PSK);
815                         return secrets;
816                 }
817                 goto no_secrets;
818         }
819
820         /* LEAP */
821         if (   priv->auth_alg
822             && !strcmp (priv->auth_alg, "leap")
823             && !strcmp (priv->key_mgmt, "ieee8021x")) {
824                 if (!priv->leap_password || !*priv->leap_password) {
825                         g_ptr_array_add (secrets, NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD);
826                         return secrets;
827                 }
828                 goto no_secrets;
829         }
830
831         if (   (strcmp (priv->key_mgmt, "ieee8021x") == 0)
832             || (strcmp (priv->key_mgmt, "wpa-eap") == 0)) {
833                 /* Let caller check the 802.1x setting for secrets */
834                 goto no_secrets;
835         }
836
837         g_assert_not_reached ();
838         return secrets;
839
840 no_secrets:
841         if (secrets)
842                 g_ptr_array_free (secrets, TRUE);
843         return NULL;
844 }
845
846 static gboolean
847 verify (NMSetting *setting, NMConnection *connection, GError **error)
848 {
849         NMSettingWirelessSecurity *self = NM_SETTING_WIRELESS_SECURITY (setting);
850         NMSettingWirelessSecurityPrivate *priv = NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE (self);
851         const char *valid_key_mgmt[] = { "none", "ieee8021x", "wpa-none", "wpa-psk", "wpa-eap", NULL };
852         const char *valid_auth_algs[] = { "open", "shared", "leap", NULL };
853         const char *valid_protos[] = { "wpa", "rsn", NULL };
854         const char *valid_pairwise[] = { "tkip", "ccmp", NULL };
855         const char *valid_groups[] = { "wep40", "wep104", "tkip", "ccmp", NULL };
856
857         if (!priv->key_mgmt) {
858                 g_set_error_literal (error,
859                                      NM_CONNECTION_ERROR,
860                                      NM_CONNECTION_ERROR_MISSING_PROPERTY,
861                                      _("property is missing"));
862                 g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SECURITY_SETTING_NAME, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT);
863                 return FALSE;
864         }
865
866         if (!_nm_utils_string_in_list (priv->key_mgmt, valid_key_mgmt)) {
867                 g_set_error (error,
868                              NM_CONNECTION_ERROR,
869                              NM_CONNECTION_ERROR_INVALID_PROPERTY,
870                              _("'%s' is not a valid value for the property"),
871                              priv->key_mgmt);
872                 g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SECURITY_SETTING_NAME, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT);
873                 return FALSE;
874         }
875
876         if (priv->auth_alg && !strcmp (priv->auth_alg, "leap")) {
877                 /* LEAP must use ieee8021x key management */
878                 if (strcmp (priv->key_mgmt, "ieee8021x")) {
879                         g_set_error (error,
880                                      NM_CONNECTION_ERROR,
881                                      NM_CONNECTION_ERROR_INVALID_PROPERTY,
882                                      _("'%s' security requires '%s=%s'"),
883                                      "leap", NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "ieee8021x");
884                         g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SECURITY_SETTING_NAME, NM_SETTING_WIRELESS_SECURITY_AUTH_ALG);
885                         return FALSE;
886                 }
887                 if (!priv->leap_username) {
888                         g_set_error_literal (error,
889                                              NM_CONNECTION_ERROR,
890                                              NM_CONNECTION_ERROR_MISSING_PROPERTY,
891                                              _("property is empty"));
892                         g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SECURITY_SETTING_NAME, NM_SETTING_WIRELESS_SECURITY_LEAP_USERNAME);
893                         return FALSE;
894                 }
895         } else {
896                 if (   (strcmp (priv->key_mgmt, "ieee8021x") == 0)
897                     || (strcmp (priv->key_mgmt, "wpa-eap") == 0)) {
898                         /* Need an 802.1x setting too */
899                         if (connection && !nm_connection_get_setting_802_1x (connection)) {
900                                 g_set_error (error,
901                                              NM_CONNECTION_ERROR,
902                                              NM_CONNECTION_ERROR_MISSING_SETTING,
903                                              _("'%s' security requires '%s' setting presence"),
904                                              priv->key_mgmt, NM_SETTING_802_1X_SETTING_NAME);
905                                 g_prefix_error (error, "%s: ", NM_SETTING_802_1X_SETTING_NAME);
906                                 return FALSE;
907                         }
908                 }
909         }
910
911         if (priv->leap_username && !strlen (priv->leap_username)) {
912                 g_set_error_literal (error,
913                                      NM_CONNECTION_ERROR,
914                                      NM_CONNECTION_ERROR_INVALID_PROPERTY,
915                                      _("property is empty"));
916                 g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SECURITY_SETTING_NAME, NM_SETTING_WIRELESS_SECURITY_LEAP_USERNAME);
917                 return FALSE;
918         }
919
920         if (priv->wep_tx_keyidx > 3) {
921                 g_set_error (error,
922                              NM_CONNECTION_ERROR,
923                              NM_CONNECTION_ERROR_INVALID_PROPERTY,
924                              _("'%d' value is out of range <0-3>"),
925                              priv->wep_tx_keyidx);
926                 g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SECURITY_SETTING_NAME, NM_SETTING_WIRELESS_SECURITY_WEP_TX_KEYIDX);
927                 return FALSE;
928         }
929
930         if (priv->wep_key_type > NM_WEP_KEY_TYPE_LAST) {
931                 g_set_error_literal (error,
932                                      NM_CONNECTION_ERROR,
933                                      NM_CONNECTION_ERROR_INVALID_PROPERTY,
934                                      _("property is invalid"));
935                 g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SECURITY_SETTING_NAME, NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE);
936                 return FALSE;
937         }
938
939         if (priv->auth_alg && !_nm_utils_string_in_list (priv->auth_alg, valid_auth_algs)) {
940                 g_set_error_literal (error,
941                                      NM_CONNECTION_ERROR,
942                                      NM_CONNECTION_ERROR_INVALID_PROPERTY,
943                                      _("property is invalid"));
944                 g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SECURITY_SETTING_NAME, NM_SETTING_WIRELESS_SECURITY_AUTH_ALG);
945                 return FALSE;
946         }
947
948         if (priv->proto && !_nm_utils_string_slist_validate (priv->proto, valid_protos)) {
949                 g_set_error_literal (error,
950                                      NM_CONNECTION_ERROR,
951                                      NM_CONNECTION_ERROR_INVALID_PROPERTY,
952                                      _("property is invalid"));
953                 g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SECURITY_SETTING_NAME, NM_SETTING_WIRELESS_SECURITY_PROTO);
954                 return FALSE;
955         }
956
957         if (priv->pairwise) {
958                 const char *wpa_none[] = { "wpa-none", NULL };
959
960                 /* For ad-hoc connections, pairwise must be "none" */
961                 if (_nm_utils_string_in_list (priv->key_mgmt, wpa_none)) {
962                         GSList *iter;
963                         gboolean found = FALSE;
964
965                         for (iter = priv->pairwise; iter; iter = g_slist_next (iter)) {
966                                 if (!strcmp ((char *) iter->data, "none")) {
967                                         found = TRUE;
968                                         break;
969                                 }
970                         }
971
972                         /* pairwise cipher list didn't contain "none", which is invalid
973                          * for WPA adhoc connections.
974                          */
975                         if (!found) {
976                                 g_set_error (error,
977                                              NM_CONNECTION_ERROR,
978                                              NM_CONNECTION_ERROR_INVALID_PROPERTY,
979                                              _("'%s' connections require '%s' in this property"),
980                                              NM_SETTING_WIRELESS_MODE_ADHOC, "none");
981                                 g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SECURITY_SETTING_NAME, NM_SETTING_WIRELESS_SECURITY_PAIRWISE);
982                                 return FALSE;
983                         }
984                 } else if (!_nm_utils_string_slist_validate (priv->pairwise, valid_pairwise)) {
985                         g_set_error_literal (error,
986                                              NM_CONNECTION_ERROR,
987                                              NM_CONNECTION_ERROR_INVALID_PROPERTY,
988                                              _("property is invalid"));
989                         g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SECURITY_SETTING_NAME, NM_SETTING_WIRELESS_SECURITY_PAIRWISE);
990                         return FALSE;
991                 }
992         }
993
994         if (priv->group && !_nm_utils_string_slist_validate (priv->group, valid_groups)) {
995                 g_set_error_literal (error,
996                                      NM_CONNECTION_ERROR,
997                                      NM_CONNECTION_ERROR_INVALID_PROPERTY,
998                                      _("property is invalid"));
999                 g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SECURITY_SETTING_NAME, NM_SETTING_WIRELESS_SECURITY_GROUP);
1000                 return FALSE;
1001         }
1002
1003         /* Shared Key auth can only be used with WEP */
1004         if (priv->auth_alg && !strcmp (priv->auth_alg, "shared")) {
1005                 if (priv->key_mgmt && strcmp (priv->key_mgmt, "none")) {
1006                         g_set_error (error,
1007                                      NM_CONNECTION_ERROR,
1008                                      NM_CONNECTION_ERROR_INVALID_PROPERTY,
1009                                      _("'%s' can only be used with '%s=%s' (WEP)"),
1010                                      "shared", NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "none");
1011                         g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SECURITY_SETTING_NAME, NM_SETTING_WIRELESS_SECURITY_AUTH_ALG);
1012                         return FALSE;
1013                 }
1014         }
1015
1016         return TRUE;
1017 }
1018
1019 static gboolean
1020 _verify_wep_key (const char *wep_key,
1021                  NMWepKeyType wep_key_type,
1022                  const char *property,
1023                  GError **error)
1024 {
1025         if (wep_key && !nm_utils_wep_key_valid (wep_key, wep_key_type)) {
1026                 g_set_error_literal (error,
1027                                      NM_CONNECTION_ERROR,
1028                                      NM_CONNECTION_ERROR_INVALID_PROPERTY,
1029                                      _("property is invalid"));
1030                 g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SECURITY_SETTING_NAME, property);
1031                 return FALSE;
1032         }
1033         return TRUE;
1034 }
1035
1036 static gboolean
1037 verify_secrets (NMSetting *setting, NMConnection *connection, GError **error)
1038 {
1039         NMSettingWirelessSecurity *self = NM_SETTING_WIRELESS_SECURITY (setting);
1040         NMSettingWirelessSecurityPrivate *priv = NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE (self);
1041
1042         /* LEAP */
1043         if (   priv->auth_alg
1044             && !strcmp (priv->auth_alg, "leap")
1045             && !strcmp (priv->key_mgmt, "ieee8021x")) {
1046                 if (!_nm_setting_verify_secret_string (priv->leap_password,
1047                                                        NM_SETTING_WIRELESS_SECURITY_SETTING_NAME,
1048                                                        NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD,
1049                                                        error))
1050                         return FALSE;
1051         }
1052
1053         /* WEP */
1054         if (!_verify_wep_key (priv->wep_key0, priv->wep_key_type, NM_SETTING_WIRELESS_SECURITY_WEP_KEY0, error))
1055                 return FALSE;
1056         if (!_verify_wep_key (priv->wep_key1, priv->wep_key_type, NM_SETTING_WIRELESS_SECURITY_WEP_KEY1, error))
1057                 return FALSE;
1058         if (!_verify_wep_key (priv->wep_key2, priv->wep_key_type, NM_SETTING_WIRELESS_SECURITY_WEP_KEY2, error))
1059                 return FALSE;
1060         if (!_verify_wep_key (priv->wep_key3, priv->wep_key_type, NM_SETTING_WIRELESS_SECURITY_WEP_KEY3, error))
1061                 return FALSE;
1062
1063         /* WPA-PSK */
1064         if (priv->psk && !nm_utils_wpa_psk_valid (priv->psk)) {
1065                 g_set_error_literal (error,
1066                                      NM_CONNECTION_ERROR,
1067                                      NM_CONNECTION_ERROR_INVALID_PROPERTY,
1068                                      _("property is invalid"));
1069                 g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SECURITY_SETTING_NAME, NM_SETTING_WIRELESS_SECURITY_PSK);
1070                 return FALSE;
1071         }
1072
1073         return TRUE;
1074 }
1075
1076 static gboolean
1077 get_secret_flags (NMSetting *setting,
1078                   const char *secret_name,
1079                   gboolean verify_secret,
1080                   NMSettingSecretFlags *out_flags,
1081                   GError **error)
1082 {
1083         NMSettingClass *setting_class;
1084         gboolean verify_override = verify_secret;
1085
1086         /* There's only one 'flags' property for WEP keys, so alias all the WEP key
1087          * property names to that flags property.
1088          */
1089         if (   !g_strcmp0 (secret_name, NM_SETTING_WIRELESS_SECURITY_WEP_KEY0)
1090             || !g_strcmp0 (secret_name, NM_SETTING_WIRELESS_SECURITY_WEP_KEY1)
1091             || !g_strcmp0 (secret_name, NM_SETTING_WIRELESS_SECURITY_WEP_KEY2)
1092             || !g_strcmp0 (secret_name, NM_SETTING_WIRELESS_SECURITY_WEP_KEY3)) {
1093                 secret_name = "wep-key";
1094                 verify_override = FALSE; /* Already know it's a secret */
1095         }
1096
1097         /* Chain up to superclass with modified key name */
1098         setting_class = NM_SETTING_CLASS (nm_setting_wireless_security_parent_class);
1099         return setting_class->get_secret_flags (setting, secret_name, verify_override, out_flags, error);
1100 }
1101
1102 static gboolean
1103 set_secret_flags (NMSetting *setting,
1104                   const char *secret_name,
1105                   gboolean verify_secret,
1106                   NMSettingSecretFlags flags,
1107                   GError **error)
1108 {
1109         NMSettingClass *setting_class;
1110         gboolean verify_override = verify_secret;
1111
1112         /* There's only one 'flags' property for WEP keys, so alias all the WEP key
1113          * property names to that flags property.
1114          */
1115         if (   !g_strcmp0 (secret_name, NM_SETTING_WIRELESS_SECURITY_WEP_KEY0)
1116             || !g_strcmp0 (secret_name, NM_SETTING_WIRELESS_SECURITY_WEP_KEY1)
1117             || !g_strcmp0 (secret_name, NM_SETTING_WIRELESS_SECURITY_WEP_KEY2)
1118             || !g_strcmp0 (secret_name, NM_SETTING_WIRELESS_SECURITY_WEP_KEY3)) {
1119                 secret_name = "wep-key";
1120                 verify_override = FALSE; /* Already know it's a secret */
1121         }
1122
1123         /* Chain up to superclass with modified key name */
1124         setting_class = NM_SETTING_CLASS (nm_setting_wireless_security_parent_class);
1125         return setting_class->set_secret_flags (setting, secret_name, verify_override, flags, error);
1126 }
1127
1128 static void
1129 nm_setting_wireless_security_init (NMSettingWirelessSecurity *setting)
1130 {
1131 }
1132
1133 static void
1134 finalize (GObject *object)
1135 {
1136         NMSettingWirelessSecurity *self = NM_SETTING_WIRELESS_SECURITY (object);
1137         NMSettingWirelessSecurityPrivate *priv = NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE (self);
1138
1139         /* Strings first. g_free() already checks for NULLs so we don't have to */
1140
1141         g_free (priv->key_mgmt);
1142         g_free (priv->auth_alg);
1143         g_free (priv->leap_username);
1144         g_free (priv->wep_key0);
1145         g_free (priv->wep_key1);
1146         g_free (priv->wep_key2);
1147         g_free (priv->wep_key3);
1148         g_free (priv->psk);
1149         g_free (priv->leap_password);
1150
1151         g_slist_free_full (priv->proto, g_free);
1152         g_slist_free_full (priv->pairwise, g_free);
1153         g_slist_free_full (priv->group, g_free);
1154
1155         G_OBJECT_CLASS (nm_setting_wireless_security_parent_class)->finalize (object);
1156 }
1157
1158 /* NMSettingWirelessSecurity:wep-key-type is an enum, but needs to be marshalled
1159  * as 'u', not 'i', for backward-compatibility.
1160  */
1161 static GVariant *
1162 wep_key_type_to_dbus (const GValue *from)
1163 {
1164         return g_variant_new_uint32 (g_value_get_enum (from));
1165 }
1166
1167 static void
1168 set_property (GObject *object, guint prop_id,
1169               const GValue *value, GParamSpec *pspec)
1170 {
1171         NMSettingWirelessSecurity *setting = NM_SETTING_WIRELESS_SECURITY (object);
1172         NMSettingWirelessSecurityPrivate *priv = NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE (setting);
1173         const char *str;
1174
1175         switch (prop_id) {
1176         case PROP_KEY_MGMT:
1177                 g_free (priv->key_mgmt);
1178                 str = g_value_get_string (value);
1179                 priv->key_mgmt = str ? g_ascii_strdown (str, -1) : NULL;
1180                 break;
1181         case PROP_WEP_TX_KEYIDX:
1182                 priv->wep_tx_keyidx = g_value_get_uint (value);
1183                 break;
1184         case PROP_AUTH_ALG:
1185                 g_free (priv->auth_alg);
1186                 str = g_value_get_string (value);
1187                 priv->auth_alg = str ? g_ascii_strdown (str, -1) : NULL;
1188                 break;
1189         case PROP_PROTO:
1190                 g_slist_free_full (priv->proto, g_free);
1191                 priv->proto = _nm_utils_strv_to_slist (g_value_get_boxed (value), TRUE);
1192                 break;
1193         case PROP_PAIRWISE:
1194                 g_slist_free_full (priv->pairwise, g_free);
1195                 priv->pairwise = _nm_utils_strv_to_slist (g_value_get_boxed (value), TRUE);
1196                 break;
1197         case PROP_GROUP:
1198                 g_slist_free_full (priv->group, g_free);
1199                 priv->group = _nm_utils_strv_to_slist (g_value_get_boxed (value), TRUE);
1200                 break;
1201         case PROP_LEAP_USERNAME:
1202                 g_free (priv->leap_username);
1203                 priv->leap_username = g_value_dup_string (value);
1204                 break;
1205         case PROP_WEP_KEY0:
1206                 g_free (priv->wep_key0);
1207                 priv->wep_key0 = g_value_dup_string (value);
1208                 break;
1209         case PROP_WEP_KEY1:
1210                 g_free (priv->wep_key1);
1211                 priv->wep_key1 = g_value_dup_string (value);
1212                 break;
1213         case PROP_WEP_KEY2:
1214                 g_free (priv->wep_key2);
1215                 priv->wep_key2 = g_value_dup_string (value);
1216                 break;
1217         case PROP_WEP_KEY3:
1218                 g_free (priv->wep_key3);
1219                 priv->wep_key3 = g_value_dup_string (value);
1220                 break;
1221         case PROP_WEP_KEY_FLAGS:
1222                 priv->wep_key_flags = g_value_get_flags (value);
1223                 break;
1224         case PROP_PSK:
1225                 g_free (priv->psk);
1226                 priv->psk = g_value_dup_string (value);
1227                 break;
1228         case PROP_PSK_FLAGS:
1229                 priv->psk_flags = g_value_get_flags (value);
1230                 break;
1231         case PROP_LEAP_PASSWORD:
1232                 g_free (priv->leap_password);
1233                 priv->leap_password = g_value_dup_string (value);
1234                 break;
1235         case PROP_LEAP_PASSWORD_FLAGS:
1236                 priv->leap_password_flags = g_value_get_flags (value);
1237                 break;
1238         case PROP_WEP_KEY_TYPE:
1239                 priv->wep_key_type = g_value_get_enum (value);
1240                 break;
1241         default:
1242                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1243                 break;
1244         }
1245 }
1246
1247 static void
1248 get_property (GObject *object, guint prop_id,
1249               GValue *value, GParamSpec *pspec)
1250 {
1251         NMSettingWirelessSecurity *setting = NM_SETTING_WIRELESS_SECURITY (object);
1252         NMSettingWirelessSecurityPrivate *priv = NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE (setting);
1253
1254         switch (prop_id) {
1255         case PROP_KEY_MGMT:
1256                 g_value_set_string (value, priv->key_mgmt);
1257                 break;
1258         case PROP_WEP_TX_KEYIDX:
1259                 g_value_set_uint (value, priv->wep_tx_keyidx);
1260                 break;
1261         case PROP_AUTH_ALG:
1262                 g_value_set_string (value, priv->auth_alg);
1263                 break;
1264         case PROP_PROTO:
1265                 g_value_take_boxed (value, _nm_utils_slist_to_strv (priv->proto, TRUE));
1266                 break;
1267         case PROP_PAIRWISE:
1268                 g_value_take_boxed (value, _nm_utils_slist_to_strv (priv->pairwise, TRUE));
1269                 break;
1270         case PROP_GROUP:
1271                 g_value_take_boxed (value, _nm_utils_slist_to_strv (priv->group, TRUE));
1272                 break;
1273         case PROP_LEAP_USERNAME:
1274                 g_value_set_string (value, priv->leap_username);
1275                 break;
1276         case PROP_WEP_KEY0:
1277                 g_value_set_string (value, priv->wep_key0);
1278                 break;
1279         case PROP_WEP_KEY1:
1280                 g_value_set_string (value, priv->wep_key1);
1281                 break;
1282         case PROP_WEP_KEY2:
1283                 g_value_set_string (value, priv->wep_key2);
1284                 break;
1285         case PROP_WEP_KEY3:
1286                 g_value_set_string (value, priv->wep_key3);
1287                 break;
1288         case PROP_WEP_KEY_FLAGS:
1289                 g_value_set_flags (value, priv->wep_key_flags);
1290                 break;
1291         case PROP_PSK:
1292                 g_value_set_string (value, priv->psk);
1293                 break;
1294         case PROP_PSK_FLAGS:
1295                 g_value_set_flags (value, priv->psk_flags);
1296                 break;
1297         case PROP_LEAP_PASSWORD:
1298                 g_value_set_string (value, priv->leap_password);
1299                 break;
1300         case PROP_LEAP_PASSWORD_FLAGS:
1301                 g_value_set_flags (value, priv->leap_password_flags);
1302                 break;
1303         case PROP_WEP_KEY_TYPE:
1304                 g_value_set_enum (value, priv->wep_key_type);
1305                 break;
1306         default:
1307                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1308                 break;
1309         }
1310 }
1311
1312 static void
1313 nm_setting_wireless_security_class_init (NMSettingWirelessSecurityClass *setting_class)
1314 {
1315         GObjectClass *object_class = G_OBJECT_CLASS (setting_class);
1316         NMSettingClass *parent_class = NM_SETTING_CLASS (setting_class);
1317
1318         g_type_class_add_private (setting_class, sizeof (NMSettingWirelessSecurityPrivate));
1319
1320         /* virtual methods */
1321         object_class->set_property = set_property;
1322         object_class->get_property = get_property;
1323         object_class->finalize     = finalize;
1324
1325         parent_class->verify           = verify;
1326         parent_class->verify_secrets   = verify_secrets;
1327         parent_class->need_secrets     = need_secrets;
1328         parent_class->get_secret_flags = get_secret_flags;
1329         parent_class->set_secret_flags = set_secret_flags;
1330
1331         /* Properties */
1332         /**
1333          * NMSettingWirelessSecurity:key-mgmt:
1334          *
1335          * Key management used for the connection.  One of "none" (WEP), "ieee8021x"
1336          * (Dynamic WEP), "wpa-none" (Ad-Hoc WPA-PSK), "wpa-psk" (infrastructure
1337          * WPA-PSK), or "wpa-eap" (WPA-Enterprise).  This property must be set for
1338          * any Wi-Fi connection that uses security.
1339          **/
1340         /* ---ifcfg-rh---
1341          * property: key-mgmt
1342          * variable: KEY_MGMT(+)
1343          * values: IEEE8021X, WPA-PSK, WPA-EAP
1344          * description: Key management menthod.
1345          * ---end---
1346          */
1347         g_object_class_install_property
1348                 (object_class, PROP_KEY_MGMT,
1349                  g_param_spec_string (NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "", "",
1350                                       NULL,
1351                                       G_PARAM_READWRITE |
1352                                       NM_SETTING_PARAM_REQUIRED |
1353                                       G_PARAM_STATIC_STRINGS));
1354
1355         /**
1356          * NMSettingWirelessSecurity:wep-tx-keyidx:
1357          *
1358          * When static WEP is used (ie, key-mgmt = "none") and a non-default WEP key
1359          * index is used by the AP, put that WEP key index here.  Valid values are 0
1360          * (default key) through 3.  Note that some consumer access points (like the
1361          * Linksys WRT54G) number the keys 1 - 4.
1362          **/
1363         /* ---ifcfg-rh---
1364          * property: wep-tx-keyidx
1365          * variable: DEFAULTKEY
1366          * values: 1, 2, 3, 4
1367          * default: 1
1368          * description: Index of active WEP key.
1369          * ---end---
1370          */
1371         g_object_class_install_property
1372                 (object_class, PROP_WEP_TX_KEYIDX,
1373                  g_param_spec_uint (NM_SETTING_WIRELESS_SECURITY_WEP_TX_KEYIDX, "", "",
1374                                     0, 3, 0,
1375                                     G_PARAM_READWRITE |
1376                                     G_PARAM_CONSTRUCT |
1377                                     G_PARAM_STATIC_STRINGS));
1378
1379         /**
1380          * NMSettingWirelessSecurity:auth-alg:
1381          *
1382          * When WEP is used (ie, key-mgmt = "none" or "ieee8021x") indicate the
1383          * 802.11 authentication algorithm required by the AP here.  One of "open"
1384          * for Open System, "shared" for Shared Key, or "leap" for Cisco LEAP.  When
1385          * using Cisco LEAP (ie, key-mgmt = "ieee8021x" and auth-alg = "leap") the
1386          * "leap-username" and "leap-password" properties must be specified.
1387          **/
1388         /* ---ifcfg-rh---
1389          * property: auth-alg
1390          * variable: SECURITYMODE(+)
1391          * values: restricted, open, leap
1392          * description: Authentication algorithm for WEP.
1393          * ---end---
1394          */
1395         g_object_class_install_property
1396                 (object_class, PROP_AUTH_ALG,
1397                  g_param_spec_string (NM_SETTING_WIRELESS_SECURITY_AUTH_ALG, "", "",
1398                                       NULL,
1399                                       G_PARAM_READWRITE |
1400                                       G_PARAM_STATIC_STRINGS));
1401
1402         /**
1403          * NMSettingWirelessSecurity:proto:
1404          *
1405          * List of strings specifying the allowed WPA protocol versions to use.
1406          * Each element may be one "wpa" (allow WPA) or "rsn" (allow WPA2/RSN).  If
1407          * not specified, both WPA and RSN connections are allowed.
1408          **/
1409         /* ---ifcfg-rh---
1410          * property: proto
1411          * variable: WPA_ALLOW_WPA(+), WPA_ALLOW_WPA2(+)
1412          * values: yes, no
1413          * default: no
1414          * description: Allowed WPA protocols, WPA and WPA2 (RSN).
1415          * ---end---
1416          */
1417         g_object_class_install_property
1418                 (object_class, PROP_PROTO,
1419                  g_param_spec_boxed (NM_SETTING_WIRELESS_SECURITY_PROTO, "", "",
1420                                      G_TYPE_STRV,
1421                                      G_PARAM_READWRITE |
1422                                      G_PARAM_STATIC_STRINGS));
1423
1424         /**
1425          * NMSettingWirelessSecurity:pairwise:
1426          *
1427          * A list of pairwise encryption algorithms which prevents connections to
1428          * Wi-Fi networks that do not utilize one of the algorithms in the list.
1429          * For maximum compatibility leave this property empty.  Each list element
1430          * may be one of "tkip" or "ccmp".
1431          **/
1432         /* ---ifcfg-rh---
1433          * property: pairwise
1434          * variable: CIPHER_PAIRWISE(+)
1435          * values: CCMP, TKIP
1436          * description: Restrict pairwise encryption algorithms, specified as a space
1437          *   separated list.
1438          * ---end---
1439          */
1440         g_object_class_install_property
1441                 (object_class, PROP_PAIRWISE,
1442                  g_param_spec_boxed (NM_SETTING_WIRELESS_SECURITY_PAIRWISE, "", "",
1443                                      G_TYPE_STRV,
1444                                      G_PARAM_READWRITE |
1445                                      G_PARAM_STATIC_STRINGS));
1446
1447         /**
1448          * NMSettingWirelessSecurity:group:
1449          *
1450          * A list of group/broadcast encryption algorithms which prevents
1451          * connections to Wi-Fi networks that do not utilize one of the algorithms
1452          * in the list.  For maximum compatibility leave this property empty.  Each
1453          * list element may be one of "wep40", "wep104", "tkip", or "ccmp".
1454          **/
1455         /* ---ifcfg-rh---
1456          * property: group
1457          * variable: CIPHER_GROUP(+)
1458          * values: CCMP, TKIP, WEP40, WEP104
1459          * description: Restrict group/broadcast encryption algorithms, specified as a space
1460          *   separated list.
1461          * ---end---
1462          */
1463         g_object_class_install_property
1464                 (object_class, PROP_GROUP,
1465                  g_param_spec_boxed (NM_SETTING_WIRELESS_SECURITY_GROUP, "", "",
1466                                      G_TYPE_STRV,
1467                                      G_PARAM_READWRITE |
1468                                      G_PARAM_STATIC_STRINGS));
1469
1470         /**
1471          * NMSettingWirelessSecurity:leap-username:
1472          *
1473          * The login username for legacy LEAP connections (ie, key-mgmt =
1474          * "ieee8021x" and auth-alg = "leap").
1475          **/
1476         /* ---ifcfg-rh---
1477          * property: leap-username
1478          * variable: IEEE_8021X_IDENTITY(+)
1479          * description: Login name for LEAP.
1480          * ---end---
1481          */
1482         g_object_class_install_property
1483                 (object_class, PROP_LEAP_USERNAME,
1484                  g_param_spec_string (NM_SETTING_WIRELESS_SECURITY_LEAP_USERNAME, "", "",
1485                                       NULL,
1486                                       G_PARAM_READWRITE |
1487                                       G_PARAM_STATIC_STRINGS));
1488
1489         /**
1490          * NMSettingWirelessSecurity:wep-key0:
1491          *
1492          * Index 0 WEP key.  This is the WEP key used in most networks.  See the
1493          * "wep-key-type" property for a description of how this key is interpreted.
1494          **/
1495         /* ---ifcfg-rh---
1496          * property: wep-key0
1497          * variable: KEY1, KEY_PASSPHRASE1(+)
1498          * description: The first WEP key (used in most networks). See also DEFAULTKEY for key index.
1499          * ---end---
1500          */
1501         g_object_class_install_property
1502                 (object_class, PROP_WEP_KEY0,
1503                  g_param_spec_string (NM_SETTING_WIRELESS_SECURITY_WEP_KEY0, "", "",
1504                                       NULL,
1505                                       G_PARAM_READWRITE |
1506                                       NM_SETTING_PARAM_SECRET |
1507                                       G_PARAM_STATIC_STRINGS));
1508
1509         /**
1510          * NMSettingWirelessSecurity:wep-key1:
1511          *
1512          * Index 1 WEP key.  This WEP index is not used by most networks.  See the
1513          * "wep-key-type" property for a description of how this key is interpreted.
1514          **/
1515         /* ---ifcfg-rh---
1516          * property: wep-key1
1517          * variable: KEY2, KEY_PASSPHRASE2(+)
1518          * description: WEP key with index 1. See also DEFAULTKEY for key index.
1519          * ---end---
1520          */
1521         g_object_class_install_property
1522                 (object_class, PROP_WEP_KEY1,
1523                  g_param_spec_string (NM_SETTING_WIRELESS_SECURITY_WEP_KEY1, "", "",
1524                                       NULL,
1525                                       G_PARAM_READWRITE |
1526                                       NM_SETTING_PARAM_SECRET |
1527                                       G_PARAM_STATIC_STRINGS));
1528
1529         /**
1530          * NMSettingWirelessSecurity:wep-key2:
1531          *
1532          * Index 2 WEP key.  This WEP index is not used by most networks.  See the
1533          * "wep-key-type" property for a description of how this key is interpreted.
1534          **/
1535         /* ---ifcfg-rh---
1536          * property: wep-key2
1537          * variable: KEY3, KEY_PASSPHRASE3(+)
1538          * description: WEP key with index 2. See also DEFAULTKEY for key index.
1539          * ---end---
1540          */
1541         g_object_class_install_property
1542                 (object_class, PROP_WEP_KEY2,
1543                  g_param_spec_string (NM_SETTING_WIRELESS_SECURITY_WEP_KEY2, "", "",
1544                                       NULL,
1545                                       G_PARAM_READWRITE |
1546                                       NM_SETTING_PARAM_SECRET |
1547                                       G_PARAM_STATIC_STRINGS));
1548
1549         /**
1550          * NMSettingWirelessSecurity:wep-key3:
1551          *
1552          * Index 3 WEP key.  This WEP index is not used by most networks.  See the
1553          * "wep-key-type" property for a description of how this key is interpreted.
1554          **/
1555         /* ---ifcfg-rh---
1556          * property: wep-key3
1557          * variable: KEY4, KEY_PASSPHRASE4(+)
1558          * description: WEP key with index 3. See also DEFAULTKEY for key index.
1559          * ---end---
1560          */
1561         g_object_class_install_property
1562                 (object_class, PROP_WEP_KEY3,
1563                  g_param_spec_string (NM_SETTING_WIRELESS_SECURITY_WEP_KEY3, "", "",
1564                                       NULL,
1565                                       G_PARAM_READWRITE |
1566                                       NM_SETTING_PARAM_SECRET |
1567                                       G_PARAM_STATIC_STRINGS));
1568
1569         /**
1570          * NMSettingWirelessSecurity:wep-key-flags:
1571          *
1572          * Flags indicating how to handle the #NMSettingWirelessSecurity:wep-key0,
1573          * #NMSettingWirelessSecurity:wep-key1, #NMSettingWirelessSecurity:wep-key2,
1574          * and #NMSettingWirelessSecurity:wep-key3 properties.
1575          **/
1576         /* ---ifcfg-rh---
1577          * property: wep-key-flags
1578          * variable: WEP_KEY_FLAGS(+)
1579          * format: NMSettingSecretFlags
1580          * description: Password flags for KEY<i>, KEY_PASSPHRASE<i> password.
1581          * ---end---
1582          */
1583         g_object_class_install_property
1584                 (object_class, PROP_WEP_KEY_FLAGS,
1585                  g_param_spec_flags (NM_SETTING_WIRELESS_SECURITY_WEP_KEY_FLAGS, "", "",
1586                                      NM_TYPE_SETTING_SECRET_FLAGS,
1587                                      NM_SETTING_SECRET_FLAG_NONE,
1588                                      G_PARAM_READWRITE |
1589                                      G_PARAM_STATIC_STRINGS));
1590
1591         /**
1592          * NMSettingWirelessSecurity:psk:
1593          *
1594          * Pre-Shared-Key for WPA networks.  If the key is 64-characters long, it
1595          * must contain only hexadecimal characters and is interpreted as a
1596          * hexadecimal WPA key.  Otherwise, the key must be between 8 and 63 ASCII
1597          * characters (as specified in the 802.11i standard) and is interpreted as a
1598          * WPA passphrase, and is hashed to derive the actual WPA-PSK used when
1599          * connecting to the Wi-Fi network.
1600          **/
1601         /* ---ifcfg-rh---
1602          * property: psk
1603          * variable: WPA_PSK
1604          * description: Pre-Shared-Key for WPA networks.
1605          * ---end---
1606          */
1607         g_object_class_install_property
1608                 (object_class, PROP_PSK,
1609                  g_param_spec_string (NM_SETTING_WIRELESS_SECURITY_PSK, "", "",
1610                                       NULL,
1611                                       G_PARAM_READWRITE |
1612                                       NM_SETTING_PARAM_SECRET |
1613                                       G_PARAM_STATIC_STRINGS));
1614
1615         /**
1616          * NMSettingWirelessSecurity:psk-flags:
1617          *
1618          * Flags indicating how to handle the #NMSettingWirelessSecurity:psk
1619          * property.
1620          **/
1621         /* ---ifcfg-rh---
1622          * property: psk-flags
1623          * variable: WPA_PSK_FLAGS(+)
1624          * format: NMSettingSecretFlags
1625          * description: Password flags for WPA_PSK_FLAGS.
1626          * example: WPA_PSK_FLAGS=user
1627          * ---end---
1628          */
1629         g_object_class_install_property
1630                 (object_class, PROP_PSK_FLAGS,
1631                  g_param_spec_flags (NM_SETTING_WIRELESS_SECURITY_PSK_FLAGS, "", "",
1632                                      NM_TYPE_SETTING_SECRET_FLAGS,
1633                                      NM_SETTING_SECRET_FLAG_NONE,
1634                                      G_PARAM_READWRITE |
1635                                      G_PARAM_STATIC_STRINGS));
1636
1637         /**
1638          * NMSettingWirelessSecurity:leap-password:
1639          *
1640          * The login password for legacy LEAP connections (ie, key-mgmt =
1641          * "ieee8021x" and auth-alg = "leap").
1642          **/
1643         /* ---ifcfg-rh---
1644          * property: leap-password
1645          * variable: IEEE_8021X_PASSWORD(+)
1646          * description: Password for LEAP. It can also go to "key-"
1647          *  lookaside file, or it can be owned by a secret agent.
1648          * ---end---
1649          */
1650         g_object_class_install_property
1651                 (object_class, PROP_LEAP_PASSWORD,
1652                  g_param_spec_string (NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD, "", "",
1653                                       NULL,
1654                                       G_PARAM_READWRITE |
1655                                       NM_SETTING_PARAM_SECRET |
1656                                       G_PARAM_STATIC_STRINGS));
1657
1658         /**
1659          * NMSettingWirelessSecurity:leap-password-flags:
1660          *
1661          * Flags indicating how to handle the
1662          * #NMSettingWirelessSecurity:leap-password property.
1663          **/
1664         /* ---ifcfg-rh---
1665          * property: leap-password-flags
1666          * variable: IEEE_8021X_PASSWORD_FLAGS(+)
1667          * format: NMSettingSecretFlags
1668          * description: Password flags for IEEE_8021X_PASSWORD_FLAGS.
1669          * ---end---
1670          */
1671         g_object_class_install_property
1672                 (object_class, PROP_LEAP_PASSWORD_FLAGS,
1673                  g_param_spec_flags (NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD_FLAGS, "", "",
1674                                      NM_TYPE_SETTING_SECRET_FLAGS,
1675                                      NM_SETTING_SECRET_FLAG_NONE,
1676                                      G_PARAM_READWRITE |
1677                                      G_PARAM_STATIC_STRINGS));
1678
1679         /**
1680          * NMSettingWirelessSecurity:wep-key-type:
1681          *
1682          * Controls the interpretation of WEP keys.  Allowed values are
1683          * %NM_WEP_KEY_TYPE_KEY, in which case the key is either a 10- or
1684          * 26-character hexadecimal string, or a 5- or 13-character ASCII password;
1685          * or %NM_WEP_KEY_TYPE_PASSPHRASE, in which case the passphrase is provided
1686          * as a string and will be hashed using the de-facto MD5 method to derive
1687          * the actual WEP key.
1688          **/
1689         /* ---ifcfg-rh---
1690          * property: wep-key-type
1691          * variable: KEY<i> or KEY_PASSPHRASE<i>(+)
1692          * description: KEY is used for "key" type (10 or 26 hexadecimal characters,
1693          *   or 5 or 13 character string prefixed with "s:"). KEY_PASSPHRASE is used
1694          *   for WEP passphrases.
1695          * example: KEY1=s:ahoj, KEY1=0a1c45bc02, KEY_PASSPHRASE1=mysupersecretkey
1696          * ---end---
1697          */
1698         g_object_class_install_property
1699                 (object_class, PROP_WEP_KEY_TYPE,
1700                  g_param_spec_enum (NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE, "", "",
1701                                     NM_TYPE_WEP_KEY_TYPE,
1702                                     NM_WEP_KEY_TYPE_UNKNOWN,
1703                                     G_PARAM_READWRITE |
1704                                     G_PARAM_CONSTRUCT |
1705                                     G_PARAM_STATIC_STRINGS));
1706         _nm_setting_class_transform_property (parent_class,
1707                                               NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE,
1708                                               G_VARIANT_TYPE_UINT32,
1709                                               wep_key_type_to_dbus,
1710                                               NULL);
1711 }