Author: saces
Date: 2009-04-14 11:11:34 +0000 (Tue, 14 Apr 2009)
New Revision: 26778

Modified:
   trunk/freenet/src/freenet/pluginmanager/PluginDownLoader.java
   trunk/freenet/src/freenet/pluginmanager/PluginDownLoaderFile.java
   trunk/freenet/src/freenet/pluginmanager/PluginDownLoaderFreenet.java
   trunk/freenet/src/freenet/pluginmanager/PluginDownLoaderURL.java
   trunk/freenet/src/freenet/pluginmanager/PluginManager.java
Log:
add support for SHA-256 digest

Modified: trunk/freenet/src/freenet/pluginmanager/PluginDownLoader.java
===================================================================
--- trunk/freenet/src/freenet/pluginmanager/PluginDownLoader.java       
2009-04-14 10:49:50 UTC (rev 26777)
+++ trunk/freenet/src/freenet/pluginmanager/PluginDownLoader.java       
2009-04-14 11:11:34 UTC (rev 26778)
@@ -31,5 +31,8 @@
        abstract String getPluginName(String source) throws 
PluginNotFoundException;
        
        abstract String getSHA1sum() throws PluginNotFoundException;
+       
+       abstract String getSHA256sum() throws PluginNotFoundException;
+       
 
 }

Modified: trunk/freenet/src/freenet/pluginmanager/PluginDownLoaderFile.java
===================================================================
--- trunk/freenet/src/freenet/pluginmanager/PluginDownLoaderFile.java   
2009-04-14 10:49:50 UTC (rev 26777)
+++ trunk/freenet/src/freenet/pluginmanager/PluginDownLoaderFile.java   
2009-04-14 11:11:34 UTC (rev 26778)
@@ -32,5 +32,10 @@
        String getSHA1sum() throws PluginNotFoundException {
                return null;
        }
+       
+       @Override
+       String getSHA256sum() throws PluginNotFoundException {
+               return null;
+       }
 
 }

Modified: trunk/freenet/src/freenet/pluginmanager/PluginDownLoaderFreenet.java
===================================================================
--- trunk/freenet/src/freenet/pluginmanager/PluginDownLoaderFreenet.java        
2009-04-14 10:49:50 UTC (rev 26777)
+++ trunk/freenet/src/freenet/pluginmanager/PluginDownLoaderFreenet.java        
2009-04-14 11:11:34 UTC (rev 26778)
@@ -57,5 +57,10 @@
        String getSHA1sum() throws PluginNotFoundException {
                return null;
        }
+       
+       @Override
+       String getSHA256sum() throws PluginNotFoundException {
+               return null;
+       }
 
 }

Modified: trunk/freenet/src/freenet/pluginmanager/PluginDownLoaderURL.java
===================================================================
--- trunk/freenet/src/freenet/pluginmanager/PluginDownLoaderURL.java    
2009-04-14 10:49:50 UTC (rev 26777)
+++ trunk/freenet/src/freenet/pluginmanager/PluginDownLoaderURL.java    
2009-04-14 11:11:34 UTC (rev 26778)
@@ -47,6 +47,12 @@
                return null;
        }
        
+       @Override
+       String getSHA256sum() throws PluginNotFoundException {
+               return null;
+       }
+
+       
        static InputStream openConnectionCheckRedirects(URLConnection c) throws 
IOException
        {
                boolean redir;

Modified: trunk/freenet/src/freenet/pluginmanager/PluginManager.java
===================================================================
--- trunk/freenet/src/freenet/pluginmanager/PluginManager.java  2009-04-14 
10:49:50 UTC (rev 26777)
+++ trunk/freenet/src/freenet/pluginmanager/PluginManager.java  2009-04-14 
11:11:34 UTC (rev 26778)
@@ -800,9 +800,19 @@
                                                        throw new 
PluginNotFoundException("could not rename temp file to plugin file");
                                                }
 
-                                               String digest = 
pdl.getSHA1sum();
+                                               // try strongest first
+                                               String testsum = null;
+                                               String digest = 
pdl.getSHA256sum();
+                                               if(digest == null) {
+                                                       digest = 
pdl.getSHA1sum();
+                                               } else {
+                                                       testsum = 
getFileDigest(pluginFile, "SHA-256");
+                                               }
+                                               if(digest != null && testsum == 
null) {
+                                                       testsum = 
getFileDigest(pluginFile, "SHA-1");
+                                               } 
+                                               
                                                if(digest != null) {
-                                                       String testsum = 
getFileSHA1(pluginFile);
                                                        
if(!(digest.equalsIgnoreCase(testsum))) {
                                                                
Logger.error(this, "Checksum verification failed, should be " + digest + " but 
was " + testsum);
                                                                throw new 
PluginNotFoundException("Checksum verification failed, should be " + digest + " 
but was " + testsum);
@@ -968,14 +978,14 @@
                }
        }
 
-       private String getFileSHA1(File file) throws PluginNotFoundException {
+       private String getFileDigest(File file, String digest) throws 
PluginNotFoundException {
                final int BUFFERSIZE = 4096;
                MessageDigest hash = null;
                FileInputStream fis = null;
                BufferedInputStream bis = null;
 
                try {
-                       hash = MessageDigest.getInstance("SHA-1");
+                       hash = MessageDigest.getInstance(digest);
                        // We compute the hash
                        // 
http://java.sun.com/developer/TechTips/1998/tt0915.html#tip2
                        fis = new FileInputStream(file);

_______________________________________________
cvs mailing list
[email protected]
http://emu.freenetproject.org/cgi-bin/mailman/listinfo/cvs

Reply via email to