[jboss-svn-commits] JBL Code SVN: r7259 - in labs/jbosslabs/trunk/portal-extensions: forge-common/src/java forge-common/src/java/com forge-common/src/java/com/twmacinta forge-common/src/java/com/twmacinta/io forge-common/src/java/com/twmacinta/util forge-common/src/java/com/twmacinta/util/test forge-common/src/java/lib forge-common/src/java/lib/arch forge-common/src/java/lib/arch/darwin_ppc forge-common/src/java/lib/arch/linux_x86 forge-common/src/java/lib/arch/win32_x86 forge-common/src/java/org/jboss/forge/common forge-login/src/java/org/jboss/labs/login forge-login-portlet/src/java/org/jbosslabs/security forge-portal-attr/src/java/org/jboss/forge/portal

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Tue Oct 31 17:21:09 EST 2006


Author: szimano
Date: 2006-10-31 17:20:54 -0500 (Tue, 31 Oct 2006)
New Revision: 7259

Added:
   labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/com/
   labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/com/twmacinta/
   labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/com/twmacinta/io/
   labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/com/twmacinta/io/NullOutputStream.java
   labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/com/twmacinta/util/
   labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/com/twmacinta/util/MD5.c
   labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/com/twmacinta/util/MD5.h
   labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/com/twmacinta/util/MD5.java
   labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/com/twmacinta/util/MD5InputStream.java
   labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/com/twmacinta/util/MD5OutputStream.java
   labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/com/twmacinta/util/MD5State.java
   labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/com/twmacinta/util/test/
   labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/com/twmacinta/util/test/MD5OutputStreamTest.java
   labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/lib/
   labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/lib/arch/
   labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/lib/arch/darwin_ppc/
   labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/lib/arch/darwin_ppc/MD5.jnilib
   labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/lib/arch/linux_x86/
   labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/lib/arch/linux_x86/MD5.so
   labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/lib/arch/win32_x86/
   labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/lib/arch/win32_x86/MD5.dll
Modified:
   labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/org/jboss/forge/common/ForgeHelper.java
   labs/jbosslabs/trunk/portal-extensions/forge-login-portlet/src/java/org/jbosslabs/security/Constants.java
   labs/jbosslabs/trunk/portal-extensions/forge-login/src/java/org/jboss/labs/login/LabsLoginModule.java
   labs/jbosslabs/trunk/portal-extensions/forge-portal-attr/src/java/org/jboss/forge/portal/AutologinFilter.java
   labs/jbosslabs/trunk/portal-extensions/forge-portal-attr/src/java/org/jboss/forge/portal/LoginServlet.java
   labs/jbosslabs/trunk/portal-extensions/forge-portal-attr/src/java/org/jboss/forge/portal/ShowLoginPageServlet.java
Log:
md5 for cookie passes


Added: labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/com/twmacinta/io/NullOutputStream.java
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/com/twmacinta/io/NullOutputStream.java	2006-10-31 22:07:42 UTC (rev 7258)
+++ labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/com/twmacinta/io/NullOutputStream.java	2006-10-31 22:20:54 UTC (rev 7259)
@@ -0,0 +1,58 @@
+package com.twmacinta.io;
+
+import java.io.*;
+
+/**
+ * Copyright (c) 2001, 2002 by Pensamos Digital, All Rights Reserved.<p>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * <p>
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ * <p>
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * <p>
+ * This OutputStream discards all data written to it.
+ *
+ * @author Tim Macinta (twm at alum.mit.edu)
+ **/
+
+public class NullOutputStream extends OutputStream {
+
+  private boolean closed = false;
+
+  public NullOutputStream() {
+  }
+
+  public void close() {
+    this.closed = true;
+  }
+
+  public void flush() throws IOException {
+    if (this.closed) _throwClosed();
+  }
+
+  private void _throwClosed() throws IOException {
+    throw new IOException("This OutputStream has been closed");
+  }
+
+  public void write(byte[] b) throws IOException {
+    if (this.closed) _throwClosed();
+  }
+
+  public void write(byte[] b, int offset, int len) throws IOException {
+    if (this.closed) _throwClosed();
+  }
+
+  public void write(int b) throws IOException {
+    if (this.closed) _throwClosed();
+  }
+
+}


Property changes on: labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/com/twmacinta/io/NullOutputStream.java
___________________________________________________________________
Name: svn:executable
   + *

