From f26e117cb9671997150ecb267d37b9b744e55182 Mon Sep 17 00:00:00 2001 From: Kaleb Luedtke Date: Thu, 29 Sep 2022 19:50:11 -0500 Subject: [PATCH 1/8] Additional logging when validating portable file fails --- src/AppInstallerCLICore/PortableInstaller.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/AppInstallerCLICore/PortableInstaller.cpp b/src/AppInstallerCLICore/PortableInstaller.cpp index 41623a14b8..0b50730ec4 100644 --- a/src/AppInstallerCLICore/PortableInstaller.cpp +++ b/src/AppInstallerCLICore/PortableInstaller.cpp @@ -62,6 +62,7 @@ namespace AppInstaller::CLI::Portable { if (std::filesystem::exists(filePath) && !SHA256::AreEqual(SHA256::ComputeHashFromFile(filePath), SHA256::ConvertToBytes(entry.SHA256))) { + AICLI_LOG(CLI, Info, << "File Hash: " << SHA256::ComputeHashFromFile(filePath).data() << " Expected: " << entry.SHA256); return false; } } @@ -69,6 +70,7 @@ namespace AppInstaller::CLI::Portable { if (Filesystem::SymlinkExists(filePath) && !Filesystem::VerifySymlink(filePath, entry.SymlinkTarget)) { + AICLI_LOG(CLI, Info, << "Symlink: " << std::filesystem::read_symlink(filePath).string() << " Expected: " << entry.SymlinkTarget); return false; } } From ad12df4427c03113db6bb51c10fff8fd8205698b Mon Sep 17 00:00:00 2001 From: Kaleb Luedtke Date: Thu, 29 Sep 2022 19:51:11 -0500 Subject: [PATCH 2/8] Fix command line output to show single backslash instead of double backslash --- src/AppInstallerCLICore/PortableInstaller.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AppInstallerCLICore/PortableInstaller.cpp b/src/AppInstallerCLICore/PortableInstaller.cpp index 0b50730ec4..e223b1bf84 100644 --- a/src/AppInstallerCLICore/PortableInstaller.cpp +++ b/src/AppInstallerCLICore/PortableInstaller.cpp @@ -123,7 +123,7 @@ namespace AppInstaller::CLI::Portable if (std::filesystem::remove(filePath)) { AICLI_LOG(CLI, Info, << "Removed existing file at " << filePath); - m_stream << Resource::String::OverwritingExistingFileAtMessage << ' ' << filePath << std::endl; + m_stream << Resource::String::OverwritingExistingFileAtMessage << ' ' << filePath.string() << std::endl; } if (Filesystem::CreateSymlink(entry.SymlinkTarget, filePath)) From be4e11c9df7a484ff0ce2f022b6402fc49ba571d Mon Sep 17 00:00:00 2001 From: Kaleb Luedtke Date: Thu, 29 Sep 2022 19:55:02 -0500 Subject: [PATCH 3/8] Avoid calculating file hash twice --- src/AppInstallerCLICore/PortableInstaller.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/AppInstallerCLICore/PortableInstaller.cpp b/src/AppInstallerCLICore/PortableInstaller.cpp index e223b1bf84..944b0a7e1f 100644 --- a/src/AppInstallerCLICore/PortableInstaller.cpp +++ b/src/AppInstallerCLICore/PortableInstaller.cpp @@ -60,9 +60,10 @@ namespace AppInstaller::CLI::Portable if (fileType == PortableFileType::File) { - if (std::filesystem::exists(filePath) && !SHA256::AreEqual(SHA256::ComputeHashFromFile(filePath), SHA256::ConvertToBytes(entry.SHA256))) + SHA256::HashBuffer fileHash = SHA256::ComputeHashFromFile(filePath); + if (std::filesystem::exists(filePath) && !SHA256::AreEqual(fileHash, SHA256::ConvertToBytes(entry.SHA256))) { - AICLI_LOG(CLI, Info, << "File Hash: " << SHA256::ComputeHashFromFile(filePath).data() << " Expected: " << entry.SHA256); + AICLI_LOG(CLI, Info, << "File Hash: " << fileHash.data() << " Expected: " << entry.SHA256); return false; } } From a55030daca3a20b78d737a39d3290a9005b3514e Mon Sep 17 00:00:00 2001 From: Kaleb Luedtke Date: Thu, 29 Sep 2022 19:59:11 -0500 Subject: [PATCH 4/8] Cleanup messages --- src/AppInstallerCLICore/PortableInstaller.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/AppInstallerCLICore/PortableInstaller.cpp b/src/AppInstallerCLICore/PortableInstaller.cpp index 944b0a7e1f..ab48e38bc8 100644 --- a/src/AppInstallerCLICore/PortableInstaller.cpp +++ b/src/AppInstallerCLICore/PortableInstaller.cpp @@ -63,7 +63,7 @@ namespace AppInstaller::CLI::Portable SHA256::HashBuffer fileHash = SHA256::ComputeHashFromFile(filePath); if (std::filesystem::exists(filePath) && !SHA256::AreEqual(fileHash, SHA256::ConvertToBytes(entry.SHA256))) { - AICLI_LOG(CLI, Info, << "File Hash: " << fileHash.data() << " Expected: " << entry.SHA256); + AICLI_LOG(CLI, Info, << "File hash does not match ARP Entry. Expected: " << entry.SHA256 << " Actual: " << fileHash.data()); return false; } } @@ -71,7 +71,7 @@ namespace AppInstaller::CLI::Portable { if (Filesystem::SymlinkExists(filePath) && !Filesystem::VerifySymlink(filePath, entry.SymlinkTarget)) { - AICLI_LOG(CLI, Info, << "Symlink: " << std::filesystem::read_symlink(filePath).string() << " Expected: " << entry.SymlinkTarget); + AICLI_LOG(CLI, Info, << "Symlink target does not match ARP Entry. Expected: " << entry.SymlinkTarget << " Actual: " << std::filesystem::read_symlink(filePath).string()); return false; } } From eff3deb415290d6f62c77671851c5a0435723099 Mon Sep 17 00:00:00 2001 From: Kaleb Luedtke Date: Thu, 29 Sep 2022 20:45:00 -0500 Subject: [PATCH 5/8] Use appropriate function for getting string --- src/AppInstallerCLICore/PortableInstaller.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AppInstallerCLICore/PortableInstaller.cpp b/src/AppInstallerCLICore/PortableInstaller.cpp index ab48e38bc8..40b1218adf 100644 --- a/src/AppInstallerCLICore/PortableInstaller.cpp +++ b/src/AppInstallerCLICore/PortableInstaller.cpp @@ -63,7 +63,7 @@ namespace AppInstaller::CLI::Portable SHA256::HashBuffer fileHash = SHA256::ComputeHashFromFile(filePath); if (std::filesystem::exists(filePath) && !SHA256::AreEqual(fileHash, SHA256::ConvertToBytes(entry.SHA256))) { - AICLI_LOG(CLI, Info, << "File hash does not match ARP Entry. Expected: " << entry.SHA256 << " Actual: " << fileHash.data()); + AICLI_LOG(CLI, Info, << "File hash does not match ARP Entry. Expected: " << entry.SHA256 << " Actual: " << SHA256::ConvertToString(fileHash)); return false; } } From cab7626dc8d79f92d3f6d364b5a192230e9ef966 Mon Sep 17 00:00:00 2001 From: Kaleb Luedtke Date: Fri, 30 Sep 2022 14:27:57 -0500 Subject: [PATCH 6/8] Address Comments --- src/AppInstallerCLICore/PortableInstaller.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/AppInstallerCLICore/PortableInstaller.cpp b/src/AppInstallerCLICore/PortableInstaller.cpp index 40b1218adf..185bfd8559 100644 --- a/src/AppInstallerCLICore/PortableInstaller.cpp +++ b/src/AppInstallerCLICore/PortableInstaller.cpp @@ -60,18 +60,22 @@ namespace AppInstaller::CLI::Portable if (fileType == PortableFileType::File) { - SHA256::HashBuffer fileHash = SHA256::ComputeHashFromFile(filePath); - if (std::filesystem::exists(filePath) && !SHA256::AreEqual(fileHash, SHA256::ConvertToBytes(entry.SHA256))) + + if (std::filesystem::exists(filePath)) { - AICLI_LOG(CLI, Info, << "File hash does not match ARP Entry. Expected: " << entry.SHA256 << " Actual: " << SHA256::ConvertToString(fileHash)); - return false; + SHA256::HashBuffer fileHash = SHA256::ComputeHashFromFile(filePath); + if (!SHA256::AreEqual(fileHash, SHA256::ConvertToBytes(entry.SHA256))) + { + AICLI_LOG(CLI, Warning, << "File hash does not match ARP Entry. Expected: " << entry.SHA256 << " Actual: " << SHA256::ConvertToString(fileHash)); + return false; + } } } else if (fileType == PortableFileType::Symlink) { if (Filesystem::SymlinkExists(filePath) && !Filesystem::VerifySymlink(filePath, entry.SymlinkTarget)) { - AICLI_LOG(CLI, Info, << "Symlink target does not match ARP Entry. Expected: " << entry.SymlinkTarget << " Actual: " << std::filesystem::read_symlink(filePath).string()); + AICLI_LOG(CLI, Warning, << "Symlink target does not match ARP Entry. Expected: " << entry.SymlinkTarget << " Actual: " << std::filesystem::read_symlink(filePath).string()); return false; } } From a958aeefc62a62f9b500c8381205cdc79ab3eed4 Mon Sep 17 00:00:00 2001 From: Kaleb Luedtke Date: Fri, 30 Sep 2022 14:30:35 -0500 Subject: [PATCH 7/8] Use log override --- src/AppInstallerCLICore/PortableInstaller.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AppInstallerCLICore/PortableInstaller.cpp b/src/AppInstallerCLICore/PortableInstaller.cpp index 185bfd8559..17f435e870 100644 --- a/src/AppInstallerCLICore/PortableInstaller.cpp +++ b/src/AppInstallerCLICore/PortableInstaller.cpp @@ -75,7 +75,7 @@ namespace AppInstaller::CLI::Portable { if (Filesystem::SymlinkExists(filePath) && !Filesystem::VerifySymlink(filePath, entry.SymlinkTarget)) { - AICLI_LOG(CLI, Warning, << "Symlink target does not match ARP Entry. Expected: " << entry.SymlinkTarget << " Actual: " << std::filesystem::read_symlink(filePath).string()); + AICLI_LOG(CLI, Warning, << "Symlink target does not match ARP Entry. Expected: " << entry.SymlinkTarget << " Actual: " << std::filesystem::read_symlink(filePath)); return false; } } From 79617b89f429e0abbae12910b297644ffed1852c Mon Sep 17 00:00:00 2001 From: Kaleb Luedtke Date: Fri, 30 Sep 2022 14:52:20 -0500 Subject: [PATCH 8/8] u8 --- src/AppInstallerCLICore/PortableInstaller.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AppInstallerCLICore/PortableInstaller.cpp b/src/AppInstallerCLICore/PortableInstaller.cpp index 17f435e870..93340ca731 100644 --- a/src/AppInstallerCLICore/PortableInstaller.cpp +++ b/src/AppInstallerCLICore/PortableInstaller.cpp @@ -128,7 +128,7 @@ namespace AppInstaller::CLI::Portable if (std::filesystem::remove(filePath)) { AICLI_LOG(CLI, Info, << "Removed existing file at " << filePath); - m_stream << Resource::String::OverwritingExistingFileAtMessage << ' ' << filePath.string() << std::endl; + m_stream << Resource::String::OverwritingExistingFileAtMessage << ' ' << filePath.u8string() << std::endl; } if (Filesystem::CreateSymlink(entry.SymlinkTarget, filePath))