Difference between revisions of "Authenticated Chat"

From Second Life Wiki
Jump to navigation Jump to search
(new)
 
m (<lsl> tag to <source>)
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
Here's a method of authenticated chat with shared secret.
Here's a method of authenticating chat with shared secret.




<pre>
<source lang="lsl2">
//By: Gigs Taggart
//By: Gigs Taggart
//Modified by Strife Onizuka
//Released under BSD license
//Released under BSD license
key gSetupQueryId;
integer gSetupNotecardLine;


string  gSetupNotecardName = "setup";
string  gSetupNotecardName = "setup";


string gPassword;
string gPassword;
integer gSeed;


key    gSetupQueryId;
integer gSetupNotecardLine;


//to sign a message we hash message+gSecret+llGetKey()
//to sign a message we hash message+gSecret+llGetKey()
string sign_message(string message)
string sign_message(string message)
{
{
        string hash=llMD5String(message+gPassword+(string)llGetKey(), 0);
    string hash = llMD5String(message + gPassword + (string)llGetKey(), gSeed);
        return llList2CSV([message,hash]);
    return message + hash;
}
}


//to verify a message we do all the same stuff except we get the sender's key
//to verify a message we do all the same stuff except we get the sender's key
integer verify_message(string message, key sender)
integer verify_message(string raw, key sender)
{
{
    list incoming=llCSV2List(message);
     string hash = llMD5String(llDeleteSubString(message, -32, -1) + gPassword + (string)sender, gSeed);
     string hash=llMD5String(llList2String(incoming, 0) +gPassword+(string)sender, 0);
     return llGetSubString(message, -32, -1) == hash;
     if (llList2String(incoming,1)!=hash)
        return FALSE;
    else
        return TRUE;
}
}


Line 37: Line 32:
{
{
   gSetupNotecardLine = 0;
   gSetupNotecardLine = 0;
   gSetupQueryId = llGetNotecardLine(gSetupNotecardName,gSetupNotecardLine);  
   gSetupQueryId = llGetNotecardLine(gSetupNotecardName, gSetupNotecardLine);  
}
}


Line 53: Line 48:
             if(data != EOF)
             if(data != EOF)
             {
             {
                 list tmp = llParseString2List(data, ["="], []);
                 integer split = llSubStringIndex(data, "=");
                string setting = llList2String(tmp,0);
                 if(~split)
                 if (setting == "password")
                 {
                 {
                     gPassword=llList2String(tmp,1);
                     string setting = llDeleteSubString(data, split, -1);
                    string value  = llDeleteSubString(data, 0,  split);
                    if (setting == "password")
                    {
                        gPassword = value;
                    }
                    else if(setting == "seed")
                    {
                        gSeed = (integer)value;
                    }
                 }
                 }
                   
                 gSetupQueryId = llGetNotecardLine(gSetupNotecardName, ++gSetupNotecardLine);  
                 gSetupQueryId = llGetNotecardLine(gSetupNotecardName,++gSetupNotecardLine);  
             }
             }
             else
             else
Line 82: Line 84:
     }
     }
}
}
</source>
====Notecard====
'''Name:''' "setup"
<pre>
password=secret
seed=0xdeadbeef
</pre>
</pre>


{{LSLC|Examples|Authenticated Chat}}
{{LSLC|Examples|Authenticated Chat}}

Latest revision as of 12:59, 24 January 2015

Here's a method of authenticating chat with shared secret.


//By: Gigs Taggart
//Modified by Strife Onizuka
//Released under BSD license

string  gSetupNotecardName = "setup";

string  gPassword;
integer gSeed;

key     gSetupQueryId;
integer gSetupNotecardLine;

//to sign a message we hash message+gSecret+llGetKey()
string sign_message(string message)
{
    string hash = llMD5String(message + gPassword + (string)llGetKey(), gSeed);
    return message + hash;
}

//to verify a message we do all the same stuff except we get the sender's key
integer verify_message(string raw, key sender)
{
    string hash = llMD5String(llDeleteSubString(message, -32, -1) + gPassword + (string)sender, gSeed);
    return llGetSubString(message, -32, -1) == hash;
}

readSettingsNotecard()
{
   gSetupNotecardLine = 0;
   gSetupQueryId = llGetNotecardLine(gSetupNotecardName, gSetupNotecardLine); 
}


default
{
    state_entry()
    {
         readSettingsNotecard();
    }
    dataserver(key queryId, string data)
    {
        if(queryId == gSetupQueryId) 
        {
            if(data != EOF)
            {
                integer split = llSubStringIndex(data, "=");
                if(~split)
                {
                    string setting = llDeleteSubString(data, split, -1);
                    string value   = llDeleteSubString(data, 0,  split);
                    if (setting == "password")
                    {
                        gPassword = value;
                    }
                    else if(setting == "seed")
                    {
                        gSeed = (integer)value;
                    }
                }
                gSetupQueryId = llGetNotecardLine(gSetupNotecardName, ++gSetupNotecardLine); 
            }
            else
            {
                state running;   
            }
        }
    }           
    changed(integer change)
    {
        llResetScript();
    }
}

state running
{

    changed(integer change)
    {
        llResetScript();
    }
}

Notecard

Name: "setup"

password=secret
seed=0xdeadbeef