Compare commits
25 commits
8dc063e4e5
...
dcecf43d10
Author | SHA1 | Date | |
---|---|---|---|
dcecf43d10 | |||
a592e55093 | |||
e6bb94c378 | |||
1085bec913 | |||
369b8b04bc | |||
0c17e706ba | |||
11cd3e137d | |||
c696803702 | |||
3070732ab5 | |||
7684957ada | |||
77d347b51f | |||
4671819397 | |||
c310018847 | |||
4e25f1080e | |||
6f4cd8ecf5 | |||
171e913138 | |||
280e1c7d5f | |||
8c17e3a11a | |||
b9067599d4 | |||
2ffa34e673 | |||
eebd026565 | |||
2f1d410423 | |||
ae2a253a13 | |||
32fa85636a | |||
c2995d9399 |
18 changed files with 1679 additions and 2304 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,2 +1,3 @@
|
||||||
/target
|
/target
|
||||||
/.vscode
|
/.vscode
|
||||||
|
keys.json
|
||||||
|
|
292
Cargo.lock
generated
292
Cargo.lock
generated
|
@ -57,6 +57,18 @@ version = "1.0.71"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9c7d0618f0e0b7e8ff11427422b64564d5fb0be1940354bfe2e0529b18a9d9b8"
|
checksum = "9c7d0618f0e0b7e8ff11427422b64564d5fb0be1940354bfe2e0529b18a9d9b8"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "autocfg"
|
||||||
|
version = "1.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "base16ct"
|
||||||
|
version = "0.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bitflags"
|
name = "bitflags"
|
||||||
version = "1.3.2"
|
version = "1.3.2"
|
||||||
|
@ -72,6 +84,15 @@ dependencies = [
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "block-buffer"
|
||||||
|
version = "0.10.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71"
|
||||||
|
dependencies = [
|
||||||
|
"generic-array",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cc"
|
name = "cc"
|
||||||
version = "1.0.79"
|
version = "1.0.79"
|
||||||
|
@ -132,6 +153,63 @@ version = "1.0.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7"
|
checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cpufeatures"
|
||||||
|
version = "0.2.8"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "03e69e28e9f7f77debdedbaafa2866e1de9ba56df55a8bd7cfc724c25a09987c"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "crypto-bigint"
|
||||||
|
version = "0.5.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "cf4c2f4e1afd912bc40bfd6fed5d9dc1f288e0ba01bfcc835cc5bc3eb13efe15"
|
||||||
|
dependencies = [
|
||||||
|
"generic-array",
|
||||||
|
"rand_core",
|
||||||
|
"subtle",
|
||||||
|
"zeroize",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "crypto-common"
|
||||||
|
version = "0.1.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3"
|
||||||
|
dependencies = [
|
||||||
|
"generic-array",
|
||||||
|
"typenum",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "digest"
|
||||||
|
version = "0.10.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292"
|
||||||
|
dependencies = [
|
||||||
|
"block-buffer",
|
||||||
|
"crypto-common",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "elliptic-curve"
|
||||||
|
version = "0.13.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "968405c8fdc9b3bf4df0a6638858cc0b52462836ab6b1c87377785dd09cf1c0b"
|
||||||
|
dependencies = [
|
||||||
|
"base16ct",
|
||||||
|
"crypto-bigint",
|
||||||
|
"ff",
|
||||||
|
"generic-array",
|
||||||
|
"group",
|
||||||
|
"rand_core",
|
||||||
|
"subtle",
|
||||||
|
"zeroize",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "errno"
|
name = "errno"
|
||||||
version = "0.3.1"
|
version = "0.3.1"
|
||||||
|
@ -154,19 +232,47 @@ dependencies = [
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "foreign-types"
|
name = "ff"
|
||||||
version = "0.3.2"
|
version = "0.13.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1"
|
checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"foreign-types-shared",
|
"rand_core",
|
||||||
|
"subtle",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "foreign-types-shared"
|
name = "generic-array"
|
||||||
version = "0.1.1"
|
version = "0.14.7"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b"
|
checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a"
|
||||||
|
dependencies = [
|
||||||
|
"typenum",
|
||||||
|
"version_check",
|
||||||
|
"zeroize",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "getrandom"
|
||||||
|
version = "0.2.10"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"libc",
|
||||||
|
"wasi",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "group"
|
||||||
|
version = "0.13.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63"
|
||||||
|
dependencies = [
|
||||||
|
"ff",
|
||||||
|
"rand_core",
|
||||||
|
"subtle",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "heck"
|
name = "heck"
|
||||||
|
@ -227,6 +333,50 @@ version = "0.4.19"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b06a4cde4c0f271a446782e3eff8de789548ce57dbc8eca9292c27f4a42004b4"
|
checksum = "b06a4cde4c0f271a446782e3eff8de789548ce57dbc8eca9292c27f4a42004b4"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "mskey"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"anyhow",
|
||||||
|
"clap",
|
||||||
|
"log",
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
|
"simple_logger",
|
||||||
|
"umskt",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "num-bigint"
|
||||||
|
version = "0.4.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f93ab6289c7b344a8a9f60f88d80aa20032336fe78da341afc91c8a2341fc75f"
|
||||||
|
dependencies = [
|
||||||
|
"autocfg",
|
||||||
|
"num-integer",
|
||||||
|
"num-traits",
|
||||||
|
"rand",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "num-integer"
|
||||||
|
version = "0.1.45"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9"
|
||||||
|
dependencies = [
|
||||||
|
"autocfg",
|
||||||
|
"num-traits",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "num-traits"
|
||||||
|
version = "0.2.15"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd"
|
||||||
|
dependencies = [
|
||||||
|
"autocfg",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "once_cell"
|
name = "once_cell"
|
||||||
version = "1.18.0"
|
version = "1.18.0"
|
||||||
|
@ -234,45 +384,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d"
|
checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "openssl"
|
name = "ppv-lite86"
|
||||||
version = "0.10.55"
|
version = "0.2.17"
|
||||||
source = "git+https://github.com/sfackler/rust-openssl#9d180ec94a92d2d08d6463ad047d9d7e7a8d9561"
|
|
||||||
dependencies = [
|
|
||||||
"bitflags",
|
|
||||||
"cfg-if",
|
|
||||||
"foreign-types",
|
|
||||||
"libc",
|
|
||||||
"once_cell",
|
|
||||||
"openssl-macros",
|
|
||||||
"openssl-sys",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "openssl-macros"
|
|
||||||
version = "0.1.1"
|
|
||||||
source = "git+https://github.com/sfackler/rust-openssl#9d180ec94a92d2d08d6463ad047d9d7e7a8d9561"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"syn",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "openssl-sys"
|
|
||||||
version = "0.9.90"
|
|
||||||
source = "git+https://github.com/sfackler/rust-openssl#9d180ec94a92d2d08d6463ad047d9d7e7a8d9561"
|
|
||||||
dependencies = [
|
|
||||||
"cc",
|
|
||||||
"libc",
|
|
||||||
"pkg-config",
|
|
||||||
"vcpkg",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "pkg-config"
|
|
||||||
version = "0.3.27"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964"
|
checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "proc-macro2"
|
name = "proc-macro2"
|
||||||
|
@ -292,6 +407,36 @@ dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rand"
|
||||||
|
version = "0.8.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
"rand_chacha",
|
||||||
|
"rand_core",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rand_chacha"
|
||||||
|
version = "0.3.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
|
||||||
|
dependencies = [
|
||||||
|
"ppv-lite86",
|
||||||
|
"rand_core",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rand_core"
|
||||||
|
version = "0.6.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
|
||||||
|
dependencies = [
|
||||||
|
"getrandom",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rustix"
|
name = "rustix"
|
||||||
version = "0.37.20"
|
version = "0.37.20"
|
||||||
|
@ -343,6 +488,17 @@ dependencies = [
|
||||||
"serde",
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "sha1"
|
||||||
|
version = "0.10.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f04293dc80c3993519f2d7f6f511707ee7094fe0c6d3406feb330cdb3540eba3"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"cpufeatures",
|
||||||
|
"digest",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "simple_logger"
|
name = "simple_logger"
|
||||||
version = "4.2.0"
|
version = "4.2.0"
|
||||||
|
@ -359,6 +515,12 @@ version = "0.10.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
|
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "subtle"
|
||||||
|
version = "2.5.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "syn"
|
name = "syn"
|
||||||
version = "2.0.21"
|
version = "2.0.21"
|
||||||
|
@ -390,14 +552,25 @@ dependencies = [
|
||||||
"syn",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "typenum"
|
||||||
|
version = "1.16.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "umskt"
|
name = "umskt"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"bitreader",
|
"bitreader",
|
||||||
"openssl",
|
"elliptic-curve",
|
||||||
|
"num-bigint",
|
||||||
|
"num-integer",
|
||||||
|
"num-traits",
|
||||||
|
"rand",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
|
"sha1",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -414,10 +587,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a"
|
checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "vcpkg"
|
name = "version_check"
|
||||||
version = "0.2.15"
|
version = "0.9.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
|
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wasi"
|
||||||
|
version = "0.11.0+wasi-snapshot-preview1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows-sys"
|
name = "windows-sys"
|
||||||
|
@ -543,14 +722,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a"
|
checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "xpkey"
|
name = "zeroize"
|
||||||
version = "0.1.0"
|
version = "1.6.0"
|
||||||
dependencies = [
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
"anyhow",
|
checksum = "2a0956f1ba7c7909bfb66c2e9e4124ab6f6482560f6628b5aaeba39207c9aad9"
|
||||||
"clap",
|
|
||||||
"log",
|
|
||||||
"serde",
|
|
||||||
"serde_json",
|
|
||||||
"simple_logger",
|
|
||||||
"umskt",
|
|
||||||
]
|
|
||||||
|
|
11
Cargo.toml
11
Cargo.toml
|
@ -1,6 +1,15 @@
|
||||||
[workspace]
|
[workspace]
|
||||||
|
resolver = "2"
|
||||||
|
|
||||||
members = [
|
members = [
|
||||||
"umskt",
|
"umskt",
|
||||||
"xpkey",
|
"mskey",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[profile.release]
|
||||||
|
lto = true
|
||||||
|
|
||||||
|
[profile.release.package.mskey]
|
||||||
|
strip = true
|
||||||
|
opt-level = "z"
|
||||||
|
codegen-units = 1
|
||||||
|
|
661
LICENSE
Normal file
661
LICENSE
Normal file
|
@ -0,0 +1,661 @@
|
||||||
|
GNU AFFERO GENERAL PUBLIC LICENSE
|
||||||
|
Version 3, 19 November 2007
|
||||||
|
|
||||||
|
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||||
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
|
Preamble
|
||||||
|
|
||||||
|
The GNU Affero General Public License is a free, copyleft license for
|
||||||
|
software and other kinds of works, specifically designed to ensure
|
||||||
|
cooperation with the community in the case of network server software.
|
||||||
|
|
||||||
|
The licenses for most software and other practical works are designed
|
||||||
|
to take away your freedom to share and change the works. By contrast,
|
||||||
|
our General Public Licenses are intended to guarantee your freedom to
|
||||||
|
share and change all versions of a program--to make sure it remains free
|
||||||
|
software for all its users.
|
||||||
|
|
||||||
|
When we speak of free software, we are referring to freedom, not
|
||||||
|
price. Our General Public Licenses are designed to make sure that you
|
||||||
|
have the freedom to distribute copies of free software (and charge for
|
||||||
|
them if you wish), that you receive source code or can get it if you
|
||||||
|
want it, that you can change the software or use pieces of it in new
|
||||||
|
free programs, and that you know you can do these things.
|
||||||
|
|
||||||
|
Developers that use our General Public Licenses protect your rights
|
||||||
|
with two steps: (1) assert copyright on the software, and (2) offer
|
||||||
|
you this License which gives you legal permission to copy, distribute
|
||||||
|
and/or modify the software.
|
||||||
|
|
||||||
|
A secondary benefit of defending all users' freedom is that
|
||||||
|
improvements made in alternate versions of the program, if they
|
||||||
|
receive widespread use, become available for other developers to
|
||||||
|
incorporate. Many developers of free software are heartened and
|
||||||
|
encouraged by the resulting cooperation. However, in the case of
|
||||||
|
software used on network servers, this result may fail to come about.
|
||||||
|
The GNU General Public License permits making a modified version and
|
||||||
|
letting the public access it on a server without ever releasing its
|
||||||
|
source code to the public.
|
||||||
|
|
||||||
|
The GNU Affero General Public License is designed specifically to
|
||||||
|
ensure that, in such cases, the modified source code becomes available
|
||||||
|
to the community. It requires the operator of a network server to
|
||||||
|
provide the source code of the modified version running there to the
|
||||||
|
users of that server. Therefore, public use of a modified version, on
|
||||||
|
a publicly accessible server, gives the public access to the source
|
||||||
|
code of the modified version.
|
||||||
|
|
||||||
|
An older license, called the Affero General Public License and
|
||||||
|
published by Affero, was designed to accomplish similar goals. This is
|
||||||
|
a different license, not a version of the Affero GPL, but Affero has
|
||||||
|
released a new version of the Affero GPL which permits relicensing under
|
||||||
|
this license.
|
||||||
|
|
||||||
|
The precise terms and conditions for copying, distribution and
|
||||||
|
modification follow.
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
0. Definitions.
|
||||||
|
|
||||||
|
"This License" refers to version 3 of the GNU Affero General Public License.
|
||||||
|
|
||||||
|
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||||
|
works, such as semiconductor masks.
|
||||||
|
|
||||||
|
"The Program" refers to any copyrightable work licensed under this
|
||||||
|
License. Each licensee is addressed as "you". "Licensees" and
|
||||||
|
"recipients" may be individuals or organizations.
|
||||||
|
|
||||||
|
To "modify" a work means to copy from or adapt all or part of the work
|
||||||
|
in a fashion requiring copyright permission, other than the making of an
|
||||||
|
exact copy. The resulting work is called a "modified version" of the
|
||||||
|
earlier work or a work "based on" the earlier work.
|
||||||
|
|
||||||
|
A "covered work" means either the unmodified Program or a work based
|
||||||
|
on the Program.
|
||||||
|
|
||||||
|
To "propagate" a work means to do anything with it that, without
|
||||||
|
permission, would make you directly or secondarily liable for
|
||||||
|
infringement under applicable copyright law, except executing it on a
|
||||||
|
computer or modifying a private copy. Propagation includes copying,
|
||||||
|
distribution (with or without modification), making available to the
|
||||||
|
public, and in some countries other activities as well.
|
||||||
|
|
||||||
|
To "convey" a work means any kind of propagation that enables other
|
||||||
|
parties to make or receive copies. Mere interaction with a user through
|
||||||
|
a computer network, with no transfer of a copy, is not conveying.
|
||||||
|
|
||||||
|
An interactive user interface displays "Appropriate Legal Notices"
|
||||||
|
to the extent that it includes a convenient and prominently visible
|
||||||
|
feature that (1) displays an appropriate copyright notice, and (2)
|
||||||
|
tells the user that there is no warranty for the work (except to the
|
||||||
|
extent that warranties are provided), that licensees may convey the
|
||||||
|
work under this License, and how to view a copy of this License. If
|
||||||
|
the interface presents a list of user commands or options, such as a
|
||||||
|
menu, a prominent item in the list meets this criterion.
|
||||||
|
|
||||||
|
1. Source Code.
|
||||||
|
|
||||||
|
The "source code" for a work means the preferred form of the work
|
||||||
|
for making modifications to it. "Object code" means any non-source
|
||||||
|
form of a work.
|
||||||
|
|
||||||
|
A "Standard Interface" means an interface that either is an official
|
||||||
|
standard defined by a recognized standards body, or, in the case of
|
||||||
|
interfaces specified for a particular programming language, one that
|
||||||
|
is widely used among developers working in that language.
|
||||||
|
|
||||||
|
The "System Libraries" of an executable work include anything, other
|
||||||
|
than the work as a whole, that (a) is included in the normal form of
|
||||||
|
packaging a Major Component, but which is not part of that Major
|
||||||
|
Component, and (b) serves only to enable use of the work with that
|
||||||
|
Major Component, or to implement a Standard Interface for which an
|
||||||
|
implementation is available to the public in source code form. A
|
||||||
|
"Major Component", in this context, means a major essential component
|
||||||
|
(kernel, window system, and so on) of the specific operating system
|
||||||
|
(if any) on which the executable work runs, or a compiler used to
|
||||||
|
produce the work, or an object code interpreter used to run it.
|
||||||
|
|
||||||
|
The "Corresponding Source" for a work in object code form means all
|
||||||
|
the source code needed to generate, install, and (for an executable
|
||||||
|
work) run the object code and to modify the work, including scripts to
|
||||||
|
control those activities. However, it does not include the work's
|
||||||
|
System Libraries, or general-purpose tools or generally available free
|
||||||
|
programs which are used unmodified in performing those activities but
|
||||||
|
which are not part of the work. For example, Corresponding Source
|
||||||
|
includes interface definition files associated with source files for
|
||||||
|
the work, and the source code for shared libraries and dynamically
|
||||||
|
linked subprograms that the work is specifically designed to require,
|
||||||
|
such as by intimate data communication or control flow between those
|
||||||
|
subprograms and other parts of the work.
|
||||||
|
|
||||||
|
The Corresponding Source need not include anything that users
|
||||||
|
can regenerate automatically from other parts of the Corresponding
|
||||||
|
Source.
|
||||||
|
|
||||||
|
The Corresponding Source for a work in source code form is that
|
||||||
|
same work.
|
||||||
|
|
||||||
|
2. Basic Permissions.
|
||||||
|
|
||||||
|
All rights granted under this License are granted for the term of
|
||||||
|
copyright on the Program, and are irrevocable provided the stated
|
||||||
|
conditions are met. This License explicitly affirms your unlimited
|
||||||
|
permission to run the unmodified Program. The output from running a
|
||||||
|
covered work is covered by this License only if the output, given its
|
||||||
|
content, constitutes a covered work. This License acknowledges your
|
||||||
|
rights of fair use or other equivalent, as provided by copyright law.
|
||||||
|
|
||||||
|
You may make, run and propagate covered works that you do not
|
||||||
|
convey, without conditions so long as your license otherwise remains
|
||||||
|
in force. You may convey covered works to others for the sole purpose
|
||||||
|
of having them make modifications exclusively for you, or provide you
|
||||||
|
with facilities for running those works, provided that you comply with
|
||||||
|
the terms of this License in conveying all material for which you do
|
||||||
|
not control copyright. Those thus making or running the covered works
|
||||||
|
for you must do so exclusively on your behalf, under your direction
|
||||||
|
and control, on terms that prohibit them from making any copies of
|
||||||
|
your copyrighted material outside their relationship with you.
|
||||||
|
|
||||||
|
Conveying under any other circumstances is permitted solely under
|
||||||
|
the conditions stated below. Sublicensing is not allowed; section 10
|
||||||
|
makes it unnecessary.
|
||||||
|
|
||||||
|
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||||
|
|
||||||
|
No covered work shall be deemed part of an effective technological
|
||||||
|
measure under any applicable law fulfilling obligations under article
|
||||||
|
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||||
|
similar laws prohibiting or restricting circumvention of such
|
||||||
|
measures.
|
||||||
|
|
||||||
|
When you convey a covered work, you waive any legal power to forbid
|
||||||
|
circumvention of technological measures to the extent such circumvention
|
||||||
|
is effected by exercising rights under this License with respect to
|
||||||
|
the covered work, and you disclaim any intention to limit operation or
|
||||||
|
modification of the work as a means of enforcing, against the work's
|
||||||
|
users, your or third parties' legal rights to forbid circumvention of
|
||||||
|
technological measures.
|
||||||
|
|
||||||
|
4. Conveying Verbatim Copies.
|
||||||
|
|
||||||
|
You may convey verbatim copies of the Program's source code as you
|
||||||
|
receive it, in any medium, provided that you conspicuously and
|
||||||
|
appropriately publish on each copy an appropriate copyright notice;
|
||||||
|
keep intact all notices stating that this License and any
|
||||||
|
non-permissive terms added in accord with section 7 apply to the code;
|
||||||
|
keep intact all notices of the absence of any warranty; and give all
|
||||||
|
recipients a copy of this License along with the Program.
|
||||||
|
|
||||||
|
You may charge any price or no price for each copy that you convey,
|
||||||
|
and you may offer support or warranty protection for a fee.
|
||||||
|
|
||||||
|
5. Conveying Modified Source Versions.
|
||||||
|
|
||||||
|
You may convey a work based on the Program, or the modifications to
|
||||||
|
produce it from the Program, in the form of source code under the
|
||||||
|
terms of section 4, provided that you also meet all of these conditions:
|
||||||
|
|
||||||
|
a) The work must carry prominent notices stating that you modified
|
||||||
|
it, and giving a relevant date.
|
||||||
|
|
||||||
|
b) The work must carry prominent notices stating that it is
|
||||||
|
released under this License and any conditions added under section
|
||||||
|
7. This requirement modifies the requirement in section 4 to
|
||||||
|
"keep intact all notices".
|
||||||
|
|
||||||
|
c) You must license the entire work, as a whole, under this
|
||||||
|
License to anyone who comes into possession of a copy. This
|
||||||
|
License will therefore apply, along with any applicable section 7
|
||||||
|
additional terms, to the whole of the work, and all its parts,
|
||||||
|
regardless of how they are packaged. This License gives no
|
||||||
|
permission to license the work in any other way, but it does not
|
||||||
|
invalidate such permission if you have separately received it.
|
||||||
|
|
||||||
|
d) If the work has interactive user interfaces, each must display
|
||||||
|
Appropriate Legal Notices; however, if the Program has interactive
|
||||||
|
interfaces that do not display Appropriate Legal Notices, your
|
||||||
|
work need not make them do so.
|
||||||
|
|
||||||
|
A compilation of a covered work with other separate and independent
|
||||||
|
works, which are not by their nature extensions of the covered work,
|
||||||
|
and which are not combined with it such as to form a larger program,
|
||||||
|
in or on a volume of a storage or distribution medium, is called an
|
||||||
|
"aggregate" if the compilation and its resulting copyright are not
|
||||||
|
used to limit the access or legal rights of the compilation's users
|
||||||
|
beyond what the individual works permit. Inclusion of a covered work
|
||||||
|
in an aggregate does not cause this License to apply to the other
|
||||||
|
parts of the aggregate.
|
||||||
|
|
||||||
|
6. Conveying Non-Source Forms.
|
||||||
|
|
||||||
|
You may convey a covered work in object code form under the terms
|
||||||
|
of sections 4 and 5, provided that you also convey the
|
||||||
|
machine-readable Corresponding Source under the terms of this License,
|
||||||
|
in one of these ways:
|
||||||
|
|
||||||
|
a) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by the
|
||||||
|
Corresponding Source fixed on a durable physical medium
|
||||||
|
customarily used for software interchange.
|
||||||
|
|
||||||
|
b) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by a
|
||||||
|
written offer, valid for at least three years and valid for as
|
||||||
|
long as you offer spare parts or customer support for that product
|
||||||
|
model, to give anyone who possesses the object code either (1) a
|
||||||
|
copy of the Corresponding Source for all the software in the
|
||||||
|
product that is covered by this License, on a durable physical
|
||||||
|
medium customarily used for software interchange, for a price no
|
||||||
|
more than your reasonable cost of physically performing this
|
||||||
|
conveying of source, or (2) access to copy the
|
||||||
|
Corresponding Source from a network server at no charge.
|
||||||
|
|
||||||
|
c) Convey individual copies of the object code with a copy of the
|
||||||
|
written offer to provide the Corresponding Source. This
|
||||||
|
alternative is allowed only occasionally and noncommercially, and
|
||||||
|
only if you received the object code with such an offer, in accord
|
||||||
|
with subsection 6b.
|
||||||
|
|
||||||
|
d) Convey the object code by offering access from a designated
|
||||||
|
place (gratis or for a charge), and offer equivalent access to the
|
||||||
|
Corresponding Source in the same way through the same place at no
|
||||||
|
further charge. You need not require recipients to copy the
|
||||||
|
Corresponding Source along with the object code. If the place to
|
||||||
|
copy the object code is a network server, the Corresponding Source
|
||||||
|
may be on a different server (operated by you or a third party)
|
||||||
|
that supports equivalent copying facilities, provided you maintain
|
||||||
|
clear directions next to the object code saying where to find the
|
||||||
|
Corresponding Source. Regardless of what server hosts the
|
||||||
|
Corresponding Source, you remain obligated to ensure that it is
|
||||||
|
available for as long as needed to satisfy these requirements.
|
||||||
|
|
||||||
|
e) Convey the object code using peer-to-peer transmission, provided
|
||||||
|
you inform other peers where the object code and Corresponding
|
||||||
|
Source of the work are being offered to the general public at no
|
||||||
|
charge under subsection 6d.
|
||||||
|
|
||||||
|
A separable portion of the object code, whose source code is excluded
|
||||||
|
from the Corresponding Source as a System Library, need not be
|
||||||
|
included in conveying the object code work.
|
||||||
|
|
||||||
|
A "User Product" is either (1) a "consumer product", which means any
|
||||||
|
tangible personal property which is normally used for personal, family,
|
||||||
|
or household purposes, or (2) anything designed or sold for incorporation
|
||||||
|
into a dwelling. In determining whether a product is a consumer product,
|
||||||
|
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||||
|
product received by a particular user, "normally used" refers to a
|
||||||
|
typical or common use of that class of product, regardless of the status
|
||||||
|
of the particular user or of the way in which the particular user
|
||||||
|
actually uses, or expects or is expected to use, the product. A product
|
||||||
|
is a consumer product regardless of whether the product has substantial
|
||||||
|
commercial, industrial or non-consumer uses, unless such uses represent
|
||||||
|
the only significant mode of use of the product.
|
||||||
|
|
||||||
|
"Installation Information" for a User Product means any methods,
|
||||||
|
procedures, authorization keys, or other information required to install
|
||||||
|
and execute modified versions of a covered work in that User Product from
|
||||||
|
a modified version of its Corresponding Source. The information must
|
||||||
|
suffice to ensure that the continued functioning of the modified object
|
||||||
|
code is in no case prevented or interfered with solely because
|
||||||
|
modification has been made.
|
||||||
|
|
||||||
|
If you convey an object code work under this section in, or with, or
|
||||||
|
specifically for use in, a User Product, and the conveying occurs as
|
||||||
|
part of a transaction in which the right of possession and use of the
|
||||||
|
User Product is transferred to the recipient in perpetuity or for a
|
||||||
|
fixed term (regardless of how the transaction is characterized), the
|
||||||
|
Corresponding Source conveyed under this section must be accompanied
|
||||||
|
by the Installation Information. But this requirement does not apply
|
||||||
|
if neither you nor any third party retains the ability to install
|
||||||
|
modified object code on the User Product (for example, the work has
|
||||||
|
been installed in ROM).
|
||||||
|
|
||||||
|
The requirement to provide Installation Information does not include a
|
||||||
|
requirement to continue to provide support service, warranty, or updates
|
||||||
|
for a work that has been modified or installed by the recipient, or for
|
||||||
|
the User Product in which it has been modified or installed. Access to a
|
||||||
|
network may be denied when the modification itself materially and
|
||||||
|
adversely affects the operation of the network or violates the rules and
|
||||||
|
protocols for communication across the network.
|
||||||
|
|
||||||
|
Corresponding Source conveyed, and Installation Information provided,
|
||||||
|
in accord with this section must be in a format that is publicly
|
||||||
|
documented (and with an implementation available to the public in
|
||||||
|
source code form), and must require no special password or key for
|
||||||
|
unpacking, reading or copying.
|
||||||
|
|
||||||
|
7. Additional Terms.
|
||||||
|
|
||||||
|
"Additional permissions" are terms that supplement the terms of this
|
||||||
|
License by making exceptions from one or more of its conditions.
|
||||||
|
Additional permissions that are applicable to the entire Program shall
|
||||||
|
be treated as though they were included in this License, to the extent
|
||||||
|
that they are valid under applicable law. If additional permissions
|
||||||
|
apply only to part of the Program, that part may be used separately
|
||||||
|
under those permissions, but the entire Program remains governed by
|
||||||
|
this License without regard to the additional permissions.
|
||||||
|
|
||||||
|
When you convey a copy of a covered work, you may at your option
|
||||||
|
remove any additional permissions from that copy, or from any part of
|
||||||
|
it. (Additional permissions may be written to require their own
|
||||||
|
removal in certain cases when you modify the work.) You may place
|
||||||
|
additional permissions on material, added by you to a covered work,
|
||||||
|
for which you have or can give appropriate copyright permission.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, for material you
|
||||||
|
add to a covered work, you may (if authorized by the copyright holders of
|
||||||
|
that material) supplement the terms of this License with terms:
|
||||||
|
|
||||||
|
a) Disclaiming warranty or limiting liability differently from the
|
||||||
|
terms of sections 15 and 16 of this License; or
|
||||||
|
|
||||||
|
b) Requiring preservation of specified reasonable legal notices or
|
||||||
|
author attributions in that material or in the Appropriate Legal
|
||||||
|
Notices displayed by works containing it; or
|
||||||
|
|
||||||
|
c) Prohibiting misrepresentation of the origin of that material, or
|
||||||
|
requiring that modified versions of such material be marked in
|
||||||
|
reasonable ways as different from the original version; or
|
||||||
|
|
||||||
|
d) Limiting the use for publicity purposes of names of licensors or
|
||||||
|
authors of the material; or
|
||||||
|
|
||||||
|
e) Declining to grant rights under trademark law for use of some
|
||||||
|
trade names, trademarks, or service marks; or
|
||||||
|
|
||||||
|
f) Requiring indemnification of licensors and authors of that
|
||||||
|
material by anyone who conveys the material (or modified versions of
|
||||||
|
it) with contractual assumptions of liability to the recipient, for
|
||||||
|
any liability that these contractual assumptions directly impose on
|
||||||
|
those licensors and authors.
|
||||||
|
|
||||||
|
All other non-permissive additional terms are considered "further
|
||||||
|
restrictions" within the meaning of section 10. If the Program as you
|
||||||
|
received it, or any part of it, contains a notice stating that it is
|
||||||
|
governed by this License along with a term that is a further
|
||||||
|
restriction, you may remove that term. If a license document contains
|
||||||
|
a further restriction but permits relicensing or conveying under this
|
||||||
|
License, you may add to a covered work material governed by the terms
|
||||||
|
of that license document, provided that the further restriction does
|
||||||
|
not survive such relicensing or conveying.
|
||||||
|
|
||||||
|
If you add terms to a covered work in accord with this section, you
|
||||||
|
must place, in the relevant source files, a statement of the
|
||||||
|
additional terms that apply to those files, or a notice indicating
|
||||||
|
where to find the applicable terms.
|
||||||
|
|
||||||
|
Additional terms, permissive or non-permissive, may be stated in the
|
||||||
|
form of a separately written license, or stated as exceptions;
|
||||||
|
the above requirements apply either way.
|
||||||
|
|
||||||
|
8. Termination.
|
||||||
|
|
||||||
|
You may not propagate or modify a covered work except as expressly
|
||||||
|
provided under this License. Any attempt otherwise to propagate or
|
||||||
|
modify it is void, and will automatically terminate your rights under
|
||||||
|
this License (including any patent licenses granted under the third
|
||||||
|
paragraph of section 11).
|
||||||
|
|
||||||
|
However, if you cease all violation of this License, then your
|
||||||
|
license from a particular copyright holder is reinstated (a)
|
||||||
|
provisionally, unless and until the copyright holder explicitly and
|
||||||
|
finally terminates your license, and (b) permanently, if the copyright
|
||||||
|
holder fails to notify you of the violation by some reasonable means
|
||||||
|
prior to 60 days after the cessation.
|
||||||
|
|
||||||
|
Moreover, your license from a particular copyright holder is
|
||||||
|
reinstated permanently if the copyright holder notifies you of the
|
||||||
|
violation by some reasonable means, this is the first time you have
|
||||||
|
received notice of violation of this License (for any work) from that
|
||||||
|
copyright holder, and you cure the violation prior to 30 days after
|
||||||
|
your receipt of the notice.
|
||||||
|
|
||||||
|
Termination of your rights under this section does not terminate the
|
||||||
|
licenses of parties who have received copies or rights from you under
|
||||||
|
this License. If your rights have been terminated and not permanently
|
||||||
|
reinstated, you do not qualify to receive new licenses for the same
|
||||||
|
material under section 10.
|
||||||
|
|
||||||
|
9. Acceptance Not Required for Having Copies.
|
||||||
|
|
||||||
|
You are not required to accept this License in order to receive or
|
||||||
|
run a copy of the Program. Ancillary propagation of a covered work
|
||||||
|
occurring solely as a consequence of using peer-to-peer transmission
|
||||||
|
to receive a copy likewise does not require acceptance. However,
|
||||||
|
nothing other than this License grants you permission to propagate or
|
||||||
|
modify any covered work. These actions infringe copyright if you do
|
||||||
|
not accept this License. Therefore, by modifying or propagating a
|
||||||
|
covered work, you indicate your acceptance of this License to do so.
|
||||||
|
|
||||||
|
10. Automatic Licensing of Downstream Recipients.
|
||||||
|
|
||||||
|
Each time you convey a covered work, the recipient automatically
|
||||||
|
receives a license from the original licensors, to run, modify and
|
||||||
|
propagate that work, subject to this License. You are not responsible
|
||||||
|
for enforcing compliance by third parties with this License.
|
||||||
|
|
||||||
|
An "entity transaction" is a transaction transferring control of an
|
||||||
|
organization, or substantially all assets of one, or subdividing an
|
||||||
|
organization, or merging organizations. If propagation of a covered
|
||||||
|
work results from an entity transaction, each party to that
|
||||||
|
transaction who receives a copy of the work also receives whatever
|
||||||
|
licenses to the work the party's predecessor in interest had or could
|
||||||
|
give under the previous paragraph, plus a right to possession of the
|
||||||
|
Corresponding Source of the work from the predecessor in interest, if
|
||||||
|
the predecessor has it or can get it with reasonable efforts.
|
||||||
|
|
||||||
|
You may not impose any further restrictions on the exercise of the
|
||||||
|
rights granted or affirmed under this License. For example, you may
|
||||||
|
not impose a license fee, royalty, or other charge for exercise of
|
||||||
|
rights granted under this License, and you may not initiate litigation
|
||||||
|
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||||
|
any patent claim is infringed by making, using, selling, offering for
|
||||||
|
sale, or importing the Program or any portion of it.
|
||||||
|
|
||||||
|
11. Patents.
|
||||||
|
|
||||||
|
A "contributor" is a copyright holder who authorizes use under this
|
||||||
|
License of the Program or a work on which the Program is based. The
|
||||||
|
work thus licensed is called the contributor's "contributor version".
|
||||||
|
|
||||||
|
A contributor's "essential patent claims" are all patent claims
|
||||||
|
owned or controlled by the contributor, whether already acquired or
|
||||||
|
hereafter acquired, that would be infringed by some manner, permitted
|
||||||
|
by this License, of making, using, or selling its contributor version,
|
||||||
|
but do not include claims that would be infringed only as a
|
||||||
|
consequence of further modification of the contributor version. For
|
||||||
|
purposes of this definition, "control" includes the right to grant
|
||||||
|
patent sublicenses in a manner consistent with the requirements of
|
||||||
|
this License.
|
||||||
|
|
||||||
|
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||||
|
patent license under the contributor's essential patent claims, to
|
||||||
|
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||||
|
propagate the contents of its contributor version.
|
||||||
|
|
||||||
|
In the following three paragraphs, a "patent license" is any express
|
||||||
|
agreement or commitment, however denominated, not to enforce a patent
|
||||||
|
(such as an express permission to practice a patent or covenant not to
|
||||||
|
sue for patent infringement). To "grant" such a patent license to a
|
||||||
|
party means to make such an agreement or commitment not to enforce a
|
||||||
|
patent against the party.
|
||||||
|
|
||||||
|
If you convey a covered work, knowingly relying on a patent license,
|
||||||
|
and the Corresponding Source of the work is not available for anyone
|
||||||
|
to copy, free of charge and under the terms of this License, through a
|
||||||
|
publicly available network server or other readily accessible means,
|
||||||
|
then you must either (1) cause the Corresponding Source to be so
|
||||||
|
available, or (2) arrange to deprive yourself of the benefit of the
|
||||||
|
patent license for this particular work, or (3) arrange, in a manner
|
||||||
|
consistent with the requirements of this License, to extend the patent
|
||||||
|
license to downstream recipients. "Knowingly relying" means you have
|
||||||
|
actual knowledge that, but for the patent license, your conveying the
|
||||||
|
covered work in a country, or your recipient's use of the covered work
|
||||||
|
in a country, would infringe one or more identifiable patents in that
|
||||||
|
country that you have reason to believe are valid.
|
||||||
|
|
||||||
|
If, pursuant to or in connection with a single transaction or
|
||||||
|
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||||
|
covered work, and grant a patent license to some of the parties
|
||||||
|
receiving the covered work authorizing them to use, propagate, modify
|
||||||
|
or convey a specific copy of the covered work, then the patent license
|
||||||
|
you grant is automatically extended to all recipients of the covered
|
||||||
|
work and works based on it.
|
||||||
|
|
||||||
|
A patent license is "discriminatory" if it does not include within
|
||||||
|
the scope of its coverage, prohibits the exercise of, or is
|
||||||
|
conditioned on the non-exercise of one or more of the rights that are
|
||||||
|
specifically granted under this License. You may not convey a covered
|
||||||
|
work if you are a party to an arrangement with a third party that is
|
||||||
|
in the business of distributing software, under which you make payment
|
||||||
|
to the third party based on the extent of your activity of conveying
|
||||||
|
the work, and under which the third party grants, to any of the
|
||||||
|
parties who would receive the covered work from you, a discriminatory
|
||||||
|
patent license (a) in connection with copies of the covered work
|
||||||
|
conveyed by you (or copies made from those copies), or (b) primarily
|
||||||
|
for and in connection with specific products or compilations that
|
||||||
|
contain the covered work, unless you entered into that arrangement,
|
||||||
|
or that patent license was granted, prior to 28 March 2007.
|
||||||
|
|
||||||
|
Nothing in this License shall be construed as excluding or limiting
|
||||||
|
any implied license or other defenses to infringement that may
|
||||||
|
otherwise be available to you under applicable patent law.
|
||||||
|
|
||||||
|
12. No Surrender of Others' Freedom.
|
||||||
|
|
||||||
|
If conditions are imposed on you (whether by court order, agreement or
|
||||||
|
otherwise) that contradict the conditions of this License, they do not
|
||||||
|
excuse you from the conditions of this License. If you cannot convey a
|
||||||
|
covered work so as to satisfy simultaneously your obligations under this
|
||||||
|
License and any other pertinent obligations, then as a consequence you may
|
||||||
|
not convey it at all. For example, if you agree to terms that obligate you
|
||||||
|
to collect a royalty for further conveying from those to whom you convey
|
||||||
|
the Program, the only way you could satisfy both those terms and this
|
||||||
|
License would be to refrain entirely from conveying the Program.
|
||||||
|
|
||||||
|
13. Remote Network Interaction; Use with the GNU General Public License.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, if you modify the
|
||||||
|
Program, your modified version must prominently offer all users
|
||||||
|
interacting with it remotely through a computer network (if your version
|
||||||
|
supports such interaction) an opportunity to receive the Corresponding
|
||||||
|
Source of your version by providing access to the Corresponding Source
|
||||||
|
from a network server at no charge, through some standard or customary
|
||||||
|
means of facilitating copying of software. This Corresponding Source
|
||||||
|
shall include the Corresponding Source for any work covered by version 3
|
||||||
|
of the GNU General Public License that is incorporated pursuant to the
|
||||||
|
following paragraph.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, you have
|
||||||
|
permission to link or combine any covered work with a work licensed
|
||||||
|
under version 3 of the GNU General Public License into a single
|
||||||
|
combined work, and to convey the resulting work. The terms of this
|
||||||
|
License will continue to apply to the part which is the covered work,
|
||||||
|
but the work with which it is combined will remain governed by version
|
||||||
|
3 of the GNU General Public License.
|
||||||
|
|
||||||
|
14. Revised Versions of this License.
|
||||||
|
|
||||||
|
The Free Software Foundation may publish revised and/or new versions of
|
||||||
|
the GNU Affero General Public License from time to time. Such new versions
|
||||||
|
will be similar in spirit to the present version, but may differ in detail to
|
||||||
|
address new problems or concerns.
|
||||||
|
|
||||||
|
Each version is given a distinguishing version number. If the
|
||||||
|
Program specifies that a certain numbered version of the GNU Affero General
|
||||||
|
Public License "or any later version" applies to it, you have the
|
||||||
|
option of following the terms and conditions either of that numbered
|
||||||
|
version or of any later version published by the Free Software
|
||||||
|
Foundation. If the Program does not specify a version number of the
|
||||||
|
GNU Affero General Public License, you may choose any version ever published
|
||||||
|
by the Free Software Foundation.
|
||||||
|
|
||||||
|
If the Program specifies that a proxy can decide which future
|
||||||
|
versions of the GNU Affero General Public License can be used, that proxy's
|
||||||
|
public statement of acceptance of a version permanently authorizes you
|
||||||
|
to choose that version for the Program.
|
||||||
|
|
||||||
|
Later license versions may give you additional or different
|
||||||
|
permissions. However, no additional obligations are imposed on any
|
||||||
|
author or copyright holder as a result of your choosing to follow a
|
||||||
|
later version.
|
||||||
|
|
||||||
|
15. Disclaimer of Warranty.
|
||||||
|
|
||||||
|
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||||
|
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||||
|
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||||
|
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||||
|
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||||
|
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||||
|
|
||||||
|
16. Limitation of Liability.
|
||||||
|
|
||||||
|
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||||
|
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||||
|
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||||
|
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||||
|
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||||
|
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||||
|
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||||
|
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||||
|
SUCH DAMAGES.
|
||||||
|
|
||||||
|
17. Interpretation of Sections 15 and 16.
|
||||||
|
|
||||||
|
If the disclaimer of warranty and limitation of liability provided
|
||||||
|
above cannot be given local legal effect according to their terms,
|
||||||
|
reviewing courts shall apply local law that most closely approximates
|
||||||
|
an absolute waiver of all civil liability in connection with the
|
||||||
|
Program, unless a warranty or assumption of liability accompanies a
|
||||||
|
copy of the Program in return for a fee.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
How to Apply These Terms to Your New Programs
|
||||||
|
|
||||||
|
If you develop a new program, and you want it to be of the greatest
|
||||||
|
possible use to the public, the best way to achieve this is to make it
|
||||||
|
free software which everyone can redistribute and change under these terms.
|
||||||
|
|
||||||
|
To do so, attach the following notices to the program. It is safest
|
||||||
|
to attach them to the start of each source file to most effectively
|
||||||
|
state the exclusion of warranty; and each file should have at least
|
||||||
|
the "copyright" line and a pointer to where the full notice is found.
|
||||||
|
|
||||||
|
<one line to give the program's name and a brief idea of what it does.>
|
||||||
|
Copyright (C) <year> <name of author>
|
||||||
|
|
||||||
|
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/>.
|
||||||
|
|
||||||
|
Also add information on how to contact you by electronic and paper mail.
|
||||||
|
|
||||||
|
If your software can interact with users remotely through a computer
|
||||||
|
network, you should also make sure that it provides a way for users to
|
||||||
|
get its source. For example, if your program is a web application, its
|
||||||
|
interface could display a "Source" link that leads users to an archive
|
||||||
|
of the code. There are many ways you could offer source, and different
|
||||||
|
solutions will be better for different programs; see section 13 for the
|
||||||
|
specific requirements.
|
||||||
|
|
||||||
|
You should also get your employer (if you work as a programmer) or school,
|
||||||
|
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||||
|
For more information on this, and how to apply and follow the GNU AGPL, see
|
||||||
|
<http://www.gnu.org/licenses/>.
|
23
README.md
Normal file
23
README.md
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
# Universal MS Key Toolkit (UMSKT) Rust Edition
|
||||||
|
|
||||||
|
This is an unofficial Rust port of the [UMSKT project](https://github.com/UMSKT/UMSKT/). It is a pure Rust implementation rather than a binding, so it does not require any C or C++ dependencies and can be built for any platform supported by Rust and std.
|
||||||
|
|
||||||
|
It does not include the required keys.json file used by UMSKT. That needs to be found elsewhere, most likely in the UMSKT codebase.
|
||||||
|
|
||||||
|
## Credits
|
||||||
|
These contributors helped create the UMSKT project that this codebase was based on:
|
||||||
|
* z22
|
||||||
|
* MSKey
|
||||||
|
* sk00ter
|
||||||
|
* diamondggg
|
||||||
|
* pottzman
|
||||||
|
* Endermanch
|
||||||
|
* Neo-Desktop
|
||||||
|
* WitherOrNot
|
||||||
|
* TheTank20
|
||||||
|
|
||||||
|
## Development Requirements
|
||||||
|
* [The Rust toolchain](https://rustup.rs/)
|
||||||
|
|
||||||
|
## Build Steps
|
||||||
|
1. `cargo build`
|
|
@ -1,14 +1,8 @@
|
||||||
[package]
|
[package]
|
||||||
name = "xpkey"
|
name = "mskey"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[profile.release]
|
|
||||||
strip = true
|
|
||||||
opt-level = "z"
|
|
||||||
lto = true
|
|
||||||
codegen-units = 1
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
umskt = { path = "../umskt" }
|
umskt = { path = "../umskt" }
|
||||||
anyhow = "1.0.71"
|
anyhow = "1.0.71"
|
|
@ -102,7 +102,6 @@ fn validate(args: &ValidateArgs) -> Result<()> {
|
||||||
fn initialize_curve(bink: &Bink, bink_id: &str) -> Result<EllipticCurve> {
|
fn initialize_curve(bink: &Bink, bink_id: &str) -> Result<EllipticCurve> {
|
||||||
let p = &bink.p;
|
let p = &bink.p;
|
||||||
let a = &bink.a;
|
let a = &bink.a;
|
||||||
let b = &bink.b;
|
|
||||||
let gx = &bink.g.x;
|
let gx = &bink.g.x;
|
||||||
let gy = &bink.g.y;
|
let gy = &bink.g.y;
|
||||||
let kx = &bink.public.x;
|
let kx = &bink.public.x;
|
||||||
|
@ -110,7 +109,7 @@ fn initialize_curve(bink: &Bink, bink_id: &str) -> Result<EllipticCurve> {
|
||||||
|
|
||||||
log::info!("Elliptic curve parameters for BINK ID {bink_id}:\n{bink}");
|
log::info!("Elliptic curve parameters for BINK ID {bink_id}:\n{bink}");
|
||||||
|
|
||||||
EllipticCurve::new(p, a, b, gx, gy, kx, ky)
|
EllipticCurve::new(p, a, gx, gy, kx, ky)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn bink1998_generate(
|
fn bink1998_generate(
|
|
@ -6,7 +6,12 @@ edition = "2021"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = "1.0.71"
|
anyhow = "1.0.71"
|
||||||
bitreader = "0.3.7"
|
bitreader = "0.3.7"
|
||||||
openssl = { git = "https://github.com/sfackler/rust-openssl" }
|
elliptic-curve = "0.13.5"
|
||||||
|
num-bigint = { version = "0.4.3", features = ["rand"] }
|
||||||
|
num-integer = "0.1.45"
|
||||||
|
num-traits = "0.2.15"
|
||||||
|
rand = "0.8.5"
|
||||||
|
sha1 = "0.10.5"
|
||||||
thiserror = "1.0.40"
|
thiserror = "1.0.40"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
|
|
|
@ -1,20 +1,24 @@
|
||||||
use std::fmt::{Display, Formatter};
|
//! Structs to deal with older BINK (< `0x40`) product keys
|
||||||
|
use std::{
|
||||||
|
cmp::Ordering,
|
||||||
|
fmt::{Display, Formatter},
|
||||||
|
};
|
||||||
|
|
||||||
use anyhow::{bail, Result};
|
use anyhow::{bail, Result};
|
||||||
use bitreader::BitReader;
|
use bitreader::BitReader;
|
||||||
use openssl::{
|
use num_bigint::{BigInt, BigUint, RandomBits};
|
||||||
bn::{BigNum, BigNumContext, MsbOption},
|
use num_integer::Integer;
|
||||||
ec::{EcGroup, EcPoint},
|
use num_traits::{FromPrimitive, ToPrimitive};
|
||||||
sha::sha1,
|
use rand::Rng;
|
||||||
};
|
use sha1::{Digest, Sha1};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
crypto::{EllipticCurve, PrivateKey},
|
crypto::{EllipticCurve, Point, PrivateKey},
|
||||||
key::{base24_decode, base24_encode, strip_key},
|
key::{base24_decode, base24_encode, strip_key},
|
||||||
math::bitmask,
|
math::bitmask,
|
||||||
};
|
};
|
||||||
|
|
||||||
const FIELD_BITS: i32 = 384;
|
const FIELD_BITS: u64 = 384;
|
||||||
const FIELD_BYTES: usize = 48;
|
const FIELD_BYTES: usize = 48;
|
||||||
const SHA_MSG_LENGTH: usize = 4 + 2 * FIELD_BYTES;
|
const SHA_MSG_LENGTH: usize = 4 + 2 * FIELD_BYTES;
|
||||||
|
|
||||||
|
@ -23,6 +27,9 @@ const SERIAL_LENGTH_BITS: u8 = 30;
|
||||||
const UPGRADE_LENGTH_BITS: u8 = 1;
|
const UPGRADE_LENGTH_BITS: u8 = 1;
|
||||||
const EVERYTHING_ELSE: u8 = HASH_LENGTH_BITS + SERIAL_LENGTH_BITS + UPGRADE_LENGTH_BITS;
|
const EVERYTHING_ELSE: u8 = HASH_LENGTH_BITS + SERIAL_LENGTH_BITS + UPGRADE_LENGTH_BITS;
|
||||||
|
|
||||||
|
/// A product key for a BINK ID less than `0x40`
|
||||||
|
///
|
||||||
|
/// Every `ProductKey` contains a valid key for its given parameters.
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||||
pub struct ProductKey {
|
pub struct ProductKey {
|
||||||
upgrade: bool,
|
upgrade: bool,
|
||||||
|
@ -33,6 +40,9 @@ pub struct ProductKey {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ProductKey {
|
impl ProductKey {
|
||||||
|
/// Generates a new product key for the given parameters.
|
||||||
|
///
|
||||||
|
/// The key is verified to be valid before being returned.
|
||||||
pub fn new(
|
pub fn new(
|
||||||
curve: &EllipticCurve,
|
curve: &EllipticCurve,
|
||||||
private_key: &PrivateKey,
|
private_key: &PrivateKey,
|
||||||
|
@ -44,101 +54,117 @@ impl ProductKey {
|
||||||
let sequence = match sequence {
|
let sequence = match sequence {
|
||||||
Some(serial) => serial,
|
Some(serial) => serial,
|
||||||
None => {
|
None => {
|
||||||
let mut bn_rand = BigNum::new()?;
|
let mut rng = rand::thread_rng();
|
||||||
bn_rand.rand(19, MsbOption::MAYBE_ZERO, false)?;
|
let random: BigInt = rng.sample(RandomBits::new(32));
|
||||||
let o_raw = u32::from_be_bytes(bn_rand.to_vec_padded(4)?.try_into().unwrap());
|
let raw = u32::from_be_bytes(random.to_bytes_be().1[0..4].try_into().unwrap());
|
||||||
o_raw % 999999
|
raw % 999999
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Default to upgrade=false
|
// Default to upgrade=false
|
||||||
let upgrade = upgrade.unwrap_or(false);
|
let upgrade = upgrade.unwrap_or(false);
|
||||||
|
|
||||||
|
let private = &private_key.gen_order - &private_key.private_key;
|
||||||
|
|
||||||
// Generate a new random key
|
// Generate a new random key
|
||||||
let product_key = Self::generate(
|
let product_key = Self::generate(
|
||||||
&curve.curve,
|
curve,
|
||||||
&curve.gen_point,
|
&curve.gen_point,
|
||||||
&private_key.gen_order,
|
&private_key.gen_order,
|
||||||
&private_key.private_key,
|
&private,
|
||||||
channel_id,
|
channel_id,
|
||||||
sequence,
|
sequence,
|
||||||
upgrade,
|
upgrade,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Make sure the key is valid
|
// Make sure the key is valid
|
||||||
product_key.verify(&curve.curve, &curve.gen_point, &curve.pub_point)?;
|
product_key.verify(curve, &curve.gen_point, &curve.pub_point)?;
|
||||||
|
|
||||||
// Ship it
|
// Ship it
|
||||||
Ok(product_key)
|
Ok(product_key)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Validates an existing product key string and tried to create a new `ProductKey` from it.
|
||||||
|
///
|
||||||
|
/// # Arguments
|
||||||
|
///
|
||||||
|
/// * `curve` - The elliptic curve to use for verification.
|
||||||
|
/// * `key` - Should be 25 characters long, not including the (optional) hyphens.
|
||||||
pub fn from_key(curve: &EllipticCurve, key: &str) -> Result<Self> {
|
pub fn from_key(curve: &EllipticCurve, key: &str) -> Result<Self> {
|
||||||
let key = strip_key(key)?;
|
let key = strip_key(key)?;
|
||||||
let Ok(packed_key) = base24_decode(&key) else {
|
let Ok(packed_key) = base24_decode(&key) else {
|
||||||
bail!("Product key is in an incorrect format!")
|
bail!("Product key is in an incorrect format!")
|
||||||
};
|
};
|
||||||
let product_key = Self::from_packed(&packed_key)?;
|
let product_key = Self::from_packed(&packed_key)?;
|
||||||
product_key.verify(&curve.curve, &curve.gen_point, &curve.pub_point)?;
|
product_key.verify(curve, &curve.gen_point, &curve.pub_point)?;
|
||||||
Ok(product_key)
|
Ok(product_key)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn generate(
|
fn generate(
|
||||||
e_curve: &EcGroup,
|
e_curve: &EllipticCurve,
|
||||||
base_point: &EcPoint,
|
base_point: &Point,
|
||||||
gen_order: &BigNum,
|
gen_order: &BigInt,
|
||||||
private_key: &BigNum,
|
private_key: &BigInt,
|
||||||
channel_id: u32,
|
channel_id: u32,
|
||||||
sequence: u32,
|
sequence: u32,
|
||||||
upgrade: bool,
|
upgrade: bool,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
let mut num_context = BigNumContext::new().unwrap();
|
|
||||||
|
|
||||||
let mut c = BigNum::new()?;
|
|
||||||
let mut s = BigNum::new()?;
|
|
||||||
let mut x = BigNum::new()?;
|
|
||||||
let mut y = BigNum::new()?;
|
|
||||||
|
|
||||||
let mut ek: BigNum;
|
|
||||||
|
|
||||||
let serial = channel_id * 1_000_000 + sequence;
|
let serial = channel_id * 1_000_000 + sequence;
|
||||||
let data = serial << 1 | upgrade as u32;
|
let data = serial << 1 | upgrade as u32;
|
||||||
|
|
||||||
|
let mut rng = rand::thread_rng();
|
||||||
|
|
||||||
let product_key = loop {
|
let product_key = loop {
|
||||||
let mut r = EcPoint::new(e_curve)?;
|
let c: BigUint = rng.sample(RandomBits::new(FIELD_BITS));
|
||||||
|
let c: BigInt = c.into();
|
||||||
|
|
||||||
// Generate a random number c consisting of 384 bits without any constraints.
|
let r = e_curve.multiply_point(&c, base_point);
|
||||||
c.rand(FIELD_BITS, MsbOption::MAYBE_ZERO, false)?;
|
|
||||||
|
|
||||||
// Pick a random derivative of the base point on the elliptic curve.
|
let (x, y) = match r {
|
||||||
// R = cG;
|
Point::Point { x, y } => (x, y),
|
||||||
r.mul(e_curve, base_point, &c, &num_context)?;
|
Point::Infinity => bail!("Point at infinity!"),
|
||||||
|
};
|
||||||
// Acquire its coordinates.
|
|
||||||
// x = R.x; y = R.y;
|
|
||||||
r.affine_coordinates(e_curve, &mut x, &mut y, &mut num_context)?;
|
|
||||||
|
|
||||||
let mut msg_buffer: [u8; SHA_MSG_LENGTH] = [0; SHA_MSG_LENGTH];
|
let mut msg_buffer: [u8; SHA_MSG_LENGTH] = [0; SHA_MSG_LENGTH];
|
||||||
|
|
||||||
let mut x_bin = x.to_vec_padded(FIELD_BYTES as i32)?;
|
let x_bin = x.to_bytes_le().1;
|
||||||
x_bin.reverse();
|
let x_bin = match x_bin.len().cmp(&FIELD_BYTES) {
|
||||||
let mut y_bin = y.to_vec_padded(FIELD_BYTES as i32)?;
|
Ordering::Less => (0..FIELD_BYTES - x_bin.len())
|
||||||
y_bin.reverse();
|
.map(|_| 0)
|
||||||
|
.chain(x_bin.into_iter())
|
||||||
|
.collect(),
|
||||||
|
Ordering::Greater => continue,
|
||||||
|
Ordering::Equal => x_bin,
|
||||||
|
};
|
||||||
|
let y_bin = y.to_bytes_le().1;
|
||||||
|
let y_bin = match y_bin.len().cmp(&FIELD_BYTES) {
|
||||||
|
Ordering::Less => (0..FIELD_BYTES - y_bin.len())
|
||||||
|
.map(|_| 0)
|
||||||
|
.chain(y_bin.into_iter())
|
||||||
|
.collect(),
|
||||||
|
Ordering::Greater => continue,
|
||||||
|
Ordering::Equal => y_bin,
|
||||||
|
};
|
||||||
|
|
||||||
msg_buffer[0..4].copy_from_slice(&data.to_le_bytes());
|
msg_buffer[0..4].copy_from_slice(&data.to_le_bytes());
|
||||||
msg_buffer[4..4 + FIELD_BYTES].copy_from_slice(&x_bin);
|
msg_buffer[4..4 + FIELD_BYTES].copy_from_slice(&x_bin);
|
||||||
msg_buffer[4 + FIELD_BYTES..4 + FIELD_BYTES * 2].copy_from_slice(&y_bin);
|
msg_buffer[4 + FIELD_BYTES..4 + FIELD_BYTES * 2].copy_from_slice(&y_bin);
|
||||||
|
|
||||||
let msg_digest = sha1(&msg_buffer);
|
let msg_digest = {
|
||||||
|
let mut hasher = Sha1::new();
|
||||||
|
hasher.update(msg_buffer);
|
||||||
|
hasher.finalize()
|
||||||
|
};
|
||||||
|
|
||||||
let hash: u32 =
|
let hash: u32 =
|
||||||
u32::from_le_bytes(msg_digest[0..4].try_into().unwrap()) >> 4 & bitmask(28) as u32;
|
u32::from_le_bytes(msg_digest[0..4].try_into().unwrap()) >> 4 & bitmask(28) as u32;
|
||||||
|
|
||||||
ek = (*private_key).to_owned()?;
|
let mut ek = private_key.clone();
|
||||||
ek.mul_word(hash)?;
|
ek *= hash;
|
||||||
|
|
||||||
s.mod_add(&ek, &c, gen_order, &mut num_context)?;
|
let s = (ek + c).mod_floor(gen_order);
|
||||||
|
|
||||||
let signature = u64::from_be_bytes(s.to_vec_padded(8)?.try_into().unwrap());
|
let signature = s.to_u64().unwrap_or(0);
|
||||||
|
|
||||||
if signature <= bitmask(55) {
|
if signature <= bitmask(55) {
|
||||||
break Self {
|
break Self {
|
||||||
|
@ -156,36 +182,43 @@ impl ProductKey {
|
||||||
|
|
||||||
fn verify(
|
fn verify(
|
||||||
&self,
|
&self,
|
||||||
e_curve: &EcGroup,
|
e_curve: &EllipticCurve,
|
||||||
base_point: &EcPoint,
|
base_point: &Point,
|
||||||
public_key: &EcPoint,
|
public_key: &Point,
|
||||||
) -> Result<bool> {
|
) -> Result<bool> {
|
||||||
let mut ctx = BigNumContext::new()?;
|
let e = BigInt::from_u32(self.hash).unwrap();
|
||||||
|
let s = BigInt::from_u64(self.signature).unwrap();
|
||||||
|
|
||||||
let e = BigNum::from_u32(self.hash)?;
|
let t = e_curve.multiply_point(&s, base_point);
|
||||||
let s = BigNum::from_slice(&self.signature.to_be_bytes())?;
|
let mut p = e_curve.multiply_point(&e, public_key);
|
||||||
let mut x = BigNum::new()?;
|
|
||||||
let mut y = BigNum::new()?;
|
|
||||||
|
|
||||||
let mut t = EcPoint::new(e_curve)?;
|
p = e_curve.add_points(&p, &t);
|
||||||
let mut p = EcPoint::new(e_curve)?;
|
|
||||||
|
|
||||||
t.mul(e_curve, base_point, &s, &ctx)?;
|
let (x, y) = match p {
|
||||||
p.mul(e_curve, public_key, &e, &ctx)?;
|
Point::Point { x, y } => (x, y),
|
||||||
|
Point::Infinity => bail!("Point at infinity!"),
|
||||||
{
|
};
|
||||||
let p_copy = p.to_owned(e_curve)?;
|
|
||||||
p.add(e_curve, &t, &p_copy, &mut ctx)?;
|
|
||||||
}
|
|
||||||
|
|
||||||
p.affine_coordinates(e_curve, &mut x, &mut y, &mut ctx)?;
|
|
||||||
|
|
||||||
let mut msg_buffer: [u8; SHA_MSG_LENGTH] = [0; SHA_MSG_LENGTH];
|
let mut msg_buffer: [u8; SHA_MSG_LENGTH] = [0; SHA_MSG_LENGTH];
|
||||||
|
|
||||||
let mut x_bin = x.to_vec_padded(FIELD_BYTES as i32)?;
|
let x_bin = x.to_bytes_le().1;
|
||||||
x_bin.reverse();
|
let x_bin = if x_bin.len() < FIELD_BYTES {
|
||||||
let mut y_bin = y.to_vec_padded(FIELD_BYTES as i32)?;
|
(0..FIELD_BYTES - x_bin.len())
|
||||||
y_bin.reverse();
|
.map(|_| 0)
|
||||||
|
.chain(x_bin.into_iter())
|
||||||
|
.collect()
|
||||||
|
} else {
|
||||||
|
x_bin
|
||||||
|
};
|
||||||
|
let y_bin = y.to_bytes_le().1;
|
||||||
|
let y_bin = if y_bin.len() < FIELD_BYTES {
|
||||||
|
(0..FIELD_BYTES - y_bin.len())
|
||||||
|
.map(|_| 0)
|
||||||
|
.chain(y_bin.into_iter())
|
||||||
|
.collect()
|
||||||
|
} else {
|
||||||
|
y_bin
|
||||||
|
};
|
||||||
|
|
||||||
let serial = self.channel_id * 1_000_000 + self.sequence;
|
let serial = self.channel_id * 1_000_000 + self.sequence;
|
||||||
let data = serial << 1 | self.upgrade as u32;
|
let data = serial << 1 | self.upgrade as u32;
|
||||||
|
@ -194,7 +227,11 @@ impl ProductKey {
|
||||||
msg_buffer[4..4 + FIELD_BYTES].copy_from_slice(&x_bin);
|
msg_buffer[4..4 + FIELD_BYTES].copy_from_slice(&x_bin);
|
||||||
msg_buffer[4 + FIELD_BYTES..4 + FIELD_BYTES * 2].copy_from_slice(&y_bin);
|
msg_buffer[4 + FIELD_BYTES..4 + FIELD_BYTES * 2].copy_from_slice(&y_bin);
|
||||||
|
|
||||||
let msg_digest = sha1(&msg_buffer);
|
let msg_digest = {
|
||||||
|
let mut hasher = Sha1::new();
|
||||||
|
hasher.update(msg_buffer);
|
||||||
|
hasher.finalize()
|
||||||
|
};
|
||||||
|
|
||||||
let hash: u32 =
|
let hash: u32 =
|
||||||
u32::from_le_bytes(msg_digest[0..4].try_into().unwrap()) >> 4 & bitmask(28) as u32;
|
u32::from_le_bytes(msg_digest[0..4].try_into().unwrap()) >> 4 & bitmask(28) as u32;
|
||||||
|
@ -265,7 +302,7 @@ mod tests {
|
||||||
|
|
||||||
use serde_json::from_reader;
|
use serde_json::from_reader;
|
||||||
|
|
||||||
use crate::crypto::EllipticCurve;
|
use crate::{bink1998, crypto::EllipticCurve};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn verify_test() {
|
fn verify_test() {
|
||||||
|
@ -283,16 +320,15 @@ mod tests {
|
||||||
|
|
||||||
let p = bink["p"].as_str().unwrap();
|
let p = bink["p"].as_str().unwrap();
|
||||||
let a = bink["a"].as_str().unwrap();
|
let a = bink["a"].as_str().unwrap();
|
||||||
let b = bink["b"].as_str().unwrap();
|
|
||||||
let gx = bink["g"]["x"].as_str().unwrap();
|
let gx = bink["g"]["x"].as_str().unwrap();
|
||||||
let gy = bink["g"]["y"].as_str().unwrap();
|
let gy = bink["g"]["y"].as_str().unwrap();
|
||||||
let kx = bink["pub"]["x"].as_str().unwrap();
|
let kx = bink["pub"]["x"].as_str().unwrap();
|
||||||
let ky = bink["pub"]["y"].as_str().unwrap();
|
let ky = bink["pub"]["y"].as_str().unwrap();
|
||||||
|
|
||||||
let curve = EllipticCurve::new(p, a, b, gx, gy, kx, ky).unwrap();
|
let curve = EllipticCurve::new(p, a, gx, gy, kx, ky).unwrap();
|
||||||
|
|
||||||
assert!(super::ProductKey::from_key(&curve, product_key).is_ok());
|
assert!(bink1998::ProductKey::from_key(&curve, product_key).is_ok());
|
||||||
assert!(super::ProductKey::from_key(&curve, "11111-R6BG2-39J83-RYKHF-W47TT").is_err());
|
assert!(bink1998::ProductKey::from_key(&curve, "11111-R6BG2-39J83-RYKHF-W47TT").is_err());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -1,21 +1,24 @@
|
||||||
use std::fmt::{Display, Formatter};
|
//! Structs to deal with newer BINK (>= `0x40`) product keys
|
||||||
|
use std::{
|
||||||
|
cmp::Ordering,
|
||||||
|
fmt::{Display, Formatter},
|
||||||
|
};
|
||||||
|
|
||||||
use anyhow::{bail, Result};
|
use anyhow::{bail, Result};
|
||||||
use bitreader::BitReader;
|
use bitreader::BitReader;
|
||||||
use openssl::{
|
use num_bigint::{BigInt, BigUint, RandomBits};
|
||||||
bn::{BigNum, BigNumContext, MsbOption},
|
use num_integer::Integer;
|
||||||
ec::{EcGroup, EcPoint},
|
use num_traits::ToPrimitive;
|
||||||
rand::rand_bytes,
|
use rand::Rng;
|
||||||
sha::sha1,
|
use sha1::{Digest, Sha1};
|
||||||
};
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
crypto::{EllipticCurve, PrivateKey},
|
crypto::{mod_sqrt, EllipticCurve, Point, PrivateKey},
|
||||||
key::{base24_decode, base24_encode, strip_key},
|
key::{base24_decode, base24_encode, strip_key},
|
||||||
math::{bitmask, by_dword, next_sn_bits},
|
math::{bitmask, by_dword, next_sn_bits},
|
||||||
};
|
};
|
||||||
|
|
||||||
const FIELD_BITS: i32 = 512;
|
const FIELD_BITS: u64 = 512;
|
||||||
const FIELD_BYTES: usize = 64;
|
const FIELD_BYTES: usize = 64;
|
||||||
const SHA_MSG_LENGTH: usize = 3 + 2 * FIELD_BYTES;
|
const SHA_MSG_LENGTH: usize = 3 + 2 * FIELD_BYTES;
|
||||||
|
|
||||||
|
@ -26,6 +29,9 @@ const UPGRADE_LENGTH_BITS: u8 = 1;
|
||||||
const EVERYTHING_ELSE: u8 =
|
const EVERYTHING_ELSE: u8 =
|
||||||
SIGNATURE_LENGTH_BITS + HASH_LENGTH_BITS + CHANNEL_ID_LENGTH_BITS + UPGRADE_LENGTH_BITS;
|
SIGNATURE_LENGTH_BITS + HASH_LENGTH_BITS + CHANNEL_ID_LENGTH_BITS + UPGRADE_LENGTH_BITS;
|
||||||
|
|
||||||
|
/// A product key for a BINK ID `0x40` or higher
|
||||||
|
///
|
||||||
|
/// Every `ProductKey` contains a valid key for its given parameters.
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||||
pub struct ProductKey {
|
pub struct ProductKey {
|
||||||
upgrade: bool,
|
upgrade: bool,
|
||||||
|
@ -36,6 +42,9 @@ pub struct ProductKey {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ProductKey {
|
impl ProductKey {
|
||||||
|
/// Generates a new product key for the given parameters.
|
||||||
|
///
|
||||||
|
/// The key is verified to be valid before being returned.
|
||||||
pub fn new(
|
pub fn new(
|
||||||
curve: &EllipticCurve,
|
curve: &EllipticCurve,
|
||||||
private_key: &PrivateKey,
|
private_key: &PrivateKey,
|
||||||
|
@ -47,9 +56,10 @@ impl ProductKey {
|
||||||
let auth_info = match auth_info {
|
let auth_info = match auth_info {
|
||||||
Some(auth_info) => auth_info,
|
Some(auth_info) => auth_info,
|
||||||
None => {
|
None => {
|
||||||
let mut auth_info_bytes = [0_u8; 4];
|
let mut rng = rand::thread_rng();
|
||||||
rand_bytes(&mut auth_info_bytes)?;
|
let random: BigInt = rng.sample(RandomBits::new(32));
|
||||||
u32::from_ne_bytes(auth_info_bytes) & ((1 << 10) - 1)
|
let raw = u32::from_be_bytes(random.to_bytes_be().1[0..4].try_into().unwrap());
|
||||||
|
raw % (bitmask(10) as u32)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -58,7 +68,7 @@ impl ProductKey {
|
||||||
|
|
||||||
// Generate a new random key
|
// Generate a new random key
|
||||||
let product_key = Self::generate(
|
let product_key = Self::generate(
|
||||||
&curve.curve,
|
curve,
|
||||||
&curve.gen_point,
|
&curve.gen_point,
|
||||||
&private_key.gen_order,
|
&private_key.gen_order,
|
||||||
&private_key.private_key,
|
&private_key.private_key,
|
||||||
|
@ -68,19 +78,25 @@ impl ProductKey {
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Make sure the key is valid
|
// Make sure the key is valid
|
||||||
product_key.verify(&curve.curve, &curve.gen_point, &curve.pub_point)?;
|
product_key.verify(curve, &curve.gen_point, &curve.pub_point)?;
|
||||||
|
|
||||||
// Ship it
|
// Ship it
|
||||||
Ok(product_key)
|
Ok(product_key)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Validates an existing product key string and tried to create a new `ProductKey` from it.
|
||||||
|
///
|
||||||
|
/// # Arguments
|
||||||
|
///
|
||||||
|
/// * `curve` - The elliptic curve to use for verification.
|
||||||
|
/// * `key` - Should be 25 characters long, not including the (optional) hyphens.
|
||||||
pub fn from_key(curve: &EllipticCurve, key: &str) -> Result<Self> {
|
pub fn from_key(curve: &EllipticCurve, key: &str) -> Result<Self> {
|
||||||
let key = strip_key(key)?;
|
let key = strip_key(key)?;
|
||||||
let Ok(packed_key) = base24_decode(&key) else {
|
let Ok(packed_key) = base24_decode(&key) else {
|
||||||
bail!("Product key is in an incorrect format!")
|
bail!("Product key is in an incorrect format!")
|
||||||
};
|
};
|
||||||
let product_key = Self::from_packed(&packed_key)?;
|
let product_key = Self::from_packed(&packed_key)?;
|
||||||
let verified = product_key.verify(&curve.curve, &curve.gen_point, &curve.pub_point)?;
|
let verified = product_key.verify(curve, &curve.gen_point, &curve.pub_point)?;
|
||||||
if !verified {
|
if !verified {
|
||||||
bail!("Product key is invalid! Wrong BINK ID?");
|
bail!("Product key is invalid! Wrong BINK ID?");
|
||||||
}
|
}
|
||||||
|
@ -88,38 +104,50 @@ impl ProductKey {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn generate(
|
fn generate(
|
||||||
e_curve: &EcGroup,
|
e_curve: &EllipticCurve,
|
||||||
base_point: &EcPoint,
|
base_point: &Point,
|
||||||
gen_order: &BigNum,
|
gen_order: &BigInt,
|
||||||
private_key: &BigNum,
|
private_key: &BigInt,
|
||||||
channel_id: u32,
|
channel_id: u32,
|
||||||
auth_info: u32,
|
auth_info: u32,
|
||||||
upgrade: bool,
|
upgrade: bool,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
let mut num_context = BigNumContext::new().unwrap();
|
|
||||||
|
|
||||||
let mut c = BigNum::new()?;
|
|
||||||
let mut x = BigNum::new()?;
|
|
||||||
let mut y = BigNum::new()?;
|
|
||||||
|
|
||||||
let data = channel_id << 1 | upgrade as u32;
|
let data = channel_id << 1 | upgrade as u32;
|
||||||
|
|
||||||
|
let mut rng = rand::thread_rng();
|
||||||
|
|
||||||
let mut no_square = false;
|
let mut no_square = false;
|
||||||
let key = loop {
|
let key = loop {
|
||||||
let mut r = EcPoint::new(e_curve)?;
|
let c: BigUint = rng.sample(RandomBits::new(FIELD_BITS));
|
||||||
|
let mut c: BigInt = c.into();
|
||||||
|
|
||||||
c.rand(FIELD_BITS, MsbOption::MAYBE_ZERO, false)?;
|
let r = e_curve.multiply_point(&c, base_point);
|
||||||
|
|
||||||
r.mul(e_curve, base_point, &c, &num_context)?;
|
let (x, y) = match r {
|
||||||
|
Point::Point { x, y } => (x, y),
|
||||||
r.affine_coordinates(e_curve, &mut x, &mut y, &mut num_context)?;
|
Point::Infinity => bail!("Point at infinity!"),
|
||||||
|
};
|
||||||
|
|
||||||
let mut msg_buffer: [u8; SHA_MSG_LENGTH] = [0; SHA_MSG_LENGTH];
|
let mut msg_buffer: [u8; SHA_MSG_LENGTH] = [0; SHA_MSG_LENGTH];
|
||||||
|
|
||||||
let mut x_bin = x.to_vec_padded(FIELD_BYTES as i32)?;
|
let x_bin = x.to_bytes_le().1;
|
||||||
x_bin.reverse();
|
let x_bin = match x_bin.len().cmp(&FIELD_BYTES) {
|
||||||
let mut y_bin = y.to_vec_padded(FIELD_BYTES as i32)?;
|
Ordering::Less => (0..FIELD_BYTES - x_bin.len())
|
||||||
y_bin.reverse();
|
.map(|_| 0)
|
||||||
|
.chain(x_bin.into_iter())
|
||||||
|
.collect(),
|
||||||
|
Ordering::Greater => continue,
|
||||||
|
Ordering::Equal => x_bin,
|
||||||
|
};
|
||||||
|
let y_bin = y.to_bytes_le().1;
|
||||||
|
let y_bin = match y_bin.len().cmp(&FIELD_BYTES) {
|
||||||
|
Ordering::Less => (0..FIELD_BYTES - y_bin.len())
|
||||||
|
.map(|_| 0)
|
||||||
|
.chain(y_bin.into_iter())
|
||||||
|
.collect(),
|
||||||
|
Ordering::Greater => continue,
|
||||||
|
Ordering::Equal => y_bin,
|
||||||
|
};
|
||||||
|
|
||||||
msg_buffer[0x00] = 0x79;
|
msg_buffer[0x00] = 0x79;
|
||||||
msg_buffer[0x01] = (data & 0x00FF) as u8;
|
msg_buffer[0x01] = (data & 0x00FF) as u8;
|
||||||
|
@ -128,7 +156,11 @@ impl ProductKey {
|
||||||
msg_buffer[3..3 + FIELD_BYTES].copy_from_slice(&x_bin);
|
msg_buffer[3..3 + FIELD_BYTES].copy_from_slice(&x_bin);
|
||||||
msg_buffer[3 + FIELD_BYTES..3 + FIELD_BYTES * 2].copy_from_slice(&y_bin);
|
msg_buffer[3 + FIELD_BYTES..3 + FIELD_BYTES * 2].copy_from_slice(&y_bin);
|
||||||
|
|
||||||
let msg_digest = sha1(&msg_buffer);
|
let msg_digest = {
|
||||||
|
let mut hasher = Sha1::new();
|
||||||
|
hasher.update(msg_buffer);
|
||||||
|
hasher.finalize()
|
||||||
|
};
|
||||||
|
|
||||||
let hash: u32 = by_dword(&msg_digest[0..4]) & bitmask(31) as u32;
|
let hash: u32 = by_dword(&msg_digest[0..4]) & bitmask(31) as u32;
|
||||||
|
|
||||||
|
@ -144,42 +176,43 @@ impl ProductKey {
|
||||||
msg_buffer[0x09] = 0x00;
|
msg_buffer[0x09] = 0x00;
|
||||||
msg_buffer[0x0A] = 0x00;
|
msg_buffer[0x0A] = 0x00;
|
||||||
|
|
||||||
let msg_digest = sha1(&msg_buffer[..=0x0A]);
|
let msg_digest = {
|
||||||
|
let mut hasher = Sha1::new();
|
||||||
|
hasher.update(&msg_buffer[..=0x0A]);
|
||||||
|
hasher.finalize()
|
||||||
|
};
|
||||||
|
|
||||||
let i_signature = next_sn_bits(by_dword(&msg_digest[4..8]) as u64, 30, 2) << 32
|
let i_signature = next_sn_bits(by_dword(&msg_digest[4..8]) as u64, 30, 2) << 32
|
||||||
| by_dword(&msg_digest[0..4]) as u64;
|
| by_dword(&msg_digest[0..4]) as u64;
|
||||||
|
|
||||||
let mut e = BigNum::from_slice(&i_signature.to_be_bytes())?;
|
let mut e = BigInt::from(i_signature);
|
||||||
|
|
||||||
let e_2 = e.to_owned()?;
|
e = (e * private_key).mod_floor(gen_order);
|
||||||
e.mod_mul(&e_2, private_key, gen_order, &mut num_context)?;
|
|
||||||
|
|
||||||
let mut s = e.to_owned()?;
|
let mut s = e.clone();
|
||||||
|
|
||||||
let s_2 = s.to_owned()?;
|
s = (&s * &s).mod_floor(gen_order);
|
||||||
s.mod_sqr(&s_2, gen_order, &mut num_context)?;
|
|
||||||
|
|
||||||
let c_2 = c.to_owned()?;
|
c <<= 2;
|
||||||
c.lshift(&c_2, 2)?;
|
|
||||||
|
|
||||||
s = &s + &c;
|
s = &s + &c;
|
||||||
|
|
||||||
let s_2 = s.to_owned()?;
|
match mod_sqrt(&s, gen_order) {
|
||||||
if s.mod_sqrt(&s_2, gen_order, &mut num_context).is_err() {
|
Some(res) => s = res,
|
||||||
no_square = true;
|
None => {
|
||||||
};
|
no_square = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let s_2 = s.to_owned()?;
|
s = (s - e).mod_floor(gen_order);
|
||||||
s.mod_sub(&s_2, &e, gen_order, &mut num_context)?;
|
|
||||||
|
|
||||||
if s.is_bit_set(0) {
|
if s.is_odd() {
|
||||||
s = &s + gen_order;
|
s = &s + gen_order;
|
||||||
}
|
}
|
||||||
|
|
||||||
let s_2 = s.to_owned()?;
|
s >>= 1;
|
||||||
s.rshift1(&s_2)?;
|
|
||||||
|
|
||||||
let signature = u64::from_be_bytes(s.to_vec_padded(8)?.try_into().unwrap());
|
let signature = s.to_u64().unwrap_or(0);
|
||||||
|
|
||||||
let product_key = Self {
|
let product_key = Self {
|
||||||
upgrade,
|
upgrade,
|
||||||
|
@ -201,12 +234,10 @@ impl ProductKey {
|
||||||
|
|
||||||
fn verify(
|
fn verify(
|
||||||
&self,
|
&self,
|
||||||
e_curve: &EcGroup,
|
e_curve: &EllipticCurve,
|
||||||
base_point: &EcPoint,
|
base_point: &Point,
|
||||||
public_key: &EcPoint,
|
public_key: &Point,
|
||||||
) -> Result<bool> {
|
) -> Result<bool> {
|
||||||
let mut num_context = BigNumContext::new()?;
|
|
||||||
|
|
||||||
let data = self.channel_id << 1 | self.upgrade as u32;
|
let data = self.channel_id << 1 | self.upgrade as u32;
|
||||||
|
|
||||||
let mut msg_buffer: [u8; SHA_MSG_LENGTH] = [0; SHA_MSG_LENGTH];
|
let mut msg_buffer: [u8; SHA_MSG_LENGTH] = [0; SHA_MSG_LENGTH];
|
||||||
|
@ -223,39 +254,47 @@ impl ProductKey {
|
||||||
msg_buffer[0x09] = 0x00;
|
msg_buffer[0x09] = 0x00;
|
||||||
msg_buffer[0x0A] = 0x00;
|
msg_buffer[0x0A] = 0x00;
|
||||||
|
|
||||||
let msg_digest = sha1(&msg_buffer[..=0x0A]);
|
let msg_digest = {
|
||||||
|
let mut hasher = Sha1::new();
|
||||||
|
hasher.update(&msg_buffer[..=0x0A]);
|
||||||
|
hasher.finalize()
|
||||||
|
};
|
||||||
|
|
||||||
let i_signature = next_sn_bits(by_dword(&msg_digest[4..8]) as u64, 30, 2) << 32
|
let i_signature = next_sn_bits(by_dword(&msg_digest[4..8]) as u64, 30, 2) << 32
|
||||||
| by_dword(&msg_digest[0..4]) as u64;
|
| by_dword(&msg_digest[0..4]) as u64;
|
||||||
|
|
||||||
let e = BigNum::from_slice(&i_signature.to_be_bytes())?;
|
let e = BigInt::from(i_signature);
|
||||||
let s = BigNum::from_slice(&self.signature.to_be_bytes())?;
|
let s = BigInt::from(self.signature);
|
||||||
|
|
||||||
let mut x = BigNum::new()?;
|
let t = e_curve.multiply_point(&s, base_point);
|
||||||
let mut y = BigNum::new()?;
|
let mut p = e_curve.multiply_point(&e, public_key);
|
||||||
|
|
||||||
let mut p = EcPoint::new(e_curve)?;
|
p = e_curve.add_points(&t, &p);
|
||||||
let mut t = EcPoint::new(e_curve)?;
|
p = e_curve.multiply_point(&s, &p);
|
||||||
|
|
||||||
t.mul(e_curve, base_point, &s, &num_context)?;
|
let (x, y) = match p {
|
||||||
p.mul(e_curve, public_key, &e, &num_context)?;
|
Point::Point { x, y } => (x, y),
|
||||||
|
Point::Infinity => bail!("Point at infinity!"),
|
||||||
|
};
|
||||||
|
|
||||||
{
|
let x_bin = x.to_bytes_le().1;
|
||||||
let p_2 = p.to_owned(e_curve)?;
|
let x_bin = if x_bin.len() < FIELD_BYTES {
|
||||||
p.add(e_curve, &t, &p_2, &mut num_context)?;
|
(0..FIELD_BYTES - x_bin.len())
|
||||||
}
|
.map(|_| 0)
|
||||||
|
.chain(x_bin.into_iter())
|
||||||
{
|
.collect()
|
||||||
let p_2 = p.to_owned(e_curve)?;
|
} else {
|
||||||
p.mul(e_curve, &p_2, &s, &num_context)?;
|
x_bin
|
||||||
}
|
};
|
||||||
|
let y_bin = y.to_bytes_le().1;
|
||||||
p.affine_coordinates(e_curve, &mut x, &mut y, &mut num_context)?;
|
let y_bin = if y_bin.len() < FIELD_BYTES {
|
||||||
|
(0..FIELD_BYTES - y_bin.len())
|
||||||
let mut x_bin = x.to_vec_padded(FIELD_BYTES as i32)?;
|
.map(|_| 0)
|
||||||
x_bin.reverse();
|
.chain(y_bin.into_iter())
|
||||||
let mut y_bin = y.to_vec_padded(FIELD_BYTES as i32)?;
|
.collect()
|
||||||
y_bin.reverse();
|
} else {
|
||||||
|
y_bin
|
||||||
|
};
|
||||||
|
|
||||||
msg_buffer[0x00] = 0x79;
|
msg_buffer[0x00] = 0x79;
|
||||||
msg_buffer[0x01] = (data & 0x00FF) as u8;
|
msg_buffer[0x01] = (data & 0x00FF) as u8;
|
||||||
|
@ -264,7 +303,11 @@ impl ProductKey {
|
||||||
msg_buffer[3..3 + FIELD_BYTES].copy_from_slice(&x_bin);
|
msg_buffer[3..3 + FIELD_BYTES].copy_from_slice(&x_bin);
|
||||||
msg_buffer[3 + FIELD_BYTES..3 + FIELD_BYTES * 2].copy_from_slice(&y_bin);
|
msg_buffer[3 + FIELD_BYTES..3 + FIELD_BYTES * 2].copy_from_slice(&y_bin);
|
||||||
|
|
||||||
let msg_digest = sha1(&msg_buffer);
|
let msg_digest = {
|
||||||
|
let mut hasher = Sha1::new();
|
||||||
|
hasher.update(msg_buffer);
|
||||||
|
hasher.finalize()
|
||||||
|
};
|
||||||
|
|
||||||
let hash: u32 = by_dword(&msg_digest[0..4]) & bitmask(31) as u32;
|
let hash: u32 = by_dword(&msg_digest[0..4]) & bitmask(31) as u32;
|
||||||
|
|
||||||
|
@ -353,13 +396,12 @@ mod tests {
|
||||||
|
|
||||||
let p = bink["p"].as_str().unwrap();
|
let p = bink["p"].as_str().unwrap();
|
||||||
let a = bink["a"].as_str().unwrap();
|
let a = bink["a"].as_str().unwrap();
|
||||||
let b = bink["b"].as_str().unwrap();
|
|
||||||
let gx = bink["g"]["x"].as_str().unwrap();
|
let gx = bink["g"]["x"].as_str().unwrap();
|
||||||
let gy = bink["g"]["y"].as_str().unwrap();
|
let gy = bink["g"]["y"].as_str().unwrap();
|
||||||
let kx = bink["pub"]["x"].as_str().unwrap();
|
let kx = bink["pub"]["x"].as_str().unwrap();
|
||||||
let ky = bink["pub"]["y"].as_str().unwrap();
|
let ky = bink["pub"]["y"].as_str().unwrap();
|
||||||
|
|
||||||
let curve = EllipticCurve::new(p, a, b, gx, gy, kx, ky).unwrap();
|
let curve = EllipticCurve::new(p, a, gx, gy, kx, ky).unwrap();
|
||||||
|
|
||||||
assert!(super::ProductKey::from_key(&curve, product_key).is_ok());
|
assert!(super::ProductKey::from_key(&curve, product_key).is_ok());
|
||||||
assert!(super::ProductKey::from_key(&curve, "11111-YRGC8-4KYTG-C3FCC-JCFDY").is_err());
|
assert!(super::ProductKey::from_key(&curve, "11111-YRGC8-4KYTG-C3FCC-JCFDY").is_err());
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,5 +1,13 @@
|
||||||
use std::ffi::{CStr, CString};
|
//! Code to generate a Confirmation ID for a given Installation ID
|
||||||
|
//!
|
||||||
|
//! ## History
|
||||||
|
//! The algorithm this uses was originally provided to the UMSKT project by diamondggg.
|
||||||
|
//! 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 Rust version of the code was created by running the original through C2Rust
|
||||||
|
//! and then manually fixing up the result.
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
mod black_box;
|
mod black_box;
|
||||||
|
@ -20,6 +28,10 @@ pub enum ConfirmationIdError {
|
||||||
Unlucky,
|
Unlucky,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Generates a confirmation ID from the given installation ID
|
||||||
|
///
|
||||||
|
/// # Arguments
|
||||||
|
/// * `installation_id` - A string with 7 groups of 6 digits, with or without hyphens
|
||||||
pub fn generate(installation_id: &str) -> Result<String, ConfirmationIdError> {
|
pub fn generate(installation_id: &str) -> Result<String, ConfirmationIdError> {
|
||||||
if installation_id.len() < 54 {
|
if installation_id.len() < 54 {
|
||||||
return Err(ConfirmationIdError::TooShort);
|
return Err(ConfirmationIdError::TooShort);
|
||||||
|
@ -27,9 +39,9 @@ pub fn generate(installation_id: &str) -> Result<String, ConfirmationIdError> {
|
||||||
if installation_id.len() > 54 {
|
if installation_id.len() > 54 {
|
||||||
return Err(ConfirmationIdError::TooLarge);
|
return Err(ConfirmationIdError::TooLarge);
|
||||||
}
|
}
|
||||||
let inst_id = CString::new(installation_id).unwrap();
|
let inst_id = installation_id.as_bytes();
|
||||||
let conf_id = [0u8; 49];
|
let mut conf_id = [0u8; 48];
|
||||||
let result = unsafe { black_box::generate(inst_id.as_ptr(), conf_id.as_ptr() as *mut i8) };
|
let result = black_box::generate(inst_id, &mut conf_id);
|
||||||
match result {
|
match result {
|
||||||
0 => {}
|
0 => {}
|
||||||
1 => return Err(ConfirmationIdError::TooShort),
|
1 => return Err(ConfirmationIdError::TooShort),
|
||||||
|
@ -40,12 +52,7 @@ pub fn generate(installation_id: &str) -> Result<String, ConfirmationIdError> {
|
||||||
6 => return Err(ConfirmationIdError::Unlucky),
|
6 => return Err(ConfirmationIdError::Unlucky),
|
||||||
_ => panic!("Unknown error code: {}", result),
|
_ => panic!("Unknown error code: {}", result),
|
||||||
}
|
}
|
||||||
unsafe {
|
Ok(String::from_utf8_lossy(&conf_id).into())
|
||||||
Ok(CStr::from_ptr(conf_id.as_ptr() as *const i8)
|
|
||||||
.to_str()
|
|
||||||
.unwrap()
|
|
||||||
.to_string())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
|
@ -1,24 +1,42 @@
|
||||||
|
//! Code that deals with elliptic curve cryptography
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use openssl::{
|
use num_bigint::BigInt;
|
||||||
bn::{BigNum, BigNumContext},
|
use num_integer::Integer;
|
||||||
ec::{EcGroup, EcPoint},
|
use num_traits::{Num, One, Zero};
|
||||||
};
|
|
||||||
|
|
||||||
pub struct EllipticCurve {
|
/// Represents a point (possibly) on an elliptic curve.
|
||||||
pub curve: EcGroup,
|
///
|
||||||
pub gen_point: EcPoint,
|
/// This is either the point at infinity, or a point with affine coordinates `x` and `y`.
|
||||||
pub pub_point: EcPoint,
|
/// It is not guaranteed to be on the curve.
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
|
pub enum Point {
|
||||||
|
Infinity,
|
||||||
|
Point { x: BigInt, y: BigInt },
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Represents an elliptic curve of the form `y^2 = x^3 + ax + b (mod p)`
|
||||||
|
///
|
||||||
|
/// `b` is not used in any of the calculations, so is not stored.
|
||||||
|
///
|
||||||
|
/// This implements all the necessary elliptic curve arithmetic for verifying and generating
|
||||||
|
/// product keys.
|
||||||
|
pub struct EllipticCurve {
|
||||||
|
a: BigInt,
|
||||||
|
p: BigInt,
|
||||||
|
pub gen_point: Point,
|
||||||
|
pub pub_point: Point,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Stores the additional data necessary to generate product keys.
|
||||||
pub struct PrivateKey {
|
pub struct PrivateKey {
|
||||||
pub gen_order: BigNum,
|
pub gen_order: BigInt,
|
||||||
pub private_key: BigNum,
|
pub private_key: BigInt,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PrivateKey {
|
impl PrivateKey {
|
||||||
pub fn new(gen_order: &str, private_key: &str) -> Result<Self> {
|
pub fn new(gen_order: &str, private_key: &str) -> Result<Self> {
|
||||||
let gen_order = BigNum::from_dec_str(gen_order)?;
|
let gen_order = BigInt::from_str_radix(gen_order, 10)?;
|
||||||
let private_key = &gen_order - &BigNum::from_dec_str(private_key)?;
|
let private_key = BigInt::from_str_radix(private_key, 10)?;
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
gen_order,
|
gen_order,
|
||||||
private_key,
|
private_key,
|
||||||
|
@ -27,37 +45,179 @@ impl PrivateKey {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EllipticCurve {
|
impl EllipticCurve {
|
||||||
|
/// Creates a new elliptic curve from the given parameters. `b` is not necessary.
|
||||||
pub fn new(
|
pub fn new(
|
||||||
p: &str,
|
p: &str,
|
||||||
a: &str,
|
a: &str,
|
||||||
b: &str,
|
|
||||||
generator_x: &str,
|
generator_x: &str,
|
||||||
generator_y: &str,
|
generator_y: &str,
|
||||||
public_key_x: &str,
|
public_key_x: &str,
|
||||||
public_key_y: &str,
|
public_key_y: &str,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
let mut context = BigNumContext::new()?;
|
let p = BigInt::from_str_radix(p, 10)?;
|
||||||
|
let a = BigInt::from_str_radix(a, 10)?;
|
||||||
|
let generator_x = BigInt::from_str_radix(generator_x, 10)?;
|
||||||
|
let generator_y = BigInt::from_str_radix(generator_y, 10)?;
|
||||||
|
let public_key_x = BigInt::from_str_radix(public_key_x, 10)?;
|
||||||
|
let public_key_y = BigInt::from_str_radix(public_key_y, 10)?;
|
||||||
|
|
||||||
let p = BigNum::from_dec_str(p)?;
|
let gen_point = Point::Point {
|
||||||
let a = BigNum::from_dec_str(a)?;
|
x: generator_x,
|
||||||
let b = BigNum::from_dec_str(b)?;
|
y: generator_y,
|
||||||
let generator_x = BigNum::from_dec_str(generator_x)?;
|
};
|
||||||
let generator_y = BigNum::from_dec_str(generator_y)?;
|
|
||||||
let public_key_x = BigNum::from_dec_str(public_key_x)?;
|
|
||||||
let public_key_y = BigNum::from_dec_str(public_key_y)?;
|
|
||||||
|
|
||||||
let curve = EcGroup::from_components(p, a, b, &mut context)?;
|
let pub_point = Point::Point {
|
||||||
|
x: public_key_x,
|
||||||
let mut gen_point = EcPoint::new(&curve)?;
|
y: public_key_y,
|
||||||
gen_point.set_affine_coordinates_gfp(&curve, &generator_x, &generator_y, &mut context)?;
|
};
|
||||||
|
|
||||||
let mut pub_point = EcPoint::new(&curve)?;
|
|
||||||
pub_point.set_affine_coordinates_gfp(&curve, &public_key_x, &public_key_y, &mut context)?;
|
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
curve,
|
a,
|
||||||
|
p,
|
||||||
gen_point,
|
gen_point,
|
||||||
pub_point,
|
pub_point,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn mod_inverse(a: &BigInt, p: &BigInt) -> BigInt {
|
||||||
|
let egcd = a.extended_gcd(p);
|
||||||
|
egcd.x.mod_floor(p)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn double_point(&self, point: &Point) -> Point {
|
||||||
|
match point {
|
||||||
|
Point::Point { x, y } => {
|
||||||
|
if y.is_zero() {
|
||||||
|
Point::Infinity
|
||||||
|
} else {
|
||||||
|
let three = BigInt::from(3);
|
||||||
|
let two = BigInt::from(2);
|
||||||
|
|
||||||
|
let lambda = (three * x * x + &self.a) * Self::mod_inverse(&(two * y), &self.p);
|
||||||
|
let lamba_sqr = (&lambda * &lambda).mod_floor(&self.p);
|
||||||
|
let x3 = (&lamba_sqr - x - x).mod_floor(&self.p);
|
||||||
|
let y3 = (&lambda * (x - &x3) - y).mod_floor(&self.p);
|
||||||
|
|
||||||
|
Point::Point { x: x3, y: y3 }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Point::Infinity => Point::Infinity,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Adds two points on the curve together.
|
||||||
|
///
|
||||||
|
/// If the points are the same, it doubles the point.
|
||||||
|
///
|
||||||
|
/// If one of the points is the point at infinity, it returns the other point.
|
||||||
|
///
|
||||||
|
/// If both points are the point at infinity, it returns the point at infinity.
|
||||||
|
pub(crate) fn add_points(&self, point1: &Point, point2: &Point) -> Point {
|
||||||
|
match (point1, point2) {
|
||||||
|
(Point::Point { x: x1, y: y1 }, Point::Point { x: x2, y: y2 }) => {
|
||||||
|
if point1 == point2 {
|
||||||
|
self.double_point(point1)
|
||||||
|
} else {
|
||||||
|
let lambda = (y2 - y1) * Self::mod_inverse(&(x2 - x1), &self.p);
|
||||||
|
let x3 = ((&lambda * &lambda) - x1 - x2).mod_floor(&self.p);
|
||||||
|
let y3: BigInt = ((&lambda * (x1 - &x3)) - y1).mod_floor(&self.p);
|
||||||
|
|
||||||
|
Point::Point { x: x3, y: y3 }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
(Point::Point { x, y }, Point::Infinity) | (Point::Infinity, Point::Point { x, y }) => {
|
||||||
|
Point::Point {
|
||||||
|
x: x.clone(),
|
||||||
|
y: y.clone(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
(Point::Infinity, Point::Infinity) => Point::Infinity,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Multiplies a point by a scalar.
|
||||||
|
///
|
||||||
|
/// Uses the double-and-add algorithm.
|
||||||
|
pub(crate) fn multiply_point(&self, s: &BigInt, point: &Point) -> Point {
|
||||||
|
let mut res = Point::Infinity;
|
||||||
|
let mut temp = point.clone();
|
||||||
|
|
||||||
|
let mut s = s.clone();
|
||||||
|
|
||||||
|
while s > BigInt::zero() {
|
||||||
|
if (&s % BigInt::from(2)) == BigInt::one() {
|
||||||
|
res = self.add_points(&res, &temp);
|
||||||
|
}
|
||||||
|
temp = self.double_point(&temp);
|
||||||
|
|
||||||
|
s >>= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
res
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Calculates the legendre symbol of `p`: `1`, `0`, or `-1 mod p`
|
||||||
|
fn ls(a: &BigInt, p: &BigInt) -> BigInt {
|
||||||
|
let exp = (p - BigInt::one()) / BigInt::from(2);
|
||||||
|
a.modpow(&exp, p)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Calculates the modular square root of `n` such that `result^2 = n (mod p)`
|
||||||
|
/// using the Tonelli-Shanks algorithm. Returns `None` if `p` is not prime.
|
||||||
|
///
|
||||||
|
/// # Arguments
|
||||||
|
///
|
||||||
|
/// * `n` - The number to find the square root of
|
||||||
|
/// * `p` - The prime modulus (_must_ be prime)
|
||||||
|
pub(crate) fn mod_sqrt(n: &BigInt, p: &BigInt) -> Option<BigInt> {
|
||||||
|
if !ls(n, p).is_one() {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut q = p - 1;
|
||||||
|
let mut s = BigInt::zero();
|
||||||
|
while (&q & &BigInt::one()).is_zero() {
|
||||||
|
s += 1;
|
||||||
|
q >>= 1
|
||||||
|
}
|
||||||
|
|
||||||
|
if s.is_one() {
|
||||||
|
let exp = (p + 1) / 4;
|
||||||
|
let r1 = n.modpow(&exp, p);
|
||||||
|
return Some(p - &r1);
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut z = BigInt::from(2);
|
||||||
|
while ls(&z, p) != p - 1 {
|
||||||
|
z += 1
|
||||||
|
}
|
||||||
|
let mut c = z.modpow(&q, p);
|
||||||
|
|
||||||
|
let mut r = n.modpow(&((&q + 1) / 2), p);
|
||||||
|
let mut t = n.modpow(&q, p);
|
||||||
|
let mut m = s;
|
||||||
|
|
||||||
|
loop {
|
||||||
|
if t.is_one() {
|
||||||
|
return Some(p - &r);
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut i = BigInt::zero();
|
||||||
|
let mut z = t.clone();
|
||||||
|
let mut b = c.clone();
|
||||||
|
while !z.is_one() && i < &m - 1 {
|
||||||
|
z = &z * &z % p;
|
||||||
|
i += 1;
|
||||||
|
}
|
||||||
|
let mut e = &m - &i - 1;
|
||||||
|
while e > BigInt::zero() {
|
||||||
|
b = &b * &b % p;
|
||||||
|
e -= 1;
|
||||||
|
}
|
||||||
|
r = &r * &b % p;
|
||||||
|
c = &b * &b % p;
|
||||||
|
t = &t * &c % p;
|
||||||
|
m = i;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
|
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use openssl::bn::BigNum;
|
use num_bigint::{BigInt, Sign};
|
||||||
|
use num_integer::Integer;
|
||||||
|
use num_traits::{ToPrimitive, Zero};
|
||||||
|
|
||||||
const PK_LENGTH: usize = 25;
|
const PK_LENGTH: usize = 25;
|
||||||
|
|
||||||
|
@ -17,20 +19,24 @@ pub(crate) fn base24_decode(cd_key: &str) -> Result<Vec<u8>> {
|
||||||
.filter_map(|c| KEY_CHARSET.iter().position(|&x| x == c).map(|i| i as u8))
|
.filter_map(|c| KEY_CHARSET.iter().position(|&x| x == c).map(|i| i as u8))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let mut y = BigNum::from_u32(0).unwrap();
|
let mut y = BigInt::zero();
|
||||||
|
|
||||||
for i in decoded_key {
|
for i in decoded_key {
|
||||||
y.mul_word((PK_LENGTH - 1) as u32).unwrap();
|
y *= PK_LENGTH - 1;
|
||||||
y.add_word(i.into()).unwrap();
|
y += i as u32;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(y.to_vec())
|
Ok(y.to_bytes_be().1)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn base24_encode(byte_seq: &[u8]) -> Result<String> {
|
pub(crate) fn base24_encode(byte_seq: &[u8]) -> Result<String> {
|
||||||
let mut z = BigNum::from_slice(byte_seq).unwrap();
|
let mut z = BigInt::from_bytes_be(Sign::Plus, byte_seq);
|
||||||
let mut out: VecDeque<char> = VecDeque::new();
|
let mut out: VecDeque<char> = VecDeque::new();
|
||||||
(0..=24).for_each(|_| out.push_front(KEY_CHARSET[z.div_word(24).unwrap() as usize]));
|
(0..=24).for_each(|_| {
|
||||||
|
let (quo, rem) = z.div_rem(&BigInt::from(24));
|
||||||
|
z = quo;
|
||||||
|
out.push_front(KEY_CHARSET[rem.to_u32().unwrap() as usize]);
|
||||||
|
});
|
||||||
Ok(out.iter().collect())
|
Ok(out.iter().collect())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,13 @@
|
||||||
|
//! # Universal MS Key Toolkit (UMSKT) Rust Edition Rust Edition
|
||||||
|
//!
|
||||||
|
//! This is an unofficial Rust port of the [UMSKT project](https://github.com/UMSKT/UMSKT/).
|
||||||
|
//! It is a pure Rust implementation rather than a binding, so it does not require any C or
|
||||||
|
//! C++ dependencies and can be built for any platform supported by Rust and `std`.
|
||||||
|
//!
|
||||||
|
//! It does not include the required `keys.json` file used by UMSKT. That needs to be found elsewhere.
|
||||||
|
//!
|
||||||
|
//! See `README.md` for more information.
|
||||||
|
//!
|
||||||
pub mod bink1998;
|
pub mod bink1998;
|
||||||
pub mod bink2002;
|
pub mod bink2002;
|
||||||
pub mod confid;
|
pub mod confid;
|
||||||
|
|
Loading…
Add table
Reference in a new issue