db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r482850 - in /db/derby/code/trunk: java/engine/org/apache/derby/impl/services/reflect/ tools/jar/
Date Wed, 06 Dec 2006 00:45:47 GMT
Author: djd
Date: Tue Dec  5 16:45:46 2006
New Revision: 482850

URL: http://svn.apache.org/viewvc?view=rev&rev=482850
Log:
DERBY-538 (partial) Move the jar based code from JarFileJava2 to InstalledJar and remove JarFileJava2.
Since J2ME/CDC/Foundation and J2SE both support java.util.jar there is no need to have a zip
based
implementation (which was for the JDK 1.1 no longer supported). More cleanup will be done
to completely
switch over to java.util.jar.

Removed:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/services/reflect/JarFileJava2.java
Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/services/reflect/InstalledJar.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/services/reflect/JarLoader.java
    db/derby/code/trunk/tools/jar/extraDBMSclasses.properties

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/services/reflect/InstalledJar.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/services/reflect/InstalledJar.java?view=diff&rev=482850&r1=482849&r2=482850
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/services/reflect/InstalledJar.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/services/reflect/InstalledJar.java
Tue Dec  5 16:45:46 2006
@@ -21,6 +21,11 @@
 
 package org.apache.derby.impl.services.reflect;
 
+import java.security.GeneralSecurityException;
+import java.security.cert.Certificate;
+import java.security.cert.X509Certificate;
+import java.util.jar.JarFile;
+import java.util.jar.JarInputStream;
 import java.util.zip.ZipFile;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipInputStream;
@@ -30,6 +35,8 @@
 import java.io.InputStream;
 import java.io.ByteArrayOutputStream;
 import org.apache.derby.iapi.util.IdUtil;
+import org.apache.derby.iapi.reference.MessageId;
+import org.apache.derby.iapi.services.i18n.MessageService;
 import org.apache.derby.iapi.services.io.InputStreamUtil;
 
 /**
@@ -39,9 +46,9 @@
  * The source for the Jar is either a File (database from a file system)
  * or an InputStream (database is in a jar file itself).
  */
