[LON-CAPA-cvs] cvs: loncom / lonenc.pm

albertel lon-capa-cvs@mail.lon-capa.org
Mon, 20 Dec 2004 19:26:53 -0000


albertel		Mon Dec 20 14:26:53 2004 EDT

  Modified files:              
    /loncom	lonenc.pm 
  Log:
  - add noise to the thing to encrypt so that the same things look different
  
  
Index: loncom/lonenc.pm
diff -u loncom/lonenc.pm:1.8 loncom/lonenc.pm:1.9
--- loncom/lonenc.pm:1.8	Fri Dec 17 16:44:19 2004
+++ loncom/lonenc.pm	Mon Dec 20 14:26:53 2004
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # URL translation for encrypted filenames
 #
-# $Id: lonenc.pm,v 1.8 2004/12/17 21:44:19 albertel Exp $
+# $Id: lonenc.pm,v 1.9 2004/12/20 19:26:53 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -34,6 +34,7 @@
 use Apache::File();
 use Apache::loncommon;
 use Crypt::IDEA;
+use Time::HiRes qw(gettimeofday);
 
 sub handler {
     my $r = shift;
@@ -83,9 +84,31 @@
 				  );
     }
     $ENV{'request.enc'}=1;
+    $decuri=&remove_noise($decuri);
     return substr($decuri,0,$cmdlength);
 }
 
+# add a randomish character after every 4th caharacter
+sub add_noise {
+    my ($uri)=@_;
+    my @noise=split(/(.)/,(&gettimeofday())[1]);
+    my $noisy;
+    my $i;
+    foreach my $chunk (split(/(....)/,$uri)) {
+	$noisy.=$chunk;
+	$noisy.=$noise[($i++)%(scalar@noise)];
+    }
+    return $noisy;
+}
+
+# remove every fifth character
+sub remove_noise {
+    my ($uri)=@_;
+    my $clean;
+    foreach my $chunk (split(/(....)./,$uri)) { $clean.=$chunk; }
+    return $clean;
+}
+
 sub encrypted {
     my $uri=shift;
     if ($ENV{'request.role.adv'}) { return($uri); }
@@ -94,10 +117,13 @@
 	return $uri;
     }
     my $cmdlength=length($uri);
-    $uri.='00000000';
+    # add noise before enc so that that same url's look different
+    $uri=&add_noise($uri);
+    my $noiselength=length($uri);
+    $uri.=time;
     my $encuri='';
     my $cipher=new IDEA $seed;
-    for (my $encidx=0;$encidx<=$cmdlength;$encidx+=8) {
+    for (my $encidx=0;$encidx<=$noiselength;$encidx+=8) {
 	$encuri.=unpack("H16",
 			$cipher->encrypt(substr($uri,$encidx,8)));
     }