twrpDigest refactor
This patch is to refactor twrpDigest using polymorphism and inheritance to use the same call patterns for creating and reading a digest. Now a library. Use SHA2 from libcrypto. SHA2 is default if device has libcrypto. Change string MD5 everywhere to use digest or Digest instead. Updated string tags to digest. Translation will be required. Switch out digest code into a driver class from partitionmanager. SHA2 is better for digest creation due to decreased collision space compared to MD5 and SHA1. See https://en.wikipedia.org/wiki/SHA-2 Change-Id: I74b5546789990b12aa4ce2e389d25f80a3fe213f
This commit is contained in:
committed by
Ethan Yonker
parent
92e2531dca
commit
56cf564658
+1
-46
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright 2013 to 2016 TeamWin
|
||||
Copyright 2013 to 2017 TeamWin
|
||||
This file is part of TWRP/TeamWin Recovery Project.
|
||||
|
||||
TWRP is free software: you can redistribute it and/or modify
|
||||
@@ -41,7 +41,6 @@
|
||||
#include "partitions.hpp"
|
||||
#include "data.hpp"
|
||||
#include "twrp-functions.hpp"
|
||||
#include "twrpDigest.hpp"
|
||||
#include "twrpTar.hpp"
|
||||
#include "exclude.hpp"
|
||||
#include "infomanager.hpp"
|
||||
@@ -1657,50 +1656,6 @@ bool TWPartition::Backup(PartitionSettings *part_settings, pid_t *tar_fork_pid)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool TWPartition::Check_Restore_File_MD5(const string& Filename) {
|
||||
twrpDigest md5sum;
|
||||
|
||||
md5sum.setfn(Filename);
|
||||
switch (md5sum.verify_md5digest()) {
|
||||
case MD5_OK:
|
||||
gui_msg(Msg("md5_matched=MD5 matched for '{1}'.")(Filename));
|
||||
return true;
|
||||
case MD5_FILE_UNREADABLE:
|
||||
case MD5_NOT_FOUND:
|
||||
gui_msg(Msg(msg::kError, "no_md5_found=No md5 file found for '{1}'. Please unselect Enable MD5 verification to restore.")(Filename));
|
||||
break;
|
||||
case MD5_MATCH_FAIL:
|
||||
gui_msg(Msg(msg::kError, "md5_fail_match=MD5 failed to match on '{1}'.")(Filename));
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool TWPartition::Check_MD5(PartitionSettings *part_settings) {
|
||||
string Full_Filename;
|
||||
char split_filename[512];
|
||||
int index = 0;
|
||||
|
||||
sync();
|
||||
|
||||
Full_Filename = part_settings->Backup_Folder + "/" + Backup_FileName;
|
||||
if (!TWFunc::Path_Exists(Full_Filename)) {
|
||||
// This is a split archive, we presume
|
||||
memset(split_filename, 0, sizeof(split_filename));
|
||||
while (index < 1000) {
|
||||
sprintf(split_filename, "%s%03i", Full_Filename.c_str(), index);
|
||||
if (!TWFunc::Path_Exists(split_filename))
|
||||
break;
|
||||
LOGINFO("split_filename: %s\n", split_filename);
|
||||
if (!Check_Restore_File_MD5(split_filename))
|
||||
return false;
|
||||
index++;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return Check_Restore_File_MD5(Full_Filename); // Single file archive
|
||||
}
|
||||
|
||||
bool TWPartition::Restore(PartitionSettings *part_settings) {
|
||||
TWFunc::GUI_Operation_Text(TW_RESTORE_TEXT, Display_Name, gui_parse_text("{@restoring_hdr}"));
|
||||
LOGINFO("Restore filename is: %s/%s\n", part_settings->Backup_Folder.c_str(), Backup_FileName.c_str());
|
||||
|
||||
Reference in New Issue
Block a user