MCPcopy Create free account
hub / github.com/Norbyte/bg3se / SignerMain

Function SignerMain

UpdateSigner/UpdateSigner.cpp:152–221  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

150}
151
152int SignerMain(int argc, char** argv)
153{
154 if (argc < 2) return 0;
155
156 gCoreLibPlatformInterface.Alloc = &OSAlloc;
157 gCoreLibPlatformInterface.Free = &OSFree;
158
159 if (!CryptAcquireContext(
160 &hCryptProv,
161 NULL,
162 (LPCWSTR)L"Microsoft Base Cryptographic Provider v1.0",
163 PROV_RSA_FULL,
164 CRYPT_VERIFYCONTEXT)) {
165 std::cout << "CryptAcquireContext failed" << std::endl;
166 return 1;
167 }
168
169 if (strcmp(argv[1], "genkey") == 0) {
170 auto path = FromStdUTF8(std::string(argv[2]));
171 if (CryptoUtils::GenerateKeys(path)) {
172 std::cout << "Key written to " << argv[2] << std::endl;
173 return 0;
174 } else {
175 std::cout << "Key generation failed!" << std::endl;
176 return 1;
177 }
178 }
179
180 if (strcmp(argv[1], "sign") == 0) {
181 auto keyPath = FromStdUTF8(std::string(argv[2]));
182 auto filePath = FromStdUTF8(std::string(argv[3]));
183
184 PackageSignature sig;
185 if (CryptoUtils::GetFileSignature(filePath, sig)) {
186 std::cout << "File " << argv[3] << " is already signed!" << std::endl;
187 return 2;
188 }
189
190 if (CryptoUtils::SignFile(filePath, keyPath)) {
191 std::cout << "Signed file " << argv[3] << " using key " << argv[2] << std::endl;
192 return 0;
193 } else {
194 std::cout << "Signing failed!" << std::endl;
195 return 3;
196 }
197 }
198
199 if (strcmp(argv[1], "verify") == 0) {
200 auto filePath = FromStdUTF8(std::string(argv[2]));
201 std::string reason;
202 if (CryptoUtils::VerifySignedFile(filePath, reason)) {
203 std::cout << "Successfully verified file " << argv[2] << std::endl;
204 return 0;
205 } else {
206 std::cout << "Verification failed: " << reason << std::endl;
207 return 1;
208 }
209 }

Callers 1

mainFunction · 0.85

Calls 3

FromStdUTF8Function · 0.85
UpdateManifestFunction · 0.85
ComputePathDigestFunction · 0.85

Tested by

no test coverage detected