Skip to content

Commit

Permalink
disable dependency loader signature checks to fix sha1 checksum issue
Browse files Browse the repository at this point in the history
  • Loading branch information
FalsePattern committed Oct 10, 2024
1 parent f725bb5 commit 2806a0e
Showing 1 changed file with 59 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ private static boolean scanForDepSpecs(URL source, List<URL> output) {
if (fileName.endsWith(".jar")) {
//Scan jar file for json in META-INF, add them to the list
try (val inputStream = new BufferedInputStream(source.openStream(), 65536);
val jarFile = new JarInputStream(inputStream)) {
val jarFile = new JarInputStream(inputStream, false)) {
ZipEntry entry;
while ((entry = jarFile.getNextEntry()) != null) {
if (!entry.getName().startsWith("META-INF") || !entry.getName().endsWith(".json")) {
Expand Down Expand Up @@ -823,68 +823,71 @@ private void validateDownloadsAllowed() {
}
}

private static final Object mutex = new Object();
private boolean tryDownloadFromMaven(String repo) {
try {
if (!repo.endsWith("/")) {
repo = repo + "/";
}
val url = String.format("%s%s/%s/%s/%s",
repo,
groupId.replace('.', '/'),
artifactId,
preferredVersion,
mavenJarName);
String finalRepo = repo;
int retryCount = 0;
while (true) {
retryCount++;
if (retryCount > 3) {
break;
}
val success = new AtomicBoolean(false);
val tmpFile = file.getParent().resolve(file.getFileName().toString() + ".tmp");
if (Files.exists(tmpFile)) {
Files.delete(tmpFile);
synchronized (mutex) {
try {
if (!repo.endsWith("/")) {
repo = repo + "/";
}
Internet.connect(new URL(url),
ex -> LOG.debug("Artifact {} could not be downloaded from repo {}: {}",
artifactLogName,
finalRepo,
ex.getMessage()),
input -> {
LOG.debug("Downloading {} from {}", artifactLogName, finalRepo);
download(input, tmpFile, d -> downloaded += d);
LOG.debug("Downloaded {} from {}", artifactLogName, finalRepo);
success.set(true);
},
contentLength -> this.contentLength = contentLength);
if (success.get()) {
try {
Files.move(tmpFile, file, StandardCopyOption.ATOMIC_MOVE);
} catch (AtomicMoveNotSupportedException ignored) {
Files.move(tmpFile, file);
val url = String.format("%s%s/%s/%s/%s",
repo,
groupId.replace('.', '/'),
artifactId,
preferredVersion,
mavenJarName);
String finalRepo = repo;
int retryCount = 0;
while (true) {
retryCount++;
if (retryCount > 3) {
break;
}
LOG.debug("Validating checksum for {}", artifactLogName);
val hadChecksum = validateChecksum(url);
switch (hadChecksum) {
case FAILED:
continue;
case OK:
break;
case MISSING:
LOG.warn("The library {} had no checksum available on the repository.\n"
+ "There's a chance it might have gotten corrupted during download,\n"
+ "but we're loading it anyways.", artifactLogName);
val success = new AtomicBoolean(false);
val tmpFile = file.getParent().resolve(file.getFileName().toString() + ".tmp");
if (Files.exists(tmpFile)) {
Files.delete(tmpFile);
}
Internet.connect(new URL(url),
ex -> LOG.debug("Artifact {} could not be downloaded from repo {}: {}",
artifactLogName,
finalRepo,
ex.getMessage()),
input -> {
LOG.debug("Downloading {} from {}", artifactLogName, finalRepo);
download(input, tmpFile, d -> downloaded += d);
LOG.debug("Downloaded {} from {}", artifactLogName, finalRepo);
success.set(true);
},
contentLength -> this.contentLength = contentLength);
if (success.get()) {
try {
Files.move(tmpFile, file, StandardCopyOption.ATOMIC_MOVE);
} catch (AtomicMoveNotSupportedException ignored) {
Files.move(tmpFile, file);
}
LOG.debug("Validating checksum for {}", artifactLogName);
val hadChecksum = validateChecksum(url);
switch (hadChecksum) {
case FAILED:
continue;
case OK:
break;
case MISSING:
LOG.warn("The library {} had no checksum available on the repository.\n"
+ "There's a chance it might have gotten corrupted during download,\n"
+ "but we're loading it anyways.", artifactLogName);
}
loadedLibraries.put(artifact, preferredVersion);
loadedLibraryMods.put(artifact, loadingModId);
addToClasspath(file);
return true;
}
loadedLibraries.put(artifact, preferredVersion);
loadedLibraryMods.put(artifact, loadingModId);
addToClasspath(file);
return true;
}
} catch (IOException ignored) {
}
} catch (IOException ignored) {
return false;
}
return false;
}

private ChecksumStatus validateChecksum(String url) throws IOException {
Expand Down

0 comments on commit 2806a0e

Please sign in to comment.