Added: labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/com/twmacinta/util/MD5.c
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/com/twmacinta/util/MD5.c	2006-10-31 22:07:42 UTC (rev 7258)
+++ labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/com/twmacinta/util/MD5.c	2006-10-31 22:20:54 UTC (rev 7259)
@@ -0,0 +1,360 @@
+/**
+ * This file provides a native method to supplement the Fast implementation
+ * of RSA's MD5 hash generator in Java JDK Beta-2 or higher.
+ * This file is Copyright (c) 2002 - 2005 Timothy W Macinta.
+ * <p>
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * <p>
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ * <p>
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * <p>
+ * See http://www.twmacinta.com/myjava/fast_md5.php for more information
+ * on this package.
+ * <p>
+ * To compile this file on Linux, the following command may be used,
+ * depending on your system:
+ * <pre>
+ *      gcc -O3 -shared -I${JAVADIR}include -I${JAVADIR}include/linux com/twmacinta/util/MD5.c -o lib/arch/linux_x86/MD5.so
+ * </pre>
+ * where ${JAVADIR} is the directory where you have installed the JDK.
+ * <p>
+ * To compile this file on Windows, the following commands may be used,
+ * depending on your system (the following should work with the MinGW
+ * distribution, and perhaps with other distributions as well):
+ * <pre>
+ *      gcc -O3 -c -I%JAVADIR%include -I%JAVADIR%include/win32 MD5.c
+ *      dllwrap --output-def MD5.def --add-stdcall-alias -o MD5.dll -s MD5.o
+ * </pre>
+ * where %JAVADIR% is the directory where you have installed the JDK.
+ * <p>
+ * To compile this file on Mac OS X, the following command may be used,
+ * depending on your system:
+ * <pre>
+ *      gcc -O3 -bundle -I/System/Library/Frameworks/JavaVM.framework/Headers -o lib/arch/darwin_ppc/MD5.jnilib -framework JavaVM com/twmacinta/util/MD5.c
+ * </pre>
+ *
+ * @author	Timothy W Macinta (twm at alum.mit.edu)
+ */
+
+//////////////////////////////////////////////
+//
+//
+
+#include <jni.h>
+#include <stdint.h>
+#include "MD5.h"
+
+/**  Determine endian-ness. **/
+#ifdef __WIN32__
+#include <sys/param.h>
+
+#else
+#ifdef __APPLE__
+#include <machine/endian.h>
+
+#else
+#include <endian.h>
+#endif
+#endif
+
+
+#ifndef __LITTLE_ENDIAN
+#define __LITTLE_ENDIAN LITTLE_ENDIAN
+#endif
+#ifndef __BYTE_ORDER
+#define __BYTE_ORDER BYTE_ORDER
+#endif
+
+
+//
+//
+//////////////////////////////////////////////
+
+#define ROTATE_LEFT_UINT32(i, shift_left) (((i) << (shift_left)) | ((i) >> (32 - (shift_left))))
+
+JNIEXPORT void JNICALL
+Java_com_twmacinta_util_MD5_Transform_1native
+(JNIEnv *env, jobject obj, jintArray state, jbyteArray buffer, jint shift, jint length) {
+  register uint32_t a;
+  register uint32_t b;
+  register uint32_t c;
+  register uint32_t d;
+  uint32_t a0, b0, c0, d0, i, buffer_index;
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+  uint32_t *x;
+#else
+  uint32_t x[16];
+#endif
+  jbyte buffer_elem[length];
+
+  /* Copy the state to local variables **/
+
+  jint *state_elem = (*env)->GetIntArrayElements(env, state, 0);
+  a0 = state_elem[0];
+  b0 = state_elem[1];
+  c0 = state_elem[2];
+  d0 = state_elem[3];
+
+  /* Copy the region to be hashed into memory on the stack **/
+
+  (*env)->GetByteArrayRegion(env, buffer, shift, length, buffer_elem);
+
+  /* Loop through the region to be hashed in chunks of 64 bytes **/
+
+  buffer_index = 0;
+  for (buffer_index = 0; buffer_index + 63 < length; buffer_index += 64) {
+
+    /* Save a copy of the state before modifications */
+
+    a = a0;
+    b = b0;
+    c = c0;
+    d = d0;
+
+    /* equivalent to Decode(buffer, shift, decode_buf); in the Java code */
+
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+    x = (uint32_t *) (buffer_elem + buffer_index);
+#else
+    x[0] = ((int) (buffer_elem[buffer_index] & 0xff)) |
+      (((int) (buffer_elem[buffer_index + 1] & 0xff)) << 8) |
+      (((int) (buffer_elem[buffer_index + 2] & 0xff)) << 16) |
+      (((int)  buffer_elem[buffer_index + 3]) << 24);
+    x[1] = ((int) (buffer_elem[buffer_index + 4] & 0xff)) |
+      (((int) (buffer_elem[buffer_index + 5] & 0xff)) << 8) |
+      (((int) (buffer_elem[buffer_index + 6] & 0xff)) << 16) |
+      (((int)  buffer_elem[buffer_index + 7]) << 24);
+    x[2] = ((int) (buffer_elem[buffer_index + 8] & 0xff)) |
+      (((int) (buffer_elem[buffer_index + 9] & 0xff)) << 8) |
+      (((int) (buffer_elem[buffer_index + 10] & 0xff)) << 16) |
+      (((int)  buffer_elem[buffer_index + 11]) << 24);
+    x[3] = ((int) (buffer_elem[buffer_index + 12] & 0xff)) |
+      (((int) (buffer_elem[buffer_index + 13] & 0xff)) << 8) |
+      (((int) (buffer_elem[buffer_index + 14] & 0xff)) << 16) |
+      (((int)  buffer_elem[buffer_index + 15]) << 24);
+    x[4] = ((int) (buffer_elem[buffer_index + 16] & 0xff)) |
+      (((int) (buffer_elem[buffer_index + 17] & 0xff)) << 8) |
+      (((int) (buffer_elem[buffer_index + 18] & 0xff)) << 16) |
+      (((int)  buffer_elem[buffer_index + 19]) << 24);
+    x[5] = ((int) (buffer_elem[buffer_index + 20] & 0xff)) |
+      (((int) (buffer_elem[buffer_index + 21] & 0xff)) << 8) |
+      (((int) (buffer_elem[buffer_index + 22] & 0xff)) << 16) |
+      (((int)  buffer_elem[buffer_index + 23]) << 24);
+    x[6] = ((int) (buffer_elem[buffer_index + 24] & 0xff)) |
+      (((int) (buffer_elem[buffer_index + 25] & 0xff)) << 8) |
+      (((int) (buffer_elem[buffer_index + 26] & 0xff)) << 16) |
+      (((int)  buffer_elem[buffer_index + 27]) << 24);
+    x[7] = ((int) (buffer_elem[buffer_index + 28] & 0xff)) |
+      (((int) (buffer_elem[buffer_index + 29] & 0xff)) << 8) |
+      (((int) (buffer_elem[buffer_index + 30] & 0xff)) << 16) |
+      (((int)  buffer_elem[buffer_index + 31]) << 24);
+    x[8] = ((int) (buffer_elem[buffer_index + 32] & 0xff)) |
+      (((int) (buffer_elem[buffer_index + 33] & 0xff)) << 8) |
+      (((int) (buffer_elem[buffer_index + 34] & 0xff)) << 16) |
+      (((int)  buffer_elem[buffer_index + 35]) << 24);
+    x[9] = ((int) (buffer_elem[buffer_index + 36] & 0xff)) |
+      (((int) (buffer_elem[buffer_index + 37] & 0xff)) << 8) |
+      (((int) (buffer_elem[buffer_index + 38] & 0xff)) << 16) |
+      (((int)  buffer_elem[buffer_index + 39]) << 24);
+    x[10] = ((int) (buffer_elem[buffer_index + 40] & 0xff)) |
+      (((int) (buffer_elem[buffer_index + 41] & 0xff)) << 8) |
+      (((int) (buffer_elem[buffer_index + 42] & 0xff)) << 16) |
+      (((int)  buffer_elem[buffer_index + 43]) << 24);
+    x[11] = ((int) (buffer_elem[buffer_index + 44] & 0xff)) |
+      (((int) (buffer_elem[buffer_index + 45] & 0xff)) << 8) |
+      (((int) (buffer_elem[buffer_index + 46] & 0xff)) << 16) |
+      (((int)  buffer_elem[buffer_index + 47]) << 24);
+    x[12] = ((int) (buffer_elem[buffer_index + 48] & 0xff)) |
+      (((int) (buffer_elem[buffer_index + 49] & 0xff)) << 8) |
+      (((int) (buffer_elem[buffer_index + 50] & 0xff)) << 16) |
+      (((int)  buffer_elem[buffer_index + 51]) << 24);
+    x[13] = ((int) (buffer_elem[buffer_index + 52] & 0xff)) |
+      (((int) (buffer_elem[buffer_index + 53] & 0xff)) << 8) |
+      (((int) (buffer_elem[buffer_index + 54] & 0xff)) << 16) |
+      (((int)  buffer_elem[buffer_index + 55]) << 24);
+    x[14] = ((int) (buffer_elem[buffer_index + 56] & 0xff)) |
+      (((int) (buffer_elem[buffer_index + 57] & 0xff)) << 8) |
+      (((int) (buffer_elem[buffer_index + 58] & 0xff)) << 16) |
+      (((int)  buffer_elem[buffer_index + 59]) << 24);
+    x[15] = ((int) (buffer_elem[buffer_index + 60] & 0xff)) |
+      (((int) (buffer_elem[buffer_index + 61] & 0xff)) << 8) |
+      (((int) (buffer_elem[buffer_index + 62] & 0xff)) << 16) |
+      (((int)  buffer_elem[buffer_index + 63]) << 24);
+#endif
+
+    /* Round 1 */
+    a += ((b & c) | (~b & d)) + x[ 0] + 0xd76aa478; /* 1 */
+    a = ROTATE_LEFT_UINT32(a, 7) + b;
+    d += ((a & b) | (~a & c)) + x[ 1] + 0xe8c7b756; /* 2 */
+    d = ROTATE_LEFT_UINT32(d, 12) + a;
+    c += ((d & a) | (~d & b)) + x[ 2] + 0x242070db; /* 3 */
+    c = ROTATE_LEFT_UINT32(c, 17) + d;
+    b += ((c & d) | (~c & a)) + x[ 3] + 0xc1bdceee; /* 4 */
+    b = ROTATE_LEFT_UINT32(b, 22) + c;
+
+    a += ((b & c) | (~b & d)) + x[ 4] + 0xf57c0faf; /* 5 */
+    a = ROTATE_LEFT_UINT32(a, 7) + b;
+    d += ((a & b) | (~a & c)) + x[ 5] + 0x4787c62a; /* 6 */
+    d = ROTATE_LEFT_UINT32(d, 12) + a;
+    c += ((d & a) | (~d & b)) + x[ 6] + 0xa8304613; /* 7 */
+    c = ROTATE_LEFT_UINT32(c, 17) + d;
+    b += ((c & d) | (~c & a)) + x[ 7] + 0xfd469501; /* 8 */
+    b = ROTATE_LEFT_UINT32(b, 22) + c;
+
+    a += ((b & c) | (~b & d)) + x[ 8] + 0x698098d8; /* 9 */
+    a = ROTATE_LEFT_UINT32(a, 7) + b;
+    d += ((a & b) | (~a & c)) + x[ 9] + 0x8b44f7af; /* 10 */
+    d = ROTATE_LEFT_UINT32(d, 12) + a;
+    c += ((d & a) | (~d & b)) + x[10] + 0xffff5bb1; /* 11 */
+    c = ROTATE_LEFT_UINT32(c, 17) + d;
+    b += ((c & d) | (~c & a)) + x[11] + 0x895cd7be; /* 12 */
+    b = ROTATE_LEFT_UINT32(b, 22) + c;
+
+    a += ((b & c) | (~b & d)) + x[12] + 0x6b901122; /* 13 */
+    a = ROTATE_LEFT_UINT32(a, 7) + b;
+    d += ((a & b) | (~a & c)) + x[13] + 0xfd987193; /* 14 */
+    d = ROTATE_LEFT_UINT32(d, 12) + a;
+    c += ((d & a) | (~d & b)) + x[14] + 0xa679438e; /* 15 */
+    c = ROTATE_LEFT_UINT32(c, 17) + d;
+    b += ((c & d) | (~c & a)) + x[15] + 0x49b40821; /* 16 */
+    b = ROTATE_LEFT_UINT32(b, 22) + c;
+    
+    
+    /* Round 2 */
+    a += ((b & d) | (c & ~d)) + x[ 1] + 0xf61e2562; /* 17 */
+    a = ROTATE_LEFT_UINT32(a, 5) + b;
+    d += ((a & c) | (b & ~c)) + x[ 6] + 0xc040b340; /* 18 */
+    d = ROTATE_LEFT_UINT32(d, 9) + a;
+    c += ((d & b) | (a & ~b)) + x[11] + 0x265e5a51; /* 19 */
+    c = ROTATE_LEFT_UINT32(c, 14) + d;
+    b += ((c & a) | (d & ~a)) + x[ 0] + 0xe9b6c7aa; /* 20 */
+    b = ROTATE_LEFT_UINT32(b, 20) + c;
+
+    a += ((b & d) | (c & ~d)) + x[ 5] + 0xd62f105d; /* 21 */
+    a = ROTATE_LEFT_UINT32(a, 5) + b;
+    d += ((a & c) | (b & ~c)) + x[10] + 0x02441453; /* 22 */
+    d = ROTATE_LEFT_UINT32(d, 9) + a;
+    c += ((d & b) | (a & ~b)) + x[15] + 0xd8a1e681; /* 23 */
+    c = ROTATE_LEFT_UINT32(c, 14) + d;
+    b += ((c & a) | (d & ~a)) + x[ 4] + 0xe7d3fbc8; /* 24 */
+    b = ROTATE_LEFT_UINT32(b, 20) + c;
+
+    a += ((b & d) | (c & ~d)) + x[ 9] + 0x21e1cde6; /* 25 */
+    a = ROTATE_LEFT_UINT32(a, 5) + b;
+    d += ((a & c) | (b & ~c)) + x[14] + 0xc33707d6; /* 26 */
+    d = ROTATE_LEFT_UINT32(d, 9) + a;
+    c += ((d & b) | (a & ~b)) + x[ 3] + 0xf4d50d87; /* 27 */
+    c = ROTATE_LEFT_UINT32(c, 14) + d;
+    b += ((c & a) | (d & ~a)) + x[ 8] + 0x455a14ed; /* 28 */
+    b = ROTATE_LEFT_UINT32(b, 20) + c;
+
+    a += ((b & d) | (c & ~d)) + x[13] + 0xa9e3e905; /* 29 */
+    a = ROTATE_LEFT_UINT32(a, 5) + b;
+    d += ((a & c) | (b & ~c)) + x[ 2] + 0xfcefa3f8; /* 30 */
+    d = ROTATE_LEFT_UINT32(d, 9) + a;
+    c += ((d & b) | (a & ~b)) + x[ 7] + 0x676f02d9; /* 31 */
+    c = ROTATE_LEFT_UINT32(c, 14) + d;
+    b += ((c & a) | (d & ~a)) + x[12] + 0x8d2a4c8a; /* 32 */
+    b = ROTATE_LEFT_UINT32(b, 20) + c;
+    
+    
+    /* Round 3 */
+    a += (b ^ c ^ d) + x[ 5] + 0xfffa3942;      /* 33 */
+    a = ROTATE_LEFT_UINT32(a, 4) + b;
+    d += (a ^ b ^ c) + x[ 8] + 0x8771f681;      /* 34 */
+    d = ROTATE_LEFT_UINT32(d, 11) + a;
+    c += (d ^ a ^ b) + x[11] + 0x6d9d6122;      /* 35 */
+    c = ROTATE_LEFT_UINT32(c, 16) + d;
+    b += (c ^ d ^ a) + x[14] + 0xfde5380c;      /* 36 */
+    b = ROTATE_LEFT_UINT32(b, 23) + c;
+    
+    a += (b ^ c ^ d) + x[ 1] + 0xa4beea44;      /* 37 */
+    a = ROTATE_LEFT_UINT32(a, 4) + b;
+    d += (a ^ b ^ c) + x[ 4] + 0x4bdecfa9;      /* 38 */
+    d = ROTATE_LEFT_UINT32(d, 11) + a;
+    c += (d ^ a ^ b) + x[ 7] + 0xf6bb4b60;      /* 39 */
+    c = ROTATE_LEFT_UINT32(c, 16) + d;
+    b += (c ^ d ^ a) + x[10] + 0xbebfbc70;      /* 40 */
+    b = ROTATE_LEFT_UINT32(b, 23) + c;
+    
+    a += (b ^ c ^ d) + x[13] + 0x289b7ec6;      /* 41 */
+    a = ROTATE_LEFT_UINT32(a, 4) + b;
+    d += (a ^ b ^ c) + x[ 0] + 0xeaa127fa;      /* 42 */
+    d = ROTATE_LEFT_UINT32(d, 11) + a;
+    c += (d ^ a ^ b) + x[ 3] + 0xd4ef3085;      /* 43 */
+    c = ROTATE_LEFT_UINT32(c, 16) + d;
+    b += (c ^ d ^ a) + x[ 6] + 0x04881d05;      /* 44 */
+    b = ROTATE_LEFT_UINT32(b, 23) + c;
+    
+    a += (b ^ c ^ d) + x[ 9] + 0xd9d4d039;      /* 33 */
+    a = ROTATE_LEFT_UINT32(a, 4) + b;
+    d += (a ^ b ^ c) + x[12] + 0xe6db99e5;      /* 34 */
+    d = ROTATE_LEFT_UINT32(d, 11) + a;
+    c += (d ^ a ^ b) + x[15] + 0x1fa27cf8;      /* 35 */
+    c = ROTATE_LEFT_UINT32(c, 16) + d;
+    b += (c ^ d ^ a) + x[ 2] + 0xc4ac5665;      /* 36 */
+    b = ROTATE_LEFT_UINT32(b, 23) + c;
+    
+
+    /* Round 4 */
+    a += (c ^ (b | ~d)) + x[ 0] + 0xf4292244; /* 49 */
+    a = ROTATE_LEFT_UINT32(a, 6) + b;
+    d += (b ^ (a | ~c)) + x[ 7] + 0x432aff97; /* 50 */
+    d = ROTATE_LEFT_UINT32(d, 10) + a;
+    c += (a ^ (d | ~b)) + x[14] + 0xab9423a7; /* 51 */
+    c = ROTATE_LEFT_UINT32(c, 15) + d;
+    b += (d ^ (c | ~a)) + x[ 5] + 0xfc93a039; /* 52 */
+    b = ROTATE_LEFT_UINT32(b, 21) + c;
+
+    a += (c ^ (b | ~d)) + x[12] + 0x655b59c3; /* 53 */
+    a = ROTATE_LEFT_UINT32(a, 6) + b;
+    d += (b ^ (a | ~c)) + x[ 3] + 0x8f0ccc92; /* 54 */
+    d = ROTATE_LEFT_UINT32(d, 10) + a;
+    c += (a ^ (d | ~b)) + x[10] + 0xffeff47d; /* 55 */
+    c = ROTATE_LEFT_UINT32(c, 15) + d;
+    b += (d ^ (c | ~a)) + x[ 1] + 0x85845dd1; /* 56 */
+    b = ROTATE_LEFT_UINT32(b, 21) + c;
+
+    a += (c ^ (b | ~d)) + x[ 8] + 0x6fa87e4f; /* 57 */
+    a = ROTATE_LEFT_UINT32(a, 6) + b;
+    d += (b ^ (a | ~c)) + x[15] + 0xfe2ce6e0; /* 58 */
+    d = ROTATE_LEFT_UINT32(d, 10) + a;
+    c += (a ^ (d | ~b)) + x[ 6] + 0xa3014314; /* 59 */
+    c = ROTATE_LEFT_UINT32(c, 15) + d;
+    b += (d ^ (c | ~a)) + x[13] + 0x4e0811a1; /* 60 */
+    b = ROTATE_LEFT_UINT32(b, 21) + c;
+
+    a += (c ^ (b | ~d)) + x[ 4] + 0xf7537e82; /* 61 */
+    a = ROTATE_LEFT_UINT32(a, 6) + b;
+    d += (b ^ (a | ~c)) + x[11] + 0xbd3af235; /* 62 */
+    d = ROTATE_LEFT_UINT32(d, 10) + a;
+    c += (a ^ (d | ~b)) + x[ 2] + 0x2ad7d2bb; /* 63 */
+    c = ROTATE_LEFT_UINT32(c, 15) + d;
+    b += (d ^ (c | ~a)) + x[ 9] + 0xeb86d391; /* 64 */
+    b = ROTATE_LEFT_UINT32(b, 21) + c;
+
+    /* update the state */
+    
+    a0 += a;
+    b0 += b;
+    c0 += c;
+    d0 += d;
+  }
+
+  /* update the state array */
+  
+  state_elem[0] = a0;
+  state_elem[1] = b0;
+  state_elem[2] = c0;
+  state_elem[3] = d0;
+  (*env)->ReleaseIntArrayElements(env, state, state_elem, 0);
+}


