X-Git-Url: https://git.cweiske.de/enigma2.git/blobdiff_plain/4aec730b6eb5eaac23a7eab69678ce13bd45a0a3..39650c9a5526bc2c82066e546f343b7bf8404dd9:/lib/python/Plugins/SystemPlugins/WirelessLan/plugin.py?ds=sidebyside diff --git a/lib/python/Plugins/SystemPlugins/WirelessLan/plugin.py b/lib/python/Plugins/SystemPlugins/WirelessLan/plugin.py old mode 100755 new mode 100644 index 2df5814c..290d139b --- a/lib/python/Plugins/SystemPlugins/WirelessLan/plugin.py +++ b/lib/python/Plugins/SystemPlugins/WirelessLan/plugin.py @@ -1,4 +1,4 @@ -from enigma import eTimer +from enigma import eTimer, eTPM, eEnv from Screens.Screen import Screen from Components.ActionMap import ActionMap, NumberActionMap from Components.Pixmap import Pixmap,MultiPixmap @@ -8,15 +8,19 @@ from Components.Sources.List import List from Components.MenuList import MenuList from Components.config import config, getConfigListEntry, ConfigYesNo, NoSave, ConfigSubsection, ConfigText, ConfigSelection, ConfigPassword from Components.ConfigList import ConfigListScreen -from Components.Network import Network, iNetwork +from Components.Network import iNetwork from Components.Console import Console from Plugins.Plugin import PluginDescriptor from os import system, path as os_path, listdir from Tools.Directories import resolveFilename, SCOPE_PLUGINS, SCOPE_SKIN_IMAGE from Tools.LoadPixmap import LoadPixmap +from Tools.HardwareInfo import HardwareInfo from Wlan import Wlan, wpaSupplicant, iStatus +import sha +from time import time +from os import urandom -plugin_path = "/usr/lib/enigma2/python/Plugins/SystemPlugins/WirelessLan" +plugin_path = eEnv.resolve("${libdir}/enigma2/python/Plugins/SystemPlugins/WirelessLan") list = [] list.append("WEP") @@ -122,7 +126,7 @@ class WlanStatus(Screen): if status is not None: self["BSSID"].setText(status[self.iface]["acesspoint"]) self["ESSID"].setText(status[self.iface]["essid"]) - self["quality"].setText(status[self.iface]["quality"]+"%") + self["quality"].setText(status[self.iface]["quality"]) self["signal"].setText(status[self.iface]["signal"]) self["bitrate"].setText(status[self.iface]["bitrate"]) self["enc"].setText(status[self.iface]["encryption"]) @@ -373,29 +377,96 @@ class WlanScan(Screen): return self.WlanList +def bin2long(s): + return reduce( lambda x,y:(x<<8L)+y, map(ord, s)) + +def long2bin(l): + res = "" + for byte in range(128): + res += chr((l >> (1024 - (byte + 1) * 8)) & 0xff) + return res + +def rsa_pub1024(src, mod): + return long2bin(pow(bin2long(src), 65537, bin2long(mod))) + +def decrypt_block(src, mod): + if len(src) != 128 and len(src) != 202: + return None + dest = rsa_pub1024(src[:128], mod) + hash = sha.new(dest[1:107]) + if len(src) == 202: + hash.update(src[131:192]) + result = hash.digest() + if result == dest[107:127]: + return dest + return None + +def validate_certificate(cert, key): + buf = decrypt_block(cert[8:], key) + if buf is None: + return None + return buf[36:107] + cert[139:196] + +def get_random(): + try: + xor = lambda a,b: ''.join(chr(ord(c)^ord(d)) for c,d in zip(a,b*100)) + random = urandom(8) + x = str(time())[-8:] + result = xor(random, x) + + return result + except: + return None + def WlanStatusScreenMain(session, iface): session.open(WlanStatus, iface) - def callFunction(iface): w = Wlan(iface) i = w.getWirelessInterfaces() if i: if iface in i: return WlanStatusScreenMain + else: + if iNetwork.isWirelessInterface(iface): + return WlanStatusScreenMain + else: + return None return None - def configStrings(iface): - driver = iNetwork.detectWlanModule() - print "Found WLAN-Driver:",driver - if driver in ('ralink', 'zydas'): - return " pre-up /usr/sbin/wpa_supplicant -i"+iface+" -c/etc/wpa_supplicant.conf -B -D"+driver+"\n post-down wpa_cli terminate" + hardware_info = HardwareInfo() + if hardware_info.device_name != "dm7025": + rootkey = ['\x9f', '|', '\xe4', 'G', '\xc9', '\xb4', '\xf4', '#', '&', '\xce', '\xb3', '\xfe', '\xda', '\xc9', 'U', '`', '\xd8', '\x8c', 's', 'o', '\x90', '\x9b', '\\', 'b', '\xc0', '\x89', '\xd1', '\x8c', '\x9e', 'J', 'T', '\xc5', 'X', '\xa1', '\xb8', '\x13', '5', 'E', '\x02', '\xc9', '\xb2', '\xe6', 't', '\x89', '\xde', '\xcd', '\x9d', '\x11', '\xdd', '\xc7', '\xf4', '\xe4', '\xe4', '\xbc', '\xdb', '\x9c', '\xea', '}', '\xad', '\xda', 't', 'r', '\x9b', '\xdc', '\xbc', '\x18', '3', '\xe7', '\xaf', '|', '\xae', '\x0c', '\xe3', '\xb5', '\x84', '\x8d', '\r', '\x8d', '\x9d', '2', '\xd0', '\xce', '\xd5', 'q', '\t', '\x84', 'c', '\xa8', ')', '\x99', '\xdc', '<', '"', 'x', '\xe8', '\x87', '\x8f', '\x02', ';', 'S', 'm', '\xd5', '\xf0', '\xa3', '_', '\xb7', 'T', '\t', '\xde', '\xa7', '\xf1', '\xc9', '\xae', '\x8a', '\xd7', '\xd2', '\xcf', '\xb2', '.', '\x13', '\xfb', '\xac', 'j', '\xdf', '\xb1', '\x1d', ':', '?'] + etpm = eTPM() + l2cert = etpm.getCert(eTPM.TPMD_DT_LEVEL2_CERT) + if l2cert is None: + return + l2key = validate_certificate(l2cert, rootkey) + if l2key is None: + return + l3cert = etpm.getCert(eTPM.TPMD_DT_LEVEL3_CERT) + if l3cert is None: + return + l3key = validate_certificate(l3cert, l2key) + if l3key is None: + return + rnd = get_random() + if rnd is None: + return + val = etpm.challenge(rnd) + result = decrypt_block(val, l3key) + if hardware_info.device_name == "dm7025" or result[80:88] == rnd: + driver = iNetwork.detectWlanModule(iface) else: - if config.plugins.wlan.essid.value == "hidden...": - return ' pre-up iwconfig '+iface+' essid "'+config.plugins.wlan.hiddenessid.value+'"\n pre-up /usr/sbin/wpa_supplicant -i'+iface+' -c/etc/wpa_supplicant.conf -B -dd -D'+driver+'\n post-down wpa_cli terminate' - else: - return ' pre-up iwconfig '+iface+' essid "'+config.plugins.wlan.essid.value+'"\n pre-up /usr/sbin/wpa_supplicant -i'+iface+' -c/etc/wpa_supplicant.conf -B -dd -D'+driver+'\n post-down wpa_cli terminate' + driver = 'dreambox' + print 'Using "%s" as wpa-supplicant driver' % (driver) + ret = "" + if config.plugins.wlan.essid.value == "hidden...": + ret += "\tpre-up iwconfig " + iface + " essid \"" + config.plugins.wlan.hiddenessid.value + "\" || true\n" + ret += "\tpre-up wpa_supplicant -i" + iface + " -c/etc/" + iface + "_wpa_supplicant.conf -B -dd -D" + driver + " || true\n" + ret += "\tpre-down wpa_cli -i" + iface + " terminate || true\n" + return ret def Plugins(**kwargs): - return PluginDescriptor(name=_("Wireless LAN"), description=_("Connect to a Wireless Network"), where = PluginDescriptor.WHERE_NETWORKSETUP, fnc={"ifaceSupported": callFunction, "configStrings": configStrings, "WlanPluginEntry": lambda x: "Wireless Network Configuartion..."}) + return PluginDescriptor(name=_("Wireless LAN"), description=_("Connect to a Wireless Network"), where = PluginDescriptor.WHERE_NETWORKSETUP, needsRestart = False, fnc={"ifaceSupported": callFunction, "configStrings": configStrings, "WlanPluginEntry": lambda x: "Wireless Network Configuartion..."})