Author: nextgens
Date: 2008-05-31 13:32:54 +0000 (Sat, 31 May 2008)
New Revision: 20157
Added:
trunk/apps/new_installer/res/startssl.pem
Modified:
trunk/apps/new_installer/install.xml
trunk/apps/new_installer/src/Sha1Test.java
Log:
new_installer: commit a new, improved Sha1Test class: it will get the checksums
from emu using a secured connection
Modified: trunk/apps/new_installer/install.xml
===================================================================
--- trunk/apps/new_installer/install.xml 2008-05-31 13:32:53 UTC (rev
20156)
+++ trunk/apps/new_installer/install.xml 2008-05-31 13:32:54 UTC (rev
20157)
@@ -116,6 +116,7 @@
<include name="bin/**/*"/>
<include name="firefox_profile/**/*"/>
<include name="wrapper.conf"/>
+ <include name="startssl.pem"/>
<include name="welcome.html"/>
<include name="welcome.*.html"/>
<include name="dont-close-me.html"/>
Added: trunk/apps/new_installer/res/startssl.pem
===================================================================
--- trunk/apps/new_installer/res/startssl.pem (rev 0)
+++ trunk/apps/new_installer/res/startssl.pem 2008-05-31 13:32:54 UTC (rev
20157)
@@ -0,0 +1,44 @@
+-----BEGIN CERTIFICATE-----
+MIIHyTCCBbGgAwIBAgIBATANBgkqhkiG9w0BAQUFADB9MQswCQYDVQQGEwJJTDEW
+MBQGA1UEChMNU3RhcnRDb20gTHRkLjErMCkGA1UECxMiU2VjdXJlIERpZ2l0YWwg
+Q2VydGlmaWNhdGUgU2lnbmluZzEpMCcGA1UEAxMgU3RhcnRDb20gQ2VydGlmaWNh
+dGlvbiBBdXRob3JpdHkwHhcNMDYwOTE3MTk0NjM2WhcNMzYwOTE3MTk0NjM2WjB9
+MQswCQYDVQQGEwJJTDEWMBQGA1UEChMNU3RhcnRDb20gTHRkLjErMCkGA1UECxMi
+U2VjdXJlIERpZ2l0YWwgQ2VydGlmaWNhdGUgU2lnbmluZzEpMCcGA1UEAxMgU3Rh
+cnRDb20gQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkwggIiMA0GCSqGSIb3DQEBAQUA
+A4ICDwAwggIKAoICAQDBiNsJvGxGfHiflXu1M5Dyc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guucQJAX6V
+um0ABj6y6koQOdjQK/W/7HW/lwLFCRsI3FU34oH7N4RDYiDK51ZLZer+bMEkkySh
+NOsF/5oirpt9P/FlUQqmMGqz9IgcgA38corog14=
+-----END CERTIFICATE-----
Modified: trunk/apps/new_installer/src/Sha1Test.java
===================================================================
--- trunk/apps/new_installer/src/Sha1Test.java 2008-05-31 13:32:53 UTC (rev
20156)
+++ trunk/apps/new_installer/src/Sha1Test.java 2008-05-31 13:32:54 UTC (rev
20157)
@@ -1,53 +1,117 @@
-import java.io.*;
-import java.net.*;
import freenet.support.HexUtil;
-import gnu.crypto.hash.*;
-import com.izforge.izpack.util.AbstractUIProcessHandler;
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.DataInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.security.KeyStore;
+import java.security.MessageDigest;
+import java.security.cert.Certificate;
+import java.security.cert.CertificateFactory;
+import java.util.Collection;
+import java.util.Iterator;
+import javax.net.ssl.SSLException;
+/**
+ * @author Florent Daignière <nextgens at freenetproject.org>
+ */
public class Sha1Test {
+
final static int BUFFERSIZE = 4096;
- final static String base = "http://downloads.freenetproject.org/alpha/";
+ final static String BASE_DOWNLOAD_URL =
"http://downloads.freenetproject.org/alpha/";
+ final static String BASE_CHECKSUM_URL =
"https://checksums.freenetproject.org/alpha/";
+ static boolean useSecureMode = false;
- public static void run(AbstractUIProcessHandler handler, String[] args){
- main(args);
+ public static void main(String[] args) {
+ File TMP_KEYSTORE = null;
+ final String uri = args[0];
+ final String path = (args.length < 2 ? "." : args[1]) + "/";
+ if(uri == null)
+ System.exit(2);
+ if(args.length > 2) {
+ useSecureMode = true;
+ FileInputStream fis = null;
+ try {
+ TMP_KEYSTORE = File.createTempFile("keystore",
".tmp");
+ TMP_KEYSTORE.deleteOnExit();
+ System.out.println("Importing " + args[2] + "
into " + TMP_KEYSTORE);
+
+ KeyStore ks = KeyStore.getInstance("JKS");
+ ks.load(null, new char[0]);
+
+ fis = new FileInputStream(args[2]);
+
+ CertificateFactory cf =
CertificateFactory.getInstance("X.509");
+ Collection c = cf.generateCertificates(fis);
+ Iterator it = c.iterator();
+ while(it.hasNext()) {
+ Certificate cert = (Certificate)
it.next();
+
ks.setCertificateEntry(cert.getPublicKey().toString(), cert);
+ }
+ ks.store(new FileOutputStream(TMP_KEYSTORE),
new char[0]);
+ System.out.println("The CA has been imported
into the trustStore");
+ } catch(Exception e) {
+ System.err.println("Error while handling the CA
:" + e.getMessage());
+ e.printStackTrace();
+ System.exit(3);
+ } finally {
+ try { if(fis != null) fis.close(); }
catch(IOException e) {}
+ }
+
+ System.setProperty("javax.net.ssl.trustStore",
TMP_KEYSTORE.toString());
+ }
+
+ try {
+ realMain(uri, path);
+ } finally {
+ TMP_KEYSTORE.delete();
+ }
}
- public static void main(String[] args) {
- final String URI2 = args[0];
- final String path = (args.length < 2 ? "." : args[1] )+"/";
+ private static void realMain(String uri, String path) {
int count = 0;
- if(URI2 == null) System.exit(2);
+ String filename = (new File(uri)).getName();
+ System.out.println("Fetching " + filename);
- String filename = (new File(URI2)).getName();
- System.out.println("Fetching "+filename);
-
- while(count<10){
- if(count>0)
- System.out.println("Attempt "+count);
- try{
- get(URI2+".sha1", path+filename+".sha1");
- if(sha1test(path+filename)) System.exit(0);
- get(URI2, path+filename);
- }catch(FileNotFoundException e){
+ while(count < 10) {
+ if(count > 0)
+ System.out.println("Attempt " + count);
+ try {
+ get(uri, path + filename, true);
+ if(sha1test(path + filename))
+ System.exit(0);
+ get(uri, path + filename, false);
+ } catch(FileNotFoundException e) {
System.err.println("Not found, let's ignore
that mirror.");
+ } catch(SSLException ssle) {
+ System.err.println("An SSL exception has
occured:" + ssle.getMessage());
+ System.exit(5);
}
count++;
- try{
+ try {
Thread.sleep(5000);
- }catch(InterruptedException e){}
+ } catch(InterruptedException e) {
+ }
}
System.err.println("No mirror is available at the moment,
please try again later");
System.exit(1);
}
public static boolean sha1test(String file) {
- File shaFile = new File(file+".sha1");
+ File shaFile = new File(file + ".sha1");
File realFile = new File(file);
if(!shaFile.exists() || !realFile.exists() ||
!realFile.canRead() || !shaFile.canRead())
return false;
- Sha160 hash=new Sha160();
- try{
+ try {
+ MessageDigest hash = MessageDigest.getInstance("SHA-1");
FileInputStream fis = null;
BufferedInputStream bis = null;
String result = "";
@@ -59,12 +123,12 @@
bis = new BufferedInputStream(fis);
int len = 0;
byte[] buffer = new byte[BUFFERSIZE];
- while ((len = bis.read(buffer)) > -1) {
- hash.update(buffer,0,len);
+ while((len = bis.read(buffer)) > -1) {
+ hash.update(buffer, 0, len);
}
} finally {
- if (bis != null) bis.close();
- if (fis != null) fis.close();
+ try{ if(bis != null) bis.close(); } catch
(IOException e) {}
+ try{ if(fis != null) fis.close(); } catch
(IOException e) {}
}
// We read the hash-file
@@ -73,62 +137,66 @@
bis = new BufferedInputStream(fis);
int len = 0;
byte[] buffer = new byte[BUFFERSIZE];
- while ((len = bis.read(buffer)) > -1) {
- result+=new String(buffer,0,len);
+ while((len = bis.read(buffer)) > -1) {
+ result += new String(buffer, 0, len);
}
} finally {
- if (bis != null) bis.close();
- if (fis != null) fis.close();
+ try{ if(bis != null) bis.close(); } catch
(IOException e) {}
+ try{ if(fis != null) fis.close(); } catch
(IOException e) {}
}
// now we compare
- byte[] digest=new byte[160];
- digest=hash.digest();
+ byte[] digest = new byte[160];
+ digest = hash.digest();
- int i=result.indexOf(' ');
- result=result.substring(0,i);
+ int i = result.indexOf(' ');
+ result = result.substring(0, i);
return
result.equalsIgnoreCase(HexUtil.bytesToHex(digest));
- }catch (Exception e){
+ } catch(Exception e) {
return false;
}
}
-
- public static void get(String file, String filename) throws
FileNotFoundException{
+ public static void get(String file, String filename, boolean checksum)
throws FileNotFoundException, SSLException {
URL url;
DataInputStream dis;
InputStream is = null;
BufferedOutputStream os = null;
try {
- url = new URL(base+file);
- is = url.openStream();
+ if(checksum)
+ url = new URL((useSecureMode ?
BASE_CHECKSUM_URL : BASE_DOWNLOAD_URL) + file + ".sha1");
+ else
+ url = new URL(BASE_DOWNLOAD_URL + file);
+ System.out.println(url);
+ URLConnection connection = url.openConnection();
+ is = connection.getInputStream();
dis = new DataInputStream(new BufferedInputStream(is));
- File f = new File(filename);
+ File f = new File(filename + (checksum ? ".sha1" : ""));
os = new BufferedOutputStream(new FileOutputStream(f));
- int b = 0;
- while ((b = dis.read()) != -1) {
- os.write(b);
+ int length = 0, offset = 0;
+ byte[] buffer = new byte[BUFFERSIZE];
+ while((length = dis.read(buffer)) != -1) {
+ os.write(buffer,offset, length);
+ offset += length;
}
os.flush();
- } catch (MalformedURLException mue) {
+ } catch(MalformedURLException mue) {
System.err.println("Ouch - a MalformedURLException
happened ; please report it.");
mue.printStackTrace();
System.exit(2);
- } catch (FileNotFoundException e) {
+ } catch(FileNotFoundException e) {
throw e;
- } catch (IOException ioe) {
- System.err.println("Caught :"+ioe.getMessage());
+ } catch(SSLException sslE) {
+ throw sslE;
+ } catch(IOException ioe) {
+ System.err.println("Caught :" + ioe.getMessage());
ioe.printStackTrace();
} finally {
- try {
- if(is != null) is.close();
- } catch (IOException ioe) {}
- try {
- if(os != null) os.close();
- } catch (IOException ioe) {}
+ try { if(is != null) is.close(); } catch(IOException
ioe) {}
+ try { if(os != null) os.close(); } catch(IOException
ioe) {}
}
}
}