Changed how packed actions are saved (in the zip extra data field now). fixed lpgl hashing method
This commit is contained in:
parent
1d8a329235
commit
ff8c718a6b
@ -169,12 +169,15 @@ public class Crypto {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CUSTOM_HEADER USE
|
// CUSTOM_HEADER USE
|
||||||
private static byte[] CUSTOM_HEADER = new byte[] {-54, -98, 98, 120};
|
private static byte[] CUSTOM_HEADER = new byte[] {-2, -54, -54, -98};
|
||||||
/**
|
/**
|
||||||
* Specifically, to return the hash of the ALL files/directories inside the jar, minus the action specified (LGPL) files.
|
* Specifically, to return the hash of the ALL files/directories inside the jar, minus the action specified (LGPL) files.
|
||||||
*/
|
*/
|
||||||
public static final byte[] hashJarContentsExcludeAction(JarFile jarFile, Digest digest, int action) throws IOException {
|
public static final byte[] hashJarContentsExcludeAction(File jarDestFilename, Digest digest, int action) throws IOException {
|
||||||
Enumeration<JarEntry> jarElements = jarFile.entries();
|
JarFile jarDestFile = new JarFile(jarDestFilename);
|
||||||
|
|
||||||
|
try {
|
||||||
|
Enumeration<JarEntry> jarElements = jarDestFile.entries();
|
||||||
|
|
||||||
boolean okToHash = false;
|
boolean okToHash = false;
|
||||||
boolean hasAction = false;
|
boolean hasAction = false;
|
||||||
@ -191,55 +194,67 @@ public class Crypto {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
okToHash = true;
|
// data with NO extra data will NOT BE HASHED
|
||||||
|
// data that matches our action bitmask WILL NOT BE HASHED
|
||||||
|
|
||||||
|
okToHash = false;
|
||||||
hasAction = false;
|
hasAction = false;
|
||||||
|
|
||||||
byte[] extraData = jarEntry.getExtra();
|
byte[] extraData = jarEntry.getExtra();
|
||||||
if (extraData != null && extraData.length > 4) {
|
if (extraData == null || extraData.length == 0) {
|
||||||
|
okToHash = false;
|
||||||
|
} else if (extraData.length >= 4) {
|
||||||
for (int i = 0; i < CUSTOM_HEADER.length; i++) {
|
for (int i = 0; i < CUSTOM_HEADER.length; i++) {
|
||||||
if (extraData[i] != CUSTOM_HEADER[i]) {
|
if (extraData[i] != CUSTOM_HEADER[i]) {
|
||||||
// can hash if we don't have an action assigned (LGPL will ALWAYS have an action assigned)
|
throw new RuntimeException("Unexpected extra data in zip assigned. Aborting");
|
||||||
okToHash = false;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// this means we matched our header
|
// this means we matched our header
|
||||||
int fileAction = 0;
|
|
||||||
|
|
||||||
if (okToHash) {
|
|
||||||
if (extraData[4] > 0) {
|
if (extraData[4] > 0) {
|
||||||
hasAction = true;
|
hasAction = true;
|
||||||
// we have an ACTION describing how it was compressed, etc
|
|
||||||
fileAction = LittleEndian.Int_.fromBytes(new byte[] {extraData[5], extraData[6], extraData[7], extraData[8]});
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((fileAction & action) == action) {
|
// we have an ACTION describing how it was compressed, etc
|
||||||
okToHash = false;
|
int fileAction = LittleEndian.Int_.fromBytes(new byte[] {extraData[5], extraData[6], extraData[7], extraData[8]});
|
||||||
|
|
||||||
|
if ((fileAction & action) != action) {
|
||||||
|
okToHash = true;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
okToHash = true;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
throw new RuntimeException("Unexpected extra data in zip assigned. Aborting");
|
||||||
}
|
}
|
||||||
|
|
||||||
// skips hashing lgpl files. (technically, whatever our action bitmask is...)
|
// skips hashing lgpl files. (technically, whatever our action bitmask is...)
|
||||||
// we want to hash everything BY DEFAULT. we ALSO want to hash the NAME, LOAD ACTION TYPE, and the contents
|
// we want to hash everything BY DEFAULT. we ALSO want to hash the NAME, LOAD ACTION TYPE, and the contents
|
||||||
if (okToHash) {
|
if (okToHash) {
|
||||||
|
// System.err.println("HASHING: " + name);
|
||||||
// hash the file name
|
// hash the file name
|
||||||
byte[] bytes = name.getBytes(OS.US_ASCII);
|
byte[] bytes = name.getBytes(OS.US_ASCII);
|
||||||
digest.update(bytes, 0, bytes.length);
|
digest.update(bytes, 0, bytes.length);
|
||||||
|
|
||||||
if (hasAction) {
|
if (hasAction) {
|
||||||
// hash the action
|
// hash the action - since we don't want to permit anyone to change this after we sign the file
|
||||||
digest.update(extraData, 5, 4);
|
digest.update(extraData, 5, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
// hash the contents
|
// hash the contents
|
||||||
InputStream inputStream = jarFile.getInputStream(jarEntry);
|
InputStream inputStream = jarDestFile.getInputStream(jarEntry);
|
||||||
while ((read = inputStream.read(buffer)) > 0) {
|
while ((read = inputStream.read(buffer)) > 0) {
|
||||||
digest.update(buffer, 0, read);
|
digest.update(buffer, 0, read);
|
||||||
}
|
}
|
||||||
inputStream.close();
|
inputStream.close();
|
||||||
|
} else {
|
||||||
|
// System.err.println("Skipping: " + name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException("Unexpected extra data in zip assigned. Aborting");
|
||||||
|
} finally {
|
||||||
|
jarDestFile.close();
|
||||||
|
}
|
||||||
|
|
||||||
byte[] digestBytes = new byte[digest.getDigestSize()];
|
byte[] digestBytes = new byte[digest.getDigestSize()];
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user