Property changes on: labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/com/twmacinta/util/MD5.c
___________________________________________________________________
Name: svn:executable
   + *

Added: labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/com/twmacinta/util/MD5.h
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/com/twmacinta/util/MD5.h	2006-10-31 22:07:42 UTC (rev 7258)
+++ labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/com/twmacinta/util/MD5.h	2006-10-31 22:20:54 UTC (rev 7259)
@@ -0,0 +1,25 @@
+/* DO NOT EDIT THIS FILE - it is machine generated */
+#include <jni.h>
+/* Header for class com_twmacinta_util_MD5 */
+
+#ifndef _Included_com_twmacinta_util_MD5
+#define _Included_com_twmacinta_util_MD5
+#ifdef __cplusplus
+extern "C" {
+#endif
+/* Inaccessible static: padding */
+/* Inaccessible static: native_lib_loaded */
+/* Inaccessible static: native_lib_init_pending */
+/* Inaccessible static: HEX_CHARS */
+/*
+ * Class:     com_twmacinta_util_MD5
+ * Method:    Transform_native
+ * Signature: ([I[BII)V
+ */
+JNIEXPORT void JNICALL Java_com_twmacinta_util_MD5_Transform_1native
+  (JNIEnv *, jobject, jintArray, jbyteArray, jint, jint);
+
+#ifdef __cplusplus
+}
+#endif
+#endif


Property changes on: labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/com/twmacinta/util/MD5.h
___________________________________________________________________
Name: svn:executable
   + *

