Skip to content

Commit

Permalink
signature windows
Browse files Browse the repository at this point in the history
  • Loading branch information
open-license-manager committed Sep 12, 2014
1 parent f76392f commit 1922d8c
Show file tree
Hide file tree
Showing 8 changed files with 342 additions and 106 deletions.
33 changes: 0 additions & 33 deletions src/bootstrap/bootstrap_win.cpp

This file was deleted.

6 changes: 3 additions & 3 deletions src/bootstrap/win/CryptoHelper.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "CryptoHelper.h"
// The RSA public-key key exchange algorithm
#define ENCRYPT_ALGORITHM CALG_RSA_KEYX
#define ENCRYPT_ALGORITHM CALG_RSA_SIGN
// The high order WORD 0x0200 (decimal 512)
// determines the key length in bits.
#define KEYLENGTH 0x02000000
Expand Down Expand Up @@ -53,7 +53,7 @@ if (m_hCryptProv != NULL)
wszContainerName,
MS_ENHANCED_PROV,
PROV_RSA_FULL,
CRYPT_MACHINE_KEYSET))
0))
{
// An error occurred in acquiring the context. This could mean
// that the key container requested does not exist. In this case,
Expand All @@ -64,7 +64,7 @@ if (m_hCryptProv != NULL)
if(!CryptAcquireContext(&m_hCryptProv,
wszContainerName,
MS_ENHANCED_PROV, PROV_RSA_FULL,
CRYPT_MACHINE_KEYSET|CRYPT_NEWKEYSET))
CRYPT_NEWKEYSET))
{
dwErrCode = GetLastError();
return HRESULT_FROM_WIN32(dwErrCode);
Expand Down
14 changes: 11 additions & 3 deletions src/library/base/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,20 @@

#ifndef LOG_ENABLED
#include <errno.h>
#ifdef __cplusplus
extern "C" {
#endif

#define clean_errno() (errno == 0 ? "None" : strerror(errno))

#ifdef NDEBUG
#define LOG_DEBUG(M, ...) _log("[INFO] %s (%s:%d) " M "\n", __FILE__, __LINE__, ##__VA_ARGS__)
#else
#define LOG_DEBUG(M,...)
#endif
#define LOG_INFO(M, ...) _log("[INFO] %s (%s:%d) " M "\n", __FILE__, __LINE__, ##__VA_ARGS__)
#define LOG_WARN(M, ...) _log("[WARN] %s (%s:%d: errno: %s) " M "\n", __FILE__, __LINE__, clean_errno(), ##__VA_ARGS__)
#define LOG_ERROR(M, ...) _log("[ERROR] %s (%s:%d: errno: %s) " M "\n", __FILE__, __LINE__, clean_errno(), ##__VA_ARGS__)
#define LOG_INFO(M, ...) _log("[INFO] (%s:%d) " M "\n", __FILE__, __LINE__, ##__VA_ARGS__)
#define LOG_WARN(M, ...) _log("[WARN] (%s:%d: errno: %s) " M "\n", __FILE__, __LINE__, clean_errno(), ##__VA_ARGS__)
#define LOG_ERROR(M, ...) _log("[ERROR] (%s:%d: errno: %s) " M "\n", __FILE__, __LINE__, clean_errno(), ##__VA_ARGS__)

#else
#define LOG_DEBUG(M,...)
Expand All @@ -23,4 +27,8 @@

void _log(char* format, ...);
void _shutdown_log();

#ifdef __cplusplus
}
#endif
#endif
2 changes: 1 addition & 1 deletion src/library/os/win/os-win.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <Windows.h>
#include <iphlpapi.h>
//definition of size_t
//definition of size_t
#include <stdlib.h>
#include "../../base/logger.h"
#include"../os.h"
Expand Down
5 changes: 5 additions & 0 deletions src/license-generator/LicenseSigner.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@
namespace license {

class LicenseSigner {
#ifdef __unix__
const string privateKey;
#else
HCRYPTPROV hProv;
HCRYPTKEY hPubKey;
#endif
string signString(const string& license);
string Opensslb64Encode(size_t slen, unsigned char* signature);

Expand Down
35 changes: 15 additions & 20 deletions src/license-generator/license-generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ vector<FullLicenseInfo> LicenseGenerator::parseLicenseInfo(
time_t curtime = time(NULL);
strftime(curdate, 20, "%Y-%m-%d", localtime(&curtime));
begin_date.assign(curdate);
} catch (invalid_argument &e) {
} catch (const invalid_argument &e) {
cerr << endl << "End date not recognized: " << dt_end
<< " Please enter a valid date in format YYYYMMDD" << endl;
exit(2);
Expand Down Expand Up @@ -189,29 +189,24 @@ int LicenseGenerator::generateLicense(int argc, const char **argv) {
}


const std::locale formats[] = { std::locale(std::locale::classic(),
new bt::time_input_facet("%Y-%m-%d")), //
std::locale(std::locale::classic(), new bt::time_input_facet("%Y/%m/%d")), //
std::locale(std::locale::classic(), new bt::time_input_facet("%Y%m%d")) };
const size_t formats_n = sizeof(formats) / sizeof(formats[0]);

string LicenseGenerator::normalize_date(const std::string& s) {
bt::ptime pt;
for (size_t i = 0; i < formats_n; ++i) {
std::istringstream is(s);
is.imbue(formats[i]);
is >> pt;
if (pt != bt::ptime()) {
break;
const std::string formats[] = { "%4u-%2u-%2u","%4u/%2u/%2u","%4u%2u%2u" };
const size_t formats_n = 3;

string LicenseGenerator::normalize_date(const char * s) {
unsigned int year, month, day;
int chread;
bool found = false;
for (size_t i = 0; i < formats_n &&!found; ++i) {
chread = sscanf(s, formats[i].c_str(),&year, &month, &day);
if (chread == 3){
found = true;
}
}
if (pt == bt::ptime()) {
throw invalid_argument(string("Date not regognized") + s);
if (!found){
throw invalid_argument("Date not recognized.");
}
ostringstream oss;
bt::time_facet *facet = new bt::time_facet("%Y-%m-%d");
oss.imbue(locale(cout.getloc(), facet));
oss << pt;
oss << year << "-"<<setfill('0') << std::setw(2)<< month<<"-"<<day;
//delete (facet);
return oss.str();
}
Expand Down
2 changes: 1 addition & 1 deletion src/license-generator/license-generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class LicenseGenerator {
static vector<FullLicenseInfo> parseLicenseInfo(po::variables_map vm);
static void generateAndOutputLicenses(const po::variables_map& vm,
ostream& outputFile);
static string normalize_date(const std::string& s);
static string normalize_date(const char * s);
public:
static int generateLicense(int argc, const char** argv);
};
Expand Down
Loading

0 comments on commit 1922d8c

Please sign in to comment.