From dd481035163b763525187766301772e6e7aaa608 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Wed, 28 Mar 2018 23:08:59 +0200 Subject: [PATCH] purge unused repo instance variable from UpdateException The repo instance variable has long since been unused, but has just been left there as a vestige. Now its presence is blocking RepoUpdater. getSigningCertFromJar() from being a static method that can be reused when checking for repos on SD Cards and other removable storage devices. --- .../org/fdroid/fdroid/IndexV1Updater.java | 16 ++++----- .../java/org/fdroid/fdroid/RepoUpdater.java | 33 +++++++++---------- .../org/fdroid/fdroid/data/RepoPersister.java | 4 +-- 3 files changed, 24 insertions(+), 29 deletions(-) diff --git a/app/src/main/java/org/fdroid/fdroid/IndexV1Updater.java b/app/src/main/java/org/fdroid/fdroid/IndexV1Updater.java index fd0f1563b..b53a6a17e 100644 --- a/app/src/main/java/org/fdroid/fdroid/IndexV1Updater.java +++ b/app/src/main/java/org/fdroid/fdroid/IndexV1Updater.java @@ -135,7 +135,7 @@ public class IndexV1Updater extends RepoUpdater { if (downloader != null) { FileUtils.deleteQuietly(downloader.outputFile); } - throw new RepoUpdater.UpdateException(repo, "Error getting index file", e2); + throw new RepoUpdater.UpdateException("Error getting index file", e2); } catch (InterruptedException e2) { // ignored if canceled, the local database just won't be updated } @@ -144,7 +144,7 @@ public class IndexV1Updater extends RepoUpdater { if (downloader != null) { FileUtils.deleteQuietly(downloader.outputFile); } - throw new RepoUpdater.UpdateException(repo, "Error getting index file", e); + throw new RepoUpdater.UpdateException("Error getting index file", e); } catch (InterruptedException e) { // ignored if canceled, the local database just won't be updated } @@ -236,7 +236,7 @@ public class IndexV1Updater extends RepoUpdater { long timestamp = (Long) repoMap.get("timestamp") / 1000; if (repo.timestamp > timestamp) { - throw new RepoUpdater.UpdateException(repo, "index.jar is older that current index! " + throw new RepoUpdater.UpdateException("index.jar is older that current index! " + timestamp + " < " + repo.timestamp); } @@ -410,16 +410,14 @@ public class IndexV1Updater extends RepoUpdater { String certFromJar = Hasher.hex(rawCertFromJar); if (TextUtils.isEmpty(certFromJar)) { - throw new SigningException(repo, - SIGNED_FILE_NAME + " must have an included signing certificate!"); + throw new SigningException(SIGNED_FILE_NAME + " must have an included signing certificate!"); } if (repo.signingCertificate == null) { if (repo.fingerprint != null) { String fingerprintFromJar = Utils.calcFingerprint(rawCertFromJar); if (!repo.fingerprint.equalsIgnoreCase(fingerprintFromJar)) { - throw new SigningException(repo, - "Supplied certificate fingerprint does not match!"); + throw new SigningException("Supplied certificate fingerprint does not match!"); } } Utils.debugLog(TAG, "Saving new signing certificate to database for " + repo.address); @@ -431,14 +429,14 @@ public class IndexV1Updater extends RepoUpdater { } if (TextUtils.isEmpty(repo.signingCertificate)) { - throw new SigningException(repo, "A empty repo signing certificate is invalid!"); + throw new SigningException("A empty repo signing certificate is invalid!"); } if (repo.signingCertificate.equals(certFromJar)) { return; // we have a match! } - throw new SigningException(repo, "Signing certificate does not match!"); + throw new SigningException("Signing certificate does not match!"); } } diff --git a/app/src/main/java/org/fdroid/fdroid/RepoUpdater.java b/app/src/main/java/org/fdroid/fdroid/RepoUpdater.java index 2ac6e7da9..9c3463b7f 100644 --- a/app/src/main/java/org/fdroid/fdroid/RepoUpdater.java +++ b/app/src/main/java/org/fdroid/fdroid/RepoUpdater.java @@ -139,7 +139,7 @@ public class RepoUpdater { } } - throw new UpdateException(repo, "Error getting index file", e); + throw new UpdateException("Error getting index file", e); } catch (InterruptedException e) { // ignored if canceled, the local database just won't be updated e.printStackTrace(); @@ -202,7 +202,7 @@ public class RepoUpdater { InputStream indexInputStream = null; try { if (downloadedFile == null || !downloadedFile.exists()) { - throw new UpdateException(repo, downloadedFile + " does not exist!"); + throw new UpdateException(downloadedFile + " does not exist!"); } // Due to a bug in Android 5.0 Lollipop, the inclusion of spongycastle causes @@ -226,7 +226,7 @@ public class RepoUpdater { long timestamp = repoDetailsToSave.getAsLong(RepoTable.Cols.TIMESTAMP); if (timestamp < repo.timestamp) { - throw new UpdateException(repo, "index.jar is older that current index! " + throw new UpdateException("index.jar is older that current index! " + timestamp + " < " + repo.timestamp); } @@ -237,7 +237,7 @@ public class RepoUpdater { assertSigningCertFromXmlCorrect(); commitToDb(); } catch (SAXException | ParserConfigurationException | IOException e) { - throw new UpdateException(repo, "Error parsing index", e); + throw new UpdateException("Error parsing index", e); } finally { FDroidApp.enableSpongyCastleOnLollipop(); Utils.closeQuietly(indexInputStream); @@ -343,22 +343,19 @@ public class RepoUpdater { public static class UpdateException extends Exception { private static final long serialVersionUID = -4492452418826132803L; - public final Repo repo; - public UpdateException(Repo repo, String message) { + public UpdateException(String message) { super(message); - this.repo = repo; } - public UpdateException(Repo repo, String message, Exception cause) { + public UpdateException(String message, Exception cause) { super(message, cause); - this.repo = repo; } } public static class SigningException extends UpdateException { - public SigningException(Repo repo, String message) { - super(repo, "Repository was not signed correctly: " + message); + public SigningException(String message) { + super("Repository was not signed correctly: " + message); } } @@ -367,18 +364,18 @@ public class RepoUpdater { * signing setups that would be valid for a regular jar. This validates those * restrictions. */ - X509Certificate getSigningCertFromJar(JarEntry jarEntry) throws SigningException { + public static X509Certificate getSigningCertFromJar(JarEntry jarEntry) throws SigningException { final CodeSigner[] codeSigners = jarEntry.getCodeSigners(); if (codeSigners == null || codeSigners.length == 0) { - throw new SigningException(repo, "No signature found in index"); + throw new SigningException("No signature found in index"); } /* we could in theory support more than 1, but as of now we do not */ if (codeSigners.length > 1) { - throw new SigningException(repo, "index.jar must be signed by a single code signer!"); + throw new SigningException("index.jar must be signed by a single code signer!"); } List certs = codeSigners[0].getSignerCertPath().getCertificates(); if (certs.size() != 1) { - throw new SigningException(repo, "index.jar code signers must only have a single certificate!"); + throw new SigningException("index.jar code signers must only have a single certificate!"); } return (X509Certificate) certs.get(0); } @@ -404,7 +401,7 @@ public class RepoUpdater { String fingerprintFromJar = Utils.calcFingerprint(rawCertFromJar); if (!repo.fingerprint.equalsIgnoreCase(fingerprintFromIndexXml) || !repo.fingerprint.equalsIgnoreCase(fingerprintFromJar)) { - throw new SigningException(repo, "Supplied certificate fingerprint does not match!"); + throw new SigningException("Supplied certificate fingerprint does not match!"); } } // else - no info to check things are valid, so just Trust On First Use @@ -435,7 +432,7 @@ public class RepoUpdater { if (TextUtils.isEmpty(repo.signingCertificate) || TextUtils.isEmpty(certFromJar) || TextUtils.isEmpty(certFromIndexXml)) { - throw new SigningException(repo, "A empty repo or signing certificate is invalid!"); + throw new SigningException("A empty repo or signing certificate is invalid!"); } // though its called repo.signingCertificate, its actually a X509 certificate @@ -444,7 +441,7 @@ public class RepoUpdater { && certFromIndexXml.equals(certFromJar)) { return; // we have a match! } - throw new SigningException(repo, "Signing certificate does not match!"); + throw new SigningException("Signing certificate does not match!"); } /** diff --git a/app/src/main/java/org/fdroid/fdroid/data/RepoPersister.java b/app/src/main/java/org/fdroid/fdroid/data/RepoPersister.java index f278de932..d8052b075 100644 --- a/app/src/main/java/org/fdroid/fdroid/data/RepoPersister.java +++ b/app/src/main/java/org/fdroid/fdroid/data/RepoPersister.java @@ -106,7 +106,7 @@ public class RepoPersister { try { context.getContentResolver().applyBatch(TempApkProvider.getAuthority(), apkOperations); } catch (RemoteException | OperationApplicationException e) { - throw new RepoUpdater.UpdateException(repo, "An internal error occurred while updating the database", e); + throw new RepoUpdater.UpdateException("An internal error occurred while updating the database", e); } } @@ -122,7 +122,7 @@ public class RepoPersister { context.getContentResolver().applyBatch(TempAppProvider.getAuthority(), appOperations); return getIdsForPackages(appsToSave); } catch (RemoteException | OperationApplicationException e) { - throw new RepoUpdater.UpdateException(repo, "An internal error occurred while updating the database", e); + throw new RepoUpdater.UpdateException("An internal error occurred while updating the database", e); } }