Skip to content

Commit

Permalink
Remove not needed scheme path and fix WEP open config
Browse files Browse the repository at this point in the history
  • Loading branch information
teclator committed Jan 28, 2021
1 parent 9bcf36a commit 33700f4
Showing 1 changed file with 40 additions and 24 deletions.
Expand Up @@ -27,7 +27,6 @@ module ConnectionConfigWriters
class Wireless < Base
DEFAULT_MODE = "infrastructure".freeze
MODE = { "ad-hoc" => "ad-hoc", "master" => "ap", "managed" => "infrastructure" }.freeze
SCHEME_PATH = "file://".freeze

# @see Y2Network::ConnectionConfigWriters::Base#update_file
def update_file(conn)
Expand All @@ -39,6 +38,21 @@ def update_file(conn)
write_auth_settings(conn)
end

# Writes authentication settings
#
# This method relies in `write_*_auth_settings` methods.
#
#
# @param conn [Y2Network::ConnectionConfig::Base] Configuration to write
#
# @see #write_eap_auth_settings
# @see #write_psk_auth_settings
# @see #write_shared_auth_settings
def write_auth_settings(conn)
meth = "write_#{conn.auth_mode}_auth_settings".to_sym
send(meth, conn) if respond_to?(meth, true)
end

# Writes autentication settings for WPA-EAP networks
#
# @param conn [Y2Network::ConnectionConfig::Base] Configuration to write
Expand All @@ -52,28 +66,13 @@ def write_eap_auth_settings(conn)
section["password"] = conn.wpa_password if conn.wpa_password
section["anonymous-identity"] = conn.wpa_anonymous_identity if conn.eap_mode == "TTLS"
section["identity"] = conn.wpa_identity if conn.wpa_identity
section["ca-cert"] = File.join(SCHEME_PATH, conn.ca_cert) if conn.ca_cert
section["ca-cert"] = conn.ca_cert if conn.ca_cert

return unless conn.eap_mode == "TLS"

section["client-cert"] = File.join(SCHEME_PATH, conn.client_cert)
section["private-key"] = File.join(SCHEME_PATH, conn.client_key)
section["private-key-password"] = File.join(SCHEME_PATH, conn.client_key_password)
end

# Writes authentication settings
#
# This method relies in `write_*_auth_settings` methods.
#
#
# @param conn [Y2Network::ConnectionConfig::Base] Configuration to write
#
# @see #write_eap_auth_settings
# @see #write_psk_auth_settings
# @see #write_shared_auth_settings
def write_auth_settings(conn)
meth = "write_#{conn.auth_mode}_auth_settings".to_sym
send(meth, conn) if respond_to?(meth, true)
section["client-cert"] = conn.client_cert
section["private-key"] = conn.client_key
section["private-key-password"] = conn.client_key_password
end

# Writes autentication settings for WPA-PSK networks
Expand All @@ -88,22 +87,39 @@ def write_psk_auth_settings(conn)
# Writes autentication settings for WEP networks
#
# @param conn [Y2Network::ConnectionConfig::Base] Configuration to write
def write_shared_auth_settings(conn)
file.wifi_secutiry["auth-alg"] = "shared"
def write_wep_auth_settings(conn)
file.wifi_security["key-mgmt"] = "none"

return if (conn.keys || []).empty?

file.wifi_security["key-mgmt"] = "none"
default_key_idx = conn.default_key || 0
file.wifi_security["wep-tx-keyidx"] = default_key_idx
conn.keys.each_with_index do |v, i|
file.wifi_security["wep-key#{i}"] = v.gsub(/^[sh:]/, "")
end
passphrase_used = conn.keys[conn.default_key_idx].to_s.start_with(/h:/)
passphrase_used = conn.keys[default_key_idx].to_s.start_with(/h:/)
# see https://developer.gnome.org/libnm/stable/NMSettingWirelessSecurity.html#NMWepKeyType
# 1: Hex or ASCII, 2: 104/128-bit Passphrase
file.wifi_security["wep-key-type"] = passphrase_used ? 2 : 1
end

# Writes autentication settings for WEP networks (open auth)
#
# @param conn [Y2Network::ConnectionConfig::Base] Configuration to write
def write_open_auth_settings(conn)
file.wifi_security["auth-alg"] = "open"

write_wep_auth_settings(conn)
end

# Writes autentication settings for WEP networks (shared auth)
#
# @param conn [Y2Network::ConnectionConfig::Base] Configuration to write
def write_shared_auth_settings(conn)
file.wifi_security["auth-alg"] = "shared"

write_wep_auth_settings(conn)
end
end
end
end
Expand Down

0 comments on commit 33700f4

Please sign in to comment.