Example #1
0
    def setEncryption(self, mode="none", username="", password="", channel="", ssid="", auth="", inner="", anon="",\
            ca_cert="", client_cert="", private_key="", private_key_passwd=""):
        have_supplicant = True
        try:
            import wpa_supplicant
        except ImportError:
            have_supplicant = False

        ifc = self.ifc

        # Disable all auth. mechanisms before try to authenticate another methods
        os.system("/usr/sbin/iwconfig %s enc off" % (ifc.name))
        if have_supplicant and wpa_supplicant.isWpaServiceUsable():
            # Stop WPA authentication
            wpa_supplicant.disableAuthentication(ifc.name)

        if mode == "wep":
            os.system("/usr/sbin/iwconfig '%s' enc restricted '%s'" %
                      (ifc.name, password))
            if channel:
                os.system("/usr/sbin/iwconfig '%s' channel %s" %
                          (ifc.name, channel))
        elif mode == "wepascii":
            os.system("/usr/sbin/iwconfig '%s' enc restricted 's:%s'" %
                      (ifc.name, password))
            if channel:
                os.system("/usr/sbin/iwconfig '%s' channel %s" %
                          (ifc.name, channel))
        elif mode == "wpa-psk":
            if not have_supplicant:
                return _(no_supplicant_msg)
            if not wpa_supplicant.startWpaService():
                fail("Unable to start WPA service")
            ret = wpa_supplicant.setWpaAuthentication(ifc.name, ssid, password)
            if not ret:
                return _(wpa_fail_msg)
        elif mode == "802.1x":
            if not have_supplicant:
                return _(no_supplicant_msg)
            if not wpa_supplicant.startWpaService():
                fail("Unable to start WPA service")

            ieee = wpa_supplicant.Wpa_EAP(ifc.name)
            ieee.ssid = ssid
            ieee.anonymous_identity = anon
            ieee.key_mgmt = "IEEE8021X"
            ieee.eap = auth
            ieee.phase2 = inner
            ieee.ca_cert = ca_cert
            ieee.client_cert = client_cert
            ieee.private_key = private_key
            ieee.private_key_passwd = private_key_passwd

            ret = ieee.authenticate(username, password)
            if not ret:
                return _(wpa_fail_msg)
        return ""
Example #2
0
    def setEncryption(self,
                      mode="none",
                      username=None,
                      password=None,
                      ssid=None):
        have_supplicant = True
        try:
            import wpa_supplicant
        except ImportError:
            have_supplicant = False

        ifc = self.ifc

        # Disable all auth. mechanisms before try to authenticate another methods
        os.system("/usr/sbin/iwconfig %s enc off" % (ifc.name))
        if have_supplicant and wpa_supplicant.isWpaServiceUsable():
            # Stop WPA authentication
            wpa_supplicant.disableAuthentication(ifc.name)

        if mode == "wep":
            os.system("/usr/sbin/iwconfig '%s' enc restricted '%s'" %
                      (ifc.name, password))
        elif mode == "wepascii":
            os.system("/usr/sbin/iwconfig '%s' enc restricted 's:%s'" %
                      (ifc.name, password))
        elif mode == "wpa-psk":
            if not have_supplicant:
                return _(no_supplicant_msg)
            if not wpa_supplicant.startWpaService():
                fail("Unable to start WPA service")
            ret = wpa_supplicant.setWpaAuthentication(ifc.name, ssid, password)
            if not ret:
                return _(wpa_fail_msg)
        elif mode == "peap-mschapv2":
            if not have_supplicant:
                return _(no_supplicant_msg)
            if not wpa_supplicant.startWpaService():
                fail("Unable to start WPA service")
            peap = wpa_supplicant.Wpa_EAP(ifc.name)
            peap.ssid = ssid
            peap.phase2 = "MSCHAPV2"
            ret = peap.authenticate(username, password)
            if not ret:
                return _(wpa_fail_msg)
        return ""