Skip to content

Commit

Permalink
build linux
Browse files Browse the repository at this point in the history
  • Loading branch information
open-license-manager committed Aug 8, 2014
1 parent 01a62b8 commit ef84976
Show file tree
Hide file tree
Showing 7 changed files with 173 additions and 51 deletions.
36 changes: 8 additions & 28 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,28 +50,10 @@ set_property(DIRECTORY PROPERTY COMPILE_DEFINITIONS_DEBUG _DEBUG)
SET( TargetArchitecture "X86_64")
SET(Boost_USE_STATIC_LIBS ON)
include(add_boost)
set(Boost_FOUND TRUE)
include_directories(${Boost_INCLUDE_DIRS})
link_directories ( ${Boost_LIBRARY_DIRS} )

#get_cmake_property(_variableNames VARIABLES)
#foreach (_variableName ${_variableNames})
# message(STATUS "${_variableName}=${${_variableName}}")
#endforeach()
#include_directories(${Boost_INCLUDE_DIRS})
#link_directories ( ${Boost_LIBRARY_DIRS} )

#find_package(CryptoPP REQUIRED)
#include_directories(${CRYPTOPP_INCLUDE_DIRS})
#link_directories ( ${Boost_LIBRARY_DIRS} )


# static runtime requires /MT
#SET(Boost_USE_MULTITHREADED ON) #SET(Boost_USE_STATIC_RUNTIME OFF)
#find_package(Boost COMPONENTS thread date_time program_options filesystem system regex unit_test_framework)
#find_package(Boost COMPONENTS date_time program_options filesystem system unit_test_framework)
#include_directories(${Boost_INCLUDE_DIRS})
#link_directories ( ${Boost_LIBRARY_DIRS} )


if(NOT WIN32)
Expand Down Expand Up @@ -123,16 +105,14 @@ include_directories(${CMAKE_BINARY_DIR})

add_subdirectory(src)

#test are done with boost_tests:disable them if boost not found.
IF(Boost_FOUND)
ENABLE_TESTING()
INCLUDE(CTest)
IF(BUILD_TESTING)
SET(BUILDNAME "${BUILDNAME}" CACHE STRING "Name of build on the dashboard")
MARK_AS_ADVANCED(BUILDNAME)
ENDIF(BUILD_TESTING)
add_subdirectory(test)
ENDIF(Boost_FOUND)
ENABLE_TESTING()
INCLUDE(CTest)
IF(BUILD_TESTING)
SET(BUILDNAME "${BUILDNAME}" CACHE STRING "Name of build on the dashboard")
MARK_AS_ADVANCED(BUILDNAME)
ENDIF(BUILD_TESTING)
add_subdirectory(test)


#include(build/modules/CmakeDebugVariables.txt)

Expand Down
14 changes: 1 addition & 13 deletions build/linux/.gitignore
Original file line number Diff line number Diff line change
@@ -1,13 +1 @@
/CMakeFiles
/src
/test
/Testing
/CMakeCache.txt
/DartConfiguration.tcl
/lib
/cmake_install.cmake
/CTestTestfile.cmake
/Makefile
/doc
/nohup.out
/build_properties.h
/*
10 changes: 8 additions & 2 deletions src/license-generator/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@


if(WIN32)
ADD_LIBRARY(license_generator_lib STATIC
license-generator.cpp
win/LicenseSigner.cpp
)
else()
ADD_LIBRARY(license_generator_lib STATIC
license-generator.cpp
LicenseSigner.cpp
linux/LicenseSigner.cpp
)
endif()

link_directories ( ${Boost_LIBRARY_DIRS} )
add_dependencies( license_generator_lib boost_filesystem private_key )
Expand Down
File renamed without changes.
148 changes: 148 additions & 0 deletions src/license-generator/win/LicenseSigner.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
/*
* LicenseSigner.cpp
*
* Created on: Apr 6, 2014
* Author: devel
*/

#include "LicenseSigner.h"
#include "private-key.h"
#include <stdexcept>
#include <string.h>
#include <openssl/evp.h>
#include <openssl/bio.h>
#include <openssl/pem.h>
#include <openssl/err.h>
#include <iostream>
#include <cmath>