Added: labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/com/twmacinta/util/MD5.java
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/com/twmacinta/util/MD5.java	2006-10-31 22:07:42 UTC (rev 7258)
+++ labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/com/twmacinta/util/MD5.java	2006-10-31 22:20:54 UTC (rev 7259)
@@ -0,0 +1,796 @@
+package com.twmacinta.util;
+
+import java.io.*;
+
+/**
+ * Fast implementation of RSA's MD5 hash generator in Java JDK Beta-2 or higher.
+ * <p>
+ * Originally written by Santeri Paavolainen, Helsinki Finland 1996.<br>
+ * (c) Santeri Paavolainen, Helsinki Finland 1996<br>
+ * Many changes Copyright (c) 2002 - 2005 Timothy W Macinta<br>
+ * <p>
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * <p>
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ * <p>
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * <p>
+ * See http://www.twmacinta.com/myjava/fast_md5.php for more information
+ * on this file and the related files.
+ * <p>
+ * This was originally a rather straight re-implementation of the
+ * reference implementation given in RFC1321 by RSA.  It passes the MD5
+ * test suite as defined in RFC1321.
+ * <p>
+ * Many optimizations made by Timothy W Macinta.  Reduced time to checksum a
+ * test file in Java alone to roughly half the time taken compared with
+ * java.security.MessageDigest (within an intepretter).  Also added an
+ * optional native method to reduce the time even further.
+ * See http://www.twmacinta.com/myjava/fast_md5.php for further information
+ * on the time improvements achieved.
+ * <p>
+ * Some bug fixes also made by Timothy W Macinta.
+ * <p>
+ * Please note: I (Timothy Macinta) have put this code in the
+ * com.twmacinta.util package only because it came without a package.  I
+ * was not the the original author of the code, although I did
+ * optimize it (substantially) and fix some bugs.
+ * <p>
+ * This Java class has been derived from the RSA Data Security, Inc. MD5 
+ * Message-Digest Algorithm and its reference implementation.
+ * <p>
+ * This class will attempt to use a native method to quickly compute
+ * checksums when the appropriate native library is available.  On Linux,
+ * this library should be named "MD5.so" and on Windows it should be
+ * named "MD5.dll".  The code will attempt to locate the library in the
+ * following locations in the order given:
+ *
+ * <ol>
+ *   <li>The path specified by the system property
+ *       "com.twmacinta.util.MD5.NATIVE_LIB_FILE"
+ *        (be sure to include "MD5.so" or "MD5.dll"
+ *        as appropriate at the end of the path).
+ *   <li>A platform specific directory beneath the "lib/arch/" directory.
+ *       On Linux for x86, this is "lib/arch/linux_x86/".  On Windows for
+ *       x86, this is "lib/arch/win32_x86/".
+ *   <li>Within the "lib/" directory.
+ *   <li>Within the current directory.
+ * </ol>
+ *
+ * <p>
+ * If the library is not found, the code will fall back to the default
+ * (slower) Java code.
+ * <p>
+ * As a side effect of having the code search for the native library,
+ * SecurityExceptions might be thrown on JVMs that have a restrictive
+ * SecurityManager.  The initialization code attempts to silently discard
+ * these exceptions and continue, but many SecurityManagers will
+ * attempt to notify the user directly of all SecurityExceptions thrown.
+ * Consequently, the code has provisions for skipping the search for
+ * the native library.  Any of these provisions may be used to skip the
+ * search as long as they are performed <i>before</i> the first
+ * instance of a com.twmacinta.util.MD5 object is constructed (note that
+ * the convenience stream objects will implicitly create an MD5 object).
+ * <p>
+ * The first option is to set the system property
+ * "com.twmacinta.util.MD5.NO_NATIVE_LIB" to "true" or "1".
+ * Unfortunately, SecurityManagers may also choose to disallow system
+ * property setting, so this won't be of use in all cases.
+ * <p>
+ * The second option is to call
+ * com.twmacinta.util.MD5.initNativeLibrary(true) before any MD5 objects
+ * are constructed.
+ *
+ * @author	Santeri Paavolainen <sjpaavol at cc.helsinki.fi>
+ * @author	Timothy W Macinta (twm at alum.mit.edu) (optimizations and bug fixes)
+ */
+
+public class MD5 {
+  /**
+   * MD5 state
+   */
+  MD5State	state;
+ 
+  /**
+   * If Final() has been called, finals is set to the current finals
+   * state. Any Update() causes this to be set to null.
+   */
+  MD5State 	finals;
+
+  /** 
+   * Padding for Final()
+   */
+  static byte	padding[] = {
+    (byte) 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
+    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
+    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+  };
+
+  private static boolean native_lib_loaded = false;
+  private static boolean native_lib_init_pending = true;
+  
+  /**
+   * Initialize MD5 internal state (object can be reused just by
+   * calling Init() after every Final()
+   */
+  public synchronized void Init () {
+    state = new MD5State();
+    finals = null;
+  }
+
+  /**
+   * Class constructor
+   */
+  public MD5 () {
+    if (native_lib_init_pending) _initNativeLibrary();
+    this.Init();
+  }
+
+  /**
+   * Initialize class, and update hash with ob.toString()
+   *
+   * @param	ob	Object, ob.toString() is used to update hash
+   *			after initialization
+   */
+  public MD5 (Object ob) {
+    this();
+    Update(ob.toString());
+  }
+
+  private void Decode (byte buffer[], int shift, int[] out) {
+    /*len += shift;
+    for (int i = 0; shift < len; i++, shift += 4) {
+      out[i] = ((int) (buffer[shift] & 0xff)) |
+	(((int) (buffer[shift + 1] & 0xff)) << 8) |
+	(((int) (buffer[shift + 2] & 0xff)) << 16) |
+	(((int)  buffer[shift + 3]) << 24);
+    }*/
+
+    // unrolled loop (original loop shown above)
+
+    out[0] = ((int) (buffer[shift] & 0xff)) |
+      (((int) (buffer[shift + 1] & 0xff)) << 8) |
+      (((int) (buffer[shift + 2] & 0xff)) << 16) |
+      (((int)  buffer[shift + 3]) << 24);
+    out[1] = ((int) (buffer[shift + 4] & 0xff)) |
+      (((int) (buffer[shift + 5] & 0xff)) << 8) |
+      (((int) (buffer[shift + 6] & 0xff)) << 16) |
+      (((int)  buffer[shift + 7]) << 24);
+    out[2] = ((int) (buffer[shift + 8] & 0xff)) |
+      (((int) (buffer[shift + 9] & 0xff)) << 8) |
+      (((int) (buffer[shift + 10] & 0xff)) << 16) |
+      (((int)  buffer[shift + 11]) << 24);
+    out[3] = ((int) (buffer[shift + 12] & 0xff)) |
+      (((int) (buffer[shift + 13] & 0xff)) << 8) |
+      (((int) (buffer[shift + 14] & 0xff)) << 16) |
+      (((int)  buffer[shift + 15]) << 24);
+    out[4] = ((int) (buffer[shift + 16] & 0xff)) |
+      (((int) (buffer[shift + 17] & 0xff)) << 8) |
+      (((int) (buffer[shift + 18] & 0xff)) << 16) |
+      (((int)  buffer[shift + 19]) << 24);
+    out[5] = ((int) (buffer[shift + 20] & 0xff)) |
+      (((int) (buffer[shift + 21] & 0xff)) << 8) |
+      (((int) (buffer[shift + 22] & 0xff)) << 16) |
+      (((int)  buffer[shift + 23]) << 24);
+    out[6] = ((int) (buffer[shift + 24] & 0xff)) |
+      (((int) (buffer[shift + 25] & 0xff)) << 8) |
+      (((int) (buffer[shift + 26] & 0xff)) << 16) |
+      (((int)  buffer[shift + 27]) << 24);
+    out[7] = ((int) (buffer[shift + 28] & 0xff)) |
+      (((int) (buffer[shift + 29] & 0xff)) << 8) |
+      (((int) (buffer[shift + 30] & 0xff)) << 16) |
+      (((int)  buffer[shift + 31]) << 24);
+    out[8] = ((int) (buffer[shift + 32] & 0xff)) |
+      (((int) (buffer[shift + 33] & 0xff)) << 8) |
+      (((int) (buffer[shift + 34] & 0xff)) << 16) |
+      (((int)  buffer[shift + 35]) << 24);
+    out[9] = ((int) (buffer[shift + 36] & 0xff)) |
+      (((int) (buffer[shift + 37] & 0xff)) << 8) |
+      (((int) (buffer[shift + 38] & 0xff)) << 16) |
+      (((int)  buffer[shift + 39]) << 24);
+    out[10] = ((int) (buffer[shift + 40] & 0xff)) |
+      (((int) (buffer[shift + 41] & 0xff)) << 8) |
+      (((int) (buffer[shift + 42] & 0xff)) << 16) |
+      (((int)  buffer[shift + 43]) << 24);
+    out[11] = ((int) (buffer[shift + 44] & 0xff)) |
+      (((int) (buffer[shift + 45] & 0xff)) << 8) |
+      (((int) (buffer[shift + 46] & 0xff)) << 16) |
+      (((int)  buffer[shift + 47]) << 24);
+    out[12] = ((int) (buffer[shift + 48] & 0xff)) |
+      (((int) (buffer[shift + 49] & 0xff)) << 8) |
+      (((int) (buffer[shift + 50] & 0xff)) << 16) |
+      (((int)  buffer[shift + 51]) << 24);
+    out[13] = ((int) (buffer[shift + 52] & 0xff)) |
+      (((int) (buffer[shift + 53] & 0xff)) << 8) |
+      (((int) (buffer[shift + 54] & 0xff)) << 16) |
+      (((int)  buffer[shift + 55]) << 24);
+    out[14] = ((int) (buffer[shift + 56] & 0xff)) |
+      (((int) (buffer[shift + 57] & 0xff)) << 8) |
+      (((int) (buffer[shift + 58] & 0xff)) << 16) |
+      (((int)  buffer[shift + 59]) << 24);
+    out[15] = ((int) (buffer[shift + 60] & 0xff)) |
+      (((int) (buffer[shift + 61] & 0xff)) << 8) |
+      (((int) (buffer[shift + 62] & 0xff)) << 16) |
+      (((int)  buffer[shift + 63]) << 24);
+  }
+
+  private native void Transform_native (int[] state, byte buffer[], int shift, int length);
+
+  private void Transform (MD5State state, byte buffer[], int shift, int[] decode_buf) {
+    int	
+      a = state.state[0],
+      b = state.state[1],
+      c = state.state[2],
+      d = state.state[3],
+      x[] = decode_buf;
+
+    Decode(buffer, shift, decode_buf);
+    
+    /* Round 1 */
+    a += ((b & c) | (~b & d)) + x[ 0] + 0xd76aa478; /* 1 */
+    a = ((a << 7) | (a >>> 25)) + b;
+    d += ((a & b) | (~a & c)) + x[ 1] + 0xe8c7b756; /* 2 */
+    d = ((d << 12) | (d >>> 20)) + a;
+    c += ((d & a) | (~d & b)) + x[ 2] + 0x242070db; /* 3 */
+    c = ((c << 17) | (c >>> 15)) + d;
+    b += ((c & d) | (~c & a)) + x[ 3] + 0xc1bdceee; /* 4 */
+    b = ((b << 22) | (b >>> 10)) + c;
+
+    a += ((b & c) | (~b & d)) + x[ 4] + 0xf57c0faf; /* 5 */
+    a = ((a << 7) | (a >>> 25)) + b;
+    d += ((a & b) | (~a & c)) + x[ 5] + 0x4787c62a; /* 6 */
+    d = ((d << 12) | (d >>> 20)) + a;
+    c += ((d & a) | (~d & b)) + x[ 6] + 0xa8304613; /* 7 */
+    c = ((c << 17) | (c >>> 15)) + d;
+    b += ((c & d) | (~c & a)) + x[ 7] + 0xfd469501; /* 8 */
+    b = ((b << 22) | (b >>> 10)) + c;
+
+    a += ((b & c) | (~b & d)) + x[ 8] + 0x698098d8; /* 9 */
+    a = ((a << 7) | (a >>> 25)) + b;
+    d += ((a & b) | (~a & c)) + x[ 9] + 0x8b44f7af; /* 10 */
+    d = ((d << 12) | (d >>> 20)) + a;
+    c += ((d & a) | (~d & b)) + x[10] + 0xffff5bb1; /* 11 */
+    c = ((c << 17) | (c >>> 15)) + d;
+    b += ((c & d) | (~c & a)) + x[11] + 0x895cd7be; /* 12 */
+    b = ((b << 22) | (b >>> 10)) + c;
+
+    a += ((b & c) | (~b & d)) + x[12] + 0x6b901122; /* 13 */
+    a = ((a << 7) | (a >>> 25)) + b;
+    d += ((a & b) | (~a & c)) + x[13] + 0xfd987193; /* 14 */
+    d = ((d << 12) | (d >>> 20)) + a;
+    c += ((d & a) | (~d & b)) + x[14] + 0xa679438e; /* 15 */
+    c = ((c << 17) | (c >>> 15)) + d;
+    b += ((c & d) | (~c & a)) + x[15] + 0x49b40821; /* 16 */
+    b = ((b << 22) | (b >>> 10)) + c;
+    
+    
+    /* Round 2 */
+    a += ((b & d) | (c & ~d)) + x[ 1] + 0xf61e2562; /* 17 */
+    a = ((a << 5) | (a >>> 27)) + b;
+    d += ((a & c) | (b & ~c)) + x[ 6] + 0xc040b340; /* 18 */
+    d = ((d << 9) | (d >>> 23)) + a;
+    c += ((d & b) | (a & ~b)) + x[11] + 0x265e5a51; /* 19 */
+    c = ((c << 14) | (c >>> 18)) + d;
+    b += ((c & a) | (d & ~a)) + x[ 0] + 0xe9b6c7aa; /* 20 */
+    b = ((b << 20) | (b >>> 12)) + c;
+
+    a += ((b & d) | (c & ~d)) + x[ 5] + 0xd62f105d; /* 21 */
+    a = ((a << 5) | (a >>> 27)) + b;
+    d += ((a & c) | (b & ~c)) + x[10] + 0x02441453; /* 22 */
+    d = ((d << 9) | (d >>> 23)) + a;
+    c += ((d & b) | (a & ~b)) + x[15] + 0xd8a1e681; /* 23 */
+    c = ((c << 14) | (c >>> 18)) + d;
+    b += ((c & a) | (d & ~a)) + x[ 4] + 0xe7d3fbc8; /* 24 */
+    b = ((b << 20) | (b >>> 12)) + c;
+
+    a += ((b & d) | (c & ~d)) + x[ 9] + 0x21e1cde6; /* 25 */
+    a = ((a << 5) | (a >>> 27)) + b;
+    d += ((a & c) | (b & ~c)) + x[14] + 0xc33707d6; /* 26 */
+    d = ((d << 9) | (d >>> 23)) + a;
+    c += ((d & b) | (a & ~b)) + x[ 3] + 0xf4d50d87; /* 27 */
+    c = ((c << 14) | (c >>> 18)) + d;
+    b += ((c & a) | (d & ~a)) + x[ 8] + 0x455a14ed; /* 28 */
+    b = ((b << 20) | (b >>> 12)) + c;
+
+    a += ((b & d) | (c & ~d)) + x[13] + 0xa9e3e905; /* 29 */
+    a = ((a << 5) | (a >>> 27)) + b;
+    d += ((a & c) | (b & ~c)) + x[ 2] + 0xfcefa3f8; /* 30 */
+    d = ((d << 9) | (d >>> 23)) + a;
+    c += ((d & b) | (a & ~b)) + x[ 7] + 0x676f02d9; /* 31 */
+    c = ((c << 14) | (c >>> 18)) + d;
+    b += ((c & a) | (d & ~a)) + x[12] + 0x8d2a4c8a; /* 32 */
+    b = ((b << 20) | (b >>> 12)) + c;
+    
+    
+    /* Round 3 */
+    a += (b ^ c ^ d) + x[ 5] + 0xfffa3942;      /* 33 */
+    a = ((a << 4) | (a >>> 28)) + b;
+    d += (a ^ b ^ c) + x[ 8] + 0x8771f681;      /* 34 */
+    d = ((d << 11) | (d >>> 21)) + a;
+    c += (d ^ a ^ b) + x[11] + 0x6d9d6122;      /* 35 */
+    c = ((c << 16) | (c >>> 16)) + d;
+    b += (c ^ d ^ a) + x[14] + 0xfde5380c;      /* 36 */
+    b = ((b << 23) | (b >>> 9)) + c;
+    
+    a += (b ^ c ^ d) + x[ 1] + 0xa4beea44;      /* 37 */
+    a = ((a << 4) | (a >>> 28)) + b;
+    d += (a ^ b ^ c) + x[ 4] + 0x4bdecfa9;      /* 38 */
+    d = ((d << 11) | (d >>> 21)) + a;
+    c += (d ^ a ^ b) + x[ 7] + 0xf6bb4b60;      /* 39 */
+    c = ((c << 16) | (c >>> 16)) + d;
+    b += (c ^ d ^ a) + x[10] + 0xbebfbc70;      /* 40 */
+    b = ((b << 23) | (b >>> 9)) + c;
+    
+    a += (b ^ c ^ d) + x[13] + 0x289b7ec6;      /* 41 */
+    a = ((a << 4) | (a >>> 28)) + b;
+    d += (a ^ b ^ c) + x[ 0] + 0xeaa127fa;      /* 42 */
+    d = ((d << 11) | (d >>> 21)) + a;
+    c += (d ^ a ^ b) + x[ 3] + 0xd4ef3085;      /* 43 */
+    c = ((c << 16) | (c >>> 16)) + d;
+    b += (c ^ d ^ a) + x[ 6] + 0x04881d05;      /* 44 */
+    b = ((b << 23) | (b >>> 9)) + c;
+    
+    a += (b ^ c ^ d) + x[ 9] + 0xd9d4d039;      /* 33 */
+    a = ((a << 4) | (a >>> 28)) + b;
+    d += (a ^ b ^ c) + x[12] + 0xe6db99e5;      /* 34 */
+    d = ((d << 11) | (d >>> 21)) + a;
+    c += (d ^ a ^ b) + x[15] + 0x1fa27cf8;      /* 35 */
+    c = ((c << 16) | (c >>> 16)) + d;
+    b += (c ^ d ^ a) + x[ 2] + 0xc4ac5665;      /* 36 */
+    b = ((b << 23) | (b >>> 9)) + c;
+    
+
+    /* Round 4 */
+    a += (c ^ (b | ~d)) + x[ 0] + 0xf4292244; /* 49 */
+    a = ((a << 6) | (a >>> 26)) + b;
+    d += (b ^ (a | ~c)) + x[ 7] + 0x432aff97; /* 50 */
+    d = ((d << 10) | (d >>> 22)) + a;
+    c += (a ^ (d | ~b)) + x[14] + 0xab9423a7; /* 51 */
+    c = ((c << 15) | (c >>> 17)) + d;
+    b += (d ^ (c | ~a)) + x[ 5] + 0xfc93a039; /* 52 */
+    b = ((b << 21) | (b >>> 11)) + c;
+
+    a += (c ^ (b | ~d)) + x[12] + 0x655b59c3; /* 53 */
+    a = ((a << 6) | (a >>> 26)) + b;
+    d += (b ^ (a | ~c)) + x[ 3] + 0x8f0ccc92; /* 54 */
+    d = ((d << 10) | (d >>> 22)) + a;
+    c += (a ^ (d | ~b)) + x[10] + 0xffeff47d; /* 55 */
+    c = ((c << 15) | (c >>> 17)) + d;
+    b += (d ^ (c | ~a)) + x[ 1] + 0x85845dd1; /* 56 */
+    b = ((b << 21) | (b >>> 11)) + c;
+
+    a += (c ^ (b | ~d)) + x[ 8] + 0x6fa87e4f; /* 57 */
+    a = ((a << 6) | (a >>> 26)) + b;
+    d += (b ^ (a | ~c)) + x[15] + 0xfe2ce6e0; /* 58 */
+    d = ((d << 10) | (d >>> 22)) + a;
+    c += (a ^ (d | ~b)) + x[ 6] + 0xa3014314; /* 59 */
+    c = ((c << 15) | (c >>> 17)) + d;
+    b += (d ^ (c | ~a)) + x[13] + 0x4e0811a1; /* 60 */
+    b = ((b << 21) | (b >>> 11)) + c;
+
+    a += (c ^ (b | ~d)) + x[ 4] + 0xf7537e82; /* 61 */
+    a = ((a << 6) | (a >>> 26)) + b;
+    d += (b ^ (a | ~c)) + x[11] + 0xbd3af235; /* 62 */
+    d = ((d << 10) | (d >>> 22)) + a;
+    c += (a ^ (d | ~b)) + x[ 2] + 0x2ad7d2bb; /* 63 */
+    c = ((c << 15) | (c >>> 17)) + d;
+    b += (d ^ (c | ~a)) + x[ 9] + 0xeb86d391; /* 64 */
+    b = ((b << 21) | (b >>> 11)) + c;
+
+    state.state[0] += a;
+    state.state[1] += b;
+    state.state[2] += c;
+    state.state[3] += d;
+  }
+
+  /**	
+   * Updates hash with the bytebuffer given (using at maximum length bytes from
+   * that buffer)
+   *
+   * @param stat	Which state is updated
+   * @param buffer	Array of bytes to be hashed
+   * @param offset	Offset to buffer array
+   * @param length	Use at maximum `length' bytes (absolute
+   *			maximum is buffer.length)
+   */
+  public void Update (MD5State stat, byte buffer[], int offset, int length) {
+    int	index, partlen, i, start;
+    finals = null;
+
+    /* Length can be told to be shorter, but not inter */
+    if ((length - offset)> buffer.length)
+      length = buffer.length - offset;
+
+    /* compute number of bytes mod 64 */
+
+    index = (int) (stat.count & 0x3f);
+    stat.count += length;
+    
+    partlen = 64 - index;
+
+    if (length >= partlen) {
+      if (native_lib_loaded) {
+	
+	// update state (using native method) to reflect input
+
+	if (partlen == 64) {
+	  partlen = 0;
+	} else {
+	  for (i = 0; i < partlen; i++)
+	    stat.buffer[i + index] = buffer[i + offset];
+	  Transform_native(stat.state, stat.buffer, 0, 64);
+	}
+	Transform_native(stat.state, buffer, partlen + offset, length - partlen);
+	i = partlen + ((length - partlen) / 64) * 64;
+      } else {
+	
+	// update state (using only Java) to reflect input
+
+	int[] decode_buf = new int[16];
+	if (partlen == 64) {
+	  partlen = 0;
+	} else {
+	  for (i = 0; i < partlen; i++)
+	    stat.buffer[i + index] = buffer[i + offset];
+	  Transform(stat, stat.buffer, 0, decode_buf);
+	}
+	for (i = partlen; (i + 63) < length; i+= 64) {
+	  Transform(stat, buffer, i + offset, decode_buf);
+	}
+      }
+      index = 0;
+    } else 
+      i = 0;
+
+    /* buffer remaining input */
+    if (i < length) {
+      start = i;
+      for (; i < length; i++) {
+	stat.buffer[index + i - start] = buffer[i + offset];
+      }
+    }
+  }
+
+  /* 
+   * Update()s for other datatypes than byte[] also. Update(byte[], int)
+   * is only the main driver.
+   */
+
+  /**
+   * Plain update, updates this object
+   */
+
+  public void Update (byte buffer[], int offset, int length) {
+      Update(this.state, buffer, offset, length);
+  }
+
+  public void Update (byte buffer[], int length) {
+      Update(this.state, buffer, 0, length);
+  }
+
+  /**
+   * Updates hash with given array of bytes
+   *
+   * @param buffer	Array of bytes to use for updating the hash
+   */
+  public void Update (byte buffer[]) {
+      Update(buffer, 0, buffer.length);
+  }
+
+  /**
+   * Updates hash with a single byte
+   *
+   * @param b		Single byte to update the hash
+   */
+  public void Update (byte b) {
+    byte buffer[] = new byte[1];
+    buffer[0] = b;
+
+    Update(buffer, 1);
+  }
+  
+  /**
+   * Update buffer with given string.  Note that because the version of
+   * the s.getBytes() method without parameters is used to convert the
+   * string to a byte array, the results of this method may be different
+   * on different platforms.  The s.getBytes() method converts the string
+   * into a byte array using the current platform's default character set
+   * and may therefore have different results on platforms with different
+   * default character sets.  If a version that works consistently
+   * across platforms with different default character sets is desired,
+   * use the overloaded version of the Update() method which takes a
+   * string and a character encoding.
+   *
+   * @param s		String to be update to hash (is used as
+   *		       	s.getBytes())
+   */
+  public void Update (String s) {
+    byte chars[] = s.getBytes();
+    Update(chars, chars.length);
+  }
+
+  /**
+   * Update buffer with given string using the given encoding.  If the
+   * given encoding is null, the encoding "ISO8859_1" is used.
+   *
+   * @param s		String to be update to hash (is used as
+   *		       	s.getBytes(charset_name))
+   * @param charset_name The character set to use to convert s to a
+   *                    byte array, or null if the "ISO8859_1"
+   *                    character set is desired.
+   * @exception         java.io.UnsupportedEncodingException If the named
+   *                    charset is not supported.
+   */
+  public void Update (String s, String charset_name) throws java.io.UnsupportedEncodingException {
+    if (charset_name == null) charset_name = "ISO8859_1";
+    byte chars[] = s.getBytes(charset_name);
+    Update(chars, chars.length);
+  }
+
+  /**
+   * Update buffer with a single integer (only & 0xff part is used,
+   * as a byte)
+   *
+   * @param i		Integer value, which is then converted to 
+   *			byte as i & 0xff
+   */
+
+  public void Update (int i) {
+      Update((byte) (i & 0xff));
+  }
+
+  private byte[] Encode (int input[], int len) {
+    int		i, j;
+    byte	out[];
+
+    out = new byte[len];
+
+    for (i = j = 0; j  < len; i++, j += 4) {
+      out[j] = (byte) (input[i] & 0xff);
+      out[j + 1] = (byte) ((input[i] >>> 8) & 0xff);
+      out[j + 2] = (byte) ((input[i] >>> 16) & 0xff);
+      out[j + 3] = (byte) ((input[i] >>> 24) & 0xff);
+    }
+
+    return out;
+  }
+
+  /**
+   * Returns array of bytes (16 bytes) representing hash as of the
+   * current state of this object. Note: getting a hash does not
+   * invalidate the hash object, it only creates a copy of the real
+   * state which is finalized. 
+   *
+   * @return	Array of 16 bytes, the hash of all updated bytes
+   */
+  public synchronized byte[] Final () {
+    byte	bits[];
+    int		index, padlen;
+    MD5State	fin;
+
+    if (finals == null) {
+      fin = new MD5State(state);
+
+      int[] count_ints = {(int) (fin.count << 3), (int) (fin.count >> 29)};
+      bits = Encode(count_ints, 8);
+    
+      index = (int) (fin.count & 0x3f);
+      padlen = (index < 56) ? (56 - index) : (120 - index);
+
+      Update(fin, padding, 0, padlen);
+      Update(fin, bits, 0, 8);	
+
+      /* Update() sets finals to null */
+      finals = fin;
+    } 
+
+    return Encode(finals.state, 16);
+  }    
+
+  private static final char[] HEX_CHARS = {'0', '1', '2', '3',
+					   '4', '5', '6', '7',
+					   '8', '9', 'a', 'b',
+					   'c', 'd', 'e', 'f',};
+
+  /**
+   * Turns array of bytes into string representing each byte as
+   * unsigned hex number.
+   * 
+   * @param hash	Array of bytes to convert to hex-string
+   * @return	Generated hex string
+   */
+  public static String asHex (byte hash[]) {
+    char buf[] = new char[hash.length * 2];
+    for (int i = 0, x = 0; i < hash.length; i++) {
+      buf[x++] = HEX_CHARS[(hash[i] >>> 4) & 0xf];
+      buf[x++] = HEX_CHARS[hash[i] & 0xf];
+    }
+    return new String(buf);
+  }
+
+  /**
+   * Returns 32-character hex representation of this objects hash
+   *
+   * @return String of this object's hash
+   */
+  public String asHex () {
+    return asHex(this.Final());
+  }
+
+  public static synchronized final void initNativeLibrary(boolean disallow_lib_loading) {
+    if (disallow_lib_loading) {
+      native_lib_init_pending = false;
+    } else {
+      _initNativeLibrary();
+    }
+  }
+
+  private static synchronized final void  _initNativeLibrary() {
+    if (!native_lib_init_pending) return;
+    native_lib_loaded = _loadNativeLibrary();
+    native_lib_init_pending = false;
+  }
+
+  private static synchronized final boolean _loadNativeLibrary() {
+    try {
+
+      // don't try to load if the right property is set
+
+      String prop = System.getProperty("com.twmacinta.util.MD5.NO_NATIVE_LIB");
+      if (prop != null) {
+	prop = prop.trim();
+	if (prop.equalsIgnoreCase("true") || prop.equals("1")) return false;
+      }
+
+      // the library to load can be specified as a property
+
+      File f;
+      prop = System.getProperty("com.twmacinta.util.MD5.NATIVE_LIB_FILE");
+      if (prop != null) {
+	f = new File(prop);
+	if (f.canRead()) {
+	  System.load(f.getAbsolutePath());
+	  return true;
+	}
+      }
+
+      // determine the operating system and architecture
+
+      String os_name = System.getProperty("os.name");
+      String os_arch = System.getProperty("os.arch");
+      if (os_name == null || os_arch == null) return false;
+      os_name = os_name.toLowerCase();
+      os_arch = os_arch.toLowerCase();
+
+      // define settings which are OS arch architecture independent
+
+      File arch_lib_path = null;
+      String arch_libfile_suffix = null;
+
+    //   fill in settings for Linux on x86
+
+      if (os_name.equals("linux") &&
+	  (os_arch.equals("x86") ||
+	   os_arch.equals("i386") ||
+	   os_arch.equals("i486") ||
+	   os_arch.equals("i586") ||
+	   os_arch.equals("i686"))) {
+	arch_lib_path = new File(new File(new File("lib"), "arch"), "linux_x86");
+	arch_libfile_suffix = ".so"; 
+
+	// fill in settings for Windows on x86
+
+      } else if (os_name.startsWith("windows ") &&
+		 (os_arch.equals("x86") ||
+		  os_arch.equals("i386") ||
+		  os_arch.equals("i486") ||
+		  os_arch.equals("i586") ||
+		  os_arch.equals("i686"))) {
+	arch_lib_path = new File(new File(new File("lib"), "arch"), "win32_x86");
+	arch_libfile_suffix = ".dll"; 
+
+	// fill in settings Mac OS X on PPC
+
+      } else if (os_name.startsWith("mac os x") &&
+		 (os_arch.equals("ppc"))) {
+	arch_lib_path = new File(new File(new File("lib"), "arch"), "darwin_ppc");
+	arch_libfile_suffix = ".jnilib";
+
+	// default to .so files with no architecture specific subdirectory
+      
+      } else {
+	arch_libfile_suffix = ".so"; 
+      }
+
+      // build the required filename
+
+      String fname = "MD5" + arch_libfile_suffix;
+
+      // try the architecture specific directory
+
+      if (arch_lib_path != null) {
+	f = new File(arch_lib_path, fname);
+	if (f.canRead()) {
+	  System.load(f.getAbsolutePath());
+	  return true;
+	}
+      }
+
+      // try the "lib" subdirectory
+
+      f = new File(new File("lib"), fname);
+      if (f.canRead()) {
+	System.load(f.getAbsolutePath());
+	return true;
+      }
+
+      // try the working directory
+
+      f = new File(fname);
+      if (f.canRead()) {
+	System.load(f.getAbsolutePath());
+	return true;
+      }
+      
+      // discard SecurityExceptions
+
+    } catch (SecurityException e) {}
+
+    // unable to load
+
+    return false;
+  }
+
+  /**
+   * Calculates and returns the hash of the contents of the given file.
+   **/
+  public static byte[] getHash(File f) throws IOException {
+    if (!f.exists()) throw new FileNotFoundException(f.toString());
+    InputStream close_me = null;
+    try {
+      long buf_size = f.length();
+      if (buf_size < 512) buf_size = 512;
+      if (buf_size > 65536) buf_size = 65536;
+      byte[] buf = new byte[(int) buf_size];
+      MD5InputStream in = new MD5InputStream(new FileInputStream(f));
+      close_me = in;
+      while (in.read(buf) != -1);
+      in.close();
+      return in.hash();
+    } catch (IOException e) {
+      if (close_me != null) try { close_me.close(); } catch (Exception e2) {}
+      throw e;
+    }
+  }
+
+  /**
+   * @return true iff the first 16 bytes of both hash1 and hash2 are
+   *         equal;  both hash1 and hash2 are null; or either hash
+   *         array is less than 16 bytes in length and their lengths and
+   *         all of their bytes are equal.
+   **/
+  public static boolean hashesEqual(byte[] hash1, byte[] hash2) {
+    if (hash1 == null) return hash2 == null;
+    if (hash2 == null) return false;
+    int targ = 16;
+    if (hash1.length < 16) {
+      if (hash2.length != hash1.length) return false;
+      targ = hash1.length;
+    } else if (hash2.length < 16) {
+      return false;
+    }
+    for (int i = 0; i < targ; i++) {
+      if (hash1[i] != hash2[i]) return false;
+    }
+    return true;
+  }
+
+}


