home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / srev13g.zip / dynpwd.rsp < prev    next >
Text File  |  1999-04-18  |  18KB  |  443 lines

  1. <!-- This is the default document/script used by the DYNPWD; the 
  2.      SRE dynamic  passwords facility.
  3.      You can customize the BODY of this,
  4.      but please note code that should NOT be modified -->
  5.  
  6.  <HTML>
  7.  <HEAD>
  8.  
  9. <!-- ****************************** BEING NON-CHANGEABLE CODE ************** -->
  10. <SCRIPT>
  11. <!--
  12.  
  13.  
  14. // DO NOT CHANGE THESE LINES (they are set dynamically!!! 
  15.     var appname="##APPNAME"          // the application that needs a dynamic password
  16.     var theip="##THEIP"              // the client's ip address
  17.     var tstamp="##TSTAMP"            // a time stamp 
  18.     var newlocation="##NEWLOCATION"  // go here on submission
  19.     var status_message="##MESSAGE"   // a status message
  20. // ----------------------------------------------------
  21.  
  22. // ------------- do NOT modify this <SCRIPT>   
  23.  /*
  24.   *  md5.jvs 1.0b 27/06/96
  25.   *
  26.   * Javascript implementation of the RSA Data Security, Inc. MD5
  27.   * Message-Digest Algorithm.
  28.   *
  29.   * Copyright (c) 1996 Henri Torgemane. All Rights Reserved.
  30.   *
  31.   * Permission to use, copy, modify, and distribute this software
  32.   * and its documentation for any purposes and without
  33.   * fee is hereby granted provided that this copyright notice
  34.   * appears in all copies. 
  35.   *
  36.   * Of course, this soft is provided "as is" without express or implied
  37.   * warranty of any kind.
  38.   */
  39.  function array(n) {
  40.    for(i=0;i<n;i++) this[i]=0;
  41.    this.length=n; }
  42.  /* Some basic logical functions had to be rewritten because of a bug in
  43.   * Javascript.. Just try to compute 0xffffffff >> 4 with it..
  44.   * Of course, these functions are slower than the original would be, but
  45.   * at least, they work!
  46.   */
  47.  function integer(n) { return n%(0xffffffff+1); }
  48.  function shr(a,b) {
  49.    a=integer(a);
  50.    b=integer(b);
  51.    if (a-0x80000000>=0) {
  52.      a=a%0x80000000;
  53.      a>>=b;
  54.      a+=0x40000000>>(b-1);   } 
  55.    else
  56.      a>>=b;
  57.    return a; }
  58.  function shl1(a) {
  59.    a=a%0x80000000;
  60.    if (a&0x40000000==0x40000000)
  61.    {     a-=0x40000000;  
  62.      a*=2;
  63.      a+=0x80000000;  }
  64.    else
  65.      a*=2;
  66.    return a; }
  67.  function shl(a,b) {
  68.    a=integer(a);
  69.    b=integer(b);
  70.    for (var i=0;i<b;i++) a=shl1(a);
  71.    return a; }
  72.  function and(a,b) {
  73.    a=integer(a);
  74.    b=integer(b);
  75.    var t1=(a-0x80000000);
  76.    var t2=(b-0x80000000);
  77.    if (t1>=0) 
  78.      if (t2>=0) 
  79.        return ((t1&t2)+0x80000000);
  80.      else
  81.        return (t1&b);
  82.    else
  83.      if (t2>=0)
  84.        return (a&t2);
  85.      else
  86.        return (a&b);   }
  87.  function or(a,b) {
  88.    a=integer(a);
  89.    b=integer(b);
  90.    var t1=(a-0x80000000);
  91.    var t2=(b-0x80000000);
  92.    if (t1>=0) 
  93.      if (t2>=0) 
  94.        return ((t1|t2)+0x80000000);
  95.      else
  96.        return ((t1|b)+0x80000000);
  97.    else
  98.      if (t2>=0)
  99.        return ((a|t2)+0x80000000);
  100.      else
  101.        return (a|b);   }
  102.  function xor(a,b) {
  103.    a=integer(a);
  104.    b=integer(b);
  105.    var t1=(a-0x80000000);
  106.    var t2=(b-0x80000000);
  107.    if (t1>=0) 
  108.      if (t2>=0) 
  109.        return (t1^t2);
  110.      else
  111.        return ((t1^b)+0x80000000);
  112.    else
  113.      if (t2>=0)
  114.        return ((a^t2)+0x80000000);
  115.      else
  116.        return (a^b);   }
  117.  function not(a) {
  118.    a=integer(a);
  119.    return (0xffffffff-a); }
  120.  /* Here begin the real algorithm */
  121.      var state = new array(4); 
  122.      var count = new array(2);
  123.          count[0] = 0;
  124.          count[1] = 0;                     
  125.      var buffer = new array(64); 
  126.      var transformBuffer = new array(16); 
  127.      var digestBits = new array(16);
  128.      var S11 = 7;     var S12 = 12;     var S13 = 17;
  129.      var S14 = 22;     var S21 = 5;     var S22 = 9;
  130.      var S23 = 14;     var S24 = 20;     var S31 = 4;
  131.      var S32 = 11;     var S33 = 16;     var S34 = 23;
  132.      var S41 = 6;     var S42 = 10;     var S43 = 15;
  133.      var S44 = 21;
  134.      function F(x,y,z) {return or(and(x,y),and(not(x),z));     }
  135.      function G(x,y,z) {return or(and(x,z),and(y,not(z)));     }
  136.      function H(x,y,z) {return xor(xor(x,y),z);     }
  137.      function I(x,y,z) {return xor(y ,or(x , not(z)));     }
  138.      function rotateLeft(a,n) {return or(shl(a, n),(shr(a,(32 - n))));     }
  139.      function FF(a,b,c,d,x,s,ac) {
  140.          a = a+F(b, c, d) + x + ac;
  141.          a = rotateLeft(a, s);
  142.          a = a+b;
  143.          return a;     }
  144.      function GG(a,b,c,d,x,s,ac) {
  145.          a = a+G(b, c, d) +x + ac;
  146.          a = rotateLeft(a, s);
  147.          a = a+b;
  148.          return a;     }
  149.      function HH(a,b,c,d,x,s,ac) {
  150.          a = a+H(b, c, d) + x + ac;
  151.          a = rotateLeft(a, s);
  152.          a = a+b;
  153.          return a;     }
  154.      function II(a,b,c,d,x,s,ac) {
  155.          a = a+I(b, c, d) + x + ac;
  156.          a = rotateLeft(a, s);
  157.          a = a+b;
  158.          return a;     }
  159.      function transform(buf,offset) { 
  160.          var a=0, b=0, c=0, d=0; 
  161.          var x = transformBuffer;
  162.          a = state[0];
  163.          b = state[1];
  164.          c = state[2];
  165.          d = state[3];
  166.          for (i = 0; i < 16; i++) {
  167.              x[i] = and(buf[i*4+offset],0xff);
  168.              for (j = 1; j < 4; j++) {
  169.                  x[i]+=shl(and(buf[i*4+j+offset] ,0xff), j * 8);      }         }
  170.          /* Round 1 */
  171.          a = FF ( a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */
  172.          d = FF ( d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */
  173.          c = FF ( c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */
  174.          b = FF ( b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */
  175.          a = FF ( a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */
  176.          d = FF ( d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */
  177.          c = FF ( c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */
  178.          b = FF ( b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */
  179.          a = FF ( a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */
  180.          d = FF ( d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */
  181.          c = FF ( c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */
  182.          b = FF ( b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */
  183.          a = FF ( a, b, c, d, x[12], S11, 0x6b901122); /* 13 */
  184.          d = FF ( d, a, b, c, x[13], S12, 0xfd987193); /* 14 */
  185.          c = FF ( c, d, a, b, x[14], S13, 0xa679438e); /* 15 */
  186.          b = FF ( b, c, d, a, x[15], S14, 0x49b40821); /* 16 */
  187.          /* Round 2 */
  188.          a = GG ( a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */
  189.          d = GG ( d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */
  190.          c = GG ( c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */
  191.          b = GG ( b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */
  192.          a = GG ( a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */
  193.          d = GG ( d, a, b, c, x[10], S22,  0x2441453); /* 22 */
  194.          c = GG ( c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */
  195.          b = GG ( b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */
  196.          a = GG ( a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */
  197.          d = GG ( d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */
  198.          c = GG ( c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */
  199.          b = GG ( b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */
  200.          a = GG ( a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */
  201.          d = GG ( d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */
  202.          c = GG ( c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */
  203.          b = GG ( b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */
  204.          /* Round 3 */
  205.          a = HH ( a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */
  206.          d = HH ( d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */
  207.          c = HH ( c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */
  208.          b = HH ( b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */
  209.          a = HH ( a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */
  210.          d = HH ( d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */
  211.          c = HH ( c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */
  212.          b = HH ( b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */
  213.          a = HH ( a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */
  214.          d = HH ( d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */
  215.          c = HH ( c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */
  216.          b = HH ( b, c, d, a, x[ 6], S34,  0x4881d05); /* 44 */
  217.          a = HH ( a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */
  218.          d = HH ( d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */
  219.          c = HH ( c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */
  220.          b = HH ( b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */
  221.          /* Round 4 */
  222.          a = II ( a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */
  223.          d = II ( d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */
  224.          c = II ( c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */
  225.          b = II ( b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */
  226.          a = II ( a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */
  227.          d = II ( d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */
  228.          c = II ( c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */
  229.          b = II ( b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */
  230.          a = II ( a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */
  231.          d = II ( d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */
  232.          c = II ( c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */
  233.          b = II ( b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */
  234.          a = II ( a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */
  235.          d = II ( d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */
  236.          c = II ( c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */
  237.          b = II ( b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */
  238.          state[0] +=a;
  239.          state[1] +=b;
  240.          state[2] +=c;
  241.          state[3] +=d;     }
  242.      function init() {
  243.          count[0]=count[1] = 0;
  244.          state[0] = 0x67452301;
  245.          state[1] = 0xefcdab89;
  246.          state[2] = 0x98badcfe;
  247.          state[3] = 0x10325476;
  248.          for (i = 0; i < digestBits.length; i++)
  249.              digestBits[i] = 0;     }
  250.      function update(b) { 
  251.          var index,i;
  252.          index = and(shr(count[0],3) , 0x3f);
  253.          if (count[0]<0xffffffff-7) 
  254.            count[0] += 8;
  255.          else {
  256.            count[1]++;
  257.            count[0]-=0xffffffff+1;
  258.            count[0]+=8;         }
  259.          buffer[index] = and(b,0xff);
  260.          if (index  >= 63) {
  261.              transform(buffer, 0);
  262.          }     }
  263.      function finish() {
  264.          var bits = new array(8);
  265.          var     padding; 
  266.          var     i=0, index=0, padLen=0;
  267.          for (i = 0; i < 4; i++) {
  268.              bits[i] = and(shr(count[0],(i * 8)), 0xff);         }
  269.          for (i = 0; i < 4; i++) {
  270.              bits[i+4]=and(shr(count[1],(i * 8)), 0xff);         }
  271.          index = and(shr(count[0], 3) ,0x3f);
  272.          padLen = (index < 56) ? (56 - index) : (120 - index);
  273.          padding = new array(64); 
  274.          padding[0] = 0x80;
  275.          for (i=0;i<padLen;i++)
  276.            update(padding[i]);
  277.          for (i=0;i<8;i++) 
  278.            update(bits[i]);
  279.          for (i = 0; i < 4; i++) {
  280.              for (j = 0; j < 4; j++) {
  281.                  digestBits[i*4+j] = and(shr(state[i], (j * 8)) , 0xff);             }
  282.          }      }
  283.  /* End of the MD5 algorithm */
  284.  function hexa(n) {
  285.   var hexa_h = "0123456789abcdef";  var hexa_c="";   var hexa_m=n;
  286.   for (hexa_i=0;hexa_i<8;hexa_i++) {
  287.     hexa_c=hexa_h.charAt(Math.abs(hexa_m)%16)+hexa_c;
  288.     hexa_m=Math.floor(hexa_m/16);  }
  289.   return hexa_c; }
  290.  var ascii="01234567890123456789012345678901" +
  291.            " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ"+
  292.            "[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
  293.  
  294.  function MD5(your_pwd)  {
  295.   var l,s,k,ka,kb,kc,kd;
  296.   init();
  297.   for (k=0;k<your_pwd.length;k++) {
  298.     l=your_pwd.charAt(k);
  299.     update(ascii.lastIndexOf(l));  }
  300.   finish();
  301.   ka=kb=kc=kd=0;
  302.   for (i=0;i<4;i++) ka+=shl(digestBits[15-i], (i*8));
  303.   for (i=4;i<8;i++) kb+=shl(digestBits[15-i], ((i-4)*8));
  304.   for (i=8;i<12;i++) kc+=shl(digestBits[15-i], ((i-8)*8));
  305.   for (i=12;i<16;i++) kd+=shl(digestBits[15-i], ((i-12)*8));
  306.   s=hexa(kd)+hexa(kc)+hexa(kb)+hexa(ka);
  307.   return s;  }
  308.  
  309.  function comp_md5(avalue,setit)
  310.    {aggx=avalue
  311.     if (setit==1){aggx=theip + '_'+ tstamp + '_' + avalue}
  312.     zaa=MD5(aggx.toUpperCase())
  313.    return zaa }
  314.  
  315.  
  316.  function byebye(aa)
  317.   {
  318.     p1=appname + "=" +tstamp + "_" + document.askmd5.session_key.value + "; PATH=/ " 
  319.     document.cookie=p1
  320.     window.location.href=newlocation
  321.     return false
  322.    }
  323.  
  324.  // -->
  325.  </SCRIPT>
  326.  
  327. <!-- ****************************** END OF NON-CHANGEABLE CODE ************** -->
  328. <!-- You can modify the remainder of the <HEAD> -->
  329.  
  330. <TITLE>Secondary logon </TITLE>
  331.  
  332. </HEAD>
  333.  
  334.  
  335. <!-- ================================================= -->
  336. <!-- You can modify the <BODY> of this document, except where noted -->
  337.  
  338. <BODY BGCOLOR="#FFFFFF">
  339.  
  340.  
  341.  
  342. <!-- Javascript required!
  343.      You can change the following if you want.
  344.      You can even convert it to HTML (and not use document.writeln)
  345.      but be sure to retain the onClick and onSubmit attributes
  346.  -->
  347. <script>
  348. document.writeln('<H2><a name="top">'+appname+': Session key (password) required</a></H2>')
  349. document.writeln('<em>' + status_message + '</em><p>')
  350. document.writeln('<FORM name="askmd5"  onSubmit="byebye() ; return false">')
  351. document.writeln(" 1) Enter your " + appname + " password:  ")
  352. document.writeln(' <INPUT type="text" name="your_pwd" value=""  size=20>')
  353. document.writeln(' <INPUT type="button" value="2) click here to generate your session key"')
  354. document.writeln('      onclick="document.askmd5.session_key.value=comp_md5(document.askmd5.your_pwd.value,1)">')
  355. document.writeln('<p> ... your <a href="#specs">session key is</a>: ')
  356. document.writeln('         <INPUT type="text" name="session_key" value="" size=35>)')
  357. document.writeln(' <br><input type="submit" value="3) then click here to return this session key to ' + appname + '">')
  358. document.writeln('</FORM>')
  359. </script>
  360.  
  361. <!-- This version of DYNPWD REQUIRES a javascript compliant browser.
  362.      It is possible to use non-javascript (but cookie compliant) browsers,
  363.      but since it would require several exchanges, we don't bother.
  364.  
  365.      You can customize the NOSCRIPT if you want.
  366. -->
  367. <noscript>
  368.    <blockquote>
  369.      Unfortunately, your browser does not support JavaScript -- 
  370.      you will not be able to use this application.
  371.     </blockquote>
  372. </noscript>
  373.  
  374.  
  375. <!-- you can safely remove or modify the following description -->
  376.  
  377. <hr>
  378. <h3><a name="specs">Technical specs </a></h3>
  379. The <tt>session key</tt> is a <em>dynamic, encrypted password</em> --
  380. it changes from day to day (and from machine to machine), and 
  381. is encrypted for safe passage over the Internet.  Use of a dynamic
  382. password, while not as secure as SSL, does solve many of the access
  383. problems associated with the standard ("basic") authentication methods
  384. used by most (http/1.0) browsers. In particular, "man in the middle" attacks
  385. (conducted by anyone who can monitor communications from you to a web site)
  386. are significantly more difficult.
  387.  
  388. <p>
  389. To return this dynamic, encrypted password to this server, you <b>must</b> be
  390. using a cookie-capable  browser that understands JavaScript; basically,
  391. NetScape 2.0 and above.
  392.  
  393. <blockquote>http/1.1 browsers and servers support "digest" authentication, which also
  394. entails the use of "dynamic, encrypted" passwords. As http/1.1 browsers become
  395. more widely adopted, the need for 3rd party solutions (such as this
  396. HTML/JavaScript/cookie approach) will disappear. </blockquote>
  397.  
  398. <h3>Implentation notes</h3>
  399. The <tt>session-key</tt>
  400. is based on a <tt>shared secret</tt> known to only the client and the server. 
  401. This need not
  402. be the same as the "logon" password required to gain access to a server's
  403. basic resource (the password entered in your browsers' username/password
  404. authentication box). In fact, since a "logon" password is transmitted without
  405. any encoding, good practice suggests that the <tt>shared secret</tt>
  406. should <b>never be used</b> as a "logon" password. 
  407. <blockquote>Many sites will use a multi-step process:<ol compact>
  408. <li>A standard ("basic") logon, where you provide a username and a "logon" password
  409. in the browsers authentication pop-up window.
  410. <li>A request for a session-key, at which point you enter the <tt>shared secret</tt>.
  411. <li>The server uses the username/password (from step 1) to lookup your <tt>shared
  412. secret</tt> (alternatively, there may be a single shared secret for all clients requesting
  413. a given resource). 
  414. <li> This shared secret is used to verify the session-key.
  415. </ol>
  416. </blockquote>
  417. <h3>The encryption method</h3>
  418. The session key is computed using an MD5 hash of the following:
  419. <menu><li>your IP-address 
  420. <li>the timestamp
  421. <li>your <tt>Shared-secret</tt> (it will be converted to upper case)
  422. </menu>
  423. In particular:<tt> session_key=md5("IP-address_timestamp_Shared-secret")</tt>
  424. <script>
  425. document.writeln('<p>For example, if:')
  426. document.writeln('<form ACTION="" name="dasample"> <menu>')
  427. document.writeln('<li>IP_Address=<tt> '+ theip + '</tt>')
  428. document.writeln('<li>Timestamp=<tt>' + tstamp + '</tt>')
  429. document.writeln('<li>Shared-secret=<tt>goose2</tt>')
  430. document.writeln('</menu>')
  431. document.writeln('then <menu>')
  432. aa=theip + '_' + tstamp + '_' + 'goose2'
  433. document.writeln('<li><tt>session_key=md5("'+aa+'")</tt>')
  434. document.writeln('<li><input type="checkbox" value=1 ')
  435. document.writeln(' onClick="document.dasample.sampkey.value=comp_md5(aa,0);return true">')
  436. document.writeln('check to compute sample <tt>session key</tt> ---> ')
  437. document.writeln('<input type="text" name="sampkey" size=24>')
  438. document.writeln('</menu></form> ')
  439. </script>
  440. <a href="#top">top</a>
  441. </body>  </HTML>
  442.  
  443.