namespace license {
using namespace std;

LicenseSigner::LicenseSigner() {
os_initialize();
}

LicenseSigner::LicenseSigner(const std::string& alternatePrimaryKey) {
os_initialize();
}

string LicenseSigner::Opensslb64Encode(size_t slen, unsigned char* signature) {
/*
FILE* stream = fmemopen(*buffer, encodedSize+1, "w");
*/
//bio = BIO_new_fp(stdout, BIO_NOCLOSE);
/*int encodedSize = 4 * ceil(slen / 3);
char* buffer = (char*) (malloc(encodedSize + 1));
memset(buffer,0,encodedSize+1);*/
BIO* mem_bio = BIO_new(BIO_s_mem());
BIO* b64 = BIO_new(BIO_f_base64());
BIO* bio1 = BIO_push(b64, mem_bio);
BIO_set_flags(bio1, BIO_FLAGS_BASE64_NO_NL);
BIO_write(bio1, signature, slen);
BIO_flush(bio1);
char* charBuf;
int sz = BIO_get_mem_data(mem_bio, &charBuf);
string signatureStr;
signatureStr.assign(charBuf, sz);
BIO_free_all(bio1);
return signatureStr;
}

string LicenseSigner::signString(const string& license) {

size_t slen;
unsigned char* signature;
signature = NULL;
/* Create the Message Digest Context */
EVP_MD_CTX* mdctx = EVP_MD_CTX_create();
if (!mdctx) {
throw logic_error("Message digest creation context");
}
const char *private_key = PRIVATE_KEY
;
BIO* bio = BIO_new_mem_buf((void*) (private_key), strlen(private_key));
EVP_PKEY *pktmp = PEM_read_bio_PrivateKey(bio, NULL, NULL, NULL);
BIO_free(bio);
/*Initialise the DigestSign operation - SHA-256 has been selected
* as the message digest function in this example */
if (1 != EVP_DigestSignInit(mdctx, NULL, EVP_sha256(), NULL, pktmp)) {
EVP_MD_CTX_destroy(mdctx);
}
/* Call update with the message */
if (EVP_DigestSignUpdate(mdctx, license.c_str(), license.length()) != 1) {
EVP_MD_CTX_destroy(mdctx);
throw logic_error("Message signing exception");
}
/* Finalise the DigestSign operation */
/* First call EVP_DigestSignFinal with a NULL sig parameter to obtain the length of the
* signature. Length is returned in slen */
if (EVP_DigestSignFinal(mdctx, NULL, &slen) != 1) {
EVP_MD_CTX_destroy(mdctx);
throw logic_error("Message signature finalization exception");
}
/* Allocate memory for the signature based on size in slen */
if (!(signature = (unsigned char *) OPENSSL_malloc(
sizeof(unsigned char) * slen))) {
EVP_MD_CTX_destroy(mdctx);
throw logic_error("Message signature memory allocation exception");
}
/* Obtain the signature */
if (1 != EVP_DigestSignFinal(mdctx, signature, &slen)) {
OPENSSL_free(signature);
EVP_MD_CTX_destroy(mdctx);
throw logic_error("Message signature exception");
}
/*
FILE* stream = fmemopen(*buffer, encodedSize+1, "w");
*/
//bio = BIO_new_fp(stdout, BIO_NOCLOSE);
/*int encodedSize = 4 * ceil(slen / 3);
char* buffer = (char*) (malloc(encodedSize + 1));
memset(buffer,0,encodedSize+1);*/
string signatureStr = Opensslb64Encode(slen, signature);
/*
* BIO *bio, *b64;
char message[] = "Hello World \n";
b64 = BIO_new(BIO_f_base64());
bio = BIO_new_fp(stdout, BIO_NOCLOSE);
bio = BIO_push(b64, bio);
BIO_write(bio, message, strlen(message));
BIO_flush(bio);
BIO_free_all(bio);
Read Base64 encoded data from standard input and write the decoded data to standard output:
BIO *bio, *b64, *bio_out;
char inbuf[512];
int inlen;
b64 = BIO_new(BIO_f_base64());
bio = BIO_new_fp(stdin, BIO_NOCLOSE);
bio_out = BIO_new_fp(stdout, BIO_NOCLOSE);
bio = BIO_push(b64, bio);
while((inlen = BIO_read(bio, inbuf, 512)) > 0)
BIO_write(bio_out, inbuf, inlen);
BIO_free_all(bio);
*/
/* Clean up */
//free(buffer);
if (pktmp)
EVP_PKEY_free(pktmp);
if (signature)
OPENSSL_free(signature);

if (mdctx)
EVP_MD_CTX_destroy(mdctx);
return signatureStr;
}

void LicenseSigner::signLicense(FullLicenseInfo& licenseInfo) {
string license = licenseInfo.printForSign();
string signature = signString(license);
licenseInfo.license_signature = signature;
}

LicenseSigner::~LicenseSigner() {

}

} /* namespace license */
15 changes: 7 additions & 8 deletions test/library/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
link_directories ( ${Boost_LIBRARY_DIRS} )

add_executable(
license_reader_test
LicenseReader_test.cpp
Expand All @@ -8,15 +6,15 @@ add_executable(
target_link_libraries(
license_reader_test
license++_static
${Boost_LIBRARIES}
)

add_dependencies( license_reader_test boost_test boost_filesystem )
SET_TARGET_PROPERTIES(license_reader_test PROPERTIES LINK_SEARCH_START_STATIC ON)
ADD_TEST(license_reader_test ${EXECUTABLE_OUTPUT_PATH}/license_reader_test)

IF(WIN32)
#IF(WIN32)
#test windows
ELSE(WIN32)
#ELSE(WIN32)
add_executable(
os_linux_test
Os_Linux_test.cpp
Expand All @@ -25,9 +23,10 @@ ELSE(WIN32)
target_link_libraries(
os_linux_test
os
${Boost_LIBRARIES}
)


add_dependencies( os_linux_test boost_test )
SET_TARGET_PROPERTIES(os_linux_test PROPERTIES LINK_SEARCH_START_STATIC ON)
ADD_TEST(os_linux_test ${EXECUTABLE_OUTPUT_PATH}/os_linux_test)
ENDIF(WIN32)

#ENDIF(WIN32)
1 change: 1 addition & 0 deletions test/license-generator/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ target_link_libraries(
license_generator_lib
)

add_dependencies( license_generator_test boost_test boost_filesystem )
SET_TARGET_PROPERTIES(license_generator_test PROPERTIES LINK_SEARCH_START_STATIC ON)
ADD_TEST(license_generator_test ${EXECUTABLE_OUTPUT_PATH}/license_generator_test)

0 comments on commit ef84976

Please sign in to comment.