open-license-manager
2014-08-27 f44096c87b9e0690bb43e2d8145d4330f914b333
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 = \"");