Property changes on: labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/com/twmacinta/util/MD5.java
___________________________________________________________________
Name: svn:executable
   + *

Added: labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/com/twmacinta/util/MD5InputStream.java
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/com/twmacinta/util/MD5InputStream.java	2006-10-31 22:07:42 UTC (rev 7258)
+++ labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/com/twmacinta/util/MD5InputStream.java	2006-10-31 22:20:54 UTC (rev 7259)
@@ -0,0 +1,169 @@
+package com.twmacinta.util;
+
+import java.io.*;
+
+/** 
+ * MD5InputStream, a subclass of FilterInputStream implementing MD5
+ * functionality on a stream.
+ * <p>
+ * Originally written by Santeri Paavolainen, Helsinki Finland 1996 <br>
+ * (c) Santeri Paavolainen, Helsinki Finland 1996 <br>
+ * Some changes Copyright (c) 2002 Timothy W Macinta <br>
+ * <p>
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * <p>
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ * <p>
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * <p>
+ * See http://www.twmacinta.com/myjava/fast_md5.php for more information
+ * on this file.
+ * <p>
+ * Please note: I (Timothy Macinta) have put this code in the
+ * com.twmacinta.util package only because it came without a package.  I
+ * was not the the original author of the code, although I did
+ * optimize it (substantially) and fix some bugs.
+ *
+ * @author	Santeri Paavolainen <santtu at cs.hut.fi>
+ * @author	Timothy W Macinta (twm at alum.mit.edu) (added main() method)
+ **/
+
+
+public class MD5InputStream extends FilterInputStream {
+  /**
+   * MD5 context
+   */
+  private MD5	md5;
+  
+  /**
+   * Creates a MD5InputStream
+   * @param in	The input stream
+   */
+  public MD5InputStream (InputStream in) {
+    super(in);
+
+    md5 = new MD5();
+  }
+
+  /**
+   * Read a byte of data. 
+   * @see java.io.FilterInputStream
+   */
+  public int read() throws IOException {
+    int c = in.read();
+
+    if (c == -1)
+	return -1;
+
+    if ((c & ~0xff) != 0) {
+      System.out.println("MD5InputStream.read() got character with (c & ~0xff) != 0)!");
+    } else {
+      md5.Update(c);
+    }
+
+    return c;
+  }
+
+  /**
+   * Reads into an array of bytes.
+   *
+   * @see java.io.FilterInputStream
+   */
+  public int read (byte bytes[], int offset, int length) throws IOException {
+    int	r;
+    
+    if ((r = in.read(bytes, offset, length)) == -1)
+      return r;
+
+    md5.Update(bytes, offset, r);
+
+    return r;
+  }
+
+  /**
+   * Returns array of bytes representing hash of the stream as
+   * finalized for the current state. 
+   * @see MD5#Final
+   */
+  public byte[] hash () {
+    return md5.Final();
+  }
+
+  public MD5 getMD5() {
+    return md5;
+  }
+
+  /**
+   * This method is here for testing purposes only - do not rely
+   * on it being here.
+   **/
+  public static void main(String[] arg) {
+    try {
+
+      ////////////////////////////////////////////////////////////////
+      //
+      // usage:  java com.twmacinta.util.MD5InputStream [--use-default-md5] [--no-native-lib] filename
+      //
+      /////////
+
+      // determine the filename to use and the MD5 impelementation to use
+
+      String filename = arg[arg.length-1];
+      boolean use_default_md5 = false;
+      boolean use_native_lib = true;
+      for (int i = 0; i < arg.length-1; i++) {
+	if (arg[i].equals("--use-default-md5")) {
+	  use_default_md5 = true;
+	} else if (arg[i].equals("--no-native-lib")) {
+	  use_native_lib = false;
+	}
+      }
+
+      // initialize common variables
+
+      byte[] buf = new byte[65536];
+      int num_read;
+
+      //   Use the default MD5 implementation that comes with Java
+
+      if (use_default_md5) {
+	InputStream in = new BufferedInputStream(new FileInputStream(filename));
+	java.security.MessageDigest digest = java.security.MessageDigest.getInstance("MD5");
+	while ((num_read = in.read(buf)) != -1) {
+	  digest.update(buf, 0, num_read);
+	}
+	System.out.println(MD5.asHex(digest.digest())+"  "+filename);
+	in.close();
+
+	// Use the optimized MD5 implementation
+
+      } else {
+
+	//    disable the native library search, if requested
+
+	if (!use_native_lib) {
+	  MD5.initNativeLibrary(true);
+	}
+
+	//    calculate the checksum
+
+	MD5InputStream in = new MD5InputStream(new BufferedInputStream(new FileInputStream(filename)));
+	while ((num_read = in.read(buf)) != -1);
+	System.out.println(MD5.asHex(in.hash())+"  "+filename);
+	in.close();
+      }
+    } catch (Exception e) {
+      e.printStackTrace();
+    }
+  }
+
+}
+


