/// <inheritdoc/> public async Task <XmppXElement> AuthenticateClientAsync(XmppClient xmppClient, CancellationToken cancellationToken) { var scramHelper = new ScramHelper(); var username = xmppClient.Username; #if STRINGPREP var password = StringPrep.SaslPrep(xmppClient.Password); #else var password = xmppClient.Password; #endif string msg = ToB64String(scramHelper.GenerateFirstClientMessage(username)); var authMessage = new Auth(SaslMechanism.ScramSha1, msg); var ret1 = await xmppClient.SendAsync <Failure, Challenge>(authMessage, cancellationToken); if (ret1 is Challenge) { var resp = GenerateFinalMessage(ret1 as Challenge, scramHelper, password); var ret2 = await xmppClient.SendAsync <Failure, Success>(resp, cancellationToken); return(ret2); } return(ret1); }
private NFS4StringPrep() { #if FEATURE_TYPEEXTENSIONS_GETTYPEINFO Assembly loader = typeof(NFS4StringPrep).GetTypeInfo().Assembly; #else Assembly loader = typeof(NFS4StringPrep).Assembly; #endif try { string resourcePrefix = "ICU4N.Dev.Data.TestData."; using (Stream nfscsiFile = loader.GetManifestResourceStream(resourcePrefix + "nfscsi.spp")) nfscsi = new StringPrep(nfscsiFile); using (Stream nfscssFile = loader.GetManifestResourceStream(resourcePrefix + "nfscss.spp")) nfscss = new StringPrep(nfscssFile); using (Stream nfscisFile = loader.GetManifestResourceStream(resourcePrefix + "nfscis.spp")) nfscis = new StringPrep(nfscisFile); using (Stream nfsmxpFile = loader.GetManifestResourceStream(resourcePrefix + "nfsmxp.spp")) nfsmxp = new StringPrep(nfsmxpFile); using (Stream nfsmxsFile = loader.GetManifestResourceStream(resourcePrefix + "nfsmxs.spp")) nfsmxs = new StringPrep(nfsmxsFile); } catch (IOException e) { throw new MissingManifestResourceException(e.ToString(), e); } }
static IDN() { InputStream stream = null; try { const String IDN_PROFILE = "uidna.spp"; if (System.SecurityManager != null) { stream = AccessController.doPrivileged(new PrivilegedActionAnonymousInnerClassHelper(IDN_PROFILE)); } else { stream = typeof(StringPrep).getResourceAsStream(IDN_PROFILE); } NamePrep = new StringPrep(stream); stream.Close(); } catch (IOException) { // should never reach here Debug.Assert(false); } }
private static byte[] Prepare(byte[] src, StringPrep strprep) { String s = Encoding.UTF8.GetString(src); UCharacterIterator iter = UCharacterIterator.GetInstance(s); StringBuffer @out = strprep.Prepare(iter, StringPrepOptions.Default); return(Encoding.UTF8.GetBytes(@out.ToString())); }
public static string PrepareResource(string resource) { if (String.IsNullOrEmpty(resource)) { return(null); } #if !STRINGPREP return(resource); #else return(StringPrep.ResourcePrep(resource)); #endif }
public static string PrepareServer(string server) { if (String.IsNullOrEmpty(server)) { return(null); } #if !STRINGPREP return(server.ToLower()); #else return(StringPrep.NamePrep(server)); #endif }
public void TestPrepare() { StringPrep sp = StringPrep.GetInstance(0); try { if (!(sp.Prepare("dummy", 0)).Equals("dummy")) { Errln("StringPrep.prepare(String,int) was suppose to return " + "'dummy'"); } } catch (Exception e) { Errln("StringPrep.prepare(String,int) was not suppose to return " + "an exception."); } }
public static string PrepareUser(string user) { if (String.IsNullOrEmpty(user)) { return(null); } // first Encode the user/node string tmpUser = EscapeNode(user); #if !STRINGPREP return(tmpUser.ToLower()); #else return(StringPrep.NodePrep(tmpUser)); #endif }
public void TestGetInstance() { // Tests when "if (profile < 0 || profile > MAX_PROFILE)" is true int[] neg_num_cases = { -100, -50, -10, -5, -2, -1 }; for (int i = 0; i < neg_num_cases.Length; i++) { try { StringPrep.GetInstance((StringPrepProfile)neg_num_cases[i]); Errln("StringPrep.GetInstance(int) expected an exception for " + "an invalid parameter of " + neg_num_cases[i]); } catch (Exception e) { } } StringPrepProfile[] max_profile_cases = { StringPrepProfile.Rfc4518LdapCaseInsensitive + 1, StringPrepProfile.Rfc4518LdapCaseInsensitive + 2, StringPrepProfile.Rfc4518LdapCaseInsensitive + 5, StringPrepProfile.Rfc4518LdapCaseInsensitive + 10 }; for (int i = 0; i < max_profile_cases.Length; i++) { try { StringPrep.GetInstance(max_profile_cases[i]); Errln("StringPrep.GetInstance(int) expected an exception for " + "an invalid parameter of " + max_profile_cases[i]); } catch (Exception e) { } } // Tests when "if (instance == null)", "if (stream != null)", "if (instance != null)", and "if (ref != null)" is true int[] cases = { 0, 1, (int)StringPrepProfile.Rfc4518LdapCaseInsensitive }; for (int i = 0; i < cases.Length; i++) { try { StringPrep.GetInstance((StringPrepProfile)cases[i]); } catch (Exception e) { Errln("StringPrep.GetInstance(int) did not expected an exception for " + "an valid parameter of " + cases[i]); } } }
public void TestProfiles() { String profileName = null; StringPrep sprep = null; String result = null; String src = null; String expected = null; for (int i = 0; i < testCases.Length; i++) { for (int j = 0; j < testCases[i].Length; j++) { if (j == 0) { profileName = testCases[i][j]; sprep = StringPrep.GetInstance(GetOptionFromProfileName(profileName)); } else { src = testCases[i][j]; expected = testCases[i][++j]; try { result = sprep.Prepare(src, StringPrepOptions.AllowUnassigned); if (src.StartsWith("FAIL", StringComparison.Ordinal)) { Errln("Failed: Expected error for Test[" + i + "] Profile: " + profileName); } else if (!result.Equals(expected)) { Errln("Failed: Test[" + i + "] Result string does not match expected string for StringPrep test for profile: " + profileName); } } catch (StringPrepParseException ex) { if (!src.StartsWith("FAIL", StringComparison.Ordinal)) { Errln("Failed: Test[" + i + "] StringPrep profile " + profileName + " got error: " + ex); } } } } } }
/// <summary> /// Builds a new Jid object. /// StringPrep is applied to the input string. /// </summary> /// <param name="user">XMPP User part</param> /// <param name="server">XMPP Domain part</param> /// <param name="resource">XMPP Resource part</param> public Jid(string user, string server, string resource) { #if !STRINGPREP if (user != null) { user = EscapeNode(user); m_User = user.ToLower(); } if (server != null) { m_Server = server.ToLower(); } if (resource != null) { m_Resource = resource; } #else if (user != null) { user = EscapeNode(user); m_User = StringPrep.NodePrep(user); } if (server != null) { m_Server = StringPrep.NamePrep(server); } if (resource != null) { m_Resource = StringPrep.ResourcePrep(resource); } #endif BuildJid(); }
//--------------------------------------------------------------------- // Static method //--------------------------------------------------------------------- public static IACEConverter Create(string pSchema) { IACEConverter converter = null; try { // valid? if (null != pSchema) { pSchema = pSchema.ToUpper(); } // create converter switch (pSchema) { case SCHEMA_RACE: converter = new ACEConverter(StringPrep.GetInstance(), new RaceConverter()); break; case SCHEMA_PUNYCODE: converter = new ACEConverter(StringPrep.GetInstance(), new PunyConverter()); break; default: converter = null; break; } } catch (Exception) { converter = null; } // Done return(converter); }