1 21 22 package org.apache.derby.impl.services.reflect; 23 24 import org.apache.derby.iapi.reference.MessageId; 25 import org.apache.derby.iapi.error.StandardException; 26 import org.apache.derby.iapi.services.i18n.MessageService; 27 28 import java.util.zip.ZipEntry ; 29 import java.util.zip.ZipInputStream ; 30 import java.io.IOException ; 31 import java.io.File ; 32 import java.io.InputStream ; 33 34 import java.security.cert.Certificate ; 36 import java.security.cert.X509Certificate ; 37 import java.security.GeneralSecurityException ; 38 39 40 41 45 46 final class JarFileJava2 extends JarFile { 47 48 JarFileJava2() { 49 super(); 50 } 51 52 JarFileJava2(String [] name) { 53 super(name); 54 } 55 56 JarFile newJarFile(String [] name) { 57 return new JarFileJava2(name); 58 } 59 60 void initialize(File jarFile) throws IOException { 61 62 java.util.jar.JarFile jf = new java.util.jar.JarFile (jarFile); 63 64 zip = jf; 66 } 67 68 ZipEntry getEntry(String entryName) { 69 return ((java.util.jar.JarFile ) zip).getJarEntry(entryName); 70 } 71 ZipInputStream getZipOnStream(InputStream in) throws IOException { 72 return new java.util.jar.JarInputStream (in); 73 } 74 ZipEntry getNextEntry(ZipInputStream in) throws IOException { 75 return ((java.util.jar.JarInputStream ) in).getNextJarEntry(); 76 } 77 78 byte[] readData(ZipEntry ze, InputStream in, String className) throws IOException { 79 try { 80 return super.readData(ze, in, className); 81 } catch (SecurityException se) { 82 throw handleException(se, className); 83 } 84 } 85 86 Object [] getSigners(String className, ZipEntry ze) throws IOException { 87 Exception e; 88 89 try { 90 Certificate [] list = ((java.util.jar.JarEntry ) ze).getCertificates(); 91 if ((list == null) || (list.length == 0)) { 92 return null; 93 } 94 95 for (int i = 0; i < list.length; i++) { 96 if (!(list[i] instanceof X509Certificate )) { 97 String msg = MessageService.getTextMessage(MessageId.CM_UNKNOWN_CERTIFICATE, className, getJarName()); 98 99 throw new SecurityException (msg); 100 } 101 102 X509Certificate cert = (X509Certificate ) list[i]; 103 104 cert.checkValidity(); 105 } 106 107 return list; 108 109 } catch (GeneralSecurityException gse) { 110 e = gse; 115 } 116 throw handleException(e, className); 117 } 118 119 private SecurityException handleException(Exception e, String className) { 120 String msg = MessageService.getTextMessage(MessageId.CM_SECURITY_EXCEPTION, className, getJarName(), e.getLocalizedMessage()); 121 return new SecurityException (msg); 122 } 123 } 124 | Popular Tags |