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

www lon-capa-cvs@mail.lon-capa.org
Wed, 31 Mar 2004 05:29:23 -0000


www		Wed Mar 31 00:29:23 2004 EDT

  Modified files:              
    /loncom	lonenc.pm 
  Log:
  Sort of works now.
  
  
Index: loncom/lonenc.pm
diff -u loncom/lonenc.pm:1.1 loncom/lonenc.pm:1.2
--- loncom/lonenc.pm:1.1	Tue Mar 30 23:38:06 2004
+++ loncom/lonenc.pm	Wed Mar 31 00:29:23 2004
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # URL translation for encrypted filenames
 #
-# $Id: lonenc.pm,v 1.1 2004/03/31 04:38:06 www Exp $
+# $Id: lonenc.pm,v 1.2 2004/03/31 05:29:23 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -55,18 +55,24 @@
     return FORBIDDEN;
 }
 
+sub encryptseed {
+    my $seed=$ENV{'course.'.$ENV{'request.course.id'}.'.internal.encseed'};
+    $seed=~s/[^0-9a-f]/0/g;
+    $seed.='0123456789abcdef';
+    $seed=substr($seed.$seed,0,32);
+    return pack("H32",$seed);
+}
+
 sub unencrypted {
     my $uri=shift;
     $uri=~s/^\/enc\/(\d+)\///;
-    &Apache::lonnet::logthis($uri);
     my $cmdlength=$1;
-    unless ($ENV{'course.'.$ENV{'request.course.id'}.'.internal.encseed'}) {
+    my $seed=&encryptseed();
+    unless ($seed) {
 	return '/'.$uri;
     }
     $uri=&Apache::lonnet::unescape($uri);
-    my $cipher=
-	new IDEA $ENV{'course.'.$ENV{'request.course.id'}.'.internal.encseed'};
-    &Apache::lonnet::logthis($ENV{'course.'.$ENV{'request.course.id'}.'.internal.encseed'});
+    my $cipher=new IDEA $seed;
     my $decuri='';
     for (my $encidx=0;$encidx<length($uri);$encidx+=16) {
 	$decuri.=$cipher->decrypt(
@@ -78,10 +84,14 @@
 
 sub encrypted {
     my $uri=shift;
+    my $seed=&encryptseed();
+    unless ($seed) {
+	return $uri;
+    }
     my $cmdlength=length($uri);
+    $uri.='00000000';
     my $encuri='';
-    my $cipher=
-	new IDEA $ENV{'course.'.$ENV{'request.course.id'}.'.internal.encseed'};
+    my $cipher=new IDEA $seed;
     for (my $encidx=0;$encidx<=$cmdlength;$encidx+=8) {
 	$encuri.=unpack("H16",
 			$cipher->encrypt(substr($uri,$encidx,8)));