| 49 | } |
| 50 | |
| 51 | bool CryptoUtils::SignFile(std::wstring const& zipPath, std::wstring const& privateKeyPath) |
| 52 | { |
| 53 | std::vector<uint8_t> contents; |
| 54 | std::vector<uint8_t> key; |
| 55 | if (!LoadFile(zipPath, contents)) return false; |
| 56 | if (!LoadFile(privateKeyPath, key)) return false; |
| 57 | |
| 58 | if (key.size() != NUM_ECC_BYTES) return false; |
| 59 | |
| 60 | PackageSignature sig; |
| 61 | memset(&sig, 0, sizeof(sig)); |
| 62 | sig.Magic = PackageSignature::MAGIC_V1; |
| 63 | sig.Version = PackageSignature::VER_SIGNATURE_IN_MANIFEST; |
| 64 | sig.SignedBytes = (uint32_t)contents.size(); |
| 65 | |
| 66 | if (!EccSign(contents.data(), contents.size(), key.data(), sig.EccSignature)) { |
| 67 | return false; |
| 68 | } |
| 69 | |
| 70 | auto contentLength = contents.size(); |
| 71 | contents.resize(contentLength + sizeof(sig)); |
| 72 | memcpy(contents.data() + contentLength, &sig, sizeof(sig)); |
| 73 | |
| 74 | return SaveFile(zipPath, contents); |
| 75 | } |
| 76 | |
| 77 | bool CryptoUtils::GenerateKeys(std::wstring const& privateKeyPath) |
| 78 | { |