mirror of
https://github.com/gryf/wicd.git
synced 2025-12-20 04:48:00 +01:00
Preliminary work on wired encryption. Implemented necessary infrastructure, bugfixing to follow.
This commit is contained in:
1
encryption/templates/active_wired
Normal file
1
encryption/templates/active_wired
Normal file
@@ -0,0 +1 @@
|
|||||||
|
wired_8021x
|
||||||
16
encryption/templates/wired_8021x
Normal file
16
encryption/templates/wired_8021x
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
name = 802.1x
|
||||||
|
author = Joe MacMahon
|
||||||
|
version = 1
|
||||||
|
requre identity *Identity password *Password
|
||||||
|
protected password *Password
|
||||||
|
-----
|
||||||
|
eapol_version=1
|
||||||
|
fast_reauth=0
|
||||||
|
network={
|
||||||
|
key_mgmt=IEEE8021X
|
||||||
|
eap=PEAP
|
||||||
|
phase1="peaplabel=1"
|
||||||
|
phase2="auth=MSCHAPV2"
|
||||||
|
identity="$_IDENTITY"
|
||||||
|
password="$_PASSWORD"
|
||||||
|
}
|
||||||
121
gtk/netentry.py
121
gtk/netentry.py
@@ -236,6 +236,12 @@ class AdvancedSettingsDialog(gtk.Dialog):
|
|||||||
for w in [self.txt_dns_1, self.txt_dns_2, self.txt_dns_3,
|
for w in [self.txt_dns_1, self.txt_dns_2, self.txt_dns_3,
|
||||||
self.txt_domain, self.txt_search_dom]:
|
self.txt_domain, self.txt_search_dom]:
|
||||||
w.set_sensitive(not self.chkbox_global_dns.get_active())
|
w.set_sensitive(not self.chkbox_global_dns.get_active())
|
||||||
|
|
||||||
|
def toggle_encryption(self, widget=None):
|
||||||
|
""" Toggle the encryption combobox based on the encryption checkbox. """
|
||||||
|
active = self.chkbox_encryption.get_active()
|
||||||
|
self.vbox_encrypt_info.set_sensitive(active)
|
||||||
|
self.combo_encryption.set_sensitive(active)
|
||||||
|
|
||||||
def destroy_called(self, *args):
|
def destroy_called(self, *args):
|
||||||
""" Clean up everything. """
|
""" Clean up everything. """
|
||||||
@@ -279,11 +285,81 @@ class AdvancedSettingsDialog(gtk.Dialog):
|
|||||||
self.chkbox_use_dhcp_hostname.get_active())
|
self.chkbox_use_dhcp_hostname.get_active())
|
||||||
self.set_net_prop("dhcphostname",noneToString(self.txt_dhcp_hostname.get_text()))
|
self.set_net_prop("dhcphostname",noneToString(self.txt_dhcp_hostname.get_text()))
|
||||||
|
|
||||||
|
def change_encrypt_method(self, widget=None):
|
||||||
|
""" Load all the entries for a given encryption method. """
|
||||||
|
for z in self.vbox_encrypt_info:
|
||||||
|
z.destroy() # Remove stuff in there already
|
||||||
|
ID = self.combo_encryption.get_active()
|
||||||
|
methods = self.encrypt_types
|
||||||
|
self.encryption_info = {}
|
||||||
|
|
||||||
|
# If nothing is selected, select the first entry.
|
||||||
|
if ID == -1:
|
||||||
|
self.combo_encryption.set_active(0)
|
||||||
|
ID = 0
|
||||||
|
|
||||||
|
for type_ in ['required', 'optional']:
|
||||||
|
fields = methods[ID][type_]
|
||||||
|
for field in fields:
|
||||||
|
try:
|
||||||
|
field_text = language[field[1].lower().replace(' ','_')]
|
||||||
|
except KeyError:
|
||||||
|
field_text = field[1].replace(' ','_')
|
||||||
|
|
||||||
|
if field in methods[ID]['protected']:
|
||||||
|
box = ProtectedLabelEntry(field_text)
|
||||||
|
else:
|
||||||
|
box = LabelEntry(field_text)
|
||||||
|
|
||||||
|
self.vbox_encrypt_info.pack_start(box)
|
||||||
|
# Add the data to a dict, so that the information
|
||||||
|
# can be easily accessed by giving the name of the wanted
|
||||||
|
# data.
|
||||||
|
self.encryption_info[field[0]] = [box, type_]
|
||||||
|
|
||||||
|
if self.wired:
|
||||||
|
box.entry.set_text(noneToBlankString(
|
||||||
|
wired.GetWiredProperty(self.networkID, field[0])))
|
||||||
|
else:
|
||||||
|
box.entry.set_text(noneToBlankString(
|
||||||
|
wireless.GetWirelessProperty(self.networkID, field[0])))
|
||||||
|
self.vbox_encrypt_info.show_all()
|
||||||
|
|
||||||
|
|
||||||
class WiredSettingsDialog(AdvancedSettingsDialog):
|
class WiredSettingsDialog(AdvancedSettingsDialog):
|
||||||
def __init__(self, name):
|
def __init__(self, name):
|
||||||
""" Build the wired settings dialog. """
|
""" Build the wired settings dialog. """
|
||||||
AdvancedSettingsDialog.__init__(self, _('Wired Network'))
|
AdvancedSettingsDialog.__init__(self, _('Wired Network'))
|
||||||
|
|
||||||
|
# So we can test if we are wired or wireless (for change_encrypt_method())
|
||||||
|
self.wired = True
|
||||||
|
|
||||||
|
## This section is largely copied from WirelessSettingsDialog, but with some changes
|
||||||
|
# Set up encryption stuff
|
||||||
|
self.networkID = networkID
|
||||||
|
self.combo_encryption = gtk.combo_box_new_text()
|
||||||
|
self.chkbox_encryption = gtk.CheckButton(_('Use Encryption'))
|
||||||
|
# Make the vbox to hold the encryption stuff.
|
||||||
|
self.vbox_encrypt_info = gtk.VBox(False, 0)
|
||||||
|
self.toggle_encryption()
|
||||||
|
self.chkbox_encryption.set_active(False)
|
||||||
|
self.combo_encryption.set_sensitive(False)
|
||||||
|
self.encrypt_types = misc.LoadEncryptionMethods(wired = True)
|
||||||
|
|
||||||
|
# Build the encryption menu
|
||||||
|
for x, enc_type in enumerate(self.encrypt_types):
|
||||||
|
self.combo_encryption.append_text(enc_type['name'])
|
||||||
|
self.combo_encryption.set_active(0)
|
||||||
|
self.change_encrypt_method()
|
||||||
|
|
||||||
|
self.cvbox.pack_start(self.chkbox_encryption, False, False)
|
||||||
|
self.cvbox.pack_start(self.combo_encryption, False, False)
|
||||||
|
self.cvbox.pack_start(self.vbox_encrypt_info, False, False)
|
||||||
|
|
||||||
|
# Connect signals.
|
||||||
|
self.chkbox_encryption.connect("toggled", self.toggle_encryption)
|
||||||
|
self.combo_encryption.connect("changed", self.change_encrypt_method)
|
||||||
|
|
||||||
self.des = self.connect("destroy", self.destroy_called)
|
self.des = self.connect("destroy", self.destroy_called)
|
||||||
self.script_button.connect("clicked", self.edit_scripts)
|
self.script_button.connect("clicked", self.edit_scripts)
|
||||||
self.prof_name = name
|
self.prof_name = name
|
||||||
@@ -350,6 +426,9 @@ class WirelessSettingsDialog(AdvancedSettingsDialog):
|
|||||||
def __init__(self, networkID):
|
def __init__(self, networkID):
|
||||||
""" Build the wireless settings dialog. """
|
""" Build the wireless settings dialog. """
|
||||||
AdvancedSettingsDialog.__init__(self, wireless.GetWirelessProperty(networkID, 'essid'))
|
AdvancedSettingsDialog.__init__(self, wireless.GetWirelessProperty(networkID, 'essid'))
|
||||||
|
# So we can test if we are wired or wireless (for change_encrypt_method())
|
||||||
|
self.wired = False
|
||||||
|
|
||||||
# Set up encryption stuff
|
# Set up encryption stuff
|
||||||
self.networkID = networkID
|
self.networkID = networkID
|
||||||
self.combo_encryption = gtk.combo_box_new_text()
|
self.combo_encryption = gtk.combo_box_new_text()
|
||||||
@@ -513,48 +592,6 @@ class WirelessSettingsDialog(AdvancedSettingsDialog):
|
|||||||
def format_entry(self, networkid, label):
|
def format_entry(self, networkid, label):
|
||||||
""" Helper method for fetching/formatting wireless properties. """
|
""" Helper method for fetching/formatting wireless properties. """
|
||||||
return noneToBlankString(wireless.GetWirelessProperty(networkid, label))
|
return noneToBlankString(wireless.GetWirelessProperty(networkid, label))
|
||||||
|
|
||||||
def toggle_encryption(self, widget=None):
|
|
||||||
""" Toggle the encryption combobox based on the encryption checkbox. """
|
|
||||||
active = self.chkbox_encryption.get_active()
|
|
||||||
self.vbox_encrypt_info.set_sensitive(active)
|
|
||||||
self.combo_encryption.set_sensitive(active)
|
|
||||||
|
|
||||||
def change_encrypt_method(self, widget=None):
|
|
||||||
""" Load all the entries for a given encryption method. """
|
|
||||||
for z in self.vbox_encrypt_info:
|
|
||||||
z.destroy() # Remove stuff in there already
|
|
||||||
ID = self.combo_encryption.get_active()
|
|
||||||
methods = self.encrypt_types
|
|
||||||
self.encryption_info = {}
|
|
||||||
|
|
||||||
# If nothing is selected, select the first entry.
|
|
||||||
if ID == -1:
|
|
||||||
self.combo_encryption.set_active(0)
|
|
||||||
ID = 0
|
|
||||||
|
|
||||||
for type_ in ['required', 'optional']:
|
|
||||||
fields = methods[ID][type_]
|
|
||||||
for field in fields:
|
|
||||||
try:
|
|
||||||
field_text = language[field[1].lower().replace(' ','_')]
|
|
||||||
except KeyError:
|
|
||||||
field_text = field[1].replace(' ','_')
|
|
||||||
|
|
||||||
if field in methods[ID]['protected']:
|
|
||||||
box = ProtectedLabelEntry(field_text)
|
|
||||||
else:
|
|
||||||
box = LabelEntry(field_text)
|
|
||||||
|
|
||||||
self.vbox_encrypt_info.pack_start(box)
|
|
||||||
# Add the data to a dict, so that the information
|
|
||||||
# can be easily accessed by giving the name of the wanted
|
|
||||||
# data.
|
|
||||||
self.encryption_info[field[0]] = [box, type_]
|
|
||||||
|
|
||||||
box.entry.set_text(noneToBlankString(
|
|
||||||
wireless.GetWirelessProperty(self.networkID, field[0])))
|
|
||||||
self.vbox_encrypt_info.show_all()
|
|
||||||
|
|
||||||
|
|
||||||
class NetworkEntry(gtk.HBox):
|
class NetworkEntry(gtk.HBox):
|
||||||
|
|||||||
20
wicd/misc.py
20
wicd/misc.py
@@ -271,7 +271,10 @@ def ParseEncryption(network):
|
|||||||
"""
|
"""
|
||||||
enctemplate = open(wpath.encryption + network["enctype"])
|
enctemplate = open(wpath.encryption + network["enctype"])
|
||||||
template = enctemplate.readlines()
|
template = enctemplate.readlines()
|
||||||
config_file = "ap_scan=1\n"
|
if network.get('essid'):
|
||||||
|
config_file = "ap_scan=1\n"
|
||||||
|
else:
|
||||||
|
config_file = "ap_scan=0\n"
|
||||||
should_replace = False
|
should_replace = False
|
||||||
for index, line in enumerate(template):
|
for index, line in enumerate(template):
|
||||||
if not should_replace:
|
if not should_replace:
|
||||||
@@ -303,8 +306,11 @@ def ParseEncryption(network):
|
|||||||
|
|
||||||
# Write the data to the files then chmod them so they can't be read
|
# Write the data to the files then chmod them so they can't be read
|
||||||
# by normal users.
|
# by normal users.
|
||||||
file_loc = os.path.join(wpath.networks,
|
if network.get('bssid'):
|
||||||
network['bssid'].replace(":", "").lower())
|
file_name = network['bssid'].replace(":", "").lower()
|
||||||
|
else:
|
||||||
|
file_name = 'wired'
|
||||||
|
file_loc = os.path.join(wpath.networks, file_name)
|
||||||
f = open(file_loc, "w")
|
f = open(file_loc, "w")
|
||||||
os.chmod(file_loc, 0600)
|
os.chmod(file_loc, 0600)
|
||||||
os.chown(file_loc, 0, 0)
|
os.chown(file_loc, 0, 0)
|
||||||
@@ -313,7 +319,7 @@ def ParseEncryption(network):
|
|||||||
f.write(config_file)
|
f.write(config_file)
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
def LoadEncryptionMethods():
|
def LoadEncryptionMethods(wired = False):
|
||||||
""" Load encryption methods from configuration files
|
""" Load encryption methods from configuration files
|
||||||
|
|
||||||
Loads all the encryption methods from the template files
|
Loads all the encryption methods from the template files
|
||||||
@@ -321,8 +327,12 @@ def LoadEncryptionMethods():
|
|||||||
loaded, the template must be listed in the "active" file.
|
loaded, the template must be listed in the "active" file.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
if wired:
|
||||||
|
active_fname = "active_wired"
|
||||||
|
else:
|
||||||
|
active_fname = "active"
|
||||||
try:
|
try:
|
||||||
enctypes = open(wpath.encryption + "active","r").readlines()
|
enctypes = open(wpath.encryption + active_fname,"r").readlines()
|
||||||
except IOError, e:
|
except IOError, e:
|
||||||
print "Fatal Error: template index file is missing."
|
print "Fatal Error: template index file is missing."
|
||||||
raise IOError(e)
|
raise IOError(e)
|
||||||
|
|||||||
@@ -1148,6 +1148,10 @@ class WiredConnectThread(ConnectThread):
|
|||||||
# Bring up interface.
|
# Bring up interface.
|
||||||
self.put_iface_up(liface)
|
self.put_iface_up(liface)
|
||||||
|
|
||||||
|
# Manage encryption.
|
||||||
|
if self.network.get('encryption'):
|
||||||
|
liface.Authenticate(self.network)
|
||||||
|
|
||||||
# Set gateway, IP adresses, and DNS servers.
|
# Set gateway, IP adresses, and DNS servers.
|
||||||
self.set_broadcast_address(liface)
|
self.set_broadcast_address(liface)
|
||||||
self.set_ip_address(liface)
|
self.set_ip_address(liface)
|
||||||
|
|||||||
@@ -892,6 +892,13 @@ class BaseWiredInterface(BaseInterface):
|
|||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def Authenticate(self, network):
|
||||||
|
misc.ParseEncryption(network)
|
||||||
|
cmd = ['wpa_supplicant', '-B', '-i', self.iface, '-c',
|
||||||
|
os.path.join(wpath.networks, 'wired'),
|
||||||
|
'-Dwired']
|
||||||
|
if self.verbose: print cmd
|
||||||
|
misc.Run(cmd)
|
||||||
|
|
||||||
class BaseWirelessInterface(BaseInterface):
|
class BaseWirelessInterface(BaseInterface):
|
||||||
""" Control a wireless network interface. """
|
""" Control a wireless network interface. """
|
||||||
|
|||||||
Reference in New Issue
Block a user