mirror of
https://github.com/Neo-Desktop/WindowsXPKg
synced 2025-06-14 17:44:16 +03:00
Compare commits
5 Commits
a827844cbd
...
neo-refact
Author | SHA1 | Date | |
---|---|---|---|
1cedbff4ef | |||
7a0faa42e8 | |||
c7eb049c0b | |||
015fd00d3f | |||
2ac7f9bc1e |
@ -1,2 +1,2 @@
|
||||
build*/
|
||||
cmake-*/
|
||||
cmake*/
|
||||
|
127
.github/workflows/dos-djgpp.yml
vendored
127
.github/workflows/dos-djgpp.yml
vendored
@ -23,21 +23,34 @@ name: C/C++ CI (DOS DJGPP)
|
||||
on:
|
||||
push:
|
||||
branches: [ "*" ]
|
||||
paths-ignore: [ '**.md', 'doc/**', '.idea/**'] # If only these files are edited, skip
|
||||
paths-ignore: [ '**.md', 'doc/**', '.idea/**' ] # If only these files are edited, skip
|
||||
pull_request:
|
||||
branches: [ "*" ]
|
||||
paths-ignore: [ '**.md', 'doc/**', '.idea/**' ] # If only these files are edited, skip
|
||||
workflow_dispatch:
|
||||
|
||||
env:
|
||||
CC: ${{ github.workspace }}/djgpp/bin/i586-pc-msdosdjgpp-gcc
|
||||
CXX: ${{ github.workspace }}/djgpp/bin/i586-pc-msdosdjgpp-g++
|
||||
CMAKE_FIND_ROOT_PATH: ${{ github.workspace }}/djgpp
|
||||
WATT_ROOT: ${{ github.workspace }}/djgpp/watt32
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
CC: ${{ github.workspace }}/djgpp/bin/i586-pc-msdosdjgpp-gcc
|
||||
CXX: ${{ github.workspace }}/djgpp/bin/i586-pc-msdosdjgpp-g++
|
||||
CMAKE_FIND_ROOT_PATH: ${{ github.workspace }}/djgpp
|
||||
GCC_EXEC_PREFIX: ${{ github.workspace }}/lib/gcc/
|
||||
DJDIR: ${{ github.workspace }}/djgpp/i586-pc-msdosdjgpp
|
||||
|
||||
steps:
|
||||
- name: Checkout Source Tree
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v4.1.1
|
||||
|
||||
- name: Set up CPM cache
|
||||
id: cache-cpm
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: ${{ github.workspace }}/.cpm-cache
|
||||
key: ${{ runner.os }}-cpm-${{ hashFiles('**/') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-cpm-
|
||||
|
||||
- name: Setup build environment
|
||||
run: |
|
||||
@ -46,34 +59,19 @@ jobs:
|
||||
|
||||
- name: Download and Setup DJGPP Toolchain
|
||||
run: |
|
||||
pushd ${{ github.workspace }}
|
||||
wget https://github.com/andrewwutw/build-djgpp/releases/download/v3.4/djgpp-linux64-gcc1220.tar.bz2
|
||||
tar xjf djgpp-linux64-gcc1220.tar.bz2
|
||||
cd ${{ github.workspace }}/djgpp
|
||||
git clone https://github.com/UMSKT/Watt-32.git watt32
|
||||
cd watt32/util
|
||||
make clean && make linux
|
||||
cd ../src
|
||||
source ${{ github.workspace }}/djgpp/setenv
|
||||
./configur.sh djgpp
|
||||
make -f djgpp.mak
|
||||
ln -s ${WATT_ROOT}/lib/libwatt.a ${{ github.workspace }}/djgpp/lib
|
||||
echo "${{ github.workspace }}/djgpp/i586-pc-msdosdjgpp/bin/" >> "$GITHUB_ENV"
|
||||
echo "${{ github.workspace }}/djgpp/bin/" >> "$GITHUB_ENV"
|
||||
|
||||
- name: Checkout and Cross Compile OpenSSL 3.1.2
|
||||
run: |
|
||||
git clone https://github.com/UMSKT/openssl.git openssl
|
||||
pushd openssl
|
||||
source ${{ github.workspace }}/djgpp/setenv
|
||||
./Configure no-threads -DOPENSSL_DEV_NO_ATOMICS --prefix=${{ github.workspace }}/djgpp DJGPP
|
||||
make && make install
|
||||
popd
|
||||
|
||||
- name: Build
|
||||
run: |
|
||||
source ${{ github.workspace }}/djgpp/setenv
|
||||
pushd build
|
||||
cmake ../ -D DJGPP_WATT32=${WATT_ROOT}/lib/libwatt.a -D CMAKE_FIND_ROOT_PATH=${CMAKE_FIND_ROOT_PATH}
|
||||
make
|
||||
- name: Build UMSKT for MSDOS via DJGPP
|
||||
uses: threeal/cmake-action@v1.3.0
|
||||
with:
|
||||
options: UMSKT_DJGPP_COMPILE=On CMAKE_FIND_ROOT_PATH=${CMAKE_FIND_ROOT_PATH} CMAKE_BUILD_TYPE=Release
|
||||
build-dir: build
|
||||
c-compiler: ${CC}
|
||||
cxx-compiler: ${CXX}
|
||||
build-args: -j 2
|
||||
|
||||
- name: Move executable to upload directory
|
||||
run: |
|
||||
@ -81,7 +79,68 @@ jobs:
|
||||
mv build/umskt.exe build/actions_upload/
|
||||
|
||||
- name: Upload build artifact
|
||||
uses: actions/upload-artifact@v3.1.2
|
||||
uses: actions/upload-artifact@v4.3.1
|
||||
with:
|
||||
name: UMSKT-DOS
|
||||
path: build/actions_upload
|
||||
|
||||
build-dos-win32-combined:
|
||||
needs: build
|
||||
runs-on: windows-latest
|
||||
steps:
|
||||
# https://github.com/actions/runner-images/issues/6067#issuecomment-1213069040
|
||||
- name: Install Windows XP Support for Visual Studio
|
||||
run: |
|
||||
Set-Location "C:\Program Files (x86)\Microsoft Visual Studio\Installer\"
|
||||
$InstallPath = "C:\Program Files\Microsoft Visual Studio\2022\Enterprise"
|
||||
$componentsToAdd = @(
|
||||
"Microsoft.VisualStudio.Component.WinXP"
|
||||
)
|
||||
[string]$workloadArgs = $componentsToAdd | ForEach-Object {" --add " + $_}
|
||||
$Arguments = ('/c', "vs_installer.exe", 'modify', '--installPath', "`"$InstallPath`"",$workloadArgs, '--quiet', '--norestart', '--nocache')
|
||||
$process = Start-Process -FilePath cmd.exe -ArgumentList $Arguments -Wait -PassThru -WindowStyle Hidden
|
||||
if ($process.ExitCode -eq 0)
|
||||
{
|
||||
Write-Host "components have been successfully added"
|
||||
Get-ChildItem C:\ProgramData\Microsoft\VisualStudio\Packages\Microsoft.Windows.XPSupport.*
|
||||
}
|
||||
else
|
||||
{
|
||||
Write-Host "components were not installed"
|
||||
exit 1
|
||||
}
|
||||
|
||||
- name: Setup MSBuild
|
||||
uses: microsoft/setup-msbuild@v1
|
||||
|
||||
- name: Checkout Source Tree
|
||||
uses: actions/checkout@v4.1.1
|
||||
|
||||
- name: Set up CPM cache
|
||||
id: cache-cpm
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: ${{ github.workspace }}/.cpm-cache
|
||||
key: ${{ runner.os }}-cpm-${{ hashFiles('**/') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-cpm-
|
||||
|
||||
- name: Download Built DOS Artifact
|
||||
uses: actions/download-artifact@v4.1.2
|
||||
with:
|
||||
name: UMSKT-DOS
|
||||
|
||||
- name: Configure and build UMSKT for DOS+Win32
|
||||
uses: threeal/cmake-action@v1.3.0
|
||||
with:
|
||||
options: UMSKT_MSVC_WINXP=On CMAKE_BUILD_TYPE=Release CPM_SOURCE_CACHE=${{ github.workspace }}/.cpm-cache UMSKT_MSVC_MSDOS_STUB=${{ github.workspace }}/umskt.exe
|
||||
generator: "Visual Studio 17 2022"
|
||||
args: -A "Win32" -T "v141_xp"
|
||||
run-build: true
|
||||
build-args: "--config Release -j 2"
|
||||
|
||||
- name: Upload build artifact
|
||||
uses: actions/upload-artifact@v4.3.1
|
||||
with:
|
||||
name: UMSKT-DOS+Win32
|
||||
path: build/Release
|
91
.github/workflows/freebsd.yml
vendored
91
.github/workflows/freebsd.yml
vendored
@ -17,49 +17,58 @@
|
||||
#
|
||||
# @FileCreated by techguy16 on 07/23/2023
|
||||
# @Maintainer techguy16
|
||||
|
||||
name: C/C++ CI (FreeBSD)
|
||||
|
||||
on:
|
||||
|
||||
name: C/C++ CI (FreeBSD)
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ "*" ]
|
||||
paths-ignore: [ '**.md', 'doc/**', '.idea/**'] # If only these files are edited, skip
|
||||
paths-ignore: [ '**.md', 'doc/**', '.idea/**' ] # If only these files are edited, skip
|
||||
pull_request:
|
||||
branches: [ "*" ]
|
||||
paths-ignore: [ '**.md', 'doc/**', '.idea/**'] # If only these files are edited, skip
|
||||
|
||||
paths-ignore: [ '**.md', 'doc/**', '.idea/**' ] # If only these files are edited, skip
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
name: build-x86_64
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Build & Test in FreeBSD
|
||||
id: test
|
||||
uses: vmactions/freebsd-vm@v1
|
||||
with:
|
||||
envs: 'MYTOKEN MYTOKEN2'
|
||||
usesh: true
|
||||
prepare: |
|
||||
pkg install -y cmake openssl git bash
|
||||
|
||||
run: |
|
||||
mkdir build
|
||||
cd build
|
||||
cmake ..
|
||||
make
|
||||
./umskt # Execute the test here
|
||||
|
||||
- name: Move files to correct directory
|
||||
run: |
|
||||
mkdir -p build/actions_upload
|
||||
mv build/umskt build/actions_upload/umskt
|
||||
|
||||
- name: Upload build artifact
|
||||
uses: actions/upload-artifact@v3.1.2
|
||||
with:
|
||||
name: UMSKT-FreeBSD
|
||||
path: build/actions_upload
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
name: build-x86_64
|
||||
|
||||
steps:
|
||||
- name: Checkout Source Tree
|
||||
uses: actions/checkout@v4.1.1
|
||||
|
||||
- name: Set up CPM cache
|
||||
id: cache-cpm
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: ${{ github.workspace }}/.cpm-cache
|
||||
key: ${{ runner.os }}-cpm-${{ hashFiles('**/') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-cpm-
|
||||
|
||||
- name: Build & Test in FreeBSD
|
||||
id: test
|
||||
uses: vmactions/freebsd-vm@v1.0.6
|
||||
with:
|
||||
usesh: true
|
||||
prepare: |
|
||||
pkg install -y cmake git bash
|
||||
|
||||
run: |
|
||||
mkdir build
|
||||
cmake -DCMAKE_BUILD_TYPE=Release -DCPM_SOURCE_CACHE= ${{ github.workspace }}/.cpm-cache -DBUILD_TESTING=On -B build/
|
||||
cmake --build build/ -j 2
|
||||
cd build
|
||||
ctest
|
||||
|
||||
- name: Move files to correct directory
|
||||
run: |
|
||||
mkdir -p build/actions_upload
|
||||
mv build/umskt build/actions_upload/umskt
|
||||
|
||||
- name: Upload build artifact
|
||||
uses: actions/upload-artifact@v4.3.1
|
||||
with:
|
||||
name: UMSKT-FreeBSD
|
||||
path: build/actions_upload
|
||||
|
98
.github/workflows/linux.yml
vendored
98
.github/workflows/linux.yml
vendored
@ -23,7 +23,10 @@ name: C/C++ CI (Linux)
|
||||
on:
|
||||
push:
|
||||
branches: [ "*" ]
|
||||
paths-ignore: [ '**.md', 'doc/**', '.idea/**'] # If only these files are edited, skip
|
||||
paths-ignore: [ '**.md', 'doc/**', '.idea/**' ] # If only these files are edited, skip
|
||||
pull_request:
|
||||
branches: [ "*" ]
|
||||
paths-ignore: [ '**.md', 'doc/**', '.idea/**' ] # If only these files are edited, skip
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
@ -31,57 +34,56 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
include:
|
||||
- arch: x86
|
||||
- arch: x86_64
|
||||
- arch: aarch64
|
||||
arch:
|
||||
- x86
|
||||
- x86_64
|
||||
- aarch64
|
||||
- armhf
|
||||
- armv7
|
||||
- ppc64le
|
||||
- s390x
|
||||
|
||||
steps:
|
||||
- name: Checkout Source Tree
|
||||
uses: actions/checkout@v3
|
||||
- name: Checkout Source Tree
|
||||
uses: actions/checkout@v4.1.1
|
||||
|
||||
- name: Setup latest Alpine Linux for ${{ matrix.arch }}
|
||||
uses: jirutka/setup-alpine@v1
|
||||
with:
|
||||
packages: >
|
||||
bash
|
||||
build-base
|
||||
cmake
|
||||
git
|
||||
musl-dev
|
||||
openssl-dev
|
||||
openssl-libs-static
|
||||
zlib-dev
|
||||
arch: ${{ matrix.arch }}
|
||||
shell-name: alpine-target.sh
|
||||
- name: Set up CPM cache
|
||||
id: cache-cpm
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: ${{ github.workspace }}/.cpm-cache
|
||||
key: ${{ runner.os }}-cpm-${{ hashFiles('**/') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-cpm-
|
||||
|
||||
- name: Configure and build UMSKT
|
||||
uses: threeal/cmake-action@7ef2eb8da6e5ec0a6de6b1ddc96987080bed06e8
|
||||
with:
|
||||
options: MUSL_STATIC=ON
|
||||
run-build: true
|
||||
shell: alpine-target.sh {0}
|
||||
- name: Setup latest Alpine Linux for ${{ matrix.arch }}
|
||||
uses: jirutka/setup-alpine@v1
|
||||
with:
|
||||
packages: >
|
||||
bash
|
||||
build-base
|
||||
cmake
|
||||
git
|
||||
musl-dev
|
||||
arch: ${{ matrix.arch }}
|
||||
shell-name: alpine-target.sh
|
||||
|
||||
- name: Move files to correct directory
|
||||
run: |
|
||||
- name: Configure and build UMSKT
|
||||
uses: threeal/cmake-action@v1.3.0
|
||||
with:
|
||||
options: UMSKT_MUSL_STATIC=ON CMAKE_BUILD_TYPE=Release CPM_SOURCE_CACHE=${{ github.workspace }}/.cpm-cache BUILD_TESTING=On
|
||||
run-build: true
|
||||
build-args: -j 2
|
||||
run-test: true
|
||||
shell: alpine-target.sh {0}
|
||||
|
||||
- name: Move files to correct directory
|
||||
run: |
|
||||
mkdir -p build/actions_upload
|
||||
mv build/umskt build/actions_upload/umskt
|
||||
|
||||
- name: Upload build artifact
|
||||
uses: actions/upload-artifact@v3.1.2
|
||||
with:
|
||||
name: UMSKT-linux-${{ matrix.arch }}-static
|
||||
path: build/actions_upload
|
||||
|
||||
- name: Configure and build static internal deps UMSKT
|
||||
uses: threeal/cmake-action@7ef2eb8da6e5ec0a6de6b1ddc96987080bed06e8
|
||||
with:
|
||||
options: MUSL_STATIC=OFF BUILD_SHARED_LIBS=OFF
|
||||
run-build: true
|
||||
shell: alpine-target.sh {0}
|
||||
|
||||
- name: Configure and build shared deps UMSKT
|
||||
uses: threeal/cmake-action@7ef2eb8da6e5ec0a6de6b1ddc96987080bed06e8
|
||||
with:
|
||||
options: MUSL_STATIC=OFF BUILD_SHARED_LIBS=ON
|
||||
run-build: true
|
||||
shell: alpine-target.sh {0}
|
||||
- name: Upload build artifact
|
||||
uses: actions/upload-artifact@v4.3.1
|
||||
with:
|
||||
name: UMSKT-linux-${{ matrix.arch }}-static
|
||||
path: build/actions_upload
|
||||
|
45
.github/workflows/macos.yml
vendored
45
.github/workflows/macos.yml
vendored
@ -23,38 +23,49 @@ name: C/C++ CI (macOS)
|
||||
on:
|
||||
push:
|
||||
branches: [ "*" ]
|
||||
paths-ignore: [ '**.md', 'doc/**', '.idea/**'] # If only these files are edited, skip
|
||||
paths-ignore: [ '**.md', 'doc/**', '.idea/**' ] # If only these files are edited, skip
|
||||
pull_request:
|
||||
branches: [ "*" ]
|
||||
paths-ignore: [ '**.md', 'doc/**', '.idea/**' ] # If only these files are edited, skip
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
build-x86:
|
||||
build:
|
||||
runs-on: macos-latest
|
||||
strategy:
|
||||
matrix:
|
||||
include:
|
||||
- arch: x86_64
|
||||
arch:
|
||||
- { name: arm64;x86_64, displayName: all-x86_64_arm64 }
|
||||
- { name: x86_64, displayName: x86_64 }
|
||||
- { name: arm64, displayName: arm64 }
|
||||
steps:
|
||||
- name: Checkout Source Tree
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v4.1.1
|
||||
|
||||
- name: Configure and build UMSKT
|
||||
run: |
|
||||
cd build
|
||||
cmake -DCMAKE_BUILD_TYPE=Release ..
|
||||
make
|
||||
- name: Set up CPM cache
|
||||
id: cache-cpm
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: ${{ github.workspace }}/.cpm-cache
|
||||
key: ${{ runner.os }}-cpm-${{ hashFiles('**/') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-cpm-
|
||||
|
||||
- name: Configure and build UMSKT for ${{ matrix.arch.displayName }}
|
||||
uses: threeal/cmake-action@v1.3.0
|
||||
with:
|
||||
options: MUSL_STATIC=ON CMAKE_BUILD_TYPE=Release CPM_SOURCE_CACHE=${{ github.workspace }}/.cpm-cache CMAKE_OSX_ARCHITECTURES="${{ matrix.arch.name }}" BUILD_TESTING=On
|
||||
run-build: true
|
||||
build-args: -j 2
|
||||
run-test: true
|
||||
|
||||
- name: Move files to correct directory
|
||||
run: |
|
||||
mkdir -p build/actions_upload
|
||||
mv build/umskt build/actions_upload/umskt
|
||||
|
||||
- name: Run tests
|
||||
run: |
|
||||
cd build/actions_upload
|
||||
./umskt
|
||||
|
||||
- name: Upload build artifact
|
||||
uses: actions/upload-artifact@v3.1.2
|
||||
uses: actions/upload-artifact@v4.3.1
|
||||
with:
|
||||
name: UMSKT-macOS-${{ matrix.arch }}
|
||||
name: UMSKT-macOS-${{ matrix.arch.displayName }}
|
||||
path: build/actions_upload
|
||||
|
110
.github/workflows/windows.yml
vendored
110
.github/workflows/windows.yml
vendored
@ -24,11 +24,17 @@ on:
|
||||
push:
|
||||
branches: [ "*" ]
|
||||
paths-ignore: [ '**.md', 'doc/**', '.idea/**'] # If only these files are edited, skip
|
||||
pull_request:
|
||||
branches: [ "*" ]
|
||||
paths-ignore: [ '**.md', 'doc/**', '.idea/**'] # If only these files are edited, skip
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
build-32bit:
|
||||
build:
|
||||
runs-on: windows-latest
|
||||
strategy:
|
||||
matrix:
|
||||
arch: [ { name: Win32, displayName: x86 }, { name: x64, displayName: x64 } ]
|
||||
steps:
|
||||
# https://github.com/actions/runner-images/issues/6067#issuecomment-1213069040
|
||||
- name: Install Windows XP Support for Visual Studio
|
||||
@ -52,97 +58,33 @@ jobs:
|
||||
exit 1
|
||||
}
|
||||
|
||||
- name: Download And Install 32-bit OpenSSL 3.1.4
|
||||
run: |
|
||||
$installDir = "$Env:ProgramFiles\OpenSSL"
|
||||
$installerURL = "https://slproweb.com/download/Win32OpenSSL-3_1_4.exe"
|
||||
$installerName = "Win32OpenSSL-3_1_4.exe"
|
||||
$installerPath = Join-Path -Path "${env:Temp}" -ChildPath "$installerName"
|
||||
|
||||
(New-Object System.Net.WebClient).DownloadFile($installerURL, $installerPath)
|
||||
|
||||
Remove-Item "$installDir" -Force -Recurse
|
||||
$installerArgs = '/silent', '/sp-', '/suppressmsgboxes', "/DIR=`"$installDir`""
|
||||
Start-Process -FilePath $installerPath -ArgumentList $installerArgs -Wait -PassThru
|
||||
- name: Set up CPM cache
|
||||
id: cache-cpm
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: ${{ github.workspace }}/.cpm-cache
|
||||
key: ${{ runner.os }}-cpm-${{ hashFiles('**/') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-cpm-
|
||||
|
||||
- name: Checkout Source Tree
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v4.1.1
|
||||
|
||||
- name: Setup MSBuild
|
||||
uses: microsoft/setup-msbuild@v1
|
||||
|
||||
- name: Configure UMSKT
|
||||
uses: threeal/cmake-action@v1.2.0
|
||||
- name: Configure and build UMSKT for ${{ matrix.values.displayName }}
|
||||
uses: threeal/cmake-action@v1.3.0
|
||||
with:
|
||||
options: CMAKE_BUILD_TYPE=Release CPM_SOURCE_CACHE=${{ github.workspace }}/.cpm-cache BUILD_TESTING=On
|
||||
generator: "Visual Studio 17 2022"
|
||||
options: CMAKE_SYSTEM_VERSION="5.1.2600"
|
||||
args: -A "Win32" -T v141_xp
|
||||
|
||||
- name: Build UMSKT
|
||||
working-directory: build
|
||||
run: msbuild ALL_BUILD.vcxproj /P:Configuration=Release
|
||||
args: -A "${{ matrix.arch.name }}" -T "v141_xp"
|
||||
run-build: true
|
||||
build-args: --config Release -j 2
|
||||
run-test: true
|
||||
|
||||
- name: Upload build artifact
|
||||
uses: actions/upload-artifact@v3.1.2
|
||||
uses: actions/upload-artifact@v4.3.1
|
||||
with:
|
||||
name: UMSKT-Win32
|
||||
path: build/Release
|
||||
|
||||
build-64bit:
|
||||
runs-on: windows-latest
|
||||
steps:
|
||||
- name: Install Windows XP Support for Visual Studio
|
||||
run: |
|
||||
Set-Location "C:\Program Files (x86)\Microsoft Visual Studio\Installer\"
|
||||
$InstallPath = "C:\Program Files\Microsoft Visual Studio\2022\Enterprise"
|
||||
$componentsToAdd = @(
|
||||
"Microsoft.VisualStudio.Component.WinXP"
|
||||
)
|
||||
[string]$workloadArgs = $componentsToAdd | ForEach-Object {" --add " + $_}
|
||||
$Arguments = ('/c', "vs_installer.exe", 'modify', '--installPath', "`"$InstallPath`"",$workloadArgs, '--quiet', '--norestart', '--nocache')
|
||||
$process = Start-Process -FilePath cmd.exe -ArgumentList $Arguments -Wait -PassThru -WindowStyle Hidden
|
||||
if ($process.ExitCode -eq 0)
|
||||
{
|
||||
Write-Host "components have been successfully added"
|
||||
Get-ChildItem C:\ProgramData\Microsoft\VisualStudio\Packages\Microsoft.Windows.XPSupport.*
|
||||
}
|
||||
else
|
||||
{
|
||||
Write-Host "components were not installed"
|
||||
exit 1
|
||||
}
|
||||
|
||||
- name: Download And Install 64-bit OpenSSL 3.1.4
|
||||
run: |
|
||||
$installDir = "$Env:ProgramFiles\OpenSSL"
|
||||
$installerURL = "https://slproweb.com/download/Win64OpenSSL-3_1_4.exe"
|
||||
$installerName = "Win64OpenSSL-3_1_4.exe"
|
||||
$installerPath = Join-Path -Path "${env:Temp}" -ChildPath "$installerName"
|
||||
|
||||
(New-Object System.Net.WebClient).DownloadFile($installerURL, $installerPath)
|
||||
|
||||
Remove-Item "$installDir" -Force -Recurse
|
||||
$installerArgs = '/silent', '/sp-', '/suppressmsgboxes', "/DIR=`"$installDir`""
|
||||
Start-Process -FilePath $installerPath -ArgumentList $installerArgs -Wait -PassThru
|
||||
|
||||
- name: Checkout Source Tree
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Setup MSBuild
|
||||
uses: microsoft/setup-msbuild@v1
|
||||
|
||||
- name: Configure UMSKT
|
||||
uses: threeal/cmake-action@v1.2.0
|
||||
with:
|
||||
generator: "Visual Studio 17 2022"
|
||||
args: -A "x64" -T "v141_xp"
|
||||
|
||||
- name: Build UMSKT
|
||||
working-directory: build
|
||||
run: msbuild ALL_BUILD.vcxproj /P:Configuration=Release
|
||||
|
||||
- name: Upload build artifact
|
||||
uses: actions/upload-artifact@v3.1.2
|
||||
with:
|
||||
name: UMSKT-Win64
|
||||
path: build/Release
|
||||
name: UMSKT-${{ matrix.values.displayName }}
|
||||
path: build/Release
|
5
.gitignore
vendored
5
.gitignore
vendored
@ -1,8 +1,9 @@
|
||||
build/*
|
||||
build*/
|
||||
*.tar
|
||||
*.exe
|
||||
*.wasm
|
||||
umskt
|
||||
.cpm-cache
|
||||
|
||||
### NotepadPP template
|
||||
# Notepad++ backups #
|
||||
@ -66,7 +67,7 @@ umskt
|
||||
# *.ipr
|
||||
|
||||
# CMake
|
||||
cmake-*/
|
||||
cmake*/
|
||||
|
||||
# Mongo Explorer plugin
|
||||
.idea/**/mongoSettings.xml
|
||||
|
@ -19,7 +19,12 @@
|
||||
# @Maintainer Neo
|
||||
|
||||
repos:
|
||||
- repo: https://github.com/pre-commit/mirrors-clang-format
|
||||
- repo: https://github.com/pre-commit/mirrors-clang-format
|
||||
rev: 'v17.0.6' # Use the sha / tag you want to point at
|
||||
hooks:
|
||||
- id: clang-format
|
||||
- id: clang-format
|
||||
|
||||
# - repo: https://github.com/cheshirekow/cmake-format-precommit
|
||||
# rev: v0.6.10
|
||||
# hooks:
|
||||
# - id: cmake-format
|
271
CMakeLists.txt
271
CMakeLists.txt
@ -19,117 +19,74 @@
|
||||
# @Maintainer Neo
|
||||
|
||||
CMAKE_MINIMUM_REQUIRED(VERSION 3.12)
|
||||
PROJECT(UMSKT)
|
||||
SET(PROJECT_NAME UMSKT)
|
||||
PROJECT(${PROJECT_NAME})
|
||||
|
||||
SET(CMAKE_CXX_STANDARD 17)
|
||||
SET(CMAKE_OSX_SYSROOT "macosx" CACHE PATH "macOS SDK path")
|
||||
SET(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
||||
|
||||
OPTION(BUILD_SHARED_LIBS "Build all libraries as shared" OFF)
|
||||
OPTION(UMSKT_USE_SHARED_OPENSSL "Force linking against the system-wide OpenSSL library" OFF)
|
||||
OPTION(MUSL_STATIC "Enable fully static builds in a muslc environment (i.e. Alpine Linux)" OFF)
|
||||
OPTION(DJGPP_WATT32 "Enable compilation and linking with DJGPP/WATT32/OpenSSL" OFF)
|
||||
OPTION(MSVC_MSDOS_STUB "Specify a custom MS-DOS stub for a 32-bit MSVC compilation" OFF)
|
||||
OPTION(BUILD_TESTING "Build testing binaries for CTest" OFF)
|
||||
OPTION(BUILD_SHARED_LIBS "Build all dependant libraries as shared" OFF)
|
||||
|
||||
SET(UMSKT_LINK_LIBS ${UMSKT_LINK_LIBS})
|
||||
SET(UMSKT_LINK_DIRS ${UMSKT_LINK_DIRS})
|
||||
OPTION(UMSKT_BUILD_SHARED_LIB "Build libumskt.so/.dll/.dylib" ON)
|
||||
OPTION(UMSKT_BUILD_STATIC_LIB "Build libumskt_static.a/.lib" ON)
|
||||
OPTION(UMSKT_MUSL_STATIC "Enable fully static builds in a muslc environment (i.e. Alpine Linux)" OFF)
|
||||
OPTION(UMSKT_DJGPP_COMPILE "Enable compilation and linking with DJGPP" OFF)
|
||||
OPTION(UMSKT_MSVC_MSDOS_STUB "Specify a custom MS-DOS stub for a 32-bit MSVC compilation" OFF)
|
||||
OPTION(UMSKT_MSVC_WINXP "Specify compile-time flag overrides for Windows XP" OFF)
|
||||
|
||||
# macOS does not support static build
|
||||
IF (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
||||
SET(UMSKT_USE_SHARED_OPENSSL ON)
|
||||
IF (NOT MSVC)
|
||||
SET(CMAKE_CXX_FLAGS "-Os -fdata-sections -ffunction-sections -flto=auto -Wl,--gc-sections")
|
||||
SET(CMAKE_CXX_FLAGS_DEBUG "-g")
|
||||
SET(CMAKE_CXX_FLAGS_DEBUG_INIT "-Wall -Wextra -pedantic")
|
||||
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-g")
|
||||
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT "-Wall -Wextra -pedantic")
|
||||
SET(CMAKE_CXX_FLAGS_RELEASE_INIT "-s")
|
||||
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static -Wl,--gc-sections")
|
||||
ENDIF ()
|
||||
|
||||
# neither does dos idk i'm trying random stuff
|
||||
IF (DJGPP_WATT32)
|
||||
SET(UMSKT_USE_SHARED_OPENSSL ON)
|
||||
ENDIF ()
|
||||
|
||||
IF (UMSKT_USE_SHARED_OPENSSL)
|
||||
SET(OPENSSL_USE_STATIC_LIBS FALSE)
|
||||
SET(OPENSSL_MSVC_STATIC_RT FALSE)
|
||||
MESSAGE(STATUS "[UMSKT] Requesting dynamic version of OpenSSL")
|
||||
ELSE ()
|
||||
SET(OPENSSL_USE_STATIC_LIBS TRUE)
|
||||
SET(OPENSSL_MSVC_STATIC_RT TRUE)
|
||||
MESSAGE(STATUS "[UMSKT] Requesting static version of OpenSSL")
|
||||
ENDIF ()
|
||||
|
||||
IF (DJGPP_WATT32)
|
||||
IF (UMSKT_DJGPP_COMPILE)
|
||||
SET(CMAKE_SYSTEM_NAME MSDOS)
|
||||
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
|
||||
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
|
||||
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
|
||||
SET(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
|
||||
SET(UMSKT_LINK_LIBS ${UMSKT_LINK_LIBS} ${DJGPP_WATT32})
|
||||
SET(UMSKT_LINK_DIRS ${UMSKT_LINK_DIRS} ${WATT_ROOT}/lib)
|
||||
SET(UMSKT_BUILD_SHARED_LIB OFF)
|
||||
SET(UMSKT_BUILD_STATIC_LIB OFF)
|
||||
SET(CMAKE_POSITION_INDEPENDENT_CODE OFF)
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-attributes -march=i386 -mtune=i386")
|
||||
MESSAGE(STATUS "[UMSKT] DJGPP Build requested - Shared libraries forced OFF")
|
||||
ENDIF ()
|
||||
|
||||
IF (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
||||
SET(BUILD_SHARED_LIBS ON)
|
||||
MESSAGE(STATUS "[UMSKT] macOS has no static library - Shared library forced on")
|
||||
MESSAGE(STATUS "[UMSKT] macOS Build requested - Shared libraries forced ON")
|
||||
ENDIF ()
|
||||
|
||||
# if we're compiling with MSVC, respect the DEBUG compile option
|
||||
IF (MSVC)
|
||||
SET(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
|
||||
SET(CMAKE_CXX_FLAGS "/Os /LTCG /Gy /OPT:REF /OPT:ICF /EHsc")
|
||||
SET(CMAKE_CXX_FLAGS_RELEASE "/MT")
|
||||
SET(CMAKE_CXX_FLAGS_DEBUG "/MTd")
|
||||
SET(CMAKE_EXE_LINKER_FLAGS "/INCREMENTAL:NO /NODEFAULTLIB:MSVCRT")
|
||||
SET(CMAKE_CXX_FLAGS_DEBUG "/MTd /Z7")
|
||||
SET(CMAKE_EXE_LINKER_FLAGS "/INCREMENTAL:NO /NODEFAULTLIB:MSVCRT /LTCG")
|
||||
SET(CMAKE_EXE_LINKER_FLAGS_DEBUG "/DEBUG")
|
||||
SET(CMAKE_ENABLE_EXPORTS ON)
|
||||
SET(UMSKT_EXE_WINDOWS_EXTRA src/windows/umskt.rc)
|
||||
SET(UMSKT_EXE_WINDOWS_DLL src/windows/dllmain.cpp)
|
||||
IF (UMSKT_MSVC_WINXP)
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /U_WIN32_WINNT /DWINVER=0x0501 /D_WIN32_WINNT=0x0501")
|
||||
ENDIF ()
|
||||
ENDIF ()
|
||||
|
||||
IF (MUSL_STATIC)
|
||||
MESSAGE(STATUS "[UMSKT] Performing a fully static build using muslc")
|
||||
MESSAGE(STATUS "[UMSKT] musl libc Build requested - Shared librares forced OFF")
|
||||
SET(BUILD_SHARED_LIBS OFF)
|
||||
SET(OPENSSL_USE_STATIC_LIBS TRUE)
|
||||
|
||||
SET(CMAKE_EXE_LINKER_FLAGS "-static -static-libgcc -static-libstdc++")
|
||||
SET(CMAKE_SHARED_LINKER_FLAGS "-static -static-libgcc -static-libstdc++")
|
||||
SET(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
|
||||
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -static-libgcc -static-libstdc++")
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libgcc -static-libstdc++")
|
||||
ENDIF ()
|
||||
|
||||
# find the system installed OpenSSL development library
|
||||
FIND_PACKAGE(OpenSSL REQUIRED)
|
||||
IF (NOT OPENSSL_FOUND)
|
||||
MESSAGE(SEND_ERROR "OpenSSL Development Libraries Not Found")
|
||||
MESSAGE(SEND_ERROR "Please consult your package manager of choice to install the prerequisite")
|
||||
MESSAGE(SEND_ERROR "The package name is commonly called libssl-dev or openssl-dev depending on distribution")
|
||||
MESSAGE(FATAL_ERROR "Can not continue without OpenSSL")
|
||||
ENDIF ()
|
||||
|
||||
IF (NOT MUSL_STATIC)
|
||||
# if we found shared libraries - do the following:
|
||||
IF (OPENSSL_USE_STATIC_LIBS)
|
||||
MESSAGE(STATUS "[UMSKT] requested static version of OpenSSL")
|
||||
IF (NOT UMSKT_USE_SHARED_OPENSSL)
|
||||
MESSAGE(STATUS "[UMSKT] not asked for shared version of OpenSSL")
|
||||
ENDIF ()
|
||||
|
||||
IF (MSVC)
|
||||
SET(UMSKT_LINK_LIBS ${UMSKT_LINK_LIBS} "ws2_32.lib")
|
||||
SET(UMSKT_LINK_LIBS ${UMSKT_LINK_LIBS} "crypt32.lib")
|
||||
MESSAGE(STATUS "[UMSKT] msvc adding ws2_32.lib crypt32.lib")
|
||||
ENDIF ()
|
||||
ENDIF ()
|
||||
|
||||
STRING(REGEX MATCH "(\\.so|\\.dll|\\.dylib)$" OPENSSL_CRYPTO_SHARED "${OPENSSL_CRYPTO_LIBRARY}")
|
||||
IF (OPENSSL_CRYPTO_SHARED)
|
||||
MESSAGE(STATUS "[UMSKT] Detected Shared library version of OpenSSL")
|
||||
ELSE ()
|
||||
MESSAGE(STATUS "[UMSKT] Detected Static Library version of OpenSSL")
|
||||
|
||||
# static libcrypto on Fedora needs -lz at link time
|
||||
IF (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
|
||||
FIND_PACKAGE(ZLIB REQUIRED)
|
||||
IF (NOT ZLIB_FOUND)
|
||||
MESSAGE(FATAL_ERROR "[UMSKT] linux static OpenSSL requires zlib")
|
||||
ENDIF ()
|
||||
ENDIF ()
|
||||
ENDIF ()
|
||||
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc -static-libstdc++")
|
||||
ENDIF ()
|
||||
|
||||
# initialize cpm.CMake
|
||||
@ -140,6 +97,7 @@ FILE(
|
||||
EXPECTED_HASH SHA256=cc155ce02e7945e7b8967ddfaff0b050e958a723ef7aad3766d368940cb15494
|
||||
)
|
||||
INCLUDE(${CMAKE_CURRENT_BINARY_DIR}/cmake/CPM.cmake)
|
||||
CPMUsePackageLock(${CMAKE_SOURCE_DIR}/package-lock.cmake)
|
||||
|
||||
# fetch cpm.CMake dependencies
|
||||
# Include JSON development library
|
||||
@ -165,22 +123,22 @@ CPMAddPackage(
|
||||
VERSION 2.0.1
|
||||
)
|
||||
|
||||
# Include Crypto++ development library
|
||||
#CPMAddPackage(
|
||||
# NAME cryptopp-cmake
|
||||
# GITHUB_REPOSITORY abdes/cryptopp-cmake
|
||||
# GIT_TAG CRYPTOPP_8_8_0
|
||||
# VERSION 8.8.0
|
||||
# OPTIONS "CRYPTOPP_BUILD_TESTING OFF"
|
||||
#)
|
||||
# Include stdint128
|
||||
CPMAddPackage(
|
||||
NAME stdint128
|
||||
GITHUB_REPOSITORY UMSKT/stdint128-cmake
|
||||
GIT_TAG v1.0.0
|
||||
VERSION 1.0.0
|
||||
)
|
||||
|
||||
#include googletest unit testing library
|
||||
#CPMAddPackage(
|
||||
# NAME googletest
|
||||
# GITHUB_REPOSITORY google/googletest
|
||||
# VERSION 1.13.0
|
||||
# OPTIONS "INSTALL_GTEST OFF" "gtest_force_shared_crt"
|
||||
#)
|
||||
# Include Crypto++ development library
|
||||
CPMAddPackage(
|
||||
NAME cryptopp-cmake
|
||||
GITHUB_REPOSITORY UMSKT/cryptopp-cmake
|
||||
GIT_TAG CRYPTOPP_8_9_0
|
||||
VERSION 8.9.0
|
||||
OPTIONS "CRYPTOPP_BUILD_TESTING OFF"
|
||||
)
|
||||
|
||||
### Resource compilation
|
||||
CMRC_ADD_RESOURCE_LIBRARY(umskt-rc ALIAS umskt::rc NAMESPACE umskt keys.json)
|
||||
@ -188,9 +146,9 @@ CMRC_ADD_RESOURCE_LIBRARY(umskt-rc ALIAS umskt::rc NAMESPACE umskt keys.json)
|
||||
SET(LIBUMSKT_PIDGEN2 src/libumskt/pidgen2/PIDGEN2.cpp)
|
||||
SET(LIBUMSKT_PIDGEN3 src/libumskt/pidgen3/PIDGEN3.cpp src/libumskt/pidgen3/BINK1998.cpp src/libumskt/pidgen3/BINK2002.cpp)
|
||||
SET(LIBUMSKT_CONFID src/libumskt/confid/confid.cpp src/libumskt/confid/polynomial.cpp src/libumskt/confid/residue.cpp src/libumskt/confid/divisor.cpp)
|
||||
SET(LIBUMSKT_SRC src/libumskt/libumskt.cpp src/libumskt/debugoutput.cpp ${LIBUMSKT_PIDGEN2} ${LIBUMSKT_PIDGEN3} ${LIBUMSKT_CONFID})
|
||||
SET(UMSKT_CLI_SRC src/main.cpp src/help.cpp src/cli.cpp src/generate.cpp)
|
||||
SET(UMSKT_LINK_LIBS ${UMSKT_LINK_LIBS} ${OPENSSL_CRYPTO_LIBRARIES} ${ZLIB_LIBRARIES} fmt)
|
||||
SET(LIBUMSKT_SRC src/libumskt/libumskt.cpp src/libumskt/init.cpp src/libumskt/pidgen.cpp ${LIBUMSKT_PIDGEN2} ${LIBUMSKT_PIDGEN3} ${LIBUMSKT_CONFID})
|
||||
SET(UMSKT_CLI_SRC src/main.cpp src/cli/help.cpp src/cli/cli.cpp src/cli/confirmationid.cpp src/cli/options.cpp src/cli/pidgen.cpp)
|
||||
SET(UMSKT_LINK_LIBS ${UMSKT_LINK_LIBS} fmt cryptopp stdint128)
|
||||
|
||||
IF (NOT MSVC)
|
||||
SET(UMSKT_LINK_LIBS ${UMSKT_LINK_LIBS} umskt::rc)
|
||||
@ -202,54 +160,105 @@ ENDIF()
|
||||
#### Separate Build Path for emscripten
|
||||
IF (EMSCRIPTEN)
|
||||
ADD_EXECUTABLE(umskt ${UMSKT_CLI_SRC} ${LIBUMSKT_SRC})
|
||||
TARGET_INCLUDE_DIRECTORIES(umskt PUBLIC ${OPENSSL_INCLUDE_DIR})
|
||||
TARGET_INCLUDE_DIRECTORIES(umskt PUBLIC ${CMAKE_SOURCE_DIR}/src ${CMAKE_BINARY_DIR})
|
||||
TARGET_LINK_DIRECTORIES(umskt PUBLIC ${UMSKT_LINK_DIRS})
|
||||
TARGET_LINK_LIBRARIES(umskt PUBLIC ${UMSKT_LINK_LIBS})
|
||||
SET(CMAKE_EXECUTABLE_SUFFIX ".html")
|
||||
|
||||
SET_TARGET_PROPERTIES(umskt PROPERTIES COMPILE_FLAGS "-Os -sEXPORTED_RUNTIME_METHODS=ccall,cwrap")
|
||||
SET_TARGET_PROPERTIES(umskt PROPERTIES LINK_FLAGS "-Os -sWASM=1 -sEXPORT_ALL=1 -sEXPORTED_RUNTIME_METHODS=ccall,cwrap --no-entry")
|
||||
SET_TARGET_PROPERTIES(umskt PROPERTIES COMPILE_FLAGS "-sEXPORTED_RUNTIME_METHODS=ccall,cwrap")
|
||||
SET_TARGET_PROPERTIES(umskt PROPERTIES LINK_FLAGS "-sWASM=1 -sEXPORT_ALL=1 -sEXPORTED_RUNTIME_METHODS=ccall,cwrap --no-entry")
|
||||
ELSE ()
|
||||
## umskt.so/.dll creation
|
||||
ADD_LIBRARY(_umskt SHARED ${LIBUMSKT_SRC} ${UMSKT_EXE_WINDOWS_EXTRA} ${UMSKT_EXE_WINDOWS_DLL})
|
||||
TARGET_INCLUDE_DIRECTORIES(_umskt PUBLIC ${OPENSSL_INCLUDE_DIR} ${CMAKE_BINARY_DIR})
|
||||
TARGET_LINK_DIRECTORIES(_umskt PUBLIC ${UMSKT_LINK_DIRS})
|
||||
TARGET_LINK_LIBRARIES(_umskt PUBLIC ${UMSKT_LINK_LIBS})
|
||||
IF(MSVC)
|
||||
SET_TARGET_PROPERTIES(_umskt PROPERTIES OUTPUT_NAME libumskt)
|
||||
ELSE()
|
||||
SET_TARGET_PROPERTIES(_umskt PROPERTIES OUTPUT_NAME umskt)
|
||||
IF (UMSKT_BUILD_SHARED_LIB)
|
||||
ADD_LIBRARY(libumskt SHARED ${LIBUMSKT_SRC} ${UMSKT_EXE_WINDOWS_EXTRA} ${UMSKT_EXE_WINDOWS_DLL})
|
||||
TARGET_INCLUDE_DIRECTORIES(libumskt PUBLIC ${CMAKE_SOURCE_DIR}/src ${CMAKE_BINARY_DIR})
|
||||
TARGET_LINK_DIRECTORIES(libumskt PUBLIC ${UMSKT_LINK_DIRS})
|
||||
TARGET_LINK_LIBRARIES(libumskt PUBLIC ${UMSKT_LINK_LIBS})
|
||||
IF (MSVC)
|
||||
SET_TARGET_PROPERTIES(libumskt PROPERTIES OUTPUT_NAME libumskt)
|
||||
ELSE ()
|
||||
SET_TARGET_PROPERTIES(libumskt PROPERTIES OUTPUT_NAME umskt)
|
||||
ENDIF ()
|
||||
ENDIF()
|
||||
|
||||
## umskt_static.a/.lib creation
|
||||
ADD_LIBRARY(umskt_static ${LIBUMSKT_SRC} ${UMSKT_EXE_WINDOWS_EXTRA} ${UMSKT_EXE_WINDOWS_DLL})
|
||||
TARGET_INCLUDE_DIRECTORIES(umskt_static PUBLIC ${OPENSSL_INCLUDE_DIR} ${CMAKE_BINARY_DIR})
|
||||
TARGET_LINK_DIRECTORIES(umskt_static PUBLIC ${UMSKT_LINK_DIRS})
|
||||
TARGET_LINK_LIBRARIES(umskt_static PUBLIC ${UMSKT_LINK_LIBS})
|
||||
IF(MSVC)
|
||||
SET_TARGET_PROPERTIES(umskt_static PROPERTIES OUTPUT_NAME libumskt_static)
|
||||
ELSE()
|
||||
SET_TARGET_PROPERTIES(umskt_static PROPERTIES OUTPUT_NAME umskt_static)
|
||||
IF (UMSKT_BUILD_STATIC_LIB)
|
||||
ADD_LIBRARY(libumskt_static ${LIBUMSKT_SRC} ${UMSKT_EXE_WINDOWS_EXTRA} ${UMSKT_EXE_WINDOWS_DLL})
|
||||
TARGET_INCLUDE_DIRECTORIES(libumskt_static PUBLIC ${CMAKE_SOURCE_DIR}/src ${CMAKE_BINARY_DIR})
|
||||
TARGET_LINK_DIRECTORIES(libumskt_static PUBLIC ${UMSKT_LINK_DIRS})
|
||||
TARGET_LINK_LIBRARIES(libumskt_static PUBLIC ${UMSKT_LINK_LIBS})
|
||||
IF (MSVC)
|
||||
SET_TARGET_PROPERTIES(libumskt_static PROPERTIES OUTPUT_NAME libumskt_static)
|
||||
ELSE ()
|
||||
SET_TARGET_PROPERTIES(libumskt_static PROPERTIES OUTPUT_NAME umskt_static)
|
||||
ENDIF ()
|
||||
ENDIF()
|
||||
|
||||
### UMSKT executable compilation
|
||||
ADD_EXECUTABLE(umskt ${UMSKT_CLI_SRC} ${UMSKT_EXE_WINDOWS_EXTRA})
|
||||
TARGET_INCLUDE_DIRECTORIES(umskt PUBLIC ${OPENSSL_INCLUDE_DIR} ${CMAKE_BINARY_DIR})
|
||||
TARGET_LINK_LIBRARIES(umskt PUBLIC umskt_static ${UMSKT_LINK_LIBS} nlohmann_json::nlohmann_json)
|
||||
TARGET_LINK_DIRECTORIES(umskt PUBLIC ${UMSKT_LINK_DIRS})
|
||||
IF (MSVC)
|
||||
SET_PROPERTY(TARGET umskt APPEND PROPERTY COMPILE_FLAGS /DUMSKT_CLI_WINRC_EMBED_JSON)
|
||||
IF (MSVC_MSDOS_STUB)
|
||||
SET_PROPERTY(TARGET umskt APPEND PROPERTY LINK_FLAGS /STUB:${MSVC_MSDOS_STUB})
|
||||
IF (CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
|
||||
### only build CLI if we're building UMSKT explicitly
|
||||
IF (UMSKT_BUILD_STATIC_LIB)
|
||||
## Link against the static lib
|
||||
ADD_EXECUTABLE(umskt ${UMSKT_CLI_SRC} ${UMSKT_EXE_WINDOWS_EXTRA})
|
||||
TARGET_LINK_LIBRARIES(umskt PUBLIC libumskt_static ${UMSKT_LINK_LIBS} nlohmann_json::nlohmann_json)
|
||||
ELSEIF (UMSKT_BUILD_SHARED_LIB)
|
||||
## Link against the dynamic lib
|
||||
ADD_EXECUTABLE(umskt ${UMSKT_CLI_SRC} ${UMSKT_EXE_WINDOWS_EXTRA})
|
||||
TARGET_LINK_LIBRARIES(umskt PUBLIC libumskt ${UMSKT_LINK_LIBS} nlohmann_json::nlohmann_json)
|
||||
ELSE()
|
||||
## Don't link against our output, do a full libumskt+cli compile
|
||||
ADD_EXECUTABLE(umskt ${LIBUMSKT_SRC} ${UMSKT_CLI_SRC} ${UMSKT_EXE_WINDOWS_EXTRA})
|
||||
TARGET_LINK_LIBRARIES(umskt PUBLIC ${UMSKT_LINK_LIBS} nlohmann_json::nlohmann_json)
|
||||
ENDIF()
|
||||
|
||||
TARGET_INCLUDE_DIRECTORIES(umskt PUBLIC ${CMAKE_SOURCE_DIR}/src ${CMAKE_BINARY_DIR})
|
||||
TARGET_LINK_DIRECTORIES(umskt PUBLIC ${UMSKT_LINK_DIRS})
|
||||
IF (MSVC)
|
||||
SET_PROPERTY(TARGET umskt APPEND PROPERTY COMPILE_FLAGS /DUMSKT_CLI_WINRC_EMBED_JSON)
|
||||
IF (MSVC_MSDOS_STUB)
|
||||
SET_PROPERTY(TARGET umskt APPEND PROPERTY LINK_FLAGS /STUB:${MSVC_MSDOS_STUB})
|
||||
ENDIF()
|
||||
ENDIF ()
|
||||
|
||||
IF (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
|
||||
INSTALL(TARGETS umskt DESTINATION bin)
|
||||
ENDIF ()
|
||||
ENDIF ()
|
||||
|
||||
IF (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
|
||||
INSTALL(TARGETS umskt DESTINATION bin)
|
||||
ENDIF ()
|
||||
|
||||
### Copy Shared Libraries and dependency files
|
||||
IF (OPENSSL_CRYPTO_SHARED)
|
||||
GET_FILENAME_COMPONENT(OPENSSL_CRYPTO_LIBRARY_FILENAME ${OPENSSL_CRYPTO_LIBRARY} NAME)
|
||||
CONFIGURE_FILE(${OPENSSL_CRYPTO_LIBRARY} "${CMAKE_CURRENT_BINARY_DIR}/${OPENSSL_CRYPTO_LIBRARY_FILENAME}" COPYONLY)
|
||||
ENDIF ()
|
||||
### Strip the built binary
|
||||
IF (${CMAKE_BUILD_TYPE} MATCHES "Release" AND NOT MSVC)
|
||||
ADD_CUSTOM_COMMAND(TARGET umskt POST_BUILD
|
||||
COMMAND strip $<TARGET_FILE:umskt>
|
||||
COMMENT "Stripping symbols for release"
|
||||
)
|
||||
ENDIF()
|
||||
ENDIF ()
|
||||
|
||||
|
||||
#### Build Path for Unit Tests
|
||||
IF ((CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME OR UMSKT_BUILD_TESTING) AND BUILD_TESTING)
|
||||
INCLUDE(CTest)
|
||||
ENABLE_TESTING()
|
||||
|
||||
#include googletest unit testing library
|
||||
CPMAddPackage(
|
||||
NAME googletest
|
||||
GITHUB_REPOSITORY google/googletest
|
||||
VERSION 1.14.0
|
||||
OPTIONS "INSTALL_GTEST OFF" "gtest_force_shared_crt"
|
||||
)
|
||||
|
||||
MACRO(ADD_GTEST TEST)
|
||||
ADD_EXECUTABLE(${TEST} ${ARGN})
|
||||
TARGET_LINK_LIBRARIES(${TEST} gtest gmock gtest_main libumskt_static)
|
||||
TARGET_COMPILE_FEATURES(${TEST} PRIVATE cxx_std_17)
|
||||
SET_TARGET_PROPERTIES(${TEST} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/tests)
|
||||
ADD_TEST(${TEST} tests/${TEST})
|
||||
ENDMACRO()
|
||||
|
||||
ADD_GTEST(TEST_PIDGEN2 src/libumskt/pidgen2/PIDGEN2_unittest.cpp)
|
||||
ADD_GTEST(TEST_PIDGEN3_BINK1998 src/libumskt/pidgen3/BINK1998_unittest.cpp)
|
||||
ADD_GTEST(TEST_PIDGEN3_BINK2002 src/libumskt/pidgen3/BINK2002_unittest.cpp)
|
||||
ADD_GTEST(TEST_CONFIRMATIONID src/libumskt/confid/confid_unittest.cpp)
|
||||
|
||||
ENDIF ()
|
||||
|
15
Dockerfile
15
Dockerfile
@ -27,9 +27,7 @@ RUN apk add --no-cache \
|
||||
build-base \
|
||||
cmake \
|
||||
git \
|
||||
musl-dev \
|
||||
openssl-dev \
|
||||
openssl-libs-static
|
||||
musl-dev
|
||||
|
||||
|
||||
# Stage 2: Build
|
||||
@ -40,14 +38,15 @@ COPY . /src
|
||||
|
||||
# Build UMSKT from the local directory
|
||||
RUN mkdir /src/build \
|
||||
&& cd /src/build \
|
||||
&& cmake -DMUSL_STATIC=ON .. \
|
||||
&& make
|
||||
&& cmake -B /src/build -DCPM_SOURCE_CACHE=/src/.cpm-cache -DCMAKE_BUILD_TYPE=Release -DUMSKT_MUSL_STATIC=ON \
|
||||
&& cmake --build /src/build -j 10
|
||||
|
||||
# Stage 3: Output
|
||||
FROM scratch as output
|
||||
|
||||
COPY --from=builder /src/build/umskt /umskt
|
||||
COPY --from=builder /src/build/umskt /
|
||||
COPY --from=builder /src/build/libumskt_static.a /
|
||||
COPY --from=builder /src/build/libumskt.so /
|
||||
|
||||
# invoke via
|
||||
# docker build -o type=tar,dest=umskt.tar .
|
||||
# docker build -o type=tar,dest=build-musl/umskt.tar .
|
||||
|
106
Dockerfile.djgpp
106
Dockerfile.djgpp
@ -19,105 +19,55 @@
|
||||
# @Maintainer Neo
|
||||
|
||||
# Stage 1: Install Prerequisites
|
||||
FROM alpine:latest as prerequisites
|
||||
FROM ubuntu:latest as prerequisites
|
||||
|
||||
# Stage 1: Install build dependencies
|
||||
RUN apk add --no-cache \
|
||||
autoconf \
|
||||
automake \
|
||||
bash \
|
||||
bison \
|
||||
build-base \
|
||||
clang \
|
||||
cmake \
|
||||
coreutils \
|
||||
curl \
|
||||
elfutils-dev \
|
||||
findutils \
|
||||
RUN apt-get update && apt-get -y install \
|
||||
build-essential \
|
||||
cmake \
|
||||
wget \
|
||||
7zip \
|
||||
git \
|
||||
gawk \
|
||||
flex \
|
||||
libelf \
|
||||
libslirp-dev \
|
||||
linux-headers \
|
||||
nasm \
|
||||
sed \
|
||||
slang-dev \
|
||||
texinfo \
|
||||
unzip \
|
||||
zlib-dev
|
||||
|
||||
libfl-dev \
|
||||
nasm \
|
||||
libslang2-dev \
|
||||
pkg-config \
|
||||
libslang2-modules \
|
||||
gcc-multilib \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
FROM prerequisites as djgpp
|
||||
|
||||
WORKDIR /tmp
|
||||
|
||||
# Stage 2: compile djgpp for muslc
|
||||
ENV DJGPP_PREFIX=/djgpp BUILD_VER=12.2.0-i386
|
||||
RUN git clone https://github.com/andrewwutw/build-djgpp.git djgpp \
|
||||
&& cd djgpp \
|
||||
&& cd script \
|
||||
&& wget https://gist.github.com/Neo-Desktop/4cfd708f61f5847a7bf457d38db3b59f/raw/25d24cf509b0fc486d5d18ecb6656f120c3d0e51/12.2.0-i386 -O 12.2.0-i386 \
|
||||
&& chmod +x 12.2.0-i386 \
|
||||
&& cd ../patch \
|
||||
&& wget https://gist.github.com/Neo-Desktop/4cfd708f61f5847a7bf457d38db3b59f/raw/25d24cf509b0fc486d5d18ecb6656f120c3d0e51/patch-alpine-Fix-attempt-to-use-poisoned-calloc-error-in-libgccji.patch -O patch-alpine-Fix-attempt-to-use-poisoned-calloc-error-in-libgccji.patch \
|
||||
&& cd .. \
|
||||
&& sed -i 's/i586/i386/g' setenv/setenv \
|
||||
&& sed -i 's/i586/i386/g' setenv/setenv.bat \
|
||||
&& ./build-djgpp.sh $BUILD_VER \
|
||||
&& rm -rf /tmp/djgpp
|
||||
|
||||
# Stage 3: compile watt32 for djgpp-i386
|
||||
FROM djgpp as watt32
|
||||
WORKDIR /djgpp
|
||||
ENV WATT_ROOT=/djgpp/watt32 DJGPP_PREFIX=i386-pc-msdosdjgpp
|
||||
SHELL ["/bin/bash", "-c"]
|
||||
RUN git clone https://github.com/gvanem/Watt-32.git watt32 \
|
||||
&& cd watt32/util \
|
||||
&& make clean && make linux \
|
||||
&& cd ../src \
|
||||
&& source /djgpp/setenv \
|
||||
&& ./configur.sh djgpp \
|
||||
&& sed -i 's/i586/i386/g' djgpp.mak \
|
||||
&& wget https://gist.github.com/Neo-Desktop/ad26e888d64b22a59c743ab4e21ac186/raw/c9a73e1eb75ba8857883ac5c08691d2fe5b82594/djgpp.err -O ../inc/sys/djgpp.err \
|
||||
&& wget https://gist.github.com/Neo-Desktop/ad26e888d64b22a59c743ab4e21ac186/raw/c9a73e1eb75ba8857883ac5c08691d2fe5b82594/syserr.c -O build/djgpp/syserr.c \
|
||||
&& make -f djgpp.mak \
|
||||
&& ln -s /djgpp/watt32/lib/libwatt.a /djgpp/lib
|
||||
|
||||
# Stage 4: compile OpenSSL for djgpp-i386/watt32
|
||||
FROM watt32 as openssl
|
||||
WORKDIR /tmp
|
||||
WORKDIR /
|
||||
|
||||
ENV CC=/djgpp/bin/i586-pc-msdosdjgpp-gcc CXX=/djgpp/bin/i586-pc-msdosdjgpp-g++ CMAKE_FIND_ROOT_PATH=/djgpp
|
||||
|
||||
# Stage 2: setup djgpp
|
||||
RUN wget https://github.com/andrewwutw/build-djgpp/releases/download/v3.4/djgpp-linux64-gcc1220.tar.bz2 \
|
||||
&& tar xjf djgpp-linux64-gcc1220.tar.bz2 \
|
||||
&& rm -rf djgpp-linux64-gcc1220.tar.bz2
|
||||
|
||||
# Stage 3: compile UMSKT
|
||||
FROM djgpp as build
|
||||
SHELL ["/bin/bash", "-c"]
|
||||
RUN git clone https://github.com/openssl/openssl.git openssl \
|
||||
&& cd openssl \
|
||||
&& git checkout openssl-3.1.1 \
|
||||
&& source /djgpp/setenv \
|
||||
&& wget https://gist.github.com/Neo-Desktop/ad26e888d64b22a59c743ab4e21ac186/raw/c9a73e1eb75ba8857883ac5c08691d2fe5b82594/50-djgpp.conf.patch -O Configurations/50-djgpp.conf.patch \
|
||||
&& git apply Configurations/50-djgpp.conf.patch \
|
||||
&& ./Configure no-threads -DOPENSSL_DEV_NO_ATOMICS --prefix=/djgpp DJGPP \
|
||||
&& make && make install
|
||||
|
||||
# Stage 5: compile UMSKT
|
||||
FROM openssl as build
|
||||
|
||||
WORKDIR /src
|
||||
COPY . /src
|
||||
|
||||
ENV CC=/djgpp/bin/i386-pc-msdosdjgpp-gcc CXX=/djgpp/bin/i386-pc-msdosdjgpp-g++ PKG_CONFIG_PATH=/djgpp/lib/pkgconfig VERBOSE=1
|
||||
SHELL ["/bin/bash", "-c"]
|
||||
# Build UMSKT from the local directory
|
||||
RUN mkdir /src/build \
|
||||
&& cd /src/build \
|
||||
&& source /djgpp/setenv \
|
||||
&& cmake -DDJGPP_WATT32=${WATT_ROOT}/lib/libwatt.a .. \
|
||||
&& make
|
||||
&& cmake -DUMSKT_DJGPP_COMPILE=On -DCMAKE_BUILD_TYPE=Release -DCPM_SOURCE_CACHE=`pwd`/.cpm-cache -B build \
|
||||
&& cmake --build build -j 10 --verbose
|
||||
|
||||
CMD ["bash"]
|
||||
|
||||
# Stage 6: Output
|
||||
FROM scratch as output
|
||||
|
||||
COPY --from=build /src/build/umskt.exe /umskt.exe
|
||||
COPY --from=build /src/build/umskt.exe /
|
||||
|
||||
# invoke via
|
||||
# docker build -f Dockerfile.djgpp -o type=tar,dest=umskt-dos.tar .
|
||||
# docker build -f Dockerfile.djgpp -o type=tar,dest=build-djgpp/umskt-dos.tar .
|
||||
|
@ -23,8 +23,8 @@
|
||||
# Stage 1: Install Visual Studio
|
||||
FROM mcr.microsoft.com/dotnet/framework/runtime:4.8.1 as visualstudio
|
||||
# Download and install Build Tools for Visual Studio 2022 for native desktop workload.
|
||||
#ADD https://aka.ms/vs/17/release/vs_buildtools.exe C:\TEMP\vs_buildtools.exe
|
||||
ADD vs_buildtools.exe C:\TEMP\vs_buildtools.exe
|
||||
ADD https://aka.ms/vs/17/release/vs_buildtools.exe C:\TEMP\vs_buildtools.exe
|
||||
#ADD vs_buildtools.exe C:\TEMP\vs_buildtools.exe
|
||||
RUN C:\TEMP\vs_buildtools.exe --quiet --wait --norestart --nocache `
|
||||
--add Microsoft.VisualStudio.Workload.VCTools `
|
||||
--add Microsoft.VisualStudio.Workload.MSBuildTools `
|
||||
@ -40,26 +40,15 @@ RUN ["powershell.exe", "-NoLogo", "-ExecutionPolicy", "Bypass", "[System.Net.Ser
|
||||
RUN ["powershell.exe", "-NoLogo", "-ExecutionPolicy", "Bypass", "choco feature enable -n allowGlobalConfirmation"]
|
||||
RUN ["powershell.exe", "-NoLogo", "-ExecutionPolicy", "Bypass", "choco install git --params \"'/GitAndUnixToolsOnPath /WindowsTerminal /NoShellIntegration /NoGuiHereIntegration /NoShellHereIntegration /NoCredentialManager /SChannel'\""]
|
||||
|
||||
#Install OpenSSL 32bit 3.1.1
|
||||
#ADD https://slproweb.com/download/Win32OpenSSL-3_1_1.msi C:\TEMP\Win32OpenSSL-3_1_1.msi
|
||||
ADD Win32OpenSSL-3_1_1.msi C:\TEMP\Win32OpenSSL-3_1_1.msi
|
||||
RUN msiexec /i C:\TEMP\Win32OpenSSL-3_1_1.msi /quiet /qn /norestart
|
||||
|
||||
#Install OpenSSL 64bit 3.1.1
|
||||
#ADD https://slproweb.com/download/Win64OpenSSL-3_1_1.msi C:\TEMP\Win64OpenSSL-3_1_1.msi
|
||||
ADD Win64OpenSSL-3_1_1.msi C:\TEMP\Win64OpenSSL-3_1_1.msi
|
||||
RUN msiexec /i C:\TEMP\Win64OpenSSL-3_1_1.msi /quiet /qn /norestart
|
||||
|
||||
# Stage 3: Build the 32-bit version of UMSKT
|
||||
FROM prereqisites as Build32
|
||||
WORKDIR C:\umskt\
|
||||
COPY . C:\umskt\
|
||||
|
||||
RUN C:\BuildTools\Common7\Tools\VsDevCmd.bat && `
|
||||
mkdir C:\umskt\build && `
|
||||
cd C:\umskt\build && `
|
||||
cmake -DMSVC_MSDOS_STUB:string=..\umskt.exe .. -G "Visual Studio 17 2022" -A "Win32" -T v141_xp && `
|
||||
msbuild ALL_BUILD.vcxproj /P:Configuration=Release
|
||||
mkdir C:\umskt\build && cd C:\umskt && `
|
||||
cmake -B build -DCPM_SOURCE_CACHE=../.cpm-cache -DUMSKT_MSVC_WINXP=On -DCMAKE_BUILD_TYPE=Release -DMSVC_MSDOS_STUB=..\umskt.exe -G "Visual Studio 17 2022" -A "Win32" -T v141_xp && `
|
||||
cmake --build build --config Release -j 10
|
||||
|
||||
# Stage 4: Build the 64-bit version of UMSKT
|
||||
FROM prereqisites as Build64
|
||||
@ -67,12 +56,10 @@ FROM prereqisites as Build64
|
||||
WORKDIR C:\umskt\
|
||||
COPY . C:\umskt\
|
||||
|
||||
ENV OPENSSL_ROOT_DIR="C:\Program Files\OpenSSL-Win64"
|
||||
RUN C:\BuildTools\Common7\Tools\VsDevCmd.bat && `
|
||||
mkdir C:\umskt\build && `
|
||||
cd C:\umskt\build && `
|
||||
cmake .. && `
|
||||
msbuild ALL_BUILD.vcxproj /P:Configuration=Release
|
||||
cd C:\umskt && `
|
||||
cmake -B build -DCPM_SOURCE_CACHE=../.cpm-cache -DCMAKE_BUILD_TYPE=Release && `
|
||||
cmake --build build --config Release -j 10
|
||||
|
||||
# Stage 5: Copy binaries to an output/runtime image
|
||||
FROM mcr.microsoft.com/dotnet/framework/runtime:4.8.1 as output
|
||||
|
@ -57,13 +57,9 @@ In light of the recent exponential interest in this project I've decided to put
|
||||
|
||||
* **Note:** Before continuing, please ensure you have the `umskt` executable extracted and on UNIX-like systems, have execution permissions (`chmod +x umskt`).
|
||||
|
||||
#### 2. Install OpenSSL 3.1.2.
|
||||
For Windows, click [here](https://slproweb.com/products/Win32OpenSSL.html) and choose the right version. For other operating systems, consult your package manager.
|
||||
*Note: This only applies if the build you download has OpenSSL embedded (static library) or not. You can usually tell if the download size is measured in KB or MB. If it's MB, you don't need this.*
|
||||
#### 2. Run `umskt` to generate a key, or add `--help` or `-h` to see more options.
|
||||
|
||||
#### 3. Run `umskt` to generate a key, or add `--help` or `-h` to see more options.
|
||||
|
||||
#### 4. *(Activation step for `Retail` and `OEM` only)*
|
||||
#### 3. *(Activation step for `Retail` and `OEM` only)*
|
||||
* After installation, you will be prompted to activate Windows.
|
||||
|
||||
|
||||
|
122
keys.json
122
keys.json
@ -39,14 +39,20 @@
|
||||
"WIN95": {
|
||||
"meta": {
|
||||
"type": "PIDGEN2",
|
||||
"tags": "windows"
|
||||
"tags": [
|
||||
"windows",
|
||||
"legacyoempid"
|
||||
]
|
||||
},
|
||||
"name": "Windows 95 (all)"
|
||||
},
|
||||
"WINNT": {
|
||||
"meta": {
|
||||
"type": "PIDGEN2",
|
||||
"tags": "windows"
|
||||
"tags": [
|
||||
"windows",
|
||||
"legacyoempid"
|
||||
]
|
||||
},
|
||||
"name": "Windows NT (all)"
|
||||
},
|
||||
@ -54,7 +60,8 @@
|
||||
"meta": {
|
||||
"type": "PIDGEN3",
|
||||
"tags": [
|
||||
"windows"
|
||||
"windows",
|
||||
"legacyoempid"
|
||||
]
|
||||
},
|
||||
"name": "Windows 98 (all versions)",
|
||||
@ -67,7 +74,8 @@
|
||||
"meta": {
|
||||
"type": "PIDGEN3",
|
||||
"tags": [
|
||||
"office"
|
||||
"office",
|
||||
"legacyoempid"
|
||||
]
|
||||
},
|
||||
"name": "Office 2000 (all versions)",
|
||||
@ -121,7 +129,8 @@
|
||||
"type": "PIDGEN3",
|
||||
"default": "PRO",
|
||||
"tags": [
|
||||
"windows"
|
||||
"windows",
|
||||
"legacyoempid"
|
||||
]
|
||||
},
|
||||
"name": "Windows 2000",
|
||||
@ -159,7 +168,8 @@
|
||||
"meta": {
|
||||
"type": "PIDGEN3",
|
||||
"tags": [
|
||||
"windows"
|
||||
"windows",
|
||||
"legacypid"
|
||||
]
|
||||
},
|
||||
"name": "Windows ME",
|
||||
@ -283,7 +293,7 @@
|
||||
"WINXP": {
|
||||
"meta": {
|
||||
"type": "PIDGEN3",
|
||||
"default": "PROVLK",
|
||||
"default": "VLK",
|
||||
"tags": [
|
||||
"windows",
|
||||
"xpbrand"
|
||||
@ -463,17 +473,56 @@
|
||||
"BINK": [
|
||||
"2C",
|
||||
"2D"
|
||||
]
|
||||
],
|
||||
"DPC": {
|
||||
"2C": [
|
||||
{
|
||||
"min": 5,
|
||||
"max": 85,
|
||||
"isEvaluation": false
|
||||
},
|
||||
{
|
||||
"min": 337,
|
||||
"max": 359,
|
||||
"isEvaluation": false
|
||||
},
|
||||
{
|
||||
"min": 755,
|
||||
"max": 779,
|
||||
"isEvaluation": false
|
||||
},
|
||||
{
|
||||
"min": 785,
|
||||
"max": 789,
|
||||
"isEvaluation": false
|
||||
}
|
||||
],
|
||||
"2D": [
|
||||
{
|
||||
"min": 119,
|
||||
"max": 119,
|
||||
"isEvaluation": false
|
||||
},
|
||||
{
|
||||
"min": 120,
|
||||
"max": 169,
|
||||
"isEvaluation": false
|
||||
},
|
||||
{
|
||||
"min": 400,
|
||||
"max": 699,
|
||||
"isEvaluation": false
|
||||
},
|
||||
{
|
||||
"min": 170,
|
||||
"max": 269,
|
||||
"isEvaluation": false
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"PROK": {
|
||||
"name": "Professional K",
|
||||
"BINK": [
|
||||
"30",
|
||||
"31"
|
||||
]
|
||||
},
|
||||
"PROVLK": {
|
||||
"name": "Professional VLK",
|
||||
"VLK": {
|
||||
"name": "Home/Professional VLK",
|
||||
"BINK": [
|
||||
"2E",
|
||||
"2F"
|
||||
@ -484,16 +533,6 @@
|
||||
"min": 640,
|
||||
"max": 699,
|
||||
"isEvaluation": false
|
||||
},
|
||||
{
|
||||
"min": 700,
|
||||
"max": 701,
|
||||
"isEvaluation": false
|
||||
},
|
||||
{
|
||||
"min": 704,
|
||||
"max": 705,
|
||||
"isEvaluation": false
|
||||
}
|
||||
]
|
||||
},
|
||||
@ -673,6 +712,20 @@
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"CNOEMHOME": {
|
||||
"name": "[CN] OEM Home",
|
||||
"BINK": [
|
||||
"30",
|
||||
"31"
|
||||
]
|
||||
},
|
||||
"CNOEMPRO": {
|
||||
"name": "[CN] OEM Professional",
|
||||
"BINK": [
|
||||
"32",
|
||||
"33"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -1182,21 +1235,6 @@
|
||||
"y": "11647588982042777999933885074728841323429055317640349743317690400085264609368266409172384083304384956740124856614996"
|
||||
}
|
||||
},
|
||||
"0B": {
|
||||
"a": "1",
|
||||
"b": "0",
|
||||
"g": {
|
||||
"x": "17272533675023793624680016937607161394427776688401278127884215858369066406365237833207419170117031265147050748737186",
|
||||
"y": "10897684556651576571671151674586120690608236542740270859915076272932083320838022698730208293779451126638581586588925"
|
||||
},
|
||||
"n": "44682719955829289",
|
||||
"p": "31123778862031392435299439090755153401162704597024288571183830527113563344679315725116915983118187065183839828632113",
|
||||
"priv": "30177475288172038",
|
||||
"pub": {
|
||||
"x": "10584120526089473026246191383792758367144927589909587205278073830223938861208553884400816982485323081066790399437204",
|
||||
"y": "19710761542152200618172612283139324015316083022563473705358032993141026289202915973780473937312193485361804450068338"
|
||||
}
|
||||
},
|
||||
"0C": {
|
||||
"a": "1",
|
||||
"b": "0",
|
||||
|
432
src/cli.cpp
432
src/cli.cpp
@ -1,432 +0,0 @@
|
||||
/**
|
||||
* This file is a part of the UMSKT Project
|
||||
*
|
||||
* Copyleft (C) 2019-2024 UMSKT Contributors (et.al.)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @FileCreated by Andrew on 01/06/2023
|
||||
* @Maintainer Neo
|
||||
*/
|
||||
|
||||
#include "cli.h"
|
||||
|
||||
// define static storage
|
||||
Options CLI::options;
|
||||
json CLI::keys;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param argcIn
|
||||
* @param argvIn
|
||||
* @return exit status (where success is 0)
|
||||
*/
|
||||
BYTE CLI::Init(int argcIn, char **argvIn)
|
||||
{
|
||||
// set default options
|
||||
options = {argcIn, argvIn, "2E", "", "", "", "", "", "WINXP", "PROVLK", 0,
|
||||
0, 1, false, false, false, false, false, false, false, PIDGEN_3, STATE_PIDGEN_GENERATE};
|
||||
|
||||
SetHelpText();
|
||||
|
||||
BOOL success = parseCommandLine();
|
||||
if (!success)
|
||||
{
|
||||
return options.error;
|
||||
}
|
||||
|
||||
// if we displayed help, without an error
|
||||
// return success
|
||||
if (options.help)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
success = processOptions();
|
||||
if (!success)
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param filename
|
||||
* @return success
|
||||
*/
|
||||
BOOL CLI::loadJSON(const fs::path &filename)
|
||||
{
|
||||
if (filename.empty())
|
||||
{
|
||||
if (options.verbose)
|
||||
{
|
||||
fmt::print("Loading internal keys file\n");
|
||||
}
|
||||
|
||||
auto retval = loadEmbeddedJSON();
|
||||
|
||||
if (retval && options.verbose)
|
||||
{
|
||||
fmt::print("Loaded internal keys file successfully\n\n");
|
||||
}
|
||||
else if (!retval)
|
||||
{
|
||||
fmt::print("Error loading internal keys file...\n\n");
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
if (!fs::exists(filename))
|
||||
{
|
||||
fmt::print("ERROR: File {} does not exist\n", filename.string());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (options.verbose)
|
||||
{
|
||||
fmt::print("Loading keys file {}\n", options.keysFilename);
|
||||
}
|
||||
|
||||
std::ifstream f(filename);
|
||||
try
|
||||
{
|
||||
keys = json::parse(f, nullptr, false, false);
|
||||
}
|
||||
catch (const json::exception &e)
|
||||
{
|
||||
fmt::print("ERROR: Exception thrown while parsing {}: {}\n", filename.string(), e.what());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (keys.is_discarded())
|
||||
{
|
||||
fmt::print("ERROR: Unable to parse keys from {}\n", filename.string());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (options.verbose)
|
||||
{
|
||||
fmt::print("Loaded keys from {} successfully\n", options.keysFilename);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param pid
|
||||
*/
|
||||
void CLI::printID(DWORD *pid)
|
||||
{
|
||||
char raw[12], b[6], c[8];
|
||||
char i, digit = 0;
|
||||
|
||||
// Convert PID to ascii-number (=raw)
|
||||
snprintf(raw, sizeof(raw), "%09lu", pid[0]);
|
||||
|
||||
// Make b-part {640-....}
|
||||
_strncpy(b, 6, &raw[0], 3);
|
||||
b[3] = 0;
|
||||
|
||||
// Make c-part {...-123456X...}
|
||||
_strcpy(c, &raw[3]);
|
||||
|
||||
// Make checksum digit-part {...56X-}
|
||||
assert(strlen(c) == 6);
|
||||
for (i = 0; i < 6; i++)
|
||||
{
|
||||
digit += c[i] - '0'; // Sum digits
|
||||
}
|
||||
|
||||
digit %= 7;
|
||||
if (digit > 0)
|
||||
{
|
||||
digit = 7 - digit;
|
||||
}
|
||||
|
||||
c[6] = digit + '0';
|
||||
c[7] = 0;
|
||||
|
||||
DWORD binkid;
|
||||
_sscanf(options.binkID.c_str(), "%lx", &binkid);
|
||||
binkid /= 2;
|
||||
|
||||
fmt::print("> Product ID: PPPPP-{}-{}-{}xxx\n", b, c, binkid);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param pidgen3
|
||||
* @return success
|
||||
*/
|
||||
BOOL CLI::InitPIDGEN3(PIDGEN3 &pidgen3)
|
||||
{
|
||||
const char *BINKID = &options.binkID[0];
|
||||
auto bink = keys["BINK"][BINKID];
|
||||
|
||||
if (options.verbose)
|
||||
{
|
||||
fmt::print("{:->80}\n", "");
|
||||
fmt::print("Loaded the following elliptic curve parameters: BINK[{}]\n", BINKID);
|
||||
fmt::print("{:->80}\n", "");
|
||||
fmt::print("{:>6}: {}\n", "P", bink["p"]);
|
||||
fmt::print("{:>6}: {}\n", "a", bink["a"]);
|
||||
fmt::print("{:>6}: {}\n", "b", bink["b"]);
|
||||
fmt::print("{:>6}: [{},\n{:>9}{}]\n", "G[x,y]", bink["g"]["x"], "", bink["g"]["y"]);
|
||||
fmt::print("{:>6}: [{},\n{:>9}{}]\n", "K[x,y]", bink["pub"]["x"], "", bink["pub"]["y"]);
|
||||
fmt::print("{:>6}: {}\n", "n", bink["n"]);
|
||||
fmt::print("{:>6}: {}\n", "k", bink["priv"]);
|
||||
fmt::print("\n");
|
||||
}
|
||||
|
||||
pidgen3.LoadEllipticCurve(bink["p"], bink["a"], bink["b"], bink["g"]["x"], bink["g"]["y"], bink["pub"]["x"],
|
||||
bink["pub"]["y"], bink["n"], bink["priv"]);
|
||||
|
||||
if (options.state != STATE_PIDGEN_GENERATE)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
pidgen3.info.setChannelID(options.channelID);
|
||||
if (options.verbose)
|
||||
{
|
||||
fmt::print("> Channel ID: {:03d}\n", options.channelID);
|
||||
}
|
||||
|
||||
if (options.serialSet)
|
||||
{
|
||||
pidgen3.info.setSerial(options.serial);
|
||||
if (options.verbose)
|
||||
{
|
||||
fmt::print("> Serial {:#09d}\n", options.serial);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param confid
|
||||
* @return success
|
||||
*/
|
||||
BOOL CLI::InitConfirmationID(ConfirmationID &confid)
|
||||
{
|
||||
auto ctx = BN_CTX_new();
|
||||
BIGNUM *pkey = BN_CTX_get(ctx), *nonresidue = BN_CTX_get(ctx), *modulous = BN_CTX_get(ctx);
|
||||
BIGNUM *fvals[6];
|
||||
QWORD fvalsq[6];
|
||||
|
||||
if (!keys["products"][options.productCode].contains("meta") ||
|
||||
!keys["products"][options.productCode]["meta"].contains("activation"))
|
||||
{
|
||||
fmt::print("ERROR: product flavour {} does not have known activation values", options.productCode);
|
||||
return false;
|
||||
}
|
||||
|
||||
auto meta = keys["products"][options.productCode]["meta"]["activation"];
|
||||
|
||||
if (!keys["activation"].contains(meta["flavour"]))
|
||||
{
|
||||
fmt::print("ERROR: {} is an unknown activation flavour", meta["flavour"]);
|
||||
return false;
|
||||
}
|
||||
|
||||
auto flavour = keys["activation"][meta["flavour"]];
|
||||
|
||||
if (options.verbose)
|
||||
{
|
||||
fmt::print("{:->80}\n", "");
|
||||
fmt::print("Loaded the following hyperelliptic curve parameters: activation[{}]\n", meta["flavour"]);
|
||||
fmt::print("{:->80}\n", "");
|
||||
fmt::print("{:>7}: {}\n", "name", flavour["name"]);
|
||||
fmt::print("{:>7}: {}\n", "version", meta["version"]);
|
||||
fmt::print("{:>7}: {}\n", "Fp", flavour["p"]);
|
||||
fmt::print("{:>7}: [{}, {}, {},\n{:>10}{}, {}, {}]\n", "F[]", flavour["x"]["0"], flavour["x"]["1"],
|
||||
flavour["x"]["2"], "", flavour["x"]["3"], flavour["x"]["4"], flavour["x"]["5"]);
|
||||
fmt::print("{:>7}: {}\n", "INV", flavour["quotient"]);
|
||||
fmt::print("{:>7}: {}\n", "mqnr", flavour["non_residue"]);
|
||||
fmt::print("{:>7}: {}\n", "k", flavour["priv"]);
|
||||
fmt::print("{:>7}: {}\n", "IID", flavour["iid_key"]);
|
||||
fmt::print("\n");
|
||||
}
|
||||
|
||||
for (BYTE i = 0; i < 6; i++)
|
||||
{
|
||||
fvals[i] = BN_CTX_get(ctx);
|
||||
auto xval = flavour["x"][fmt::format("{}", i)].get<std::string>();
|
||||
BN_dec2bn(&fvals[i], xval.c_str());
|
||||
UMSKT::BN_bn2lebin(fvals[i], (unsigned char *)&fvalsq[i], sizeof(*fvalsq));
|
||||
}
|
||||
|
||||
// confid.LoadHyperellipticCurve(fvals, );
|
||||
|
||||
BN_CTX_free(ctx);
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return success
|
||||
*/
|
||||
BOOL CLI::PIDGENGenerate()
|
||||
{
|
||||
// TODO:
|
||||
// if options.pidgen2generate
|
||||
// return pidgen2generate
|
||||
// otherwise...
|
||||
|
||||
const char *BINKID = &options.binkID[0];
|
||||
auto bink = keys["BINK"][BINKID];
|
||||
|
||||
std::string key;
|
||||
bink["p"].get_to(key);
|
||||
|
||||
if (PIDGEN3::checkFieldStrIsBink1998(key))
|
||||
{
|
||||
if (options.verbose)
|
||||
{
|
||||
fmt::print("Detected a BINK1998 key\n");
|
||||
}
|
||||
|
||||
auto bink1998 = BINK1998();
|
||||
InitPIDGEN3(bink1998);
|
||||
return BINK1998Generate(bink1998);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (options.verbose)
|
||||
{
|
||||
fmt::print("Detected a BINK2002 key\n");
|
||||
}
|
||||
auto bink2002 = BINK2002();
|
||||
InitPIDGEN3(bink2002);
|
||||
return BINK2002Generate(bink2002);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return isValid
|
||||
*/
|
||||
BOOL CLI::PIDGENValidate()
|
||||
{
|
||||
// TODO:
|
||||
// if options.pidgen2validate
|
||||
// return pidgen2validate
|
||||
// otherwise...
|
||||
|
||||
const char *BINKID = &options.binkID[0];
|
||||
auto bink = keys["BINK"][BINKID];
|
||||
|
||||
std::string key;
|
||||
bink["p"].get_to(key);
|
||||
|
||||
if (PIDGEN3::checkFieldStrIsBink1998(key))
|
||||
{
|
||||
if (options.verbose)
|
||||
{
|
||||
fmt::print("Detected a BINK1998 key\n");
|
||||
}
|
||||
auto bink1998 = BINK1998();
|
||||
InitPIDGEN3(bink1998);
|
||||
return BINK1998Validate(bink1998);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (options.verbose)
|
||||
{
|
||||
fmt::print("Detected a BINK2002 key\n");
|
||||
}
|
||||
auto bink2002 = BINK2002();
|
||||
InitPIDGEN3(bink2002);
|
||||
return BINK2002Validate(bink2002);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process application state
|
||||
*
|
||||
* @return application status code
|
||||
*/
|
||||
int CLI::Run()
|
||||
{
|
||||
/**
|
||||
* TODO: we should be checking if the system's pseudorandom facilities work
|
||||
* before attempting generation, validation does not require entropy
|
||||
*/
|
||||
switch (options.state)
|
||||
{
|
||||
case STATE_PIDGEN_GENERATE:
|
||||
return PIDGENGenerate();
|
||||
|
||||
case STATE_PIDGEN_VALIDATE:
|
||||
return PIDGENValidate();
|
||||
|
||||
case STATE_CONFIRMATION_ID:
|
||||
return ConfirmationIDGenerate();
|
||||
|
||||
default:
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints a product key to stdout
|
||||
*
|
||||
* @param pk std::string to print
|
||||
*/
|
||||
void CLI::printKey(std::string &pk)
|
||||
{
|
||||
assert(pk.length() >= PK_LENGTH);
|
||||
|
||||
fmt::print("{}-{}-{}-{}-{}", pk.substr(0, 5), pk.substr(5, 5), pk.substr(10, 5), pk.substr(15, 5),
|
||||
pk.substr(20, 5));
|
||||
}
|
||||
|
||||
/**
|
||||
* std::BinaryOperation compatible accumulator for validating/stripping an input string against the PIDGEN3 charset
|
||||
* this can be moved to the PIDGEN3 at a later date
|
||||
*
|
||||
* @param accumulator
|
||||
* @param currentChar
|
||||
* @return
|
||||
*/
|
||||
std::string CLI::validateInputKeyCharset(std::string &accumulator, char currentChar)
|
||||
{
|
||||
char cchar = ::toupper(currentChar);
|
||||
if (std::find(std::begin(PIDGEN3::pKeyCharset), std::end(PIDGEN3::pKeyCharset), cchar) !=
|
||||
std::end(PIDGEN3::pKeyCharset))
|
||||
{
|
||||
accumulator.push_back(cchar);
|
||||
}
|
||||
return accumulator;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param in_key
|
||||
* @param out_key
|
||||
* @return
|
||||
*/
|
||||
BOOL CLI::stripKey(const std::string &in_key, std::string &out_key)
|
||||
{
|
||||
// copy out the product key stripping out extraneous characters
|
||||
out_key = std::accumulate(in_key.begin(), in_key.end(), std::string(), validateInputKeyCharset);
|
||||
|
||||
// only return true if we've handled exactly PK_LENGTH chars
|
||||
return (out_key.length() == PK_LENGTH);
|
||||
}
|
159
src/cli/cli.cpp
Normal file
159
src/cli/cli.cpp
Normal file
@ -0,0 +1,159 @@
|
||||
/**
|
||||
* This file is a part of the UMSKT Project
|
||||
*
|
||||
* Copyleft (C) 2019-2024 UMSKT Contributors (et.al.)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @FileCreated by Andrew on 01/06/2023
|
||||
* @Maintainer Neo
|
||||
*/
|
||||
|
||||
#include "cli.h"
|
||||
|
||||
// define static storage
|
||||
CLI::Options CLI::options;
|
||||
json CLI::keys;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param argcIn
|
||||
* @param argvIn
|
||||
* @return exit status (where success is 0)
|
||||
*/
|
||||
BYTE CLI::Init(int argcIn, char **argvIn)
|
||||
{
|
||||
// set default options
|
||||
options.argc = argcIn;
|
||||
options.argv = argvIn;
|
||||
options.binkID = "2E";
|
||||
options.productCode = "WINXP";
|
||||
options.productFlavour = "VLK";
|
||||
options.numKeys = 1;
|
||||
options.pidgenversion = Options::PIDGEN_VERSION::PIDGEN_3;
|
||||
options.state = Options::APPLICATION_STATE::STATE_PIDGEN_GENERATE;
|
||||
|
||||
SetHelpText();
|
||||
|
||||
BOOL success = parseCommandLine();
|
||||
if (!success)
|
||||
{
|
||||
return options.error;
|
||||
}
|
||||
|
||||
// if we displayed help, without an error
|
||||
// return success
|
||||
if (options.help)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
success = processOptions();
|
||||
if (!success)
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param filename
|
||||
* @return success
|
||||
*/
|
||||
BOOL CLI::loadJSON(const fs::path &filename)
|
||||
{
|
||||
if (filename.empty())
|
||||
{
|
||||
if (options.verbose)
|
||||
{
|
||||
fmt::print("Loading internal keys file\n");
|
||||
}
|
||||
|
||||
auto retval = loadEmbeddedJSON();
|
||||
|
||||
if (retval && options.verbose)
|
||||
{
|
||||
fmt::print("Loaded internal keys file successfully\n\n");
|
||||
}
|
||||
else if (!retval)
|
||||
{
|
||||
fmt::print("Error loading internal keys file...\n\n");
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
if (!fs::exists(filename))
|
||||
{
|
||||
fmt::print("ERROR: File {} does not exist\n", filename.string());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (options.verbose)
|
||||
{
|
||||
fmt::print("Loading keys file: {}\n", options.keysFilename);
|
||||
}
|
||||
|
||||
std::ifstream f(filename);
|
||||
try
|
||||
{
|
||||
keys = json::parse(f, nullptr, false, false);
|
||||
}
|
||||
catch (const json::exception &e)
|
||||
{
|
||||
fmt::print("ERROR: Exception thrown while parsing {}: {}\n", filename.string(), e.what());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (keys.is_discarded())
|
||||
{
|
||||
fmt::print("ERROR: Unable to parse keys from: {}\n", filename.string());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (options.verbose)
|
||||
{
|
||||
fmt::print("Loaded keys from \"{}\" successfully\n", options.keysFilename);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process application state
|
||||
*
|
||||
* @return application status code
|
||||
*/
|
||||
int CLI::Run()
|
||||
{
|
||||
/**
|
||||
* TODO: we should be checking if the system's pseudorandom facilities work
|
||||
* before attempting generation, validation does not require entropy
|
||||
*/
|
||||
switch (options.state)
|
||||
{
|
||||
case Options::APPLICATION_STATE::STATE_PIDGEN_GENERATE:
|
||||
return PIDGenerate();
|
||||
|
||||
case Options::APPLICATION_STATE::STATE_PIDGEN_VALIDATE:
|
||||
return PIDValidate();
|
||||
|
||||
case Options::APPLICATION_STATE::STATE_CONFIRMATION_ID:
|
||||
return ConfirmationIDGenerate();
|
||||
|
||||
default:
|
||||
return 1;
|
||||
}
|
||||
}
|
@ -23,18 +23,14 @@
|
||||
#ifndef UMSKT_CLI_H
|
||||
#define UMSKT_CLI_H
|
||||
|
||||
#include "typedefs.h"
|
||||
#include <libumskt/libumskt.h>
|
||||
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include <fmt/color.h>
|
||||
#include <fmt/core.h>
|
||||
#include <fmt/ostream.h>
|
||||
#include <fmt/ranges.h>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
@ -42,7 +38,7 @@ using json = nlohmann::json;
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
// fmt <-> json linkage
|
||||
template <> struct fmt::formatter<json> : ostream_formatter
|
||||
template <> struct fmt::formatter<json> : formatter<string_view>
|
||||
{
|
||||
auto format(const json &j, format_context &ctx) const
|
||||
{
|
||||
@ -52,85 +48,72 @@ template <> struct fmt::formatter<json> : ostream_formatter
|
||||
}
|
||||
else
|
||||
{
|
||||
return basic_ostream_formatter<char>::format(j, ctx);
|
||||
std::stringstream s;
|
||||
s << j;
|
||||
return formatter<string_view>::format(s.str(), ctx);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#include "../libumskt/confid/confid.h"
|
||||
#include "../libumskt/libumskt.h"
|
||||
#include "../libumskt/pidgen2/PIDGEN2.h"
|
||||
#include "../libumskt/pidgen3/BINK1998.h"
|
||||
#include "../libumskt/pidgen3/BINK2002.h"
|
||||
#include "../libumskt/pidgen3/PIDGEN3.h"
|
||||
#include "help.h"
|
||||
#include "libumskt/confid/confid.h"
|
||||
#include "libumskt/libumskt.h"
|
||||
#include "libumskt/pidgen2/PIDGEN2.h"
|
||||
#include "libumskt/pidgen3/BINK1998.h"
|
||||
#include "libumskt/pidgen3/BINK2002.h"
|
||||
#include "libumskt/pidgen3/PIDGEN3.h"
|
||||
|
||||
#ifndef UMSKTCLI_VERSION_STRING
|
||||
#define UMSKTCLI_VERSION_STRING "unknown version-dirty"
|
||||
#endif
|
||||
|
||||
enum APPLICATION_STATE
|
||||
{
|
||||
STATE_PIDGEN_GENERATE,
|
||||
STATE_PIDGEN_VALIDATE,
|
||||
STATE_CONFIRMATION_ID
|
||||
};
|
||||
|
||||
enum PIDGEN_VERSION
|
||||
{
|
||||
PIDGEN_2 = 2,
|
||||
PIDGEN_3 = 3,
|
||||
};
|
||||
|
||||
struct Options
|
||||
{
|
||||
int argc;
|
||||
char **argv;
|
||||
|
||||
std::string binkID;
|
||||
std::string keysFilename;
|
||||
std::string installationID;
|
||||
std::string keyToCheck;
|
||||
std::string productID;
|
||||
std::string authInfo;
|
||||
std::string productCode;
|
||||
std::string productFlavour;
|
||||
|
||||
DWORD channelID;
|
||||
DWORD serial;
|
||||
DWORD numKeys;
|
||||
|
||||
BOOL oem;
|
||||
BOOL upgrade;
|
||||
BOOL serialSet;
|
||||
BOOL verbose;
|
||||
BOOL help;
|
||||
BOOL error;
|
||||
BOOL list;
|
||||
|
||||
struct Meta
|
||||
{
|
||||
std::string type;
|
||||
std::vector<std::string> tags;
|
||||
struct Activation
|
||||
{
|
||||
std::string flavour;
|
||||
int version;
|
||||
};
|
||||
};
|
||||
|
||||
PIDGEN3::KeyInfo info;
|
||||
|
||||
PIDGEN_VERSION pidgenversion;
|
||||
APPLICATION_STATE state;
|
||||
};
|
||||
|
||||
class CLI
|
||||
{
|
||||
std::string pKey;
|
||||
DWORD count, total, iBinkID;
|
||||
DWORD32 count, total, iBinkID;
|
||||
|
||||
static Options options;
|
||||
struct Options
|
||||
{
|
||||
int argc;
|
||||
char **argv;
|
||||
|
||||
std::string binkID;
|
||||
std::string keysFilename;
|
||||
std::string installationID;
|
||||
std::string keyToCheck;
|
||||
std::string productID;
|
||||
std::string authInfo;
|
||||
std::string productCode;
|
||||
std::string productFlavour;
|
||||
|
||||
Integer channelID;
|
||||
Integer serial;
|
||||
DWORD32 numKeys;
|
||||
|
||||
BOOL oem;
|
||||
BOOL upgrade;
|
||||
BOOL verbose;
|
||||
BOOL help;
|
||||
BOOL error;
|
||||
BOOL list;
|
||||
|
||||
PIDGEN3::KeyInfo info;
|
||||
|
||||
enum PIDGEN_VERSION
|
||||
{
|
||||
PIDGEN_2 = 2,
|
||||
PIDGEN_3 = 3,
|
||||
};
|
||||
PIDGEN_VERSION pidgenversion;
|
||||
|
||||
enum APPLICATION_STATE
|
||||
{
|
||||
STATE_PIDGEN_GENERATE,
|
||||
STATE_PIDGEN_VALIDATE,
|
||||
STATE_CONFIRMATION_ID
|
||||
};
|
||||
APPLICATION_STATE state;
|
||||
} static options;
|
||||
|
||||
public:
|
||||
CLI()
|
||||
@ -165,42 +148,24 @@ class CLI
|
||||
static CLIHandlerFunc SetValidateOption;
|
||||
static CLIHandlerFunc SetProductCodeOption;
|
||||
static CLIHandlerFunc SetFlavourOption;
|
||||
static CLIHandlerFunc SetAuthDataOption;
|
||||
|
||||
static BOOL parseCommandLine();
|
||||
static BOOL processOptions();
|
||||
static void printID(DWORD *pid);
|
||||
static void printKey(std::string &pk);
|
||||
static BOOL stripKey(const std::string &in_key, std::string &out_key);
|
||||
static std::string validateInputKeyCharset(std::string &accumulator, char currentChar);
|
||||
static BOOL processListCommand();
|
||||
|
||||
BOOL InitPIDGEN3(PIDGEN3 &pidgen3);
|
||||
BOOL InitPIDGEN3(PIDGEN3 *p3);
|
||||
BOOL InitConfirmationID(ConfirmationID &confid);
|
||||
|
||||
BOOL PIDGENGenerate();
|
||||
BOOL PIDGENValidate();
|
||||
BOOL PIDGenerate();
|
||||
BOOL PIDValidate();
|
||||
|
||||
BOOL PIDGEN2Generate(PIDGEN2 &pidgen2);
|
||||
BOOL PIDGEN2Validate(PIDGEN2 &pidgen2);
|
||||
BOOL BINK1998Generate(PIDGEN3 &pidgen3);
|
||||
BOOL BINK1998Validate(PIDGEN3 &pidgen3);
|
||||
BOOL BINK2002Generate(PIDGEN3 &pidgen3);
|
||||
BOOL BINK2002Validate(PIDGEN3 &pidgen3);
|
||||
BOOL PIDGEN2Generate(PIDGEN2 &p2);
|
||||
BOOL PIDGEN2Validate(PIDGEN2 &p2);
|
||||
BOOL PIDGEN3Generate(PIDGEN3 *p3);
|
||||
BOOL PIDGEN3Validate(PIDGEN3 *p3);
|
||||
BOOL ConfirmationIDGenerate();
|
||||
|
||||
INLINE static std::string strtolower(std::string &in)
|
||||
{
|
||||
auto retval = std::string(in);
|
||||
std::transform(retval.begin(), retval.end(), retval.begin(), ::tolower);
|
||||
return retval;
|
||||
}
|
||||
|
||||
INLINE static std::string strtoupper(std::string &in)
|
||||
{
|
||||
auto retval = std::string(in);
|
||||
std::transform(retval.begin(), retval.end(), retval.begin(), ::toupper);
|
||||
return retval;
|
||||
}
|
||||
|
||||
int Run();
|
||||
};
|
||||
|
127
src/cli/confirmationid.cpp
Normal file
127
src/cli/confirmationid.cpp
Normal file
@ -0,0 +1,127 @@
|
||||
/**
|
||||
* This file is a part of the UMSKT Project
|
||||
*
|
||||
* Copyleft (C) 2019-2024 UMSKT Contributors (et.al.)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @FileCreated by Neo on 02/18/2024
|
||||
* @Maintainer Neo
|
||||
*/
|
||||
|
||||
#include "cli.h"
|
||||
|
||||
/**
|
||||
*
|
||||
* @param confid
|
||||
* @return success
|
||||
*/
|
||||
BOOL CLI::InitConfirmationID(ConfirmationID &confid)
|
||||
{
|
||||
if (!keys["products"][options.productCode].contains("meta") ||
|
||||
!keys["products"][options.productCode]["meta"].contains("activation"))
|
||||
{
|
||||
fmt::print("ERROR: product flavour \"{}\" does not have known activation values", options.productCode);
|
||||
return false;
|
||||
}
|
||||
|
||||
auto meta = keys["products"][options.productCode]["meta"]["activation"];
|
||||
|
||||
if (!keys["activation"].contains(meta["flavour"]))
|
||||
{
|
||||
fmt::print("ERROR: \"{}\" is an unknown activation flavour", meta["flavour"]);
|
||||
return false;
|
||||
}
|
||||
|
||||
auto flavour = keys["activation"][meta["flavour"]];
|
||||
|
||||
if (options.verbose)
|
||||
{
|
||||
fmt::print("{:->80}\n", "");
|
||||
fmt::print("Loaded the following hyperelliptic curve parameters: activation[{}]\n", meta["flavour"]);
|
||||
fmt::print("{:->80}\n", "");
|
||||
fmt::print("{:>7}: {}\n", "name", flavour["name"]);
|
||||
fmt::print("{:>7}: {}\n", "version", meta["version"]);
|
||||
fmt::print("{:>7}: {}\n", "Fp", flavour["p"]);
|
||||
fmt::print("{:>7}: [{}, {}, {},\n{:>10}{}, {}, {}]\n", "F[]", flavour["x"]["0"], flavour["x"]["1"],
|
||||
flavour["x"]["2"], "", flavour["x"]["3"], flavour["x"]["4"], flavour["x"]["5"]);
|
||||
fmt::print("{:>7}: {}\n", "INV", flavour["quotient"]);
|
||||
fmt::print("{:>7}: {}\n", "mqnr", flavour["non_residue"]);
|
||||
fmt::print("{:>7}: {}\n", "k", flavour["priv"]);
|
||||
fmt::print("{:>7}: {}\n", "IID", flavour["iid_key"]);
|
||||
fmt::print("\n");
|
||||
}
|
||||
|
||||
confid.LoadHyperellipticCurve(flavour["x"]["0"], flavour["x"]["1"], flavour["x"]["2"], flavour["x"]["3"],
|
||||
flavour["x"]["4"], flavour["x"]["5"], flavour["priv"], flavour["quotient"],
|
||||
flavour["non_residue"], flavour["iid_key"], meta["tags"].contains("xpbrand"),
|
||||
meta["tags"].contains("office"), meta["activation"]["version"]);
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return success
|
||||
*/
|
||||
BOOL CLI::ConfirmationIDGenerate()
|
||||
{
|
||||
auto confid = ConfirmationID();
|
||||
std::string confirmation_id;
|
||||
|
||||
if (!InitConfirmationID(confid))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
DWORD32 err = confid.Generate(options.installationID, confirmation_id, options.productID);
|
||||
|
||||
if (err == SUCCESS)
|
||||
{
|
||||
fmt::print("{}\n", confirmation_id);
|
||||
return true;
|
||||
}
|
||||
|
||||
switch (err)
|
||||
{
|
||||
case ERR_TOO_SHORT:
|
||||
fmt::print("ERROR: Installation ID is too short.\n");
|
||||
break;
|
||||
|
||||
case ERR_TOO_LARGE:
|
||||
fmt::print("ERROR: Installation ID is too long.\n");
|
||||
break;
|
||||
|
||||
case ERR_INVALID_CHARACTER:
|
||||
fmt::print("ERROR: Invalid character in installation ID.\n");
|
||||
break;
|
||||
|
||||
case ERR_INVALID_CHECK_DIGIT:
|
||||
fmt::print("ERROR: Installation ID checksum failed. Please check that it is typed correctly.\n");
|
||||
break;
|
||||
|
||||
case ERR_UNKNOWN_VERSION:
|
||||
fmt::print("ERROR: Unknown installation ID version.\n");
|
||||
break;
|
||||
|
||||
case ERR_UNLUCKY:
|
||||
fmt::print("ERROR: Unable to generate valid confirmation ID.\n");
|
||||
break;
|
||||
|
||||
default:
|
||||
fmt::print("Unknown error occurred during Confirmation ID generation: {}\n", err);
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
@ -37,7 +37,7 @@ void CLI::SetHelpText()
|
||||
helpOptions[OPTION_DEBUG] = {"d", "debug", "enable debug output", false, "", &SetDebugOption};
|
||||
|
||||
helpOptions[OPTION_FILE] = {
|
||||
"F", "file", "(advanced) specify which keys JSON file to load", true, "[embedded file]", &SetFileOption};
|
||||
"", "file", "(advanced) specify which keys JSON file to load", true, "[embedded file]", &SetFileOption};
|
||||
|
||||
helpOptions[OPTION_LIST] = {"l", "list", "list supported products", false, "", &SetListOption};
|
||||
|
||||
@ -52,7 +52,7 @@ void CLI::SetHelpText()
|
||||
true, "1", &SetNumberOption};
|
||||
|
||||
helpOptions[OPTION_ACTIVATIONID] = {
|
||||
"i", "installationID", "(activation only) installation ID used to generate confirmation ID", true,
|
||||
"I", "installationID", "(activation only) installation ID used to generate confirmation ID", true,
|
||||
"", &SetActivationIDOption};
|
||||
|
||||
helpOptions[OPTION_ACTIVATIONPID] = {
|
||||
@ -64,19 +64,19 @@ void CLI::SetHelpText()
|
||||
helpOptions[OPTION_UPGRADE] = {"U", "upgrade", "(PIDGEN 3 only) generate an upgrade key",
|
||||
false, "", &SetUpgradeOption};
|
||||
|
||||
helpOptions[OPTION_BINK] = {"b", "binkID", "(advanced) override which BINK identifier to load",
|
||||
true, "", &SetBINKOption};
|
||||
helpOptions[OPTION_BINK] = {"", "bink", "(advanced) override which BINK identifier to load",
|
||||
true, "", &SetBINKOption};
|
||||
|
||||
helpOptions[OPTION_CHANNELID] = {"c", "channelid", "(advanced) override which product channel to use",
|
||||
true, "", &SetChannelIDOption};
|
||||
helpOptions[OPTION_CHANNELID] = {"", "channel", "(advanced) override which product channel to use",
|
||||
true, "", &SetChannelIDOption};
|
||||
|
||||
helpOptions[OPTION_SERIAL] = {
|
||||
"s", "serial", "(advanced, PIDGEN 2/3 [BINK 1998] only) specify a serial to generate",
|
||||
"", "serial", "(advanced, PIDGEN 2/3 [BINK 1998] only) specify a serial to generate",
|
||||
true, "", &SetSerialOption};
|
||||
|
||||
helpOptions[OPTION_AUTHDATA] = {
|
||||
"a", "authdata", "(advanced, PIDGEN 3 [BINK 2002] only) specify a value for the authentication data field",
|
||||
true, "", nullptr};
|
||||
true, "", &SetAuthDataOption};
|
||||
|
||||
helpOptions[OPTION_VALIDATE] = {
|
||||
"V", "validate", "validate a specified product ID against known BINKs and algorithms",
|
||||
@ -89,7 +89,7 @@ void CLI::SetHelpText()
|
||||
*/
|
||||
BOOL CLI::parseCommandLine()
|
||||
{
|
||||
for (DWORD i = 1; i < options.argc; i++)
|
||||
for (DWORD32 i = 1; i < options.argc; i++)
|
||||
{
|
||||
std::string arg = options.argv[i];
|
||||
|
||||
@ -132,7 +132,7 @@ BOOL CLI::parseCommandLine()
|
||||
continue;
|
||||
}
|
||||
|
||||
auto success = thisOption.handler(1, &nextarg[0]);
|
||||
auto success = thisOption.handler(nextarg);
|
||||
|
||||
if (!success)
|
||||
{
|
||||
@ -155,9 +155,13 @@ BOOL CLI::parseCommandLine()
|
||||
}
|
||||
|
||||
CommandLineParseEnd:
|
||||
if (options.verbose)
|
||||
{
|
||||
fmt::print("\n");
|
||||
}
|
||||
if (options.error)
|
||||
{
|
||||
DisplayErrorMessage(0, nullptr);
|
||||
DisplayErrorMessage("");
|
||||
}
|
||||
return !options.error;
|
||||
}
|
||||
@ -176,126 +180,114 @@ BOOL CLI::processOptions()
|
||||
|
||||
if (options.list)
|
||||
{
|
||||
// the following code is absolutely unhinged
|
||||
// I'm so sorry
|
||||
|
||||
#if defined(__UNICODE__) || defined(__GNUC__)
|
||||
auto *leaf = "\u251C", *last = "\u2514", *line = "\u2500";
|
||||
#else
|
||||
auto *leaf = "\xC3", *last = "\xC0", *line = "\xC4";
|
||||
#endif
|
||||
|
||||
fmt::print("Listing known products and flavours: \n\n");
|
||||
|
||||
fmt::print("* The following product list uses this style of formatting:\n");
|
||||
fmt::print("{}: {} \n", fmt::styled("PRODUCT", fmt::emphasis::bold), "Product name");
|
||||
fmt::print("{}{}{} {}: {} \n", last, line, line, "FLAVOUR", "Flavour name");
|
||||
fmt::print("* Products that require a flavour are noted with {}\n\n",
|
||||
fmt::styled("(no default)", fmt::emphasis::bold));
|
||||
|
||||
for (auto const &i : keys["products"].items())
|
||||
{
|
||||
auto el = i.value();
|
||||
auto containsFlavours = el.contains("flavours");
|
||||
|
||||
fmt::print("{:<9} {} ", fmt::styled(fmt::format("{}:", i.key()), fmt::emphasis::bold), el["name"]);
|
||||
if (el.contains("BINK"))
|
||||
{
|
||||
fmt::print("{}\n", el["BINK"]);
|
||||
}
|
||||
else if (el["meta"].contains("default"))
|
||||
{
|
||||
fmt::print("(default: {} {})\n", fmt::styled(el["meta"]["default"], fmt::emphasis::bold),
|
||||
el["flavours"][el["meta"]["default"]]["BINK"]);
|
||||
}
|
||||
else if (el["meta"]["type"].get<std::string>() == "PIDGEN3")
|
||||
{
|
||||
fmt::print("[{}]\n", el["meta"]["type"]);
|
||||
}
|
||||
else
|
||||
{
|
||||
fmt::print("{}\n", fmt::styled("(no default)", fmt::emphasis::bold));
|
||||
}
|
||||
if (containsFlavours)
|
||||
{
|
||||
auto flavours = el["flavours"];
|
||||
for (auto j = flavours.begin(); j != flavours.end(); j++)
|
||||
{
|
||||
auto el2 = j.value();
|
||||
BOOL isLast = j == --flavours.end();
|
||||
fmt::print("{}{}{} {:<9} {} ", !isLast ? leaf : last, line, line, fmt::format("{}:", j.key()),
|
||||
fmt::format("{} {}", el["name"], el2["name"]));
|
||||
if (el2.contains("meta") && el2["meta"].contains("type"))
|
||||
{
|
||||
fmt::print("[{}]\n", el2["meta"]["type"]);
|
||||
}
|
||||
else
|
||||
{
|
||||
fmt::print("{}\n", el2["BINK"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
fmt::print("\n");
|
||||
}
|
||||
|
||||
return false;
|
||||
return processListCommand();
|
||||
}
|
||||
|
||||
if (options.productCode.empty())
|
||||
{
|
||||
fmt::print("ERROR: product code is required. Exiting...");
|
||||
DisplayHelp(0, nullptr);
|
||||
fmt::print("ERROR: product code is required. Exiting...\n");
|
||||
DisplayHelp("");
|
||||
return false;
|
||||
}
|
||||
|
||||
const char *productCode = &options.productCode[0];
|
||||
if (!keys["products"].contains(productCode))
|
||||
if (!keys["products"].contains(options.productCode))
|
||||
{
|
||||
fmt::print("ERROR: Product {} is unknown", productCode);
|
||||
fmt::print("ERROR: Product \"{}\" is unknown\n", options.productCode);
|
||||
return false;
|
||||
}
|
||||
|
||||
auto product = keys["products"][productCode];
|
||||
auto product = keys["products"][options.productCode];
|
||||
if (options.verbose)
|
||||
{
|
||||
fmt::print("Selecting product: {}\n", productCode);
|
||||
fmt::print("Selecting product: {}\n", options.productCode);
|
||||
}
|
||||
|
||||
json flavour;
|
||||
if (product.contains("flavours"))
|
||||
{
|
||||
flavour = product["flavours"][options.productFlavour];
|
||||
if (options.verbose)
|
||||
// no default flavour, no flavour specified
|
||||
if (!product["meta"].contains("default") && options.productFlavour.empty())
|
||||
{
|
||||
fmt::print("Selecting flavour: {}\n", options.productFlavour);
|
||||
fmt::print("ERROR: Product \"{}\n does not have a default flavour. Please specify a flavour.",
|
||||
options.productCode);
|
||||
return false;
|
||||
}
|
||||
// yes flavour specified, but not found
|
||||
else if (!product["flavours"].contains(options.productFlavour) && !options.productFlavour.empty())
|
||||
{
|
||||
fmt::print("ERROR: Product \"{}\" does not have a flavour named \"{}\"\n", options.productCode,
|
||||
options.productFlavour);
|
||||
return false;
|
||||
}
|
||||
// yes default flavour, no flavour specified
|
||||
else if (product["meta"].contains("default") && options.productFlavour.empty())
|
||||
{
|
||||
flavour = product["flavours"][product["meta"]["default"]];
|
||||
if (options.verbose)
|
||||
{
|
||||
fmt::print("Selecting default flavour: {}\n", product["meta"]["default"]);
|
||||
}
|
||||
}
|
||||
// yes flavour specified, and is found
|
||||
else
|
||||
{
|
||||
flavour = product["flavours"][options.productFlavour];
|
||||
if (options.verbose)
|
||||
{
|
||||
fmt::print("Selecting flavour: {}\n", options.productFlavour);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// no variants, just go with what we have
|
||||
flavour = product;
|
||||
}
|
||||
|
||||
if (options.state != STATE_PIDGEN_GENERATE && options.state != STATE_PIDGEN_VALIDATE)
|
||||
auto pidtype = product["meta"]["type"];
|
||||
if (flavour["meta"].contains("type"))
|
||||
{
|
||||
pidtype = flavour["meta"]["type"];
|
||||
}
|
||||
|
||||
if (options.state != Options::STATE_PIDGEN_GENERATE && options.state != Options::STATE_PIDGEN_VALIDATE)
|
||||
{
|
||||
// exit early if we're not doing PIDGEN
|
||||
goto processOptionsExitEarly;
|
||||
}
|
||||
|
||||
if (options.oem)
|
||||
if (pidtype == "PIDGEN3")
|
||||
{
|
||||
flavour["BINK"][1].get_to(options.binkID);
|
||||
options.pidgenversion = Options::PIDGEN_VERSION::PIDGEN_3;
|
||||
if (options.verbose)
|
||||
{
|
||||
fmt::print("Setting PIDGEN type to \"PIDGEN3\"\n");
|
||||
}
|
||||
|
||||
if (options.oem)
|
||||
{
|
||||
flavour["BINK"][1].get_to(options.binkID);
|
||||
}
|
||||
else
|
||||
{
|
||||
flavour["BINK"][0].get_to(options.binkID);
|
||||
}
|
||||
|
||||
if (options.verbose)
|
||||
{
|
||||
fmt::print("Selected BINK: {}\n", options.binkID);
|
||||
}
|
||||
}
|
||||
else
|
||||
else if (pidtype == "PIDGEN2")
|
||||
{
|
||||
flavour["BINK"][0].get_to(options.binkID);
|
||||
options.pidgenversion = Options::PIDGEN_VERSION::PIDGEN_2;
|
||||
if (options.verbose)
|
||||
{
|
||||
fmt::print("Setting PIDGEN type to \"PIDGEN2\"\n");
|
||||
}
|
||||
}
|
||||
|
||||
if (options.verbose)
|
||||
{
|
||||
fmt::print("Selected BINK: {}\n", options.binkID);
|
||||
}
|
||||
|
||||
if (options.state != STATE_PIDGEN_GENERATE)
|
||||
if (options.state != Options::STATE_PIDGEN_GENERATE)
|
||||
{
|
||||
// exit early if we're only validating
|
||||
goto processOptionsExitEarly;
|
||||
@ -329,14 +321,15 @@ BOOL CLI::processOptions()
|
||||
|
||||
if (options.verbose)
|
||||
{
|
||||
fmt::print("Selected channel ID: {} (DPC entry {}/{})\n", options.channelID, rand % filtered.size(),
|
||||
fmt::print("Selected channel ID: {} (DPC entry {}/{})\n", options.channelID, (rand % filtered.size()) + 1,
|
||||
filtered.size());
|
||||
}
|
||||
}
|
||||
|
||||
if (options.channelID == 0)
|
||||
if (options.channelID.IsZero())
|
||||
{
|
||||
options.channelID = UMSKT::getRandom<WORD>() % 999;
|
||||
options.channelID.Randomize(UMSKT::rng, sizeof(DWORD32) * 8);
|
||||
options.channelID %= PIDGEN::MaxChannelID;
|
||||
if (options.verbose)
|
||||
{
|
||||
fmt::print("Generated channel ID: {}\n", options.channelID);
|
||||
@ -344,9 +337,9 @@ BOOL CLI::processOptions()
|
||||
}
|
||||
|
||||
// FE and FF are BINK 1998, but use a different, currently unhandled encoding scheme, we return an error here
|
||||
if (options.binkID == "FE" || options.binkID == "FF")
|
||||
if (options.binkID == "TS00" || options.binkID == "TS01")
|
||||
{
|
||||
fmt::print("ERROR: Terminal Services BINKs (FE and FF) are unsupported at this time\n");
|
||||
fmt::print("ERROR: Terminal Services BINKs (TS00 and TS01) are unsupported at this time\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -359,11 +352,88 @@ processOptionsExitEarly:
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays the contents of the input JSON file in an
|
||||
* intuitive and attractive pattern
|
||||
*
|
||||
* @return false
|
||||
*/
|
||||
BOOL CLI::processListCommand()
|
||||
{
|
||||
// the following code is absolutely unhinged
|
||||
// I'm so sorry
|
||||
|
||||
#if defined(UNICODE) || defined(__GNUC__)
|
||||
auto *leaf = "\u251C", *last = "\u2514", *line = "\u2500";
|
||||
#else
|
||||
auto *leaf = "\xC3", *last = "\xC0", *line = "\xC4";
|
||||
#endif
|
||||
|
||||
fmt::print("Listing known products and flavours: \n\n");
|
||||
|
||||
fmt::print("* The following product list uses this style of formatting:\n");
|
||||
fmt::print("{}: {} \n", fmt::styled("PRODUCT", fmt::emphasis::bold), "Product name");
|
||||
fmt::print("{}{}{} {}: {} \n", last, line, line, "FLAVOUR", "Flavour name");
|
||||
fmt::print("* Products that require a flavour are noted with {}\n\n",
|
||||
fmt::styled("(no default)", fmt::emphasis::bold));
|
||||
|
||||
for (auto const &i : keys["products"].items())
|
||||
{
|
||||
auto el = i.value();
|
||||
auto containsFlavours = el.contains("flavours");
|
||||
|
||||
fmt::print("{:<9} {} ", fmt::styled(fmt::format("{}:", i.key()), fmt::emphasis::bold), el["name"]);
|
||||
if (el.contains("BINK"))
|
||||
{
|
||||
fmt::print("{}\n", el["BINK"]);
|
||||
}
|
||||
else if (el["meta"].contains("default"))
|
||||
{
|
||||
fmt::print("(default: {} {})\n", fmt::styled(el["meta"]["default"], fmt::emphasis::bold),
|
||||
el["flavours"][el["meta"]["default"]]["BINK"]);
|
||||
}
|
||||
else if (el["meta"]["type"] == "PIDGEN3")
|
||||
{
|
||||
fmt::print("[{}]\n", el["meta"]["type"]);
|
||||
}
|
||||
else
|
||||
{
|
||||
fmt::print("{}\n", fmt::styled("(no default)", fmt::emphasis::bold));
|
||||
}
|
||||
|
||||
if (containsFlavours)
|
||||
{
|
||||
auto flavours = el["flavours"];
|
||||
for (auto j = flavours.begin(); j != flavours.end(); j++)
|
||||
{
|
||||
auto el2 = j.value();
|
||||
BOOL isLast = j == --flavours.end();
|
||||
|
||||
fmt::print("{}{}{} {:<9} {} ", !isLast ? leaf : last, line, line, fmt::format("{}:", j.key()),
|
||||
fmt::format("{} {}", el["name"], el2["name"]));
|
||||
|
||||
if (el2.contains("meta") && el2["meta"].contains("type"))
|
||||
{
|
||||
fmt::print("[{}]\n", el2["meta"]["type"]);
|
||||
}
|
||||
else
|
||||
{
|
||||
fmt::print("{}\n", el2["BINK"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fmt::print("\n");
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return success
|
||||
*/
|
||||
BOOL CLI::DisplayHelp(int, char *)
|
||||
BOOL CLI::DisplayHelp(const std::string &)
|
||||
{
|
||||
options.help = true;
|
||||
fmt::print("usage: {} \n", options.argv[0]);
|
||||
@ -371,6 +441,7 @@ BOOL CLI::DisplayHelp(int, char *)
|
||||
for (BYTE i = 0; i < CLIHelpOptionID_END; i++)
|
||||
{
|
||||
CLIHelpOptions o = helpOptions[i];
|
||||
|
||||
if (o.Short.empty())
|
||||
{
|
||||
fmt::print("\t{:>2} --{:<15} {}", "", o.Long, o.HelpText);
|
||||
@ -396,33 +467,31 @@ BOOL CLI::DisplayHelp(int, char *)
|
||||
return true;
|
||||
}
|
||||
|
||||
BOOL CLI::DisplayErrorMessage(int, char *)
|
||||
BOOL CLI::DisplayErrorMessage(const std::string &)
|
||||
{
|
||||
fmt::print("Error parsing command line options\n");
|
||||
DisplayHelp(0, nullptr);
|
||||
DisplayHelp("");
|
||||
options.error = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
BOOL CLI::SetVerboseOption(int, char *)
|
||||
BOOL CLI::SetVerboseOption(const std::string &)
|
||||
{
|
||||
fmt::print("Enabling verbose option\n\n");
|
||||
options.verbose = true;
|
||||
UMSKT::VERBOSE = true;
|
||||
UMSKT::setDebugOutput(stderr);
|
||||
UMSKT::setVerboseOutput(stdout);
|
||||
fmt::print(UMSKT::verbose, "Enabling verbose option\n");
|
||||
return true;
|
||||
}
|
||||
|
||||
BOOL CLI::SetDebugOption(int, char *)
|
||||
BOOL CLI::SetDebugOption(const std::string &)
|
||||
{
|
||||
fmt::print("Enabling debug option\n");
|
||||
options.verbose = true;
|
||||
UMSKT::DEBUG = true;
|
||||
UMSKT::setDebugOutput(stderr);
|
||||
UMSKT::setDebugOutput(stdout);
|
||||
fmt::print(UMSKT::debug, "Enabling debug option\n");
|
||||
return true;
|
||||
}
|
||||
|
||||
BOOL CLI::SetListOption(int, char *)
|
||||
BOOL CLI::SetListOption(const std::string &)
|
||||
{
|
||||
if (options.verbose)
|
||||
{
|
||||
@ -432,17 +501,17 @@ BOOL CLI::SetListOption(int, char *)
|
||||
return true;
|
||||
}
|
||||
|
||||
BOOL CLI::SetOEMOption(int, char *)
|
||||
BOOL CLI::SetOEMOption(const std::string &)
|
||||
{
|
||||
if (options.verbose)
|
||||
{
|
||||
fmt::print("Setting oem option\n");
|
||||
fmt::print("Setting OEM option\n");
|
||||
}
|
||||
options.oem = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
BOOL CLI::SetUpgradeOption(int, char *)
|
||||
BOOL CLI::SetUpgradeOption(const std::string &)
|
||||
{
|
||||
if (options.verbose)
|
||||
{
|
||||
@ -452,49 +521,36 @@ BOOL CLI::SetUpgradeOption(int, char *)
|
||||
return true;
|
||||
}
|
||||
|
||||
BOOL CLI::SetFileOption(int count, char *file)
|
||||
BOOL CLI::SetFileOption(const std::string &file)
|
||||
{
|
||||
if (options.verbose)
|
||||
{
|
||||
fmt::print("Setting file option to: {}\n", file);
|
||||
}
|
||||
options.keysFilename = file;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
BOOL CLI::SetNumberOption(int count, char *num)
|
||||
BOOL CLI::SetNumberOption(const std::string &num)
|
||||
{
|
||||
int nKeys;
|
||||
if (!_sscanf(num, "%d", &nKeys))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
auto nKeys = UMSKT::IntegerS(num);
|
||||
|
||||
if (options.verbose)
|
||||
{
|
||||
fmt::print("Setting generation number option to: {}\n", num);
|
||||
}
|
||||
|
||||
options.numKeys = nKeys;
|
||||
options.numKeys = nKeys.ConvertToLong();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param count
|
||||
* @param channum
|
||||
* @return
|
||||
*/
|
||||
BOOL CLI::SetChannelIDOption(int count, char *channum)
|
||||
BOOL CLI::SetChannelIDOption(const std::string &channum)
|
||||
{
|
||||
int siteID;
|
||||
if (!_sscanf(channum, "%d", &siteID))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
Integer channelID = UMSKT::IntegerS(channum);
|
||||
|
||||
// channel ids must be between 000 and 999
|
||||
if (siteID > 999)
|
||||
if (channelID >= PIDGEN::MaxChannelID)
|
||||
{
|
||||
fmt::print("ERROR: refusing to create a key with a Channel ID greater than 999\n");
|
||||
return false;
|
||||
@ -502,94 +558,117 @@ BOOL CLI::SetChannelIDOption(int count, char *channum)
|
||||
|
||||
if (options.verbose)
|
||||
{
|
||||
fmt::print("Setting channel number option to: {}\n", siteID);
|
||||
fmt::print("Setting Channel ID option to: {}\n", channelID);
|
||||
}
|
||||
|
||||
options.channelID = siteID;
|
||||
options.channelID = channelID;
|
||||
return true;
|
||||
}
|
||||
|
||||
BOOL CLI::SetBINKOption(int count, char *bink)
|
||||
BOOL CLI::SetBINKOption(const std::string &bink)
|
||||
{
|
||||
auto strbinkid = std::string(bink);
|
||||
options.binkID = strtoupper(strbinkid);
|
||||
options.binkID = UMSKT::strtoupper(strbinkid);
|
||||
|
||||
if (options.verbose)
|
||||
{
|
||||
fmt::print("Setting BINK option to {}\n", strbinkid);
|
||||
fmt::print("Setting BINK option to: {}\n", strbinkid);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
BOOL CLI::SetFlavourOption(int count, char *flavour)
|
||||
BOOL CLI::SetFlavourOption(const std::string &flavour)
|
||||
{
|
||||
auto strFlavour = UMSKT::strtoupper(flavour);
|
||||
options.productFlavour = strFlavour;
|
||||
|
||||
if (options.verbose)
|
||||
{
|
||||
fmt::print("Setting flavour option to {}\n", flavour);
|
||||
fmt::print("Setting flavour option to: {}\n", strFlavour);
|
||||
}
|
||||
|
||||
options.productFlavour = flavour;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param count
|
||||
* @param arg
|
||||
* @return
|
||||
*/
|
||||
BOOL CLI::SetSerialOption(int count, char *arg)
|
||||
BOOL CLI::SetSerialOption(const std::string &arg)
|
||||
{
|
||||
int serial_val;
|
||||
if (!_sscanf(arg, "%d", &serial_val))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
Integer Serial = UMSKT::IntegerS(arg);
|
||||
|
||||
// serials must be between 000000 and 999999
|
||||
if (serial_val > 999999)
|
||||
if (Serial >= PIDGEN::MaxSerial)
|
||||
{
|
||||
fmt::print("ERROR: refusing to create a key with a Serial not between 000000 and 999999\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
options.serialSet = true;
|
||||
options.serial = serial_val;
|
||||
options.serial = Serial;
|
||||
|
||||
if (options.verbose)
|
||||
{
|
||||
fmt::print("Setting serial number option to: {}\n", Serial);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
BOOL CLI::SetActivationIDOption(int count, char *aid)
|
||||
BOOL CLI::SetActivationIDOption(const std::string &aid)
|
||||
{
|
||||
options.installationID = aid;
|
||||
options.state = STATE_CONFIRMATION_ID;
|
||||
return true;
|
||||
}
|
||||
options.state = Options::STATE_CONFIRMATION_ID;
|
||||
|
||||
BOOL CLI::SetProductIDOption(int count, char *product)
|
||||
{
|
||||
if (options.verbose)
|
||||
{
|
||||
fmt::print("Setting product ID to {}", product);
|
||||
fmt::print("Setting program state to Confirmation ID Generation\n");
|
||||
}
|
||||
options.productID = product;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
BOOL CLI::SetValidateOption(int count, char *productID)
|
||||
BOOL CLI::SetProductIDOption(const std::string &product)
|
||||
{
|
||||
options.productID = product;
|
||||
|
||||
if (options.verbose)
|
||||
{
|
||||
fmt::print("Setting product ID option to: {}\n", product);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
BOOL CLI::SetValidateOption(const std::string &productID)
|
||||
{
|
||||
options.keyToCheck = productID;
|
||||
options.state = STATE_PIDGEN_VALIDATE;
|
||||
return true;
|
||||
}
|
||||
options.state = Options::STATE_PIDGEN_VALIDATE;
|
||||
|
||||
BOOL CLI::SetProductCodeOption(int, char *product)
|
||||
{
|
||||
if (options.verbose)
|
||||
{
|
||||
fmt::print("Setting product code to {}\n", product);
|
||||
fmt::print("Setting program state to PIDGEN Validation\n");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
BOOL CLI::SetProductCodeOption(const std::string &product)
|
||||
{
|
||||
auto strProduct = std::string(product);
|
||||
options.productCode = UMSKT::strtoupper(strProduct);
|
||||
options.productFlavour = "";
|
||||
|
||||
if (options.verbose)
|
||||
{
|
||||
fmt::print("Setting product code to: {}\n", strProduct);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
BOOL CLI::SetAuthDataOption(const std::string &authData)
|
||||
{
|
||||
auto strAuthData = std::string(authData);
|
||||
options.authInfo = strAuthData;
|
||||
|
||||
if (options.verbose)
|
||||
{
|
||||
fmt::print("Setting authdata option to: {}\n", strAuthData);
|
||||
}
|
||||
|
||||
auto strProduct = std::string(product);
|
||||
options.productCode = strtoupper(strProduct);
|
||||
return true;
|
||||
}
|
@ -23,8 +23,15 @@
|
||||
#ifndef UMSKT_HELP_H
|
||||
#define UMSKT_HELP_H
|
||||
|
||||
typedef BOOL CLIHandlerFunc(int, char *);
|
||||
typedef BOOL CLIHandlerFunc(const std::string &);
|
||||
|
||||
/**
|
||||
* CLI Options List.
|
||||
*
|
||||
* Note: options are processed in the order found in the ENUM
|
||||
* order matters mostly for UX.
|
||||
*
|
||||
*/
|
||||
enum CLIHelpOptionIDs
|
||||
{
|
||||
OPTION_HELP,
|
3
src/cli/options.cpp
Normal file
3
src/cli/options.cpp
Normal file
@ -0,0 +1,3 @@
|
||||
//
|
||||
// Created by neo on 2/18/2024.
|
||||
//
|
319
src/cli/pidgen.cpp
Normal file
319
src/cli/pidgen.cpp
Normal file
@ -0,0 +1,319 @@
|
||||
/**
|
||||
* This file is a part of the UMSKT Project
|
||||
*
|
||||
* Copyleft (C) 2019-2024 UMSKT Contributors (et.al.)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @FileCreated by Neo on 02/18/2024
|
||||
* @Maintainer Neo
|
||||
*/
|
||||
|
||||
#include "cli.h"
|
||||
|
||||
/**
|
||||
*
|
||||
* @param pidgen3
|
||||
* @return success
|
||||
*/
|
||||
BOOL CLI::InitPIDGEN3(PIDGEN3 *p3)
|
||||
{
|
||||
auto bink = keys["BINK"][options.binkID];
|
||||
|
||||
if (options.verbose)
|
||||
{
|
||||
fmt::print("{:->80}\n", "");
|
||||
fmt::print("Loaded the following elliptic curve parameters: BINK[{}]\n", options.binkID);
|
||||
fmt::print("{:->80}\n", "");
|
||||
fmt::print("{:>6}: {}\n", "P", bink["p"]);
|
||||
fmt::print("{:>6}: {}\n", "a", bink["a"]);
|
||||
fmt::print("{:>6}: {}\n", "b", bink["b"]);
|
||||
fmt::print("{:>6}: [{},\n{:>9}{}]\n", "G[x,y]", bink["g"]["x"], "", bink["g"]["y"]);
|
||||
fmt::print("{:>6}: [{},\n{:>9}{}]\n", "K[x,y]", bink["pub"]["x"], "", bink["pub"]["y"]);
|
||||
fmt::print("{:>6}: {}\n", "n", bink["n"]);
|
||||
fmt::print("{:>6}: {}\n", "k", bink["priv"]);
|
||||
fmt::print("\n");
|
||||
}
|
||||
|
||||
p3->LoadEllipticCurve(options.binkID, bink["p"], bink["a"], bink["b"], bink["g"]["x"], bink["g"]["y"],
|
||||
bink["pub"]["x"], bink["pub"]["y"], bink["n"], bink["priv"]);
|
||||
|
||||
if (options.state != Options::APPLICATION_STATE::STATE_PIDGEN_GENERATE)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (options.channelID.IsZero())
|
||||
{
|
||||
options.channelID.Randomize(UMSKT::rng, sizeof(DWORD32) * 8);
|
||||
}
|
||||
|
||||
options.channelID %= 1000;
|
||||
p3->info.ChannelID = options.channelID;
|
||||
if (options.verbose)
|
||||
{
|
||||
fmt::print("> Channel ID: {:d}\n", options.channelID);
|
||||
}
|
||||
|
||||
if (options.serial.NotZero() && p3->checkFieldIsBink1998())
|
||||
{
|
||||
p3->info.Serial = options.serial;
|
||||
if (options.verbose)
|
||||
{
|
||||
fmt::print("> Serial {:d}\n", options.serial);
|
||||
}
|
||||
}
|
||||
else if (options.serial.NotZero() && !p3->checkFieldIsBink1998())
|
||||
{
|
||||
fmt::print("Warning: Discarding user-supplied serial for BINK2002\n");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param pidgen2
|
||||
* @return success
|
||||
*/
|
||||
BOOL CLI::PIDGEN2Generate(PIDGEN2 &p2)
|
||||
{
|
||||
p2.info.ChannelID = options.channelID;
|
||||
p2.info.Serial = options.serial;
|
||||
p2.info.isOEM = options.oem;
|
||||
|
||||
std::string serial;
|
||||
p2.Generate(serial);
|
||||
|
||||
serial = p2.StringifyKey(serial);
|
||||
|
||||
fmt::print("{}", serial);
|
||||
|
||||
auto retval = p2.Validate(serial);
|
||||
|
||||
if (!retval)
|
||||
{
|
||||
fmt::print(" [INVALID]");
|
||||
}
|
||||
|
||||
fmt::print("\n");
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param pidgen2
|
||||
* @return success
|
||||
*/
|
||||
BOOL CLI::PIDGEN2Validate(PIDGEN2 &p2)
|
||||
{
|
||||
std::string product_key;
|
||||
|
||||
if (!p2.ValidateKeyString(options.keyToCheck, product_key))
|
||||
{
|
||||
fmt::print("ERROR: Product key is in an incorrect format!\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
fmt::print("{}\n", p2.StringifyKey(product_key));
|
||||
|
||||
if (!p2.Validate(product_key))
|
||||
{
|
||||
fmt::print("ERROR: Product key is invalid! Wrong BINK ID?\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
fmt::print("Key validated successfully!\n");
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return success
|
||||
*/
|
||||
BOOL CLI::PIDGEN3Generate(PIDGEN3 *p3)
|
||||
{
|
||||
// raw PID/serial value
|
||||
Integer serialRnd;
|
||||
|
||||
if (p3->checkFieldIsBink1998())
|
||||
{
|
||||
if (options.serial.NotZero())
|
||||
{
|
||||
// using user-provided serial
|
||||
serialRnd = options.serial;
|
||||
}
|
||||
else
|
||||
{
|
||||
// generate a random number to use as a serial
|
||||
serialRnd.Randomize(UMSKT::rng, sizeof(DWORD32) * 8);
|
||||
}
|
||||
|
||||
// make sure it's less than 999999
|
||||
serialRnd %= 1000000;
|
||||
}
|
||||
|
||||
p3->info.isOEM = options.oem;
|
||||
|
||||
for (DWORD32 i = 0; i < total; i++)
|
||||
{
|
||||
if (!p3->checkFieldIsBink1998())
|
||||
{
|
||||
if (options.authInfo.empty())
|
||||
{
|
||||
p3->info.AuthInfo.Randomize(UMSKT::rng, 10);
|
||||
}
|
||||
else
|
||||
{
|
||||
p3->info.AuthInfo = CryptoPP::Crop(UMSKT::IntegerS(options.authInfo), 10);
|
||||
}
|
||||
|
||||
if (options.verbose)
|
||||
{
|
||||
fmt::print("> AuthInfo: {:d}\n", p3->info.AuthInfo);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
p3->info.Serial = serialRnd;
|
||||
}
|
||||
|
||||
if (options.verbose)
|
||||
{
|
||||
fmt::print("\n");
|
||||
}
|
||||
|
||||
p3->Generate(pKey);
|
||||
|
||||
if (options.verbose)
|
||||
{
|
||||
fmt::print("> Product ID: {}\n\n", p3->StringifyProductID());
|
||||
}
|
||||
|
||||
bool isValid = p3->Validate(pKey);
|
||||
if (isValid)
|
||||
{
|
||||
fmt::print(p3->StringifyKey(pKey));
|
||||
if (i <= total - 1 || options.verbose)
|
||||
{
|
||||
fmt::print("\n");
|
||||
}
|
||||
count += isValid;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (options.verbose)
|
||||
{
|
||||
fmt::print("{} [Invalid]", p3->StringifyKey(pKey));
|
||||
if (i <= total - 1)
|
||||
{
|
||||
fmt::print("\n");
|
||||
}
|
||||
}
|
||||
total++; // queue a redo, basically
|
||||
}
|
||||
}
|
||||
|
||||
if (options.verbose)
|
||||
{
|
||||
fmt::print("\nSuccess count: {}/{}\n", count, total);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return success
|
||||
*/
|
||||
BOOL CLI::PIDGEN3Validate(PIDGEN3 *p3)
|
||||
{
|
||||
std::string product_key;
|
||||
|
||||
if (!p3->ValidateKeyString(options.keyToCheck, product_key))
|
||||
{
|
||||
fmt::print("ERROR: Product key is in an incorrect format!\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
fmt::print("{}\n", p3->StringifyKey(product_key));
|
||||
|
||||
if (!p3->Validate(product_key))
|
||||
{
|
||||
fmt::print("ERROR: Product key is invalid! Wrong BINK ID?\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
fmt::print("Key validated successfully!\n");
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return success
|
||||
*/
|
||||
BOOL CLI::PIDGenerate()
|
||||
{
|
||||
BOOL retval = false;
|
||||
|
||||
if (options.pidgenversion == Options::PIDGEN_VERSION::PIDGEN_2)
|
||||
{
|
||||
auto p2 = PIDGEN2();
|
||||
retval = PIDGEN2Generate(p2);
|
||||
return retval;
|
||||
}
|
||||
else if (options.pidgenversion == Options::PIDGEN_VERSION::PIDGEN_3)
|
||||
{
|
||||
auto bink = keys["BINK"][options.binkID];
|
||||
|
||||
auto p3 = PIDGEN3::Factory(bink["p"]);
|
||||
InitPIDGEN3(p3);
|
||||
retval = PIDGEN3Generate(p3);
|
||||
|
||||
delete p3;
|
||||
return retval;
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return isValid
|
||||
*/
|
||||
BOOL CLI::PIDValidate()
|
||||
{
|
||||
BOOL retval = false;
|
||||
|
||||
if (options.pidgenversion == Options::PIDGEN_VERSION::PIDGEN_2)
|
||||
{
|
||||
auto p2 = PIDGEN2();
|
||||
retval = PIDGEN2Validate(p2);
|
||||
return retval;
|
||||
}
|
||||
else if (options.pidgenversion == Options::PIDGEN_VERSION::PIDGEN_3)
|
||||
{
|
||||
auto bink = keys["BINK"][options.binkID];
|
||||
|
||||
auto p3 = PIDGEN3::Factory(bink["p"]);
|
||||
InitPIDGEN3(p3);
|
||||
retval = PIDGEN3Validate(p3);
|
||||
|
||||
delete p3;
|
||||
return retval;
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
271
src/generate.cpp
271
src/generate.cpp
@ -1,271 +0,0 @@
|
||||
/**
|
||||
* This file is a part of the UMSKT Project
|
||||
*
|
||||
* Copyleft (C) 2019-2024 UMSKT Contributors (et.al.)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @FileCreated by Neo on 01/05/2024
|
||||
* @Maintainer Neo
|
||||
*/
|
||||
|
||||
#include "cli.h"
|
||||
|
||||
/**
|
||||
*
|
||||
* @param pidgen2
|
||||
* @return success
|
||||
*/
|
||||
BOOL CLI::PIDGEN2Generate(PIDGEN2 &pidgen2)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param pidgen2
|
||||
* @return success
|
||||
*/
|
||||
BOOL CLI::PIDGEN2Validate(PIDGEN2 &pidgen2)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return success
|
||||
*/
|
||||
BOOL CLI::BINK1998Generate(PIDGEN3 &pidgen3)
|
||||
{
|
||||
// raw PID/serial value
|
||||
DWORD nRaw = options.channelID * 1'000'000;
|
||||
DWORD serialRnd;
|
||||
|
||||
if (options.serialSet)
|
||||
{
|
||||
// using user-provided serial
|
||||
serialRnd = options.serial;
|
||||
}
|
||||
else
|
||||
{
|
||||
// generate a random number to use as a serial
|
||||
serialRnd = UMSKT::getRandom<DWORD>();
|
||||
}
|
||||
|
||||
// make sure it's less than 999999
|
||||
nRaw += (serialRnd % 999999);
|
||||
|
||||
if (options.verbose)
|
||||
{
|
||||
// print the resulting Product ID
|
||||
// PID value is printed in BINK1998::Generate
|
||||
printID(&nRaw);
|
||||
}
|
||||
|
||||
for (int i = 0; i < total; i++)
|
||||
{
|
||||
pidgen3.info.setSerial(nRaw);
|
||||
pidgen3.Generate(pKey);
|
||||
|
||||
bool isValid = pidgen3.Validate(pKey);
|
||||
if (isValid)
|
||||
{
|
||||
printKey(pKey);
|
||||
if (i <= total - 1 || options.verbose)
|
||||
{
|
||||
fmt::print("\n");
|
||||
}
|
||||
count += isValid;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (options.verbose)
|
||||
{
|
||||
printKey(pKey);
|
||||
fmt::print(" [Invalid]");
|
||||
if (i <= total - 1)
|
||||
{
|
||||
fmt::print("\n");
|
||||
}
|
||||
}
|
||||
total++; // queue a redo, basically
|
||||
}
|
||||
}
|
||||
|
||||
if (options.verbose)
|
||||
{
|
||||
fmt::print("\nSuccess count: {}/{}\n", count, total);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return success
|
||||
*/
|
||||
BOOL CLI::BINK1998Validate(PIDGEN3 &bink1998)
|
||||
{
|
||||
std::string product_key;
|
||||
|
||||
if (!CLI::stripKey(options.keyToCheck, product_key))
|
||||
{
|
||||
fmt::print("ERROR: Product key is in an incorrect format!\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
CLI::printKey(product_key);
|
||||
fmt::print("\n");
|
||||
if (!bink1998.Validate(product_key))
|
||||
{
|
||||
fmt::print("ERROR: Product key is invalid! Wrong BINK ID?\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
fmt::print("Key validated successfully!\n");
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return success
|
||||
*/
|
||||
BOOL CLI::BINK2002Generate(PIDGEN3 &pidgen3)
|
||||
{
|
||||
// generate a key
|
||||
for (int i = 0; i < total; i++)
|
||||
{
|
||||
pidgen3.info.AuthInfo = UMSKT::getRandom<DWORD>() & BITMASK(10);
|
||||
|
||||
if (options.verbose)
|
||||
{
|
||||
fmt::print("> AuthInfo: {:#08x}\n", pidgen3.info.AuthInfo);
|
||||
}
|
||||
|
||||
pidgen3.Generate(pKey);
|
||||
|
||||
bool isValid = pidgen3.Validate(pKey);
|
||||
if (isValid)
|
||||
{
|
||||
CLI::printKey(pKey);
|
||||
if (i <= total - 1 || options.verbose)
|
||||
{ // check if end of list or verbose
|
||||
fmt::print("\n");
|
||||
}
|
||||
count += isValid; // add to count
|
||||
}
|
||||
else
|
||||
{
|
||||
if (options.verbose)
|
||||
{
|
||||
CLI::printKey(pKey); // print the key
|
||||
fmt::print(" [Invalid]"); // and add " [Invalid]" to the key
|
||||
if (i <= total - 1)
|
||||
{ // check if end of list
|
||||
fmt::print("\n");
|
||||
}
|
||||
}
|
||||
total++; // queue a redo, basically
|
||||
}
|
||||
}
|
||||
|
||||
if (options.verbose)
|
||||
{
|
||||
fmt::print("\nSuccess count: {}/{}\n", count, total);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return success
|
||||
*/
|
||||
BOOL CLI::BINK2002Validate(PIDGEN3 &pidgen3)
|
||||
{
|
||||
std::string product_key;
|
||||
|
||||
if (!CLI::stripKey(options.keyToCheck, product_key))
|
||||
{
|
||||
fmt::print("ERROR: Product key is in an incorrect format!\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
CLI::printKey(product_key);
|
||||
fmt::print("\n");
|
||||
if (!pidgen3.Validate(product_key))
|
||||
{
|
||||
fmt::print("ERROR: Product key is invalid! Wrong BINK ID?\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
fmt::print("Key validated successfully!\n");
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return success
|
||||
*/
|
||||
BOOL CLI::ConfirmationIDGenerate()
|
||||
{
|
||||
auto confid = ConfirmationID();
|
||||
std::string confirmation_id;
|
||||
|
||||
if (!InitConfirmationID(confid))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
DWORD err = confid.Generate(options.installationID, confirmation_id, options.productID);
|
||||
|
||||
if (err == SUCCESS)
|
||||
{
|
||||
fmt::print("{}\n", confirmation_id);
|
||||
return true;
|
||||
}
|
||||
|
||||
switch (err)
|
||||
{
|
||||
case ERR_TOO_SHORT:
|
||||
fmt::print("ERROR: Installation ID is too short.\n");
|
||||
break;
|
||||
|
||||
case ERR_TOO_LARGE:
|
||||
fmt::print("ERROR: Installation ID is too long.\n");
|
||||
break;
|
||||
|
||||
case ERR_INVALID_CHARACTER:
|
||||
fmt::print("ERROR: Invalid character in installation ID.\n");
|
||||
break;
|
||||
|
||||
case ERR_INVALID_CHECK_DIGIT:
|
||||
fmt::print("ERROR: Installation ID checksum failed. Please check that it is typed correctly.\n");
|
||||
break;
|
||||
|
||||
case ERR_UNKNOWN_VERSION:
|
||||
fmt::print("ERROR: Unknown installation ID version.\n");
|
||||
break;
|
||||
|
||||
case ERR_UNLUCKY:
|
||||
fmt::print("ERROR: Unable to generate valid confirmation ID.\n");
|
||||
break;
|
||||
|
||||
default:
|
||||
fmt::print("Unknown error occurred during Confirmation ID generation: {}\n", err);
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
@ -24,6 +24,8 @@
|
||||
* the history provided by diamondggg is that they are the originator of the code
|
||||
* and was created in tandem with an acquaintance who knows number theory.
|
||||
* The file dates suggest this code was written sometime in 2017/2018
|
||||
*
|
||||
* The algorithm was refactored by Neo in 2023
|
||||
* }
|
||||
*/
|
||||
|
||||
@ -38,7 +40,7 @@
|
||||
* @param x4
|
||||
* @param x5
|
||||
* @param priv
|
||||
* @param modulous
|
||||
* @param modulus
|
||||
* @param nonresidue
|
||||
* @param isOffice
|
||||
* @param isXPBrand
|
||||
@ -46,58 +48,74 @@
|
||||
* @return
|
||||
*/
|
||||
BOOL ConfirmationID::LoadHyperellipticCurve(QWORD x0, QWORD x1, QWORD x2, QWORD x3, QWORD x4, QWORD x5, Q_OWORD priv,
|
||||
QWORD modulous, QWORD nonresidue, BOOL isOffice, BOOL isXPBrand,
|
||||
BYTE flagVersion)
|
||||
QWORD modulus, QWORD nonresidue, DWORD32 iidkey, BOOL isOffice,
|
||||
BOOL isXPBrand, BYTE flagVersion)
|
||||
{
|
||||
curve[0] = x0;
|
||||
curve[1] = x1;
|
||||
curve[2] = x2;
|
||||
curve[3] = x3;
|
||||
curve[4] = x4;
|
||||
curve[5] = x5;
|
||||
QWORD fvals[6] = {x0, x1, x2, x3, x4, x5};
|
||||
|
||||
memcpy(&privateKey, &priv, sizeof(Q_OWORD));
|
||||
|
||||
MOD = modulous;
|
||||
NON_RESIDUE = nonresidue;
|
||||
this->isOffice = isOffice;
|
||||
this->isXPBrand = isXPBrand;
|
||||
this->flagVersion = flagVersion;
|
||||
|
||||
return true;
|
||||
return LoadHyperellipticCurve(fvals, priv, modulus, nonresidue, iidkey, isOffice, isXPBrand, flagVersion);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param f
|
||||
* @param priv
|
||||
* @param modulous
|
||||
* @param modulus
|
||||
* @param nonresidue
|
||||
* @param isOffice
|
||||
* @param isXPBrand
|
||||
* @param flagVersion
|
||||
* @return
|
||||
*/
|
||||
BOOL ConfirmationID::LoadHyperellipticCurve(QWORD *f, Q_OWORD priv, QWORD modulous, QWORD nonresidue, BOOL isOffice,
|
||||
BOOL isXPBrand, BYTE flagVersion)
|
||||
BOOL ConfirmationID::LoadHyperellipticCurve(QWORD *f, Q_OWORD priv, QWORD modulus, QWORD nonresidue, DWORD32 iidkey,
|
||||
BOOL isOffice, BOOL isXPBrand, BYTE flagVersion)
|
||||
{
|
||||
memcpy(&curve, f, sizeof(curve));
|
||||
memcpy(&privateKey, &priv, sizeof(Q_OWORD));
|
||||
|
||||
MOD = modulous;
|
||||
MOD = modulus;
|
||||
NON_RESIDUE = nonresidue;
|
||||
this->isOffice = isOffice;
|
||||
this->isXPBrand = isXPBrand;
|
||||
this->flagVersion = flagVersion;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
BOOL LoadHyperellipticCurve(const std::string &x0, const std::string &x1, const std::string &x2, const std::string &x3,
|
||||
const std::string &x4, const std::string &x5, const std::string &priv,
|
||||
const std::string &modulous, const std::string &nonresidue, BOOL isOffice, BOOL isXPBrand,
|
||||
BYTE flagVersion)
|
||||
BOOL ConfirmationID::LoadHyperellipticCurve(const std::string &x0, const std::string &x1, const std::string &x2,
|
||||
const std::string &x3, const std::string &x4, const std::string &x5,
|
||||
const std::string &priv, const std::string &modulus,
|
||||
const std::string &nonresidue, const std::string &iidkey, BOOL isOffice,
|
||||
BOOL isXPBrand, BYTE flagVersion)
|
||||
{
|
||||
std::string f[6];
|
||||
f[0] = x0;
|
||||
f[1] = x1;
|
||||
f[2] = x2;
|
||||
f[3] = x3;
|
||||
f[4] = x4;
|
||||
f[5] = x5;
|
||||
|
||||
return LoadHyperellipticCurve(f, priv, modulus, nonresidue, iidkey, isOffice, isXPBrand, flagVersion);
|
||||
}
|
||||
|
||||
BOOL ConfirmationID::LoadHyperellipticCurve(const std::string *f, const std::string &priv, const std::string &modulus,
|
||||
const std::string &nonresidue, const std::string &iidkey, BOOL isOffice,
|
||||
BOOL isXPBrand, BYTE flagVersion)
|
||||
{
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
EncodeN(IntegerS(f[i]), curve[i]);
|
||||
}
|
||||
|
||||
EncodeN(IntegerS(priv), privateKey);
|
||||
|
||||
EncodeN(IntegerS(modulus), MOD);
|
||||
|
||||
EncodeN(IntegerS(nonresidue), NON_RESIDUE);
|
||||
|
||||
this->isOffice = isOffice;
|
||||
this->isXPBrand = isXPBrand;
|
||||
this->flagVersion = flagVersion;
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -107,9 +125,9 @@ BOOL LoadHyperellipticCurve(const std::string &x0, const std::string &x1, const
|
||||
* @param pid
|
||||
* @return
|
||||
*/
|
||||
DWORD ConfirmationID::calculateCheckDigit(DWORD pid)
|
||||
DWORD32 ConfirmationID::calculateCheckDigit(DWORD32 pid)
|
||||
{
|
||||
DWORD i = 0, j = 0, k = 0;
|
||||
DWORD32 i = 0, j = 0, k = 0;
|
||||
for (j = pid; j; i += k)
|
||||
{
|
||||
k = j % 10;
|
||||
@ -125,7 +143,7 @@ DWORD ConfirmationID::calculateCheckDigit(DWORD pid)
|
||||
* @param hwid
|
||||
* @param version
|
||||
*/
|
||||
void ConfirmationID::decode_iid_new_version(BYTE *iid, BYTE *hwid, DWORD *version)
|
||||
void ConfirmationID::decode_iid_new_version(BYTE *iid, BYTE *hwid, DWORD32 *version)
|
||||
{
|
||||
QWORD buffer[5];
|
||||
for (BYTE i = 0; i < 5; i++)
|
||||
@ -133,8 +151,8 @@ void ConfirmationID::decode_iid_new_version(BYTE *iid, BYTE *hwid, DWORD *versio
|
||||
memcpy(&buffer[i], (iid + (4 * i)), 4);
|
||||
}
|
||||
|
||||
DWORD v1 = (buffer[3] & 0xFFFFFFF8) | 2;
|
||||
DWORD v2 = ((buffer[3] & 7) << 29) | (buffer[2] >> 3);
|
||||
DWORD32 v1 = (buffer[3] & 0xFFFFFFF8) | 2;
|
||||
DWORD32 v2 = ((buffer[3] & 7) << 29) | (buffer[2] >> 3);
|
||||
QWORD hardwareIDVal = ((QWORD)v1 << 32) | v2;
|
||||
for (BYTE i = 0; i < 8; ++i)
|
||||
{
|
||||
@ -153,8 +171,9 @@ void ConfirmationID::decode_iid_new_version(BYTE *iid, BYTE *hwid, DWORD *versio
|
||||
*/
|
||||
void ConfirmationID::Mix(BYTE *buffer, BYTE bufSize, const BYTE *key, BYTE keySize)
|
||||
{
|
||||
BYTE sha1_input[64], sha1_result[20];
|
||||
BYTE sha1_input[64], sha1_result[SHA1::DIGESTSIZE];
|
||||
BYTE half = bufSize / 2;
|
||||
auto digest = SHA1();
|
||||
|
||||
// assert(half <= sizeof(sha1_result) && half + keySize <= sizeof(sha1_input) - 9);
|
||||
for (BYTE external_counter = 0; external_counter < 4; external_counter++)
|
||||
@ -181,7 +200,8 @@ void ConfirmationID::Mix(BYTE *buffer, BYTE bufSize, const BYTE *key, BYTE keySi
|
||||
sha1_input[sizeof(sha1_input) - 2] = (1 + half + keySize) * 8 / 0x100;
|
||||
}
|
||||
|
||||
SHA1(sha1_input, sizeof(sha1_input), sha1_result);
|
||||
digest.Update(sha1_input, sizeof(sha1_input));
|
||||
digest.Final(sha1_result);
|
||||
|
||||
for (BYTE i = half & ~3; i < half; i++)
|
||||
{
|
||||
@ -206,8 +226,9 @@ void ConfirmationID::Mix(BYTE *buffer, BYTE bufSize, const BYTE *key, BYTE keySi
|
||||
*/
|
||||
void ConfirmationID::Unmix(BYTE *buffer, BYTE bufSize, const BYTE key[4], BYTE keySize)
|
||||
{
|
||||
BYTE sha1_input[64], sha1_result[20];
|
||||
BYTE sha1_input[64], sha1_result[SHA1::DIGESTSIZE];
|
||||
BYTE half = bufSize / 2;
|
||||
auto digest = SHA1();
|
||||
// assert(half <= sizeof(sha1_result) && half + keySize <= sizeof(sha1_input) - 9);
|
||||
|
||||
for (BYTE external_counter = 0; external_counter < 4; external_counter++)
|
||||
@ -232,7 +253,8 @@ void ConfirmationID::Unmix(BYTE *buffer, BYTE bufSize, const BYTE key[4], BYTE k
|
||||
sha1_input[sizeof(sha1_input) - 2] = (1 + half + keySize) * 8 / 0x100;
|
||||
}
|
||||
|
||||
SHA1(sha1_input, sizeof(sha1_input), sha1_result);
|
||||
digest.Update(sha1_input, sizeof(sha1_input));
|
||||
digest.Final(sha1_result);
|
||||
|
||||
for (BYTE i = half & ~3; i < half; i++)
|
||||
{
|
||||
@ -258,13 +280,13 @@ void ConfirmationID::Unmix(BYTE *buffer, BYTE bufSize, const BYTE key[4], BYTE k
|
||||
CONFIRMATION_ID_STATUS ConfirmationID::Generate(const std::string &installationIDIn, std::string &confirmationIDOut,
|
||||
std::string &productIDIn)
|
||||
{
|
||||
DWORD version;
|
||||
DWORD32 version;
|
||||
BYTE hardwareID[8];
|
||||
BYTE installation_id[19]; // 10**45 < 256**19
|
||||
BYTE productID[4];
|
||||
|
||||
BYTE installation_id_len = 0;
|
||||
auto pid = installationIDIn.c_str();
|
||||
auto pid = &installationIDIn[0];
|
||||
|
||||
BYTE count = 0, totalCount = 0;
|
||||
unsigned check = 0;
|
||||
@ -441,8 +463,8 @@ CONFIRMATION_ID_STATUS ConfirmationID::Generate(const std::string &installationI
|
||||
QWORD x1 = ulowhi.qword[0] - x2 * MOD;
|
||||
x2++;
|
||||
|
||||
d.u[0] = residue->sub(residue->mul(x1, x1), residue->mul(NON_RESIDUE, residue->mul(x2, x2)));
|
||||
d.u[1] = residue->add(x1, x1);
|
||||
d.u.qword[0] = residue->sub(residue->mul(x1, x1), residue->mul(NON_RESIDUE, residue->mul(x2, x2)));
|
||||
d.u.qword[1] = residue->add(x1, x1);
|
||||
if (divisor->find_divisor_v(&d))
|
||||
{
|
||||
break;
|
||||
@ -462,23 +484,23 @@ CONFIRMATION_ID_STATUS ConfirmationID::Generate(const std::string &installationI
|
||||
Q_OWORD e;
|
||||
memset(&e, 0, sizeof(e));
|
||||
|
||||
if (d.u[0] == BAD)
|
||||
if (d.u.qword[0] == BAD)
|
||||
{
|
||||
// we can not get the zero divisor, actually...
|
||||
e.qword[0] = residue->__umul128(MOD + 2, MOD, &e.qword[1]);
|
||||
}
|
||||
else if (d.u[1] == BAD)
|
||||
else if (d.u.qword[1] == BAD)
|
||||
{
|
||||
// O(1/MOD) chance
|
||||
// encoded = (unsigned __int128)(MOD + 1) * d.u[0] + MOD; // * MOD + d.u[0] is fine too
|
||||
e.qword[0] = residue->__umul128(MOD + 1, d.u[0], &e.qword[1]);
|
||||
e.qword[0] = residue->__umul128(MOD + 1, d.u.qword[0], &e.qword[1]);
|
||||
e.qword[0] += MOD;
|
||||
e.qword[1] += (e.qword[0] < MOD);
|
||||
}
|
||||
else
|
||||
{
|
||||
QWORD x1 = (d.u[1] % 2 ? d.u[1] + MOD : d.u[1]) / 2;
|
||||
QWORD x2sqr = residue->sub(residue->mul(x1, x1), d.u[0]);
|
||||
QWORD x1 = (d.u.qword[1] % 2 ? d.u.qword[1] + MOD : d.u.qword[1]) / 2;
|
||||
QWORD x2sqr = residue->sub(residue->mul(x1, x1), d.u.qword[0]);
|
||||
QWORD x2 = residue->sqrt(x2sqr);
|
||||
|
||||
if (x2 == BAD)
|
||||
@ -493,9 +515,9 @@ CONFIRMATION_ID_STATUS ConfirmationID::Generate(const std::string &installationI
|
||||
{
|
||||
// points (-x1+x2, v(-x1+x2)) and (-x1-x2, v(-x1-x2))
|
||||
QWORD x1a = residue->sub(x1, x2);
|
||||
QWORD y1 = residue->sub(d.v[0], residue->mul(d.v[1], x1a));
|
||||
QWORD y1 = residue->sub(d.v.qword[0], residue->mul(d.v.qword[1], x1a));
|
||||
QWORD x2a = residue->add(x1, x2);
|
||||
QWORD y2 = residue->sub(d.v[0], residue->mul(d.v[1], x2a));
|
||||
QWORD y2 = residue->sub(d.v.qword[0], residue->mul(d.v.qword[1], x2a));
|
||||
if (x1a > x2a)
|
||||
{
|
||||
QWORD tmp = x1a;
|
||||
@ -534,7 +556,7 @@ CONFIRMATION_ID_STATUS ConfirmationID::Generate(const std::string &installationI
|
||||
decimal[34 - i] = c4;
|
||||
}
|
||||
|
||||
assert(e.encoded[0] == 0 && e.encoded[1] == 0 && e.encoded[2] == 0 && e.encoded[3] == 0);
|
||||
assert(e.byte[0] == 0 && e.byte[1] == 0 && e.byte[2] == 0 && e.byte[3] == 0);
|
||||
|
||||
char *q = &confirmationIDOut[0];
|
||||
|
||||
|
@ -23,7 +23,7 @@
|
||||
#ifndef UMSKT_CONFID_H
|
||||
#define UMSKT_CONFID_H
|
||||
|
||||
#include "../libumskt.h"
|
||||
#include <libumskt/libumskt.h>
|
||||
|
||||
// Confirmation ID generator constants
|
||||
enum CONFIRMATION_ID_STATUS
|
||||
@ -41,11 +41,10 @@ enum CONFIRMATION_ID_STATUS
|
||||
|
||||
typedef struct
|
||||
{
|
||||
QWORD u[2];
|
||||
QWORD v[2];
|
||||
Q_OWORD u, v;
|
||||
} TDivisor;
|
||||
|
||||
class EXPORT ConfirmationID
|
||||
class EXPORT ConfirmationID : public UMSKT
|
||||
{
|
||||
QWORD MOD = 0, NON_RESIDUE = 0;
|
||||
QWORD curve[6] = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0};
|
||||
@ -55,8 +54,8 @@ class EXPORT ConfirmationID
|
||||
BOOL isOffice = false, isXPBrand = false;
|
||||
unsigned flagVersion = 0;
|
||||
|
||||
DWORD calculateCheckDigit(DWORD pid);
|
||||
void decode_iid_new_version(BYTE *iid, BYTE *hwid, DWORD *version);
|
||||
DWORD32 calculateCheckDigit(DWORD32 pid);
|
||||
void decode_iid_new_version(BYTE *iid, BYTE *hwid, DWORD32 *version);
|
||||
void Mix(BYTE *buffer, BYTE bufSize, const BYTE *key, BYTE keySize);
|
||||
void Unmix(BYTE *buffer, BYTE bufSize, const BYTE *key, BYTE keySize);
|
||||
|
||||
@ -127,26 +126,31 @@ class EXPORT ConfirmationID
|
||||
residue = new Residue(this);
|
||||
polynomial = new Polynomial(this);
|
||||
divisor = new Divisor(this);
|
||||
privateKey.qword[0] = privateKey.qword[1] = 0x00;
|
||||
}
|
||||
|
||||
BOOL LoadHyperellipticCurve(const std::string *f, const std::string &priv, const std::string &modulus,
|
||||
const std::string &nonresidue, const std::string &iidkey, BOOL isOffice, BOOL isXPBrand,
|
||||
BYTE flagVersion);
|
||||
|
||||
BOOL LoadHyperellipticCurve(const std::string &x0, const std::string &x1, const std::string &x2,
|
||||
const std::string &x3, const std::string &x4, const std::string &x5,
|
||||
const std::string &priv, const std::string &modulous, const std::string &nonresidue,
|
||||
BOOL isOffice, BOOL isXPBrand, BYTE flagVersion);
|
||||
const std::string &priv, const std::string &modulus, const std::string &nonresidue,
|
||||
const std::string &iidkey, BOOL isOffice, BOOL isXPBrand, BYTE flagVersion);
|
||||
|
||||
BOOL LoadHyperellipticCurve(QWORD x0, QWORD x1, QWORD x2, QWORD x3, QWORD x4, QWORD x5, Q_OWORD priv,
|
||||
QWORD modulous, QWORD nonresidue, BOOL isOffice, BOOL isXPBrand, BYTE flagVersion);
|
||||
BOOL LoadHyperellipticCurve(QWORD x0, QWORD x1, QWORD x2, QWORD x3, QWORD x4, QWORD x5, Q_OWORD priv, QWORD modulus,
|
||||
QWORD nonresidue, DWORD32 iidkey, BOOL isOffice, BOOL isXPBrand, BYTE flagVersion);
|
||||
|
||||
BOOL LoadHyperellipticCurve(QWORD *f, Q_OWORD priv, QWORD modulous, QWORD nonresidue, BOOL isOffice, BOOL isXPBrand,
|
||||
BYTE flagVersion);
|
||||
BOOL LoadHyperellipticCurve(QWORD *f, Q_OWORD priv, QWORD modulus, QWORD nonresidue, DWORD32 iidkey, BOOL isOffice,
|
||||
BOOL isXPBrand, BYTE flagVersion);
|
||||
|
||||
CONFIRMATION_ID_STATUS Generate(const std::string &installation_id_str, std::string &confirmation_id,
|
||||
std::string &productid);
|
||||
|
||||
~ConfirmationID()
|
||||
{
|
||||
delete residue, polynomial, divisor;
|
||||
delete residue;
|
||||
delete polynomial;
|
||||
delete divisor;
|
||||
}
|
||||
};
|
||||
|
||||
|
55
src/libumskt/confid/confid_unittest.cpp
Normal file
55
src/libumskt/confid/confid_unittest.cpp
Normal file
@ -0,0 +1,55 @@
|
||||
/**
|
||||
* This file is a part of the UMSKT Project
|
||||
*
|
||||
* Copyleft (C) 2019-2024 UMSKT Contributors (et.al.)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @FileCreated by Neo on 02/20/2024
|
||||
* @Maintainer Neo
|
||||
*/
|
||||
|
||||
#include "confid.h"
|
||||
#include <libumskt/libumskt_unittest.h>
|
||||
|
||||
/**
|
||||
* ConfirmationID must not be an abstract class.
|
||||
*/
|
||||
TEST(TestConfirmationID, InstantiateConfirmationID)
|
||||
{
|
||||
auto p3 = new ConfirmationID();
|
||||
ASSERT_NE(p3, nullptr);
|
||||
delete p3;
|
||||
}
|
||||
|
||||
class TestConfirmationID : public libumsktUnitTests
|
||||
{
|
||||
protected:
|
||||
ConfirmationID *cid;
|
||||
|
||||
void SetUp() override
|
||||
{
|
||||
cid = new ConfirmationID();
|
||||
cid->LoadHyperellipticCurve()
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
{
|
||||
if (cid != nullptr)
|
||||
{
|
||||
delete cid;
|
||||
cid = nullptr;
|
||||
}
|
||||
}
|
||||
};
|
@ -39,7 +39,7 @@ int ConfirmationID::ConfirmationID::Divisor::find_divisor_v(TDivisor *d)
|
||||
f2[i] = parent->curve[i];
|
||||
}
|
||||
|
||||
const QWORD u0 = d->u[0], u1 = d->u[1];
|
||||
const QWORD u0 = d->u.qword[0], u1 = d->u.qword[1];
|
||||
for (BYTE j = 4; j--;)
|
||||
{
|
||||
f2[j] = parent->residue->sub(f2[j], parent->residue->mul(u0, f2[j + 2]));
|
||||
@ -106,8 +106,8 @@ int ConfirmationID::ConfirmationID::Divisor::find_divisor_v(TDivisor *d)
|
||||
|
||||
QWORD v0 = parent->residue->mul(parent->residue->add(f1, parent->residue->mul(u1, parent->residue->mul(v1, v1))),
|
||||
parent->residue->inv(parent->residue->add(v1, v1)));
|
||||
d->v[0] = v0;
|
||||
d->v[1] = v1;
|
||||
d->v.qword[0] = v0;
|
||||
d->v.qword[1] = v1;
|
||||
|
||||
return 1;
|
||||
}
|
||||
@ -121,24 +121,24 @@ int ConfirmationID::ConfirmationID::Divisor::find_divisor_v(TDivisor *d)
|
||||
*/
|
||||
int ConfirmationID::ConfirmationID::Divisor::u2poly(const TDivisor *src, QWORD polyu[3], QWORD polyv[2])
|
||||
{
|
||||
if (src->u[1] != BAD)
|
||||
if (src->u.qword[1] != BAD)
|
||||
{
|
||||
polyu[0] = src->u[0];
|
||||
polyu[1] = src->u[1];
|
||||
polyu[0] = src->u.qword[0];
|
||||
polyu[1] = src->u.qword[1];
|
||||
polyu[2] = 1;
|
||||
|
||||
polyv[0] = src->v[0];
|
||||
polyv[1] = src->v[1];
|
||||
polyv[0] = src->v.qword[0];
|
||||
polyv[1] = src->v.qword[1];
|
||||
|
||||
return 2;
|
||||
}
|
||||
|
||||
if (src->u[0] != BAD)
|
||||
if (src->u.qword[0] != BAD)
|
||||
{
|
||||
polyu[0] = src->u[0];
|
||||
polyu[0] = src->u.qword[0];
|
||||
polyu[1] = 1;
|
||||
|
||||
polyv[0] = src->v[0];
|
||||
polyv[0] = src->v.qword[0];
|
||||
polyv[1] = 0;
|
||||
|
||||
return 1;
|
||||
@ -237,7 +237,7 @@ void ConfirmationID::Divisor::add(const TDivisor *src1, const TDivisor *src2, TD
|
||||
}
|
||||
}
|
||||
|
||||
vdeg = parent->polynomial->div_monic(vdeg, v, udeg, u, NULL);
|
||||
vdeg = parent->polynomial->div_monic(vdeg, v, udeg, u, nullptr);
|
||||
|
||||
while (udeg > 2)
|
||||
{
|
||||
@ -279,30 +279,30 @@ void ConfirmationID::Divisor::add(const TDivisor *src1, const TDivisor *src2, TD
|
||||
v[i] = parent->residue->sub(0, v[i]);
|
||||
}
|
||||
|
||||
vdeg = parent->polynomial->div_monic(vdeg, v, udeg, u, NULL);
|
||||
vdeg = parent->polynomial->div_monic(vdeg, v, udeg, u, nullptr);
|
||||
}
|
||||
|
||||
if (udeg == 2)
|
||||
{
|
||||
dst->u[0] = u[0];
|
||||
dst->u[1] = u[1];
|
||||
dst->v[0] = (vdeg >= 0 ? v[0] : 0);
|
||||
dst->v[1] = (vdeg >= 1 ? v[1] : 0);
|
||||
dst->u.qword[0] = u[0];
|
||||
dst->u.qword[1] = u[1];
|
||||
dst->v.qword[0] = (vdeg >= 0 ? v[0] : 0);
|
||||
dst->v.qword[1] = (vdeg >= 1 ? v[1] : 0);
|
||||
}
|
||||
else if (udeg == 1)
|
||||
{
|
||||
dst->u[0] = u[0];
|
||||
dst->u[1] = BAD;
|
||||
dst->v[0] = (vdeg >= 0 ? v[0] : 0);
|
||||
dst->v[1] = BAD;
|
||||
dst->u.qword[0] = u[0];
|
||||
dst->u.qword[1] = BAD;
|
||||
dst->v.qword[0] = (vdeg >= 0 ? v[0] : 0);
|
||||
dst->v.qword[1] = BAD;
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(udeg == 0);
|
||||
dst->u[0] = BAD;
|
||||
dst->u[1] = BAD;
|
||||
dst->v[0] = BAD;
|
||||
dst->v[1] = BAD;
|
||||
dst->u.qword[0] = BAD;
|
||||
dst->u.qword[1] = BAD;
|
||||
dst->v.qword[0] = BAD;
|
||||
dst->v.qword[1] = BAD;
|
||||
}
|
||||
}
|
||||
|
||||
@ -318,10 +318,10 @@ void ConfirmationID::Divisor::mul(const TDivisor *src, QWORD mult, TDivisor *dst
|
||||
{
|
||||
if (mult == 0)
|
||||
{
|
||||
dst->u[0] = BAD;
|
||||
dst->u[1] = BAD;
|
||||
dst->v[0] = BAD;
|
||||
dst->v[1] = BAD;
|
||||
dst->u.qword[0] = BAD;
|
||||
dst->u.qword[1] = BAD;
|
||||
dst->v.qword[0] = BAD;
|
||||
dst->v.qword[1] = BAD;
|
||||
return;
|
||||
}
|
||||
|
||||
@ -354,10 +354,10 @@ void ConfirmationID::Divisor::mul128(const TDivisor *src, QWORD mult_lo, QWORD m
|
||||
{
|
||||
if (mult_lo == 0 && mult_hi == 0)
|
||||
{
|
||||
dst->u[0] = BAD;
|
||||
dst->u[1] = BAD;
|
||||
dst->v[0] = BAD;
|
||||
dst->v[1] = BAD;
|
||||
dst->u.qword[0] = BAD;
|
||||
dst->u.qword[1] = BAD;
|
||||
dst->v.qword[0] = BAD;
|
||||
dst->v.qword[1] = BAD;
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -20,22 +20,28 @@
|
||||
* @Maintainer Neo
|
||||
*/
|
||||
|
||||
#include "libumskt.h"
|
||||
#include <libumskt/libumskt.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
// this seems janky but it works, and doesn't use storage that would otherwise get clobbered
|
||||
std::FILE *getFileStreamToNul()
|
||||
std::FILE *UMSKT::debug;
|
||||
std::FILE *UMSKT::verbose;
|
||||
|
||||
BOOL UMSKT::IS_CONSTRUCTED = UMSKT::CONSTRUCT();
|
||||
|
||||
/**
|
||||
* a static "constructor" that does some housekeeping for certain
|
||||
* platforms, in DJGPP for instance we need to setup the interval
|
||||
* timer for RNG.
|
||||
*
|
||||
* @return true
|
||||
*/
|
||||
BOOL UMSKT::CONSTRUCT()
|
||||
{
|
||||
fopen_s(&UMSKT::debug, "nul", "w");
|
||||
return UMSKT::debug;
|
||||
}
|
||||
std::FILE *UMSKT::debug = getFileStreamToNul();
|
||||
#else
|
||||
std::FILE *UMSKT::debug = std::fopen("/dev/null", "w");
|
||||
#ifdef __DJGPP__
|
||||
// this should be set up as early as possible
|
||||
uclock();
|
||||
#endif
|
||||
|
||||
BOOL UMSKT::VERBOSE = false;
|
||||
BOOL UMSKT::DEBUG = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* sets the filestream used for debugging
|
||||
@ -46,3 +52,13 @@ void UMSKT::setDebugOutput(std::FILE *input)
|
||||
{
|
||||
debug = input;
|
||||
}
|
||||
|
||||
/**
|
||||
* sets the filestream used for verbose messages
|
||||
*
|
||||
* @param input std::FILE
|
||||
*/
|
||||
void UMSKT::setVerboseOutput(std::FILE *input)
|
||||
{
|
||||
verbose = input;
|
||||
}
|
@ -20,18 +20,18 @@
|
||||
* @Maintainer Neo
|
||||
*/
|
||||
|
||||
#include "libumskt.h"
|
||||
#include "confid/confid.h"
|
||||
#include "pidgen2/PIDGEN2.h"
|
||||
#include "pidgen3/BINK1998.h"
|
||||
#include "pidgen3/BINK2002.h"
|
||||
#include "pidgen3/PIDGEN3.h"
|
||||
#include <libumskt/confid/confid.h>
|
||||
#include <libumskt/libumskt.h>
|
||||
#include <libumskt/pidgen2/PIDGEN2.h>
|
||||
#include <libumskt/pidgen3/BINK1998.h>
|
||||
#include <libumskt/pidgen3/BINK2002.h>
|
||||
#include <libumskt/pidgen3/PIDGEN3.h>
|
||||
|
||||
std::map<UMSKT_TAG, UMSKT_Value> UMSKT::tags;
|
||||
CryptoPP::DefaultAutoSeededRNG UMSKT::rng;
|
||||
|
||||
extern "C"
|
||||
{
|
||||
|
||||
/**
|
||||
* Sets debug output to a given C++ File stream
|
||||
* if the memory allocated at filestream is "STDOUT" or "STDERR"
|
||||
@ -148,7 +148,7 @@ extern "C"
|
||||
|
||||
// ---------------------------------------------
|
||||
|
||||
EXPORT void *PIDGEN3_INIT(const char *p, const char *a, const char *b, const char *generatorX,
|
||||
EXPORT void *PIDGEN3_INIT(const char *binkid, const char *p, const char *a, const char *b, const char *generatorX,
|
||||
const char *generatorY, const char *publicKeyX, const char *publicKeyY,
|
||||
const char *genOrder, const char *privateKey)
|
||||
{
|
||||
@ -163,7 +163,7 @@ extern "C"
|
||||
p3 = new BINK2002();
|
||||
}
|
||||
|
||||
p3->LoadEllipticCurve(p, a, b, generatorX, generatorY, publicKeyX, publicKeyY, genOrder, privateKey);
|
||||
p3->LoadEllipticCurve(binkid, p, a, b, generatorX, generatorY, publicKeyX, publicKeyY, genOrder, privateKey);
|
||||
|
||||
return p3;
|
||||
}
|
||||
@ -195,7 +195,7 @@ extern "C"
|
||||
std::string str;
|
||||
BOOL retval = p3->Generate(str);
|
||||
|
||||
assert(pKeySizeIn >= str.length() + 1);
|
||||
assert(pKeySizeIn >= str.length() + NULL_TERMINATOR);
|
||||
|
||||
memcpy(pKeyOut, &str[0], str.length());
|
||||
pKeyOut[str.length()] = 0;
|
||||
@ -245,48 +245,3 @@ extern "C"
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
|
||||
/**
|
||||
* Convert data between endianness types.
|
||||
*
|
||||
* @param data [in]
|
||||
* @param length [in]
|
||||
**/
|
||||
void UMSKT::endian(BYTE *data, int length)
|
||||
{
|
||||
for (int i = 0; i < length / 2; i++)
|
||||
{
|
||||
BYTE temp = data[i];
|
||||
data[i] = data[length - i - 1];
|
||||
data[length - i - 1] = temp;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an OpenSSL BigNumber to it's Little Endian binary equivalent
|
||||
*
|
||||
* @param a [in] BigNumber to convert
|
||||
* @param to [out] char* binary representation
|
||||
* @param tolen [in] length of the char* array
|
||||
*
|
||||
* @return length of number in to
|
||||
**/
|
||||
int UMSKT::BN_bn2lebin(const BIGNUM *a, unsigned char *to, int tolen)
|
||||
{
|
||||
if (a == nullptr || to == nullptr)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int len = BN_bn2bin(a, to);
|
||||
|
||||
if (len > tolen)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Choke point inside BN_bn2lebinpad: OpenSSL uses len instead of tolen.
|
||||
endian(to, tolen);
|
||||
|
||||
return len;
|
||||
}
|
@ -23,40 +23,91 @@
|
||||
#ifndef UMSKT_LIBUMSKT_H
|
||||
#define UMSKT_LIBUMSKT_H
|
||||
|
||||
#include "../typedefs.h"
|
||||
#include <typedefs.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#ifdef __DJGPP__
|
||||
#include <time.h>
|
||||
#endif
|
||||
|
||||
#include <openssl/bn.h>
|
||||
#include <openssl/ec.h>
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/rand.h>
|
||||
#include <openssl/sha.h>
|
||||
#include <cryptopp/cryptlib.h>
|
||||
#include <cryptopp/ecp.h>
|
||||
#include <cryptopp/integer.h>
|
||||
#include <cryptopp/misc.h>
|
||||
#include <cryptopp/nbtheory.h>
|
||||
#include <cryptopp/osrng.h>
|
||||
#include <cryptopp/sha.h>
|
||||
|
||||
using ECP = CryptoPP::ECP;
|
||||
using SHA1 = CryptoPP::SHA1;
|
||||
using Integer = CryptoPP::Integer;
|
||||
|
||||
#include <fmt/core.h>
|
||||
#include <fmt/format.h>
|
||||
|
||||
// fmt <-> CryptoPP linkage
|
||||
template <> class fmt::formatter<Integer>
|
||||
{
|
||||
char type_ = 'd';
|
||||
|
||||
public:
|
||||
constexpr auto parse(format_parse_context &ctx)
|
||||
{
|
||||
auto i = ctx.begin(), end = ctx.end();
|
||||
|
||||
if (i != end)
|
||||
{
|
||||
switch (*i)
|
||||
{
|
||||
case 'B':
|
||||
case 'b':
|
||||
case 'o':
|
||||
case 'X':
|
||||
case 'x':
|
||||
case 'd':
|
||||
type_ = *i++;
|
||||
}
|
||||
}
|
||||
|
||||
if (i != end && *i != '}')
|
||||
{
|
||||
throw format_error("invalid format");
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
template <typename FmtContext> constexpr auto format(const Integer &i, FmtContext &ctx) const
|
||||
{
|
||||
switch (type_)
|
||||
{
|
||||
case 'B':
|
||||
case 'b':
|
||||
return format_to(ctx.out(), "{}", IntToString(i, 2));
|
||||
|
||||
case 'o':
|
||||
return format_to(ctx.out(), "{}", IntToString(i, 8));
|
||||
|
||||
case 'X':
|
||||
case 'x':
|
||||
return format_to(ctx.out(), "{}", IntToString(i, 16));
|
||||
|
||||
case 'd':
|
||||
default:
|
||||
return format_to(ctx.out(), "{}", IntToString(i, 10));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Algorithm macros
|
||||
#define PK_LENGTH 25
|
||||
#define NULL_TERMINATOR 1
|
||||
|
||||
#define FIELD_BITS 384
|
||||
#define FIELD_BYTES 48
|
||||
#define FIELD_BITS_2003 512
|
||||
#define FIELD_BYTES_2003 64
|
||||
|
||||
#define SHA_MSG_LENGTH_XP (4 + 2 * FIELD_BYTES)
|
||||
#define SHA_MSG_LENGTH_2003 (3 + 2 * FIELD_BYTES_2003)
|
||||
|
||||
#define NEXTSNBITS(field, n, offset) (((QWORD)(field) >> (offset)) & ((1ULL << (n)) - 1))
|
||||
#define FIRSTNBITS(field, n) NEXTSNBITS((field), (n), 0)
|
||||
|
||||
#define HIBYTES(field, bytes) NEXTSNBITS((QWORD)(field), ((bytes) * 8), ((bytes) * 8))
|
||||
#define LOBYTES(field, bytes) FIRSTNBITS((QWORD)(field), ((bytes) * 8))
|
||||
|
||||
#define BYDWORD(n) (DWORD)(*((n) + 0) | *((n) + 1) << 8 | *((n) + 2) << 16 | *((n) + 3) << 24)
|
||||
#define BYDWORD(n) (DWORD32)(*((n) + 0) | *((n) + 1) << 8 | *((n) + 2) << 16 | *((n) + 3) << 24)
|
||||
#define BITMASK(n) ((1ULL << (n)) - 1)
|
||||
|
||||
#ifndef LIBUMSKT_VERSION_STRING
|
||||
@ -79,7 +130,7 @@ struct UMSKT_Value
|
||||
union {
|
||||
BOOL boolean;
|
||||
WORD word;
|
||||
DWORD dword;
|
||||
DWORD32 dword;
|
||||
QWORD qword;
|
||||
OWORD oword;
|
||||
char *chars;
|
||||
@ -103,37 +154,156 @@ enum UMSKT_TAG
|
||||
class EXPORT UMSKT
|
||||
{
|
||||
public:
|
||||
static std::FILE *debug;
|
||||
static BOOL VERBOSE;
|
||||
static BOOL DEBUG;
|
||||
static std::map<UMSKT_TAG, UMSKT_Value> tags;
|
||||
|
||||
// Hello OpenSSL developers, please tell me, where is this function at?
|
||||
static int BN_bn2lebin(const BIGNUM *a, unsigned char *to, int tolen);
|
||||
static void endian(BYTE *data, int length);
|
||||
|
||||
static void DESTRUCT()
|
||||
/**
|
||||
* Convert a std::string to an Integer
|
||||
*
|
||||
* @param in
|
||||
* @return
|
||||
*/
|
||||
INLINE static Integer IntegerS(const std::string &in)
|
||||
{
|
||||
if (debug != nullptr)
|
||||
{
|
||||
std::fclose(debug);
|
||||
}
|
||||
debug = nullptr;
|
||||
return Integer(&in[0]);
|
||||
}
|
||||
|
||||
static void setDebugOutput(std::FILE *input);
|
||||
/**
|
||||
* Convert a std::string to an Integer
|
||||
*
|
||||
* @param in
|
||||
* @return
|
||||
*/
|
||||
INLINE static Integer IntegerHexS(const std::string &in)
|
||||
{
|
||||
return IntegerS("0x" + in);
|
||||
}
|
||||
|
||||
template <typename T> static T getRandom()
|
||||
/**
|
||||
* Convert Native byte buffer to Integer
|
||||
*
|
||||
* @param buf
|
||||
* @param size
|
||||
* @return
|
||||
*/
|
||||
INLINE static Integer IntegerN(BYTE *buf, size_t size)
|
||||
{
|
||||
return {buf, size, Integer::UNSIGNED, CryptoPP::LITTLE_ENDIAN_ORDER};
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert Native Type T to Integer, where T is a concrete type
|
||||
*
|
||||
* @tparam T
|
||||
* @param in
|
||||
* @return
|
||||
*/
|
||||
template <typename T> INLINE static Integer IntegerN(const T &in)
|
||||
{
|
||||
return IntegerN((BYTE *)&in, sizeof(T));
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode Integer to a Native byte buffer
|
||||
*
|
||||
* @param in
|
||||
* @param buf
|
||||
* @param buflen
|
||||
* @return
|
||||
*/
|
||||
INLINE static BYTE *EncodeN(const Integer &in, BYTE *buf, size_t buflen)
|
||||
{
|
||||
in.Encode(buf, buflen);
|
||||
std::reverse(buf, buf + buflen);
|
||||
return buf + buflen;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode Integer to Native type T where T is a concrete type
|
||||
*
|
||||
* @tparam T
|
||||
* @param in
|
||||
* @param buf
|
||||
* @return
|
||||
*/
|
||||
template <typename T> INLINE static BYTE *EncodeN(const Integer &in, T &buf)
|
||||
{
|
||||
return EncodeN(in, (BYTE *)&buf, sizeof(T));
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode Integer to Native type T where T is a concrete type
|
||||
*
|
||||
* @tparam T
|
||||
* @param in
|
||||
* @param buf
|
||||
* @return
|
||||
*/
|
||||
template <typename T = DWORD32> INLINE static T EncodeN(const Integer &in)
|
||||
{
|
||||
T buf;
|
||||
EncodeN(in, (BYTE *)&buf, sizeof(T));
|
||||
return buf;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode a random number into a Native concrete type
|
||||
*
|
||||
* @tparam T
|
||||
* @return
|
||||
*/
|
||||
template <typename T> INLINE static T getRandom()
|
||||
{
|
||||
T retval;
|
||||
RAND_bytes((BYTE *)&retval, sizeof(retval));
|
||||
rng.GenerateBlock((BYTE *)&retval, sizeof(retval));
|
||||
return retval;
|
||||
}
|
||||
|
||||
static const char *VERSION()
|
||||
INLINE static std::string strtolower(std::string &in)
|
||||
{
|
||||
return fmt::format("LIBUMSKT {} compiled on {} {}", LIBUMSKT_VERSION_STRING, __DATE__, __TIME__).c_str();
|
||||
auto retval = std::string(in);
|
||||
std::transform(retval.begin(), retval.end(), retval.begin(), ::tolower);
|
||||
return retval;
|
||||
}
|
||||
|
||||
INLINE static std::string strtoupper(const std::string &in)
|
||||
{
|
||||
auto retval = std::string(in);
|
||||
std::transform(retval.begin(), retval.end(), retval.begin(), ::toupper);
|
||||
return retval;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the compiled-in version information
|
||||
*
|
||||
* @return Null-Terminated C-Style string pointer
|
||||
*/
|
||||
INLINE static const std::string VERSION()
|
||||
{
|
||||
return fmt::format("LIBUMSKT {} compiled on {} {}", LIBUMSKT_VERSION_STRING, __DATE__, __TIME__);
|
||||
}
|
||||
|
||||
static std::FILE *debug;
|
||||
static std::FILE *verbose;
|
||||
static BOOL IS_CONSTRUCTED;
|
||||
static std::map<UMSKT_TAG, UMSKT_Value> tags;
|
||||
static CryptoPP::DefaultAutoSeededRNG rng;
|
||||
|
||||
static BOOL CONSTRUCT();
|
||||
|
||||
static void DESTRUCT()
|
||||
{
|
||||
if (debug != nullptr && debug != stdout && debug != stderr)
|
||||
{
|
||||
std::fclose(debug);
|
||||
debug = nullptr;
|
||||
}
|
||||
if (verbose != nullptr && verbose != stdout && debug != stderr)
|
||||
{
|
||||
std::fclose(verbose);
|
||||
verbose = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
static void setDebugOutput(std::FILE *input);
|
||||
static void setVerboseOutput(std::FILE *input);
|
||||
};
|
||||
|
||||
#endif // UMSKT_LIBUMSKT_H
|
||||
|
39
src/libumskt/libumskt_unittest.h
Normal file
39
src/libumskt/libumskt_unittest.h
Normal file
@ -0,0 +1,39 @@
|
||||
/**
|
||||
* This file is a part of the UMSKT Project
|
||||
*
|
||||
* Copyleft (C) 2019-2024 UMSKT Contributors (et.al.)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @FileCreated by Neo on 02/19/2024
|
||||
* @Maintainer Neo
|
||||
*/
|
||||
#ifndef UMSKT_LIBUMSKT_UNITTEST_H
|
||||
#define UMSKT_LIBUMSKT_UNITTEST_H
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <libumskt/libumskt.h>
|
||||
|
||||
class libumsktUnitTests : public testing::Test
|
||||
{
|
||||
public:
|
||||
libumsktUnitTests()
|
||||
{
|
||||
// UMSKT::setVerboseOutput(stderr);
|
||||
// UMSKT::setDebugOutput(stderr);
|
||||
}
|
||||
~libumsktUnitTests() override = default;
|
||||
};
|
||||
|
||||
#endif // UMSKT_LIBUMSKT_UNITTEST_H
|
76
src/libumskt/pidgen.cpp
Normal file
76
src/libumskt/pidgen.cpp
Normal file
@ -0,0 +1,76 @@
|
||||
/**
|
||||
* This file is a part of the UMSKT Project
|
||||
*
|
||||
* Copyleft (C) 2019-2024 UMSKT Contributors (et.al.)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @FileCreated by Neo on 02/13/2024
|
||||
* @Maintainer Neo
|
||||
*/
|
||||
|
||||
#include "pidgen.h"
|
||||
|
||||
/**
|
||||
* The number 7 in an Integer for optimization
|
||||
*/
|
||||
const Integer PIDGEN::SEVEN = Integer(7);
|
||||
|
||||
/**
|
||||
* The number 10 in an Integer for optimization
|
||||
*/
|
||||
const Integer PIDGEN::TEN = Integer(10);
|
||||
|
||||
/**
|
||||
* The maximum Channel ID size (PID 2.0/3.0) in an Integer for optimization
|
||||
* 000 - 999
|
||||
*/
|
||||
const Integer PIDGEN::MaxChannelID = Integer(1'000);
|
||||
|
||||
/**
|
||||
* The maximum serial size (PID 2.0/3.0) in an Integer for optimization
|
||||
* 000000 - 999999
|
||||
*/
|
||||
const Integer PIDGEN::MaxSerial = Integer(1'000'000);
|
||||
|
||||
/**
|
||||
* Generates a Mod7 check digit for a given Integer
|
||||
*
|
||||
* @param in Integer to generate
|
||||
* @return Mod7 check digit
|
||||
*/
|
||||
Integer PIDGEN::GenerateMod7(const Integer &in)
|
||||
{
|
||||
Integer Sum = 0, CheckNum = in;
|
||||
|
||||
while (CheckNum.NotZero())
|
||||
{
|
||||
Sum += CheckNum % TEN;
|
||||
CheckNum /= TEN;
|
||||
}
|
||||
|
||||
return SEVEN - (Sum % SEVEN);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if the last digit (one's place) of a given Integer
|
||||
* is the expected check digit.
|
||||
*
|
||||
* @param in Integer to validate
|
||||
* @return validity
|
||||
*/
|
||||
BOOL PIDGEN::isValidMod7(const Integer &in)
|
||||
{
|
||||
return GenerateMod7(in / TEN) == (in % TEN);
|
||||
}
|
72
src/libumskt/pidgen.h
Normal file
72
src/libumskt/pidgen.h
Normal file
@ -0,0 +1,72 @@
|
||||
/**
|
||||
* This file is a part of the UMSKT Project
|
||||
*
|
||||
* Copyleft (C) 2019-2024 UMSKT Contributors (et.al.)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @FileCreated by Neo on 02/13/2024
|
||||
* @Maintainer Neo
|
||||
*/
|
||||
|
||||
#include "libumskt.h"
|
||||
|
||||
#ifndef UMSKT_PIDGEN_H
|
||||
#define UMSKT_PIDGEN_H
|
||||
|
||||
/**
|
||||
* PIDGEN Interface
|
||||
*
|
||||
* Defines three entry points:
|
||||
* Generate, Validate, StringifyKey
|
||||
*/
|
||||
class PIDGEN : public UMSKT
|
||||
{
|
||||
public:
|
||||
virtual ~PIDGEN() = default;
|
||||
static const Integer SEVEN;
|
||||
static const Integer TEN;
|
||||
static const Integer MaxChannelID;
|
||||
static const Integer MaxSerial;
|
||||
|
||||
virtual BOOL Generate(std::string &pKey)
|
||||
{
|
||||
throw std::runtime_error("PIDGEN::Generate() pure virtual function call");
|
||||
}
|
||||
|
||||
virtual BOOL Validate(const std::string &pKey)
|
||||
{
|
||||
throw std::runtime_error("PIDGEN::Validate() pure virtual function call");
|
||||
}
|
||||
|
||||
virtual std::string StringifyKey(const std::string &pKey)
|
||||
{
|
||||
throw std::runtime_error("PIDGEN::StringifyKey() pure virtual function call");
|
||||
}
|
||||
|
||||
virtual std::string StringifyProductID()
|
||||
{
|
||||
throw std::runtime_error("PIDGEN::StringifyProductID() pure virtual function call");
|
||||
}
|
||||
|
||||
virtual BOOL ValidateKeyString(const std::string &in_key, std::string &out_key)
|
||||
{
|
||||
throw std::runtime_error("PIDGEN::ValidateKeyString() pure virtual function call");
|
||||
}
|
||||
|
||||
Integer GenerateMod7(const Integer &in);
|
||||
BOOL isValidMod7(const Integer &in);
|
||||
};
|
||||
|
||||
#endif // UMSKT_PIDGEN_H
|
@ -22,187 +22,294 @@
|
||||
|
||||
#include "PIDGEN2.h"
|
||||
|
||||
const std::vector<std::string> PIDGEN2::channelIDDisallowList = {"333", "444", "555", "666", "777", "888", "999"};
|
||||
const std::vector<std::string> PIDGEN2::validYears = {"95", "96", "97", "98", "99", "00", "01", "02"};
|
||||
|
||||
/**
|
||||
* Generates a PID 2.0 key, output is placed in pKey
|
||||
*
|
||||
* @param input
|
||||
* @return
|
||||
* @param pKey
|
||||
* @return true
|
||||
*/
|
||||
BOOL PIDGEN2::isNumericString(char *input)
|
||||
BOOL PIDGEN2::Generate(std::string &pKey)
|
||||
{
|
||||
for (int i = 0; i < strlen(input); i++)
|
||||
Integer random;
|
||||
random.Randomize(rng, sizeof(DWORD32) * 8);
|
||||
|
||||
info.ChannelID = info.ChannelID % MaxChannelID;
|
||||
info.Serial = info.Serial % MaxSerial;
|
||||
|
||||
if (info.isOEM)
|
||||
{
|
||||
if (input[i] < '0' || input[i] > '9')
|
||||
info.Day = info.Day % Integer(366);
|
||||
// info.Year = info.Year;
|
||||
|
||||
info.OEMID = (info.ChannelID * TEN) + (info.Serial / (MaxSerial / TEN));
|
||||
info.Serial %= (MaxSerial / TEN);
|
||||
|
||||
info.OEMID = (info.OEMID * TEN) + GenerateMod7(info.OEMID);
|
||||
|
||||
DWORD32 day = EncodeN(info.Day), year = EncodeN(info.Year), serial = EncodeN(info.Serial),
|
||||
oemid = EncodeN(info.OEMID);
|
||||
|
||||
if (debug)
|
||||
{
|
||||
return false;
|
||||
fmt::print("\n{:03d}{:02d}-OEM-{:07d}-{:05d}\n", day, year, oemid, serial);
|
||||
}
|
||||
|
||||
pKey = fmt::format("{:03d}{:02d}{:07d}{:05d}", day, year, oemid, serial);
|
||||
}
|
||||
else if (info.isOffice)
|
||||
{
|
||||
info.ChannelID = (info.ChannelID * TEN) + ((info.ChannelID % TEN) + 1);
|
||||
info.Serial = (info.Serial * TEN) + GenerateMod7(info.Serial);
|
||||
|
||||
DWORD32 channelid = EncodeN(info.ChannelID), serial = EncodeN(info.Serial);
|
||||
|
||||
if (debug)
|
||||
{
|
||||
fmt::print("\n{:04d}-{:07d}\n", channelid, serial);
|
||||
}
|
||||
|
||||
pKey = fmt::format("{:04d}{:07d}", channelid, serial);
|
||||
}
|
||||
else
|
||||
{
|
||||
info.Serial = (info.Serial * TEN) + GenerateMod7(info.Serial);
|
||||
|
||||
DWORD32 channelid = EncodeN(info.ChannelID), serial = EncodeN(info.Serial);
|
||||
|
||||
if (debug)
|
||||
{
|
||||
fmt::print("\n{:03d}-{:07d}\n", channelid, serial);
|
||||
}
|
||||
|
||||
pKey = fmt::format("{:03d}{:07d}", channelid, serial);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Valid serial types are:
|
||||
*
|
||||
* @param input
|
||||
* C = Channel/Site ID (001 - 998)
|
||||
* E = Office Channel ID (+1) Check Digit
|
||||
* N = Serial
|
||||
* K = Mod7 Check Digit
|
||||
*
|
||||
* -- OEM Specific
|
||||
* D = 3 Digit day (001 - 366)
|
||||
* Y = 2 Digit year
|
||||
* O = OEM ID - typically seen as a channel ID + the first digit of the serial + mod7 check digit
|
||||
*
|
||||
* note that the N segment for OEM serials do not have a Mod7 check
|
||||
*
|
||||
* CCC-NNNNNNK
|
||||
* CCCE-NNNNNNK
|
||||
* DDDYY-ZZOOONK-NNNNN
|
||||
* DDDYY-OEM-ZZOOONK-NNNNN
|
||||
*
|
||||
* we can determine what type of key we have
|
||||
* simply by counting the numeric characters
|
||||
*
|
||||
* @param pKey
|
||||
* @return
|
||||
*/
|
||||
int PIDGEN2::addDigits(char *input)
|
||||
BOOL PIDGEN2::Validate(const std::string &pKey)
|
||||
{
|
||||
int output = 0;
|
||||
std::string filtered;
|
||||
ValidateKeyString(pKey, filtered);
|
||||
|
||||
if (!isNumericString(input))
|
||||
bool bIsValidChannelID, bIsValidSerial, bIsValidOEMDay, bIsValidOEMYear, bIsValidOEMID;
|
||||
|
||||
switch (filtered.length())
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
case KeySize::FPP:
|
||||
// standard FPP/CCP has 10 digits
|
||||
info.ChannelID = IntegerS(filtered.substr(0, 3));
|
||||
info.Serial = IntegerS(filtered.substr(3, 7));
|
||||
|
||||
for (int i = 0; i < strlen(input); i++)
|
||||
{
|
||||
output += input[i] - '0';
|
||||
}
|
||||
bIsValidChannelID = isValidChannelID();
|
||||
bIsValidSerial = isValidSerial();
|
||||
|
||||
return output;
|
||||
if (debug)
|
||||
{
|
||||
fmt::print("\n\nisValidChannelID: {} isValidSerial: {}\n", bIsValidChannelID, bIsValidSerial);
|
||||
}
|
||||
|
||||
return bIsValidChannelID && bIsValidSerial;
|
||||
|
||||
case KeySize::Office:
|
||||
// so far only office 97 has been documented using this
|
||||
info.isOffice = true;
|
||||
info.ChannelID = IntegerS(filtered.substr(0, 4));
|
||||
info.Serial = IntegerS(filtered.substr(4, 7));
|
||||
|
||||
bIsValidChannelID = isValidChannelID();
|
||||
bIsValidSerial = isValidSerial();
|
||||
|
||||
if (debug)
|
||||
{
|
||||
fmt::print("\n\nisValidChannelID: {} isValidSerial: {}\n", bIsValidChannelID, bIsValidSerial);
|
||||
}
|
||||
|
||||
return bIsValidChannelID && bIsValidSerial;
|
||||
|
||||
case KeySize::OEM:
|
||||
// all OEM keys follow this pattern
|
||||
info.isOEM = true;
|
||||
info.Day = IntegerS(filtered.substr(0, 3));
|
||||
info.Year = IntegerS(filtered.substr(3, 2));
|
||||
info.OEMID = IntegerS(filtered.substr(5, 7)); // 6 + check digit
|
||||
info.Serial = IntegerS(filtered.substr(12, 5));
|
||||
|
||||
bIsValidOEMDay = isValidOEMDay();
|
||||
bIsValidOEMYear = isValidOEMYear();
|
||||
bIsValidOEMID = isValidOEMID();
|
||||
|
||||
if (debug)
|
||||
{
|
||||
fmt::print("\n\nisValidOEMDay: {} isValidOEMYear: {} isValidOEMID: {}\n", bIsValidOEMDay, bIsValidOEMYear,
|
||||
bIsValidOEMID);
|
||||
}
|
||||
|
||||
return bIsValidOEMDay && bIsValidOEMYear && bIsValidOEMID;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param channelID
|
||||
* @param pKey
|
||||
* @return
|
||||
*/
|
||||
BOOL PIDGEN2::isValidChannelID(char *channelID)
|
||||
std::string PIDGEN2::StringifyKey(const std::string &pKey)
|
||||
{
|
||||
if (strlen(channelID) > 3)
|
||||
switch (pKey.length())
|
||||
{
|
||||
case KeySize::FPP:
|
||||
return fmt::format("{}-{}", pKey.substr(0, 3), pKey.substr(3, 7));
|
||||
|
||||
case KeySize::Office:
|
||||
return fmt::format("{}-{}", pKey.substr(0, 4), pKey.substr(4, 7));
|
||||
|
||||
case KeySize::OEM:
|
||||
return fmt::format("{}-OEM-{}-{}", pKey.substr(0, 5), pKey.substr(5, 7), pKey.substr(12, 5));
|
||||
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
std::string PIDGEN2::StringifyProductID()
|
||||
{
|
||||
if (info.isOEM)
|
||||
{
|
||||
return fmt::format("{:d}{:d}-OEM-{:d}-{:d}", info.Year, info.Day, info.OEMID, info.Serial);
|
||||
}
|
||||
|
||||
return fmt::format("{}-{}", info.ChannelID, info.Serial);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param in_key
|
||||
* @param out_key
|
||||
* @return
|
||||
*/
|
||||
BOOL INLINE PIDGEN2::ValidateKeyString(const std::string &in_key, std::string &out_key)
|
||||
{
|
||||
std::copy_if(in_key.begin(), in_key.end(), std::back_inserter(out_key), [](char c) { return std::isdigit(c); });
|
||||
|
||||
return out_key.length() == KeySize::FPP || out_key.length() == KeySize::Office || out_key.length() == KeySize::OEM;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the Serial with check digit a valid serial?
|
||||
*
|
||||
* standard Mod7 Check
|
||||
*
|
||||
* @return validity
|
||||
*/
|
||||
BOOL PIDGEN2::isValidSerial()
|
||||
{
|
||||
return isValidMod7(info.Serial);
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the OEMID a valid?
|
||||
*
|
||||
* @return validity
|
||||
*/
|
||||
BOOL PIDGEN2::isValidOEMID()
|
||||
{
|
||||
if (info.OEMID.IsZero())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = 0; i <= 6; i++)
|
||||
return isValidMod7(info.OEMID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the Channel ID a valid Channel ID?
|
||||
* also validates Channel ID check digit if applicable
|
||||
*
|
||||
* Known invalid Channel IDs are:
|
||||
* 333, 444, 555, 666, 777, 888, 999
|
||||
*
|
||||
* @return validity
|
||||
*/
|
||||
BOOL PIDGEN2::isValidChannelID() const
|
||||
{
|
||||
// if we're office, do the last digit +1 checksum
|
||||
if (info.isOffice)
|
||||
{
|
||||
if (strcmp(channelID, channelIDBlacklist[i]) != 0)
|
||||
Integer CheckDigit = (info.ChannelID % TEN), ChannelID = (info.ChannelID / TEN);
|
||||
|
||||
if (std::find(channelIDDisallowList.begin(), channelIDDisallowList.end(), IntToString(ChannelID)) !=
|
||||
channelIDDisallowList.end())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return (ChannelID % TEN) + 1 == CheckDigit;
|
||||
}
|
||||
|
||||
return true;
|
||||
// otherwise just make sure we're not in the disallow list
|
||||
return std::find(channelIDDisallowList.begin(), channelIDDisallowList.end(), IntToString(info.ChannelID)) ==
|
||||
channelIDDisallowList.end();
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the OEM year in the allow list?
|
||||
*
|
||||
* @param OEMID
|
||||
* @return
|
||||
* Known allowed years are:
|
||||
* 95, 96, 97, 98, 99, 00, 01, 02
|
||||
*
|
||||
* @return validity
|
||||
*/
|
||||
BOOL PIDGEN2::isValidOEMID(char *OEMID)
|
||||
BOOL PIDGEN2::isValidOEMYear() const
|
||||
{
|
||||
if (!isNumericString(OEMID))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (strlen(OEMID) > 5)
|
||||
{
|
||||
if (OEMID[0] != '0' || OEMID[1] != '0')
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
int mod = addDigits(OEMID);
|
||||
|
||||
return (mod % 21 == 0);
|
||||
auto year = fmt::format("{:02d}", info.Year.ConvertToLong());
|
||||
return std::find(validYears.begin(), validYears.end(), year) != validYears.end();
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the OEM Day an allowed day?
|
||||
*
|
||||
* @param year
|
||||
* @return
|
||||
* Allowed days are 1 - 366 inclusive
|
||||
*
|
||||
* @return validity
|
||||
*/
|
||||
BOOL PIDGEN2::isValidYear(char *year)
|
||||
BOOL PIDGEN2::isValidOEMDay() const
|
||||
{
|
||||
for (int i = 0; i <= 7; i++)
|
||||
{
|
||||
if (year == validYears[i])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return info.Day >= 0 && info.Day <= 366;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param day
|
||||
* @return
|
||||
*/
|
||||
BOOL PIDGEN2::isValidDay(char *day)
|
||||
{
|
||||
if (!isNumericString(day))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
int iDay = std::stoi(day);
|
||||
if (iDay == 0 || iDay >= 365)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param productID
|
||||
* @return
|
||||
*/
|
||||
BOOL PIDGEN2::isValidRetailProductID(char *productID)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param channelID
|
||||
* @param keyout
|
||||
* @return
|
||||
*/
|
||||
int PIDGEN2::GenerateRetail(char *channelID, char *&keyout)
|
||||
{
|
||||
if (!isValidChannelID(channelID))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param year
|
||||
* @param day
|
||||
* @param oem
|
||||
* @param keyout
|
||||
* @return
|
||||
*/
|
||||
int PIDGEN2::GenerateOEM(char *year, char *day, char *oem, char *&keyout)
|
||||
{
|
||||
if (!isValidOEMID(oem))
|
||||
{
|
||||
int mod = addDigits(oem);
|
||||
mod += mod % 21;
|
||||
|
||||
snprintf(oem, 8, "%07u", mod);
|
||||
}
|
||||
|
||||
if (!isValidYear(year))
|
||||
{
|
||||
_strncpy(year, 4, validYears[0], 4);
|
||||
}
|
||||
|
||||
if (!isValidDay(day))
|
||||
{
|
||||
auto iday = UMSKT::getRandom<int>();
|
||||
iday = (iday + 1) % 365;
|
||||
}
|
||||
|
||||
_strncpy(keyout, 32, &fmt::format("{}{}-OEM-{}-{}", year, day, oem, oem).c_str()[0], 32);
|
||||
|
||||
return 0;
|
||||
}
|
@ -23,28 +23,40 @@
|
||||
#ifndef UMSKT_PIDGEN2_H
|
||||
#define UMSKT_PIDGEN2_H
|
||||
|
||||
#include "../libumskt.h"
|
||||
#include <libumskt/pidgen.h>
|
||||
|
||||
class EXPORT PIDGEN2
|
||||
class EXPORT PIDGEN2 : public PIDGEN
|
||||
{
|
||||
DWORD year;
|
||||
DWORD day;
|
||||
BOOL isOEM;
|
||||
BOOL isOffice;
|
||||
static const std::vector<std::string> channelIDDisallowList;
|
||||
static const std::vector<std::string> validYears;
|
||||
|
||||
static constexpr char channelIDBlacklist[7][4] = {"333", "444", "555", "666", "777", "888", "999"};
|
||||
static constexpr char validYears[8][3] = {"95", "96", "97", "98", "99", "00", "01", "02"};
|
||||
enum KeySize
|
||||
{
|
||||
FPP = 10,
|
||||
Office = 11,
|
||||
OEM = 17
|
||||
};
|
||||
|
||||
public:
|
||||
BOOL isNumericString(char *input);
|
||||
BOOL isValidChannelID(char *channelID);
|
||||
BOOL isValidOEMID(char *OEMID);
|
||||
BOOL isValidYear(char *year);
|
||||
BOOL isValidDay(char *day);
|
||||
BOOL isValidRetailProductID(char *productID);
|
||||
int addDigits(char *input);
|
||||
int GenerateRetail(char *channelID, char *&keyout);
|
||||
int GenerateOEM(char *year, char *day, char *oem, char *&keyout);
|
||||
~PIDGEN2() override = default;
|
||||
|
||||
struct KeyInfo
|
||||
{
|
||||
BOOL isOEM, isOffice;
|
||||
Integer Day, Year, OEMID, ChannelID, Serial;
|
||||
} info;
|
||||
|
||||
BOOL Generate(std::string &pKey) override;
|
||||
BOOL Validate(const std::string &pKey) override;
|
||||
std::string StringifyKey(const std::string &pKey) override;
|
||||
std::string StringifyProductID() override;
|
||||
BOOL ValidateKeyString(const std::string &in_key, std::string &out_key) override;
|
||||
|
||||
BOOL isValidSerial();
|
||||
BOOL isValidOEMID();
|
||||
[[nodiscard]] BOOL isValidChannelID() const;
|
||||
[[nodiscard]] BOOL isValidOEMYear() const;
|
||||
[[nodiscard]] BOOL isValidOEMDay() const;
|
||||
};
|
||||
|
||||
#endif // UMSKT_PIDGEN2_H
|
||||
|
115
src/libumskt/pidgen2/PIDGEN2_unittest.cpp
Normal file
115
src/libumskt/pidgen2/PIDGEN2_unittest.cpp
Normal file
@ -0,0 +1,115 @@
|
||||
/**
|
||||
* This file is a part of the UMSKT Project
|
||||
*
|
||||
* Copyleft (C) 2019-2024 UMSKT Contributors (et.al.)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @FileCreated by Neo on 02/19/2024
|
||||
* @Maintainer Neo
|
||||
*/
|
||||
|
||||
#include "PIDGEN2.h"
|
||||
#include <libumskt/libumskt_unittest.h>
|
||||
|
||||
/**
|
||||
* PIDGEN2 must not be an abstract class.
|
||||
*/
|
||||
TEST(PIDGEN2, InstantiatePIDGEN2)
|
||||
{
|
||||
auto p2 = new PIDGEN2();
|
||||
ASSERT_NE(p2, nullptr);
|
||||
delete p2;
|
||||
}
|
||||
|
||||
class TestPIDGEN2 : public libumsktUnitTests
|
||||
{
|
||||
protected:
|
||||
PIDGEN *p;
|
||||
PIDGEN2 *p2;
|
||||
|
||||
PIDGEN2::KeyInfo valid_ki = {false, false, 60, 99, 0, 95, 111111};
|
||||
|
||||
void SetUp() override
|
||||
{
|
||||
p2 = new PIDGEN2();
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
{
|
||||
if (p != nullptr)
|
||||
{
|
||||
delete p;
|
||||
p = nullptr;
|
||||
}
|
||||
if (p2 != nullptr)
|
||||
{
|
||||
delete p2;
|
||||
p2 = nullptr;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(TestPIDGEN2, TestStringifyKeyFPP)
|
||||
{
|
||||
std::string pKey = "0951111111";
|
||||
pKey = p2->StringifyKey(pKey);
|
||||
ASSERT_STRCASEEQ(&pKey[0], "095-1111111");
|
||||
}
|
||||
|
||||
TEST_F(TestPIDGEN2, TestStringifyKeyOffice)
|
||||
{
|
||||
std::string pKey = "09561111111";
|
||||
pKey = p2->StringifyKey(pKey);
|
||||
ASSERT_STREQ(&pKey[0], "0956-1111111");
|
||||
}
|
||||
|
||||
TEST_F(TestPIDGEN2, TestStringifyKeyOEM)
|
||||
{
|
||||
std::string pKey = "06099000951611111";
|
||||
pKey = p2->StringifyKey(pKey);
|
||||
ASSERT_STREQ(&pKey[0], "06099-OEM-0009516-11111");
|
||||
}
|
||||
|
||||
TEST_F(TestPIDGEN2, GenerateValidFPPKey)
|
||||
{
|
||||
p2->info = valid_ki;
|
||||
|
||||
std::string pKey;
|
||||
p2->Generate(pKey);
|
||||
pKey = p2->StringifyKey(pKey);
|
||||
ASSERT_STREQ(&pKey[0], "095-1111111");
|
||||
}
|
||||
|
||||
TEST_F(TestPIDGEN2, GenerateValidOfficeKey)
|
||||
{
|
||||
p2->info = valid_ki;
|
||||
p2->info.isOffice = true;
|
||||
|
||||
std::string pKey;
|
||||
p2->Generate(pKey);
|
||||
pKey = p2->StringifyKey(pKey);
|
||||
ASSERT_STREQ(&pKey[0], "0956-1111111");
|
||||
}
|
||||
|
||||
TEST_F(TestPIDGEN2, GenerateValidOEMKey)
|
||||
{
|
||||
p2->info = valid_ki;
|
||||
p2->info.isOEM = true;
|
||||
|
||||
std::string pKey;
|
||||
p2->Generate(pKey);
|
||||
pKey = p2->StringifyKey(pKey);
|
||||
ASSERT_STREQ(&pKey[0], "06099-OEM-0009516-11111");
|
||||
}
|
@ -24,6 +24,7 @@
|
||||
* and uploaded to GitHub by TheMCHK in August of 2019
|
||||
*
|
||||
* Endermanch (Andrew) rewrote the algorithm in May of 2023
|
||||
* Neo ported Endermanch's algorithm to CryptoPP in February of 2024
|
||||
* }
|
||||
*/
|
||||
|
||||
@ -32,101 +33,138 @@
|
||||
/**
|
||||
* Packs a Windows XP-like Product Key.
|
||||
*
|
||||
* @param pRaw [in] *QWORD[2] raw product key input
|
||||
**/
|
||||
BOOL BINK1998::Pack(QWORD *pRaw)
|
||||
* @param ki
|
||||
* @return Integer representation of KeyInfo
|
||||
*/
|
||||
Integer BINK1998::Pack(const KeyInfo &ki)
|
||||
{
|
||||
// The quantity of information the key provides is 114 bits.
|
||||
// We're storing it in 2 64-bit quad-words with 14 trailing bits.
|
||||
// 64 * 2 = 128
|
||||
auto serial = (ki.ChannelID * MaxSerial) + ki.Serial;
|
||||
|
||||
// Signature [114..59] <- Hash [58..31] <- Serial [30..1] <- Upgrade [0]
|
||||
pRaw[0] = FIRSTNBITS(info.Signature, 5) << 59 | FIRSTNBITS(info.Hash, 28) << 31 | info.Serial << 1 | info.isUpgrade;
|
||||
pRaw[1] = NEXTSNBITS(info.Signature, 51, 5);
|
||||
Integer raw = CryptoPP::Crop(ki.Signature, 56) << 59 | CryptoPP::Crop(ki.Hash, 28) << 31 |
|
||||
CryptoPP::Crop(serial, 30) << 1 | ki.isUpgrade;
|
||||
|
||||
return true;
|
||||
if (debug)
|
||||
{
|
||||
fmt::print(debug, "pack: {:x}\n\n", raw);
|
||||
}
|
||||
|
||||
return raw;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unpacks a Windows XP-like Product Key.
|
||||
*
|
||||
* @param pRaw [out] *QWORD[2] raw product key output
|
||||
**/
|
||||
BOOL BINK1998::Unpack(QWORD *pRaw)
|
||||
* @param raw Integer to unpack
|
||||
* @return populated PIDGEN3::KeyInfo struct
|
||||
*/
|
||||
BINK1998::KeyInfo BINK1998::Unpack(const Integer &raw)
|
||||
{
|
||||
KeyInfo ki;
|
||||
|
||||
// We're assuming that the quantity of information within the product key is at most 114 bits.
|
||||
// log2(24^25) = 114.
|
||||
|
||||
// Upgrade = Bit 0
|
||||
info.isUpgrade = FIRSTNBITS(pRaw[0], 1);
|
||||
ki.isUpgrade = CryptoPP::Crop(raw, 1).ConvertToLong();
|
||||
|
||||
// Serial = Bits [1..30] -> 30 bits
|
||||
info.Serial = NEXTSNBITS(pRaw[0], 30, 1);
|
||||
auto serialPack = CryptoPP::Crop((raw >> 1), 30);
|
||||
ki.Serial = serialPack % MaxSerial;
|
||||
ki.ChannelID = ((serialPack - ki.Serial) / MaxSerial);
|
||||
|
||||
// Hash = Bits [31..58] -> 28 bits
|
||||
info.Hash = NEXTSNBITS(pRaw[0], 28, 31);
|
||||
ki.Hash = CryptoPP::Crop((raw >> 31), 28);
|
||||
|
||||
// Signature = Bits [59..113] -> 56 bits
|
||||
info.Signature = FIRSTNBITS(pRaw[1], 51) << 5 | NEXTSNBITS(pRaw[0], 5, 59);
|
||||
ki.Signature = CryptoPP::Crop((raw >> 59), 56);
|
||||
|
||||
return true;
|
||||
return ki;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a Windows XP-like Product Key.
|
||||
*
|
||||
* @param pKey [out]
|
||||
*
|
||||
* @return true on success, false on fail
|
||||
*/
|
||||
BOOL BINK1998::Generate(std::string &pKey)
|
||||
{
|
||||
BN_CTX *numContext = BN_CTX_new();
|
||||
Integer c, s, pRaw;
|
||||
SHA1 sha1;
|
||||
|
||||
BIGNUM *c = BN_CTX_get(numContext), *s = BN_CTX_get(numContext), *x = BN_CTX_get(numContext),
|
||||
*y = BN_CTX_get(numContext);
|
||||
// copy initial state from object
|
||||
auto ki = info;
|
||||
|
||||
QWORD pRaw[2];
|
||||
if (!ki.Rand.IsZero())
|
||||
{
|
||||
c = ki.Rand;
|
||||
}
|
||||
|
||||
// Data segment of the RPK.
|
||||
DWORD pData = info.Serial << 1 | info.isUpgrade;
|
||||
Integer serialPack = (ki.ChannelID * MaxSerial) + ki.Serial;
|
||||
Integer pData = (serialPack << 1) | ki.isUpgrade;
|
||||
|
||||
// prepare the private key for generation
|
||||
BN_sub(privateKey, genOrder, privateKey);
|
||||
privateKey = genOrder - privateKey;
|
||||
|
||||
do
|
||||
{
|
||||
EC_POINT *r = EC_POINT_new(eCurve);
|
||||
ECP::Point R;
|
||||
|
||||
// Generate a random number c consisting of 384 bits without any constraints.
|
||||
BN_rand(c, FIELD_BITS, BN_RAND_TOP_ANY, BN_RAND_BOTTOM_ANY);
|
||||
if (ki.Rand.IsZero())
|
||||
{
|
||||
// Generate a random number c consisting of 384 bits without any constraints.
|
||||
c.Randomize(UMSKT::rng, FieldBits);
|
||||
}
|
||||
|
||||
// Pick a random derivative of the base point on the elliptic curve.
|
||||
// R = cG;
|
||||
EC_POINT_mul(eCurve, r, nullptr, genPoint, c, numContext);
|
||||
R = eCurve.Multiply(c, genPoint);
|
||||
if (debug)
|
||||
{
|
||||
fmt::print(debug, "c: {:x}\n\n", c);
|
||||
fmt::print(debug, "R[x,y] [{:x},\n{:x}]\n\n", R.x, R.y);
|
||||
}
|
||||
|
||||
// Acquire its coordinates.
|
||||
// x = R.x; y = R.y;
|
||||
EC_POINT_get_affine_coordinates(eCurve, r, x, y, numContext);
|
||||
|
||||
BYTE msgDigest[SHA_DIGEST_LENGTH], msgBuffer[SHA_MSG_LENGTH_XP];
|
||||
BYTE xBin[FIELD_BYTES], yBin[FIELD_BYTES];
|
||||
|
||||
// Convert coordinates to bytes.
|
||||
UMSKT::BN_bn2lebin(x, xBin, FIELD_BYTES);
|
||||
UMSKT::BN_bn2lebin(y, yBin, FIELD_BYTES);
|
||||
BYTE msgDigest[SHA1::DIGESTSIZE], msgBuffer[SHAMessageLength], *pMsgBuffer = msgBuffer;
|
||||
|
||||
// Assemble the SHA message.
|
||||
memcpy(&msgBuffer[0], &pData, 4);
|
||||
memcpy(&msgBuffer[4], xBin, FIELD_BYTES);
|
||||
memcpy(&msgBuffer[4 + FIELD_BYTES], yBin, FIELD_BYTES);
|
||||
pMsgBuffer = EncodeN(pData, pMsgBuffer, 4);
|
||||
pMsgBuffer = EncodeN(R.x, pMsgBuffer, FieldBytes);
|
||||
EncodeN(R.y, pMsgBuffer, FieldBytes);
|
||||
|
||||
// pHash = SHA1(pSerial || R.x || R.y)
|
||||
SHA1(msgBuffer, SHA_MSG_LENGTH_XP, msgDigest);
|
||||
sha1.CalculateDigest(msgDigest, msgBuffer, sizeof(msgBuffer));
|
||||
|
||||
if (debug)
|
||||
{
|
||||
fmt::print(debug, "msgBuffer: ");
|
||||
for (BYTE b : msgBuffer)
|
||||
{
|
||||
fmt::print(debug, "{:x}", b);
|
||||
}
|
||||
fmt::print(debug, "\n\n");
|
||||
|
||||
fmt::print(debug, "msgDigest: ");
|
||||
for (BYTE b : msgDigest)
|
||||
{
|
||||
fmt::print(debug, "{:x}", b);
|
||||
}
|
||||
fmt::print(debug, "\n\n");
|
||||
}
|
||||
|
||||
// Translate the byte digest into a 32-bit integer - this is our computed pHash.
|
||||
// Truncate the pHash to 28 bits.
|
||||
info.Hash = BYDWORD(msgDigest) >> 4 & BITMASK(28);
|
||||
|
||||
ki.Hash = IntegerN(msgDigest, 4) >> 4;
|
||||
ki.Hash = CryptoPP::Crop(ki.Hash, 28);
|
||||
|
||||
/*
|
||||
*
|
||||
@ -148,37 +186,38 @@ BOOL BINK1998::Generate(std::string &pKey)
|
||||
*/
|
||||
|
||||
// s = ek;
|
||||
BN_copy(s, privateKey);
|
||||
BN_mul_word(s, info.Hash);
|
||||
s = privateKey * ki.Hash;
|
||||
|
||||
// s += c (mod n)
|
||||
BN_mod_add(s, s, c, genOrder, numContext);
|
||||
s += c;
|
||||
s %= genOrder;
|
||||
|
||||
// Translate resulting scalar into a 64-bit integer (the byte order is little-endian).
|
||||
BN_bn2lebinpad(s, (BYTE *)&info.Signature, BN_num_bytes(s));
|
||||
// Translate resulting scalar into an Integer.
|
||||
ki.Signature = s;
|
||||
|
||||
// Pack product key.
|
||||
Pack(pRaw);
|
||||
pRaw = Pack(ki);
|
||||
|
||||
auto serial = fmt::format("{:d}", info.Serial);
|
||||
fmt::print(UMSKT::debug, "Generation results:\n");
|
||||
fmt::print(UMSKT::debug, "{:>10}: {:b}\n", "Upgrade", (bool)info.isUpgrade);
|
||||
fmt::print(UMSKT::debug, "{:>10}: {}\n", "Channel ID", serial.substr(0, 3));
|
||||
fmt::print(UMSKT::debug, "{:>10}: {}\n", "Sequence", serial.substr(3));
|
||||
fmt::print(UMSKT::debug, "{:>10}: {:d}\n", "Hash", info.Hash);
|
||||
fmt::print(UMSKT::debug, "{:>10}: {:d}\n", "Signature", info.Signature);
|
||||
fmt::print(UMSKT::debug, "\n");
|
||||
if (verbose)
|
||||
{
|
||||
fmt::print(verbose, "Generation results:\n");
|
||||
fmt::print(verbose, "{:>10}: {}\n", "Upgrade", (bool)ki.isUpgrade);
|
||||
fmt::print(verbose, "{:>10}: {}\n", "Channel ID", ki.ChannelID);
|
||||
fmt::print(verbose, "{:>10}: {}\n", "Sequence", ki.Serial);
|
||||
fmt::print(verbose, "{:>10}: {:x}\n", "Hash", ki.Hash);
|
||||
fmt::print(verbose, "{:>10}: {:x}\n", "Signature", ki.Signature);
|
||||
fmt::print(verbose, "\n");
|
||||
}
|
||||
|
||||
EC_POINT_free(r);
|
||||
} while (info.Signature > BITMASK(55));
|
||||
} while (ki.Signature.BitCount() > 55 && ki.Rand.IsZero());
|
||||
// ↑ ↑ ↑
|
||||
// The signature can't be longer than 55 bits, else it will
|
||||
// make the CD-key longer than 25 characters.
|
||||
|
||||
// Convert bytecode to Base24 CD-key.
|
||||
base24(pKey, (BYTE *)pRaw);
|
||||
pKey = base24(pRaw);
|
||||
|
||||
BN_CTX_free(numContext);
|
||||
info = ki;
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -190,33 +229,33 @@ BOOL BINK1998::Generate(std::string &pKey)
|
||||
*
|
||||
* @return true if provided key validates against loaded curve
|
||||
*/
|
||||
BOOL BINK1998::Validate(std::string &pKey)
|
||||
BOOL BINK1998::Validate(const std::string &pKey)
|
||||
{
|
||||
if (pKey.length() != 25)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
BN_CTX *numContext = BN_CTX_new();
|
||||
|
||||
QWORD pRaw[2];
|
||||
|
||||
// Convert Base24 CD-key to bytecode.
|
||||
unbase24((BYTE *)pRaw, pKey);
|
||||
Integer pRaw = unbase24(pKey);
|
||||
SHA1 sha1;
|
||||
|
||||
// Extract RPK, hash and signature from bytecode.
|
||||
Unpack(pRaw);
|
||||
KeyInfo ki = Unpack(pRaw);
|
||||
|
||||
auto serial = fmt::format("{:d}", info.Serial);
|
||||
fmt::print(UMSKT::debug, "Validation results:\n");
|
||||
fmt::print(UMSKT::debug, "{:>10}: {}\n", "Upgrade", (bool)info.isUpgrade);
|
||||
fmt::print(UMSKT::debug, "{:>10}: {}\n", "Channel ID", serial.substr(0, 3));
|
||||
fmt::print(UMSKT::debug, "{:>10}: {}\n", "Sequence", serial.substr(3));
|
||||
fmt::print(UMSKT::debug, "{:>10}: {:d}\n", "Hash", info.Hash);
|
||||
fmt::print(UMSKT::debug, "{:>10}: {:d}\n", "Signature", info.Signature);
|
||||
fmt::print(UMSKT::debug, "\n");
|
||||
if (verbose)
|
||||
{
|
||||
fmt::print(verbose, "Validation results:\n");
|
||||
fmt::print(verbose, "{:>10}: {}\n", "Upgrade", (bool)ki.isUpgrade);
|
||||
fmt::print(verbose, "{:>10}: {}\n", "Channel ID", ki.ChannelID);
|
||||
fmt::print(verbose, "{:>10}: {}\n", "Sequence", ki.Serial);
|
||||
fmt::print(verbose, "{:>10}: {:x}\n", "Hash", ki.Hash);
|
||||
fmt::print(verbose, "{:>10}: {:x}\n", "Signature", ki.Signature);
|
||||
fmt::print(verbose, "\n");
|
||||
}
|
||||
|
||||
DWORD pData = info.Serial << 1 | info.isUpgrade;
|
||||
Integer serialPack = (ki.ChannelID * MaxSerial) + ki.Serial;
|
||||
Integer pData = serialPack << 1 | ki.isUpgrade;
|
||||
|
||||
/*
|
||||
*
|
||||
@ -233,52 +272,49 @@ BOOL BINK1998::Validate(std::string &pKey)
|
||||
*
|
||||
*/
|
||||
|
||||
BIGNUM *e = BN_lebin2bn((BYTE *)&info.Hash, sizeof(info.Hash), nullptr),
|
||||
*s = BN_lebin2bn((BYTE *)&info.Signature, sizeof(info.Signature), nullptr);
|
||||
|
||||
BIGNUM *x = BN_CTX_get(numContext), *y = BN_CTX_get(numContext);
|
||||
Integer e = ki.Hash, s = ki.Signature;
|
||||
|
||||
// Create 2 points on the elliptic curve.
|
||||
EC_POINT *t = EC_POINT_new(eCurve), *p = EC_POINT_new(eCurve);
|
||||
ECP::Point t, P;
|
||||
|
||||
// t = sG
|
||||
EC_POINT_mul(eCurve, t, nullptr, genPoint, s, numContext);
|
||||
t = eCurve.Multiply(s, genPoint);
|
||||
|
||||
// P = eK
|
||||
EC_POINT_mul(eCurve, p, nullptr, pubPoint, e, numContext);
|
||||
P = eCurve.Multiply(e, pubPoint);
|
||||
|
||||
// P += t
|
||||
EC_POINT_add(eCurve, p, t, p, numContext);
|
||||
P = eCurve.Add(P, t);
|
||||
|
||||
// x = P.x; y = P.y;
|
||||
EC_POINT_get_affine_coordinates(eCurve, p, x, y, numContext);
|
||||
if (debug)
|
||||
{
|
||||
fmt::print(debug, "P[x,y]: [{:x},\n{:x}]\n\n", P.x, P.y);
|
||||
}
|
||||
|
||||
BYTE msgDigest[SHA_DIGEST_LENGTH], msgBuffer[SHA_MSG_LENGTH_XP], xBin[FIELD_BYTES], yBin[FIELD_BYTES];
|
||||
BYTE msgDigest[SHA1::DIGESTSIZE], msgBuffer[SHAMessageLength], *pMsgBuffer = msgBuffer;
|
||||
|
||||
// Convert resulting point coordinates to bytes.
|
||||
UMSKT::BN_bn2lebin(x, xBin, FIELD_BYTES);
|
||||
UMSKT::BN_bn2lebin(y, yBin, FIELD_BYTES);
|
||||
|
||||
// Assemble the SHA message.
|
||||
memcpy(&msgBuffer[0], &pData, 4);
|
||||
memcpy(&msgBuffer[4], xBin, FIELD_BYTES);
|
||||
memcpy(&msgBuffer[4 + FIELD_BYTES], yBin, FIELD_BYTES);
|
||||
pMsgBuffer = EncodeN(pData, pMsgBuffer, 4);
|
||||
pMsgBuffer = EncodeN(P.x, pMsgBuffer, FieldBytes);
|
||||
EncodeN(P.y, pMsgBuffer, FieldBytes);
|
||||
|
||||
// compHash = SHA1(pSerial || P.x || P.y)
|
||||
SHA1(msgBuffer, SHA_MSG_LENGTH_XP, msgDigest);
|
||||
sha1.CalculateDigest(msgDigest, msgBuffer, SHAMessageLength);
|
||||
|
||||
// Translate the byte digest into a 32-bit integer - this is our computed hash.
|
||||
auto intDigest = IntegerN(msgDigest);
|
||||
if (debug)
|
||||
{
|
||||
fmt::print(debug, "hash: {:x}\n\n", intDigest);
|
||||
}
|
||||
|
||||
info = ki;
|
||||
|
||||
// Translate the byte sha1 into a 32-bit integer - this is our computed hash.
|
||||
// Truncate the hash to 28 bits.
|
||||
DWORD compHash = BYDWORD(msgDigest) >> 4 & BITMASK(28);
|
||||
|
||||
BN_free(e);
|
||||
BN_free(s);
|
||||
|
||||
BN_CTX_free(numContext);
|
||||
|
||||
EC_POINT_free(t);
|
||||
EC_POINT_free(p);
|
||||
Integer compHash = CryptoPP::Crop(intDigest >> 4, 28);
|
||||
|
||||
// If the computed hash checks out, the key is valid.
|
||||
return compHash == info.Hash;
|
||||
return compHash == ki.Hash;
|
||||
}
|
||||
|
@ -29,6 +29,7 @@ class EXPORT BINK1998 : public PIDGEN3
|
||||
{
|
||||
public:
|
||||
using PIDGEN3::PIDGEN3;
|
||||
BINK1998() = default;
|
||||
explicit BINK1998(PIDGEN3 *p3)
|
||||
{
|
||||
privateKey = p3->privateKey;
|
||||
@ -38,17 +39,23 @@ class EXPORT BINK1998 : public PIDGEN3
|
||||
eCurve = p3->eCurve;
|
||||
}
|
||||
|
||||
~BINK1998() override = default;
|
||||
|
||||
static constexpr DWORD32 FieldBits = (48 * 8);
|
||||
static constexpr DWORD32 FieldBytes = (FieldBits / 8);
|
||||
static constexpr DWORD32 SHAMessageLength = (4 + 2 * FieldBytes);
|
||||
|
||||
using PIDGEN3::Pack;
|
||||
BOOL Pack(QWORD *pRaw) override;
|
||||
Integer Pack(const KeyInfo &ki) override;
|
||||
|
||||
using PIDGEN3::Unpack;
|
||||
BOOL Unpack(QWORD *pRaw) override;
|
||||
KeyInfo Unpack(const Integer &raw) override;
|
||||
|
||||
using PIDGEN3::Generate;
|
||||
BOOL Generate(std::string &pKey) override;
|
||||
|
||||
using PIDGEN3::Validate;
|
||||
BOOL Validate(std::string &pKey) override;
|
||||
BOOL Validate(const std::string &pKey) override;
|
||||
};
|
||||
|
||||
#endif // UMSKT_BINK1998_H
|
||||
|
110
src/libumskt/pidgen3/BINK1998_unittest.cpp
Normal file
110
src/libumskt/pidgen3/BINK1998_unittest.cpp
Normal file
@ -0,0 +1,110 @@
|
||||
/**
|
||||
* This file is a part of the UMSKT Project
|
||||
*
|
||||
* Copyleft (C) 2019-2024 UMSKT Contributors (et.al.)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @FileCreated by Neo on 02/19/2024
|
||||
* @Maintainer Neo
|
||||
*/
|
||||
|
||||
#include "../libumskt_unittest.h"
|
||||
#include "BINK1998.h"
|
||||
|
||||
/**
|
||||
* BINK1998 must not be an abstract class.
|
||||
*/
|
||||
TEST(PIDGEN3_BINK1998, InstantiateBINK1998)
|
||||
{
|
||||
auto p3 = new BINK1998();
|
||||
ASSERT_NE(p3, nullptr);
|
||||
delete p3;
|
||||
}
|
||||
|
||||
class TestBINK1998 : public libumsktUnitTests
|
||||
{
|
||||
protected:
|
||||
PIDGEN *p;
|
||||
PIDGEN3 *p3;
|
||||
BINK1998 *bink1998;
|
||||
|
||||
BINK1998::KeyInfo valid_ki = {false, false, 640, 111111, 0};
|
||||
|
||||
void SetUp() override
|
||||
{
|
||||
bink1998 = new BINK1998();
|
||||
bink1998->LoadEllipticCurve("0x2E",
|
||||
"2260481414313563299067995668434431120981995280321627195247220485552475627515144045"
|
||||
"6421260165232069708317717961315241",
|
||||
"1", "0",
|
||||
"1091074492220651278115691316907175015302838688467620894706280834607253141127048943"
|
||||
"2930252839559606812441712224597826",
|
||||
"1917099366991720451749161800061981867915210969017264186834961288993048036527467509"
|
||||
"6509477191800826190959228181870174",
|
||||
"1439923035396364333971294001595406158106423983592682351741971676961393703934682226"
|
||||
"9422480779920783799484349086780408",
|
||||
"5484731395987446993229594927733430043632089703338918322171291299699820472711849119"
|
||||
"800714736923107362018017833200634",
|
||||
"61760995553426173", "37454031876727861");
|
||||
bink1998->info = valid_ki;
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
{
|
||||
if (bink1998 != nullptr)
|
||||
{
|
||||
delete bink1998;
|
||||
bink1998 = nullptr;
|
||||
}
|
||||
if (p3 != nullptr)
|
||||
{
|
||||
delete p3;
|
||||
p3 = nullptr;
|
||||
}
|
||||
if (p != nullptr)
|
||||
{
|
||||
p = nullptr;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(TestBINK1998, ValidateValidKeyString)
|
||||
{
|
||||
std::string pKey;
|
||||
auto ValidateKeyString = bink1998->ValidateKeyString("7KWK7-9W7H4-T64D6-DB8V7-BW7MW", pKey);
|
||||
|
||||
ASSERT_TRUE(ValidateKeyString);
|
||||
ASSERT_STREQ(&pKey[0], "7KWK79W7H4T64D6DB8V7BW7MW");
|
||||
}
|
||||
|
||||
TEST_F(TestBINK1998, ValidateValidKey)
|
||||
{
|
||||
std::string pKey = "7KWK79W7H4T64D6DB8V7BW7MW";
|
||||
|
||||
auto Validate = bink1998->Validate(pKey);
|
||||
ASSERT_TRUE(Validate);
|
||||
}
|
||||
|
||||
TEST_F(TestBINK1998, GenerateValidKey)
|
||||
{
|
||||
bink1998->info.Rand = UMSKT::IntegerS("3427338792529164195109698841758932126727183763685994848291878088992924483488"
|
||||
"5768429236548372772607190036626858221847");
|
||||
|
||||
std::string pKey;
|
||||
bink1998->Generate(pKey);
|
||||
pKey = bink1998->StringifyKey(pKey);
|
||||
|
||||
ASSERT_STREQ(&pKey[0], "7KWK7-9W7H4-T64D6-DB8V7-BW7MW");
|
||||
}
|
@ -24,6 +24,7 @@
|
||||
* and uploaded to GitHub by TheMCHK in August of 2019
|
||||
*
|
||||
* Endermanch (Andrew) rewrote the algorithm in May of 2023
|
||||
* Neo ported Endermanch's algorithm to CryptoPP in February of 2024
|
||||
* }
|
||||
*/
|
||||
|
||||
@ -32,45 +33,53 @@
|
||||
/**
|
||||
* Packs a Windows Server 2003-like Product Key.
|
||||
*
|
||||
* @param pRaw *QWORD[2] raw product key output
|
||||
**/
|
||||
BOOL BINK2002::Pack(QWORD *pRaw)
|
||||
* @param ki PIDGEN3::KeyInfo struct to pack
|
||||
* @return Integer representation of the Product Key
|
||||
*/
|
||||
Integer BINK2002::Pack(const KeyInfo &ki)
|
||||
{
|
||||
// AuthInfo [113..104] <- Signature [103..42] <- Hash [41..11] <- Channel ID [10..1] <- Upgrade [0]
|
||||
pRaw[0] = FIRSTNBITS(info.Signature, 22) << 42 | (QWORD)info.Hash << 11 | info.ChannelID << 1 | info.isUpgrade;
|
||||
pRaw[1] = FIRSTNBITS(info.AuthInfo, 10) << 40 | NEXTSNBITS(info.Signature, 40, 22);
|
||||
// AuthInfo [113..104] <- Signature [103..42] <- Hash [41..11] <- Channel ID [10..1] <- Upgrade [0];
|
||||
Integer raw = CryptoPP::Crop(ki.AuthInfo, 10) << 104 | CryptoPP::Crop(ki.Signature, 62) << 42 |
|
||||
CryptoPP::Crop(ki.Hash, 31) << 11 | CryptoPP::Crop(ki.ChannelID, 10) << 1 | ki.isUpgrade;
|
||||
|
||||
return true;
|
||||
if (debug)
|
||||
{
|
||||
fmt::print(debug, "pack: {:x}\n\n", raw);
|
||||
}
|
||||
|
||||
return raw;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unpacks a Windows Server 2003-like Product Key.
|
||||
*
|
||||
* @param pRaw *QWORD[2] raw product key input
|
||||
**/
|
||||
BOOL BINK2002::Unpack(QWORD *pRaw)
|
||||
* @param raw Integer representation of the product key
|
||||
* @return unpacked PIDGEN3::KeyInfo struct
|
||||
*/
|
||||
BINK2002::KeyInfo BINK2002::Unpack(const Integer &raw)
|
||||
{
|
||||
// We're assuming that the quantity of information within the product key is at most 114 bits.
|
||||
// log2(24^25) = 114.
|
||||
KeyInfo ki;
|
||||
|
||||
// Upgrade = Bit 0
|
||||
info.isUpgrade = FIRSTNBITS(pRaw[0], 1);
|
||||
ki.isUpgrade = CryptoPP::Crop(raw, 1).ConvertToLong();
|
||||
|
||||
// Channel ID = Bits [1..10] -> 10 bits
|
||||
info.ChannelID = NEXTSNBITS(pRaw[0], 10, 1);
|
||||
ki.ChannelID = CryptoPP::Crop(raw >> 1, 10);
|
||||
|
||||
// Hash = Bits [11..41] -> 31 bits
|
||||
info.Hash = NEXTSNBITS(pRaw[0], 31, 11);
|
||||
// Hash = Bits [11..41] -> 30 bits
|
||||
ki.Hash = CryptoPP::Crop(raw >> 11, 31);
|
||||
|
||||
// Signature = Bits [42..103] -> 62 bits
|
||||
// The quad-word signature overlaps AuthInfo in bits 104 and 105,
|
||||
// hence Microsoft employs a secret technique called: Signature = HIDWORD(Signature) >> 2 | LODWORD(Signature)
|
||||
info.Signature = NEXTSNBITS(pRaw[1], 30, 10) << 32 | FIRSTNBITS(pRaw[1], 10) << 22 | NEXTSNBITS(pRaw[0], 22, 42);
|
||||
ki.Signature = CryptoPP::Crop(raw >> 42, 62);
|
||||
|
||||
// AuthInfo = Bits [104..113] -> 10 bits
|
||||
info.AuthInfo = NEXTSNBITS(pRaw[1], 10, 40);
|
||||
ki.AuthInfo = CryptoPP::Crop(raw >> 104, 10);
|
||||
|
||||
return true;
|
||||
return ki;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -82,77 +91,143 @@ BOOL BINK2002::Unpack(QWORD *pRaw)
|
||||
*/
|
||||
BOOL BINK2002::Generate(std::string &pKey)
|
||||
{
|
||||
BN_CTX *numContext = BN_CTX_new();
|
||||
// copy the starting state from the class
|
||||
KeyInfo ki = info;
|
||||
SHA1 sha1;
|
||||
|
||||
BIGNUM *c = BN_CTX_get(numContext), *e = BN_CTX_get(numContext), *s = BN_CTX_get(numContext),
|
||||
*x = BN_CTX_get(numContext), *y = BN_CTX_get(numContext);
|
||||
Integer c, e, s, pRaw;
|
||||
|
||||
QWORD pRaw[2];
|
||||
if (!ki.Rand.IsZero())
|
||||
{
|
||||
c = ki.Rand;
|
||||
}
|
||||
|
||||
// Data segment of the RPK.
|
||||
DWORD pData = info.ChannelID << 1 | info.isUpgrade;
|
||||
Integer pData = ki.ChannelID << 1 | ki.isUpgrade;
|
||||
|
||||
BOOL noSquare;
|
||||
|
||||
do
|
||||
{
|
||||
EC_POINT *r = EC_POINT_new(eCurve);
|
||||
ECP::Point R;
|
||||
|
||||
// Generate a random number c consisting of 512 bits without any constraints.
|
||||
BN_rand(c, FIELD_BITS_2003, BN_RAND_TOP_ANY, BN_RAND_BOTTOM_ANY);
|
||||
if (ki.Rand.IsZero())
|
||||
{
|
||||
// Generate a random number c consisting of 512 bits without any constraints.
|
||||
c.Randomize(UMSKT::rng, FieldBits);
|
||||
}
|
||||
|
||||
// R = cG
|
||||
EC_POINT_mul(eCurve, r, nullptr, genPoint, c, numContext);
|
||||
R = eCurve.Multiply(c, genPoint);
|
||||
if (debug)
|
||||
{
|
||||
fmt::print(debug, "c: {:x}\n\n", c);
|
||||
fmt::print(debug, "R[x,y] [{:x},\n{:x}]\n\n", R.x, R.y);
|
||||
}
|
||||
|
||||
// Acquire its coordinates.
|
||||
// x = R.x; y = R.y;
|
||||
EC_POINT_get_affine_coordinates(eCurve, r, x, y, numContext);
|
||||
|
||||
BYTE msgDigest[SHA_DIGEST_LENGTH], msgBuffer[SHA_MSG_LENGTH_2003], xBin[FIELD_BYTES_2003],
|
||||
yBin[FIELD_BYTES_2003];
|
||||
|
||||
// Convert resulting point coordinates to bytes.
|
||||
UMSKT::BN_bn2lebin(x, xBin, FIELD_BYTES_2003);
|
||||
UMSKT::BN_bn2lebin(y, yBin, FIELD_BYTES_2003);
|
||||
BYTE msgDigest[SHA1::DIGESTSIZE], msgBuffer[SHAMessageLength], *pMsgBuffer = msgBuffer;
|
||||
|
||||
// Assemble the first SHA message.
|
||||
msgBuffer[0x00] = 0x79;
|
||||
msgBuffer[0x01] = (pData & 0x00FF);
|
||||
msgBuffer[0x02] = (pData & 0xFF00) >> 8;
|
||||
*pMsgBuffer = 0x79;
|
||||
pMsgBuffer++;
|
||||
|
||||
memcpy(&msgBuffer[3], xBin, FIELD_BYTES_2003);
|
||||
memcpy(&msgBuffer[3 + FIELD_BYTES_2003], yBin, FIELD_BYTES_2003);
|
||||
pMsgBuffer = EncodeN(pData, pMsgBuffer, 2);
|
||||
|
||||
// Convert resulting point coordinates to bytes.
|
||||
// and flip the endianness
|
||||
pMsgBuffer = EncodeN(R.x, pMsgBuffer, FieldBytes);
|
||||
EncodeN(R.y, pMsgBuffer, FieldBytes);
|
||||
|
||||
// pHash = SHA1(79 || Channel ID || R.x || R.y)
|
||||
SHA1(msgBuffer, SHA_MSG_LENGTH_2003, msgDigest);
|
||||
sha1.CalculateDigest(msgDigest, msgBuffer, SHAMessageLength);
|
||||
|
||||
// Translate the byte digest into a 32-bit integer - this is our computed hash.
|
||||
if (debug)
|
||||
{
|
||||
fmt::print(debug, "msgBuffer[1]: ");
|
||||
for (BYTE b : msgBuffer)
|
||||
{
|
||||
fmt::print(debug, "{:x}", b);
|
||||
}
|
||||
fmt::print(debug, "\n\n");
|
||||
|
||||
fmt::print(debug, "msgDigest[1]: ");
|
||||
for (BYTE b : msgDigest)
|
||||
{
|
||||
fmt::print(debug, "{:x}", b);
|
||||
}
|
||||
fmt::print(debug, "\n\n");
|
||||
}
|
||||
|
||||
// Translate the byte sha1 into a 32-bit integer - this is our computed hash.
|
||||
// Truncate the hash to 31 bits.
|
||||
info.Hash = BYDWORD(msgDigest) & BITMASK(31);
|
||||
ki.Hash = CryptoPP::Crop(IntegerN(msgDigest), 31);
|
||||
|
||||
if (verbose)
|
||||
{
|
||||
BYTE buf[8];
|
||||
sha1.CalculateTruncatedDigest(buf, sizeof(buf), msgBuffer, SHAMessageLength);
|
||||
|
||||
fmt::print(verbose, "truncated buffer: ");
|
||||
for (BYTE b : buf)
|
||||
{
|
||||
fmt::print(verbose, "{:x}", b);
|
||||
}
|
||||
fmt::print(verbose, "\n\n");
|
||||
|
||||
DWORD h0 = ((DWORD)buf[0] | ((DWORD)buf[1] << 8) | ((DWORD)buf[2] << 16) | ((DWORD)buf[3] << 24));
|
||||
DWORD h1 =
|
||||
((((DWORD)buf[4]) | ((DWORD)buf[5] << 8) | ((DWORD)buf[6] << 16) | ((DWORD)buf[7] << 24)) >> (32 - 19))
|
||||
<< 1;
|
||||
|
||||
h1 |= (h0 >> 31) & 1;
|
||||
|
||||
fmt::print(verbose, "h0,1: {:x} {:x}\n\n", h0, h1);
|
||||
|
||||
ki.Serial = IntegerN(h1);
|
||||
|
||||
fmt::print(verbose, "serial: {:d}\n\n", ki.Serial);
|
||||
}
|
||||
|
||||
// Assemble the second SHA message.
|
||||
pMsgBuffer = msgBuffer;
|
||||
msgBuffer[0x00] = 0x5D;
|
||||
msgBuffer[0x01] = (pData & 0x00FF);
|
||||
msgBuffer[0x02] = (pData & 0xFF00) >> 8;
|
||||
msgBuffer[0x03] = (info.Hash & 0x000000FF);
|
||||
msgBuffer[0x04] = (info.Hash & 0x0000FF00) >> 8;
|
||||
msgBuffer[0x05] = (info.Hash & 0x00FF0000) >> 16;
|
||||
msgBuffer[0x06] = (info.Hash & 0xFF000000) >> 24;
|
||||
msgBuffer[0x07] = (info.AuthInfo & 0x00FF);
|
||||
msgBuffer[0x08] = (info.AuthInfo & 0xFF00) >> 8;
|
||||
msgBuffer[0x09] = 0x00;
|
||||
msgBuffer[0x0A] = 0x00;
|
||||
pMsgBuffer++;
|
||||
|
||||
pMsgBuffer = EncodeN(pData, pMsgBuffer, 2);
|
||||
pMsgBuffer = EncodeN(ki.Hash, pMsgBuffer, 4);
|
||||
pMsgBuffer = EncodeN(ki.AuthInfo, pMsgBuffer, 2);
|
||||
|
||||
*pMsgBuffer = 0x00;
|
||||
pMsgBuffer++;
|
||||
|
||||
*pMsgBuffer = 0x00;
|
||||
pMsgBuffer++;
|
||||
|
||||
// newSignature = SHA1(5D || Channel ID || Hash || AuthInfo || 00 00)
|
||||
SHA1(msgBuffer, 11, msgDigest);
|
||||
sha1.CalculateDigest(msgDigest, msgBuffer, pMsgBuffer - msgBuffer);
|
||||
|
||||
// Translate the byte digest into a 64-bit integer - this is our computed intermediate signature.
|
||||
if (debug)
|
||||
{
|
||||
fmt::print(debug, "msgBuffer[2]: ");
|
||||
for (BYTE b : msgBuffer)
|
||||
{
|
||||
fmt::print(debug, "{:x}", b);
|
||||
}
|
||||
fmt::print(debug, "\n\n");
|
||||
|
||||
fmt::print(debug, "msgDigest[2]: ");
|
||||
for (BYTE b : msgDigest)
|
||||
{
|
||||
fmt::print(debug, "{:x}", b);
|
||||
}
|
||||
fmt::print(debug, "\n\n");
|
||||
}
|
||||
|
||||
// Translate the byte sha1 into a 64-bit integer - this is our computed intermediate signature.
|
||||
// As the signature is only 62 bits long at most, we have to truncate it by shifting the high DWORD right 2
|
||||
// bits (per spec).
|
||||
QWORD iSignature = NEXTSNBITS(BYDWORD(&msgDigest[4]), 30, 2) << 32 | BYDWORD(msgDigest);
|
||||
|
||||
BN_lebin2bn((BYTE *)&iSignature, sizeof(iSignature), e);
|
||||
|
||||
/*
|
||||
*
|
||||
* Scalars:
|
||||
@ -183,63 +258,62 @@ BOOL BINK2002::Generate(std::string &pKey)
|
||||
*/
|
||||
|
||||
// e = ek (mod n)
|
||||
BN_mod_mul(e, e, privateKey, genOrder, numContext);
|
||||
|
||||
// s = e
|
||||
BN_copy(s, e);
|
||||
e = CryptoPP::ModularMultiplication(IntegerN(iSignature), privateKey, genOrder);
|
||||
|
||||
// s = (ek (mod n))²
|
||||
BN_mod_sqr(s, s, genOrder, numContext);
|
||||
s = CryptoPP::ModularExponentiation(e, Integer::Two(), genOrder);
|
||||
|
||||
// c *= 4 (c <<= 2)
|
||||
BN_lshift(c, c, 2);
|
||||
c *= 4;
|
||||
|
||||
// s += c
|
||||
BN_add(s, s, c);
|
||||
s += c;
|
||||
|
||||
// Around half of numbers modulo a prime are not squares -> BN_sqrt_mod fails about half of the times,
|
||||
// hence if BN_sqrt_mod returns NULL, we need to restart with a different seed.
|
||||
// s = √((ek)² + 4c (mod n))
|
||||
noSquare = BN_mod_sqrt(s, s, genOrder, numContext) == nullptr;
|
||||
s = CryptoPP::ModularSquareRoot(s, genOrder);
|
||||
noSquare = s.IsZero();
|
||||
|
||||
// s = -ek + √((ek)² + 4c) (mod n)
|
||||
BN_mod_sub(s, s, e, genOrder, numContext);
|
||||
s -= e;
|
||||
s %= genOrder;
|
||||
|
||||
// If s is odd, add order to it.
|
||||
// The order is a prime, so it can't be even.
|
||||
if (BN_is_odd(s))
|
||||
if (s % Integer::Two() != 0)
|
||||
{
|
||||
// s = -ek + √((ek)² + 4c) + n
|
||||
BN_add(s, s, genOrder);
|
||||
s += genOrder;
|
||||
}
|
||||
|
||||
// s /= 2 (s >>= 1)
|
||||
BN_rshift1(s, s);
|
||||
s /= 2;
|
||||
|
||||
// Translate resulting scalar into a 64-bit integer (the byte order is little-endian).
|
||||
BN_bn2lebinpad(s, (BYTE *)&info.Signature, BN_num_bytes(s));
|
||||
ki.Signature = s;
|
||||
|
||||
// Pack product key.
|
||||
Pack(pRaw);
|
||||
pRaw = Pack(ki);
|
||||
|
||||
fmt::print(UMSKT::debug, "Generation results:\n");
|
||||
fmt::print(UMSKT::debug, "{:>10}: {:b}\n", "Upgrade", (bool)info.isUpgrade);
|
||||
fmt::print(UMSKT::debug, "{:>10}: {:d}\n", "Channel ID", info.ChannelID);
|
||||
fmt::print(UMSKT::debug, "{:>10}: {:d}\n", "Hash", info.Hash);
|
||||
fmt::print(UMSKT::debug, "{:>10}: {:d}\n", "Signature", info.Signature);
|
||||
fmt::print(UMSKT::debug, "{:>10}: {:d}\n", "AuthInfo", info.AuthInfo);
|
||||
fmt::print(UMSKT::debug, "\n");
|
||||
|
||||
EC_POINT_free(r);
|
||||
} while (info.Signature > BITMASK(62) || noSquare);
|
||||
if (verbose)
|
||||
{
|
||||
fmt::print(verbose, "Generation results:\n");
|
||||
fmt::print(verbose, "{:>10}: {}\n", "Upgrade", (bool)ki.isUpgrade);
|
||||
fmt::print(verbose, "{:>10}: {}\n", "Channel ID", ki.ChannelID);
|
||||
fmt::print(verbose, "{:>10}: {:x}\n", "Hash", ki.Hash);
|
||||
fmt::print(verbose, "{:>10}: {:x}\n", "Signature", ki.Signature);
|
||||
fmt::print(verbose, "{:>10}: {:x}\n", "AuthInfo", ki.AuthInfo);
|
||||
fmt::print(verbose, "\n");
|
||||
}
|
||||
} while ((ki.Signature.BitCount() > 62 || noSquare) && ki.Rand.IsZero());
|
||||
// ↑ ↑ ↑
|
||||
// The signature can't be longer than 62 bits, else it will
|
||||
// overlap with the AuthInfo segment next to it.
|
||||
|
||||
// Convert bytecode to Base24 CD-key.
|
||||
base24(pKey, (BYTE *)pRaw);
|
||||
pKey = base24(pRaw);
|
||||
|
||||
BN_CTX_free(numContext);
|
||||
info = ki;
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -249,47 +323,56 @@ BOOL BINK2002::Generate(std::string &pKey)
|
||||
*
|
||||
* @param pKey
|
||||
**/
|
||||
BOOL BINK2002::Validate(std::string &pKey)
|
||||
BOOL BINK2002::Validate(const std::string &pKey)
|
||||
{
|
||||
BN_CTX *context = BN_CTX_new();
|
||||
|
||||
QWORD bKey[2];
|
||||
Integer pRaw;
|
||||
SHA1 sha1;
|
||||
|
||||
// Convert Base24 CD-key to bytecode.
|
||||
unbase24((BYTE *)bKey, &pKey[0]);
|
||||
pRaw = unbase24(pKey);
|
||||
|
||||
// Extract product key segments from bytecode.
|
||||
Unpack(bKey);
|
||||
KeyInfo ki = Unpack(pRaw);
|
||||
|
||||
DWORD pData = info.ChannelID << 1 | info.isUpgrade;
|
||||
Integer pData = ki.ChannelID << 1 | ki.isUpgrade;
|
||||
|
||||
fmt::print(UMSKT::debug, "Validation results:\n");
|
||||
fmt::print(UMSKT::debug, "{:>10}: {:b}\n", "Upgrade", (bool)info.isUpgrade);
|
||||
fmt::print(UMSKT::debug, "{:>10}: {:d}\n", "Channel ID", info.ChannelID);
|
||||
fmt::print(UMSKT::debug, "{:>10}: {:d}\n", "Hash", info.Hash);
|
||||
fmt::print(UMSKT::debug, "{:>10}: {:d}\n", "Signature", info.Signature);
|
||||
fmt::print(UMSKT::debug, "{:>10}: {:d}\n", "AuthInfo", info.AuthInfo);
|
||||
fmt::print(UMSKT::debug, "\n");
|
||||
if (verbose)
|
||||
{
|
||||
fmt::print(verbose, "Validation results:\n");
|
||||
fmt::print(verbose, "{:>10}: {}\n", "Upgrade", (bool)ki.isUpgrade);
|
||||
fmt::print(verbose, "{:>10}: {}\n", "Channel ID", ki.ChannelID);
|
||||
fmt::print(verbose, "{:>10}: {:x}\n", "Hash", ki.Hash);
|
||||
fmt::print(verbose, "{:>10}: {:x}\n", "Signature", ki.Signature);
|
||||
fmt::print(verbose, "{:>10}: {:x}\n", "AuthInfo", ki.AuthInfo);
|
||||
fmt::print(verbose, "\n");
|
||||
}
|
||||
|
||||
BYTE msgDigest[SHA_DIGEST_LENGTH], msgBuffer[SHA_MSG_LENGTH_2003], xBin[FIELD_BYTES_2003], yBin[FIELD_BYTES_2003];
|
||||
BYTE msgDigest[SHA1::DIGESTSIZE], msgBuffer[SHAMessageLength], *pMsgBuffer = msgBuffer;
|
||||
|
||||
// Assemble the first SHA message.
|
||||
msgBuffer[0x00] = 0x5D;
|
||||
msgBuffer[0x01] = (pData & 0x00FF);
|
||||
msgBuffer[0x02] = (pData & 0xFF00) >> 8;
|
||||
msgBuffer[0x03] = (info.Hash & 0x000000FF);
|
||||
msgBuffer[0x04] = (info.Hash & 0x0000FF00) >> 8;
|
||||
msgBuffer[0x05] = (info.Hash & 0x00FF0000) >> 16;
|
||||
msgBuffer[0x06] = (info.Hash & 0xFF000000) >> 24;
|
||||
msgBuffer[0x07] = (info.AuthInfo & 0x00FF);
|
||||
msgBuffer[0x08] = (info.AuthInfo & 0xFF00) >> 8;
|
||||
msgBuffer[0x09] = 0x00;
|
||||
msgBuffer[0x0A] = 0x00;
|
||||
pMsgBuffer++;
|
||||
|
||||
pMsgBuffer = EncodeN(pData, pMsgBuffer, 2);
|
||||
pMsgBuffer = EncodeN(ki.Hash, pMsgBuffer, 4);
|
||||
pMsgBuffer = EncodeN(ki.AuthInfo, pMsgBuffer, 2);
|
||||
|
||||
*pMsgBuffer = 0x00;
|
||||
pMsgBuffer++;
|
||||
|
||||
*pMsgBuffer = 0x00;
|
||||
pMsgBuffer++;
|
||||
|
||||
// newSignature = SHA1(5D || Channel ID || Hash || AuthInfo || 00 00)
|
||||
SHA1(msgBuffer, 11, msgDigest);
|
||||
sha1.CalculateDigest(msgDigest, msgBuffer, pMsgBuffer - msgBuffer);
|
||||
|
||||
// Translate the byte digest into a 64-bit integer - this is our computed intermediate signature.
|
||||
if (debug)
|
||||
{
|
||||
auto intDigest = IntegerN(msgDigest);
|
||||
fmt::print(debug, "\nhash 1: {:x}\n\n", intDigest);
|
||||
}
|
||||
|
||||
// Translate the byte sha1 into a 64-bit integer - this is our computed intermediate signature.
|
||||
// As the signature is only 62 bits long at most, we have to truncate it by shifting the high DWORD right 2 bits
|
||||
// (per spec).
|
||||
QWORD iSignature = NEXTSNBITS(BYDWORD(&msgDigest[4]), 30, 2) << 32 | BYDWORD(msgDigest);
|
||||
@ -308,56 +391,52 @@ BOOL BINK2002::Validate(std::string &pKey)
|
||||
* P = s(sG + eK)
|
||||
*
|
||||
*/
|
||||
|
||||
BIGNUM *e = BN_lebin2bn((BYTE *)&iSignature, sizeof(iSignature), nullptr),
|
||||
*s = BN_lebin2bn((BYTE *)&info.Signature, sizeof(info.Signature), nullptr);
|
||||
BIGNUM *x = BN_CTX_get(context), *y = BN_CTX_get(context);
|
||||
Integer e = IntegerN(iSignature), s = ki.Signature;
|
||||
|
||||
// Create 2 points on the elliptic curve.
|
||||
EC_POINT *p = EC_POINT_new(eCurve), *t = EC_POINT_new(eCurve);
|
||||
ECP::Point P, t;
|
||||
|
||||
// t = sG
|
||||
EC_POINT_mul(eCurve, t, nullptr, genPoint, s, context);
|
||||
t = eCurve.Multiply(s, genPoint);
|
||||
|
||||
// p = eK
|
||||
EC_POINT_mul(eCurve, p, nullptr, pubPoint, e, context);
|
||||
// P = eK
|
||||
P = eCurve.Multiply(e, pubPoint);
|
||||
|
||||
// p += t
|
||||
EC_POINT_add(eCurve, p, t, p, context);
|
||||
// P += t
|
||||
P = eCurve.Add(P, t);
|
||||
|
||||
// p *= s
|
||||
EC_POINT_mul(eCurve, p, nullptr, p, s, context);
|
||||
// P *= s
|
||||
P = eCurve.Multiply(s, P);
|
||||
|
||||
// x = p.x; y = p.y;
|
||||
EC_POINT_get_affine_coordinates(eCurve, p, x, y, context);
|
||||
|
||||
// Convert resulting point coordinates to bytes.
|
||||
UMSKT::BN_bn2lebin(x, xBin, FIELD_BYTES_2003);
|
||||
UMSKT::BN_bn2lebin(y, yBin, FIELD_BYTES_2003);
|
||||
if (debug)
|
||||
{
|
||||
fmt::print(debug, "P[x,y]: [{:x},\n{:x}]\n\n", P.x, P.y);
|
||||
}
|
||||
|
||||
// Assemble the second SHA message.
|
||||
pMsgBuffer = msgBuffer;
|
||||
msgBuffer[0x00] = 0x79;
|
||||
msgBuffer[0x01] = (pData & 0x00FF);
|
||||
msgBuffer[0x02] = (pData & 0xFF00) >> 8;
|
||||
pMsgBuffer++;
|
||||
|
||||
memcpy((void *)&msgBuffer[3], (void *)xBin, FIELD_BYTES_2003);
|
||||
memcpy((void *)&msgBuffer[3 + FIELD_BYTES_2003], (void *)yBin, FIELD_BYTES_2003);
|
||||
pMsgBuffer = EncodeN(pData, pMsgBuffer, 2);
|
||||
pMsgBuffer = EncodeN(P.x, pMsgBuffer, FieldBytes);
|
||||
EncodeN(P.y, pMsgBuffer, FieldBytes);
|
||||
|
||||
// compHash = SHA1(79 || Channel ID || p.x || p.y)
|
||||
SHA1(msgBuffer, SHA_MSG_LENGTH_2003, msgDigest);
|
||||
// compHash = SHA1(79 || Channel ID || P.x || P.y)
|
||||
sha1.CalculateDigest(msgDigest, msgBuffer, SHAMessageLength);
|
||||
|
||||
// Translate the byte digest into a 32-bit integer - this is our computed hash.
|
||||
auto intDigest = IntegerN(msgDigest);
|
||||
if (debug)
|
||||
{
|
||||
fmt::print(debug, "hash 2: {:x}\n\n", intDigest);
|
||||
}
|
||||
|
||||
// Translate the byte sha1 into a 32-bit integer - this is our computed hash.
|
||||
// Truncate the hash to 31 bits.
|
||||
DWORD compHash = BYDWORD(msgDigest) & BITMASK(31);
|
||||
Integer compHash = CryptoPP::Crop(intDigest, 31);
|
||||
|
||||
BN_free(s);
|
||||
BN_free(e);
|
||||
|
||||
EC_POINT_free(p);
|
||||
EC_POINT_free(t);
|
||||
|
||||
BN_CTX_free(context);
|
||||
info = ki;
|
||||
|
||||
// If the computed hash checks out, the key is valid.
|
||||
return compHash == info.Hash;
|
||||
return compHash == ki.Hash;
|
||||
}
|
||||
|
@ -29,6 +29,7 @@ class EXPORT BINK2002 : public PIDGEN3
|
||||
{
|
||||
public:
|
||||
using PIDGEN3::PIDGEN3;
|
||||
BINK2002() = default;
|
||||
explicit BINK2002(PIDGEN3 *p3)
|
||||
{
|
||||
privateKey = p3->privateKey;
|
||||
@ -38,17 +39,23 @@ class EXPORT BINK2002 : public PIDGEN3
|
||||
eCurve = p3->eCurve;
|
||||
}
|
||||
|
||||
~BINK2002() override = default;
|
||||
|
||||
static constexpr DWORD32 FieldBits = (64 * 8);
|
||||
static constexpr DWORD32 FieldBytes = (FieldBits / 8);
|
||||
static constexpr DWORD32 SHAMessageLength = (3 + 2 * FieldBytes);
|
||||
|
||||
using PIDGEN3::Pack;
|
||||
BOOL Pack(QWORD *pRaw) override;
|
||||
Integer Pack(const KeyInfo &ki) override;
|
||||
|
||||
using PIDGEN3::Unpack;
|
||||
BOOL Unpack(QWORD *pRaw) override;
|
||||
KeyInfo Unpack(const Integer &raw) override;
|
||||
|
||||
using PIDGEN3::Generate;
|
||||
BOOL Generate(std::string &pKey) override;
|
||||
|
||||
using PIDGEN3::Validate;
|
||||
BOOL Validate(std::string &pKey) override;
|
||||
BOOL Validate(const std::string &pKey) override;
|
||||
};
|
||||
|
||||
#endif // UMSKT_BINK2002_H
|
||||
|
121
src/libumskt/pidgen3/BINK2002_unittest.cpp
Normal file
121
src/libumskt/pidgen3/BINK2002_unittest.cpp
Normal file
@ -0,0 +1,121 @@
|
||||
/**
|
||||
* This file is a part of the UMSKT Project
|
||||
*
|
||||
* Copyleft (C) 2019-2024 UMSKT Contributors (et.al.)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @FileCreated by Neo on 02/19/2024
|
||||
* @Maintainer Neo
|
||||
*/
|
||||
|
||||
#include "BINK2002.h"
|
||||
#include <libumskt/libumskt_unittest.h>
|
||||
|
||||
/**
|
||||
* BINK2002 must not be an abstract class.
|
||||
*/
|
||||
TEST(PIDGEN3_BINK2002, InstantiateBINK2002)
|
||||
{
|
||||
auto p3 = new BINK2002();
|
||||
ASSERT_NE(p3, nullptr);
|
||||
delete p3;
|
||||
}
|
||||
|
||||
class TestBINK2002 : public libumsktUnitTests
|
||||
{
|
||||
protected:
|
||||
PIDGEN *p;
|
||||
PIDGEN3 *p3;
|
||||
BINK2002 *bink2002;
|
||||
|
||||
BINK2002::KeyInfo valid_ki = {false, false, 640, 0, 701};
|
||||
|
||||
void SetUp() override
|
||||
{
|
||||
bink2002 = new BINK2002();
|
||||
bink2002->LoadEllipticCurve("0x54",
|
||||
"1250964251969733259611431105354461862074700938981465222536952118871017192617497641"
|
||||
"9995384745134703589248167610052719613586668754176591418831031596093374569",
|
||||
"1", "0",
|
||||
"8059057663701168311917532277618827622978515614146963913097592614451721430413021070"
|
||||
"395782723330339842826599481063797559797462512297834269467666807971588275",
|
||||
"1223930383017475319177970597922037862339473226753699711562597963240231208768364492"
|
||||
"7405756146495100825573682155171145924668759419114616275413724686284123408",
|
||||
"4895832170509729140211911021638266775170167022247175324972987673313207244495397975"
|
||||
"379010973250279668424167408883454560376269866102669741515127286188717976",
|
||||
"5846013328426281815512452704859777850382010968846722453046994319336479079120767834"
|
||||
"777937190955827245502389471872759584209649693396095099112777776298051208",
|
||||
"5622613991231344109", "1285511085175426271");
|
||||
bink2002->info = valid_ki;
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
{
|
||||
if (bink2002 != nullptr)
|
||||
{
|
||||
delete bink2002;
|
||||
bink2002 = nullptr;
|
||||
}
|
||||
if (p3 != nullptr)
|
||||
{
|
||||
delete p3;
|
||||
p3 = nullptr;
|
||||
}
|
||||
if (p != nullptr)
|
||||
{
|
||||
p = nullptr;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(TestBINK2002, ValidateValidKeyString)
|
||||
{
|
||||
std::string pKey;
|
||||
auto ValidateKeyString = bink2002->ValidateKeyString("QX7C7-6668G-RHTTC-9XXD6-4QKVM", pKey);
|
||||
ASSERT_TRUE(ValidateKeyString);
|
||||
ASSERT_STREQ(&pKey[0], "QX7C76668GRHTTC9XXD64QKVM");
|
||||
}
|
||||
|
||||
TEST_F(TestBINK2002, ValidateInvalidKeyString)
|
||||
{
|
||||
std::string pKey;
|
||||
auto ValidateKeyString = bink2002->ValidateKeyString("QX7C7-6668G-RHTTC-9XXD6-4QKVM-7", pKey);
|
||||
ASSERT_FALSE(ValidateKeyString);
|
||||
}
|
||||
|
||||
TEST_F(TestBINK2002, ValidateValidKey)
|
||||
{
|
||||
std::string pKey = "QX7C76668GRHTTC9XXD64QKVM";
|
||||
auto Validate = bink2002->Validate(pKey);
|
||||
ASSERT_TRUE(Validate);
|
||||
}
|
||||
|
||||
TEST_F(TestBINK2002, ValidateInvalidKey)
|
||||
{
|
||||
std::string pKey = "QX7C76668GRHTTC9XXD64QKV7";
|
||||
auto Validate = bink2002->Validate(pKey);
|
||||
ASSERT_FALSE(Validate);
|
||||
}
|
||||
|
||||
TEST_F(TestBINK2002, GenerateValidKey)
|
||||
{
|
||||
bink2002->info.Rand = UMSKT::IntegerS("2715417548459431244234182116258933974639514924173191881913315754156057922856"
|
||||
"789413383072541627152533502894944768632184791880876163762899980230935");
|
||||
std::string pKey;
|
||||
bink2002->Generate(pKey);
|
||||
pKey = bink2002->StringifyKey(pKey);
|
||||
|
||||
ASSERT_STREQ(&pKey[0], "QX7C7-6668G-RHTTC-9XXD6-4QKVM");
|
||||
}
|
@ -25,7 +25,19 @@
|
||||
#include "BINK2002.h"
|
||||
|
||||
/**
|
||||
* https://xkcd.com/221/
|
||||
* PID 3.0 Product Key Character Set
|
||||
*/
|
||||
const std::string PIDGEN3::pKeyCharset = "BCDFGHJKMPQRTVWXY2346789";
|
||||
|
||||
/**
|
||||
* Maximum Field size for BINK 1998
|
||||
*/
|
||||
const DWORD32 PIDGEN3::MaxSizeBINK1998 = BINK1998::FieldBits + 1;
|
||||
|
||||
/**
|
||||
* RFC 1149.5 specifies 4 as the standard IEEE-vetted random number.
|
||||
*
|
||||
* see also: https://xkcd.com/221/
|
||||
*
|
||||
* @return 4
|
||||
*/
|
||||
@ -50,10 +62,11 @@ int getRandomNumber()
|
||||
*
|
||||
* @return true on success, false on fail
|
||||
*/
|
||||
BOOL PIDGEN3::LoadEllipticCurve(const std::string pSel, const std::string aSel, const std::string bSel,
|
||||
const std::string generatorXSel, const std::string generatorYSel,
|
||||
const std::string publicKeyXSel, const std::string publicKeyYSel,
|
||||
const std::string genOrderSel, const std::string privateKeySel)
|
||||
BOOL PIDGEN3::LoadEllipticCurve(const std::string &BinkIDSel, const std::string &pSel, const std::string &aSel,
|
||||
const std::string &bSel, const std::string &generatorXSel,
|
||||
const std::string &generatorYSel, const std::string &publicKeyXSel,
|
||||
const std::string &publicKeyYSel, const std::string &genOrderSel,
|
||||
const std::string &privateKeySel)
|
||||
{
|
||||
// We cannot produce a valid key without knowing the private key k. The reason for this is that
|
||||
// we need the result of the function K(x; y) = kG(x; y).
|
||||
@ -61,217 +74,243 @@ BOOL PIDGEN3::LoadEllipticCurve(const std::string pSel, const std::string aSel,
|
||||
// We can, however, validate any given key using the available public key: {p, a, b, G, K}.
|
||||
// genOrder the order of the generator G, a value we have to reverse -> Schoof's Algorithm.
|
||||
|
||||
// Initialize BIGNUM and BIGNUMCTX structures.
|
||||
// BIGNUM - Large numbers
|
||||
// BIGNUMCTX - Context large numbers (temporary)
|
||||
|
||||
// Context variable
|
||||
BN_CTX *context = BN_CTX_new();
|
||||
BINKID = IntegerHexS(BinkIDSel);
|
||||
|
||||
// We're presented with an elliptic curve, a multivariable function y(x; p; a; b), where
|
||||
// y^2 % p = x^3 + ax + b % p.
|
||||
BIGNUM *a = BN_CTX_get(context), *b = BN_CTX_get(context), *p = BN_CTX_get(context);
|
||||
auto p = IntegerS(pSel), a = IntegerS(aSel), b = IntegerS(bSel);
|
||||
|
||||
// Public key will consist of the resulting (x; y) values.
|
||||
BIGNUM *publicKeyX = BN_CTX_get(context), *publicKeyY = BN_CTX_get(context);
|
||||
auto generatorX = IntegerS(generatorXSel), generatorY = IntegerS(generatorYSel);
|
||||
|
||||
// G(x; y) is a generator function, its return value represents a point on the elliptic curve.
|
||||
BIGNUM *generatorX = BN_CTX_get(context), *generatorY = BN_CTX_get(context);
|
||||
|
||||
genOrder = BN_new();
|
||||
privateKey = BN_new();
|
||||
|
||||
/* Public data */
|
||||
BN_dec2bn(&p, &pSel[0]);
|
||||
BN_dec2bn(&a, &aSel[0]);
|
||||
BN_dec2bn(&b, &bSel[0]);
|
||||
BN_dec2bn(&generatorX, &generatorXSel[0]);
|
||||
BN_dec2bn(&generatorY, &generatorYSel[0]);
|
||||
|
||||
BN_dec2bn(&publicKeyX, &publicKeyXSel[0]);
|
||||
BN_dec2bn(&publicKeyY, &publicKeyYSel[0]);
|
||||
auto publicKeyX = IntegerS(publicKeyXSel), publicKeyY = IntegerS(publicKeyYSel);
|
||||
|
||||
/* Computed Data */
|
||||
BN_dec2bn(&genOrder, &genOrderSel[0]);
|
||||
BN_dec2bn(&privateKey, &privateKeySel[0]);
|
||||
genOrder = IntegerS(genOrderSel);
|
||||
privateKey = IntegerS(privateKeySel);
|
||||
|
||||
/* Elliptic Curve calculations. */
|
||||
// The group is defined via Fp = all integers [0; p - 1], where p is prime.
|
||||
// The function EC_POINT_set_affine_coordinates() sets the x and y coordinates for the point p defined over the
|
||||
// curve given in group.
|
||||
eCurve = EC_GROUP_new_curve_GFp(p, a, b, context);
|
||||
eCurve = ECP(p, a, b);
|
||||
|
||||
// Create new point for the generator on the elliptic curve and set its coordinates to (genX; genY).
|
||||
genPoint = EC_POINT_new(eCurve);
|
||||
EC_POINT_set_affine_coordinates(eCurve, genPoint, generatorX, generatorY, context);
|
||||
// Create new point N for the generator on the elliptic curve and set its coordinates to (genX; genY).
|
||||
genPoint = ECP::Point(generatorX, generatorY);
|
||||
|
||||
// Create new point for the public key on the elliptic curve and set its coordinates to (pubX; pubY).
|
||||
pubPoint = EC_POINT_new(eCurve);
|
||||
EC_POINT_set_affine_coordinates(eCurve, pubPoint, publicKeyX, publicKeyY, context);
|
||||
// Create new point Q for the public key on the elliptic curve and set its coordinates to (pubX; pubY).
|
||||
pubPoint = ECP::Point(publicKeyX, publicKeyY);
|
||||
|
||||
// If generator and public key points are not on the elliptic curve, either the generator or the public key values
|
||||
// are incorrect.
|
||||
assert(EC_POINT_is_on_curve(eCurve, genPoint, context) == true);
|
||||
assert(EC_POINT_is_on_curve(eCurve, pubPoint, context) == true);
|
||||
|
||||
// Cleanup
|
||||
BN_CTX_free(context);
|
||||
assert(eCurve.VerifyPoint(genPoint) == true);
|
||||
assert(eCurve.VerifyPoint(pubPoint) == true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
BOOL PIDGEN3::Generate(std::string &pKey)
|
||||
/**
|
||||
* Instantiates a PID 3.0 generator based on a given field on the heap
|
||||
*
|
||||
* @param field
|
||||
* @return PIDGEN3 based on the field type
|
||||
*/
|
||||
PIDGEN3 *PIDGEN3::Factory(const std::string &field)
|
||||
{
|
||||
BOOL retval;
|
||||
|
||||
if (checkFieldIsBink1998())
|
||||
if (checkFieldStrIsBink1998(field))
|
||||
{
|
||||
auto p3 = BINK1998();
|
||||
retval = p3.Generate(pKey);
|
||||
return new BINK1998();
|
||||
}
|
||||
else
|
||||
{
|
||||
auto p3 = BINK2002();
|
||||
retval = p3.Generate(pKey);
|
||||
}
|
||||
|
||||
return retval;
|
||||
return new BINK2002();
|
||||
}
|
||||
|
||||
BOOL PIDGEN3::Validate(std::string &pKey)
|
||||
/**
|
||||
* Factory-style Generate function, checks the currently instantiated field
|
||||
* creates the correct PIDGEN for the field type using the copy constructor
|
||||
* and invokes its Generate()
|
||||
*
|
||||
* @param pKey
|
||||
* @return successfulness
|
||||
*/
|
||||
BOOL PIDGEN3::Generate(std::string &pKey)
|
||||
{
|
||||
BOOL retval;
|
||||
|
||||
if (checkFieldIsBink1998())
|
||||
{
|
||||
auto p3 = BINK1998(this);
|
||||
retval = p3.Validate(pKey);
|
||||
}
|
||||
else
|
||||
{
|
||||
auto p3 = BINK2002(this);
|
||||
retval = p3.Validate(pKey);
|
||||
return p3.Generate(pKey);
|
||||
}
|
||||
|
||||
return retval;
|
||||
auto p3 = BINK2002(this);
|
||||
return p3.Generate(pKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory style Validate function, see Generate() for more info
|
||||
*
|
||||
* @param pKey
|
||||
* @return successfulness
|
||||
*/
|
||||
BOOL PIDGEN3::Validate(const std::string &pKey)
|
||||
{
|
||||
if (checkFieldIsBink1998())
|
||||
{
|
||||
auto p3 = BINK1998(this);
|
||||
return p3.Validate(pKey);
|
||||
}
|
||||
|
||||
auto p3 = BINK2002(this);
|
||||
return p3.Validate(pKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts from byte sequence to the CD-key.
|
||||
*
|
||||
* @param cdKey [out] std::string CDKey input
|
||||
* @param byteSeq [in] BYTE*
|
||||
* @param seq Integer representation
|
||||
* @return std::string CDKey output
|
||||
**/
|
||||
void PIDGEN3::base24(std::string &cdKey, BYTE *byteSeq)
|
||||
std::string PIDGEN3::base24(Integer &seq)
|
||||
{
|
||||
BYTE rbyteSeq[16], output[26];
|
||||
BIGNUM *z;
|
||||
|
||||
// Copy byte sequence to the reversed byte sequence.
|
||||
memcpy(rbyteSeq, byteSeq, sizeof(rbyteSeq));
|
||||
|
||||
// Skip trailing zeroes and reverse y.
|
||||
int length;
|
||||
|
||||
for (length = 15; rbyteSeq[length] <= 0; length--)
|
||||
{
|
||||
; // do nothing, just counting
|
||||
}
|
||||
|
||||
UMSKT::endian(rbyteSeq, ++length);
|
||||
|
||||
// Convert reversed byte sequence to BigNum z.
|
||||
z = BN_bin2bn(rbyteSeq, length, nullptr);
|
||||
std::string cdKey;
|
||||
cdKey.reserve(PK_LENGTH);
|
||||
|
||||
// Divide z by 24 and convert the remainder to a CD-key char.
|
||||
for (int i = 24; i >= 0; i--)
|
||||
Integer r, q, a = seq;
|
||||
for (int i = PK_LENGTH - 1; i >= 0; i--)
|
||||
{
|
||||
output[i] = pKeyCharset[BN_div_word(z, 24)];
|
||||
Integer::Divide(r, q, a, (WORD)pKeyCharset.length());
|
||||
cdKey.insert(cdKey.begin(), pKeyCharset[r.ConvertToLong()]);
|
||||
a = q;
|
||||
}
|
||||
|
||||
output[25] = 0;
|
||||
|
||||
cdKey = (char *)output;
|
||||
|
||||
BN_free(z);
|
||||
return cdKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts from CD-key to a byte sequence.
|
||||
*
|
||||
* @param byteSeq [out] *BYTE representation of the CDKey
|
||||
* @param cdKey [in] std::string CDKey to convert
|
||||
* @param cdKey std::string CDKey to convert
|
||||
* @return Integer raw representation of the CDKey
|
||||
**/
|
||||
void PIDGEN3::unbase24(BYTE *byteSeq, std::string cdKey)
|
||||
Integer PIDGEN3::unbase24(const std::string &cdKey)
|
||||
{
|
||||
BYTE pDecodedKey[PK_LENGTH + NULL_TERMINATOR]{};
|
||||
BIGNUM *y = BN_new();
|
||||
Integer result;
|
||||
|
||||
// Remove dashes from the CD-key and put it into a Base24 byte array.
|
||||
for (int i = 0, k = 0; i < cdKey.length() && k < PK_LENGTH; i++)
|
||||
for (char ch : cdKey)
|
||||
{
|
||||
for (int j = 0; j < 24; j++)
|
||||
auto val = std::find(pKeyCharset.begin(), pKeyCharset.end(), ch);
|
||||
|
||||
// character is not in set, return early
|
||||
if (val == pKeyCharset.end())
|
||||
{
|
||||
if (cdKey[i] != '-' && cdKey[i] == pKeyCharset[j])
|
||||
{
|
||||
pDecodedKey[k++] = j;
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// add the weighted sum to result
|
||||
result *= (int)pKeyCharset.length();
|
||||
result += (int)(val - pKeyCharset.begin());
|
||||
}
|
||||
|
||||
// Empty byte sequence.
|
||||
memset(byteSeq, 0, 16);
|
||||
|
||||
// Calculate the weighed sum of byte array elements.
|
||||
for (int i = 0; i < PK_LENGTH; i++)
|
||||
{
|
||||
BN_mul_word(y, PK_LENGTH - 1);
|
||||
BN_add_word(y, pDecodedKey[i]);
|
||||
}
|
||||
|
||||
// Acquire length.
|
||||
int n = BN_num_bytes(y);
|
||||
|
||||
// Place the generated code into the byte sequence.
|
||||
BN_bn2bin(y, byteSeq);
|
||||
BN_free(y);
|
||||
|
||||
// Reverse the byte sequence.
|
||||
UMSKT::endian(byteSeq, n);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes the currently loaded Class-level KeyInfo and calculates the check digit for display.
|
||||
*
|
||||
* Algorithm directly taken from PIDGEN
|
||||
*
|
||||
* @return std::string representation of the Product ID as Displayed on the Product
|
||||
*/
|
||||
std::string PIDGEN3::StringifyProductID()
|
||||
{
|
||||
if (info.isOEM)
|
||||
{
|
||||
Integer OEMID = info.ChannelID * Integer(100);
|
||||
OEMID += ((info.Serial / (MaxSerial / TEN)) * TEN);
|
||||
OEMID += GenerateMod7(OEMID);
|
||||
|
||||
Integer Serial = info.Serial % (MaxSerial / TEN);
|
||||
|
||||
DWORD32 iOEMID = OEMID.ConvertToLong(), iSerial = Serial.ConvertToLong();
|
||||
return fmt::format("PPPPP-OEM-{:07d}-{:05d}", iOEMID, iSerial);
|
||||
}
|
||||
else
|
||||
{
|
||||
DWORD32 ChannelID = info.ChannelID.ConvertToLong(),
|
||||
Serial = (info.Serial * TEN + GenerateMod7(info.Serial)).ConvertToLong(),
|
||||
BinkID = (BINKID / Integer::Two()).ConvertToLong();
|
||||
return fmt::format("PPPPP-{:03d}-{:07d}-{:d}xxx", ChannelID, Serial, BinkID);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks to see if the currently instantiated PIDGEN3 object has a
|
||||
* field size greater than the maximum known BINK1998 size.
|
||||
*
|
||||
* @return boolean value
|
||||
*/
|
||||
BOOL PIDGEN3::checkFieldIsBink1998()
|
||||
{
|
||||
auto *max = BN_new();
|
||||
|
||||
// 1 << 385 (or max size of BINK1998 field in bits + 1)
|
||||
BN_set_bit(max, (12 * 4 * 8) + 1);
|
||||
|
||||
// retval is -1 when (max < privateKey)
|
||||
int retval = BN_cmp(max, privateKey);
|
||||
|
||||
BN_free(max);
|
||||
|
||||
// is max > privateKey?
|
||||
return retval == 1;
|
||||
// is fieldSize < max?
|
||||
return (eCurve.FieldSize().BitCount() < MaxSizeBINK1998);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a given field, in a std::string, is greater than
|
||||
* the maximum known BINK1998 size
|
||||
*
|
||||
* @param keyin std::string representation of a Field
|
||||
* @return boolean value
|
||||
*/
|
||||
BOOL PIDGEN3::checkFieldStrIsBink1998(std::string keyin)
|
||||
{
|
||||
auto *context = BN_CTX_new();
|
||||
auto max = BN_CTX_get(context), input = BN_CTX_get(context);
|
||||
auto check = IntegerS(keyin);
|
||||
|
||||
BN_dec2bn(&input, &keyin[0]);
|
||||
|
||||
// 1 << 385 (or max size of BINK1998 field in bits + 1)
|
||||
BN_set_bit(max, (12 * 4 * 8) + 1);
|
||||
|
||||
// retval is -1 when (max < privateKey)
|
||||
int retval = BN_cmp(max, input);
|
||||
|
||||
BN_CTX_free(context);
|
||||
|
||||
// is max > privateKey?
|
||||
return retval == 1;
|
||||
// is fieldSize < max?
|
||||
return (check.BitCount() < MaxSizeBINK1998);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints a product key to stdout
|
||||
*
|
||||
* @param pk std::string to print
|
||||
*/
|
||||
std::string PIDGEN3::StringifyKey(const std::string &pKey)
|
||||
{
|
||||
assert(pKey.length() >= PK_LENGTH);
|
||||
|
||||
return fmt::format("{}-{}-{}-{}-{}", pKey.substr(0, 5), pKey.substr(5, 5), pKey.substr(10, 5), pKey.substr(15, 5),
|
||||
pKey.substr(20, 5));
|
||||
}
|
||||
|
||||
/**
|
||||
* std::BinaryOperation compatible accumulator for validating/stripping an input string against the PIDGEN3 charset
|
||||
*
|
||||
* @param accumulator
|
||||
* @param currentChar
|
||||
* @return
|
||||
*/
|
||||
std::string INLINE PIDGEN3::ValidateStringKeyInputCharset(std::string &accumulator, char currentChar)
|
||||
{
|
||||
char cchar = (char)::toupper(currentChar);
|
||||
if (std::find(pKeyCharset.begin(), pKeyCharset.end(), cchar) != pKeyCharset.end())
|
||||
{
|
||||
accumulator.push_back(cchar);
|
||||
}
|
||||
return accumulator;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param in_key
|
||||
* @param out_key
|
||||
* @return
|
||||
*/
|
||||
BOOL PIDGEN3::ValidateKeyString(const std::string &in_key, std::string &out_key)
|
||||
{
|
||||
// copy out the product key stripping out extraneous characters
|
||||
out_key = std::accumulate(in_key.begin(), in_key.end(), std::string(), ValidateStringKeyInputCharset);
|
||||
|
||||
// only return true if we've handled exactly PK_LENGTH chars
|
||||
return (out_key.length() == PK_LENGTH);
|
||||
}
|
||||
|
@ -23,82 +23,89 @@
|
||||
#ifndef UMSKT_PIDGEN3_H
|
||||
#define UMSKT_PIDGEN3_H
|
||||
|
||||
#include "../libumskt.h"
|
||||
#include <libumskt/pidgen.h>
|
||||
|
||||
class BINK1998;
|
||||
class BINK2002;
|
||||
|
||||
class EXPORT PIDGEN3
|
||||
class EXPORT PIDGEN3 : public PIDGEN
|
||||
{
|
||||
friend class BINK1998;
|
||||
friend class BINK2002;
|
||||
|
||||
protected:
|
||||
BIGNUM *privateKey, *genOrder;
|
||||
EC_POINT *genPoint, *pubPoint;
|
||||
EC_GROUP *eCurve;
|
||||
Integer BINKID;
|
||||
Integer privateKey, genOrder;
|
||||
ECP::Point pubPoint, genPoint;
|
||||
ECP eCurve;
|
||||
|
||||
public:
|
||||
PIDGEN3()
|
||||
{
|
||||
}
|
||||
PIDGEN3() = default;
|
||||
|
||||
PIDGEN3(PIDGEN3 &p3)
|
||||
{
|
||||
privateKey = p3.privateKey;
|
||||
genOrder = p3.genOrder;
|
||||
genPoint = p3.genPoint;
|
||||
pubPoint = p3.pubPoint;
|
||||
genPoint = p3.genPoint;
|
||||
eCurve = p3.eCurve;
|
||||
}
|
||||
|
||||
virtual ~PIDGEN3()
|
||||
{
|
||||
EC_GROUP_free(eCurve);
|
||||
EC_POINT_free(genPoint);
|
||||
EC_POINT_free(pubPoint);
|
||||
BN_free(genOrder);
|
||||
BN_free(privateKey);
|
||||
}
|
||||
~PIDGEN3() override = default;
|
||||
|
||||
struct KeyInfo
|
||||
{
|
||||
DWORD Serial = 0, AuthInfo = 0, ChannelID = 0, Hash = 0;
|
||||
QWORD Signature = 0;
|
||||
BOOL isUpgrade = false;
|
||||
BOOL isUpgrade = false, isOEM = false;
|
||||
Integer ChannelID = 0, Serial = 0, AuthInfo = 0, Rand = 0, Hash = 0, Signature = 0;
|
||||
|
||||
void setSerial(DWORD serialIn)
|
||||
void setSerial(DWORD32 SerialIn)
|
||||
{
|
||||
Serial = serialIn;
|
||||
Serial = IntegerN(SerialIn);
|
||||
}
|
||||
|
||||
void setAuthInfo(DWORD AuthInfoIn)
|
||||
void setAuthInfo(DWORD32 AuthInfoIn)
|
||||
{
|
||||
AuthInfo = AuthInfoIn;
|
||||
AuthInfo = IntegerN(AuthInfoIn);
|
||||
}
|
||||
|
||||
void setChannelID(DWORD ChannelIDIn)
|
||||
void setChannelID(DWORD32 ChannelIDIn)
|
||||
{
|
||||
ChannelID = ChannelIDIn;
|
||||
ChannelID = IntegerN(ChannelIDIn);
|
||||
}
|
||||
} info;
|
||||
|
||||
static constexpr char pKeyCharset[] = "BCDFGHJKMPQRTVWXY2346789";
|
||||
static const std::string pKeyCharset;
|
||||
static const DWORD32 MaxSizeBINK1998;
|
||||
|
||||
BOOL LoadEllipticCurve(std::string pSel, std::string aSel, std::string bSel, std::string generatorXSel,
|
||||
std::string generatorYSel, std::string publicKeyXSel, std::string publicKeyYSel,
|
||||
std::string genOrderSel, std::string privateKeySel);
|
||||
BOOL LoadEllipticCurve(const std::string &BinkIDSel, const std::string &pSel, const std::string &aSel,
|
||||
const std::string &bSel, const std::string &generatorXSel, const std::string &generatorYSel,
|
||||
const std::string &publicKeyXSel, const std::string &publicKeyYSel,
|
||||
const std::string &genOrderSel, const std::string &privateKeySel);
|
||||
|
||||
virtual BOOL Pack(QWORD *pRaw) = 0;
|
||||
virtual BOOL Unpack(QWORD *pRaw) = 0;
|
||||
virtual BOOL Generate(std::string &pKey);
|
||||
virtual BOOL Validate(std::string &pKey);
|
||||
BOOL Generate(std::string &pKey) override;
|
||||
BOOL Validate(const std::string &pKey) override;
|
||||
std::string StringifyKey(const std::string &pKey) override;
|
||||
std::string StringifyProductID() override;
|
||||
BOOL ValidateKeyString(const std::string &in_key, std::string &out_key) override;
|
||||
|
||||
virtual Integer Pack(const KeyInfo &ki)
|
||||
{
|
||||
throw std::runtime_error("PIDGEN3::Pack() pure virtual function call");
|
||||
}
|
||||
|
||||
virtual KeyInfo Unpack(const Integer &raw)
|
||||
{
|
||||
throw std::runtime_error("PIDGEN3::Unpack() pure virtual function call");
|
||||
}
|
||||
|
||||
// PIDGEN3.cpp
|
||||
void base24(std::string &cdKey, BYTE *byteSeq);
|
||||
void unbase24(BYTE *byteSeq, std::string cdKey);
|
||||
BOOL checkFieldIsBink1998();
|
||||
static PIDGEN3 *Factory(const std::string &field);
|
||||
static BOOL checkFieldStrIsBink1998(std::string keyin);
|
||||
static std::string ValidateStringKeyInputCharset(std::string &accumulator, char currentChar);
|
||||
static std::string base24(Integer &seq);
|
||||
static Integer unbase24(const std::string &cdKey);
|
||||
|
||||
BOOL checkFieldIsBink1998();
|
||||
};
|
||||
|
||||
#endif // UMSKT_PIDGEN3_H
|
||||
|
@ -20,7 +20,7 @@
|
||||
* @Maintainer Neo
|
||||
*/
|
||||
|
||||
#include "cli.h"
|
||||
#include <cli/cli.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
@ -20,7 +20,7 @@
|
||||
* @Maintainer Neo
|
||||
*/
|
||||
|
||||
#include "cli.h"
|
||||
#include <cli/cli.h>
|
||||
|
||||
#include <cmrc/cmrc.hpp>
|
||||
CMRC_DECLARE(umskt);
|
||||
|
@ -25,19 +25,27 @@
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
|
||||
// squelch the insane amount of warnings from cstdbool
|
||||
#define _SILENCE_ALL_CXX17_DEPRECATION_WARNINGS
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <intrin.h>
|
||||
#include <windows.h>
|
||||
#undef WIN32_LEAN_AND_MEAN
|
||||
|
||||
#endif // defined(WIN32)
|
||||
#endif // defined(_MSC_VER)
|
||||
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
#include <cstdbool>
|
||||
#include <cstdint>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <numeric>
|
||||
#include <sstream>
|
||||
#include <stdint128>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#ifdef DEBUG
|
||||
#if defined(DEBUG) || 1
|
||||
#include <cassert>
|
||||
#else
|
||||
#define assert(x) /* do nothing */
|
||||
@ -76,45 +84,19 @@
|
||||
#define INLINE FNINLINE
|
||||
#endif // ifdef __EMSCRIPTEN__
|
||||
|
||||
// POSIX <-> Windows compatability layer, because MS just *had* to be different
|
||||
#ifdef _MSC_VER
|
||||
#ifndef _sscanf
|
||||
#define _sscanf sscanf_s
|
||||
#endif
|
||||
#ifndef _strncpy
|
||||
#define _strncpy strncpy_s
|
||||
#endif
|
||||
#ifndef _strcpy
|
||||
#define _strcpy strcpy_s
|
||||
#endif
|
||||
#else
|
||||
#define _sscanf sscanf
|
||||
#define _strncpy(x, y, z, w) strncpy(x, z, w)
|
||||
#define _strcpy strcpy
|
||||
#endif // ifdef _MSC_VER
|
||||
|
||||
// Type definitions now with more windows compatability (unfortunately)
|
||||
using BOOL = int32_t;
|
||||
using BYTE = uint8_t;
|
||||
using WORD = uint16_t;
|
||||
using DWORD = unsigned long;
|
||||
using DWORD32 = uint32_t;
|
||||
using QWORD = uint64_t;
|
||||
|
||||
#if defined(_M_ARM) // for Windows on ARM ??
|
||||
using __m128 = __n128;
|
||||
#endif
|
||||
|
||||
#if defined(__SIZEOF_INT128__) || defined(__int128)
|
||||
using uint128_t = unsigned __int128;
|
||||
#else // use the intel-supplied __m128 intrisic
|
||||
using uint128_t = __m128;
|
||||
#endif
|
||||
using OWORD = uint128_t;
|
||||
|
||||
typedef union {
|
||||
OWORD oword;
|
||||
QWORD qword[2];
|
||||
DWORD dword[4];
|
||||
DWORD32 dword32[4];
|
||||
WORD word[8];
|
||||
BYTE byte[16];
|
||||
} Q_OWORD;
|
||||
|
@ -20,8 +20,8 @@
|
||||
* @Maintainer Neo
|
||||
*/
|
||||
|
||||
#include "../typedefs.h"
|
||||
#include "resource.h"
|
||||
#include "typedefs.h"
|
||||
|
||||
BOOLEAN WINAPI DllMain(IN HINSTANCE hDllHandle, IN DWORD nReason, IN LPVOID Reserved)
|
||||
{
|
||||
|
@ -20,7 +20,7 @@
|
||||
* @Maintainer Neo
|
||||
*/
|
||||
|
||||
#include "../cli.h"
|
||||
#include "cli/cli.h"
|
||||
#include "resource.h"
|
||||
|
||||
/**
|
||||
|
Binary file not shown.
Reference in New Issue
Block a user