Skip to content

Commit

Permalink
Update java.util.jar to openJdk8u60
Browse files Browse the repository at this point in the history
Attributes.java
- header change
- Use of generics
- Updated documentation links
- Deprecated:
 EXTENSION_INSTALLATION, IMPLEMENTATION_VENDOR_ID, IMPLEMENTATION_URL

JarEntry.java
- header change
- Updated javadoc

JarFile.java:
- Entry enumerator moved to seperate static inner class
- Streams implementation
- Non-crucial META-INF/* (not *.SF|*.DSA|*.RSA|*.EC|MANIFEST.MF) files are not
passed to JarVerifier in .intializeVerifier() call. Otherwise we could signal
the end of META-INF parsing (due to changes in JarVerifier).
- Refactoring of hasClassPathAttribute, divided into
many methods
- Android-changed: Commented out isKnownNotToHaveSpecialAttributes()
method that doesn't make sense on android

JarOutputStream.java
- Header change
- Replaced a use of "& 0xff" with a cleaner conversion to unsigned int

JarVerifier.java
- Use of generics
- beginEntry explicitly omits META-INF manifest and index signature
check (So they can be passed to beginEntry without side-effects)
- beginEntry process properly non-crucial META-INF/ entries (not
*.SF|*.DSA|*.RSA|*.EC|MANIFEST.MF) and checks their signatures
(added a test for that)
- Change from "Enhance signed jar verification": .entryNames
treats .findMatchingSigners(c) null result as empty array
(probably a bug fix).

Manifest.java
- Use of generics
- Replaced a use of "& 0xff" with a cleaner conversion to unsigned int

Pack200.java
- Copyright update
- javadoc formating changes
- addPropertyChangeListener & removePropertyChangeListener gained empty default
implementation and deprecated

SignatureFileVerifier.java:
- uncommented isSigningRelated (requried by JarFile)

Test: CtsLibcoreTestCases
Change-Id: I56c59fac628c97a8b7c6967a43c0e23c8b068120
  • Loading branch information
pszc committed Dec 8, 2016
1 parent c949b53 commit 03d2687
Show file tree
Hide file tree
Showing 11 changed files with 398 additions and 203 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import java.security.cert.Certificate;
import java.security.cert.X509Certificate;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.Vector;
Expand Down Expand Up @@ -1124,4 +1125,45 @@ protected Object engineGetParameter(String param) throws InvalidParameterExcepti
}
}
}

/**
* java.util.jar.JarFile#stream()
*/
public void test_stream() throws Exception {
/*
* Note only (and all of) the following should be contained in the file
* META-INF/ META-INF/MANIFEST.MF Blah.txt foo/ foo/bar/ foo/bar/A.class
*/
Support_Resources.copyFile(resources, null, jarName);
JarFile jarFile = new JarFile(new File(resources, jarName));

final List<String> names = new ArrayList<>();
jarFile.stream().forEach((ZipEntry entry) -> names.add(entry.getName()));
assertEquals(Arrays.asList("META-INF/", "META-INF/MANIFEST.MF", "Blah.txt", "foo/", "foo/bar/",
"foo/bar/A.class"), names);
jarFile.close();
}


