mirror of
https://gitee.com/milvus-io/milvus.git
synced 2024-12-05 05:18:52 +08:00
license check is vaild
Former-commit-id: 7381ad310d5b554c99f1f19f7fc460b33c36659f
This commit is contained in:
parent
384b9b8af2
commit
35eeae6f08
@ -45,6 +45,10 @@ endif ()
|
||||
|
||||
if(CMAKE_BUILD_TYPE STREQUAL "Release")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -fPIC -DELPP_THREAD_SAFE")
|
||||
if (GPU_VERSION STREQUAL "ON")
|
||||
set(ENABLE_LICENSE "ON")
|
||||
add_definitions("-DENABLE_LICENSE")
|
||||
endif ()
|
||||
else()
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -g -fPIC -DELPP_THREAD_SAFE")
|
||||
endif()
|
||||
|
@ -10,6 +10,9 @@ db_config:
|
||||
db_flush_interval: 5 #unit: second
|
||||
idmapper_max_open_file: 128
|
||||
|
||||
license_config:
|
||||
license_path: "/tmp/megasearch/abc.license"
|
||||
|
||||
log_config:
|
||||
global:
|
||||
format: "%datetime | %level | %logger | %msg"
|
||||
|
@ -12,8 +12,13 @@ aux_source_directory(db db_files)
|
||||
aux_source_directory(wrapper wrapper_files)
|
||||
|
||||
set(license_check_files
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/license/LicenseLibrary.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/license/LicenseLibrary.h
|
||||
license/LicenseLibrary.cpp
|
||||
license/LicenseCheck.cpp
|
||||
)
|
||||
|
||||
set(license_generator_src
|
||||
license/LicenseGenerator.cpp
|
||||
license/LicenseLibrary.cpp
|
||||
)
|
||||
|
||||
set(service_files
|
||||
@ -29,11 +34,8 @@ set(vecwise_engine_src
|
||||
${wrapper_files}
|
||||
)
|
||||
|
||||
set(license_generator_src
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/license/LicenseGenerator.cpp)
|
||||
|
||||
set(get_sys_info_src
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/license/GetSysInfo.cpp)
|
||||
license/GetSysInfo.cpp)
|
||||
|
||||
include_directories(/usr/include)
|
||||
include_directories(/usr/local/cuda/include)
|
||||
@ -63,10 +65,29 @@ else()
|
||||
)
|
||||
endif ()
|
||||
|
||||
cuda_add_library(vecwise_engine STATIC ${vecwise_engine_src})
|
||||
if (ENABLE_LICENSE STREQUAL "ON")
|
||||
link_directories(/usr/local/cuda/lib64/stubs)
|
||||
link_directories(/usr/local/cuda/lib64)
|
||||
set(license_libs
|
||||
nvidia-ml
|
||||
libboost_system.a
|
||||
libboost_filesystem.a
|
||||
libboost_serialization.a
|
||||
crypto
|
||||
cudart
|
||||
cublas
|
||||
)
|
||||
endif ()
|
||||
|
||||
|
||||
cuda_add_library(vecwise_engine STATIC ${vecwise_engine_src})
|
||||
target_link_libraries(vecwise_engine ${engine_libs})
|
||||
|
||||
if (ENABLE_LICENSE STREQUAL "ON")
|
||||
add_library(vecwise_license STATIC ${license_check_files})
|
||||
target_link_libraries(vecwise_license ${license_libs})
|
||||
endif ()
|
||||
|
||||
add_executable(vecwise_server
|
||||
${config_files}
|
||||
${server_files}
|
||||
@ -91,12 +112,17 @@ set(server_libs
|
||||
dl
|
||||
)
|
||||
|
||||
if (ENABLE_LICENSE STREQUAL "ON")
|
||||
target_link_libraries(vecwise_server ${server_libs} vecwise_license)
|
||||
else ()
|
||||
target_link_libraries(vecwise_server ${server_libs})
|
||||
endif()
|
||||
|
||||
if (ENABLE_LICENSE STREQUAL "ON")
|
||||
add_executable(license_generator ${license_generator_src})
|
||||
<<<<<<< b84d32553f910adf71e4ee069889e1d9fdd8a09f
|
||||
add_executable(get_sys_info ${get_sys_info_src})
|
||||
target_link_libraries(get_sys_info ${license_libs} vecwise_license)
|
||||
target_link_libraries(license_generator ${license_libs})
|
||||
endif ()
|
||||
|
||||
install(TARGETS vecwise_server DESTINATION bin)
|
||||
=======
|
||||
add_executable(get_sys_info ${get_sys_info_src})
|
||||
>>>>>>> Refactor code
|
||||
|
@ -1,133 +0,0 @@
|
||||
//
|
||||
// Created by zilliz on 19-5-10.
|
||||
//
|
||||
|
||||
#ifndef VECWISE_ENGINE_BOOSTARCHIVE_H
|
||||
#define VECWISE_ENGINE_BOOSTARCHIVE_H
|
||||
#include <list>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <boost/archive/text_iarchive.hpp>
|
||||
#include <boost/archive/text_oarchive.hpp>
|
||||
|
||||
using std::list;
|
||||
using std::ifstream;
|
||||
using std::ofstream;
|
||||
using std::string;
|
||||
using std::map;
|
||||
|
||||
template <class T>
|
||||
class BoostArchive
|
||||
{
|
||||
public:
|
||||
typedef T entity_type;
|
||||
typedef boost::archive::binary_iarchive InputArchive;
|
||||
typedef boost::archive::binary_oarchive OutputArchive;
|
||||
|
||||
BoostArchive(const string & archive_file_path)
|
||||
: _file_path_name(archive_file_path)
|
||||
, _p_ofs(NULL)
|
||||
, _p_output_archive(NULL)
|
||||
, _entity_nums(0)
|
||||
{
|
||||
load_arvhive_info();
|
||||
}
|
||||
~BoostArchive()
|
||||
{
|
||||
close_output();
|
||||
}
|
||||
//存储一个对象,序列化
|
||||
void store(const entity_type & entity);
|
||||
|
||||
//反序列化, 提取所有对象
|
||||
bool restore(list<entity_type> & entitys);
|
||||
|
||||
size_t size() const
|
||||
{
|
||||
return _entity_nums;
|
||||
}
|
||||
|
||||
private:
|
||||
void save_archive_info() //保存已序列化的对象个数信息
|
||||
{
|
||||
ofstream ofs;
|
||||
ofs.open(get_archive_info_file_path(),std::ios::out | std::ios::trunc);
|
||||
if (ofs.is_open())
|
||||
{
|
||||
ofs << _entity_nums;
|
||||
}
|
||||
ofs.close();
|
||||
}
|
||||
|
||||
void load_arvhive_info()//读取已序列化的对象个数信息
|
||||
{
|
||||
ifstream ifs;
|
||||
ifs.open(get_archive_info_file_path(),std::ios_base::in);
|
||||
if (ifs.is_open() && !ifs.eof())
|
||||
{
|
||||
int enity_num = 0;
|
||||
ifs >> enity_num;
|
||||
_entity_nums = enity_num;
|
||||
}
|
||||
ifs.close();
|
||||
}
|
||||
|
||||
string get_archive_info_file_path()
|
||||
{
|
||||
return "/tmp/vecwise_engine.meta";
|
||||
}
|
||||
|
||||
void close_output()
|
||||
{
|
||||
if (NULL != _p_output_archive)
|
||||
{
|
||||
delete _p_output_archive;
|
||||
_p_output_archive = NULL;
|
||||
save_archive_info();
|
||||
}
|
||||
if (NULL != _p_ofs)
|
||||
{
|
||||
delete _p_ofs;
|
||||
_p_ofs = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
size_t _entity_nums;
|
||||
string _file_path_name;
|
||||
ofstream * _p_ofs;
|
||||
OutputArchive * _p_output_archive;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
bool BoostArchive<T>::restore( list<entity_type> & entitys )
|
||||
{
|
||||
close_output();
|
||||
load_arvhive_info();
|
||||
ifstream ifs(_file_path_name);
|
||||
if (ifs)
|
||||
{
|
||||
InputArchive ia(ifs);
|
||||
for (size_t cnt = 0; cnt < _entity_nums; ++cnt)
|
||||
{
|
||||
entity_type entity;
|
||||
ia & entity;
|
||||
entitys.push_back(entity);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void BoostArchive<T>::store( const entity_type & entity )
|
||||
{
|
||||
if (NULL == _p_output_archive)
|
||||
{
|
||||
_p_ofs = new ofstream(_file_path_name);
|
||||
_p_output_archive = new OutputArchive(*_p_ofs);
|
||||
}
|
||||
(*_p_output_archive) & entity;
|
||||
++_entity_nums;
|
||||
}
|
||||
#endif //VECWISE_ENGINE_BOOSTARCHIVE_H
|
@ -1,15 +1,20 @@
|
||||
|
||||
#include "utils/Log.h"
|
||||
#include "LicenseLibrary.h"
|
||||
#include "utils/Error.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <getopt.h>
|
||||
#include <memory.h>
|
||||
|
||||
// Not provide path: current work path will be used and system.info.
|
||||
using namespace zilliz::vecwise;
|
||||
|
||||
void
|
||||
print_usage(const std::string &app_name) {
|
||||
printf("\n Usage: %s [OPTIONS]\n\n", app_name.c_str());
|
||||
printf(" Options:\n");
|
||||
printf(" -h --help Print this help\n");
|
||||
printf(" -d --sysinfo filename Generate system info file as given name\n");
|
||||
printf(" -s --sysinfo filename Generate system info file as given name\n");
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
@ -20,32 +25,59 @@ int main(int argc, char* argv[]) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
static struct option long_options[] = {{"system_info", required_argument, 0, 'd'},
|
||||
static struct option long_options[] = {{"system_info", required_argument, 0, 's'},
|
||||
{"help", no_argument, 0, 'h'},
|
||||
{NULL, 0, 0, 0}};
|
||||
int value = 0;
|
||||
int option_index = 0;
|
||||
std::string system_info_filename = "./system.info";
|
||||
while ((value = getopt_long(argc, argv, "d:h", long_options, &option_index)) != -1) {
|
||||
while ((value = getopt_long(argc, argv, "s:h", long_options, &option_index)) != -1) {
|
||||
switch (value) {
|
||||
case 'd': {
|
||||
case 's': {
|
||||
char *system_info_filename_ptr = strdup(optarg);
|
||||
system_info_filename = system_info_filename_ptr;
|
||||
free(system_info_filename_ptr);
|
||||
// printf("Generate system info file: %s\n", system_info_filename.c_str());
|
||||
break;
|
||||
}
|
||||
case 'h':
|
||||
print_usage(app_name);
|
||||
case 'h':print_usage(app_name);
|
||||
return EXIT_SUCCESS;
|
||||
case '?':
|
||||
print_usage(app_name);
|
||||
case '?':print_usage(app_name);
|
||||
return EXIT_FAILURE;
|
||||
default:
|
||||
print_usage(app_name);
|
||||
default:print_usage(app_name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int device_count = 0;
|
||||
server::ServerError err = server::LicenseLibrary::GetDeviceCount(device_count);
|
||||
if (err != server::SERVER_SUCCESS) return -1;
|
||||
|
||||
// 2. Get All GPU UUID
|
||||
std::vector<std::string> uuid_array;
|
||||
err = server::LicenseLibrary::GetUUID(device_count, uuid_array);
|
||||
if (err != server::SERVER_SUCCESS) return -1;
|
||||
|
||||
// 3. Get UUID SHA256
|
||||
std::vector<std::string> uuid_sha256_array;
|
||||
err = server::LicenseLibrary::GetUUIDSHA256(device_count, uuid_array, uuid_sha256_array);
|
||||
if (err != server::SERVER_SUCCESS) return -1;
|
||||
|
||||
// 4. Generate GPU ID map with GPU UUID
|
||||
std::map<int, std::string> uuid_encrption_map;
|
||||
for (int i = 0; i < device_count; ++i) {
|
||||
uuid_encrption_map[i] = uuid_sha256_array[i];
|
||||
}
|
||||
|
||||
|
||||
// 6. Generate GPU_info File
|
||||
err = server::LicenseLibrary::GPUinfoFileSerialization(system_info_filename,
|
||||
device_count,
|
||||
uuid_encrption_map);
|
||||
if (err != server::SERVER_SUCCESS) return -1;
|
||||
|
||||
printf("Generate GPU_info File Success\n");
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,28 +1,137 @@
|
||||
#include "LicenseCheck.h"
|
||||
#include <iostream>
|
||||
#include <boost/archive/binary_oarchive.hpp>
|
||||
#include <boost/archive/binary_iarchive.hpp>
|
||||
//#include <boost/foreach.hpp>
|
||||
//#include <boost/serialization/vector.hpp>
|
||||
#include <boost/filesystem/path.hpp>
|
||||
#include <boost/serialization/map.hpp>
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
|
||||
|
||||
namespace zilliz {
|
||||
namespace vecwise {
|
||||
namespace server {
|
||||
|
||||
class LicenseCheck {
|
||||
public:
|
||||
static LicenseCheck&
|
||||
GetInstance() {
|
||||
static LicenseCheck instance;
|
||||
return instance;
|
||||
|
||||
//ServerError
|
||||
//LicenseCheck::IntegrityCheck(const std::string &license_file_path, const std::string &secret_file_path) {
|
||||
//
|
||||
// std::string file_md5;
|
||||
// LicenseLibrary::GetFileMD5(license_file_path, file_md5);
|
||||
// time_t update_time;
|
||||
// off_t file_size;
|
||||
// LicenseLibrary::GetFileUpdateTimeAndSize(license_file_path, update_time, file_size);
|
||||
// time_t system_time;
|
||||
// LicenseLibrary::GetSystemTime(system_time);
|
||||
//
|
||||
// std::string output_file_md5;
|
||||
// time_t output_update_time;
|
||||
// off_t output_file_size;
|
||||
// time_t output_starting_time;
|
||||
// time_t output_end_time;
|
||||
// LicenseLibrary::SecretFileDeserialization(secret_file_path,
|
||||
// output_update_time,
|
||||
// output_file_size,
|
||||
// output_starting_time,
|
||||
// output_end_time,
|
||||
// output_file_md5);
|
||||
// if (file_md5 != output_file_md5) {
|
||||
// printf("License file has been modified\n");
|
||||
// return SERVER_UNEXPECTED_ERROR;
|
||||
// }
|
||||
// if (update_time != output_update_time) {
|
||||
// printf("update_time is wrong\n");
|
||||
// return SERVER_UNEXPECTED_ERROR;
|
||||
// }
|
||||
// if (file_size != output_file_size) {
|
||||
// printf("file_size is wrong\n");
|
||||
// return SERVER_UNEXPECTED_ERROR;
|
||||
// }
|
||||
// if (system_time < output_starting_time || system_time > output_end_time) {
|
||||
// printf("License expired\n");
|
||||
// return SERVER_UNEXPECTED_ERROR;
|
||||
// }
|
||||
// return SERVER_SUCCESS;
|
||||
//}
|
||||
|
||||
// Part 1: Legality check
|
||||
|
||||
ServerError
|
||||
LicenseCheck::LegalityCheck(const std::string &license_file_path) {
|
||||
|
||||
int device_count;
|
||||
LicenseLibrary::GetDeviceCount(device_count);
|
||||
std::vector<std::string> uuid_array;
|
||||
LicenseLibrary::GetUUID(device_count, uuid_array);
|
||||
|
||||
std::vector<std::string> sha_array;
|
||||
LicenseLibrary::GetUUIDSHA256(device_count, uuid_array, sha_array);
|
||||
|
||||
int output_device_count;
|
||||
std::map<int, std::string> uuid_encryption_map;
|
||||
time_t starting_time;
|
||||
time_t end_time;
|
||||
ServerError err = LicenseLibrary::LicenseFileDeserialization(license_file_path,
|
||||
output_device_count,
|
||||
uuid_encryption_map,
|
||||
starting_time,
|
||||
end_time);
|
||||
if(err !=SERVER_SUCCESS)
|
||||
{
|
||||
printf("License check error: 01\n");
|
||||
return SERVER_UNEXPECTED_ERROR;
|
||||
}
|
||||
time_t system_time;
|
||||
LicenseLibrary::GetSystemTime(system_time);
|
||||
|
||||
if (device_count != output_device_count) {
|
||||
printf("License check error: 02\n");
|
||||
return SERVER_UNEXPECTED_ERROR;
|
||||
}
|
||||
for (int i = 0; i < device_count; ++i) {
|
||||
if (sha_array[i] != uuid_encryption_map[i]) {
|
||||
printf("License check error: 03\n");
|
||||
return SERVER_UNEXPECTED_ERROR;
|
||||
}
|
||||
}
|
||||
if (system_time < starting_time || system_time > end_time) {
|
||||
printf("License check error: 04\n");
|
||||
return SERVER_UNEXPECTED_ERROR;
|
||||
}
|
||||
printf("Legality Check Success\n");
|
||||
return SERVER_SUCCESS;
|
||||
}
|
||||
|
||||
// Part 2: Timing check license
|
||||
|
||||
ServerError
|
||||
LicenseCheck::AlterFile(const std::string &license_file_path,
|
||||
const boost::system::error_code &ec,
|
||||
boost::asio::deadline_timer *pt) {
|
||||
|
||||
ServerError err = LegalityCheck(license_file_path);
|
||||
if(err!=SERVER_SUCCESS)
|
||||
{
|
||||
exit(1);
|
||||
}
|
||||
printf("---runing---\n");
|
||||
pt->expires_at(pt->expires_at() + boost::posix_time::hours(1));
|
||||
pt->async_wait(boost::bind(AlterFile, license_file_path, boost::asio::placeholders::error, pt));
|
||||
return SERVER_SUCCESS;
|
||||
|
||||
}
|
||||
|
||||
ServerError
|
||||
Check();
|
||||
LicenseCheck::StartCountingDown(const std::string &license_file_path) {
|
||||
|
||||
ServerError
|
||||
PeriodicUpdate();
|
||||
|
||||
private:
|
||||
LicenseCheck() {};
|
||||
|
||||
|
||||
};
|
||||
if (!LicenseLibrary::IsFileExistent(license_file_path)) return SERVER_LICENSE_FILE_NOT_EXIST;
|
||||
boost::asio::io_service io;
|
||||
boost::asio::deadline_timer t(io, boost::posix_time::hours(1));
|
||||
t.async_wait(boost::bind(AlterFile, license_file_path, boost::asio::placeholders::error, &t));
|
||||
io.run();
|
||||
return SERVER_SUCCESS;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,47 @@
|
||||
#pragma once
|
||||
|
||||
#include "utils/Error.h"
|
||||
#include "LicenseLibrary.h"
|
||||
|
||||
#include <boost/asio.hpp>
|
||||
#include <boost/thread.hpp>
|
||||
#include <boost/date_time/posix_time/posix_time.hpp>
|
||||
|
||||
|
||||
namespace zilliz {
|
||||
namespace vecwise {
|
||||
namespace server {
|
||||
|
||||
class LicenseCheck {
|
||||
public:
|
||||
static LicenseCheck &
|
||||
GetInstance() {
|
||||
static LicenseCheck instance;
|
||||
return instance;
|
||||
};
|
||||
|
||||
// static ServerError
|
||||
// IntegrityCheck(const std::string &license_file_path, const std::string &secret_file_path);
|
||||
|
||||
// Part 1: Legality check
|
||||
static ServerError
|
||||
LegalityCheck(const std::string &license_file_path);
|
||||
|
||||
|
||||
// Part 2: Timing check license
|
||||
static ServerError
|
||||
AlterFile(const std::string &license_file_path,
|
||||
const boost::system::error_code &ec,
|
||||
boost::asio::deadline_timer *pt);
|
||||
|
||||
|
||||
static ServerError
|
||||
StartCountingDown(const std::string &license_file_path);
|
||||
|
||||
private:
|
||||
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,71 +0,0 @@
|
||||
//
|
||||
// Created by zilliz on 19-5-11.
|
||||
//
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
|
||||
#include "utils/Error.h"
|
||||
#include "license/LicenseCheck.h"
|
||||
#include "license/LicensePublic.h"
|
||||
|
||||
using namespace zilliz::vecwise;
|
||||
|
||||
|
||||
|
||||
//TEST(LicenseTest, LICENSE_TEST) {
|
||||
//
|
||||
// std::string path1 = "/tmp/vecwise_engine.sha";
|
||||
// std::string path2 = "/tmp/vecwise_engine.license";
|
||||
// std::string path3 = "/tmp/vecwise_engine2.license";
|
||||
//
|
||||
// std::cout << "This is create licenseTime " << std::endl;
|
||||
//
|
||||
// server::ServerError err;
|
||||
// int deviceCount=0;
|
||||
//
|
||||
// std::vector<std::string> shas;
|
||||
// err = server::LicenseLoad(path1,deviceCount,shas);
|
||||
// ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
//
|
||||
// std::map<int,std::string> uuidEncryption;
|
||||
// std::cout<< "deviceCount : " << deviceCount << std::endl;
|
||||
// for(int i=0;i<deviceCount;i++)
|
||||
// {
|
||||
// std::cout<< "uuidshas : " << shas[i] << std::endl;
|
||||
// uuidEncryption.insert(std::make_pair(i,shas[i]));
|
||||
// }
|
||||
// int64_t RemainingTime;
|
||||
// std::cout<< "cin RemainingTime: (Hours)" << std::endl;
|
||||
// std::cin >> RemainingTime ;
|
||||
//
|
||||
// err = server::LiSave(path2,deviceCount,uuidEncryption,RemainingTime);
|
||||
// ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
//
|
||||
//// int64_t RemainingTimecheck;
|
||||
//// std::map<int,std::string> uuidEncryptioncheck;
|
||||
//// int deviceCountcheck;
|
||||
//// err = server::LiLoad(path2,deviceCountcheck,uuidEncryptioncheck,RemainingTimecheck);
|
||||
////
|
||||
//// printf("\n deviceCountcheck = %d\n",deviceCountcheck);
|
||||
//// std::cout<< "RemainingTimecheck: " << RemainingTimecheck<< std::endl;
|
||||
//
|
||||
// time_t update_time;
|
||||
// off_t file_size;
|
||||
// std::string filemd5;
|
||||
//
|
||||
// server::LicenseGetfiletime(path2,update_time);
|
||||
// ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
// server::LicenseGetfilesize(path2,file_size);
|
||||
// ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
// server::LicenseGetfilemd5(path2,filemd5);
|
||||
// ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
//
|
||||
//
|
||||
// err = server::LifileSave(path3,update_time,file_size,filemd5);
|
||||
// ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
//
|
||||
// std::cout<< "success" << std::endl;
|
||||
//
|
||||
//}
|
@ -1,33 +0,0 @@
|
||||
//
|
||||
// Created by zilliz on 19-5-11.
|
||||
//
|
||||
#include <gtest/gtest.h>
|
||||
#include <iostream>
|
||||
|
||||
#include "utils/Error.h"
|
||||
#include "license/LicenseCheck.h"
|
||||
|
||||
|
||||
using namespace zilliz::vecwise;
|
||||
|
||||
//
|
||||
//TEST(LicenseTest, LICENSE_TEST) {
|
||||
//
|
||||
// std::string path1 = "/tmp/vecwise_engine.sha";
|
||||
// std::cout << "This is create uuidshafile " << std::endl;
|
||||
//
|
||||
// server::ServerError err;
|
||||
// int deviceCount=0;
|
||||
// std::vector<std::string> uuids;
|
||||
//
|
||||
// err = server::LicenseGetuuid(deviceCount,uuids);
|
||||
// ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
//
|
||||
// std::vector<std::string> shas;
|
||||
// err = server::LicenseGetuuidsha(deviceCount,uuids,shas);
|
||||
// ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
//
|
||||
// err = server::LicenseSave(path1,deviceCount,shas);
|
||||
// ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
//
|
||||
//}
|
@ -10,12 +10,19 @@
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
|
||||
class LicenseFile {
|
||||
public:
|
||||
LicenseFile() = default;
|
||||
|
||||
LicenseFile(const int &device_count, const std::map<int, std::string> &uuid_encryption_map, const int64_t &remaining_hour)
|
||||
: device_count_(device_count), uuid_encryption_map_(uuid_encryption_map), remaining_hour_(remaining_hour) {}
|
||||
LicenseFile(const int &device_count,
|
||||
const std::map<int, std::string> &uuid_encryption_map,
|
||||
const time_t &starting_time,
|
||||
const time_t &end_time)
|
||||
: device_count_(device_count),
|
||||
uuid_encryption_map_(uuid_encryption_map),
|
||||
starting_time_(starting_time),
|
||||
end_time_(end_time) {}
|
||||
|
||||
int get_device_count() {
|
||||
return device_count_;
|
||||
@ -23,8 +30,11 @@ class LicenseFile {
|
||||
std::map<int, std::string> &get_uuid_encryption_map() {
|
||||
return uuid_encryption_map_;
|
||||
}
|
||||
int64_t get_remaining_hour() {
|
||||
return remaining_hour_;
|
||||
time_t get_starting_time() {
|
||||
return starting_time_;
|
||||
}
|
||||
time_t get_end_time() {
|
||||
return end_time_;
|
||||
}
|
||||
|
||||
public:
|
||||
@ -34,13 +44,15 @@ class LicenseFile {
|
||||
void serialize(Archive &ar, const unsigned int version) {
|
||||
ar & device_count_;
|
||||
ar & uuid_encryption_map_;
|
||||
ar & remaining_hour_;
|
||||
ar & starting_time_;
|
||||
ar & end_time_;
|
||||
}
|
||||
|
||||
public:
|
||||
int device_count_ = 0;
|
||||
std::map<int, std::string> uuid_encryption_map_;
|
||||
int64_t remaining_hour_ = 0;
|
||||
time_t starting_time_ = 0;
|
||||
time_t end_time_ = 0;
|
||||
};
|
||||
|
||||
class SerializedLicenseFile {
|
||||
|
@ -1,6 +1,136 @@
|
||||
|
||||
#include <iostream>
|
||||
int main() {
|
||||
std::cout << "This is license generator" << std::endl;
|
||||
#include <getopt.h>
|
||||
#include <memory.h>
|
||||
|
||||
#include "utils/Log.h"
|
||||
#include "license/LicenseLibrary.h"
|
||||
#include "utils/Error.h"
|
||||
|
||||
|
||||
using namespace zilliz::vecwise;
|
||||
// Not provide path: current work path will be used and system.info.
|
||||
|
||||
void
|
||||
print_usage(const std::string &app_name) {
|
||||
printf("\n Usage: %s [OPTIONS]\n\n", app_name.c_str());
|
||||
printf(" Options:\n");
|
||||
printf(" -h --help Print this help\n");
|
||||
printf(" -s --sysinfo filename sysinfo file location\n");
|
||||
printf(" -l --license filename Generate license file as given name\n");
|
||||
printf(" -b --starting time Set start time Similar to year-month-day\n");
|
||||
printf(" -e --end time Set end time Similar to year-month-day \n");
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
std::string app_name = argv[0];
|
||||
// if (argc != 1 && argc != 3) {
|
||||
// print_usage(app_name);
|
||||
// return EXIT_FAILURE;
|
||||
// }
|
||||
static struct option long_options[] = {{"system_info", required_argument, 0, 's'},
|
||||
{"license", optional_argument, 0, 'l'},
|
||||
{"help", no_argument, 0, 'h'},
|
||||
{"starting_time", required_argument, 0, 'b'},
|
||||
{"end_time", required_argument, 0, 'e'},
|
||||
{NULL, 0, 0, 0}};
|
||||
server::ServerError err;
|
||||
int value = 0;
|
||||
int option_index = 0;
|
||||
std::string system_info_filename = "./system.info";
|
||||
std::string license_filename = "./system.license";
|
||||
char *string_starting_time = NULL;
|
||||
char *string_end_time = NULL;
|
||||
time_t starting_time = 0;
|
||||
time_t end_time = 0;
|
||||
int flag_s = 1;
|
||||
int flag_b = 1;
|
||||
int flag_e = 1;
|
||||
while ((value = getopt_long(argc, argv, "hl:s:b:e:", long_options, NULL)) != -1) {
|
||||
switch (value) {
|
||||
case 's': {
|
||||
flag_s = 0;
|
||||
system_info_filename = (std::string) (optarg);
|
||||
// char *system_info_filename_ptr = strdup(optarg);
|
||||
// system_info_filename = system_info_filename_ptr;
|
||||
// free(system_info_filename_ptr);
|
||||
// printf("Generate system info file: %s\n", system_info_filename.c_str());
|
||||
break;
|
||||
}
|
||||
case 'b': {
|
||||
flag_b = 0;
|
||||
string_starting_time = optarg;
|
||||
// char *time = strdup(optarg);
|
||||
// err = server::LicenseLibrary::GetDateTime(time, starting_time);
|
||||
// if (err != server::SERVER_SUCCESS) return -1;
|
||||
// free(time);
|
||||
break;
|
||||
}
|
||||
case 'e': {
|
||||
flag_e = 0;
|
||||
string_end_time = optarg;
|
||||
// char *time = strdup(optarg);
|
||||
// err = server::LicenseLibrary::GetDateTime(time, end_time);
|
||||
// if (err != server::SERVER_SUCCESS) return -1;
|
||||
// free(time);
|
||||
break;
|
||||
}
|
||||
case 'l': {
|
||||
license_filename = (std::string) (optarg);
|
||||
// char *system_info_filename_ptr = strdup(optarg);
|
||||
// license_filename = system_info_filename_ptr;
|
||||
// free(system_info_filename_ptr);
|
||||
break;
|
||||
}
|
||||
case 'h':print_usage(app_name);
|
||||
return EXIT_SUCCESS;
|
||||
case '?':print_usage(app_name);
|
||||
return EXIT_FAILURE;
|
||||
default:print_usage(app_name);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
if (flag_s) {
|
||||
printf("Error: sysinfo file location must be entered\n");
|
||||
return 1;
|
||||
}
|
||||
if (flag_b) {
|
||||
printf("Error: start time must be entered\n");
|
||||
return 1;
|
||||
}
|
||||
if (flag_e) {
|
||||
printf("Error: end time must be entered\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
err = server::LicenseLibrary::GetDateTime(string_starting_time, starting_time);
|
||||
if (err != server::SERVER_SUCCESS) return -1;
|
||||
|
||||
err = server::LicenseLibrary::GetDateTime(string_end_time, end_time);
|
||||
if (err != server::SERVER_SUCCESS) return -1;
|
||||
|
||||
|
||||
int output_info_device_count = 0;
|
||||
std::map<int, std::string> output_info_uuid_encrption_map;
|
||||
|
||||
|
||||
err = server::LicenseLibrary::GPUinfoFileDeserialization(system_info_filename,
|
||||
output_info_device_count,
|
||||
output_info_uuid_encrption_map);
|
||||
if (err != server::SERVER_SUCCESS) return -1;
|
||||
|
||||
|
||||
err = server::LicenseLibrary::LicenseFileSerialization(license_filename,
|
||||
output_info_device_count,
|
||||
output_info_uuid_encrption_map,
|
||||
starting_time,
|
||||
end_time);
|
||||
if (err != server::SERVER_SUCCESS) return -1;
|
||||
|
||||
|
||||
printf("Generate License File Success\n");
|
||||
|
||||
return 0;
|
||||
}
|
@ -133,12 +133,19 @@ LicenseLibrary::GetUUIDSHA256(const int &device_count,
|
||||
return SERVER_SUCCESS;
|
||||
}
|
||||
|
||||
ServerError
|
||||
LicenseLibrary::GetSystemTime(time_t &system_time) {
|
||||
system_time = time(NULL);
|
||||
return SERVER_SUCCESS;
|
||||
}
|
||||
|
||||
// Part 2: Handle License File
|
||||
ServerError
|
||||
LicenseLibrary::LicenseFileSerialization(const std::string &path,
|
||||
int device_count,
|
||||
const std::map<int, std::string> &uuid_encrption_map,
|
||||
int64_t remaining_hour) {
|
||||
time_t starting_time,
|
||||
time_t end_time) {
|
||||
|
||||
std::ofstream file(path);
|
||||
boost::archive::binary_oarchive oa(file);
|
||||
@ -146,7 +153,10 @@ LicenseLibrary::LicenseFileSerialization(const std::string &path,
|
||||
|
||||
SerializedLicenseFile serialized_license_file;
|
||||
|
||||
serialized_license_file.set_license_file(new LicenseFile(device_count, uuid_encrption_map, remaining_hour));
|
||||
serialized_license_file.set_license_file(new LicenseFile(device_count,
|
||||
uuid_encrption_map,
|
||||
starting_time,
|
||||
end_time));
|
||||
oa << serialized_license_file;
|
||||
|
||||
file.close();
|
||||
@ -157,9 +167,9 @@ ServerError
|
||||
LicenseLibrary::LicenseFileDeserialization(const std::string &path,
|
||||
int &device_count,
|
||||
std::map<int, std::string> &uuid_encrption_map,
|
||||
int64_t &remaining_hour) {
|
||||
time_t &starting_time,
|
||||
time_t &end_time) {
|
||||
if (!IsFileExistent(path)) return SERVER_LICENSE_FILE_NOT_EXIST;
|
||||
|
||||
std::ifstream file(path);
|
||||
boost::archive::binary_iarchive ia(file);
|
||||
ia.register_type<LicenseFile>();
|
||||
@ -169,49 +179,56 @@ LicenseLibrary::LicenseFileDeserialization(const std::string &path,
|
||||
|
||||
device_count = serialized_license_file.get_license_file()->get_device_count();
|
||||
uuid_encrption_map = serialized_license_file.get_license_file()->get_uuid_encryption_map();
|
||||
remaining_hour = serialized_license_file.get_license_file()->get_remaining_hour();
|
||||
starting_time = serialized_license_file.get_license_file()->get_starting_time();
|
||||
end_time = serialized_license_file.get_license_file()->get_end_time();
|
||||
|
||||
file.close();
|
||||
return SERVER_SUCCESS;
|
||||
}
|
||||
|
||||
ServerError
|
||||
LicenseLibrary::SecretFileSerialization(const std::string &path,
|
||||
const time_t &update_time,
|
||||
const off_t &file_size,
|
||||
const std::string &file_md5) {
|
||||
std::ofstream file(path);
|
||||
boost::archive::binary_oarchive oa(file);
|
||||
oa.register_type<SecretFile>();
|
||||
|
||||
SerializedSecretFile serialized_secret_file;
|
||||
|
||||
serialized_secret_file.set_secret_file(new SecretFile(update_time, file_size, file_md5));
|
||||
oa << serialized_secret_file;
|
||||
|
||||
file.close();
|
||||
return SERVER_SUCCESS;
|
||||
}
|
||||
|
||||
ServerError
|
||||
LicenseLibrary::SecretFileDeserialization(const std::string &path,
|
||||
time_t &update_time,
|
||||
off_t &file_size,
|
||||
std::string &file_md5) {
|
||||
if(!IsFileExistent(path)) return SERVER_LICENSE_FILE_NOT_EXIST;
|
||||
|
||||
std::ifstream file(path);
|
||||
boost::archive::binary_iarchive ia(file);
|
||||
ia.register_type<SecretFile>();
|
||||
SerializedSecretFile serialized_secret_file;
|
||||
|
||||
ia >> serialized_secret_file;
|
||||
update_time = serialized_secret_file.get_secret_file()->get_update_time();
|
||||
file_size = serialized_secret_file.get_secret_file()->get_file_size();
|
||||
file_md5 = serialized_secret_file.get_secret_file()->get_file_md5();
|
||||
file.close();
|
||||
return SERVER_SUCCESS;
|
||||
}
|
||||
//ServerError
|
||||
//LicenseLibrary::SecretFileSerialization(const std::string &path,
|
||||
// const time_t &update_time,
|
||||
// const off_t &file_size,
|
||||
// const time_t &starting_time,
|
||||
// const time_t &end_time,
|
||||
// const std::string &file_md5) {
|
||||
// std::ofstream file(path);
|
||||
// boost::archive::binary_oarchive oa(file);
|
||||
// oa.register_type<SecretFile>();
|
||||
//
|
||||
// SerializedSecretFile serialized_secret_file;
|
||||
//
|
||||
// serialized_secret_file.set_secret_file(new SecretFile(update_time, file_size, starting_time, end_time, file_md5));
|
||||
// oa << serialized_secret_file;
|
||||
//
|
||||
// file.close();
|
||||
// return SERVER_SUCCESS;
|
||||
//}
|
||||
//
|
||||
//ServerError
|
||||
//LicenseLibrary::SecretFileDeserialization(const std::string &path,
|
||||
// time_t &update_time,
|
||||
// off_t &file_size,
|
||||
// time_t &starting_time,
|
||||
// time_t &end_time,
|
||||
// std::string &file_md5) {
|
||||
// if (!IsFileExistent(path)) return SERVER_LICENSE_FILE_NOT_EXIST;
|
||||
//
|
||||
// std::ifstream file(path);
|
||||
// boost::archive::binary_iarchive ia(file);
|
||||
// ia.register_type<SecretFile>();
|
||||
// SerializedSecretFile serialized_secret_file;
|
||||
//
|
||||
// ia >> serialized_secret_file;
|
||||
// update_time = serialized_secret_file.get_secret_file()->get_update_time();
|
||||
// file_size = serialized_secret_file.get_secret_file()->get_file_size();
|
||||
// starting_time = serialized_secret_file.get_secret_file()->get_starting_time();
|
||||
// end_time = serialized_secret_file.get_secret_file()->get_end_time();
|
||||
// file_md5 = serialized_secret_file.get_secret_file()->get_file_md5();
|
||||
// file.close();
|
||||
// return SERVER_SUCCESS;
|
||||
//}
|
||||
|
||||
// Part 3: File attribute: UpdateTime Time/ Size/ MD5
|
||||
ServerError
|
||||
@ -303,115 +320,143 @@ LicenseLibrary::GPUinfoFileDeserialization(const std::string &path,
|
||||
return SERVER_SUCCESS;
|
||||
}
|
||||
|
||||
ServerError
|
||||
LicenseLibrary::GetDateTime(char *cha, time_t &data_time) {
|
||||
tm tm_;
|
||||
int year, month, day;
|
||||
sscanf(cha, "%d-%d-%d", &year, &month, &day);
|
||||
tm_.tm_year = year - 1900;
|
||||
tm_.tm_mon = month - 1;
|
||||
tm_.tm_mday = day;
|
||||
tm_.tm_hour = 0;
|
||||
tm_.tm_min = 0;
|
||||
tm_.tm_sec = 0;
|
||||
tm_.tm_isdst = 0;
|
||||
data_time = mktime(&tm_);
|
||||
return SERVER_SUCCESS;
|
||||
|
||||
}
|
||||
// Part 5: Integrity check and Legality check
|
||||
ServerError
|
||||
LicenseLibrary::IntegrityCheck(const std::string &license_file_path, const std::string &secret_file_path) {
|
||||
//ServerError
|
||||
//LicenseLibrary::IntegrityCheck(const std::string &license_file_path, const std::string &secret_file_path) {
|
||||
//
|
||||
// std::string file_md5;
|
||||
// GetFileMD5(license_file_path, file_md5);
|
||||
// time_t update_time;
|
||||
// off_t file_size;
|
||||
// GetFileUpdateTimeAndSize(license_file_path, update_time, file_size);
|
||||
// time_t system_time;
|
||||
// GetSystemTime(system_time);
|
||||
//
|
||||
// std::string output_file_md5;
|
||||
// time_t output_update_time;
|
||||
// off_t output_file_size;
|
||||
// time_t output_starting_time;
|
||||
// time_t output_end_time;
|
||||
// SecretFileDeserialization(secret_file_path,
|
||||
// output_update_time,
|
||||
// output_file_size,
|
||||
// output_starting_time,
|
||||
// output_end_time,
|
||||
// output_file_md5);
|
||||
// if (file_md5 != output_file_md5) {
|
||||
// printf("License file has been modified\n");
|
||||
// return SERVER_UNEXPECTED_ERROR;
|
||||
// }
|
||||
// if (update_time != output_update_time) {
|
||||
// printf("update_time is wrong\n");
|
||||
// return SERVER_UNEXPECTED_ERROR;
|
||||
// }
|
||||
// if (file_size != output_file_size) {
|
||||
// printf("file_size is wrong\n");
|
||||
// return SERVER_UNEXPECTED_ERROR;
|
||||
// }
|
||||
// if (system_time < output_starting_time || system_time > output_end_time) {
|
||||
// printf("License expired\n");
|
||||
// return SERVER_UNEXPECTED_ERROR;
|
||||
// }
|
||||
// return SERVER_SUCCESS;
|
||||
//}
|
||||
//
|
||||
//ServerError
|
||||
//LicenseLibrary::LegalityCheck(const std::string &license_file_path) {
|
||||
//
|
||||
// int device_count;
|
||||
// GetDeviceCount(device_count);
|
||||
// std::vector<std::string> uuid_array;
|
||||
// GetUUID(device_count, uuid_array);
|
||||
//
|
||||
// std::vector<std::string> sha_array;
|
||||
// GetUUIDSHA256(device_count, uuid_array, sha_array);
|
||||
//
|
||||
// int output_device_count;
|
||||
// std::map<int, std::string> uuid_encryption_map;
|
||||
// int64_t remaining_time;
|
||||
// LicenseFileDeserialization(license_file_path, output_device_count, uuid_encryption_map, remaining_time);
|
||||
//
|
||||
// if (device_count != output_device_count) {
|
||||
// printf("device_count is wrong\n");
|
||||
// return SERVER_UNEXPECTED_ERROR;
|
||||
// }
|
||||
// for (int i = 0; i < device_count; ++i) {
|
||||
// if (sha_array[i] != uuid_encryption_map[i]) {
|
||||
// printf("uuid_encryption_map %d is wrong\n", i);
|
||||
// return SERVER_UNEXPECTED_ERROR;
|
||||
// }
|
||||
// }
|
||||
// if (remaining_time <= 0) {
|
||||
// printf("License expired\n");
|
||||
// return SERVER_UNEXPECTED_ERROR;
|
||||
// }
|
||||
// std::cout << "Legality Check Success" << std::endl;
|
||||
// return SERVER_SUCCESS;
|
||||
//}
|
||||
|
||||
std::string file_md5;
|
||||
GetFileMD5(license_file_path, file_md5);
|
||||
time_t update_time;
|
||||
off_t file_size;
|
||||
GetFileUpdateTimeAndSize(license_file_path, update_time, file_size);
|
||||
|
||||
std::string output_file_md5;
|
||||
time_t output_update_time;
|
||||
off_t output_file_size;
|
||||
SecretFileDeserialization(secret_file_path, output_update_time, output_file_size, output_file_md5);
|
||||
if (file_md5 != output_file_md5) {
|
||||
printf("License file has been modified\n");
|
||||
return SERVER_UNEXPECTED_ERROR;
|
||||
}
|
||||
if (update_time != output_update_time) {
|
||||
printf("update_time is wrong\n");
|
||||
return SERVER_UNEXPECTED_ERROR;
|
||||
}
|
||||
if (file_size != output_file_size) {
|
||||
printf("file_size is wrong\n");
|
||||
return SERVER_UNEXPECTED_ERROR;
|
||||
}
|
||||
|
||||
return SERVER_SUCCESS;
|
||||
}
|
||||
|
||||
ServerError
|
||||
LicenseLibrary::LegalityCheck(const std::string &license_file_path) {
|
||||
|
||||
int device_count;
|
||||
GetDeviceCount(device_count);
|
||||
std::vector<std::string> uuid_array;
|
||||
GetUUID(device_count, uuid_array);
|
||||
|
||||
std::vector<std::string> sha_array;
|
||||
GetUUIDSHA256(device_count, uuid_array, sha_array);
|
||||
|
||||
int output_device_count;
|
||||
std::map<int, std::string> uuid_encryption_map;
|
||||
int64_t remaining_time;
|
||||
LicenseFileDeserialization(license_file_path, output_device_count, uuid_encryption_map, remaining_time);
|
||||
|
||||
if (device_count != output_device_count) {
|
||||
printf("device_count is wrong\n");
|
||||
return SERVER_UNEXPECTED_ERROR;
|
||||
}
|
||||
for (int i = 0; i < device_count; ++i) {
|
||||
if (sha_array[i] != uuid_encryption_map[i]) {
|
||||
printf("uuid_encryption_map %d is wrong\n", i);
|
||||
return SERVER_UNEXPECTED_ERROR;
|
||||
}
|
||||
}
|
||||
if (remaining_time <= 0) {
|
||||
printf("License expired\n");
|
||||
return SERVER_UNEXPECTED_ERROR;
|
||||
}
|
||||
std::cout << "Legality Check Success" << std::endl;
|
||||
return SERVER_SUCCESS;
|
||||
}
|
||||
|
||||
// Part 6: Timer
|
||||
ServerError
|
||||
LicenseLibrary::AlterFile(const std::string &license_file_path,
|
||||
const std::string &secret_file_path,
|
||||
const boost::system::error_code &ec,
|
||||
boost::asio::deadline_timer *pt) {
|
||||
int device_count;
|
||||
std::map<int, std::string> uuid_encryption_map;
|
||||
int64_t remaining_time;
|
||||
LicenseFileDeserialization(license_file_path, device_count, uuid_encryption_map, remaining_time);
|
||||
|
||||
std::cout << "remaining_time: " << remaining_time << std::endl;
|
||||
|
||||
if (remaining_time <= 0) {
|
||||
std::cout << "License expired" << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
--remaining_time;
|
||||
LicenseFileSerialization(license_file_path, device_count, uuid_encryption_map, remaining_time);
|
||||
|
||||
time_t update_time;
|
||||
off_t file_size;
|
||||
GetFileUpdateTimeAndSize(license_file_path, update_time, file_size);
|
||||
std::string file_md5;
|
||||
GetFileMD5(license_file_path, file_md5);
|
||||
SecretFileSerialization(secret_file_path, update_time, file_size, file_md5);
|
||||
|
||||
pt->expires_at(pt->expires_at() + boost::posix_time::hours(1));
|
||||
pt->async_wait(boost::bind(AlterFile, license_file_path, secret_file_path, boost::asio::placeholders::error, pt));
|
||||
return SERVER_SUCCESS;
|
||||
}
|
||||
|
||||
ServerError
|
||||
LicenseLibrary::StartCountingDown(const std::string &license_file_path, const std::string &secret_file_path) {
|
||||
|
||||
if(!IsFileExistent(license_file_path)) return SERVER_LICENSE_FILE_NOT_EXIST;
|
||||
if(!IsFileExistent(secret_file_path)) return SERVER_LICENSE_FILE_NOT_EXIST;
|
||||
|
||||
boost::asio::io_service io;
|
||||
boost::asio::deadline_timer t(io, boost::posix_time::hours(1));
|
||||
t.async_wait(boost::bind(AlterFile, license_file_path, secret_file_path, boost::asio::placeholders::error, &t));
|
||||
std::cout << "Timing begins" << std::endl;
|
||||
io.run();
|
||||
return SERVER_SUCCESS;
|
||||
}
|
||||
//// Part 6: Timer
|
||||
//ServerError
|
||||
//LicenseLibrary::AlterFile(const std::string &license_file_path,
|
||||
// const std::string &secret_file_path,
|
||||
// const boost::system::error_code &ec,
|
||||
// boost::asio::deadline_timer *pt) {
|
||||
// int device_count;
|
||||
// std::map<int, std::string> uuid_encryption_map;
|
||||
// int64_t remaining_time;
|
||||
// LicenseFileDeserialization(license_file_path, device_count, uuid_encryption_map, remaining_time);
|
||||
//
|
||||
// std::cout << "remaining_time: " << remaining_time << std::endl;
|
||||
//
|
||||
// if (remaining_time <= 0) {
|
||||
// std::cout << "License expired" << std::endl;
|
||||
// exit(1);
|
||||
// }
|
||||
// --remaining_time;
|
||||
// LicenseFileSerialization(license_file_path, device_count, uuid_encryption_map, remaining_time);
|
||||
//
|
||||
// time_t update_time;
|
||||
// off_t file_size;
|
||||
// GetFileUpdateTimeAndSize(license_file_path, update_time, file_size);
|
||||
// std::string file_md5;
|
||||
// GetFileMD5(license_file_path, file_md5);
|
||||
// SecretFileSerialization(secret_file_path, update_time, file_size, file_md5);
|
||||
//
|
||||
// pt->expires_at(pt->expires_at() + boost::posix_time::hours(1));
|
||||
// pt->async_wait(boost::bind(AlterFile, license_file_path, secret_file_path, boost::asio::placeholders::error, pt));
|
||||
// return SERVER_SUCCESS;
|
||||
//}
|
||||
//
|
||||
//ServerError
|
||||
//LicenseLibrary::StartCountingDown(const std::string &license_file_path, const std::string &secret_file_path) {
|
||||
//
|
||||
// if (!IsFileExistent(license_file_path)) return SERVER_LICENSE_FILE_NOT_EXIST;
|
||||
// if (!IsFileExistent(secret_file_path)) return SERVER_LICENSE_FILE_NOT_EXIST;
|
||||
//
|
||||
// boost::asio::io_service io;
|
||||
// boost::asio::deadline_timer t(io, boost::posix_time::hours(1));
|
||||
// t.async_wait(boost::bind(AlterFile, license_file_path, secret_file_path, boost::asio::placeholders::error, &t));
|
||||
// std::cout << "Timing begins" << std::endl;
|
||||
// io.run();
|
||||
// return SERVER_SUCCESS;
|
||||
//}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "LicenseFile.h"
|
||||
#include "SecretFile.h"
|
||||
#include "GPUInfoFile.h"
|
||||
|
||||
#include "utils/Error.h"
|
||||
@ -12,6 +11,7 @@
|
||||
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <time.h>
|
||||
|
||||
|
||||
namespace zilliz {
|
||||
@ -40,26 +40,39 @@ class LicenseLibrary {
|
||||
std::vector<std::string> &uuid_array,
|
||||
std::vector<std::string> &sha_array);
|
||||
|
||||
static ServerError
|
||||
GetSystemTime(time_t &system_time);
|
||||
|
||||
// Part 2: Handle License File
|
||||
static ServerError
|
||||
LicenseFileSerialization(const std::string &path,
|
||||
int device_count,
|
||||
const std::map<int, std::string> &uuid_encrption_map, int64_t remaining_hour);
|
||||
const std::map<int, std::string> &uuid_encrption_map,
|
||||
time_t starting_time,
|
||||
time_t end_time);
|
||||
|
||||
static ServerError
|
||||
LicenseFileDeserialization(const std::string &path,
|
||||
int &device_count,
|
||||
std::map<int, std::string> &uuid_encrption_map,
|
||||
int64_t &remaining_hour);
|
||||
time_t &starting_time,
|
||||
time_t &end_time);
|
||||
|
||||
static ServerError
|
||||
SecretFileSerialization(const std::string &path,
|
||||
const time_t &update_time,
|
||||
const off_t &file_size,
|
||||
const std::string &file_md5);
|
||||
|
||||
static ServerError
|
||||
SecretFileDeserialization(const std::string &path, time_t &update_time, off_t &file_size, std::string &file_md5);
|
||||
// static ServerError
|
||||
// SecretFileSerialization(const std::string &path,
|
||||
// const time_t &update_time,
|
||||
// const off_t &file_size,
|
||||
// const time_t &starting_time,
|
||||
// const time_t &end_time,
|
||||
// const std::string &file_md5);
|
||||
//
|
||||
// static ServerError
|
||||
// SecretFileDeserialization(const std::string &path,
|
||||
// time_t &update_time,
|
||||
// off_t &file_size,
|
||||
// time_t &starting_time,
|
||||
// time_t &end_time,
|
||||
// std::string &file_md5);
|
||||
|
||||
// Part 3: File attribute: UpdateTime Time/ Size/ MD5
|
||||
static ServerError
|
||||
@ -78,22 +91,25 @@ class LicenseLibrary {
|
||||
int &device_count,
|
||||
std::map<int, std::string> &uuid_encrption_map);
|
||||
|
||||
// Part 5: Integrity check and Legality check
|
||||
static ServerError
|
||||
IntegrityCheck(const std::string &license_file_path, const std::string &secret_file_path);
|
||||
GetDateTime(char *cha, time_t &data_time);
|
||||
|
||||
static ServerError
|
||||
LegalityCheck(const std::string &license_file_path);
|
||||
// Part 5: Integrity check and Legality check
|
||||
// static ServerError
|
||||
// IntegrityCheck(const std::string &license_file_path, const std::string &secret_file_path);
|
||||
//
|
||||
// static ServerError
|
||||
// LegalityCheck(const std::string &license_file_path);
|
||||
|
||||
// Part 6: Timer
|
||||
static ServerError
|
||||
AlterFile(const std::string &license_file_path,
|
||||
const std::string &secret_file_path,
|
||||
const boost::system::error_code &ec,
|
||||
boost::asio::deadline_timer *pt);
|
||||
|
||||
static ServerError
|
||||
StartCountingDown(const std::string &license_file_path, const std::string &secret_file_path);
|
||||
// static ServerError
|
||||
// AlterFile(const std::string &license_file_path,
|
||||
// const std::string &secret_file_path,
|
||||
// const boost::system::error_code &ec,
|
||||
// boost::asio::deadline_timer *pt);
|
||||
//
|
||||
// static ServerError
|
||||
// StartCountingDown(const std::string &license_file_path, const std::string &secret_file_path);
|
||||
|
||||
|
||||
private:
|
||||
|
@ -1,357 +0,0 @@
|
||||
//
|
||||
// Created by zilliz on 19-5-10.
|
||||
//
|
||||
|
||||
#include "LicensePublic.h"
|
||||
#include "license/LicenseCheck.h"
|
||||
//#include "BoostArchive.h"
|
||||
#define RTime 100
|
||||
|
||||
using std::string;
|
||||
using std::map;
|
||||
namespace zilliz {
|
||||
namespace vecwise {
|
||||
namespace server {
|
||||
|
||||
// GET /tmp/vecwise_engine.license
|
||||
class Licensedata1
|
||||
{
|
||||
public:
|
||||
Licensedata1()
|
||||
:_deviceCount(0)
|
||||
,_RemainingTime(RTime)
|
||||
{}
|
||||
|
||||
Licensedata1(const int& deviceCount,const map<int,string>& uuidEncryption)
|
||||
:_deviceCount(deviceCount)
|
||||
,_uuidEncryption(uuidEncryption)
|
||||
,_RemainingTime(RTime)
|
||||
{}
|
||||
|
||||
Licensedata1(const int& deviceCount,const map<int,string>& uuidEncryption,const int64_t& RemainingTime)
|
||||
:_deviceCount(deviceCount)
|
||||
,_uuidEncryption(uuidEncryption)
|
||||
,_RemainingTime(RemainingTime)
|
||||
{}
|
||||
|
||||
int GetdeviceCount()
|
||||
{
|
||||
return _deviceCount;
|
||||
}
|
||||
map<int,string> GetuuidEncryption()
|
||||
{
|
||||
return _uuidEncryption;
|
||||
}
|
||||
int64_t GetRemainingTime()
|
||||
{
|
||||
return _RemainingTime;
|
||||
}
|
||||
|
||||
private:
|
||||
friend class boost::serialization::access;
|
||||
template <typename Archive>
|
||||
void serialize(Archive &ar, const unsigned int version)
|
||||
{
|
||||
ar & _deviceCount;
|
||||
ar & _uuidEncryption;
|
||||
ar & _RemainingTime;
|
||||
}
|
||||
|
||||
public:
|
||||
int _deviceCount;
|
||||
map<int,string> _uuidEncryption;
|
||||
int64_t _RemainingTime;
|
||||
};
|
||||
|
||||
|
||||
class STLlicensedata
|
||||
{
|
||||
private:
|
||||
friend class boost::serialization::access;
|
||||
template <typename Archive>
|
||||
void serialize(Archive& ar, const unsigned int version)
|
||||
{
|
||||
ar & m_licensedata;
|
||||
}
|
||||
|
||||
public:
|
||||
Licensedata1* m_licensedata;
|
||||
};
|
||||
|
||||
|
||||
ServerError
|
||||
LiSave(const string& path,const int& deviceCount,const map<int,string>& uuidEncryption)
|
||||
{
|
||||
std::ofstream file(path);
|
||||
boost::archive::binary_oarchive oa(file);
|
||||
oa.register_type<Licensedata1>();
|
||||
STLlicensedata stllicensedata;
|
||||
|
||||
Licensedata1 *p = new Licensedata1(deviceCount,uuidEncryption);
|
||||
stllicensedata.m_licensedata = p;
|
||||
oa << stllicensedata;
|
||||
|
||||
delete p;
|
||||
file.close();
|
||||
return SERVER_SUCCESS;
|
||||
}
|
||||
|
||||
ServerError
|
||||
LiSave(const string& path,const int& deviceCount,const map<int,string>& uuidEncryption, const int64_t& RemainingTime)
|
||||
{
|
||||
std::ofstream file(path);
|
||||
boost::archive::binary_oarchive oa(file);
|
||||
oa.register_type<Licensedata1>();
|
||||
STLlicensedata stllicensedata;
|
||||
|
||||
Licensedata1 *p = new Licensedata1(deviceCount,uuidEncryption,RemainingTime);
|
||||
stllicensedata.m_licensedata = p;
|
||||
oa << stllicensedata;
|
||||
|
||||
delete p;
|
||||
file.close();
|
||||
return SERVER_SUCCESS;
|
||||
}
|
||||
|
||||
ServerError
|
||||
LiLoad(const string& path,int& deviceCount,map<int,string>& uuidEncryption,int64_t& RemainingTime)
|
||||
{
|
||||
std::ifstream file(path);
|
||||
boost::archive::binary_iarchive ia(file);
|
||||
ia.register_type<Licensedata1>();
|
||||
STLlicensedata stllicensedata;
|
||||
ia >> stllicensedata;
|
||||
deviceCount = stllicensedata.m_licensedata->GetdeviceCount();
|
||||
uuidEncryption = stllicensedata.m_licensedata->GetuuidEncryption();
|
||||
RemainingTime = stllicensedata.m_licensedata->GetRemainingTime();
|
||||
file.close();
|
||||
return SERVER_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
// GET /tmp/vecwise_engine2.license
|
||||
|
||||
class Licensefiledata
|
||||
{
|
||||
public:
|
||||
Licensefiledata()
|
||||
:_update_time(0)
|
||||
,_file_size(0)
|
||||
,_filemd5("")
|
||||
{}
|
||||
|
||||
Licensefiledata(const time_t& update_time,const off_t& file_size,const string& filemd5)
|
||||
:_update_time(update_time)
|
||||
,_file_size(file_size)
|
||||
,_filemd5(filemd5)
|
||||
{}
|
||||
|
||||
time_t Getupdate_time()
|
||||
{
|
||||
return _update_time;
|
||||
}
|
||||
off_t Getfile_size()
|
||||
{
|
||||
return _file_size;
|
||||
}
|
||||
string Getfilemd5()
|
||||
{
|
||||
return _filemd5;
|
||||
}
|
||||
|
||||
private:
|
||||
friend class boost::serialization::access;
|
||||
template <typename Archive>
|
||||
void serialize(Archive &ar, const unsigned int version)
|
||||
{
|
||||
ar & _update_time;
|
||||
ar & _file_size;
|
||||
ar & _filemd5;
|
||||
}
|
||||
|
||||
public:
|
||||
time_t _update_time;
|
||||
off_t _file_size;
|
||||
string _filemd5;
|
||||
};
|
||||
|
||||
|
||||
class STLlicensefiledata
|
||||
{
|
||||
private:
|
||||
friend class boost::serialization::access;
|
||||
template <typename Archive>
|
||||
void serialize(Archive& ar, const unsigned int version)
|
||||
{
|
||||
ar & m_licensefiledata;
|
||||
}
|
||||
|
||||
public:
|
||||
Licensefiledata* m_licensefiledata;
|
||||
};
|
||||
|
||||
|
||||
ServerError
|
||||
LifileSave(const string& path,const time_t& update_time,const off_t& file_size,const string& filemd5)
|
||||
{
|
||||
std::ofstream file(path);
|
||||
boost::archive::binary_oarchive oa(file);
|
||||
oa.register_type<Licensefiledata>();
|
||||
STLlicensefiledata stllicensefiledata;
|
||||
|
||||
Licensefiledata *p = new Licensefiledata(update_time,file_size,filemd5);
|
||||
stllicensefiledata.m_licensefiledata = p;
|
||||
oa << stllicensefiledata;
|
||||
|
||||
delete p;
|
||||
file.close();
|
||||
return SERVER_SUCCESS;
|
||||
}
|
||||
|
||||
ServerError
|
||||
LifileLoad(const string& path,time_t& update_time,off_t& file_size,string& filemd5)
|
||||
{
|
||||
std::ifstream file(path);
|
||||
boost::archive::binary_iarchive ia(file);
|
||||
ia.register_type<Licensefiledata>();
|
||||
STLlicensefiledata stllicensefiledata;
|
||||
ia >> stllicensefiledata;
|
||||
update_time = stllicensefiledata.m_licensefiledata->Getupdate_time();
|
||||
file_size = stllicensefiledata.m_licensefiledata->Getfile_size();
|
||||
filemd5 = stllicensefiledata.m_licensefiledata->Getfilemd5();
|
||||
file.close();
|
||||
return SERVER_SUCCESS;
|
||||
}
|
||||
|
||||
ServerError
|
||||
LicenseLegality_check(const std::string& path)
|
||||
{
|
||||
int deviceCount;
|
||||
std::vector<std::string> uuids;
|
||||
LicenseGetuuid(deviceCount,uuids);
|
||||
|
||||
std::vector<std::string> shas;
|
||||
LicenseGetuuidsha(deviceCount,uuids,shas);
|
||||
|
||||
|
||||
int deviceCountcheck;
|
||||
std::map<int,std::string> uuidEncryption;
|
||||
int64_t RemainingTime;
|
||||
LiLoad(path,deviceCountcheck,uuidEncryption,RemainingTime);
|
||||
|
||||
if(deviceCount!=deviceCountcheck)
|
||||
{
|
||||
printf("deviceCount is wrong\n");
|
||||
return SERVER_UNEXPECTED_ERROR;
|
||||
}
|
||||
for(int i=0;i<deviceCount;i++)
|
||||
{
|
||||
if(uuidEncryption[i]!=shas[i])
|
||||
{
|
||||
printf("uuidsha %d is wrong\n",i);
|
||||
return SERVER_UNEXPECTED_ERROR;
|
||||
}
|
||||
}
|
||||
if(RemainingTime <=0 )
|
||||
{
|
||||
printf("License expired\n");
|
||||
return SERVER_UNEXPECTED_ERROR;
|
||||
}
|
||||
return SERVER_SUCCESS;
|
||||
}
|
||||
|
||||
ServerError
|
||||
LicenseIntegrity_check(const std::string& path,const std::string& path2)
|
||||
{
|
||||
std::string filemd5;
|
||||
LicenseGetfilemd5(path,filemd5);
|
||||
time_t update_time;
|
||||
LicenseGetfiletime(path,update_time);
|
||||
off_t file_size;
|
||||
LicenseGetfilesize(path,file_size);
|
||||
|
||||
time_t update_timecheck;
|
||||
std::string filemd5check;
|
||||
off_t file_sizecheck;
|
||||
LifileLoad(path2,update_timecheck,file_sizecheck,filemd5check);
|
||||
|
||||
if(filemd5!=filemd5check)
|
||||
{
|
||||
printf("This file has been modified\n");
|
||||
return SERVER_UNEXPECTED_ERROR;
|
||||
}
|
||||
if(update_time!=update_timecheck)
|
||||
{
|
||||
printf("update_time is wrong\n");
|
||||
return SERVER_UNEXPECTED_ERROR;
|
||||
}
|
||||
if(file_size!=file_sizecheck)
|
||||
{
|
||||
printf("file_size is wrong\n");
|
||||
return SERVER_UNEXPECTED_ERROR;
|
||||
}
|
||||
|
||||
return SERVER_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Alterfile(const string &path1, const string &path2 ,const boost::system::error_code &ec, boost::asio::deadline_timer* pt)
|
||||
{
|
||||
int deviceCount;
|
||||
map<int,string> uuidEncryption;
|
||||
int64_t RemainingTime;
|
||||
LiLoad(path1,deviceCount,uuidEncryption,RemainingTime);
|
||||
|
||||
std::cout<< "RemainingTime: " << RemainingTime <<std::endl;
|
||||
|
||||
if(RemainingTime<=0)
|
||||
{
|
||||
std::cout<< "License expired" <<std::endl;
|
||||
exit(1);
|
||||
}
|
||||
RemainingTime--;
|
||||
LiSave(path1,deviceCount,uuidEncryption,RemainingTime);
|
||||
|
||||
int deviceCountcheck;
|
||||
map<int,string> uuidEncryptioncheck;
|
||||
int64_t RemainingTimecheck;
|
||||
LiLoad(path1,deviceCountcheck,uuidEncryptioncheck,RemainingTimecheck);
|
||||
|
||||
std::cout<< "RemainingTimecheck: " << RemainingTimecheck <<std::endl;
|
||||
|
||||
time_t update_time;
|
||||
LicenseGetfiletime(path1,update_time);
|
||||
off_t file_size;
|
||||
LicenseGetfilesize(path1,file_size);
|
||||
string filemd5;
|
||||
LicenseGetfilemd5(path1,filemd5);
|
||||
|
||||
std::cout<< "filemd5: " << filemd5 <<std::endl;
|
||||
|
||||
LifileSave(path2,update_time,file_size,filemd5);
|
||||
time_t update_timecheck;
|
||||
off_t file_sizecheck;
|
||||
string filemd5check;
|
||||
LifileLoad(path2,update_timecheck,file_sizecheck,filemd5check);
|
||||
|
||||
std::cout<< "update_timecheck: " << update_timecheck <<std::endl;
|
||||
std::cout<< "file_sizecheck: " << file_sizecheck <<std::endl;
|
||||
std::cout<< "filemd5check: " << filemd5check <<std::endl;
|
||||
|
||||
pt->expires_at(pt->expires_at() + boost::posix_time::hours(1)) ;
|
||||
pt->async_wait(boost::bind(Alterfile,path1,path2, boost::asio::placeholders::error, pt));
|
||||
|
||||
}
|
||||
void Runtime(const string &path1, const string &path2 )
|
||||
{
|
||||
boost::asio::io_service io;
|
||||
boost::asio::deadline_timer t(io, boost::posix_time::hours(1));
|
||||
t.async_wait(boost::bind(Alterfile,path1,path2, boost::asio::placeholders::error, &t));
|
||||
io.run();
|
||||
return;;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -1,88 +0,0 @@
|
||||
//
|
||||
// Created by zilliz on 19-5-10.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "utils/Error.h"
|
||||
#include <cuda.h>
|
||||
#include <memory>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <string.h>
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
#include <sys/stat.h>
|
||||
#include <map>
|
||||
#include <list>
|
||||
#include <boost/archive/binary_oarchive.hpp>
|
||||
#include <boost/archive/binary_iarchive.hpp>
|
||||
#include <boost/foreach.hpp>
|
||||
#include <boost/serialization/vector.hpp>
|
||||
#include <boost/serialization/map.hpp>
|
||||
|
||||
#include <boost/asio.hpp>
|
||||
#include <boost/thread.hpp>
|
||||
#include <boost/date_time/posix_time/posix_time.hpp>
|
||||
|
||||
#include <cuda_runtime.h>
|
||||
#include <nvml.h>
|
||||
#include <openssl/md5.h>
|
||||
#include <openssl/sha.h>
|
||||
|
||||
|
||||
namespace zilliz {
|
||||
namespace vecwise {
|
||||
namespace server {
|
||||
|
||||
class
|
||||
BoostArchive;
|
||||
|
||||
class
|
||||
Licensedata1;
|
||||
|
||||
|
||||
class
|
||||
Licensefiledata;
|
||||
|
||||
class
|
||||
STLlicensefiledata;
|
||||
|
||||
|
||||
ServerError
|
||||
LiSave(const std::string &path, const int &deviceCount, const std::map<int, std::string> &uuidEncryption);
|
||||
|
||||
ServerError
|
||||
LiLoad(const std::string &path, int &deviceCount, std::map<int, std::string> &uuidEncryption, int64_t &RemainingTime);
|
||||
|
||||
ServerError
|
||||
LifileSave(const std::string &path, const time_t &update_time, const off_t &file_size, const std::string &filemd5);
|
||||
|
||||
ServerError
|
||||
LifileLoad(const std::string &path, time_t &update_time, off_t &file_size, std::string &filemd5);
|
||||
|
||||
ServerError
|
||||
LiSave(const std::string &path,
|
||||
const int &deviceCount,
|
||||
const std::map<int, std::string> &uuidEncryption,
|
||||
const int64_t &RemainingTime);
|
||||
|
||||
ServerError
|
||||
LicenseIntegrity_check(const std::string &path, const std::string &path2);
|
||||
|
||||
ServerError
|
||||
LicenseLegality_check(const std::string &path);
|
||||
|
||||
void
|
||||
Alterfile(const std::string &path1,
|
||||
const std::string &path2,
|
||||
const boost::system::error_code &ec,
|
||||
boost::asio::deadline_timer *pt);
|
||||
|
||||
void
|
||||
Runtime(const std::string &path1, const std::string &path2);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
//
|
||||
// Created by zilliz on 19-5-11.
|
||||
//
|
||||
#include <gtest/gtest.h>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
|
||||
#include "utils/Error.h"
|
||||
#include "license/LicenseCheck.h"
|
||||
#include "license/LicensePublic.h"
|
||||
|
||||
|
||||
using namespace zilliz::vecwise;
|
||||
|
||||
//TEST(LicenseTest, LICENSE_TEST) {
|
||||
//
|
||||
// std::string path1 = "/tmp/vecwise_engine.license";
|
||||
// std::string path2 = "/tmp/vecwise_engine2.license";
|
||||
// std::cout << "This is run " << std::endl;
|
||||
//
|
||||
// server::ServerError err;
|
||||
//
|
||||
// err = server::Licensefileread(path1);
|
||||
// if(err!=server::SERVER_SUCCESS)
|
||||
// {
|
||||
// exit(1);
|
||||
// }
|
||||
// err = server::LicenseIntegrity_check(path1,path2);
|
||||
// if(err!=server::SERVER_SUCCESS)
|
||||
// {
|
||||
// std::cout << "Integrity_check is wrong " << std::endl;
|
||||
// exit(1);
|
||||
// }
|
||||
// err = server::LicenseLegality_check(path1);
|
||||
// if(err!=server::SERVER_SUCCESS)
|
||||
// {
|
||||
// std::cout << "Legality_check is wrong " << std::endl;
|
||||
// exit(1);
|
||||
// }
|
||||
// std::cout << " runing " << std::endl;
|
||||
// server::Runtime(path1,path2);
|
||||
//}
|
@ -1,72 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
|
||||
* Unauthorized copying of this file, via any medium is strictly prohibited.
|
||||
* Proprietary and confidential.
|
||||
******************************************************************************/
|
||||
#pragma once
|
||||
#include <string>
|
||||
|
||||
class SecretFile {
|
||||
public:
|
||||
SecretFile() = default;
|
||||
|
||||
SecretFile(const time_t &update_time, const off_t &file_size, const std::string &file_md5)
|
||||
: update_time_(update_time), file_size_(file_size), file_md5_(file_md5) {}
|
||||
|
||||
time_t get_update_time() {
|
||||
return update_time_;
|
||||
}
|
||||
off_t get_file_size() {
|
||||
return file_size_;
|
||||
}
|
||||
std::string get_file_md5() {
|
||||
return file_md5_;
|
||||
}
|
||||
|
||||
private:
|
||||
friend class boost::serialization::access;
|
||||
|
||||
template<typename Archive>
|
||||
void serialize(Archive &ar, const unsigned int version) {
|
||||
ar & update_time_;
|
||||
ar & file_size_;
|
||||
ar & file_md5_;
|
||||
}
|
||||
|
||||
public:
|
||||
time_t update_time_ = 0;
|
||||
off_t file_size_ = 0;
|
||||
std::string file_md5_;
|
||||
};
|
||||
|
||||
class SerializedSecretFile {
|
||||
public:
|
||||
~SerializedSecretFile() {
|
||||
if(secret_file_ != nullptr) {
|
||||
delete secret_file_;
|
||||
secret_file_ = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
set_secret_file(SecretFile* secret_file) {
|
||||
secret_file_ = secret_file;
|
||||
}
|
||||
|
||||
SecretFile* get_secret_file() {
|
||||
return secret_file_;
|
||||
}
|
||||
|
||||
private:
|
||||
friend class boost::serialization::access;
|
||||
|
||||
template<typename Archive>
|
||||
void serialize(Archive &ar, const unsigned int version) {
|
||||
ar & secret_file_;
|
||||
}
|
||||
|
||||
private:
|
||||
SecretFile *secret_file_ = nullptr;
|
||||
};
|
||||
|
||||
|
@ -133,12 +133,6 @@ Server::Daemonize() {
|
||||
|
||||
int
|
||||
Server::Start() {
|
||||
std::string license_file_path = "/tmp/vecwise.license";
|
||||
if(LicenseValidate(license_file_path) != SERVER_SUCCESS) {
|
||||
SERVER_LOG_ERROR << "License check failed";
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (daemonized_) {
|
||||
Daemonize();
|
||||
}
|
||||
@ -157,6 +151,21 @@ Server::Start() {
|
||||
//print config into console and log
|
||||
config.PrintAll();
|
||||
|
||||
#ifdef ENABLE_LICENSE
|
||||
ConfigNode license_config = config.GetConfig(CONFIG_LICENSE);
|
||||
std::string license_file_path = license_config.GetValue(CONFIG_LICENSE_PATH);
|
||||
SERVER_LOG_INFO << "License path: " << license_file_path;
|
||||
if(server::LicenseCheck::LegalityCheck(license_file_path) != SERVER_SUCCESS) {
|
||||
SERVER_LOG_ERROR << "License check failed";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if(server::LicenseCheck::StartCountingDown(license_file_path) != SERVER_SUCCESS) {
|
||||
SERVER_LOG_ERROR << "License counter start error";
|
||||
exit(1);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Handle Signal
|
||||
signal(SIGINT, SignalUtil::HandleSignal);
|
||||
signal(SIGHUP, SignalUtil::HandleSignal);
|
||||
|
@ -32,6 +32,9 @@ static const std::string CONFIG_CACHE = "cache_config";
|
||||
static const std::string CONFIG_CPU_CACHE_CAPACITY = "cpu_cache_capacity";
|
||||
static const std::string CONFIG_GPU_CACHE_CAPACITY = "gpu_cache_capacity";
|
||||
|
||||
static const std::string CONFIG_LICENSE = "license_config";
|
||||
static const std::string CONFIG_LICENSE_PATH = "license_path";
|
||||
|
||||
class ServerConfig {
|
||||
public:
|
||||
static ServerConfig &GetInstance();
|
||||
|
@ -19,15 +19,18 @@ link_directories(/usr/local/cuda/targets/x86_64-linux/lib/stubs/)
|
||||
|
||||
set(require_files
|
||||
../../src/license/LicenseLibrary.cpp
|
||||
../../src/license/LicenseCheck.cpp
|
||||
# ../../src/license/License.cpp
|
||||
# ../../src/license/LicensePublic.cpp
|
||||
# ../../src/license/LicenseCreateuuidshafile.cpp
|
||||
)
|
||||
|
||||
|
||||
set(db_test_src
|
||||
|
||||
# license_tests.cpp
|
||||
license_library_tests.cpp
|
||||
license_check_test.cpp
|
||||
|
||||
|
||||
${require_files})
|
||||
|
||||
cuda_add_executable(license_test ${db_test_src})
|
||||
|
68
cpp/unittest/license/license_check_test.cpp
Normal file
68
cpp/unittest/license/license_check_test.cpp
Normal file
@ -0,0 +1,68 @@
|
||||
//
|
||||
// Created by zilliz on 19-5-13.
|
||||
//
|
||||
|
||||
#include "utils/Log.h"
|
||||
#include "license/LicenseCheck.h"
|
||||
#include "utils/Error.h"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
using namespace zilliz::vecwise;
|
||||
|
||||
TEST(LicenseLibraryTest, CHECK_TEST) {
|
||||
|
||||
server::ServerError err;
|
||||
|
||||
std::string license_file_path("/tmp/megasearch/abc.license");
|
||||
|
||||
|
||||
int device_count;
|
||||
std::map<int, std::string> uuid_encryption_map;
|
||||
//
|
||||
// err = server::LicenseLibrary::GPUinfoFileDeserialization(sys_info_file_path, device_count, uuid_encryption_map);
|
||||
// ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
// std::cout << " device_count: " << device_count << std::endl;
|
||||
// for (int i = 0; i < device_count; i++) {
|
||||
// std::cout << " uuid_encryption_map: " << i << " " << uuid_encryption_map[i] << std::endl;
|
||||
// }
|
||||
//
|
||||
time_t starting_time;
|
||||
time_t end_time;
|
||||
err = server::LicenseLibrary::LicenseFileDeserialization(license_file_path,
|
||||
device_count,
|
||||
uuid_encryption_map,
|
||||
starting_time,
|
||||
end_time);
|
||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
//
|
||||
// std::cout << "device_count: " << device_count << std::endl;
|
||||
// for (int i = 0; i < device_count; i++) {
|
||||
// std::cout << " uuid_encryption_map: " << i << " " << uuid_encryption_map[i] << std::endl;
|
||||
// }
|
||||
// std::cout << "starting_time: " << starting_time << std::endl;
|
||||
// std::cout << "end_time: " << end_time << std::endl;
|
||||
|
||||
|
||||
time_t system_time;
|
||||
err = server::LicenseLibrary::GetSystemTime(system_time);
|
||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
|
||||
system_time+=111100;
|
||||
err = server::LicenseLibrary::LicenseFileSerialization(license_file_path,
|
||||
device_count,
|
||||
uuid_encryption_map,
|
||||
system_time,
|
||||
end_time);
|
||||
// ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
// 19. Legality check
|
||||
err = server::LicenseCheck::LegalityCheck(license_file_path);
|
||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
|
||||
// 20. Start counting down
|
||||
|
||||
// err = server::LicenseCheck::StartCountingDown(license_file_path);
|
||||
// ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
}
|
@ -12,6 +12,7 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
using namespace zilliz::vecwise;
|
||||
|
||||
TEST(LicenseLibraryTest, FILE_EXISTENT_TEST) {
|
||||
@ -55,6 +56,12 @@ TEST(LicenseLibraryTest, GPU_INFO_TEST) {
|
||||
std::cout << "Device Id: " << i << ", UUID: " << uuid_array[i] << ", UUID_SHA256: "
|
||||
<< uuid_sha256_array[i] << std::endl;
|
||||
}
|
||||
|
||||
time_t systemtime;
|
||||
err = server::LicenseLibrary::GetSystemTime(systemtime);
|
||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
std::cout << "System Time: " << systemtime << std::endl;
|
||||
|
||||
}
|
||||
|
||||
TEST(LicenseLibraryTest, LICENSE_FILE_TEST) {
|
||||
@ -112,27 +119,40 @@ TEST(LicenseLibraryTest, LICENSE_FILE_TEST) {
|
||||
ASSERT_EQ(uuid_encrption_map[i], output_info_uuid_encrption_map[i]);
|
||||
}
|
||||
|
||||
|
||||
// 16. Get System Time/starting_time ans End Time
|
||||
time_t starting_time;
|
||||
err = server::LicenseLibrary::GetSystemTime(starting_time);
|
||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
time_t end_time;
|
||||
end_time = starting_time + (long) (60 * 60 * 24 * 7);
|
||||
|
||||
// 11. Generate License File
|
||||
err = server::LicenseLibrary::LicenseFileSerialization(license_file_path,
|
||||
device_count,
|
||||
uuid_encrption_map,
|
||||
remaining_hour);
|
||||
starting_time,
|
||||
end_time);
|
||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
|
||||
// 12. Define output var
|
||||
int output_device_count = 0;
|
||||
std::map<int, std::string> output_uuid_encrption_map;
|
||||
int64_t output_remaining_hour;
|
||||
time_t output_starting_time;
|
||||
time_t output_end_time;
|
||||
|
||||
// 13. Read License File
|
||||
err = server::LicenseLibrary::LicenseFileDeserialization(license_file_path,
|
||||
output_device_count,
|
||||
output_uuid_encrption_map,
|
||||
output_remaining_hour);
|
||||
output_starting_time,
|
||||
output_end_time);
|
||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
|
||||
ASSERT_EQ(device_count, output_device_count);
|
||||
ASSERT_EQ(remaining_hour, output_remaining_hour);
|
||||
ASSERT_EQ(starting_time, output_starting_time);
|
||||
ASSERT_EQ(end_time, output_end_time);
|
||||
|
||||
for (int i = 0; i < device_count; ++i) {
|
||||
ASSERT_EQ(uuid_encrption_map[i], output_uuid_encrption_map[i]);
|
||||
}
|
||||
@ -148,53 +168,49 @@ TEST(LicenseLibraryTest, LICENSE_FILE_TEST) {
|
||||
err = server::LicenseLibrary::GetFileMD5(license_file_path, file_md5);
|
||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
|
||||
|
||||
|
||||
// 16. Generate Secret File
|
||||
std::string secret_file_path("/tmp/megasearch.secret");
|
||||
err = server::LicenseLibrary::SecretFileSerialization(secret_file_path, update_time, file_size, file_md5);
|
||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
// std::string secret_file_path("/tmp/megasearch.secret");
|
||||
// err = server::LicenseLibrary::SecretFileSerialization(secret_file_path,
|
||||
// update_time,
|
||||
// file_size,
|
||||
// starting_time,
|
||||
// end_time,
|
||||
// file_md5);
|
||||
// ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
|
||||
// 17. Define output var
|
||||
time_t output_update_time;
|
||||
off_t output_file_size;
|
||||
std::string output_file_md5;
|
||||
// time_t output_update_time;
|
||||
// off_t output_file_size;
|
||||
// time_t output_starting_time;
|
||||
// time_t output_end_time;
|
||||
// std::string output_file_md5;
|
||||
|
||||
// 18. Read License File
|
||||
err = server::LicenseLibrary::SecretFileDeserialization(secret_file_path,
|
||||
output_update_time,
|
||||
output_file_size,
|
||||
output_file_md5);
|
||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
|
||||
ASSERT_EQ(update_time, output_update_time);
|
||||
ASSERT_EQ(file_size, output_file_size);
|
||||
ASSERT_EQ(file_md5, output_file_md5);
|
||||
// err = server::LicenseLibrary::SecretFileDeserialization(secret_file_path,
|
||||
// output_update_time,
|
||||
// output_file_size,
|
||||
// output_starting_time,
|
||||
// output_end_time,
|
||||
// output_file_md5);
|
||||
// ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
//
|
||||
// ASSERT_EQ(update_time, output_update_time);
|
||||
// ASSERT_EQ(file_size, output_file_size);
|
||||
// ASSERT_EQ(starting_time, output_starting_time);
|
||||
// ASSERT_EQ(end_time, output_end_time);
|
||||
// ASSERT_EQ(file_md5, output_file_md5);
|
||||
|
||||
// 19. Integrity check and Legality check
|
||||
err = server::LicenseLibrary::IntegrityCheck(license_file_path, secret_file_path);
|
||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
|
||||
err = server::LicenseLibrary::LegalityCheck(license_file_path);
|
||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
// err = server::LicenseLibrary::IntegrityCheck(license_file_path, secret_file_path);
|
||||
// ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
//
|
||||
// err = server::LicenseLibrary::LegalityCheck(license_file_path);
|
||||
// ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
|
||||
}
|
||||
|
||||
TEST(LicenseLibraryTest, Timer_TEST) {
|
||||
|
||||
server::ServerError err;
|
||||
std::string license_file_path("/tmp/megasearch.license");
|
||||
std::string secret_file_path("/tmp/megasearch.secret");
|
||||
|
||||
// 19. Integrity check and Legality check
|
||||
err = server::LicenseLibrary::IntegrityCheck(license_file_path, secret_file_path);
|
||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
|
||||
err = server::LicenseLibrary::LegalityCheck(license_file_path);
|
||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
|
||||
// 20. Start counting down
|
||||
err = server::LicenseLibrary::StartCountingDown(license_file_path, secret_file_path);
|
||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
}
|
||||
|
||||
TEST(LicenseLibraryTest, GET_GPU_INFO_FILE) {
|
||||
|
||||
@ -250,39 +266,64 @@ TEST(LicenseLibraryTest, GET_LICENSE_FILE) {
|
||||
output_info_uuid_encrption_map);
|
||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
|
||||
// 5. Enter time
|
||||
int64_t remaining_hour = 24*7 ;
|
||||
std::cout << "Please enter the authorization time (hours)" << std::endl;
|
||||
// std::cin >> remaining_hour;
|
||||
time_t system_time;
|
||||
err = server::LicenseLibrary::GetSystemTime(system_time);
|
||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
time_t starting_time = system_time;
|
||||
time_t end_time = system_time + (long) (60 * 60 * 24 * 7);
|
||||
|
||||
err = server::LicenseLibrary::LicenseFileSerialization(license_file_path,
|
||||
output_info_device_count,
|
||||
output_info_uuid_encrption_map,
|
||||
remaining_hour);
|
||||
starting_time,
|
||||
end_time);
|
||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
std::cout << "Generate License File Success" << std::endl;
|
||||
|
||||
}
|
||||
|
||||
TEST(LicenseLibraryTest, GET_SECRET_FILE) {
|
||||
|
||||
TEST(LicenseLibraryTest, GET_DATA_TIME) {
|
||||
server::ServerError err;
|
||||
std::string license_file_path("/tmp/megasearch.license");
|
||||
std::string secret_file_path("/tmp/megasearch.secret");
|
||||
|
||||
// 14. Get License File Attribute
|
||||
time_t update_time;
|
||||
off_t file_size;
|
||||
err = server::LicenseLibrary::GetFileUpdateTimeAndSize(license_file_path, update_time, file_size);
|
||||
char * a ="2018-03-06";
|
||||
time_t pp;
|
||||
err = server::LicenseLibrary::GetDateTime(a,pp);
|
||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
std::cout << pp <<std::endl;
|
||||
|
||||
// 15. Get License File MD5
|
||||
std::string file_md5;
|
||||
err = server::LicenseLibrary::GetFileMD5(license_file_path, file_md5);
|
||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
|
||||
// 16. Generate Secret File
|
||||
err = server::LicenseLibrary::SecretFileSerialization(secret_file_path, update_time, file_size, file_md5);
|
||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
|
||||
std::cout << "Generate Secret File Success" << std::endl;
|
||||
}
|
||||
|
||||
//TEST(LicenseLibraryTest, GET_SECRET_FILE) {
|
||||
//
|
||||
// server::ServerError err;
|
||||
// std::string license_file_path("/tmp/megasearch.license");
|
||||
// std::string secret_file_path("/tmp/megasearch.secret");
|
||||
//
|
||||
// // 14. Get License File Attribute
|
||||
// time_t update_time;
|
||||
// off_t file_size;
|
||||
// err = server::LicenseLibrary::GetFileUpdateTimeAndSize(license_file_path, update_time, file_size);
|
||||
// ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
//
|
||||
// // 15. Get License File MD5
|
||||
// std::string file_md5;
|
||||
// err = server::LicenseLibrary::GetFileMD5(license_file_path, file_md5);
|
||||
// ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
//
|
||||
// // 16. Get System Time/starting_time ans End Time
|
||||
// time_t starting_time;
|
||||
// err = server::LicenseLibrary::GetSystemTime(starting_time);
|
||||
// ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
// time_t end_time;
|
||||
// end_time = starting_time + (long) (60 * 60 * 24 * 7);
|
||||
//
|
||||
// // 16. Generate Secret File
|
||||
// err = server::LicenseLibrary::SecretFileSerialization(secret_file_path,
|
||||
// update_time,
|
||||
// file_size,
|
||||
// starting_time,
|
||||
// end_time,
|
||||
// file_md5);
|
||||
// ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
//
|
||||
// std::cout << "Generate Secret File Success" << std::endl;
|
||||
//}
|
||||
|
Loading…
Reference in New Issue
Block a user