Property changes on: labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/com/twmacinta/util/MD5InputStream.java
___________________________________________________________________
Name: svn:executable
   + *

Added: labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/com/twmacinta/util/MD5OutputStream.java
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/com/twmacinta/util/MD5OutputStream.java	2006-10-31 22:07:42 UTC (rev 7258)
+++ labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/com/twmacinta/util/MD5OutputStream.java	2006-10-31 22:20:54 UTC (rev 7259)
@@ -0,0 +1,117 @@
+package com.twmacinta.util;
+
+import java.io.*;
+
+/** 
+ * MD5OutputStream is a subclass of FilterOutputStream adding MD5
+ * hashing of the output.
+ * <p>
+ * Originally written by Santeri Paavolainen, Helsinki Finland 1996 <br>
+ * (c) Santeri Paavolainen, Helsinki Finland 1996 <br>
+ * Some changes Copyright (c) 2002 Timothy W Macinta <br>
+ * <p>
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * <p>
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ * <p>
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * <p>
+ * See http://www.twmacinta.com/myjava/fast_md5.php for more information
+ * on this file.
+ * <p>
+ * Please note: I (Timothy Macinta) have put this code in the
+ * com.twmacinta.util package only because it came without a package.  I
+ * was not the the original author of the code, although I did
+ * optimize it (substantially) and fix some bugs.
+ *
+ * @author	Santeri Paavolainen <santtu at cs.hut.fi>
+ * @author	Timothy W Macinta (twm at alum.mit.edu) (added main() method)
+ **/
+
+public class MD5OutputStream extends FilterOutputStream {
+    /**
+     * MD5 context
+     */
+    private MD5	md5;
+
+    /**
+     * Creates MD5OutputStream
+     * @param out	The output stream
+     */
+
+    public MD5OutputStream (OutputStream out) {
+	super(out);
+
+	md5 = new MD5();
+    }
+
+    /**
+     * Writes a byte. 
+     *
+     * @see java.io.FilterOutputStream
+     */
+
+    public void write (int b) throws IOException {
+	out.write(b);
+	md5.Update((byte) b);
+    }
+
+    /**
+     * Writes a sub array of bytes.
+     *
+     * @see java.io.FilterOutputStream
+     */
+
+    public void write (byte b[], int off, int len) throws IOException {
+	out.write(b, off, len);
+	md5.Update(b, off, len);
+    }
+
+    /**
+     * Returns array of bytes representing hash of the stream as finalized
+     * for the current state.
+     * @see MD5#Final
+     */
+
+    public byte[] hash () {
+	return md5.Final();
+    }
+
+  public MD5 getMD5() {
+    return md5;
+  }
+
+  /**
+   * This method is here for testing purposes only - do not rely
+   * on it being here.
+   **/
+  public static void main(String[] arg) {
+    try {
+      MD5OutputStream out = new MD5OutputStream(new com.twmacinta.io.NullOutputStream());
+      InputStream in = new BufferedInputStream(new FileInputStream(arg[0]));
+      byte[] buf = new byte[65536];
+      int num_read;
+      long total_read = 0;
+      while ((num_read = in.read(buf)) != -1) {
+	total_read += num_read;
+	out.write(buf, 0, num_read);
+      }
+      System.out.println(MD5.asHex(out.hash())+"  "+arg[0]);
+      in.close();
+      out.close();
+    } catch (Exception e) {
+      e.printStackTrace();
+    }
+  }
+
+
+}
+


