<add>更新
This commit is contained in:
parent
f0fa01786a
commit
36c3eaf3aa
|
@ -1,18 +1,32 @@
|
||||||
cmake_minimum_required(VERSION 3.16)
|
cmake_minimum_required(VERSION 3.16)
|
||||||
|
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/lib)
|
||||||
project(certificate)
|
project(certificate)
|
||||||
|
|
||||||
FILE(GLOB SRC src/*.cpp)
|
FILE(GLOB_RECURSE SRC
|
||||||
FILE(GLOB HEAD include/*.h)
|
CONFIGURE_DEPENDS
|
||||||
FILE(GLOB API include/api/*.h)
|
LIST_DIRECTORIES false
|
||||||
|
src/*.cpp
|
||||||
|
)
|
||||||
|
FILE(GLOB HEAD include/*.h)
|
||||||
|
FILE(GLOB API include/api/*.h)
|
||||||
|
FILE(GLOB OS include/os/*.h)
|
||||||
|
FILE(GLOB VIEW include/view/*.h)
|
||||||
|
|
||||||
add_executable(${PROJECT_NAME} ${SRC} ${HEAD} ${API} README.md)
|
add_library(${PROJECT_NAME} STATIC ${SRC} ${HEAD} ${API} ${OS} ${VIEW} README.md)
|
||||||
|
|
||||||
target_include_directories(${PROJECT_NAME} PUBLIC include)
|
target_include_directories(${PROJECT_NAME} PUBLIC include include/api)
|
||||||
|
|
||||||
if (MSVC)
|
if (MSVC)
|
||||||
target_compile_options(${PROJECT_NAME} PRIVATE /WX /utf-8)
|
target_compile_options(${PROJECT_NAME} PRIVATE /WX /utf-8)
|
||||||
|
target_compile_definitions(${PROJECT_NAME} PRIVATE CERTIFICATE_DLL)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
source_group("API" FILES ${API})
|
source_group("API" FILES ${API})
|
||||||
|
source_group("OS" FILES ${OS})
|
||||||
|
source_group("VIEW" FILES ${VIEW})
|
||||||
source_group("DOC" FILES README.md)
|
source_group("DOC" FILES README.md)
|
||||||
|
|
||||||
|
option(BUILD_TEST ON "test")
|
||||||
|
if (BUILD_TEST)
|
||||||
|
add_subdirectory(test)
|
||||||
|
endif()
|
|
@ -5,17 +5,22 @@
|
||||||
namespace util {
|
namespace util {
|
||||||
|
|
||||||
class Ceroptions;
|
class Ceroptions;
|
||||||
|
class IView;
|
||||||
|
|
||||||
class ICertificate {
|
class ICertificate {
|
||||||
public:
|
public:
|
||||||
|
virtual ~ICertificate() = default;
|
||||||
|
|
||||||
// 获取与硬件相关的标识
|
// 获取与硬件相关的标识
|
||||||
virtual void GetMachineCode(char* code, uint16_t len) = 0;
|
virtual void GetMachineCode(char* code, uint16_t len) = 0;
|
||||||
|
|
||||||
// 生成证书
|
// 生成证书
|
||||||
virtual void CreateCertificate(Ceroptions* op) = 0;
|
virtual void CreateCertificate(Ceroptions* op) = 0;
|
||||||
|
|
||||||
// 验证证书
|
// 验证证书
|
||||||
virtual bool Verification(const char* lic) = 0;
|
virtual bool Verification(const char* lic) = 0;
|
||||||
|
|
||||||
|
// 配置视图程序
|
||||||
|
virtual void PushView(const IView* ) = 0;
|
||||||
};
|
};
|
||||||
}
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
#pragma once
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
namespace util {
|
||||||
|
|
||||||
|
/*
|
||||||
|
@berf 证书操作的可视化接口
|
||||||
|
可视化操作包括证书的输入, 标识的可视化输出
|
||||||
|
视图是可选配的
|
||||||
|
*/
|
||||||
|
class IView {
|
||||||
|
public:
|
||||||
|
virtual ~IView() = default;
|
||||||
|
// 启动视图
|
||||||
|
virtual void Exec() const = 0;
|
||||||
|
|
||||||
|
// 查看证书
|
||||||
|
virtual void About() const = 0;
|
||||||
|
|
||||||
|
// 从视图获取证书
|
||||||
|
virtual void GetLicense(char* lic, uint16_t len) const = 0;
|
||||||
|
|
||||||
|
// 输出硬件标识
|
||||||
|
virtual void GetMachineCode(char* code, uint16_t len) const = 0;
|
||||||
|
};
|
||||||
|
}
|
|
@ -1 +1,10 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#define MAC_LEN 0x10
|
||||||
|
|
||||||
|
struct __mac_addr
|
||||||
|
{
|
||||||
|
char _mac[MAC_LEN];
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef __mac_addr MacAddr_t;
|
|
@ -0,0 +1,9 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifdef CERTIFICATE_DLL
|
||||||
|
# ifdef _WIN32
|
||||||
|
# define CEREXPORT __declspec(dllexport)
|
||||||
|
# endif
|
||||||
|
#else
|
||||||
|
# define CEREXPORT
|
||||||
|
#endif
|
|
@ -0,0 +1,15 @@
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include "cerdef.h"
|
||||||
|
#include "cert_export.h"
|
||||||
|
/*
|
||||||
|
默认生成 MAC地址 + 主板序列号 + 磁盘ID的SHA-256哈希
|
||||||
|
用于硬件唯一标识
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace os {
|
||||||
|
|
||||||
|
// 获取mac地址
|
||||||
|
extern void CEREXPORT GetMacAddress(MacAddr_t* mac);
|
||||||
|
|
||||||
|
} // os
|
|
@ -0,0 +1,24 @@
|
||||||
|
#include "IView.h"
|
||||||
|
#include "view/httplib.h"
|
||||||
|
|
||||||
|
namespace hp = httplib;
|
||||||
|
|
||||||
|
class HttpView : util::IView
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
HttpView() { }
|
||||||
|
|
||||||
|
void Exec() const final;
|
||||||
|
|
||||||
|
// 查看证书
|
||||||
|
void About() const;
|
||||||
|
|
||||||
|
// 从视图获取证书
|
||||||
|
void GetLicense(char* lic, uint16_t len) const;
|
||||||
|
|
||||||
|
// 输出硬件标识
|
||||||
|
void GetMachineCode(char* code, uint16_t len) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
mutable hp::Server m_svr;
|
||||||
|
};
|
File diff suppressed because it is too large
Load Diff
|
@ -1,6 +1,6 @@
|
||||||
#include <iostream>
|
//#include <iostream>
|
||||||
|
//
|
||||||
int main()
|
//int main()
|
||||||
{
|
//{
|
||||||
return 0;
|
// return 0;
|
||||||
}
|
//}
|
|
@ -0,0 +1,52 @@
|
||||||
|
#include "os/machine.h"
|
||||||
|
#pragma comment(lib, "iphlpapi.lib")
|
||||||
|
#include <winsock2.h>
|
||||||
|
#include <iphlpapi.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <iomanip>
|
||||||
|
|
||||||
|
void os::GetMacAddress(MacAddr_t* mac)
|
||||||
|
{
|
||||||
|
PIP_ADAPTER_INFO pAdapterInfo = NULL;
|
||||||
|
PIP_ADAPTER_INFO pAdapter = NULL;
|
||||||
|
DWORD dwRetVal = 0;
|
||||||
|
ULONG ulOutBufLen = sizeof(IP_ADAPTER_INFO);
|
||||||
|
|
||||||
|
// 获取所需缓冲区大小
|
||||||
|
pAdapterInfo = (IP_ADAPTER_INFO*)malloc(ulOutBufLen);
|
||||||
|
if (pAdapterInfo == NULL) {
|
||||||
|
std::cerr << "Error allocating memory\n";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (GetAdaptersInfo(pAdapterInfo, &ulOutBufLen) == ERROR_BUFFER_OVERFLOW) {
|
||||||
|
free(pAdapterInfo);
|
||||||
|
pAdapterInfo = (IP_ADAPTER_INFO*)malloc(ulOutBufLen);
|
||||||
|
if (pAdapterInfo == NULL) {
|
||||||
|
std::cerr << "Error allocating memory\n";
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((dwRetVal = GetAdaptersInfo(pAdapterInfo, &ulOutBufLen)) != NO_ERROR) {
|
||||||
|
std::cerr << "GetAdaptersInfo failed: " << dwRetVal << "\n";
|
||||||
|
free(pAdapterInfo);
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
|
||||||
|
static constexpr char hex_map[] = "0123456789abcdef";
|
||||||
|
pAdapter = pAdapterInfo;
|
||||||
|
if (pAdapterInfo)
|
||||||
|
{
|
||||||
|
for (uint32_t i = 0; i < pAdapter->AddressLength; i++)
|
||||||
|
{
|
||||||
|
for (uint32_t j = 0; j < pAdapter->Address[i]; j++)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
free(pAdapterInfo);
|
||||||
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
#include "view/HttpView.h"
|
||||||
|
|
||||||
|
|
||||||
|
void HttpView::Exec() const
|
||||||
|
{
|
||||||
|
m_svr.Get("/hi", [](const hp::Request & req, hp::Response & res) {
|
||||||
|
res.set_content("Hello World!", "text/plain");
|
||||||
|
});
|
||||||
|
std::thread t([&]() {
|
||||||
|
m_svr.listen("0.0.0.0", 1234);
|
||||||
|
});
|
||||||
|
|
||||||
|
t.detach();
|
||||||
|
}
|
||||||
|
|
||||||
|
void HttpView::About() const
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void HttpView::GetLicense(char* lic, uint16_t len) const
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void HttpView::GetMachineCode(char* code, uint16_t len) const
|
||||||
|
{
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
|
||||||
|
project(testCer)
|
||||||
|
|
||||||
|
add_executable(${PROJECT_NAME} test.cpp)
|
||||||
|
|
||||||
|
target_include_directories(${PROJECT_NAME} PUBLIC ../include ../include/api)
|
||||||
|
|
||||||
|
if (MSVC)
|
||||||
|
target_compile_options(${PROJECT_NAME} PRIVATE /WX /utf-8)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
target_link_libraries(${PROJECT_NAME} PRIVATE certificate)
|
|
@ -0,0 +1,11 @@
|
||||||
|
#include "os/machine.h"
|
||||||
|
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
//MacAddr_t mac;
|
||||||
|
//os::GetMacAddress(&mac);
|
||||||
|
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue