public static string GetAuthInfo(Wlan.Dot11AuthAlgorithm auth, Wlan.Dot11CipherAlgorithm cipher) { string a = ""; string e = ""; if (auth == Wlan.Dot11AuthAlgorithm.IEEE80211_Open) { a = "open"; } else if (auth == Wlan.Dot11AuthAlgorithm.RSNA_PSK) { a = "WPA2PSK"; } else if (auth == Wlan.Dot11AuthAlgorithm.WPA_PSK) { a = "WPAPSK"; } if (cipher == Wlan.Dot11CipherAlgorithm.WEP) { e = "WEP"; } else if (cipher == Wlan.Dot11CipherAlgorithm.CCMP) { e = "AES"; } return("<authentication>" + a + "</authentication><encryption>" + e + "</encryption>"); }
private static string AlgorithmToString(Wlan.Dot11CipherAlgorithm algo) { switch (algo) { case Wlan.Dot11CipherAlgorithm.CCMP: return("AES"); case Wlan.Dot11CipherAlgorithm.WEP40: case Wlan.Dot11CipherAlgorithm.WEP104: case Wlan.Dot11CipherAlgorithm.WEP: return("WEP"); case Wlan.Dot11CipherAlgorithm.TKIP: return("TKIP"); case Wlan.Dot11CipherAlgorithm.None: return("None"); case Wlan.Dot11CipherAlgorithm.WPA_UseGroup: return("WPA"); default: return("Unknown"); } }
public static string getCipher(Wlan.Dot11CipherAlgorithm cipher) { string cif = string.Empty; switch (cipher.ToString()) { case "CCMP": cif = "AES"; break; case "TKIP": cif = "TKIP"; break; case "WEP": cif = "WEP"; break; } return(cif); }
/// <summary> /// Creates a readable string based on the encryption algorithm and /// the authentication method /// </summary> /// <param name="authentication">authentication used</param> /// <param name="encryption">encryption used</param> /// <returns>a string representing the security mode</returns> public static string CreateSecurityString(Wlan.Dot11AuthAlgorithm authentication, Wlan.Dot11CipherAlgorithm encryption) { String text = authentication + "-" + encryption; text = text.Replace("RSNA", "WPA2"); text = text.Replace("_PSK-CCMP", "-Personal"); text = text.Replace("_PSK-TKIP", "-Personal"); text = text.Replace("CCMP", "Enterprise"); text = text.Replace("IEEE80211_", ""); text = text.Replace("None", ""); text = text.Replace("Open", ""); text = text.Replace("WEP40", "WEP"); text = text.Replace("WEP104", "WEP"); text = text.Trim(new[] { '-' }); if (null == text || text.Equals(String.Empty)) { text = "Open"; } return(text); }
static string CipherToStringInProfile(Wlan.Dot11CipherAlgorithm algorithm) { switch (algorithm) { case Wlan.Dot11CipherAlgorithm.None: return("none"); case Wlan.Dot11CipherAlgorithm.WEP: case Wlan.Dot11CipherAlgorithm.WEP104: case Wlan.Dot11CipherAlgorithm.WEP40: return("WEP"); case Wlan.Dot11CipherAlgorithm.TKIP: return("TKIP"); case Wlan.Dot11CipherAlgorithm.CCMP: return("AES"); default: throw new Exception("Unsupported cipher algorithm: " + algorithm); } }
/// <summary> /// Create a valid Profile xml according to: http://msdn.microsoft.com/en-us/library/ms707381(v=VS.85).aspx /// </summary> /// <param name="ssid"></param> /// <param name="key"></param> /// <param name="authAlg"></param> /// <param name="encAlg"></param> /// <returns></returns> internal static string GetProfileXml(string ssid, string key, Wlan.Dot11AuthAlgorithm authAlg, Wlan.Dot11CipherAlgorithm encAlg) { WinProfileAuthenticationEnumeration?auth = null; WinProfileEncryptionEnumeration? enc = null; switch (authAlg) { case Wlan.Dot11AuthAlgorithm.IEEE80211_SharedKey: auth = WinProfileAuthenticationEnumeration.open; enc = WinProfileEncryptionEnumeration.WEP; break; case Wlan.Dot11AuthAlgorithm.WPA_PSK: auth = WinProfileAuthenticationEnumeration.WPAPSK; break; case Wlan.Dot11AuthAlgorithm.RSNA_PSK: auth = WinProfileAuthenticationEnumeration.WPA2PSK; break; } switch (encAlg) { case Wlan.Dot11CipherAlgorithm.TKIP: enc = WinProfileEncryptionEnumeration.TKIP; break; case Wlan.Dot11CipherAlgorithm.CCMP: enc = WinProfileEncryptionEnumeration.AES; break; } if (enc != null && auth != null) { return(string.Format(@"<?xml version=""1.0""?> <WLANProfile xmlns=""http://www.microsoft.com/networking/WLAN/profile/v1""> <name>{0}</name> <SSIDConfig> <SSID> <name>{0}</name> </SSID> </SSIDConfig> <connectionType>ESS</connectionType> <connectionMode>auto</connectionMode> <MSM> <security> <authEncryption> <authentication>{2}</authentication> <encryption>{3}</encryption> <useOneX>false</useOneX> </authEncryption> <sharedKey> <keyType>passPhrase</keyType> <protected>false</protected> <keyMaterial>{1}</keyMaterial> </sharedKey> </security> </MSM> </WLANProfile>", ssid, key, auth.ToString(), enc.ToString())); } else { return(null); } }
bool IsInsecureCipherAlgorithm(Wlan.Dot11CipherAlgorithm algo) { return(algo == Wlan.Dot11CipherAlgorithm.None || algo == Wlan.Dot11CipherAlgorithm.WEP40); }
public static string GenerateXmlWLAN(string profileName, string key, Wlan.Dot11AuthAlgorithm auth, Wlan.Dot11CipherAlgorithm cipher) { string mac = StringToHex(profileName); string result = ""; if (cipher == Wlan.Dot11CipherAlgorithm.WEP) { result = string.Format("<?xml version=\"1.0\"?><WLANProfile xmlns=\"http://www.microsoft.com/networking/WLAN/profile/v1\"><name>{0}</name><SSIDConfig><SSID><hex>{1}</hex><name>{0}</name></SSID></SSIDConfig><connectionType>ESS</connectionType><MSM><security><authEncryption>{2}<useOneX>false</useOneX></authEncryption><sharedKey><keyType>networkKey</keyType><protected>false</protected><keyMaterial>{3}</keyMaterial></sharedKey><keyIndex>0</keyIndex></security></MSM></WLANProfile>", profileName, mac, GetAuthInfo(auth, cipher), key); } else { result = string.Format("<?xml version=\"1.0\"?><WLANProfile xmlns=\"http://www.microsoft.com/networking/WLAN/profile/v1\"><name>{0}</name><SSIDConfig><SSID><hex>{1}</hex><name>{0}</name></SSID></SSIDConfig><connectionType>ESS</connectionType><MSM><security><authEncryption>{2}<useOneX>false</useOneX></authEncryption><sharedKey><keyType>passPhrase</keyType><protected>false</protected><keyMaterial>{3}</keyMaterial></sharedKey><keyIndex>0</keyIndex></security></MSM></WLANProfile>", profileName, mac, GetAuthInfo(auth, cipher), key); } return(result); }
public Wlan.HostedNetworkReason HostedNetworkSecuritySettings(Wlan.Dot11AuthAlgorithm Auth, Wlan.Dot11CipherAlgorithm Cipher) { Wlan.HostedNetworkReason ConfigResult; Wlan.WlanHostedNetworkSecuritySettings settings = new Wlan.WlanHostedNetworkSecuritySettings() { Dot11AuthAlgo = Auth, Dot11CipherAlgo = Cipher }; IntPtr data = Marshal.AllocHGlobal(Marshal.SizeOf(settings)); Marshal.StructureToPtr(settings, data, false); Wlan.WlanHostedNetworkSetProperty(ClientHandle, Wlan.HostedNetworkOpcode.SecuritySettings, (uint)Marshal.SizeOf(settings), data, out ConfigResult, IntPtr.Zero); return(ConfigResult); }