Beispiel #1
0
            public override void Begin()
            {
                //string Request = MyJID.GetBareJID();
                //Request = Convert.ToBase64String(Encoding.UTF8.GetBytes(Request));

                // Todo: Check if Subject alt name contains a jid or many, if so we need to set the jid here (Request) otherwise empty (=).
                string AuthXML = string.Empty;

                AuthXML += "<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='EXTERNAL'>";
                AuthXML += "=";
                AuthXML += "</auth>";

                Uplink.WriteTextToSocket(AuthXML);
            }
Beispiel #2
0
            public override void Begin()
            {
                SelectedNounce = "arne";                 // Guid.NewGuid().ToString();
                string Request = "n,,n=" + MyJID.GetUsername() + ",r=" + SelectedNounce;

                /*char[] outArray = new char[1024];
                 *              int nrTotal = Convert.ToBase64CharArray(tempbuff, 0, offset, outArray, 0);
                 *              string EncodedResponse = new string(outArray, 0, nrTotal);*/

                Request = Convert.ToBase64String(Encoding.UTF8.GetBytes((Request)),
                                                 Base64FormattingOptions.None);

                string AuthXML = string.Empty;

                AuthXML += "<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='SCRAM-SHA-1'>";                // << std::endl;
                AuthXML += Request;
                AuthXML += "</auth>";

                Uplink.WriteTextToSocket(AuthXML);
            }
Beispiel #3
0
                public override void Begin()
                {
                    string ManagedString_authid  = MyJID.GetUsername();
                    string ManagedString_authzid = "";

                    byte [] tempbuff = new byte[1024];
                    int     offset   = 0;

                    byte[] authzid  = Encoding.UTF8.GetBytes(ManagedString_authzid);
                    byte[] authid   = Encoding.UTF8.GetBytes(ManagedString_authid);
                    byte[] password = Encoding.UTF8.GetBytes(Password);

                    memcpy(tempbuff, offset, authzid, authzid.Length);

                    offset            += authzid.Length;
                    tempbuff[offset++] = 0;

                    memcpy(tempbuff, offset, authid, authid.Length);
                    offset            += authid.Length;
                    tempbuff[offset++] = 0;

                    memcpy(tempbuff, offset, password, password.Length);
                    offset += password.Length;

                    char[] outArray        = new char[1024];
                    int    nrTotal         = Convert.ToBase64CharArray(tempbuff, 0, offset, outArray, 0);
                    string EncodedResponse = new string(outArray, 0, nrTotal);

                    string AuthXML = string.Empty;

                    AuthXML += "<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='PLAIN'>";                    // << std::endl;
                    AuthXML += EncodedResponse;
                    AuthXML += "</auth>";

                    //std::string blaha = AuthXML.str();
                    Uplink.WriteTextToSocket(AuthXML);
                }
Beispiel #4
0
            public override void Challenge(XElement Challenge)
            {
                //string ChallengeBase64 = "cj1hcm5lV21qejZsQkI5ZmxjUWtld09rWnNYQT09LHM9ZEVPaUhHaC9KRVRIc2xKcGZVY2FBZz09LGk9NDA5Ng=="; //Challenge.Value;
                string ChallengeBase64  = Challenge.Value;
                string DecodedChallenge = Encoding.UTF8.GetString(
                    Convert.FromBase64String(ChallengeBase64));

                string[] SplittedChallenge = DecodedChallenge.Split(',');

                Dictionary <string, string> ChallengeMap = new Dictionary <string, string>();

                foreach (string str in SplittedChallenge)
                {
                    string[] SplittedSplit = str.Split(new char[] { '=' }, 2);
                    ChallengeMap[SplittedSplit[0]] = SplittedSplit[1];
                }
                string r = ChallengeMap["r"];
                string s = ChallengeMap["s"];
                string i = ChallengeMap["i"];

                int    NrNrIterations = Convert.ToInt32(i);
                string n = MyJID.GetUsername();

                byte[] SaltBytes = new byte[1024];
                byte[] DecodedS  = Convert.FromBase64String(s);
                memcpy(SaltBytes, 0, DecodedS, DecodedS.Length);
                SaltBytes[DecodedS.Length]     = 0;
                SaltBytes[DecodedS.Length + 1] = 0;
                SaltBytes[DecodedS.Length + 2] = 0;
                SaltBytes[DecodedS.Length + 3] = 1;

                string c = "biws";


                HMACSHA1 hmacFromPassword = new HMACSHA1(Encoding.UTF8.GetBytes(Password));

                byte[] Result   = hmacFromPassword.ComputeHash(SaltBytes, 0, DecodedS.Length + 4);
                byte[] Previous = (byte[])Result.Clone();

                for (int j = 1; j < NrNrIterations; j++)
                {
                    byte[] tmp = hmacFromPassword.ComputeHash(Previous);
                    for (int k = 0; k < tmp.Length; k++)
                    {
                        Result[k]   = (byte)(Result[k] ^ tmp[k]);
                        Previous[k] = tmp[k];
                    }
                }
                HMACSHA1 hmacFromSaltedPassword = new HMACSHA1(Result);

                byte[] ClientKey = hmacFromSaltedPassword.ComputeHash(Encoding.UTF8.GetBytes("Client Key"));
                SHA1   hash      = SHA1.Create();

                byte[] StoredKey = hash.ComputeHash(ClientKey);

                string AuthMessage = string.Format("n={0},r={1},{2},c={3},r={4}",
                                                   n,
                                                   SelectedNounce,
                                                   DecodedChallenge,
                                                   c,
                                                   r);


                HMACSHA1 hmacFromStoredKey = new HMACSHA1(StoredKey);

                byte[] ClientSignature = hmacFromStoredKey.ComputeHash(Encoding.UTF8.GetBytes(AuthMessage));
                byte[] ClientProof     = new byte[ClientSignature.Length];

                for (int k = 0; k < ClientSignature.Length; k++)
                {
                    ClientProof[k] = (byte)(ClientKey[k] ^ ClientSignature[k]);
                }

                byte[] ServerKey = hmacFromSaltedPassword.ComputeHash(Encoding.UTF8.GetBytes("Server Key"));

                HMACSHA1 hmacFromServerKey = new HMACSHA1(ServerKey);

                byte[] ServerSignature = hmacFromServerKey.ComputeHash(Encoding.UTF8.GetBytes(AuthMessage));
                ServerProof = Convert.ToBase64String(ServerSignature, Base64FormattingOptions.None);

                string proof               = Convert.ToBase64String(ClientProof, Base64FormattingOptions.None);
                string InnerResponse       = string.Format("c={0},r={1},p={2}", c, r, proof);
                string Base64InnerResponse = Convert.ToBase64String(Encoding.UTF8.GetBytes(InnerResponse));
                string Response            = string.Format("<response xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>{0}</response>", Base64InnerResponse);

                Uplink.WriteTextToSocket(Response);
            }