-abstract class InstalledJar {
+final class InstalledJar {
 	final String[] name;
-	protected ZipFile zip;
+	private JarFile jar;
 	boolean isStream;
 
 	InstalledJar(String[] name) {
@@ -54,62 +61,102 @@
 
 
 	final boolean isZip() {
-		return zip != null;
+		return jar != null;
 	}
 
 	final ZipFile getZip() {
-		return zip;
+		return jar;
 	}
 
 	void initialize(File jarFile) throws IOException {
-		zip = new ZipFile(jarFile);
+        jar = new java.util.jar.JarFile(jarFile);
 	}
 
 	final void setInvalid() {
-		if (zip != null) {
+		if (jar != null) {
 			try {
-				zip.close();
+				jar.close();
 			} catch (IOException ioe) {
 			}
-			zip = null;
+			jar = null;
 
 		}
 		isStream = false;
 	}
 
 	ZipEntry getEntry(String entryName) {
-		return zip.getEntry(entryName);
+		return jar.getJarEntry(entryName);
 	}
 	ZipInputStream getZipOnStream(InputStream in) throws IOException {
-		return new ZipInputStream(in);
+		return new JarInputStream(in);
 	}
 	ZipEntry getNextEntry(ZipInputStream in) throws IOException {
-		return in.getNextEntry();
+		return ((JarInputStream) in).getNextJarEntry();
 	}
 
 	byte[] readData(ZipEntry ze, InputStream in, String className) throws IOException {
 
-		int size = (int) ze.getSize();
+		try {
+            int size = (int) ze.getSize();
 
-		if (size != -1) {
-			byte[] data = new byte[size];
+            if (size != -1) {
+            	byte[] data = new byte[size];
 
-			InputStreamUtil.readFully(in, data, 0, size);
+            	InputStreamUtil.readFully(in, data, 0, size);
 
-			return data;
-		}
-
-		// unknown size
-		byte[] data = new byte[1024];
-		ByteArrayOutputStream os = new ByteArrayOutputStream(1024);
-		int r;
-		while ((r = in.read(data)) != -1) {
-			os.write(data, 0, r);
-		}
-
-		data = os.toByteArray();
-		return data;
-	}
-
-	abstract Object[] getSigners(String className, ZipEntry ze) throws IOException;
+            	return data;
+            }
+
+            // unknown size
+            byte[] data = new byte[1024];
+            ByteArrayOutputStream os = new ByteArrayOutputStream(1024);
+            int r;
+            while ((r = in.read(data)) != -1) {
+            	os.write(data, 0, r);
+            }
+
+            data = os.toByteArray();
+            return data;
+        } catch (SecurityException se) {
+            throw handleException(se, className);
+        }
+	}
+
+    Object[] getSigners(String className, ZipEntry ze) throws IOException {
+        Exception e;
+
+        try {
+            Certificate[] list = ((java.util.jar.JarEntry) ze).getCertificates();
+            if ((list == null) || (list.length == 0)) {
+                return null;
+            }
+
+            for (int i = 0; i < list.length; i++) {
+                if (!(list[i] instanceof X509Certificate)) {
+                    String msg = MessageService.getTextMessage(MessageId.CM_UNKNOWN_CERTIFICATE,
className, getJarName());
+
+                    throw new SecurityException(msg);
+                }
+
+                X509Certificate cert = (X509Certificate) list[i];
+
+                cert.checkValidity();
+            }
+
+            return list;
+
+        } catch (GeneralSecurityException gse) {
+            // convert this into an unchecked security
+            // exception. Unchecked as eventually it has
+            // to pass through a method that's only throwing
+            // ClassNotFoundException
+            e = gse;
+        }
+        throw handleException(e, className);
+    }
+
+    private SecurityException handleException(Exception e, String className) {
+        String msg = MessageService.getTextMessage(MessageId.CM_SECURITY_EXCEPTION, className,
getJarName(), e.getLocalizedMessage());
+        return new SecurityException(msg);
+    }
 }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/services/reflect/JarLoader.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/services/reflect/JarLoader.java?view=diff&rev=482850&r1=482849&r2=482850
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/services/reflect/JarLoader.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/services/reflect/JarLoader.java
Tue Dec  5 16:45:46 2006
@@ -49,7 +49,7 @@
 	JarLoader(UpdateLoader updateLoader, String[] name, HeaderPrintWriter vs) {
 
 		this.updateLoader = updateLoader;
-		this.jf = new JarFileJava2(name);
+		this.jf = new InstalledJar(name);
 		this.vs = vs;
 	}
 
@@ -265,7 +265,7 @@
 
 		jf.setInvalid();
 		updateLoader = null;
-		return newJarFile ? new JarFileJava2(jf.name) : null;
+		return newJarFile ? new InstalledJar(jf.name) : null;
 	}
 
 	/*

Modified: db/derby/code/trunk/tools/jar/extraDBMSclasses.properties
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/tools/jar/extraDBMSclasses.properties?view=diff&rev=482850&r1=482849&r2=482850
==============================================================================
--- db/derby/code/trunk/tools/jar/extraDBMSclasses.properties (original)
+++ db/derby/code/trunk/tools/jar/extraDBMSclasses.properties Tue Dec  5 16:45:46 2006
@@ -44,8 +44,6 @@
 derby.module.diag.diagnosticable.generic=org.apache.derby.iapi.services.diag.DiagnosticableGeneric
 derby.module.diag.diagnostic.util=org.apache.derby.iapi.services.diag.DiagnosticUtil
 
-derby.module.classFactory.signedJar.jdk12=org.apache.derby.impl.services.reflect.JarFileJava2
-
 derby.module.internalUtil.classsizecatalogimpl=org.apache.derby.iapi.services.cache.ClassSizeCatalog
 
 derby.module.catalog.getprocedurecolumns=org.apache.derby.catalog.GetProcedureColumns



Mime
View raw message