8 class Settings(object):
9 def __init__(self
, conmap
= {}):
14 def __getitem__(self
, key
):
15 return self
.conmap
.__getitem
__(key
)
18 def __setitem__(self
, key
, value
):
19 return self
.conmap
.__setitem
__(key
, value
)
22 return self
.conmap
["connection"]["type"]
25 return self
.conmap
["connection"]["id"]
29 return self
.conmap
["802-11-wireless"]["ssid"]
32 # probably 802-3-ethernet
37 return self
.conmap
["802-11-wireless-security"]["psk"]
41 return self
.conmap
["802-11-wireless-security"]["wep-key0"]
49 return self
.conmap
[self
.Type()]["security"]
53 def isNet(self
, net_name
):
54 return self
.ID() == net_name
or self
.Ssid() == net_name
56 # FIXME check spec/NM what to censor
57 secrets
= dict.fromkeys(["wep-key0", "psk"])
60 "For GetSettings: censor secrets."
63 for n1
, v1
in self
.conmap
.iteritems():
65 for n2
, v2
in v1
.iteritems():
67 if self
.secrets
.has_key(n2
):
73 "For GetSecrets: only secrets."
82 for n1
, v1
in self
.conmap
.iteritems():
84 for n2
, v2
in v1
.iteritems():
85 print " %s: %s" % (n2
, v2
)
89 def __init__(self
, ssid
):
93 'uuid': str(uuid
.uuid1()), # new in oS 11.1
94 'type': '802-11-wireless',
97 'ssid': dbus
.ByteArray(ssid
), # TODO move to ConMap?
98 'mode': 'infrastructure',
101 super(WiFi
, self
).__init
__(conmap
)
104 def __init__(self
, ssid
, key
, hashed_key
=""):
105 "One of key, hashed_key must be present"
107 super(WiFi
, self
).__init
__(ssid
)
108 self
["802-11-wireless"]["security"] = "802-11-wireless-security"
109 self
["802-11-wireless-security"] = {}
110 self
["802-11-wireless-security"]["key-mgmt"] = "none"
111 self
["802-11-wireless-security"]["wep-tx-keyidx"] = 0
113 # http://www.mail-archive.com/networkmanager-list@gnome.org/msg07935.html
114 hashed_key
= hashlib
.md5(Wep
._elongate
(key
, 64)).hexdigest()
115 self
["802-11-wireless-security"]["wep-key0"] = hashed_key
118 def _elongate(s
, tlen
):
119 "repeat string s to target length tlen"
122 copies_needed
= int(math
.ceil(tlen
/ float(len(s
))))
123 return (s
* copies_needed
)[:tlen
]
126 def __init__(self
, ssid
, key
, hashed_key
=""):
127 "One of key, hashed_key must be present"
129 super(WiFi
, self
).__init
__(ssid
)
130 self
["802-11-wireless"]["security"] = "802-11-wireless-security"
131 self
["802-11-wireless-security"] = {}
132 self
["802-11-wireless-security"]["group"] = ["tkip", "cselfp"]
133 self
["802-11-wireless-security"]["pairwise"] = ["tkip", "ccmp"]
134 self
["802-11-wireless-security"]["key-mgmt"] = "wpa-psk"
136 hashed_key
= binascii
.b2a_hex(pbkdf2
.pbkdf2(key
, ssid
, 4096, 32))
137 self
["802-11-wireless-security"]["psk"] = hashed_key