Skip to content

Commit 974139a

Browse files
tdmmikeNG
authored andcommitted
recovery: Allow bypassing signature verification on non-release builds
For non-release (userdebug, eng) builds, when signature verification fails, ask the user whether they wish to install anyway. [aleasto] Rewritten to minimize the diff footprint for maintainability Change-Id: I950ad455e6f698cabe348f0482eb64287cc88a08
1 parent 42133e9 commit 974139a

File tree

6 files changed

+31
-2
lines changed

6 files changed

+31
-2
lines changed

install/install.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,15 @@
5555
#include "otautil/sysutil.h"
5656
#include "otautil/verifier.h"
5757
#include "private/setup_commands.h"
58+
#include "recovery_ui/device.h"
5859
#include "recovery_ui/ui.h"
5960
#include "recovery_utils/roots.h"
6061
#include "recovery_utils/thermalutil.h"
6162

6263
using namespace std::chrono_literals;
6364

65+
bool ask_to_continue_unverified(Device* device);
66+
6467
static constexpr int kRecoveryApiVersion = 3;
6568
// We define RECOVERY_API_VERSION in Android.mk, which will be picked up by build system and packed
6669
// into target_files.zip. Assert the version defined in code and in Android.mk are consistent.
@@ -609,7 +612,9 @@ static InstallResult VerifyAndInstallPackage(Package* package, bool* wipe_cache,
609612
// Verify package.
610613
if (!verify_package(package, ui)) {
611614
log_buffer->push_back(android::base::StringPrintf("error: %d", kZipVerificationFailure));
612-
return INSTALL_CORRUPT;
615+
if (!ui->IsTextVisible() || !ask_to_continue_unverified(ui->GetDevice())) {
616+
return INSTALL_CORRUPT;
617+
}
613618
}
614619

615620
// Verify and install the contents of the package.

recovery.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,15 @@ static bool yes_no(Device* device, const char* question1, const char* question2)
165165
return (chosen_item == 1);
166166
}
167167

168+
bool ask_to_continue_unverified(Device* device) {
169+
if (get_build_type() == "user") {
170+
return false;
171+
} else {
172+
device->GetUI()->SetProgressType(RecoveryUI::EMPTY);
173+
return yes_no(device, "Signature verification failed", "Install anyway?");
174+
}
175+
}
176+
168177
static bool ask_to_wipe_data(Device* device) {
169178
std::vector<std::string> headers{ "Format user data?", "This includes internal storage.", "THIS CANNOT BE UNDONE!" };
170179
std::vector<std::string> items{ " Cancel", " Format data" };

recovery.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,5 @@
2222
#include "recovery_ui/device.h"
2323

2424
Device::BuiltinAction start_recovery(Device* device, const std::vector<std::string>& args);
25+
26+
std::string get_build_type();

recovery_main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ static bool IsDeviceUnlocked() {
7777
return "orange" == android::base::GetProperty("ro.boot.verifiedbootstate", "");
7878
}
7979

80-
static std::string get_build_type() {
80+
std::string get_build_type() {
8181
return android::base::GetProperty("ro.build.type", "");
8282
}
8383

recovery_ui/device.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ static void PopulateMenuItems() {
7474
}
7575

7676
Device::Device(RecoveryUI* ui) : ui_(ui) {
77+
ui->SetDevice(this);
7778
PopulateMenuItems();
7879
}
7980

recovery_ui/include/recovery_ui/ui.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
#include <thread>
2929
#include <vector>
3030

31+
class Device;
32+
3133
static constexpr const char* DEFAULT_LOCALE = "en-US";
3234

3335
/*
@@ -144,6 +146,14 @@ class RecoveryUI {
144146

145147
virtual ~RecoveryUI();
146148

149+
void SetDevice(Device* device) {
150+
device_ = device;
151+
}
152+
153+
Device* GetDevice() {
154+
return device_;
155+
}
156+
147157
// Initializes the object; called before anything else. UI texts will be initialized according
148158
// to the given locale. Returns true on success.
149159
virtual bool Init(const std::string& locale);
@@ -310,6 +320,8 @@ class RecoveryUI {
310320
OFF,
311321
};
312322

323+
Device* device_;
324+
313325
// The sensitivity when detecting a swipe.
314326
const int touch_low_threshold_;
315327
const int touch_high_threshold_;

0 commit comments

Comments
 (0)