From d6f99e5f666d14e91ce8c3a8db95fb8ba893027e Mon Sep 17 00:00:00 2001 From: Brett Porter Date: Mon, 9 Mar 2009 00:56:29 +0000 Subject: [PATCH] [MRM-1062] find artifact no longer worked in several browsers due to the file input not returning the full path as a security measure. For Firefox 3, the file will now be checksummed in JavaScript, and other browsers will present an alert dialog git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@751562 13f79535-47bb-0310-9956-ffa450edef68 --- .../maven/archiva/applet/ChecksumApplet.java | 7 +- .../main/webapp/WEB-INF/jsp/findArtifact.jsp | 46 +++-- .../src/main/webapp/js/webtoolkit.md5.js | 180 ++++++++++++++++++ 3 files changed, 209 insertions(+), 24 deletions(-) create mode 100644 archiva-modules/archiva-web/archiva-webapp/src/main/webapp/js/webtoolkit.md5.js diff --git a/archiva-modules/archiva-web/archiva-applet/src/main/java/org/apache/maven/archiva/applet/ChecksumApplet.java b/archiva-modules/archiva-web/archiva-applet/src/main/java/org/apache/maven/archiva/applet/ChecksumApplet.java index 52b99d44b..03d8e33f1 100644 --- a/archiva-modules/archiva-web/archiva-applet/src/main/java/org/apache/maven/archiva/applet/ChecksumApplet.java +++ b/archiva-modules/archiva-web/archiva-applet/src/main/java/org/apache/maven/archiva/applet/ChecksumApplet.java @@ -72,7 +72,7 @@ public class ChecksumApplet } catch ( FileNotFoundException e ) { - return "Couldn't find the file. " + e.getMessage(); + return "Couldn't find the file: " + e.getMessage(); } catch ( IOException e ) { @@ -88,8 +88,9 @@ public class ChecksumApplet { MessageDigest digest = MessageDigest.getInstance( "MD5" ); - long total = new File( file ).length(); - InputStream fis = new FileInputStream( file ); + File f = new File( file ); + long total = f.length(); + InputStream fis = new FileInputStream( f ); try { long totalRead = 0; diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/findArtifact.jsp b/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/findArtifact.jsp index 5cab0954c..a8a549dce 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/findArtifact.jsp +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/findArtifact.jsp @@ -25,37 +25,42 @@ - +

Find Artifact

- \ No newline at end of file + diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/js/webtoolkit.md5.js b/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/js/webtoolkit.md5.js new file mode 100644 index 000000000..9811cd288 --- /dev/null +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/js/webtoolkit.md5.js @@ -0,0 +1,180 @@ +/** +* +* MD5 (Message-Digest Algorithm) +* http://www.webtoolkit.info/ +* +* - modified to remove Utf8Encode +**/ + +var MD5 = function (string) { + + function RotateLeft(lValue, iShiftBits) { + return (lValue<>>(32-iShiftBits)); + } + + function AddUnsigned(lX,lY) { + var lX4,lY4,lX8,lY8,lResult; + lX8 = (lX & 0x80000000); + lY8 = (lY & 0x80000000); + lX4 = (lX & 0x40000000); + lY4 = (lY & 0x40000000); + lResult = (lX & 0x3FFFFFFF)+(lY & 0x3FFFFFFF); + if (lX4 & lY4) { + return (lResult ^ 0x80000000 ^ lX8 ^ lY8); + } + if (lX4 | lY4) { + if (lResult & 0x40000000) { + return (lResult ^ 0xC0000000 ^ lX8 ^ lY8); + } else { + return (lResult ^ 0x40000000 ^ lX8 ^ lY8); + } + } else { + return (lResult ^ lX8 ^ lY8); + } + } + + function F(x,y,z) { return (x & y) | ((~x) & z); } + function G(x,y,z) { return (x & z) | (y & (~z)); } + function H(x,y,z) { return (x ^ y ^ z); } + function I(x,y,z) { return (y ^ (x | (~z))); } + + function FF(a,b,c,d,x,s,ac) { + a = AddUnsigned(a, AddUnsigned(AddUnsigned(F(b, c, d), x), ac)); + return AddUnsigned(RotateLeft(a, s), b); + }; + + function GG(a,b,c,d,x,s,ac) { + a = AddUnsigned(a, AddUnsigned(AddUnsigned(G(b, c, d), x), ac)); + return AddUnsigned(RotateLeft(a, s), b); + }; + + function HH(a,b,c,d,x,s,ac) { + a = AddUnsigned(a, AddUnsigned(AddUnsigned(H(b, c, d), x), ac)); + return AddUnsigned(RotateLeft(a, s), b); + }; + + function II(a,b,c,d,x,s,ac) { + a = AddUnsigned(a, AddUnsigned(AddUnsigned(I(b, c, d), x), ac)); + return AddUnsigned(RotateLeft(a, s), b); + }; + + function ConvertToWordArray(string) { + var lWordCount; + var lMessageLength = string.length; + var lNumberOfWords_temp1=lMessageLength + 8; + var lNumberOfWords_temp2=(lNumberOfWords_temp1-(lNumberOfWords_temp1 % 64))/64; + var lNumberOfWords = (lNumberOfWords_temp2+1)*16; + var lWordArray=Array(lNumberOfWords-1); + var lBytePosition = 0; + var lByteCount = 0; + while ( lByteCount < lMessageLength ) { + lWordCount = (lByteCount-(lByteCount % 4))/4; + lBytePosition = (lByteCount % 4)*8; + lWordArray[lWordCount] = (lWordArray[lWordCount] | (string.charCodeAt(lByteCount)<>>29; + return lWordArray; + }; + + function WordToHex(lValue) { + var WordToHexValue="",WordToHexValue_temp="",lByte,lCount; + for (lCount = 0;lCount<=3;lCount++) { + lByte = (lValue>>>(lCount*8)) & 255; + WordToHexValue_temp = "0" + lByte.toString(16); + WordToHexValue = WordToHexValue + WordToHexValue_temp.substr(WordToHexValue_temp.length-2,2); + } + return WordToHexValue; + }; + + var x=Array(); + var k,AA,BB,CC,DD,a,b,c,d; + var S11=7, S12=12, S13=17, S14=22; + var S21=5, S22=9 , S23=14, S24=20; + var S31=4, S32=11, S33=16, S34=23; + var S41=6, S42=10, S43=15, S44=21; + + x = ConvertToWordArray(string); + + a = 0x67452301; b = 0xEFCDAB89; c = 0x98BADCFE; d = 0x10325476; + + for (k=0;k