/** * process the signature block file. Goes through the .SF file * and adds code signers for each section where the .SF section * hash was verified against the Manifest section. * * */ public void process(Hashtable<String, CodeSigner[]> signers, List<Object> manifestDigests) throws IOException, SignatureException, NoSuchAlgorithmException, JarException, CertificateException { // calls Signature.getInstance() and MessageDigest.getInstance() // need to use local providers here, see Providers class Object obj = null; try { obj = Providers.startJarVerification(); processImpl(signers, manifestDigests); } finally { Providers.stopJarVerification(obj); } }
/** * Pedantic method that requires the next attribute in the Manifest to be the * "Manifest-Version". This follows the Manifest spec closely but reject some * jar Manifest files out in the wild. */ private static void readVersionInfo(Attributes attr, BufferedReader br) throws IOException { String version_header = Name.MANIFEST_VERSION.toString(); try { String value = expectHeader(version_header, br); attr.putValue(MANIFEST_VERSION, value); } catch (IOException ioe) { throw new JarException("Manifest should start with a " + version_header + ": " + ioe.getMessage()); } }
private static void readAttribute(Attributes attr, String s, BufferedReader br) throws IOException { try { int colon = s.indexOf(": "); String name = s.substring(0, colon); String value_start = s.substring(colon + 2); String value = readHeaderValue(value_start, br); attr.putValue(name, value); } catch (IndexOutOfBoundsException iobe) { throw new JarException("Manifest contains a bad header: " + s); } }
private static Attributes readSectionName(String s, BufferedReader br, Map entries) throws JarException { try { String name = expectHeader(NAME, br, s); Attributes attr = new Attributes(); entries.put(name, attr); return attr; } catch (IOException ioe) { throw new JarException("Section should start with a Name header: " + ioe.getMessage()); } }
private static String expectHeader(String header, BufferedReader br, String s) throws IOException { try { String name = s.substring(0, header.length() + 1); if (name.equalsIgnoreCase(header + ":")) { String value_start = s.substring(header.length() + 2); return readHeaderValue(value_start, br); } } catch (IndexOutOfBoundsException ignored) { } // If we arrive here, something went wrong throw new JarException("unexpected '" + s + "'"); }
String getJdbcDriver() throws JarException { switch (this._DBtype) { case MS_SQL_Server: return "com.microsoft.sqlserver.jdbc.SQLServerDriver"; case Oracle: return "oracle.jdbc.driver.OracleDriver"; case DB2: return "com.ibm.db2.jcc.DB2Driver"; case MySQL: return "com.mysql.jdbc.Driver"; case HSQL: return "org.hsqldb.jdbcDriver"; case Ingres: return "com.ingres.jdbc.IngresDriver"; case Postgres: return "org.postgresql.Driver"; default: break; } throw new JarException("The .jar file for " + this._DBtype.ToString() +" Jdbc Driver not found"); }
public static void readSFManifest(Attributes attr, Map entries, InputStream in) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(in, "UTF-8")); String version_header = Name.SIGNATURE_VERSION.toString(); try { String version = expectHeader(version_header, br); attr.putValue(SIGNATURE_VERSION, version); if (! DEFAULT_SF_VERSION.equals(version)) log.warning("Unexpected version number: " + version + ". Continue (but may fail later)"); } catch (IOException ioe) { throw new JarException("Signature file MUST start with a " + version_header + ": " + ioe.getMessage()); } read_attributes(attr, br); // read individual sections String s = br.readLine(); while (s != null && s.length() > 0) { Attributes eAttr = readSectionName(s, br, entries); read_attributes(eAttr, br); s = br.readLine(); } }
private static String expectHeader(String header, BufferedReader br) throws IOException { String s = br.readLine(); if (s == null) throw new JarException("unexpected end of file"); return expectHeader(header, br, s); }
private static void writeAttributeEntry(Map.Entry entry, OutputStream out) throws IOException { String name = entry.getKey().toString(); String value = entry.getValue().toString(); if (name.equalsIgnoreCase(NAME)) throw new JarException("Attributes cannot be called 'Name'"); if (name.startsWith("From")) throw new JarException("Header cannot start with the four letters 'From'" + name); writeHeader(name, value, out); }
private static void modifyTarget(File originalRuntime, String mergeRenamePrefix, File outputRuntime, boolean watermark, byte[]... classFiles) throws JarException, IOException { Engine engine = new Engine(originalRuntime, mergeRenamePrefix); for(byte[] classFile : classFiles){ engine.process(classFile); } if(watermark){ engine.addFile(WATERMARK, WATERMARK.getBytes(), true); } engine.save(outputRuntime); }
/** * @tests java.util.jar.JarException#JarException(java.lang.String) */ public void test_Constructor() throws Exception { JarException ex = new JarException(); JarException ex1 = new JarException("Test string"); JarException ex2 = new JarException(null); assertNotSame(ex, ex1); assertNotSame(ex.getMessage(), ex1.getMessage()); assertNotSame(ex, ex2); assertSame(ex.getMessage(), ex2.getMessage()); }
public Engine(File jar, String mergeRenamePrefix) throws JarException, IOException { this.mergeRenamePrefix = mergeRenamePrefix; this.jarModifier = new JarModifier(jar); this.jarName = jar.getName(); this.originalEntries = new HashSet<String>(jarModifier.getJarEntrySet()); }
public Engine(File jar, String mergeRenamePrefix, ClassLoader[] classLoaders) throws JarException, IOException { this(jar, mergeRenamePrefix); this.classLoaders = classLoaders; }