Property changes on: labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/com/twmacinta/util/MD5OutputStream.java
___________________________________________________________________
Name: svn:executable
   + *

Added: labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/com/twmacinta/util/MD5State.java
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/com/twmacinta/util/MD5State.java	2006-10-31 22:07:42 UTC (rev 7258)
+++ labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/com/twmacinta/util/MD5State.java	2006-10-31 22:20:54 UTC (rev 7259)
@@ -0,0 +1,79 @@
+package com.twmacinta.util;
+
+/**
+ * Fast implementation of RSA's MD5 hash generator in Java JDK Beta-2 or higher<br>
+ * Originally written by Santeri Paavolainen, Helsinki Finland 1996 <br>
+ * (c) Santeri Paavolainen, Helsinki Finland 1996 <br>
+ * Some changes Copyright (c) 2002 Timothy W Macinta <br>
+ * <p>
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * <p>
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ * <p>
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * <p>
+ * See http://www.twmacinta.com/myjava/fast_md5.php for more information
+ * on this file.
+ * <p>
+ * Contains internal state of the MD5 class
+ * <p>
+ * Please note: I (Timothy Macinta) have put this code in the
+ * com.twmacinta.util package only because it came without a package.  I
+ * was not the the original author of the code, although I did
+ * optimize it (substantially) and fix some bugs.
+ *
+ * @author	Santeri Paavolainen <sjpaavol at cc.helsinki.fi>
+ * @author	Timothy W Macinta (twm at alum.mit.edu) (optimizations and bug fixes)
+ **/
+
+class MD5State {
+  /**
+   * 128-bit state 
+   */
+  int	state[];
+  
+  /**
+   * 64-bit character count
+   */
+  long count;
+  
+  /**
+   * 64-byte buffer (512 bits) for storing to-be-hashed characters
+   */
+  byte	buffer[];
+
+  public MD5State() {
+    buffer = new byte[64];
+    count = 0;
+    state = new int[4];
+    
+    state[0] = 0x67452301;
+    state[1] = 0xefcdab89;
+    state[2] = 0x98badcfe;
+    state[3] = 0x10325476;
+
+  }
+
+  /** Create this State as a copy of another state */
+  public MD5State (MD5State from) {
+    this();
+    
+    int i;
+    
+    for (i = 0; i < buffer.length; i++)
+      this.buffer[i] = from.buffer[i];
+    
+    for (i = 0; i < state.length; i++)
+      this.state[i] = from.state[i];
+    
+    this.count = from.count;
+  }
+};


Property changes on: labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/com/twmacinta/util/MD5State.java
___________________________________________________________________
Name: svn:executable
   + *

Added: labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/com/twmacinta/util/test/MD5OutputStreamTest.java
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/com/twmacinta/util/test/MD5OutputStreamTest.java	2006-10-31 22:07:42 UTC (rev 7258)
+++ labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/com/twmacinta/util/test/MD5OutputStreamTest.java	2006-10-31 22:20:54 UTC (rev 7259)
@@ -0,0 +1,157 @@
+package com.twmacinta.util.test;
+
+import java.io.*;
+import java.util.*;
+import com.twmacinta.io.*;
+import com.twmacinta.util.*;
+
+/**
+ * Copyright (c) 2002 by Timothy W Macinta, All Rights Reserved.<p>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * <p>
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ * <p>
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * <p>
+ * This class generates a stream of random data and compares the
+ * results of the md5 checksum generated by an instance of
+ * MD5OutputStream with the md5 checksum by piping the data through
+ * the local md5sum binary.
+ * <p>
+ * See http://www.twmacinta.com/myjava/fast_md5.php for more information
+ * on this file.
+ *
+ * @author Tim Macinta (twm at alum.mit.edu)
+ **/
+
+public class MD5OutputStreamTest {
+
+  /**
+   * Usage:
+   *   java com.twmacinta.util.test.MD5OutputStreamTest [seed | "time" [max_data]]
+   **/
+  public static void main(String arg[]) {
+    try {
+      long seed = System.currentTimeMillis();
+      if (arg.length > 0) {
+	if (!arg[0].equals("time")) {
+	  seed = Long.parseLong(arg[0]);
+	}
+      }
+
+      long max_data = (20L * (1 << 30)); // max 20 gigabytes
+      if (arg.length > 1) {
+	max_data = Long.parseLong(arg[1]);
+      }
+
+      Random ran = new Random(seed);
+      while (true) {
+	System.out.print("seed:  "+seed+"  \t");
+	long data_size = ran.nextLong();
+	if (data_size < 0) data_size = -data_size;
+	data_size = data_size % (max_data + 1);
+	System.out.println("size:  "+data_size);
+	runTest(data_size, ran);
+	seed = ran.nextLong();
+	ran.setSeed(seed);
+      }
+    } catch (Exception e) {
+      e.printStackTrace();
+    }
+  }
+
+  private static void runTest(long data_size, Random ran) throws IOException {
+    Process proc = Runtime.getRuntime().exec("md5sum");
+    MD5OutputStream out1 = new MD5OutputStream(new NullOutputStream());
+    OutputStream out2 = new BufferedOutputStream(proc.getOutputStream());
+    
+    while (data_size > 0) {
+
+      int output_type = ran.nextInt() % 100;
+
+      output_type -= 5;  // 5% chance
+      if (output_type < 0) {
+	outputSingleByte(ran, out1, out2);
+	data_size--;
+	continue;
+      }
+
+      output_type -= 25;  // 25% chance
+      if (output_type < 0) {
+	data_size -= outputFullBuffer(ran, out1, out2, data_size);
+	continue;
+      }
+
+      // the default
+
+      data_size -= outputPartialBuffer(ran, out1, out2, data_size);
+    }
+
+    BufferedReader in = new BufferedReader(new InputStreamReader(proc.getInputStream()));
+    out2.flush();
+    out2.close();
+
+    String native_sum = new StringTokenizer(in.readLine()).nextToken();
+    in.close();
+    String java_sum = MD5.asHex(out1.hash());
+    if (!native_sum.equals(java_sum)) {
+      out1.close();
+      System.out.println("ERROR");
+      System.out.println("java:   " + java_sum);
+      System.out.println("native: " + native_sum);
+      System.exit(1);
+    }
+    out1.close();
+  }
+
+  private static void outputSingleByte(Random ran, OutputStream out1, OutputStream out2) throws IOException {
+    int b = ran.nextInt() & 0xff;
+    out1.write(b);
+    out2.write(b);
+  }
+
+  private static long outputFullBuffer(Random ran, OutputStream out1, OutputStream out2, long max_bytes) throws IOException {
+    int b_len = ran.nextInt();
+    if (b_len < 0) b_len = -b_len;
+    b_len = b_len % ((1 << 20) / 8);  // 1/8 meg max
+    if (b_len > max_bytes) b_len = (int) max_bytes;
+    byte[] b = new byte[b_len];
+    ran.nextBytes(b);
+    out1.write(b);
+    out2.write(b);
+    return b_len;
+  }
+
+  private static long outputPartialBuffer(Random ran, OutputStream out1, OutputStream out2, long max_bytes) throws IOException {
+    int b_len = ran.nextInt();
+    if (b_len < 0) b_len = -b_len;
+    b_len = b_len % ((1 << 20) / 2);  // 1/2 meg max
+    if (b_len > max_bytes) b_len = (int) max_bytes;
+    if (b_len == 0) return 0;
+    byte[] b = new byte[b_len];
+    ran.nextBytes(b);
+
+    int off = ran.nextInt();
+    if (off < 0) off = -off;
+    off = off % b_len;
+    if (off == b_len) return 0;
+    
+    int len = ran.nextInt();
+    if (len < 0) len = -len;
+    len = len % (b_len - off);
+
+    out1.write(b, off, len);
+    out2.write(b, off, len);
+    return len;
+  }
+
+}


Property changes on: labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/com/twmacinta/util/test/MD5OutputStreamTest.java
___________________________________________________________________
Name: svn:executable
   + *

Added: labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/lib/arch/darwin_ppc/MD5.jnilib
===================================================================
(Binary files differ)


Property changes on: labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/lib/arch/darwin_ppc/MD5.jnilib
___________________________________________________________________
Name: svn:executable
   + *
Name: svn:mime-type
   + application/octet-stream

Added: labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/lib/arch/linux_x86/MD5.so
===================================================================
(Binary files differ)


Property changes on: labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/lib/arch/linux_x86/MD5.so
___________________________________________________________________
Name: svn:executable
   + *
Name: svn:mime-type
   + application/octet-stream

Added: labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/lib/arch/win32_x86/MD5.dll
===================================================================
(Binary files differ)


Property changes on: labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/lib/arch/win32_x86/MD5.dll
___________________________________________________________________
Name: svn:executable
   + *
Name: svn:mime-type
   + application/octet-stream

Modified: labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/org/jboss/forge/common/ForgeHelper.java
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/org/jboss/forge/common/ForgeHelper.java	2006-10-31 22:07:42 UTC (rev 7258)
+++ labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/org/jboss/forge/common/ForgeHelper.java	2006-10-31 22:20:54 UTC (rev 7259)
@@ -53,6 +53,8 @@
 import org.jboss.shotoku.aop.CacheItem;
 import org.w3c.dom.Node;
 
+import com.twmacinta.util.MD5;
+
 /**
  * Common constants and functions for the forge.
  * 
@@ -596,4 +598,12 @@
 	public static String getFilePath(Integer num) {
 		return tempFiles.get(num);
 	}
+	
+	public static String encodeToMD5(String phrase) {
+		MD5 md5 = new MD5();
+		
+		md5.Update(phrase);
+		
+		return md5.asHex();
+	}
 }

Modified: labs/jbosslabs/trunk/portal-extensions/forge-login/src/java/org/jboss/labs/login/LabsLoginModule.java
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/forge-login/src/java/org/jboss/labs/login/LabsLoginModule.java	2006-10-31 22:07:42 UTC (rev 7258)
+++ labs/jbosslabs/trunk/portal-extensions/forge-login/src/java/org/jboss/labs/login/LabsLoginModule.java	2006-10-31 22:20:54 UTC (rev 7259)
@@ -21,6 +21,7 @@
  */
 package org.jboss.labs.login;
 
