//This is a LSL implementation of the (SHA-1 algorithm used by) Amazon Mturk Account Balance Checking system //To use the script, enter your secret key and access key below, and execute the script. You will see your account //Balance on the Chat channel. //string Aws_secret_key="69UpmIewQNh+Nva4ekyPvk0P1ELBfY5z2Dpg1Qjm"; //Enter Sceret key within the quotes.. //string Aws_access_key="13324DMR90QHWWT0Y502";//Enter access key within quotes.. string AWS_ACCESS_KEY="13324DMR90QHWWT0Y502"; string AWS_SECRET_KEY="69UpmIewQNh+Nva4ekyPvk0P1ELBfY5z2Dpg1Qjm"; string AWSURL="http://mechanicalturk.amazonaws.com/onca/xml?"; string SERVICE="AWSMechanicalTurkRequester"; string OPERATION="GetAccountBalance"; integer SIGNATURECHANNEL=0; string b64pad = "="; integer chrsz = 8; //string b64_hmac_sha1(){ return binb2b64(hmacret);} list core_sha1(list x, integer len) { integer temp2; list temp=[(llList2Integer(x,(len >> 5)))|(0x80 << (24 -len % 32))]; x=llListReplaceList(x,temp,(len >> 5),(len >> 5)); temp=[]; list xx=x; temp=[len]; x=[]; for (temp2=0;temp2<=(((len + 64 >> 9) << 4) + 15);temp2++) { x+=[0]; } x=llListReplaceList(x,xx,0,llGetListLength(xx)-1); temp2=0; x=llListReplaceList(x,temp,(((len + 64 >> 9) << 4) + 15),(((len + 64 >> 9) << 4) + 15)); list w=[]; integer a = 1732584193; integer b = -271733879; integer c = -1732584194; integer d = 271733878; integer e = -1009589776; integer i=0; for (;i= 0) inn= temp2 >> (31); else inn= (temp2 & 0x7FFFFFFF) >> (31) | 1 << 0; temp= [(temp2 << 1) | inn]; //temp=[rol(temp2,1)]; } w=llListReplaceList(w,temp,j,j); temp2=0; temp2=llList2Integer(w,j); integer xy=rol(a,5); integer yy=sha1_ft(j,b,c,d); integer ttt=(((xy & 0xFFFF) + (yy & 0xFFFF))&0xFFFF)|(((xy >> 16) + (yy >> 16) + (((xy & 0xFFFF) + (yy & 0xFFFF)) >> 16))<<16 ); integer ttt2=(((e & 0xFFFF) + (temp2 & 0xFFFF))&0xFFFF)|(((e >> 16) + (temp2 >> 16) + (((e & 0xFFFF) + (temp2 & 0xFFFF)) >> 16))<<16 ); integer ttt3=sha1_kt(j); integer ttt4=(((ttt2 & 0xFFFF) + (ttt3 & 0xFFFF))&0xFFFF)|(((ttt2 >> 16) + (ttt3 >> 16) + (((ttt2 & 0xFFFF) + (ttt3 & 0xFFFF)) >> 16))<<16 ); //integer t=safe_add(safe_add(rol(a,5),sha1_ft(j,b,c,d)),safe_add(safe_add(e,temp2),sha1_kt(j))); integer t=(((ttt & 0xFFFF) + (ttt4 & 0xFFFF))&0xFFFF)|(((ttt >> 16) + (ttt4 >> 16) + (((ttt & 0xFFFF) + (ttt4 & 0xFFFF)) >> 16))<<16 ); //integer t=safe_add(ttt,ttt4); e = d; d = c; c = rol(b, 30); b = a; a = t; } a = safe_add(a, olda); b = safe_add(b, oldb); c = safe_add(c, oldc); d = safe_add(d, oldd); e = safe_add(e, olde); } temp=[]; temp=[a,b,c,d,e]; return temp; } integer sha1_ft(integer t, integer b, integer c,integer d) { integer temp2; if(t < 20) {temp2=(b & c) | ((~b) & d);} else if(t>=20 && t < 40) {temp2= b ^ c ^ d;} else if(t>=40 && t < 60) {temp2= (b & c) | (b & d) | (c & d);} else {temp2= b ^ c ^ d;} return temp2; } integer sha1_kt(integer t) { integer temp2; if (t<20) temp2= 1518500249; else if (t>=20&&t<40) temp2= 1859775393; else if (t>=40&&t<60) temp2= -1894007588; else temp2= -899497514; return temp2; } list opad; core_hmac_sha1(string keys, string data) { list bkey = str2binb(keys); if (llGetListLength(bkey)>16) bkey=core_sha1(bkey, (llStringLength(keys) * chrsz)); list ipad=[]; opad=[]; integer i; for(i=0;i<16;i++) { ipad+=[llList2Integer(bkey,i)^0x36363636]; opad+=[llList2Integer(bkey,i)^0x5C5C5C5C]; } llMessageLinked(LINK_SET,(512+(llStringLength(data)*chrsz)),llList2CSV(ipad+str2binb(data)),"00000000-0000-0000-0000-000000000001"); // list hash = core_sha1((ipad+str2binb(data)),(512+(llStringLength(data)*chrsz))); //return core_sha1(opad+hash,512+160); } integer safe_add(integer x,integer y) { //(((x & 0xFFFF) + (y & 0xFFFF))&0xFFFF)|(((x >> 16) + (y >> 16) + (((x & 0xFFFF) + (y & 0xFFFF)) >> 16))<<16); //integer lsw = (x & 0xFFFF) + (y & 0xFFFF); //integer msw = (x >> 16) + (y >> 16) + (lsw >> 16); //return (msw << 16) | (lsw & 0xFFFF); return (((x & 0xFFFF) + (y & 0xFFFF))&0xFFFF)|(((x >> 16) + (y >> 16) + (((x & 0xFFFF) + (y & 0xFFFF)) >> 16))<<16); } integer ord(string chr) { string ASCIII = " \n !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz"; if(llStringLength(chr) != 1) return -1; if(chr == " ") return 32; return llSubStringIndex(ASCIII,chr); } //integer shr(integer value, integer count) //{ // if (value >= 0) // return value >> count; // else // return (value & 0x7FFFFFFF) >> count | 1 << (31 - count); //} integer rol(integer num,integer cnt) { integer in; if (num >= 0) in= num >> (32-cnt); else in= (num & 0x7FFFFFFF) >> (32-cnt) | 1 << (cnt-1); return (num << cnt) | in; } list str2binb(string str) { list bin=[]; list temp=[]; integer temp2; integer mask= (1<>5); temp=[]; integer in; string chr=llGetSubString(str,(i/chrsz),(i/chrsz)); string ASCIII = " \n !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz"; if(llStringLength(chr) != 1) in= -1; else if(chr == " ") in= 32; else in=llSubStringIndex(ASCIII,chr); //return llSubStringIndex(ASCIII,chr); //temp2|= (ord(llGetSubString(str,(i/chrsz),(i/chrsz))) &mask)<< (32 - chrsz - i%32); temp2=temp2| (in&mask)<< (32 - chrsz - i%32); temp=[temp2]; bin=llListReplaceList(bin,temp,i>>5,i>>5); } return bin; } string binb2b64(list binarray) { string tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; string str = ""; integer i=0; for (;i<(llGetListLength(binarray)*4);i+=3) { integer triplet = (((llList2Integer(binarray,i>>2) >> 8 * (3 - i %4)) & 0xFF) << 16) | (((llList2Integer(binarray,(i+1)>>2) >> 8 * (3 - (i+1)%4)) & 0xFF) << 8 ) | ((llList2Integer(binarray,(i+2)>>2) >> 8 * (3 - (i+2)%4)) & 0xFF); integer j=0; for(;j<4;j++) { if(i * 8 + j * 6 > (llGetListLength(binarray)* 32)) str += b64pad; else str += llGetSubString(tab,(triplet >> 6*(3-j)) & 0x3F,(triplet >> 6*(3-j)) & 0x3F); } } return str; } //string ts() //{ // string nn=llGetTimestamp(); // list nnn=llParseString2List(nn,["."],[]); // list nnnn=llList2List(nnn,0,0); // string o=(string)nnnn+".000Z"; // return o; //} string whack; string timestamps; string CalculateSignature(string service,string operation) { string timestamp=""; if (timestamp=="") { string nn=llGetTimestamp(); list nnn=llParseString2List(nn,["."],[]); list nnnn=llList2List(nnn,0,0); nn=""; nn=""+(string)nnnn+".000Z"; timestamp= nn; //timestamp=ts(); } //string message = "Key: " + keys // + "\n\nService: " + service // + " \n\nOperation: " + operation // + " \n\nTimestamp: " + timestamp // + "\n\nSignature: "; core_hmac_sha1(AWS_SECRET_KEY,service+operation+timestamp); //string signature = b64_hmac_sha1 (keys, service+operation+timestamp); // whack = "http://mechanicalturk.amazonaws.com/onca/xml?" + // "Service=AWSMechanicalTurkRequester&" + // "Timestamp="+timestamp+"&"+ // "Signature="+signature+"&"+ // "AWSAccessKeyId="+Aws_access_key+"&"+ // "Operation="+operation+""+""; // llWhisper(0,whack); //return message+signature; return timestamp; } key rid; integer counter=0; default { state_entry() { timestamps= CalculateSignature(SERVICE,OPERATION); //integer p=llGetFreeMemory(); //llWhisper(0,(string)p); } http_response(key request_id, integer status, list metadata, string body) { if (request_id == rid) llWhisper(0, "Web server said: " + body); } link_message(integer sender_number, integer number, string messager, key id) { if (id=="00000000-0000-0000-0000-000000000002") {//counter++; //llWhisper(0,"1st entry"); list hash=llCSV2List(messager); messager=""; //llWhisper(0,messager+"is hash"); llMessageLinked(LINK_SET,512+160,llList2CSV(opad+hash),"00000000-0000-0000-0000-000000000003"); } if(id=="00000000-0000-0000-0000-000000000004") {//counter++; //llWhisper(0,"2nd entry"); list hmacret=llCSV2List(messager); messager=""; string signature=binb2b64(hmacret); whack = AWSURL + "Service="+SERVICE+"&" + "Timestamp="+timestamps+"&"+ "Signature="+signature+"&"+ "AWSAccessKeyId="+AWS_ACCESS_KEY+"&"+ "Operation="+OPERATION+""+""; llWhisper(SIGNATURECHANNEL,whack); // rid=llHTTPRequest(whack,[HTTP_METHOD,"Get"],""); } } }