From 1922d8c2cf7dcaacafd17394849577794b1f10eb Mon Sep 17 00:00:00 2001 From: open-license-manager <rillf@maildrop.cc> Date: 周六, 13 9月 2014 06:24:55 +0800 Subject: [PATCH] signature windows --- src/bootstrap/win/Main.cpp | 33 +++++++++++++++++++++++++++++++-- 1 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/bootstrap/win/Main.cpp b/src/bootstrap/win/Main.cpp index 26006c5..c910a2f 100644 --- a/src/bootstrap/win/Main.cpp +++ b/src/bootstrap/win/Main.cpp @@ -1,6 +1,8 @@ #include <stdio.h> #include "CryptoHelper.h" #include <string> +#include <stdlib.h> +#include <iostream> using namespace std; @@ -19,7 +21,27 @@ fprintf(fp, "%d", pbPublicKey[i]); } fprintf(fp, "\n};\n\n"); - fprintf(fp, "#define SHARED_RANDOM %d;\n", 12345); + int random = rand() % 1000; + fprintf(fp, "#define SHARED_RANDOM %d;\n", random); + fprintf(fp, "#endif\n"); + fclose(fp); +} + +void write_privkey_file(string private_fname, BYTE *privateKey, DWORD dwPrivateKeySize){ + FILE* fp = fopen(private_fname.c_str(), "w"); + fprintf(fp, "//file generated by bootstrap.cpp, do not edit.\n\n"); + fprintf(fp, "#ifndef PRIVATE_KEY_H_\n#define PRIVATE_KEY_H_\n"); + fprintf(fp, "static BYTE PRIVATE_KEY[] = {"); + for (int i = 0; i < dwPrivateKeySize; i++){ + if (i != 0){ + fprintf(fp, ","); + } + if (i % 15 == 0){ + fprintf(fp, "\n "); + } + fprintf(fp, "%d", privateKey[i]); + } + fprintf(fp, "\n};\n\n"); fprintf(fp, "#endif\n"); fclose(fp); } @@ -43,6 +65,7 @@ if (FAILED( hr = cryptoHlpr.ExportPublicKey(&pbPublicKey, dwPublicKeySize))) { // Call FormatMessage to display the error returned in hr. + cerr << "error exporting pubkey" << endl; return; } else { @@ -56,7 +79,13 @@ } wprintf(L"\"\n"); // Export out the private key blob. - cryptoHlpr.ExportPrivateKey(&pbPrivateKey, dwPrivateKeySize); + if (FAILED(cryptoHlpr.ExportPrivateKey(&pbPrivateKey, dwPrivateKeySize))){ + cerr << "Error exporting private key." << endl; + return; + } + else{ + write_privkey_file(private_include, pbPrivateKey, dwPrivateKeySize); + } // Print out the private key to console as a // hexadecimal string. wprintf(L"\n\nPrivateKey = \""); -- Gitblit v1.9.1