mirror of
https://github.com/Neo-Desktop/WindowsXPKg
synced 2024-12-21 12:00:16 +02:00
remove bink generation script
add runtime json parsing add cmake.cpm update cmake to reflect this fix compilation errors ** breaks 2k3 key generation, work in progress
This commit is contained in:
parent
1f30ff762d
commit
96639bbaf7
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,5 +1,4 @@
|
||||
build/*
|
||||
bink.h
|
||||
|
||||
### NotepadPP template
|
||||
# Notepad++ backups #
|
||||
|
@ -10,22 +10,22 @@ if (!OPENSSL_FOUND)
|
||||
message(FATAL_ERROR "OpenSSL Development Libraries Not Found")
|
||||
endif()
|
||||
|
||||
# generate bink.h
|
||||
add_custom_command(
|
||||
OUTPUT bink.h
|
||||
COMMAND ${PROJECT_SOURCE_DIR}/convert_keys_to_cpp.py
|
||||
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
|
||||
DEPENDS bink.h
|
||||
)
|
||||
include(cmake/CPM.cmake)
|
||||
|
||||
# include json runtime library
|
||||
CPMAddPackage(
|
||||
NAME nlohmann_json
|
||||
GITHUB_REPOSITORY nlohmann/json
|
||||
VERSION 3.11.2)
|
||||
|
||||
configure_file(keys.json keys.json COPYONLY)
|
||||
|
||||
set(BUILD_SHARED_LIBS OFF)
|
||||
set(CMAKE_EXE_LINKER_FLAGS "-static")
|
||||
ADD_EXECUTABLE(xpkey main.cpp xp.cpp key.cpp util.cpp cli.cpp bink.h)
|
||||
ADD_EXECUTABLE(xpkey main.cpp xp.cpp key.cpp util.cpp cli.cpp)
|
||||
TARGET_INCLUDE_DIRECTORIES(xpkey PUBLIC crypto)
|
||||
TARGET_LINK_LIBRARIES(xpkey PUBLIC crypto)
|
||||
add_dependencies(xpkey bink.h)
|
||||
TARGET_LINK_LIBRARIES(xpkey PUBLIC crypto nlohmann_json::nlohmann_json)
|
||||
|
||||
ADD_EXECUTABLE(srv2003key server.cpp key.cpp util.cpp cli.cpp bink.h)
|
||||
ADD_EXECUTABLE(srv2003key server.cpp key.cpp util.cpp cli.cpp)
|
||||
TARGET_INCLUDE_DIRECTORIES(srv2003key PUBLIC crypto)
|
||||
TARGET_LINK_LIBRARIES(srv2003key PUBLIC crypto)
|
||||
add_dependencies(srv2003key bink.h)
|
||||
TARGET_LINK_LIBRARIES(srv2003key PUBLIC crypto nlohmann_json::nlohmann_json)
|
33
cmake/CPM.cmake
Normal file
33
cmake/CPM.cmake
Normal file
@ -0,0 +1,33 @@
|
||||
set(CPM_DOWNLOAD_VERSION 0.38.1)
|
||||
|
||||
if(CPM_SOURCE_CACHE)
|
||||
set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
|
||||
elseif(DEFINED ENV{CPM_SOURCE_CACHE})
|
||||
set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
|
||||
else()
|
||||
set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
|
||||
endif()
|
||||
|
||||
# Expand relative path. This is important if the provided path contains a tilde (~)
|
||||
get_filename_component(CPM_DOWNLOAD_LOCATION ${CPM_DOWNLOAD_LOCATION} ABSOLUTE)
|
||||
|
||||
function(download_cpm)
|
||||
message(STATUS "Downloading CPM.cmake to ${CPM_DOWNLOAD_LOCATION}")
|
||||
file(DOWNLOAD
|
||||
https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake
|
||||
${CPM_DOWNLOAD_LOCATION}
|
||||
)
|
||||
endfunction()
|
||||
|
||||
if(NOT (EXISTS ${CPM_DOWNLOAD_LOCATION}))
|
||||
download_cpm()
|
||||
else()
|
||||
# resume download if it previously failed
|
||||
file(READ ${CPM_DOWNLOAD_LOCATION} check)
|
||||
if("${check}" STREQUAL "")
|
||||
download_cpm()
|
||||
endif()
|
||||
unset(check)
|
||||
endif()
|
||||
|
||||
include(${CPM_DOWNLOAD_LOCATION})
|
@ -1,63 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
import json
|
||||
|
||||
with open('keys.json') as json_file:
|
||||
data = json.load(json_file)
|
||||
|
||||
with open('bink.h', 'w') as out:
|
||||
out.write('''
|
||||
/******************************************************************
|
||||
* This file was automatically generated by convert_keys_to_cpp.py *
|
||||
* DO NOT EDIT *
|
||||
******************************************************************/
|
||||
|
||||
#ifndef WINDOWSXPKG_BINK_H
|
||||
#define WINDOWSXPKG_BINK_H
|
||||
|
||||
struct ECDLP_Params {
|
||||
// p, a, b
|
||||
std::tuple<std::string, std::string, std::string> E;
|
||||
|
||||
// x, y
|
||||
std::tuple<std::string, std::string> K;
|
||||
|
||||
// x, y
|
||||
std::tuple<std::string, std::string> G;
|
||||
|
||||
std::string n;
|
||||
std::string k;
|
||||
};
|
||||
|
||||
std::unordered_map<std::string, std::unordered_map<int, std::string>> Products;
|
||||
std::unordered_map<std::string, ECDLP_Params> BINKData;
|
||||
|
||||
struct ProductID {
|
||||
uint8_t SiteID;
|
||||
uint16_t Serial;
|
||||
};
|
||||
|
||||
void initBink() {
|
||||
''')
|
||||
|
||||
for product in data['Products']:
|
||||
d = data['Products'][product]
|
||||
k = 0
|
||||
for v in d:
|
||||
out.write(' Products["' + product + '"][' + str(k) + '] = "' + v + '";' + "\n")
|
||||
k += 1
|
||||
|
||||
out.write("\n")
|
||||
|
||||
for bink in data['BINK']:
|
||||
d = data['BINK'][bink]
|
||||
out.write(' BINKData["' + bink + '"] = {' +
|
||||
'{"' + d['p'] + '", "' + d['a'] + '", "' + d['b'] + '"}, ' +
|
||||
'{"' + d['pub']['x'] + '", "' + d['pub']['y'] + '"}, ' +
|
||||
'{"' + d['g']['x'] + '", "' + d['g']['y'] + '"}, ' +
|
||||
'"' + d['n'] + '", "' + d['priv'] + '"};' + "\n")
|
||||
|
||||
out.write('''
|
||||
}
|
||||
|
||||
#endif //WINDOWSXPKG_BINK_H
|
||||
''')
|
7
header.h
7
header.h
@ -10,17 +10,18 @@
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <ctime>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#include <openssl/bn.h>
|
||||
#include <openssl/ec.h>
|
||||
#include <openssl/sha.h>
|
||||
#include <openssl/rand.h>
|
||||
|
||||
#include "bink.h"
|
||||
|
||||
#define PK_LENGTH 25
|
||||
#define NULL_TERMINATOR 1
|
||||
|
||||
@ -38,7 +39,7 @@ extern char charset[];
|
||||
void endian(byte *data, int length);
|
||||
|
||||
// key.cpp
|
||||
void unbase24(ul32 *byteSeq, char *cdKey);
|
||||
void unbase24(ul32 *byteSeq, const char *cdKey);
|
||||
void base24(char *cdKey, ul32 *byteSeq);
|
||||
|
||||
// cli.cpp
|
||||
|
23
main.cpp
23
main.cpp
@ -6,9 +6,12 @@
|
||||
|
||||
char charset[] = "BCDFGHJKMPQRTVWXY2346789";
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
int main()
|
||||
{
|
||||
initBink();
|
||||
std::ifstream f("keys.json");
|
||||
json keys = json::parse(f);
|
||||
|
||||
rand();
|
||||
srand(time(nullptr));
|
||||
@ -33,25 +36,25 @@ int main()
|
||||
|
||||
// Data from pidgen-Bink-resources
|
||||
/* Elliptic curve parameters: y^2 = x^3 + ax + b mod p */
|
||||
BN_dec2bn(&p, std::get<0>(BINKData[BINKID].E).c_str());
|
||||
BN_dec2bn(&a, std::get<1>(BINKData[BINKID].E).c_str());
|
||||
BN_dec2bn(&b, std::get<2>(BINKData[BINKID].E).c_str());
|
||||
BN_dec2bn(&p, keys["BINK"][BINKID]["p"].get<std::string>().c_str());
|
||||
BN_dec2bn(&a, keys["BINK"][BINKID]["a"].get<std::string>().c_str());
|
||||
BN_dec2bn(&b, keys["BINK"][BINKID]["b"].get<std::string>().c_str());
|
||||
|
||||
|
||||
/* base point (generator) G */
|
||||
BN_dec2bn(&gx, std::get<0>(BINKData[BINKID].G).c_str());
|
||||
BN_dec2bn(&gy, std::get<1>(BINKData[BINKID].G).c_str());
|
||||
BN_dec2bn(&gx, keys["BINK"][BINKID]["g"]["x"].get<std::string>().c_str());
|
||||
BN_dec2bn(&gy, keys["BINK"][BINKID]["g"]["y"].get<std::string>().c_str());
|
||||
|
||||
/* inverse of public key */
|
||||
BN_dec2bn(&pubx, std::get<0>(BINKData[BINKID].K).c_str());
|
||||
BN_dec2bn(&puby, std::get<1>(BINKData[BINKID].K).c_str());
|
||||
BN_dec2bn(&pubx, keys["BINK"][BINKID]["pub"]["x"].get<std::string>().c_str());
|
||||
BN_dec2bn(&puby, keys["BINK"][BINKID]["pub"]["y"].get<std::string>().c_str());
|
||||
|
||||
// Computed data
|
||||
/* order of G - computed in 18 hours using a P3-450 */
|
||||
BN_dec2bn(&n, BINKData[BINKID].n.c_str());
|
||||
BN_dec2bn(&n, keys["BINK"][BINKID]["n"].get<std::string>().c_str());
|
||||
|
||||
/* THE private key - computed in 10 hours using a P3-450 */
|
||||
BN_dec2bn(&priv, BINKData[BINKID].k.c_str());
|
||||
BN_dec2bn(&n, keys["BINK"][BINKID]["priv"].get<std::string>().c_str());
|
||||
|
||||
// Calculation
|
||||
EC_GROUP *ec = EC_GROUP_new_curve_GFp(p, a, b, ctx);
|
||||
|
@ -1,5 +1,7 @@
|
||||
#include "header.h"
|
||||
|
||||
char charset[] = "BCDFGHJKMPQRTVWXY2346789";
|
||||
|
||||
void unpack2003(ul32 *osfamily, ul32 *hash, ul32 *sig, ul32 *prefix, ul32 *raw)
|
||||
{
|
||||
osfamily[0] = raw[0] & 0x7ff;
|
||||
|
Loading…
Reference in New Issue
Block a user