| 112 | } |
| 113 | |
| 114 | bool CryptoUtils::VerifySignedFile(std::wstring const& zipPath, std::string& reason) |
| 115 | { |
| 116 | std::vector<uint8_t> contents; |
| 117 | if (!LoadFile(zipPath, contents)) { |
| 118 | reason = "Unable to open update package"; |
| 119 | return false; |
| 120 | } |
| 121 | |
| 122 | if (contents.size() < sizeof(PackageSignature)) { |
| 123 | reason = "Update package not cryptographically signed"; |
| 124 | return false; |
| 125 | } |
| 126 | |
| 127 | auto sig = reinterpret_cast<PackageSignature*>(contents.data() + contents.size() - sizeof(PackageSignature)); |
| 128 | if (sig->Magic != PackageSignature::MAGIC_V1) { |
| 129 | reason = "Update package not cryptographically signed"; |
| 130 | return false; |
| 131 | } |
| 132 | |
| 133 | if (!EccVerify(contents.data(), contents.size() - sizeof(PackageSignature), UpdaterPublicKey, sig->EccSignature)) { |
| 134 | reason = "Cryptographic signature on update package is incorrect"; |
| 135 | return false; |
| 136 | } |
| 137 | |
| 138 | return true; |
| 139 | } |
| 140 | |
| 141 | END_SE() |