/**
* hyts_metainf.jar contains an additional entry in META-INF (META-INF/bad_checksum.txt),
* that has been altered since jar signing - we expect to detect a mismatching digest.
*/
public void test_metainf_verification() throws Exception {
String jarFilename = "hyts_metainf.jar";
Support_Resources.copyFile(resources, null, jarFilename);
try (JarFile jarFile = new JarFile(new File(resources, jarFilename))) {

JarEntry jre = new JarEntry("META-INF/bad_checksum.txt");
InputStream in = jarFile.getInputStream(jre);

byte[] buffer = new byte[1024];
try {
while (in.available() > 0) {
in.read(buffer);
}
fail("SecurityException expected");
} catch (SecurityException expected) {}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -403,4 +403,35 @@ public void test_getNextEntry() throws Exception {
// expected
}
}

/**
* hyts_metainf.jar contains an additional entry in META-INF (META-INF/bad_checksum.txt),
* that has been altered since jar signing - we expect to detect a mismatching digest.
*/
public void test_metainf_verification() throws Exception {
String jarFilename = "hyts_metainf.jar";
File resources = Support_Resources.createTempFolder();
Support_Resources.copyFile(resources, null, jarFilename);
InputStream is = Support_Resources.getStream(jarFilename);

try (JarInputStream jis = new JarInputStream(is, true)) {
JarEntry je = jis.getNextJarEntry();
je = jis.getNextJarEntry();
je = jis.getNextJarEntry();
je = jis.getNextJarEntry();

if (!je.getName().equals("META-INF/bad_checksum.txt")) {
fail("Expected META-INF/bad_checksum.txt as a 4th entry, got:" + je.getName());
}
byte[] buffer = new byte[1024];
int length = 0;
try {
while (length >= 0) {
length = jis.read(buffer);
}
fail("SecurityException expected");
} catch (SecurityException expected) {}
}
}

}
43 changes: 26 additions & 17 deletions ojluni/src/main/java/java/util/jar/Attributes.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2014 The Android Open Source Project
* Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -72,7 +72,7 @@ public Attributes() {
* @param size the initial number of attributes
*/
public Attributes(int size) {
map = new HashMap(size);
map = new HashMap<>(size);
}

/**
Expand All @@ -82,7 +82,7 @@ public Attributes(int size) {
* @param attr the specified Attributes
*/
public Attributes(Attributes attr) {
map = new HashMap(attr);
map = new HashMap<>(attr);
}


Expand Down Expand Up @@ -297,9 +297,9 @@ public Object clone() {
* XXX Need to handle UTF8 values and break up lines longer than 72 bytes
*/
void write(DataOutputStream os) throws IOException {
Iterator it = entrySet().iterator();
Iterator<Map.Entry<Object, Object>> it = entrySet().iterator();
while (it.hasNext()) {
Map.Entry e = (Map.Entry)it.next();
Map.Entry<Object, Object> e = it.next();
StringBuffer buffer = new StringBuffer(
((Name)e.getKey()).toString());
buffer.append(": ");
Expand Down Expand Up @@ -341,9 +341,9 @@ void writeMain(DataOutputStream out) throws IOException

// write out all attributes except for the version
// we wrote out earlier
Iterator it = entrySet().iterator();
Iterator<Map.Entry<Object, Object>> it = entrySet().iterator();
while (it.hasNext()) {
Map.Entry e = (Map.Entry)it.next();
Map.Entry<Object, Object> e = it.next();
String name = ((Name)e.getKey()).toString();
if ((version != null) && ! (name.equalsIgnoreCase(vername))) {

Expand Down Expand Up @@ -500,7 +500,7 @@ private static boolean isDigit(char c) {
*/
public boolean equals(Object o) {
if (o instanceof Name) {
Comparator c = ASCIICaseInsensitiveComparator.CASE_INSENSITIVE_ORDER;
Comparator<String> c = ASCIICaseInsensitiveComparator.CASE_INSENSITIVE_ORDER;
return c.compare(name, ((Name)o).name) == 0;
} else {
return false;
Expand Down Expand Up @@ -551,8 +551,8 @@ public String toString() {
* <code>Name</code> object for <code>Class-Path</code>
* manifest attribute. Bundled extensions can use this attribute
* to find other JAR files containing needed classes.
* @see <a href="{@docRoot}openjdk-redirect.html?v=8&path=/technotes/guides/extensions/spec.html#bundled">
* Extensions Specification</a>
* @see <a href="{@docRoot}openjdk-redirect.html?v=8&path=/technotes/guides/jar/jar.html#classpath">
* JAR file specification</a>
*/
public static final Name CLASS_PATH = new Name("Class-Path");

Expand All @@ -568,8 +568,8 @@ public String toString() {
/**
* <code>Name</code> object for <code>Sealed</code> manifest attribute
* used for sealing.
* @see <a href="{@docRoot}openjdk-redirect.html?v=8&path=/technotes/guides/extensions/spec.html#sealing">
* Extension Sealing</a>
* @see <a href="{@docRoot}openjdk-redirect.html?v=8&path=/technotes/guides/jar/jar.html#sealing">
* Package Sealing</a>
*/
public static final Name SEALED = new Name("Sealed");

Expand All @@ -592,9 +592,12 @@ public String toString() {
/**
* <code>Name</code> object for <code>Extension-Name</code> manifest attribute
* used for declaring dependencies on installed extensions.
* @deprecated Extension mechanism will be removed in a future release.
* Use class path instead.
* @see <a href="{@docRoot}openjdk-redirect.html?v=8&path=/technotes/guides/extensions/spec.html#dependency">
* Installed extension dependency</a>
*/
@Deprecated
public static final Name EXTENSION_INSTALLATION = new Name("Extension-Installation");

/**
Expand Down Expand Up @@ -624,17 +627,23 @@ public String toString() {
/**
* <code>Name</code> object for <code>Implementation-Vendor-Id</code>
* manifest attribute used for package versioning.
* @see <a href="{@docRoot}openjdk-redirect.html?v=8&path=/technotes/guides/versioning/spec/versioning2.html#wp90779">
* Java Product Versioning Specification</a>
* @deprecated Extension mechanism will be removed in a future release.
* Use class path instead.
* @see <a href="{@docRoot}openjdk-redirect.html?v=8&path=/technotes/guides/extensions/versioning.html#applet">
* Optional Package Versioning</a>
*/
@Deprecated
public static final Name IMPLEMENTATION_VENDOR_ID = new Name("Implementation-Vendor-Id");

/**
* <code>Name</code> object for <code>Implementation-Vendor-URL</code>
* <code>Name</code> object for <code>Implementation-URL</code>
* manifest attribute used for package versioning.
* @see <a href="{@docRoot}openjdk-redirect.html?v=8&path=/technotes/guides/versioning/spec/versioning2.html#wp90779">
* Java Product Versioning Specification</a>
* @deprecated Extension mechanism will be removed in a future release.
* Use class path instead.
* @see <a href="{@docRoot}openjdk-redirect.html?v=8&path=/technotes/guides/extensions/versioning.html#applet">
* Optional Package Versioning</a>
*/
@Deprecated
public static final Name IMPLEMENTATION_URL = new Name("Implementation-URL");

/**
Expand Down
3 changes: 2 additions & 1 deletion ojluni/src/main/java/java/util/jar/JarEntry.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2005, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -81,6 +81,7 @@ public JarEntry(JarEntry je) {
*
* @return the <code>Manifest</code> <code>Attributes</code> for this
* entry, or <code>null</code> if none
* @throws IOException if an I/O error has occurred
*/
public Attributes getAttributes() throws IOException {
return attr;
Expand Down
Loading

0 comments on commit 03d2687

Please sign in to comment.