+import java.security.MessageDigest;
 import java.security.Principal;
 import java.security.acl.Group;
 import java.sql.Connection;
@@ -40,6 +41,7 @@
 import javax.sql.DataSource;
 import javax.transaction.TransactionManager;
 
+import org.jboss.forge.common.ForgeHelper;
 import org.jboss.forge.common.PermissionTools;
 import org.jboss.forge.common.propertypersistance.PropertyService;
 import org.jboss.forge.common.soa.LabsServices;
@@ -75,6 +77,7 @@
 	private static final String TOKENIZER = "<!AutoLoginTokenizer!>";
 
 	private static final String AUTLOGIN_PASSWORD = "Autologin:password";
+	
 
 	public void initialize(Subject subject, CallbackHandler callbackHandler,
 			Map sharedState, Map options) {
@@ -125,7 +128,11 @@
 				String browser = tokens[2];
 				String key = ip + browser + getUsername();
 				String pass = tokens[3];
-
+				
+				pass = ForgeHelper.encodeToMD5(pass);
+				
+				log.info("Encoded pass: "+pass);
+				
 				PropertyService service = LabsServices.getPropertyService();
 				
 				String persistedPass = (String)service.getProperty(key, AUTLOGIN_PASSWORD);

Modified: labs/jbosslabs/trunk/portal-extensions/forge-login-portlet/src/java/org/jbosslabs/security/Constants.java
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/forge-login-portlet/src/java/org/jbosslabs/security/Constants.java	2006-10-31 22:07:42 UTC (rev 7258)
+++ labs/jbosslabs/trunk/portal-extensions/forge-login-portlet/src/java/org/jbosslabs/security/Constants.java	2006-10-31 22:20:54 UTC (rev 7259)
@@ -2,7 +2,7 @@
 
 public interface Constants 
 {
-	public static final String param1 = "action";
+	public static final String param1 = "loginFailed";
 	
 	public static final String LOGOUT = "logout";
 

Modified: labs/jbosslabs/trunk/portal-extensions/forge-portal-attr/src/java/org/jboss/forge/portal/AutologinFilter.java
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/forge-portal-attr/src/java/org/jboss/forge/portal/AutologinFilter.java	2006-10-31 22:07:42 UTC (rev 7258)
+++ labs/jbosslabs/trunk/portal-extensions/forge-portal-attr/src/java/org/jboss/forge/portal/AutologinFilter.java	2006-10-31 22:20:54 UTC (rev 7259)
@@ -15,6 +15,7 @@
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.jboss.forge.common.ForgeHelper;
 import org.jboss.forge.common.propertypersistance.PropertyService;
 import org.jboss.forge.common.soa.LabsServices;
 import org.jboss.logging.Logger;
@@ -35,6 +36,8 @@
 
 	private static final String AUTLOGIN_PASSWORD = "Autologin:password";
 
+	private static final String SESSION_REFRESHED = "SessionRefreshed";
+
 	public void destroy() {
 		// TODO Auto-generated method stub
 
@@ -46,8 +49,9 @@
 		HttpServletRequest httpReq = (HttpServletRequest) request;
 		HttpServletResponse httpResp = (HttpServletResponse) response;
 
-		log.info("Request: "+httpReq.getRequestURI()+" Query: "+httpReq.getQueryString());
-		
+		log.info("Request: " + httpReq.getRequestURI() + " Query: "
+				+ httpReq.getQueryString());
+
 		log.info("doing login");
 		if (httpReq.getUserPrincipal() != null
 				&& httpReq.getSession().getAttribute(REQUEST_AUTOLOGIN) != null
@@ -67,7 +71,7 @@
 					.getUserPrincipal().getName());
 			userCookie.setMaxAge(COOKIE_EXPIRE);
 			userCookie.setPath("/");
-			
+
 			httpResp.addCookie(passCookie);
 			httpResp.addCookie(userCookie);
 
@@ -75,15 +79,14 @@
 					.getRemoteAddr(), httpReq.getHeader("User-Agent"));
 
 			log.info(httpReq.getUserPrincipal().getName());
-		} 
-		else if (httpReq.getUserPrincipal() != null) {
+		} else if (httpReq.getUserPrincipal() != null) {
 			String[] cred = hasCookies(httpReq);
-			
-			if (cred != null && cred.length == 2) {
+
+			if (cred != null && cred.length == 2 && httpReq.getSession().getAttribute(SESSION_REFRESHED) == null) {
 				refreshCookies(httpReq, httpResp);
+				httpReq.getSession().setAttribute(SESSION_REFRESHED, true);
 			}
-		}
-		else if (httpReq.getUserPrincipal() == null
+		} else if (httpReq.getUserPrincipal() == null
 				&& !httpReq.getRequestURI().equals("/portal/default/login")) {
 			// user not logged in - try autologin
 
@@ -92,7 +95,7 @@
 			String[] cred;
 
 			if ((cred = hasCookies(httpReq)) != null && cred.length == 2) {
-				String url = httpReq.getContextPath() + "/auth"
+				String url = httpReq.getContextPath() + (httpReq.isSecure() ? "/authsec" : "/auth")
 						+ httpReq.getServletPath() + httpReq.getPathInfo();
 				url = httpResp.encodeRedirectURL(url);
 				httpResp.sendRedirect(url);
@@ -104,17 +107,43 @@
 
 	}
 
-	private void refreshCookies(HttpServletRequest request, HttpServletResponse response) {
+	private void refreshCookies(HttpServletRequest request,
+			HttpServletResponse response) {
 		Cookie[] cookies = request.getCookies();
 
 		if (cookies != null)
 			for (int i = 0; i < cookies.length; i++) {
-				
+
 				if (cookies[i].getName().equals(USER_COOKIE)
 						|| cookies[i].getName().equals(PASS_COOKIE)) {
-					
+
 					cookies[i].setMaxAge(COOKIE_EXPIRE);
 					cookies[i].setPath("/");
+					if (cookies[i].getName().equals(PASS_COOKIE)) {
+						// generate new pass ans persist it in db
+
+						try {
+							PropertyService propertyService = LabsServices
+									.getPropertyService();
+
+							String newPass = generatePass();
+							cookies[i].setValue(newPass);
+
+							String id = request.getRemoteAddr()
+									+ request.getHeader("User-Agent")
+									+ request.getUserPrincipal().getName();
+
+							propertyService.setProperty(id, AUTLOGIN_PASSWORD,
+									ForgeHelper.encodeToMD5(newPass));
+
+							log.info("cookie refreshed: " + newPass + " "
+									+ ForgeHelper.encodeToMD5(newPass));
+
+						} catch (NamingException e) {
+							log.error(e);
+						}
+					}
+
 					response.addCookie(cookies[i]);
 				}
 			}
@@ -128,13 +157,13 @@
 		boolean hasPassCookie = false;
 
 		log.info("iterating thru cookies");
-		
+
 		if (cookies != null)
 			for (int i = 0; i < cookies.length
 					&& !(hasUserCookie && hasPassCookie); i++) {
-				
-					log.info(i+" cookie: "+cookies[i].getName());
-					
+
+				log.info(i + " cookie: " + cookies[i].getName());
+
 				if (cookies[i].getName().equals(USER_COOKIE)) {
 					hasUserCookie = true;
 					cred[0] = cookies[i].getValue();
@@ -175,14 +204,14 @@
 
 			String id = ip + browser + username;
 
-			propertyService.setProperty(id, AUTLOGIN_PASSWORD, password);
+			propertyService.setProperty(id, AUTLOGIN_PASSWORD, ForgeHelper
+					.encodeToMD5(password));
 
 			log.info("Saved: " + username + " " + password + " " + ip + " "
 					+ browser);
 
 		} catch (NamingException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
+			log.error(e);
 		}
 	}
 
@@ -192,8 +221,8 @@
 
 		if (cookies != null)
 			for (int i = 0; i < cookies.length; i++) {
-				log.info("Cookie: "+cookies[i].getName());
-				
+				log.info("Cookie: " + cookies[i].getName());
+
 				if (cookies[i].getName().equals(USER_COOKIE)
 						|| cookies[i].getName().equals(PASS_COOKIE)) {
 					log.info("deleting cookie: " + cookies[i].getName());
@@ -207,18 +236,18 @@
 			String key = request.getRemoteAddr()
 					+ request.getHeader("User-Agent")
 					+ request.getUserPrincipal().getName();
-			
+
 			PropertyService propertyService;
 			try {
 				propertyService = LabsServices.getPropertyService();
-				
+
 				if (propertyService.getProperty(key, AUTLOGIN_PASSWORD) != null) {
 					propertyService.removeProperty(key, AUTLOGIN_PASSWORD);
 				}
 			} catch (NamingException e) {
 				log.error(e);
 			}
-			
+
 		}
 
 	}

Modified: labs/jbosslabs/trunk/portal-extensions/forge-portal-attr/src/java/org/jboss/forge/portal/LoginServlet.java
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/forge-portal-attr/src/java/org/jboss/forge/portal/LoginServlet.java	2006-10-31 22:07:42 UTC (rev 7258)
+++ labs/jbosslabs/trunk/portal-extensions/forge-portal-attr/src/java/org/jboss/forge/portal/LoginServlet.java	2006-10-31 22:20:54 UTC (rev 7259)
@@ -34,9 +34,13 @@
 			log.debug("autologin disabled");
 		}
 
-		response.sendRedirect("j_security_check?j_username="
+		String url = response.encodeRedirectURL("j_security_check?j_username="
 				+ request.getParameter("j_username") + "&j_password="
 				+ request.getParameter("j_password"));
+		
+		response.sendRedirect(url);
+		
+		//request.getRequestDispatcher(url).forward(request, response);
 	}
 
 }

Modified: labs/jbosslabs/trunk/portal-extensions/forge-portal-attr/src/java/org/jboss/forge/portal/ShowLoginPageServlet.java
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/forge-portal-attr/src/java/org/jboss/forge/portal/ShowLoginPageServlet.java	2006-10-31 22:07:42 UTC (rev 7258)
+++ labs/jbosslabs/trunk/portal-extensions/forge-portal-attr/src/java/org/jboss/forge/portal/ShowLoginPageServlet.java	2006-10-31 22:20:54 UTC (rev 7259)
@@ -45,18 +45,18 @@
 						+ "&j_password=" + PASS_TOKEN + TOKENIZER
 						+ request.getRemoteAddr() + TOKENIZER
 						+ request.getHeader("User-Agent") + TOKENIZER + cred[1];
-				
+
 				url = response.encodeRedirectURL(url);
-				
+
 				log.info(url);
 
-				//request.getRequestDispatcher(url).forward(request, response);
+				// request.getRequestDispatcher(url).forward(request, response);
 				response.sendRedirect(url);
-				
+
 				return;
 
 			} else {
-				response.sendRedirect("/portal/login");
+				request.getRequestDispatcher("login").forward(request, response);
 				return;
 			}
 		}




More information about the jboss-svn-commits mailing list