Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cb956573 authored by Doug Zongker's avatar Doug Zongker
Browse files

make RecoverySystem.verifyPackage interruptible

Change-Id: I09f6746914ef63c81312efd3a8959b0c28f6003a
parent 3802141d
Loading
Loading
Loading
Loading
+11 −1
Original line number Original line Diff line number Diff line
@@ -117,7 +117,10 @@ public class RecoverySystem {
     * exception.
     * exception.
     *
     *
     * Verification of a package can take significant time, so this
     * Verification of a package can take significant time, so this
     * function should not be called from a UI thread.
     * function should not be called from a UI thread.  Interrupting
     * the thread while this function is in progress will result in a
     * SecurityException being thrown (and the thread's interrupt flag
     * will be cleared).
     *
     *
     * @param packageFile  the package to be verified
     * @param packageFile  the package to be verified
     * @param listener     an object to receive periodic progress
     * @param listener     an object to receive periodic progress
@@ -259,7 +262,10 @@ public class RecoverySystem {
            long soFar = 0;
            long soFar = 0;
            raf.seek(0);
            raf.seek(0);
            byte[] buffer = new byte[4096];
            byte[] buffer = new byte[4096];
            boolean interrupted = false;
            while (soFar < toRead) {
            while (soFar < toRead) {
                interrupted = Thread.interrupted();
                if (interrupted) break;
                int size = buffer.length;
                int size = buffer.length;
                if (soFar + size > toRead) {
                if (soFar + size > toRead) {
                    size = (int)(toRead - soFar);
                    size = (int)(toRead - soFar);
@@ -283,6 +289,10 @@ public class RecoverySystem {
                listener.onProgress(100);
                listener.onProgress(100);
            }
            }


            if (interrupted) {
                throw new SignatureException("verification was interrupted");
            }

            if (!sig.verify(sigInfo.getEncryptedDigest())) {
            if (!sig.verify(sigInfo.getEncryptedDigest())) {
                throw new SignatureException("signature digest verification failed");
                throw new SignatureException("signature digest verification failed");
            }
            }