mirror of
https://github.com/danog/tergent.git
synced 2024-11-26 12:04:49 +01:00
Switch the interface to cryptoki
Remove the ssh-agent interface and replace it with PKCS#11 (cryptoki).
This commit is contained in:
parent
34d7d546c6
commit
d685846c88
329
Cargo.lock
generated
329
Cargo.lock
generated
@ -1,164 +1,309 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
[[package]]
|
||||
name = "arc-swap"
|
||||
version = "0.3.0"
|
||||
name = "autocfg"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d"
|
||||
|
||||
[[package]]
|
||||
name = "base64"
|
||||
version = "0.9.3"
|
||||
version = "0.12.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"byteorder 1.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"safemem 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
checksum = "3441f0f7b02788e948e47f457ca01f1d7e6d92c693bc132c22b087d3141c03ff"
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "1.0.4"
|
||||
version = "1.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
|
||||
|
||||
[[package]]
|
||||
name = "byteorder"
|
||||
version = "1.2.6"
|
||||
name = "cc"
|
||||
version = "1.0.58"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f9a06fb2e53271d7c279ec1efea6ab691c35a2ae67ec0d91d7acec0caf13b518"
|
||||
|
||||
[[package]]
|
||||
name = "cloudabi"
|
||||
version = "0.0.3"
|
||||
name = "cfg-if"
|
||||
version = "0.1.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
|
||||
|
||||
[[package]]
|
||||
name = "chrono"
|
||||
version = "0.4.13"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c74d84029116787153e02106bf53e66828452a4b325cc8652b788b5967c0a0b6"
|
||||
dependencies = [
|
||||
"bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num-integer",
|
||||
"num-traits",
|
||||
"time",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fuchsia-zircon"
|
||||
version = "0.3.3"
|
||||
name = "getrandom"
|
||||
version = "0.1.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7abc8dd8451921606d809ba32e95b6111925cd2906060d2dcc29c070220503eb"
|
||||
dependencies = [
|
||||
"bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"wasi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fuchsia-zircon-sys"
|
||||
version = "0.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "hex"
|
||||
version = "0.3.2"
|
||||
version = "0.4.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "644f9158b2f133fd50f5fb3242878846d9eb792e445c893805ff0e3824006e35"
|
||||
|
||||
[[package]]
|
||||
name = "itoa"
|
||||
version = "0.4.3"
|
||||
version = "0.4.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dc6f3ad7b9d11a0c00842ff8de1b60ee58661048eb8049ed33c73594f359d7e6"
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.43"
|
||||
version = "0.2.74"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a2f02823cf78b754822df5f7f268fb59822e7296276d3e069d8e8cb26a14bd10"
|
||||
|
||||
[[package]]
|
||||
name = "nix"
|
||||
version = "0.18.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "83450fe6a6142ddd95fb064b746083fc4ef1705fe81f64a64e1d4b39f54a1055"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"cc",
|
||||
"cfg-if",
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-bigint"
|
||||
version = "0.2.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "090c7f9998ee0ff65aa5b723e4009f7b217707f1fb5ea551329cc4d6231fb304"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"num-integer",
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-derive"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e0396233fb2d5b0ae3f05ff6aba9a09185f7f6e70f87fb01147d545f85364665"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-integer"
|
||||
version = "0.1.43"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8d59457e662d541ba17869cf51cf177c0b5f0cbf476c66bdc90bf1edac4f875b"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-traits"
|
||||
version = "0.2.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ac267bcc07f48ee5f8935ab0d24f316fb722d7a1292e2913f0cc196b29ffd611"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "once_cell"
|
||||
version = "1.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0b631f7e854af39a1739f401cf34a8a013dfe09eac4fa4dba91e9768bd28168d"
|
||||
|
||||
[[package]]
|
||||
name = "ppv-lite86"
|
||||
version = "0.2.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "237a5ed80e274dbc66f86bd59c1e25edc039660be53194b5fe0a482e0f2612ea"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.19"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "04f5f085b5d71e2188cb8271e5da0161ad52c3f227a661a3c135fdf28e258b12"
|
||||
dependencies = [
|
||||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand"
|
||||
version = "0.5.5"
|
||||
version = "0.7.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03"
|
||||
dependencies = [
|
||||
"cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rand_core 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"getrandom",
|
||||
"libc",
|
||||
"rand_chacha",
|
||||
"rand_core",
|
||||
"rand_hc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_chacha"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402"
|
||||
dependencies = [
|
||||
"ppv-lite86",
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_core"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "ryu"
|
||||
version = "0.2.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "safemem"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.77"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
version = "1.0.27"
|
||||
version = "0.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19"
|
||||
dependencies = [
|
||||
"itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ryu 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.77 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"getrandom",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "signal-hook"
|
||||
version = "0.1.5"
|
||||
name = "rand_hc"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c"
|
||||
dependencies = [
|
||||
"arc-swap 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ryu"
|
||||
version = "1.0.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e"
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.114"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5317f7588f0a5078ee60ef675ef96735a1442132dc645eb1d12c018620ed8cd3"
|
||||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
version = "1.0.57"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "164eacbdb13512ec2745fb09d51fd5b22b0d65ed294a1dcf7285a360c80a675c"
|
||||
dependencies = [
|
||||
"itoa",
|
||||
"ryu",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "simple_asn1"
|
||||
version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "692ca13de57ce0613a363c8c2f1de925adebc81b04c923ac60c5488bb44abe4b"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"num-bigint",
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.38"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e69abc24912995b3038597a7a593be5053eb0fb44f3cc5beec0deb421790c1f4"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tergent"
|
||||
version = "0.1.0"
|
||||
version = "1.0.0"
|
||||
dependencies = [
|
||||
"base64 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"byteorder 1.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_json 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"signal-hook 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"base64",
|
||||
"bitflags",
|
||||
"hex",
|
||||
"nix",
|
||||
"num-derive",
|
||||
"num-traits",
|
||||
"once_cell",
|
||||
"serde_json",
|
||||
"simple_asn1",
|
||||
"uuid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winapi"
|
||||
version = "0.3.5"
|
||||
name = "time"
|
||||
version = "0.1.43"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438"
|
||||
dependencies = [
|
||||
"winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-xid"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564"
|
||||
|
||||
[[package]]
|
||||
name = "uuid"
|
||||
version = "0.8.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9fde2f6a4bea1d6e007c4ad38c6839fa71cbb63b6dbf5b595aa38dc9b1093c11"
|
||||
dependencies = [
|
||||
"rand",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasi"
|
||||
version = "0.9.0+wasi-snapshot-preview1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519"
|
||||
|
||||
[[package]]
|
||||
name = "winapi"
|
||||
version = "0.3.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
|
||||
dependencies = [
|
||||
"winapi-i686-pc-windows-gnu",
|
||||
"winapi-x86_64-pc-windows-gnu",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winapi-i686-pc-windows-gnu"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
|
||||
|
||||
[[package]]
|
||||
name = "winapi-x86_64-pc-windows-gnu"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[metadata]
|
||||
"checksum arc-swap 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f753d9b7c861f9f426fdb10479e35ffef7eaa4359d7c3595610645459df8849a"
|
||||
"checksum base64 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)" = "489d6c0ed21b11d038c31b6ceccca973e65d73ba3bd8ecb9a2babf5546164643"
|
||||
"checksum bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12"
|
||||
"checksum byteorder 1.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "90492c5858dd7d2e78691cfb89f90d273a2800fc11d98f60786e5d87e2f83781"
|
||||
"checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f"
|
||||
"checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82"
|
||||
"checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7"
|
||||
"checksum hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "805026a5d0141ffc30abb3be3173848ad46a1b1664fe632428479619a3644d77"
|
||||
"checksum itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1306f3464951f30e30d12373d31c79fbd52d236e5e896fd92f96ec7babbbe60b"
|
||||
"checksum libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)" = "76e3a3ef172f1a0b9a9ff0dd1491ae5e6c948b94479a3021819ba7d860c8645d"
|
||||
"checksum rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)" = "e464cd887e869cddcae8792a4ee31d23c7edd516700695608f5b98c67ee0131c"
|
||||
"checksum rand_core 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "edecf0f94da5551fc9b492093e30b041a891657db7940ee221f9d2f66e82eef2"
|
||||
"checksum ryu 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "7153dd96dade874ab973e098cb62fcdbb89a03682e46b144fd09550998d4a4a7"
|
||||
"checksum safemem 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8dca453248a96cb0749e36ccdfe2b0b4e54a61bfef89fb97ec621eb8e0a93dd9"
|
||||
"checksum serde 1.0.77 (registry+https://github.com/rust-lang/crates.io-index)" = "c6e67977d7523ce4d9284ed58918af99392de8edb6192c44afefcf634654ab7f"
|
||||
"checksum serde_json 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)" = "59790990c5115d16027f00913e2e66de23a51f70422e549d2ad68c8c5f268f1c"
|
||||
"checksum signal-hook 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "f7ca1f1c0ed6c8beaab713ad902c041e4f09d06e1b4bb74c5fc553c078ed0110"
|
||||
"checksum winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "773ef9dcc5f24b7d850d0ff101e542ff24c3b090a9768e03ff889fdef41f00fd"
|
||||
"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
|
||||
"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||
|
24
Cargo.toml
24
Cargo.toml
@ -1,12 +1,22 @@
|
||||
[package]
|
||||
name = "tergent"
|
||||
version = "0.1.1"
|
||||
version = "1.0.0"
|
||||
authors = ["Kaan Karaagacli <kaankaraagacli@gmail.com>"]
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[dependencies]
|
||||
serde_json = "1.0"
|
||||
hex = "0.3.2"
|
||||
rand = "0.5.5"
|
||||
byteorder = "1"
|
||||
base64 = "0.9.3"
|
||||
signal-hook = "0.1.5"
|
||||
base64 = "0.12.3"
|
||||
bitflags = "1.2.1"
|
||||
hex = "0.4.2"
|
||||
nix = "0.18.0"
|
||||
num-derive = "0.3.1"
|
||||
num-traits = "0.2.12"
|
||||
once_cell = "1.4.0"
|
||||
serde_json = "1.0.57"
|
||||
simple_asn1 = "0.4.1"
|
||||
uuid = { version = "0.8.1", features = ["v4"] }
|
||||
|
810
LICENSE
810
LICENSE
@ -1,202 +1,674 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
Preamble
|
||||
|
||||
1. Definitions.
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is 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. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
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.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
0. Definitions.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
"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.
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
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.
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
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.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
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.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
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.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
1. Source Code.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
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.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
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.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
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.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
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.
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
2. Basic Permissions.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
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.
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
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.
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
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. Use with the GNU Affero General Public License.
|
||||
|
||||
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 Affero 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 special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU 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 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 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 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 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
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 GPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
||||
|
69
README.md
69
README.md
@ -1,13 +1,15 @@
|
||||
tergent - termux ssh agent
|
||||
--------------------------
|
||||
tergent - a cryptoki library for termux keystore
|
||||
------------------------------------------------
|
||||
|
||||
An [ssh-agent implementation](https://tools.ietf.org/id/draft-miller-ssh-agent-02.html) for [Termux](https://termux.com/) that uses [Android Keystore](https://developer.android.com/training/articles/keystore) as its backend.
|
||||
A [cryptoki/PKCS#11 library](http://docs.oasis-open.org/pkcs11/pkcs11-base/v2.40/os/pkcs11-base-v2.40-os.html) for [Termux](https://termux.com/) that uses [Android Keystore](https://developer.android.com/training/articles/keystore) as its backend.
|
||||
|
||||
This application enables the use of keys securely stored in termux-api with ssh-agent protocol capable clients. These clients include the applications provided by openssh, such as `ssh`, `scp`, `ssh-add` and `ssh-copy-id`.
|
||||
This library enables the use of keys securely stored in termux-api with PKCS#11 protocol capable applications. These include the applications provided by openssh, such as `ssh` and `scp`.
|
||||
|
||||
Tergent does not (and cannot) access your private keys as they are stored inside the secure hardware. In fact, they can never leave the chip even with root privileges, thanks to [extraction preventation](https://developer.android.com/training/articles/keystore#ExtractionPrevention).
|
||||
Cryptographic actions are performed by the hardware itself.
|
||||
|
||||
This library is aimed to be compliant with PKCS#11 version 2.40. For now it implements all the APIs required for `ssh` and the related applications to function. If you encounter any issues trying to use tergent with any other PKCS#11 capable application, please open a bug report.
|
||||
|
||||
Compiling
|
||||
---------
|
||||
Install [Rust](https://www.rust-lang.org/en-US/install.html) and [Android NDK](https://developer.android.com/ndk/).
|
||||
@ -17,37 +19,60 @@ Then this project can be compiled with the command `cargo build --target=aarch64
|
||||
|
||||
Alternatively, you can download a precompiled deb package from the releases page.
|
||||
|
||||
Upgrading from 0.1
|
||||
------------------
|
||||
Keys generated for tergent 0.1 will not work for the latest version. If you do not want to lose access to your server, generate new keys using step 2 below and copy it to your server before upgrading.
|
||||
If you have already upgraded, you can download a copy of an older version from the releases page.
|
||||
After upgrading, any modifications made in `.bash_profile` or similar files should be removed. There is no need to keep running a background process anymore.
|
||||
|
||||
Usage
|
||||
-----
|
||||
1. Make sure you have the latest version of [Termux:API](https://play.google.com/store/apps/details?id=com.termux.api) installed. Don't forget to install the scripts using the command `pkg install termux-api`.
|
||||
|
||||
2. Generate a key using the command `termux-keystore generate myAlias`, where myAlias is the name you want to give to the key.
|
||||
- This command creates an RSA key - to create an ECDSA key, use the argument "-a EC": `termux-keystore generate myAlias -a EC`.
|
||||
- To specify a key size, use the argument "-s", e.g. `termux-keystore generate myAlias -s 4096` or `termux-keystore generate myAlias -a EC -s 521`.
|
||||
2. As of now `termux-keystore` cannot generate keys compatible with tergent. Use one of these commands instead:
|
||||
- To generate an RSA key:
|
||||
```
|
||||
/data/data/com.termux/files/usr/libexec/termux-api Keystore -e command generate -e alias ALIAS -e algorithm ALGORITHM --ei purposes 12 --esa digests NONE,SHA-1,SHA-256,SHA-384,SHA-512 --ei size SIZE --ei validity VALIDITY
|
||||
```
|
||||
- To generate an EC key:
|
||||
```
|
||||
/data/data/com.termux/files/usr/libexec/termux-api Keystore -e command generate -e alias ALIAS -e algorithm EC --ei purposes 12 --esa digests NONE,SHA-1,SHA-256,SHA-384,SHA-512 -e curve CURVE --ei validity VALIDITY
|
||||
```
|
||||
- ALIAS is the name you want to give to the key.
|
||||
- SIZE can be 2048, 3072 or 4096, this is only used for RSA keys.
|
||||
- CURVE can be secp256r1, secp384r1 or secp521r1, this determines the EC key size.
|
||||
- VALIDITY can be used for user validity, see Auto-locking below. Use 0 to disable.
|
||||
|
||||
3. Verify the key is generated by running the command `termux-keystore list`.
|
||||
3. List the keys to verify using the standard ssh tool: `ssh-keygen -D $PREFIX/lib/libtergent.so`. Even though the command is called `ssh-keygen`, `-D` switch lists cryptoki keys instead of generating new keys.
|
||||
|
||||
4. Run tergent with this command: `eval $(tergent)`.
|
||||
4. Copy the public key to your server.
|
||||
1. First export the public keys using: `ssh-keygen -D $PREFIX/lib/libtergent.so > keys.pub`.
|
||||
2. Optionally, remove any keys from the generated file using a text editor if needed: `nano keys.pub`.
|
||||
3. Copy the keys to your server using `ssh-copy-id -f -i keys.pub example.com`.
|
||||
|
||||
5. Again list the keys to verify, but now using the standard ssh tool: `ssh-add -l`.
|
||||
5. Connect to your server using the command `ssh -I $PREFIX/lib/libtergent.so example.com`.
|
||||
|
||||
6. Copy the public key to your server. For this, you have two options:
|
||||
- ssh-copy-id is the standard tool for this - invoke it by running `ssh-copy-id example.com`.
|
||||
- You can also use `ssh-add -L` (notice the uppercase L), and manually copy and append the output to the `.ssh/authorized_keys` file on your server.
|
||||
|
||||
7. Connect to your server using the usual command `ssh example.com`.
|
||||
|
||||
You will need to run the command `eval $(tergent)` every time you start up the terminal. This command can be included in .bash_profile (or a similar script) for convenience.
|
||||
To make `ssh` remember the library path, modify your `~/.ssh/config` file. For a single host:
|
||||
```
|
||||
Host example.com
|
||||
PKCS11Provider /data/data/com.termux/files/usr/lib/libtergent.so
|
||||
```
|
||||
Or alternatively you can make tergent apply to all connections:
|
||||
```
|
||||
Host *
|
||||
PKCS11Provider /data/data/com.termux/files/usr/lib/libtergent.so
|
||||
```
|
||||
After saving this file you can just run `ssh example.com` to connect.
|
||||
|
||||
How do I...
|
||||
-----------
|
||||
* **list keys**: run either `ssh-add -l` or `termux-keystore list`
|
||||
* **create a new key**: use `termux-keystore generate`
|
||||
* **use a key**: just run `ssh`
|
||||
* **list keys**: run either `ssh-keygen -D $PREFIX/lib/libtergent.so` or `termux-keystore list`
|
||||
* **create a new key**: see step 2 from instructions above
|
||||
* **use a key**: run `ssh -I $PREFIX/lib/libtergent.so`
|
||||
* **delete a key**: use `termux-keystore delete`
|
||||
* **import a key**: not supported, generate a new key instead
|
||||
|
||||
Auto-locking
|
||||
------------
|
||||
tergent does not yet support locking the agent with a password.
|
||||
However, Android [provides a mechanism](https://developer.android.com/training/articles/keystore#UserAuthentication) to automatically lock the keys after a specified time has passed since the last device unlock. To take advantage of this feature, use the "-u" flag while generating the keys, e.g. `termux-keystore generate myAlias -u 10` for a 10-second lock. In this case, the keys are usable only for 10 seconds after the phone is unlocked. To unlock the keys after this time has passed, simply re-lock and unlock your device again.
|
||||
tergent does not provide password protected sessions yet.
|
||||
However, Android [provides a mechanism](https://developer.android.com/training/articles/keystore#UserAuthentication) to automatically lock the keys after a specified time has passed since the last device unlock. To take advantage of this feature, use the flag while generating the keys, e.g. `--ei validity 10` for a 10-second lock. In this case, the keys are usable only for 10 seconds after the phone is unlocked. To unlock the keys after this time has passed, simply re-lock and unlock your device again.
|
||||
|
@ -1,38 +0,0 @@
|
||||
use base64;
|
||||
|
||||
use std::io::Write;
|
||||
use std::process::{Command, Stdio};
|
||||
|
||||
/// Location of the `termux-api` application.
|
||||
const PROGRAM: &str = "/data/data/com.termux/files/usr/libexec/termux-api";
|
||||
|
||||
/// Send a request to `termux-api` to list all the keys.
|
||||
pub fn list_keys() -> String {
|
||||
let output = Command::new(PROGRAM)
|
||||
.args(&["Keystore", "-e", "command", "list"])
|
||||
.args(&["--ez", "detailed", "true"])
|
||||
.output()
|
||||
.expect("Could not execute the termux-api program.");
|
||||
|
||||
String::from_utf8(output.stdout)
|
||||
.expect("Malformed response received from termux-api.")
|
||||
}
|
||||
|
||||
/// Send some data to `termux-api` to be signed.
|
||||
/// Algorithm parameter must be in the format that keystore expects
|
||||
/// (e.g. "SHA512withRSA").
|
||||
pub fn sign(alias: &str, algorithm: &str, data: &[u8]) -> Vec<u8> {
|
||||
let mut child = Command::new(PROGRAM)
|
||||
.args(&["Keystore", "-e", "command", "sign"])
|
||||
.args(&["-e", "alias", alias, "-e", "algorithm", algorithm])
|
||||
.stdin(Stdio::piped())
|
||||
.stdout(Stdio::piped())
|
||||
.spawn()
|
||||
.expect("Could not execute the termux-api program.");
|
||||
|
||||
child.stdin.as_mut().and_then(|i| i.write_all(data).ok())
|
||||
.expect("Could not send the data to termux-api.");
|
||||
|
||||
child.wait_with_output().ok().and_then(|o| base64::decode(&o.stdout).ok())
|
||||
.expect("Could not read the signature response from termux-api.")
|
||||
}
|
70
src/bridge/mod.rs
Normal file
70
src/bridge/mod.rs
Normal file
@ -0,0 +1,70 @@
|
||||
//! Provides the bridge to the termux-api. All communication with the
|
||||
//! termux-api must go through this module.
|
||||
|
||||
mod socket;
|
||||
|
||||
use std::error::Error;
|
||||
use std::io::{Read, Write};
|
||||
use std::process::{Command, Stdio};
|
||||
|
||||
use base64;
|
||||
|
||||
/// Send a request to `termux-api` to list all the keys.
|
||||
/// Returns a string that contains a JSON object.
|
||||
pub fn list_keys() -> Result<String, Box<dyn Error>> {
|
||||
Ok(communicate(&["list", "--ez", "detailed", "true"], &[0; 0])?)
|
||||
}
|
||||
|
||||
/// Send some data to `termux-api` to be signed.
|
||||
/// Algorithm parameter must be in the format that keystore expects
|
||||
/// (e.g. "SHA512withRSA"). See the full list at the
|
||||
/// Java documentation for [Signature algorithms].
|
||||
/// Returns the signature of the data provided.
|
||||
///
|
||||
/// [Signature algorithms]:
|
||||
/// https://docs.oracle.com/javase/8/docs/technotes/guides/security/StandardNames.html#Signature
|
||||
pub fn sign(alias: &str, algorithm: &str, data: &[u8]) -> Result<Vec<u8>, Box<dyn Error>> {
|
||||
let args = ["sign", "-e", "alias", alias, "-e", "algorithm", algorithm];
|
||||
let output = communicate(&args, data)?;
|
||||
return Ok(base64::decode(output)?);
|
||||
}
|
||||
|
||||
/// Performs a generic call to `termux-api`, providing `args` to its receiver.
|
||||
/// Sets up proper sockets so that the `input` is provided to `termux-api` and
|
||||
/// its output is returned from this function.
|
||||
fn communicate(args: &[&str], input: &[u8]) -> Result<String, Box<dyn Error>> {
|
||||
let mut input_socket = socket::Socket::new()?;
|
||||
let mut output_socket = socket::Socket::new()?;
|
||||
|
||||
// This executable does not use stdin/stdout itself.
|
||||
let mut command = Command::new("/data/data/com.termux/files/usr/bin/am")
|
||||
.arg("broadcast")
|
||||
.args(&["--user", "0"])
|
||||
.args(&["-n", "com.termux.api/.TermuxApiReceiver"])
|
||||
.args(&["--es", "socket_input", &output_socket.address()])
|
||||
.args(&["--es", "socket_output", &input_socket.address()])
|
||||
.args(&["--es", "api_method", "Keystore", "-e", "command"])
|
||||
.args(args)
|
||||
.stdin(Stdio::null())
|
||||
.stdout(Stdio::null())
|
||||
.stderr(Stdio::null())
|
||||
.spawn()?;
|
||||
|
||||
input_socket.accept()?;
|
||||
|
||||
// Do not accept on the output socket if there is nothing to send.
|
||||
// This is important as it will hang if termux-api is not expecting to receive any input.
|
||||
if input.len() > 0 {
|
||||
output_socket.accept()?;
|
||||
output_socket.write(input)?;
|
||||
output_socket.close()?;
|
||||
}
|
||||
|
||||
let mut output = String::new();
|
||||
input_socket.read_to_string(&mut output)?;
|
||||
input_socket.close()?;
|
||||
|
||||
// We need to reap our children otherwise they will stay as zombies.
|
||||
command.wait()?;
|
||||
Ok(output)
|
||||
}
|
100
src/bridge/socket.rs
Normal file
100
src/bridge/socket.rs
Normal file
@ -0,0 +1,100 @@
|
||||
//! Provides a struct which can be used to create and use Unix abstract sockets.
|
||||
|
||||
use std::error::Error;
|
||||
use std::io::{self, ErrorKind, Read, Write};
|
||||
|
||||
use nix::sys::socket::{self, AddressFamily, SockAddr, SockFlag, SockType, UnixAddr};
|
||||
use nix::unistd;
|
||||
|
||||
use uuid::adapter::Hyphenated;
|
||||
use uuid::Uuid;
|
||||
|
||||
/// Represents an abstract Unix socket.
|
||||
pub struct Socket {
|
||||
address: SockAddr,
|
||||
server_socket: i32,
|
||||
client_socket: Option<i32>,
|
||||
}
|
||||
|
||||
impl Socket {
|
||||
/// Creates a new abstract Unix socket with a randomly generated address,
|
||||
/// binds to it and starts listening on this address.
|
||||
pub fn new() -> Result<Self, Box<dyn Error>> {
|
||||
let mut buf = [0u8; Hyphenated::LENGTH];
|
||||
Uuid::new_v4().to_hyphenated().encode_lower(&mut buf);
|
||||
let address = UnixAddr::new_abstract(&buf)?;
|
||||
let address = SockAddr::Unix(address);
|
||||
let server_socket = socket::socket(
|
||||
AddressFamily::Unix,
|
||||
SockType::Stream,
|
||||
SockFlag::SOCK_CLOEXEC,
|
||||
None,
|
||||
)?;
|
||||
socket::bind(server_socket, &address)?;
|
||||
socket::listen(server_socket, 1)?;
|
||||
Ok(Socket {
|
||||
address,
|
||||
server_socket,
|
||||
client_socket: None,
|
||||
})
|
||||
}
|
||||
|
||||
/// Accept a connection through this socket. This will block until
|
||||
/// the other side of the socket connects to this socket, if not
|
||||
/// connected already.
|
||||
pub fn accept(&mut self) -> Result<(), Box<dyn Error>> {
|
||||
let client_socket = socket::accept(self.server_socket)?;
|
||||
self.client_socket = Some(client_socket);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Closes this socket. It will be possible to accept another
|
||||
/// connection after this.
|
||||
pub fn close(&mut self) -> Result<(), Box<dyn Error>> {
|
||||
unistd::close(self.client_socket()?)?;
|
||||
self.client_socket = None;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Returns the address of this socket. It will not have a leading
|
||||
/// null byte nor an "@" symbol.
|
||||
pub fn address(&self) -> String {
|
||||
let mut address = self.address.to_str();
|
||||
address.remove(0);
|
||||
address
|
||||
}
|
||||
|
||||
/// Returns the client socket associated with this socket.
|
||||
/// Returns `None` if the socket has not accepted a connection yet.
|
||||
fn client_socket(&self) -> io::Result<i32> {
|
||||
Ok(self.client_socket.ok_or(io::Error::new(
|
||||
ErrorKind::NotConnected,
|
||||
self.address.to_str(),
|
||||
))?)
|
||||
}
|
||||
}
|
||||
|
||||
impl Read for Socket {
|
||||
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
|
||||
unistd::read(self.client_socket()?, buf).map_err(to_io_err)
|
||||
}
|
||||
}
|
||||
|
||||
impl Write for Socket {
|
||||
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
|
||||
unistd::write(self.client_socket()?, buf).map_err(to_io_err)
|
||||
}
|
||||
|
||||
fn flush(&mut self) -> io::Result<()> {
|
||||
// It is not possible to implement this with Unix abstract sockets.
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
/// Converts a [`nix::Error`] to [`io::Error`].
|
||||
///
|
||||
/// [`nix::Error`]: https://docs.rs/nix/0.18.0/nix/enum.Error.html
|
||||
/// [`io::Error`]: https://doc.rust-lang.org/std/io/struct.Error.html
|
||||
fn to_io_err(err: nix::Error) -> io::Error {
|
||||
io::Error::new(ErrorKind::Other, err)
|
||||
}
|
48
src/key.rs
48
src/key.rs
@ -1,48 +0,0 @@
|
||||
/// A key instance, representing a key stored inside the keystore.
|
||||
pub struct Key {
|
||||
pub algorithm: Algorithm,
|
||||
pub alias: String,
|
||||
}
|
||||
|
||||
pub enum Algorithm {
|
||||
Rsa, Ec(Curve),
|
||||
}
|
||||
|
||||
/// Available elliptic curves, each representing a NIST P curve.
|
||||
pub enum Curve {
|
||||
P256, P384, P521,
|
||||
}
|
||||
|
||||
impl Algorithm {
|
||||
/// Tries to find the corrensponding algorithm given the fields
|
||||
/// acquired from `termux-api`. Returns an empty response if
|
||||
/// either the algorithm is unknown or the key size is incompatible
|
||||
/// with the algorithm.
|
||||
pub fn parse(algorithm: &str, size: u64) -> Option<Algorithm> {
|
||||
match algorithm {
|
||||
// In SSH, RSA only has one key type that represents all sizes.
|
||||
"RSA" => Some(Algorithm::Rsa),
|
||||
"EC" => {
|
||||
let curve = match size {
|
||||
256 => Curve::P256,
|
||||
384 => Curve::P384,
|
||||
521 => Curve::P521,
|
||||
_ => return None, // unknown curve
|
||||
};
|
||||
Some(Algorithm::Ec(curve))
|
||||
},
|
||||
_ => None, // unknown algorithm
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Curve {
|
||||
/// Returns the full curve name, e.g. "nistp256".
|
||||
pub fn name(&self) -> &'static str {
|
||||
match self {
|
||||
Curve::P256 => "nistp256",
|
||||
Curve::P384 => "nistp384",
|
||||
Curve::P521 => "nistp521",
|
||||
}
|
||||
}
|
||||
}
|
97
src/key/asn1.rs
Normal file
97
src/key/asn1.rs
Normal file
@ -0,0 +1,97 @@
|
||||
//! Implementations for parsing and creating ASN.1 encoded documents.
|
||||
//! All ASN.1 related functions must reside in this module.
|
||||
|
||||
use std::iter;
|
||||
|
||||
use simple_asn1::*;
|
||||
|
||||
use super::{EcCurve, EcKey};
|
||||
|
||||
/// For elliptic curves, 2 and 3 means compressed and 4 means uncompressed.
|
||||
/// We only support the uncompressed point representation.
|
||||
const EC_UNCOMPRESSED_POINT: u8 = 4;
|
||||
|
||||
impl EcCurve {
|
||||
/// Returns the required parameter length for this curve. All values
|
||||
/// (x, y, r and s) must be prepended with zeroes so that they have this length.
|
||||
fn param_length(&self) -> usize {
|
||||
match &self {
|
||||
EcCurve::P256 => 32,
|
||||
EcCurve::P384 => 48,
|
||||
EcCurve::P521 => 66,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl EcKey {
|
||||
/// Returns the point values (x and y), which is the public key of this EC key.
|
||||
/// The output is formatted in ASN.1.
|
||||
pub fn point_as_asn1(&self) -> Result<Vec<u8>, ASN1EncodeErr> {
|
||||
let x_prepend = &self.curve.param_length() - self.x.len();
|
||||
let y_prepend = &self.curve.param_length() - self.y.len();
|
||||
|
||||
let point = iter::once(EC_UNCOMPRESSED_POINT)
|
||||
.chain(iter::repeat(0).take(x_prepend))
|
||||
.chain(self.x.iter().copied())
|
||||
.chain(iter::repeat(0).take(y_prepend))
|
||||
.chain(self.y.iter().copied())
|
||||
.collect();
|
||||
|
||||
let asn = ASN1Block::OctetString(0, point);
|
||||
to_der(&asn)
|
||||
}
|
||||
|
||||
/// Returns the params of this EC key, which represents the curve used in this key.
|
||||
/// The output is formatted in ASN.1.
|
||||
pub fn params_as_asn1(&self) -> Result<Vec<u8>, ASN1EncodeErr> {
|
||||
let oid = match self.curve {
|
||||
EcCurve::P256 => oid!(1, 2, 840, 10045, 3, 1, 7),
|
||||
EcCurve::P384 => oid!(1, 3, 132, 0, 34),
|
||||
EcCurve::P521 => oid!(1, 3, 132, 0, 35),
|
||||
};
|
||||
let asn = ASN1Block::ObjectIdentifier(0, oid);
|
||||
to_der(&asn)
|
||||
}
|
||||
|
||||
/// Parses a signature value formatted in ASN.1, and returns a vector that contains
|
||||
/// the signature values (r and s), with proper padding so that it has the expected
|
||||
/// total length (2*`param_length()`).
|
||||
pub fn signature_from_asn1(&self, signature: &[u8]) -> Option<Vec<u8>> {
|
||||
let asn = from_der(signature).ok()?;
|
||||
// First item in the signature will contain two values.
|
||||
let first = asn.into_iter().next()?;
|
||||
let block = match first {
|
||||
ASN1Block::Sequence(_, block) => block,
|
||||
_ => {
|
||||
return None;
|
||||
}
|
||||
};
|
||||
// First one is the r value.
|
||||
let r = match &block[0] {
|
||||
ASN1Block::Integer(_, one) => one,
|
||||
_ => {
|
||||
return None;
|
||||
}
|
||||
};
|
||||
// Second one is the s value.
|
||||
let s = match &block[1] {
|
||||
ASN1Block::Integer(_, two) => two,
|
||||
_ => {
|
||||
return None;
|
||||
}
|
||||
};
|
||||
let r = r.to_bytes_be().1;
|
||||
let s = s.to_bytes_be().1;
|
||||
// Prepend to the required length.
|
||||
let r_prepend = &self.curve.param_length() - r.len();
|
||||
let s_prepend = &self.curve.param_length() - s.len();
|
||||
Some(
|
||||
iter::repeat(0)
|
||||
.take(r_prepend)
|
||||
.chain(r)
|
||||
.chain(iter::repeat(0).take(s_prepend))
|
||||
.chain(s)
|
||||
.collect(),
|
||||
)
|
||||
}
|
||||
}
|
75
src/key/json.rs
Normal file
75
src/key/json.rs
Normal file
@ -0,0 +1,75 @@
|
||||
//! Functions related to parsing JSON output, which is vended
|
||||
//! by termux keystore. JSON related code must be contained in this module.
|
||||
|
||||
use hex;
|
||||
use serde_json;
|
||||
|
||||
use super::{EcCurve, EcKey, Key, RsaKey};
|
||||
|
||||
/// Convents a JSON string to key vector. Returns `None` if the overall
|
||||
/// structure is invalid. Skips over the keys that are unparseable.
|
||||
pub fn to_list(json: String) -> Option<Vec<Key>> {
|
||||
let keys = serde_json::from_str::<serde_json::Value>(&json).ok()?;
|
||||
let keys = keys.as_array()?;
|
||||
|
||||
Some(keys.iter().filter_map(parse_key).collect())
|
||||
}
|
||||
|
||||
/// Parse a single JSON object containing information about a key.
|
||||
fn parse_key(object: &serde_json::Value) -> Option<Key> {
|
||||
let alias = object.get("alias")?.as_str()?;
|
||||
let algorithm = object.get("algorithm")?.as_str()?;
|
||||
let size = object.get("size")?.as_u64()?;
|
||||
|
||||
match algorithm {
|
||||
"RSA" => {
|
||||
let modulus = object.get("modulus")?.as_hex()?;
|
||||
let exponent = object.get("exponent")?.as_hex()?;
|
||||
let key = RsaKey {
|
||||
label: String::from(alias),
|
||||
modulus,
|
||||
exponent,
|
||||
};
|
||||
Some(Key::Rsa(key))
|
||||
}
|
||||
"EC" => {
|
||||
let x = object.get("x")?.as_hex()?;
|
||||
let y = object.get("y")?.as_hex()?;
|
||||
let curve = match size {
|
||||
256 => EcCurve::P256,
|
||||
384 => EcCurve::P384,
|
||||
521 => EcCurve::P521,
|
||||
_ => {
|
||||
return None;
|
||||
}
|
||||
};
|
||||
let key = EcKey {
|
||||
label: String::from(alias),
|
||||
curve,
|
||||
x,
|
||||
y,
|
||||
};
|
||||
Some(Key::Ec(key))
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
trait HexValue {
|
||||
fn as_hex(&self) -> Option<Vec<u8>>;
|
||||
}
|
||||
|
||||
/// Extend the JSON value struct to support parsing base16 integers.
|
||||
impl HexValue for serde_json::Value {
|
||||
fn as_hex(&self) -> Option<Vec<u8>> {
|
||||
let value = self.as_str()?;
|
||||
|
||||
if value.len() % 2 == 1 {
|
||||
// hex module will fail if the number of letters is odd
|
||||
// prepend a zero to get the result without failing
|
||||
hex::decode(format!("0{}", value)).ok()
|
||||
} else {
|
||||
hex::decode(value).ok()
|
||||
}
|
||||
}
|
||||
}
|
76
src/key/mod.rs
Normal file
76
src/key/mod.rs
Normal file
@ -0,0 +1,76 @@
|
||||
//! Module to represent a single public key. Also provides functionality
|
||||
//! build the key objects from JSON and to sign using these keys.
|
||||
|
||||
mod asn1;
|
||||
mod json;
|
||||
|
||||
pub use json::to_list as json_to_list;
|
||||
|
||||
/// A public key instance.
|
||||
pub enum Key {
|
||||
Rsa(RsaKey),
|
||||
Ec(EcKey),
|
||||
}
|
||||
|
||||
/// A public RSA key instance.
|
||||
pub struct RsaKey {
|
||||
label: String,
|
||||
modulus: Vec<u8>,
|
||||
exponent: Vec<u8>,
|
||||
}
|
||||
|
||||
/// A public EC key instance.
|
||||
pub struct EcKey {
|
||||
label: String,
|
||||
curve: EcCurve,
|
||||
x: Vec<u8>,
|
||||
y: Vec<u8>,
|
||||
}
|
||||
|
||||
/// An EC key must use one of these curves.
|
||||
pub enum EcCurve {
|
||||
P256,
|
||||
P384,
|
||||
P521,
|
||||
}
|
||||
|
||||
impl Key {
|
||||
/// Returns the human-readable label of this key.
|
||||
pub fn label(&self) -> &str {
|
||||
match self {
|
||||
Key::Rsa(key) => &key.label,
|
||||
Key::Ec(key) => &key.label,
|
||||
}
|
||||
}
|
||||
|
||||
/// Signs data using this key.
|
||||
pub fn sign(&self, data: &[u8]) -> Option<Vec<u8>> {
|
||||
match self {
|
||||
Key::Rsa(key) => key.sign(data),
|
||||
Key::Ec(key) => key.sign(data),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl RsaKey {
|
||||
/// Returns the modulus of this key. Its size will be equal to the key length.
|
||||
pub fn modulus(&self) -> &[u8] {
|
||||
&self.modulus
|
||||
}
|
||||
|
||||
/// Returns the exponent of this key, usually 65537.
|
||||
pub fn exponent(&self) -> &[u8] {
|
||||
&self.exponent
|
||||
}
|
||||
|
||||
pub fn sign(&self, data: &[u8]) -> Option<Vec<u8>> {
|
||||
super::bridge::sign(&self.label, "NONEwithRSA", data).ok()
|
||||
}
|
||||
}
|
||||
|
||||
impl EcKey {
|
||||
pub fn sign(&self, data: &[u8]) -> Option<Vec<u8>> {
|
||||
let sign = super::bridge::sign(&self.label, "NONEwithECDSA", data).ok()?;
|
||||
self.signature_from_asn1(&sign)
|
||||
}
|
||||
}
|
1048
src/lib.rs
Normal file
1048
src/lib.rs
Normal file
File diff suppressed because it is too large
Load Diff
35
src/list.rs
35
src/list.rs
@ -1,35 +0,0 @@
|
||||
use std::io::{Write, Result};
|
||||
use byteorder::{BE, WriteBytesExt};
|
||||
|
||||
use super::KeyStore;
|
||||
|
||||
// defined in the specification document
|
||||
const SSH_AGENT_IDENTITIES_ANSWER: u8 = 12;
|
||||
|
||||
/// Prints the information about all the keys stored in the keystore
|
||||
/// to the given stream, in the format expected by a ssh-agent client.
|
||||
pub fn write_list_response(store: &KeyStore, stream: &mut Write) -> Result<()> {
|
||||
// total length of the keys
|
||||
let length: u32 = store.iter().map(|(blob, key)| {
|
||||
// blob already includes its header
|
||||
// need 4 for alias header
|
||||
(blob.len() as u32) + 4 + (key.alias.len() as u32)
|
||||
}).sum();
|
||||
|
||||
// total packet size: +1 for message type and +4 for number of keys
|
||||
stream.write_u32::<BE>(length + 5)?;
|
||||
// message type
|
||||
stream.write_u8(SSH_AGENT_IDENTITIES_ANSWER)?;
|
||||
// number of keys
|
||||
stream.write_u32::<BE>(store.len() as u32)?;
|
||||
|
||||
for (blob, key) in store {
|
||||
// blob (includes size inside)
|
||||
stream.write_all(blob)?;
|
||||
// alias
|
||||
stream.write_u32::<BE>(key.alias.len() as u32)?;
|
||||
stream.write_all(key.alias.as_bytes())?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
129
src/main.rs
129
src/main.rs
@ -1,129 +0,0 @@
|
||||
extern crate base64;
|
||||
extern crate byteorder;
|
||||
extern crate hex;
|
||||
extern crate rand;
|
||||
extern crate serde_json;
|
||||
extern crate signal_hook;
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::io::{Read, Write, Result};
|
||||
use std::os::unix::net::{UnixStream, UnixListener};
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::thread;
|
||||
use byteorder::{BE, ReadBytesExt, WriteBytesExt};
|
||||
|
||||
mod bridge;
|
||||
mod key;
|
||||
mod list;
|
||||
mod sign;
|
||||
mod startup;
|
||||
mod store;
|
||||
|
||||
// defined in the specification document
|
||||
const SSH_AGENTC_REQUEST_IDENTITIES: u8 = 11;
|
||||
const SSH_AGENTC_SIGN_REQUEST: u8 = 13;
|
||||
const SSH_AGENT_FAILURE: u8 = 5;
|
||||
|
||||
type KeyStore = HashMap<Vec<u8>, key::Key>;
|
||||
|
||||
fn main() {
|
||||
// check if "-h" is passed, print help and exit if so
|
||||
let help_requested = startup::print_help();
|
||||
if help_requested { return; }
|
||||
|
||||
let foreground_mode = startup::is_foreground();
|
||||
let socket = startup::get_socket();
|
||||
|
||||
let pid = if foreground_mode {
|
||||
// if we are running in the foreground mode, set up the
|
||||
// socket, and use our own PID
|
||||
startup::initialize_socket(&socket);
|
||||
startup::get_pid()
|
||||
} else {
|
||||
// if not, spawn a child that runs in foreground mode,
|
||||
// and use its PID
|
||||
startup::spawn_child(&socket)
|
||||
.expect("Could not execute a child process.")
|
||||
};
|
||||
|
||||
// print the greetings: the socket and PID information
|
||||
println!("{}", startup::create_shell_commands(&socket, pid));
|
||||
// child will take over if we are not in foreground mode
|
||||
if !foreground_mode { return; }
|
||||
|
||||
// keystore cache that will be used throughout the application
|
||||
let store = Arc::new(Mutex::new(KeyStore::new()));
|
||||
|
||||
let listener = UnixListener::bind(socket).expect("Could not create the socket.");
|
||||
|
||||
for stream in listener.incoming() {
|
||||
if let Ok(mut stream) = stream {
|
||||
let store = Arc::clone(&store);
|
||||
thread::spawn(move || {
|
||||
loop {
|
||||
if let Err(_) = handle_stream(&store, &mut stream) {
|
||||
break;
|
||||
};
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_stream(store: &Arc<Mutex<KeyStore>>, stream: &mut UnixStream) -> Result<()> {
|
||||
let length = stream.read_u32::<BE>()?;
|
||||
let msg_type = stream.read_u8()?;
|
||||
match msg_type {
|
||||
SSH_AGENTC_REQUEST_IDENTITIES => {
|
||||
let mut store = store.lock().unwrap();
|
||||
|
||||
// grab the keys from termux-api
|
||||
let json = bridge::list_keys();
|
||||
|
||||
// parse the JSON to refresh the local cache
|
||||
store::load_all(&mut store, json);
|
||||
|
||||
// print the keys from the cache
|
||||
list::write_list_response(&store, stream)?;
|
||||
},
|
||||
SSH_AGENTC_SIGN_REQUEST => {
|
||||
let mut store = store.lock().unwrap();
|
||||
|
||||
// create a separate stream for reading
|
||||
let mut read = stream.try_clone().unwrap().take((length - 1).into());
|
||||
|
||||
// parse the request received from the client
|
||||
let request = match sign::read_request(&store, &mut read)? {
|
||||
Some(request) => request,
|
||||
_ => { return write_error(stream) },
|
||||
};
|
||||
|
||||
// transmit the request to termux-api
|
||||
let signature = bridge::sign(
|
||||
&request.key().alias, &request.keystore_name(), &request.data()
|
||||
);
|
||||
|
||||
if signature.len() == 0 {
|
||||
// termux-api returned empty response
|
||||
// it is probably locked due to user validity enforcement
|
||||
return write_error(stream);
|
||||
}
|
||||
|
||||
// print the signature response to the client
|
||||
sign::write_response(&request, &signature, stream)?;
|
||||
stream.flush()?;
|
||||
},
|
||||
_ => {
|
||||
// unsupported message type
|
||||
write_error(stream)?;
|
||||
},
|
||||
};
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn write_error(stream: &mut Write) -> Result<()> {
|
||||
stream.write_u32::<BE>(1)?;
|
||||
stream.write_u8(SSH_AGENT_FAILURE)?;
|
||||
stream.flush()?;
|
||||
Ok(())
|
||||
}
|
129
src/pkcs11/attribute_type.rs
Normal file
129
src/pkcs11/attribute_type.rs
Normal file
@ -0,0 +1,129 @@
|
||||
use std::convert::TryFrom;
|
||||
use std::os::raw::c_ulong;
|
||||
|
||||
use num_derive::{FromPrimitive, ToPrimitive};
|
||||
use num_traits::{FromPrimitive, ToPrimitive};
|
||||
|
||||
#[derive(Debug, FromPrimitive, ToPrimitive)]
|
||||
pub enum AttributeType {
|
||||
Class = 0x0000,
|
||||
Token = 0x0001,
|
||||
Private = 0x0002,
|
||||
Label = 0x0003,
|
||||
Application = 0x0010,
|
||||
Value = 0x0011,
|
||||
ObjectId = 0x0012,
|
||||
CertificateType = 0x0080,
|
||||
Issuer = 0x0081,
|
||||
SerialNumber = 0x0082,
|
||||
AcIssuer = 0x0083,
|
||||
Owner = 0x0084,
|
||||
AttrTypes = 0x0085,
|
||||
Trusted = 0x0086,
|
||||
CertificateCategory = 0x0087,
|
||||
JavaMidpSecurityDomain = 0x0088,
|
||||
Url = 0x0089,
|
||||
HashOfSubjectPublicKey = 0x008a,
|
||||
HashOfIssuerPublicKey = 0x008b,
|
||||
NameHashAlgorithm = 0x008c,
|
||||
CheckValue = 0x0090,
|
||||
KeyType = 0x0100,
|
||||
Subject = 0x0101,
|
||||
Id = 0x0102,
|
||||
Sensitive = 0x0103,
|
||||
Encrypt = 0x0104,
|
||||
Decrypt = 0x0105,
|
||||
Wrap = 0x0106,
|
||||
Unwrap = 0x0107,
|
||||
Sign = 0x0108,
|
||||
SignRecover = 0x0109,
|
||||
Verify = 0x010a,
|
||||
VerifyRecover = 0x010b,
|
||||
Derive = 0x010c,
|
||||
StartDate = 0x0110,
|
||||
EndDate = 0x0111,
|
||||
Modulus = 0x0120,
|
||||
ModulusBits = 0x0121,
|
||||
PublicExponent = 0x0122,
|
||||
PrivateExponent = 0x0123,
|
||||
Prime1 = 0x0124,
|
||||
Prime2 = 0x0125,
|
||||
Exponent1 = 0x0126,
|
||||
Exponent2 = 0x0127,
|
||||
Coefficient = 0x0128,
|
||||
PublicKeyInfo = 0x0129,
|
||||
Prime = 0x0130,
|
||||
Subprime = 0x0131,
|
||||
Base = 0x0132,
|
||||
PrimeBits = 0x0133,
|
||||
SubPrimeBits = 0x0134,
|
||||
ValueBits = 0x0160,
|
||||
ValueLen = 0x0161,
|
||||
Extractable = 0x0162,
|
||||
Local = 0x0163,
|
||||
NeverExtractable = 0x0164,
|
||||
AlwaysSensitive = 0x0165,
|
||||
KeyGenMechanism = 0x0166,
|
||||
Modifiable = 0x0170,
|
||||
Copyable = 0x0171,
|
||||
Destroyable = 0x0172,
|
||||
EcParams = 0x0180,
|
||||
EcPoint = 0x0181,
|
||||
SecondaryAuth = 0x0200,
|
||||
AuthPinFlags = 0x0201,
|
||||
AlwaysAuthenticate = 0x0202,
|
||||
WrapWithTrusted = 0x0210,
|
||||
WrapTemplate = 0x40000211,
|
||||
UnwrapTemplate = 0x40000212,
|
||||
DeriveTemplate = 0x40000213,
|
||||
OtpFormat = 0x0220,
|
||||
OtpLength = 0x0221,
|
||||
OtpTimeInterval = 0x0222,
|
||||
OtpUserFriendlyMode = 0x0223,
|
||||
OtpChallengeRequirement = 0x0224,
|
||||
OtpTimeRequirement = 0x0225,
|
||||
OtpCounterRequirement = 0x0226,
|
||||
OtpPinRequirement = 0x0227,
|
||||
OtpCounter = 0x022e,
|
||||
OtpTime = 0x022f,
|
||||
OtpUserIdentifier = 0x022a,
|
||||
OtpServiceIdentifier = 0x022b,
|
||||
OtpServiceLogo = 0x022c,
|
||||
OtpServiceLogoType = 0x022d,
|
||||
Gostr3410Params = 0x0250,
|
||||
Gostr3411Params = 0x0251,
|
||||
Gost28147Params = 0x0252,
|
||||
HwFeatureType = 0x0300,
|
||||
ResetOnInit = 0x0301,
|
||||
HasReset = 0x0302,
|
||||
PixelX = 0x0400,
|
||||
PixelY = 0x0401,
|
||||
Resolution = 0x0402,
|
||||
CharRows = 0x0403,
|
||||
CharColumns = 0x0404,
|
||||
Color = 0x0405,
|
||||
BitsPerPixel = 0x0406,
|
||||
CharSets = 0x0480,
|
||||
EncodingMethods = 0x0481,
|
||||
MimeTypes = 0x0482,
|
||||
MechanismType = 0x0500,
|
||||
RequiredCmsAttributes = 0x0501,
|
||||
DefaultCmsAttributes = 0x0502,
|
||||
SupportedCmsAttributes = 0x0503,
|
||||
AllowedMechanisms = 0x40000600,
|
||||
VendorDefined = 0x80000000,
|
||||
}
|
||||
|
||||
impl TryFrom<c_ulong> for AttributeType {
|
||||
type Error = ();
|
||||
fn try_from(value: c_ulong) -> Result<Self, Self::Error> {
|
||||
AttributeType::from_u64(value).ok_or(())
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<AttributeType> for c_ulong {
|
||||
type Error = ();
|
||||
fn try_from(value: AttributeType) -> Result<Self, Self::Error> {
|
||||
AttributeType::to_u64(&value).ok_or(())
|
||||
}
|
||||
}
|
27
src/pkcs11/certificate_category.rs
Normal file
27
src/pkcs11/certificate_category.rs
Normal file
@ -0,0 +1,27 @@
|
||||
use std::convert::TryFrom;
|
||||
use std::os::raw::c_ulong;
|
||||
|
||||
use num_derive::{FromPrimitive, ToPrimitive};
|
||||
use num_traits::{FromPrimitive, ToPrimitive};
|
||||
|
||||
#[derive(Debug, FromPrimitive, ToPrimitive)]
|
||||
pub enum CertificateCategory {
|
||||
Unspecified = 0,
|
||||
TokenUser = 1,
|
||||
Authority = 2,
|
||||
OtherEntity = 3,
|
||||
}
|
||||
|
||||
impl TryFrom<c_ulong> for CertificateCategory {
|
||||
type Error = ();
|
||||
fn try_from(value: c_ulong) -> Result<Self, Self::Error> {
|
||||
CertificateCategory::from_u64(value).ok_or(())
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<CertificateCategory> for c_ulong {
|
||||
type Error = ();
|
||||
fn try_from(value: CertificateCategory) -> Result<Self, Self::Error> {
|
||||
CertificateCategory::to_u64(&value).ok_or(())
|
||||
}
|
||||
}
|
27
src/pkcs11/certificate_type.rs
Normal file
27
src/pkcs11/certificate_type.rs
Normal file
@ -0,0 +1,27 @@
|
||||
use std::convert::TryFrom;
|
||||
use std::os::raw::c_ulong;
|
||||
|
||||
use num_derive::{FromPrimitive, ToPrimitive};
|
||||
use num_traits::{FromPrimitive, ToPrimitive};
|
||||
|
||||
#[derive(Debug, FromPrimitive, ToPrimitive)]
|
||||
pub enum CertificateType {
|
||||
X509 = 0,
|
||||
X509AttrCert = 1,
|
||||
Wtls = 2,
|
||||
VendorDefined = 0x80000000,
|
||||
}
|
||||
|
||||
impl TryFrom<c_ulong> for CertificateType {
|
||||
type Error = ();
|
||||
fn try_from(value: c_ulong) -> Result<Self, Self::Error> {
|
||||
CertificateType::from_u64(value).ok_or(())
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<CertificateType> for c_ulong {
|
||||
type Error = ();
|
||||
fn try_from(value: CertificateType) -> Result<Self, Self::Error> {
|
||||
CertificateType::to_u64(&value).ok_or(())
|
||||
}
|
||||
}
|
65
src/pkcs11/flags.rs
Normal file
65
src/pkcs11/flags.rs
Normal file
@ -0,0 +1,65 @@
|
||||
use bitflags::bitflags;
|
||||
|
||||
bitflags! {
|
||||
pub struct Flags: u32 {
|
||||
const TOKEN_PRESENT = 0x00000001;
|
||||
const REMOVABLE_DEVICE = 0x00000002;
|
||||
const HW_SLOT = 0x00000004;
|
||||
const RNG = 0x00000001;
|
||||
const WRITE_PROTECTED = 0x00000002;
|
||||
const LOGIN_REQUIRED = 0x00000004;
|
||||
const USER_PIN_INITIALIZED = 0x00000008;
|
||||
const RESTORE_KEY_NOT_NEEDED = 0x00000020;
|
||||
const CLOCK_ON_TOKEN = 0x00000040;
|
||||
const PROTECTED_AUTHENTICATION_PATH = 0x00000100;
|
||||
const DUAL_CRYPTO_OPERATIONS = 0x00000200;
|
||||
const TOKEN_INITIALIZED = 0x00000400;
|
||||
const SECONDARY_AUTHENTICATION = 0x00000800;
|
||||
const USER_PIN_COUNT_LOW = 0x00010000;
|
||||
const USER_PIN_FINAL_TRY = 0x00020000;
|
||||
const USER_PIN_LOCKED = 0x00040000;
|
||||
const USER_PIN_TO_BE_CHANGED = 0x00080000;
|
||||
const SO_PIN_COUNT_LOW = 0x00100000;
|
||||
const SO_PIN_FINAL_TRY = 0x00200000;
|
||||
const SO_PIN_LOCKED = 0x00400000;
|
||||
const SO_PIN_TO_BE_CHANGED = 0x00800000;
|
||||
const ERROR_STATE = 0x01000000;
|
||||
|
||||
const RW_SESSION = 0x00000002;
|
||||
const SERIAL_SESSION = 0x00000004;
|
||||
|
||||
const ARRAY_ATTRIBUTE = 0x40000000;
|
||||
|
||||
const HW = 0x00000001;
|
||||
const ENCRYPT = 0x00000100;
|
||||
const DECRYPT = 0x00000200;
|
||||
const DIGEST = 0x00000400;
|
||||
const SIGN = 0x00000800;
|
||||
const SIGN_RECOVER = 0x00001000;
|
||||
const VERIFY = 0x00002000;
|
||||
const VERIFY_RECOVER = 0x00004000;
|
||||
const GENERATE = 0x00008000;
|
||||
const GENERATE_KEY_PAIR = 0x00010000;
|
||||
const WRAP = 0x00020000;
|
||||
const UNWRAP = 0x00040000;
|
||||
const DERIVE = 0x00080000;
|
||||
const EC_F_P = 0x00100000;
|
||||
const EC_F_2M = 0x00200000;
|
||||
const EC_ECPARAMETERS = 0x00400000;
|
||||
const EC_NAMEDCURVE = 0x00800000;
|
||||
const EC_UNCOMPRESS = 0x01000000;
|
||||
const EC_COMPRESS = 0x02000000;
|
||||
const EXTENSION = 0x80000000;
|
||||
|
||||
const LIBRARY_CANT_CREATE_OS_THREADS = 0x00000001;
|
||||
const OS_LOCKING_OK = 0x00000002;
|
||||
const DONT_BLOCK = 1;
|
||||
|
||||
const NEXT_OTP = 0x00000001;
|
||||
const EXCLUDE_TIME = 0x00000002;
|
||||
const EXCLUDE_COUNTER = 0x00000004;
|
||||
const EXCLUDE_CHALLENGE = 0x00000008;
|
||||
const EXCLUDE_PIN = 0x00000010;
|
||||
const USER_FRIENDLY_OTP = 0x00000020;
|
||||
}
|
||||
}
|
27
src/pkcs11/hardware_feature_type.rs
Normal file
27
src/pkcs11/hardware_feature_type.rs
Normal file
@ -0,0 +1,27 @@
|
||||
use std::convert::TryFrom;
|
||||
use std::os::raw::c_ulong;
|
||||
|
||||
use num_derive::{FromPrimitive, ToPrimitive};
|
||||
use num_traits::{FromPrimitive, ToPrimitive};
|
||||
|
||||
#[derive(Debug, FromPrimitive, ToPrimitive)]
|
||||
pub enum HardwareFeatureType {
|
||||
MonotonicCounter = 0x01,
|
||||
Clock = 0x02,
|
||||
UserInterface = 0x03,
|
||||
VendorDefined = 0x80000000,
|
||||
}
|
||||
|
||||
impl TryFrom<c_ulong> for HardwareFeatureType {
|
||||
type Error = ();
|
||||
fn try_from(value: c_ulong) -> Result<Self, Self::Error> {
|
||||
HardwareFeatureType::from_u64(value).ok_or(())
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<HardwareFeatureType> for c_ulong {
|
||||
type Error = ();
|
||||
fn try_from(value: HardwareFeatureType) -> Result<Self, Self::Error> {
|
||||
HardwareFeatureType::to_u64(&value).ok_or(())
|
||||
}
|
||||
}
|
32
src/pkcs11/key_derivation_function.rs
Normal file
32
src/pkcs11/key_derivation_function.rs
Normal file
@ -0,0 +1,32 @@
|
||||
use std::convert::TryFrom;
|
||||
use std::os::raw::c_ulong;
|
||||
|
||||
use num_derive::{FromPrimitive, ToPrimitive};
|
||||
use num_traits::{FromPrimitive, ToPrimitive};
|
||||
|
||||
#[derive(Debug, FromPrimitive, ToPrimitive)]
|
||||
pub enum KeyDerivationFunction {
|
||||
Null = 1,
|
||||
Sha1Kdf2 = 2,
|
||||
Sha1KdfAsn1 = 3,
|
||||
Sha1KdfConcatenate = 4,
|
||||
Sha224Kdf = 5,
|
||||
Sha256Kdf = 6,
|
||||
Sha384Kdf = 7,
|
||||
Sha512Kdf = 8,
|
||||
CpdiversifyKdf = 9,
|
||||
}
|
||||
|
||||
impl TryFrom<c_ulong> for KeyDerivationFunction {
|
||||
type Error = ();
|
||||
fn try_from(value: c_ulong) -> Result<Self, Self::Error> {
|
||||
KeyDerivationFunction::from_u64(value).ok_or(())
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<KeyDerivationFunction> for c_ulong {
|
||||
type Error = ();
|
||||
fn try_from(value: KeyDerivationFunction) -> Result<Self, Self::Error> {
|
||||
KeyDerivationFunction::to_u64(&value).ok_or(())
|
||||
}
|
||||
}
|
65
src/pkcs11/key_type.rs
Normal file
65
src/pkcs11/key_type.rs
Normal file
@ -0,0 +1,65 @@
|
||||
use std::convert::TryFrom;
|
||||
use std::os::raw::c_ulong;
|
||||
|
||||
use num_derive::{FromPrimitive, ToPrimitive};
|
||||
use num_traits::{FromPrimitive, ToPrimitive};
|
||||
|
||||
#[derive(Debug, FromPrimitive, ToPrimitive)]
|
||||
pub enum KeyType {
|
||||
Rsa = 0x0000,
|
||||
Dsa = 0x0001,
|
||||
Dh = 0x0002,
|
||||
Ec = 0x0003,
|
||||
X942Dh = 0x0004,
|
||||
Kea = 0x0005,
|
||||
GenericSecret = 0x0010,
|
||||
Rc2 = 0x0011,
|
||||
Rc4 = 0x0012,
|
||||
Des = 0x0013,
|
||||
Des2 = 0x0014,
|
||||
Des3 = 0x0015,
|
||||
Cast = 0x0016,
|
||||
Cast3 = 0x0017,
|
||||
Cast128 = 0x0018,
|
||||
Rc5 = 0x0019,
|
||||
Idea = 0x001a,
|
||||
Skipjack = 0x001b,
|
||||
Baton = 0x001c,
|
||||
Juniper = 0x001d,
|
||||
Cdmf = 0x001e,
|
||||
Aes = 0x001f,
|
||||
Blowfish = 0x0020,
|
||||
Twofish = 0x0021,
|
||||
Securid = 0x0022,
|
||||
Hotp = 0x0023,
|
||||
Acti = 0x0024,
|
||||
Camellia = 0x0025,
|
||||
Aria = 0x0026,
|
||||
Md5Hmac = 0x0027,
|
||||
Sha1Hmac = 0x0028,
|
||||
Ripemd128Hmac = 0x0029,
|
||||
Ripemd160Hmac = 0x002a,
|
||||
Sha256Hmac = 0x002b,
|
||||
Sha384Hmac = 0x002c,
|
||||
Sha512Hmac = 0x002d,
|
||||
Sha224Hmac = 0x002e,
|
||||
Seed = 0x002f,
|
||||
Gostr3410 = 0x0030,
|
||||
Gostr3411 = 0x0031,
|
||||
Gost28147 = 0x0032,
|
||||
VendorDefined = 0x80000000,
|
||||
}
|
||||
|
||||
impl TryFrom<c_ulong> for KeyType {
|
||||
type Error = ();
|
||||
fn try_from(value: c_ulong) -> Result<Self, Self::Error> {
|
||||
KeyType::from_u64(value).ok_or(())
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<KeyType> for c_ulong {
|
||||
type Error = ();
|
||||
fn try_from(value: KeyType) -> Result<Self, Self::Error> {
|
||||
KeyType::to_u64(&value).ok_or(())
|
||||
}
|
||||
}
|
28
src/pkcs11/mask_generation_function.rs
Normal file
28
src/pkcs11/mask_generation_function.rs
Normal file
@ -0,0 +1,28 @@
|
||||
use std::convert::TryFrom;
|
||||
use std::os::raw::c_ulong;
|
||||
|
||||
use num_derive::{FromPrimitive, ToPrimitive};
|
||||
use num_traits::{FromPrimitive, ToPrimitive};
|
||||
|
||||
#[derive(Debug, FromPrimitive, ToPrimitive)]
|
||||
pub enum MaskGenerationFunction {
|
||||
Mgf1Sha1 = 1,
|
||||
Mgf1Sha256 = 2,
|
||||
Mgf1Sha384 = 3,
|
||||
Mgf1Sha512 = 4,
|
||||
Mgf1Sha224 = 5,
|
||||
}
|
||||
|
||||
impl TryFrom<c_ulong> for MaskGenerationFunction {
|
||||
type Error = ();
|
||||
fn try_from(value: c_ulong) -> Result<Self, Self::Error> {
|
||||
MaskGenerationFunction::from_u64(value).ok_or(())
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<MaskGenerationFunction> for c_ulong {
|
||||
type Error = ();
|
||||
fn try_from(value: MaskGenerationFunction) -> Result<Self, Self::Error> {
|
||||
MaskGenerationFunction::to_u64(&value).ok_or(())
|
||||
}
|
||||
}
|
347
src/pkcs11/mechanism_type.rs
Normal file
347
src/pkcs11/mechanism_type.rs
Normal file
@ -0,0 +1,347 @@
|
||||
use std::convert::TryFrom;
|
||||
use std::os::raw::c_ulong;
|
||||
|
||||
use num_derive::{FromPrimitive, ToPrimitive};
|
||||
use num_traits::{FromPrimitive, ToPrimitive};
|
||||
|
||||
#[derive(Debug, FromPrimitive, ToPrimitive)]
|
||||
pub enum MechanismType {
|
||||
RsaPkcsKeyPairGen = 0x0000,
|
||||
RsaPkcs = 0x0001,
|
||||
Rsa9796 = 0x0002,
|
||||
RsaX509 = 0x0003,
|
||||
Md2RsaPkcs = 0x0004,
|
||||
Md5RsaPkcs = 0x0005,
|
||||
Sha1RsaPkcs = 0x0006,
|
||||
Ripemd128RsaPkcs = 0x0007,
|
||||
Ripemd160RsaPkcs = 0x0008,
|
||||
RsaPkcsOaep = 0x0009,
|
||||
RsaX931KeyPairGen = 0x000a,
|
||||
RsaX931 = 0x000b,
|
||||
Sha1RsaX931 = 0x000c,
|
||||
RsaPkcsPss = 0x000d,
|
||||
Sha1RsaPkcsPss = 0x000e,
|
||||
DsaKeyPairGen = 0x0010,
|
||||
Dsa = 0x0011,
|
||||
DsaSha1 = 0x0012,
|
||||
DsaSha224 = 0x0013,
|
||||
DsaSha256 = 0x0014,
|
||||
DsaSha384 = 0x0015,
|
||||
DsaSha512 = 0x0016,
|
||||
DhPkcsKeyPairGen = 0x0020,
|
||||
DhPkcsDerive = 0x0021,
|
||||
X942DhKeyPairGen = 0x0030,
|
||||
X942DhDerive = 0x0031,
|
||||
X942DhHybridDerive = 0x0032,
|
||||
X942MqvDerive = 0x0033,
|
||||
Sha256RsaPkcs = 0x0040,
|
||||
Sha384RsaPkcs = 0x0041,
|
||||
Sha512RsaPkcs = 0x0042,
|
||||
Sha256RsaPkcsPss = 0x0043,
|
||||
Sha384RsaPkcsPss = 0x0044,
|
||||
Sha512RsaPkcsPss = 0x0045,
|
||||
Sha224RsaPkcs = 0x0046,
|
||||
Sha224RsaPkcsPss = 0x0047,
|
||||
Sha512224 = 0x0048,
|
||||
Sha512224Hmac = 0x0049,
|
||||
Sha512224HmacGeneral = 0x004a,
|
||||
Sha512224KeyDerivation = 0x004b,
|
||||
Sha512256 = 0x004c,
|
||||
Sha512256Hmac = 0x004d,
|
||||
Sha512256HmacGeneral = 0x004e,
|
||||
Sha512256KeyDerivation = 0x004f,
|
||||
Sha512T = 0x0050,
|
||||
Sha512THmac = 0x0051,
|
||||
Sha512THmacGeneral = 0x0052,
|
||||
Sha512TKeyDerivation = 0x0053,
|
||||
Rc2KeyGen = 0x0100,
|
||||
Rc2Ecb = 0x0101,
|
||||
Rc2Cbc = 0x0102,
|
||||
Rc2Mac = 0x0103,
|
||||
Rc2MacGeneral = 0x0104,
|
||||
Rc2CbcPad = 0x0105,
|
||||
Rc4KeyGen = 0x0110,
|
||||
Rc4 = 0x0111,
|
||||
DesKeyGen = 0x0120,
|
||||
DesEcb = 0x0121,
|
||||
DesCbc = 0x0122,
|
||||
DesMac = 0x0123,
|
||||
DesMacGeneral = 0x0124,
|
||||
DesCbcPad = 0x0125,
|
||||
Des2KeyGen = 0x0130,
|
||||
Des3KeyGen = 0x0131,
|
||||
Des3Ecb = 0x0132,
|
||||
Des3Cbc = 0x0133,
|
||||
Des3Mac = 0x0134,
|
||||
Des3MacGeneral = 0x0135,
|
||||
Des3CbcPad = 0x0136,
|
||||
Des3CmacGeneral = 0x0137,
|
||||
Des3Cmac = 0x0138,
|
||||
CdmfKeyGen = 0x0140,
|
||||
CdmfEcb = 0x0141,
|
||||
CdmfCbc = 0x0142,
|
||||
CdmfMac = 0x0143,
|
||||
CdmfMacGeneral = 0x0144,
|
||||
CdmfCbcPad = 0x0145,
|
||||
DesOfb64 = 0x0150,
|
||||
DesOfb8 = 0x0151,
|
||||
DesCfb64 = 0x0152,
|
||||
DesCfb8 = 0x0153,
|
||||
Md2 = 0x0200,
|
||||
Md2Hmac = 0x0201,
|
||||
Md2HmacGeneral = 0x0202,
|
||||
Md5 = 0x0210,
|
||||
Md5Hmac = 0x0211,
|
||||
Md5HmacGeneral = 0x0212,
|
||||
Sha1 = 0x0220,
|
||||
Sha1Hmac = 0x0221,
|
||||
Sha1HmacGeneral = 0x0222,
|
||||
Ripemd128 = 0x0230,
|
||||
Ripemd128Hmac = 0x0231,
|
||||
Ripemd128HmacGeneral = 0x0232,
|
||||
Ripemd160 = 0x0240,
|
||||
Ripemd160Hmac = 0x0241,
|
||||
Ripemd160HmacGeneral = 0x0242,
|
||||
Sha256 = 0x0250,
|
||||
Sha256Hmac = 0x0251,
|
||||
Sha256HmacGeneral = 0x0252,
|
||||
Sha224 = 0x0255,
|
||||
Sha224Hmac = 0x0256,
|
||||
Sha224HmacGeneral = 0x0257,
|
||||
Sha384 = 0x0260,
|
||||
Sha384Hmac = 0x0261,
|
||||
Sha384HmacGeneral = 0x0262,
|
||||
Sha512 = 0x0270,
|
||||
Sha512Hmac = 0x0271,
|
||||
Sha512HmacGeneral = 0x0272,
|
||||
SecuridKeyGen = 0x0280,
|
||||
Securid = 0x0282,
|
||||
HotpKeyGen = 0x0290,
|
||||
Hotp = 0x0291,
|
||||
Acti = 0x02a0,
|
||||
ActiKeyGen = 0x02a1,
|
||||
CastKeyGen = 0x0300,
|
||||
CastEcb = 0x0301,
|
||||
CastCbc = 0x0302,
|
||||
CastMac = 0x0303,
|
||||
CastMacGeneral = 0x0304,
|
||||
CastCbcPad = 0x0305,
|
||||
Cast3KeyGen = 0x0310,
|
||||
Cast3Ecb = 0x0311,
|
||||
Cast3Cbc = 0x0312,
|
||||
Cast3Mac = 0x0313,
|
||||
Cast3MacGeneral = 0x0314,
|
||||
Cast3CbcPad = 0x0315,
|
||||
Cast128KeyGen = 0x0320,
|
||||
Cast128Ecb = 0x0321,
|
||||
Cast128Cbc = 0x0322,
|
||||
Cast128Mac = 0x0323,
|
||||
Cast128MacGeneral = 0x0324,
|
||||
Cast128CbcPad = 0x0325,
|
||||
Rc5KeyGen = 0x0330,
|
||||
Rc5Ecb = 0x0331,
|
||||
Rc5Cbc = 0x0332,
|
||||
Rc5Mac = 0x0333,
|
||||
Rc5MacGeneral = 0x0334,
|
||||
Rc5CbcPad = 0x0335,
|
||||
IdeaKeyGen = 0x0340,
|
||||
IdeaEcb = 0x0341,
|
||||
IdeaCbc = 0x0342,
|
||||
IdeaMac = 0x0343,
|
||||
IdeaMacGeneral = 0x0344,
|
||||
IdeaCbcPad = 0x0345,
|
||||
GenericSecretKeyGen = 0x0350,
|
||||
ConcatenateBaseAndKey = 0x0360,
|
||||
ConcatenateBaseAndData = 0x0362,
|
||||
ConcatenateDataAndBase = 0x0363,
|
||||
XorBaseAndData = 0x0364,
|
||||
ExtractKeyFromKey = 0x0365,
|
||||
Ssl3PreMasterKeyGen = 0x0370,
|
||||
Ssl3MasterKeyDerive = 0x0371,
|
||||
Ssl3KeyAndMacDerive = 0x0372,
|
||||
Ssl3MasterKeyDeriveDh = 0x0373,
|
||||
TlsPreMasterKeyGen = 0x0374,
|
||||
TlsMasterKeyDerive = 0x0375,
|
||||
TlsKeyAndMacDerive = 0x0376,
|
||||
TlsMasterKeyDeriveDh = 0x0377,
|
||||
TlsPrf = 0x0378,
|
||||
Ssl3Md5Mac = 0x0380,
|
||||
Ssl3Sha1Mac = 0x0381,
|
||||
Md5KeyDerivation = 0x0390,
|
||||
Md2KeyDerivation = 0x0391,
|
||||
Sha1KeyDerivation = 0x0392,
|
||||
Sha256KeyDerivation = 0x0393,
|
||||
Sha384KeyDerivation = 0x0394,
|
||||
Sha512KeyDerivation = 0x0395,
|
||||
Sha224KeyDerivation = 0x0396,
|
||||
PbeMd2DesCbc = 0x03a0,
|
||||
PbeMd5DesCbc = 0x03a1,
|
||||
PbeMd5CastCbc = 0x03a2,
|
||||
PbeMd5Cast3Cbc = 0x03a3,
|
||||
PbeMd5Cast128Cbc = 0x03a4,
|
||||
PbeSha1Cast128Cbc = 0x03a5,
|
||||
PbeSha1Rc4128 = 0x03a6,
|
||||
PbeSha1Rc440 = 0x03a7,
|
||||
PbeSha1Des3EdeCbc = 0x03a8,
|
||||
PbeSha1Des2EdeCbc = 0x03a9,
|
||||
PbeSha1Rc2128Cbc = 0x03aa,
|
||||
PbeSha1Rc240Cbc = 0x03ab,
|
||||
Pkcs5Pbkd2 = 0x03b0,
|
||||
PbaSha1WithSha1Hmac = 0x03c0,
|
||||
WtlsPreMasterKeyGen = 0x03d0,
|
||||
WtlsMasterKeyDerive = 0x03d1,
|
||||
WtlsMasterKeyDeriveDhEcc = 0x03d2,
|
||||
WtlsPrf = 0x03d3,
|
||||
WtlsServerKeyAndMacDerive = 0x03d4,
|
||||
WtlsClientKeyAndMacDerive = 0x03d5,
|
||||
Tls10MacServer = 0x03d6,
|
||||
Tls10MacClient = 0x03d7,
|
||||
Tls12Mac = 0x03d8,
|
||||
Tls12Kdf = 0x03d9,
|
||||
Tls12MasterKeyDerive = 0x03e0,
|
||||
Tls12KeyAndMacDerive = 0x03e1,
|
||||
Tls12MasterKeyDeriveDh = 0x03e2,
|
||||
Tls12KeySafeDerive = 0x03e3,
|
||||
TlsMac = 0x03e4,
|
||||
TlsKdf = 0x03e5,
|
||||
KeyWrapLynks = 0x0400,
|
||||
KeyWrapSetOaep = 0x0401,
|
||||
CmsSig = 0x0500,
|
||||
KipDerive = 0x0510,
|
||||
KipWrap = 0x0511,
|
||||
KipMac = 0x0512,
|
||||
CamelliaKeyGen = 0x0550,
|
||||
CamelliaEcb = 0x0551,
|
||||
CamelliaCbc = 0x0552,
|
||||
CamelliaMac = 0x0553,
|
||||
CamelliaMacGeneral = 0x0554,
|
||||
CamelliaCbcPad = 0x0555,
|
||||
CamelliaEcbEncryptData = 0x0556,
|
||||
CamelliaCbcEncryptData = 0x0557,
|
||||
CamelliaCtr = 0x0558,
|
||||
AriaKeyGen = 0x0560,
|
||||
AriaEcb = 0x0561,
|
||||
AriaCbc = 0x0562,
|
||||
AriaMac = 0x0563,
|
||||
AriaMacGeneral = 0x0564,
|
||||
AriaCbcPad = 0x0565,
|
||||
AriaEcbEncryptData = 0x0566,
|
||||
AriaCbcEncryptData = 0x0567,
|
||||
SeedKeyGen = 0x0650,
|
||||
SeedEcb = 0x0651,
|
||||
SeedCbc = 0x0652,
|
||||
SeedMac = 0x0653,
|
||||
SeedMacGeneral = 0x0654,
|
||||
SeedCbcPad = 0x0655,
|
||||
SeedEcbEncryptData = 0x0656,
|
||||
SeedCbcEncryptData = 0x0657,
|
||||
SkipjackKeyGen = 0x1000,
|
||||
SkipjackEcb64 = 0x1001,
|
||||
SkipjackCbc64 = 0x1002,
|
||||
SkipjackOfb64 = 0x1003,
|
||||
SkipjackCfb64 = 0x1004,
|
||||
SkipjackCfb32 = 0x1005,
|
||||
SkipjackCfb16 = 0x1006,
|
||||
SkipjackCfb8 = 0x1007,
|
||||
SkipjackWrap = 0x1008,
|
||||
SkipjackPrivateWrap = 0x1009,
|
||||
SkipjackRelayx = 0x100a,
|
||||
KeaKeyPairGen = 0x1010,
|
||||
KeaKeyDerive = 0x1011,
|
||||
KeaDerive = 0x1012,
|
||||
FortezzaTimestamp = 0x1020,
|
||||
BatonKeyGen = 0x1030,
|
||||
BatonEcb128 = 0x1031,
|
||||
BatonEcb96 = 0x1032,
|
||||
BatonCbc128 = 0x1033,
|
||||
BatonCounter = 0x1034,
|
||||
BatonShuffle = 0x1035,
|
||||
BatonWrap = 0x1036,
|
||||
EcKeyPairGen = 0x1040,
|
||||
Ecdsa = 0x1041,
|
||||
EcdsaSha1 = 0x1042,
|
||||
EcdsaSha224 = 0x1043,
|
||||
EcdsaSha256 = 0x1044,
|
||||
EcdsaSha384 = 0x1045,
|
||||
EcdsaSha512 = 0x1046,
|
||||
Ecdh1Derive = 0x1050,
|
||||
Ecdh1CofactorDerive = 0x1051,
|
||||
EcmqvDerive = 0x1052,
|
||||
EcdhAesKeyWrap = 0x1053,
|
||||
RsaAesKeyWrap = 0x1054,
|
||||
JuniperKeyGen = 0x1060,
|
||||
JuniperEcb128 = 0x1061,
|
||||
JuniperCbc128 = 0x1062,
|
||||
JuniperCounter = 0x1063,
|
||||
JuniperShuffle = 0x1064,
|
||||
JuniperWrap = 0x1065,
|
||||
Fasthash = 0x1070,
|
||||
AesKeyGen = 0x1080,
|
||||
AesEcb = 0x1081,
|
||||
AesCbc = 0x1082,
|
||||
AesMac = 0x1083,
|
||||
AesMacGeneral = 0x1084,
|
||||
AesCbcPad = 0x1085,
|
||||
AesCtr = 0x1086,
|
||||
AesGcm = 0x1087,
|
||||
AesCcm = 0x1088,
|
||||
AesCts = 0x1089,
|
||||
AesCmac = 0x108a,
|
||||
AesCmacGeneral = 0x108b,
|
||||
AesXcbcMac = 0x108c,
|
||||
AesXcbcMac96 = 0x108d,
|
||||
AesGmac = 0x108e,
|
||||
BlowfishKeyGen = 0x1090,
|
||||
BlowfishCbc = 0x1091,
|
||||
TwofishKeyGen = 0x1092,
|
||||
TwofishCbc = 0x1093,
|
||||
BlowfishCbcPad = 0x1094,
|
||||
TwofishCbcPad = 0x1095,
|
||||
DesEcbEncryptData = 0x1100,
|
||||
DesCbcEncryptData = 0x1101,
|
||||
Des3EcbEncryptData = 0x1102,
|
||||
Des3CbcEncryptData = 0x1103,
|
||||
AesEcbEncryptData = 0x1104,
|
||||
AesCbcEncryptData = 0x1105,
|
||||
Gostr3410KeyPairGen = 0x1200,
|
||||
Gostr3410 = 0x1201,
|
||||
Gostr3410WithGostr3411 = 0x1202,
|
||||
Gostr3410KeyWrap = 0x1203,
|
||||
Gostr3410Derive = 0x1204,
|
||||
Gostr3411 = 0x1210,
|
||||
Gostr3411Hmac = 0x1211,
|
||||
Gost28147KeyGen = 0x1220,
|
||||
Gost28147Ecb = 0x1221,
|
||||
Gost28147 = 0x1222,
|
||||
Gost28147Mac = 0x1223,
|
||||
Gost28147KeyWrap = 0x1224,
|
||||
DsaParameterGen = 0x2000,
|
||||
DhPkcsParameterGen = 0x2001,
|
||||
X942DhParameterGen = 0x2002,
|
||||
DsaProbablisticParameterGen = 0x2003,
|
||||
DsaShaweTaylorParameterGen = 0x2004,
|
||||
AesOfb = 0x2104,
|
||||
AesCfb64 = 0x2105,
|
||||
AesCfb8 = 0x2106,
|
||||
AesCfb128 = 0x2107,
|
||||
AesCfb1 = 0x2108,
|
||||
AesKeyWrap = 0x2109,
|
||||
AesKeyWrapPad = 0x210a,
|
||||
RsaPkcsTpm11 = 0x4001,
|
||||
RsaPkcsOaepTpm11 = 0x4002,
|
||||
VendorDefined = 0x80000000,
|
||||
}
|
||||
|
||||
impl TryFrom<c_ulong> for MechanismType {
|
||||
type Error = ();
|
||||
fn try_from(value: c_ulong) -> Result<Self, Self::Error> {
|
||||
MechanismType::from_u64(value).ok_or(())
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<MechanismType> for c_ulong {
|
||||
type Error = ();
|
||||
fn try_from(value: MechanismType) -> Result<Self, Self::Error> {
|
||||
MechanismType::to_u64(&value).ok_or(())
|
||||
}
|
||||
}
|
102
src/pkcs11/mod.rs
Normal file
102
src/pkcs11/mod.rs
Normal file
@ -0,0 +1,102 @@
|
||||
//! Types related to PKCS#11.
|
||||
//! This module was originally automatically generated by rust-bindgen,
|
||||
//! however it is now heavily modified.
|
||||
|
||||
use std::convert::TryInto;
|
||||
use std::slice;
|
||||
|
||||
pub const CRYPTOKI_VERSION_MAJOR: u32 = 2;
|
||||
pub const CRYPTOKI_VERSION_MINOR: u32 = 40;
|
||||
pub const _CRYPTOKI_VERSION_AMENDMENT: u32 = 0;
|
||||
pub const UNAVAILABLE_INFORMATION: i32 = -1;
|
||||
pub const _EFFECTIVELY_INFINITE: u32 = 0;
|
||||
pub const _INVALID_HANDLE: u32 = 0;
|
||||
pub const _NEED_ARG_LIST: u32 = 1;
|
||||
//pub const CKZ_DATA_SPECIFIED: u32 = 1;
|
||||
//pub const CKZ_SALT_SPECIFIED: u32 = 1;
|
||||
|
||||
mod notification;
|
||||
pub use notification::Notification;
|
||||
mod user_type;
|
||||
pub use user_type::UserType;
|
||||
mod session_state;
|
||||
pub use session_state::SessionState;
|
||||
mod flags;
|
||||
pub use flags::Flags;
|
||||
mod object_class;
|
||||
pub use object_class::ObjectClass;
|
||||
mod hardware_feature_type;
|
||||
pub use hardware_feature_type::HardwareFeatureType;
|
||||
mod key_type;
|
||||
pub use key_type::KeyType;
|
||||
mod certificate_category;
|
||||
pub use certificate_category::CertificateCategory;
|
||||
mod security_domain;
|
||||
pub use security_domain::SecurityDomain;
|
||||
mod certificate_type;
|
||||
pub use certificate_type::CertificateType;
|
||||
mod attribute_type;
|
||||
pub mod otp;
|
||||
pub use attribute_type::AttributeType;
|
||||
mod mechanism_type;
|
||||
pub use mechanism_type::MechanismType;
|
||||
mod return_value;
|
||||
pub use return_value::ReturnValue;
|
||||
mod mask_generation_function;
|
||||
pub use mask_generation_function::MaskGenerationFunction;
|
||||
mod key_derivation_function;
|
||||
pub use key_derivation_function::KeyDerivationFunction;
|
||||
mod pseudo_random_function;
|
||||
pub use pseudo_random_function::PseudoRandomFunction;
|
||||
mod types;
|
||||
pub use types::*;
|
||||
|
||||
impl Attribute {
|
||||
/// Sets the value field of this attribute. Returns `None`
|
||||
/// if the attribute does not have enough space to store this value.
|
||||
///
|
||||
/// # Safety
|
||||
/// As attribute does not own the value field (instead it contains a pointer)
|
||||
/// any safety considerations regarding pointers apply.
|
||||
pub fn set_value(&mut self, value: &[u8]) -> Option<()> {
|
||||
let len: u64 = value.len().try_into().ok()?;
|
||||
if self.value.is_null() {
|
||||
self.value_len = len;
|
||||
return Some(());
|
||||
}
|
||||
|
||||
if self.value_len < len {
|
||||
return None;
|
||||
}
|
||||
|
||||
let v = self.value as *mut u8;
|
||||
let v = unsafe { slice::from_raw_parts_mut(v, value.len()) };
|
||||
v.copy_from_slice(value);
|
||||
self.value_len = len;
|
||||
Some(())
|
||||
}
|
||||
|
||||
/// Sets the value of this attribute to the given value. Use `set_value` if you
|
||||
/// need to set a slice instead.
|
||||
///
|
||||
/// # Safety
|
||||
/// Attribute values are pointers, therefore any safety considerations
|
||||
/// regarding pointers apply.
|
||||
pub fn set_value_single(&mut self, value: u64) {
|
||||
let val = self.value as *mut u64;
|
||||
unsafe {
|
||||
*val = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Copy a string to the target slice. If the slice is larger than the size required
|
||||
/// by the string, the rest is filled with empty space.
|
||||
pub fn copy_padded(target: &mut [u8], data: &str) {
|
||||
let data = data.as_bytes();
|
||||
let (left, right) = target.split_at_mut(data.len());
|
||||
for a in right.iter_mut() {
|
||||
*a = 32;
|
||||
}
|
||||
left.copy_from_slice(data);
|
||||
}
|
25
src/pkcs11/notification.rs
Normal file
25
src/pkcs11/notification.rs
Normal file
@ -0,0 +1,25 @@
|
||||
use std::convert::TryFrom;
|
||||
use std::os::raw::c_ulong;
|
||||
|
||||
use num_derive::{FromPrimitive, ToPrimitive};
|
||||
use num_traits::{FromPrimitive, ToPrimitive};
|
||||
|
||||
#[derive(Debug, FromPrimitive, ToPrimitive)]
|
||||
pub enum Notification {
|
||||
Surrender = 0,
|
||||
OtpChanged = 1,
|
||||
}
|
||||
|
||||
impl TryFrom<c_ulong> for Notification {
|
||||
type Error = ();
|
||||
fn try_from(value: c_ulong) -> Result<Self, Self::Error> {
|
||||
Notification::from_u64(value).ok_or(())
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<Notification> for c_ulong {
|
||||
type Error = ();
|
||||
fn try_from(value: Notification) -> Result<Self, Self::Error> {
|
||||
Notification::to_u64(&value).ok_or(())
|
||||
}
|
||||
}
|
33
src/pkcs11/object_class.rs
Normal file
33
src/pkcs11/object_class.rs
Normal file
@ -0,0 +1,33 @@
|
||||
use std::convert::TryFrom;
|
||||
use std::os::raw::c_ulong;
|
||||
|
||||
use num_derive::{FromPrimitive, ToPrimitive};
|
||||
use num_traits::{FromPrimitive, ToPrimitive};
|
||||
|
||||
#[derive(Debug, FromPrimitive, ToPrimitive)]
|
||||
pub enum ObjectClass {
|
||||
Data = 0,
|
||||
Certificate = 1,
|
||||
PublicKey = 2,
|
||||
PrivateKey = 3,
|
||||
SecretKey = 4,
|
||||
HwFeature = 5,
|
||||
DomainParameters = 6,
|
||||
Mechanism = 7,
|
||||
OtpKey = 8,
|
||||
VendorDefined = 0x80000000,
|
||||
}
|
||||
|
||||
impl TryFrom<c_ulong> for ObjectClass {
|
||||
type Error = ();
|
||||
fn try_from(value: c_ulong) -> Result<Self, Self::Error> {
|
||||
ObjectClass::from_u64(value).ok_or(())
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<ObjectClass> for c_ulong {
|
||||
type Error = ();
|
||||
fn try_from(value: ObjectClass) -> Result<Self, Self::Error> {
|
||||
ObjectClass::to_u64(&value).ok_or(())
|
||||
}
|
||||
}
|
57
src/pkcs11/otp.rs
Normal file
57
src/pkcs11/otp.rs
Normal file
@ -0,0 +1,57 @@
|
||||
use std::convert::TryFrom;
|
||||
use std::os::raw::c_ulong;
|
||||
|
||||
use num_derive::{FromPrimitive, ToPrimitive};
|
||||
use num_traits::{FromPrimitive, ToPrimitive};
|
||||
|
||||
pub const _VALUE: u32 = 0;
|
||||
pub const _PIN: u32 = 1;
|
||||
pub const _CHALLENGE: u32 = 2;
|
||||
pub const _TIME: u32 = 3;
|
||||
pub const _COUNTER: u32 = 4;
|
||||
pub const _FLAGS: u32 = 5;
|
||||
pub const _OUTPUT_LENGTH: u32 = 6;
|
||||
pub const _OUTPUT_FORMAT: u32 = 7;
|
||||
|
||||
#[derive(Debug, FromPrimitive, ToPrimitive)]
|
||||
pub enum Format {
|
||||
Decimal = 0,
|
||||
Hexadecimal = 1,
|
||||
Alphanumeric = 2,
|
||||
Binary = 3,
|
||||
}
|
||||
|
||||
#[derive(Debug, FromPrimitive, ToPrimitive)]
|
||||
pub enum Param {
|
||||
Ignored = 0,
|
||||
Optional = 1,
|
||||
Mandatory = 2,
|
||||
}
|
||||
|
||||
impl TryFrom<c_ulong> for Format {
|
||||
type Error = ();
|
||||
fn try_from(value: c_ulong) -> Result<Self, Self::Error> {
|
||||
Format::from_u64(value).ok_or(())
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<Format> for c_ulong {
|
||||
type Error = ();
|
||||
fn try_from(value: Format) -> Result<Self, Self::Error> {
|
||||
Format::to_u64(&value).ok_or(())
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<c_ulong> for Param {
|
||||
type Error = ();
|
||||
fn try_from(value: c_ulong) -> Result<Self, Self::Error> {
|
||||
Param::from_u64(value).ok_or(())
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<Param> for c_ulong {
|
||||
type Error = ();
|
||||
fn try_from(value: Param) -> Result<Self, Self::Error> {
|
||||
Param::to_u64(&value).ok_or(())
|
||||
}
|
||||
}
|
31
src/pkcs11/pseudo_random_function.rs
Normal file
31
src/pkcs11/pseudo_random_function.rs
Normal file
@ -0,0 +1,31 @@
|
||||
use std::convert::TryFrom;
|
||||
use std::os::raw::c_ulong;
|
||||
|
||||
use num_derive::{FromPrimitive, ToPrimitive};
|
||||
use num_traits::{FromPrimitive, ToPrimitive};
|
||||
|
||||
#[derive(Debug, FromPrimitive, ToPrimitive)]
|
||||
pub enum PseudoRandomFunction {
|
||||
Pkcs5Pbkd2HmacSha1 = 1,
|
||||
Pkcs5Pbkd2HmacGostr3411 = 2,
|
||||
Pkcs5Pbkd2HmacSha224 = 3,
|
||||
Pkcs5Pbkd2HmacSha256 = 4,
|
||||
Pkcs5Pbkd2HmacSha384 = 5,
|
||||
Pkcs5Pbkd2HmacSha512 = 6,
|
||||
Pkcs5Pbkd2HmacSha512224 = 7,
|
||||
Pkcs5Pbkd2HmacSha512256 = 8,
|
||||
}
|
||||
|
||||
impl TryFrom<c_ulong> for PseudoRandomFunction {
|
||||
type Error = ();
|
||||
fn try_from(value: c_ulong) -> Result<Self, Self::Error> {
|
||||
PseudoRandomFunction::from_u64(value).ok_or(())
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<PseudoRandomFunction> for c_ulong {
|
||||
type Error = ();
|
||||
fn try_from(value: PseudoRandomFunction) -> Result<Self, Self::Error> {
|
||||
PseudoRandomFunction::to_u64(&value).ok_or(())
|
||||
}
|
||||
}
|
118
src/pkcs11/return_value.rs
Normal file
118
src/pkcs11/return_value.rs
Normal file
@ -0,0 +1,118 @@
|
||||
use std::convert::TryFrom;
|
||||
use std::os::raw::c_ulong;
|
||||
|
||||
use num_derive::{FromPrimitive, ToPrimitive};
|
||||
use num_traits::{FromPrimitive, ToPrimitive};
|
||||
|
||||
#[derive(Debug, FromPrimitive, ToPrimitive)]
|
||||
pub enum ReturnValue {
|
||||
Ok = 0x0000,
|
||||
Cancel = 0x0001,
|
||||
HostMemory = 0x0002,
|
||||
SlotIdInvalid = 0x0003,
|
||||
GeneralError = 0x0005,
|
||||
FunctionFailed = 0x0006,
|
||||
ArgumentsBad = 0x0007,
|
||||
NoEvent = 0x0008,
|
||||
NeedToCreateThreads = 0x0009,
|
||||
CantLock = 0x000a,
|
||||
AttributeReadOnly = 0x0010,
|
||||
AttributeSensitive = 0x0011,
|
||||
AttributeTypeInvalid = 0x0012,
|
||||
AttributeValueInvalid = 0x0013,
|
||||
ActionProhibited = 0x001b,
|
||||
DataInvalid = 0x0020,
|
||||
DataLenRange = 0x0021,
|
||||
DeviceError = 0x0030,
|
||||
DeviceMemory = 0x0031,
|
||||
DeviceRemoved = 0x0032,
|
||||
EncryptedDataInvalid = 0x0040,
|
||||
EncryptedDataLenRange = 0x0041,
|
||||
FunctionCanceled = 0x0050,
|
||||
FunctionNotParallel = 0x0051,
|
||||
FunctionNotSupported = 0x0054,
|
||||
KeyHandleInvalid = 0x0060,
|
||||
KeySizeRange = 0x0062,
|
||||
KeyTypeInconsistent = 0x0063,
|
||||
KeyNotNeeded = 0x0064,
|
||||
KeyChanged = 0x0065,
|
||||
KeyNeeded = 0x0066,
|
||||
KeyIndigestible = 0x0067,
|
||||
KeyFunctionNotPermitted = 0x0068,
|
||||
KeyNotWrappable = 0x0069,
|
||||
KeyUnextractable = 0x006a,
|
||||
MechanismInvalid = 0x0070,
|
||||
MechanismParamInvalid = 0x0071,
|
||||
ObjectHandleInvalid = 0x0082,
|
||||
OperationActive = 0x0090,
|
||||
OperationNotInitialized = 0x0091,
|
||||
PinIncorrect = 0x00a0,
|
||||
PinInvalid = 0x00a1,
|
||||
PinLenRange = 0x00a2,
|
||||
PinExpired = 0x00a3,
|
||||
PinLocked = 0x00a4,
|
||||
SessionClosed = 0x00b0,
|
||||
SessionCount = 0x00b1,
|
||||
SessionHandleInvalid = 0x00b3,
|
||||
SessionParallelNotSupported = 0x00b4,
|
||||
SessionReadOnly = 0x00b5,
|
||||
SessionExists = 0x00b6,
|
||||
SessionReadOnlyExists = 0x00b7,
|
||||
SessionReadWriteSoExists = 0x00b8,
|
||||
SignatureInvalid = 0x00c0,
|
||||
SignatureLenRange = 0x00c1,
|
||||
TemplateIncomplete = 0x00d0,
|
||||
TemplateInconsistent = 0x00d1,
|
||||
TokenNotPresent = 0x00e0,
|
||||
TokenNotRecognized = 0x00e1,
|
||||
TokenWriteProtected = 0x00e2,
|
||||
UnwrappingKeyHandleInvalid = 0x00f0,
|
||||
UnwrappingKeySizeRange = 0x00f1,
|
||||
UnwrappingKeyTypeInconsistent = 0x00f2,
|
||||
UserAlreadyLoggedIn = 0x0100,
|
||||
UserNotLoggedIn = 0x0101,
|
||||
UserPinNotInitialized = 0x0102,
|
||||
UserTypeInvalid = 0x0103,
|
||||
UserAnotherAlreadyLoggedIn = 0x0104,
|
||||
UserTooManyTypes = 0x0105,
|
||||
WrappedKeyInvalid = 0x0110,
|
||||
WrappedKeyLenRange = 0x0112,
|
||||
WrappingKeyHandleInvalid = 0x0113,
|
||||
WrappingKeySizeRange = 0x0114,
|
||||
WrappingKeyTypeInconsistent = 0x0115,
|
||||
RandomSeedNotSupported = 0x0120,
|
||||
RandomNoRng = 0x0121,
|
||||
DomainParamsInvalid = 0x0130,
|
||||
CurveNotSupported = 0x0140,
|
||||
BufferTooSmall = 0x0150,
|
||||
SavedStateInvalid = 0x0160,
|
||||
InformationSensitive = 0x0170,
|
||||
StateUnsaveable = 0x0180,
|
||||
CryptokiNotInitialized = 0x0190,
|
||||
CryptokiAlreadyInitialized = 0x0191,
|
||||
MutexBad = 0x01a0,
|
||||
MutexNotLocked = 0x01a1,
|
||||
NewPinMode = 0x01b0,
|
||||
NextOtp = 0x01b1,
|
||||
ExceededMaxIterations = 0x01b5,
|
||||
FipsSelfTestFailed = 0x01b6,
|
||||
LibraryLoadFailed = 0x01b7,
|
||||
PinTooWeak = 0x01b8,
|
||||
PublicKeyInvalid = 0x01b9,
|
||||
FunctionRejected = 0x0200,
|
||||
VendorDefined = 0x80000000,
|
||||
}
|
||||
|
||||
impl TryFrom<c_ulong> for ReturnValue {
|
||||
type Error = ();
|
||||
fn try_from(value: c_ulong) -> Result<Self, Self::Error> {
|
||||
ReturnValue::from_u64(value).ok_or(())
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<ReturnValue> for c_ulong {
|
||||
type Error = ();
|
||||
fn try_from(value: ReturnValue) -> Result<Self, Self::Error> {
|
||||
ReturnValue::to_u64(&value).ok_or(())
|
||||
}
|
||||
}
|
27
src/pkcs11/security_domain.rs
Normal file
27
src/pkcs11/security_domain.rs
Normal file
@ -0,0 +1,27 @@
|
||||
use std::convert::TryFrom;
|
||||
use std::os::raw::c_ulong;
|
||||
|
||||
use num_derive::{FromPrimitive, ToPrimitive};
|
||||
use num_traits::{FromPrimitive, ToPrimitive};
|
||||
|
||||
#[derive(Debug, FromPrimitive, ToPrimitive)]
|
||||
pub enum SecurityDomain {
|
||||
Unspecified = 0,
|
||||
Manufacturer = 1,
|
||||
Operator = 2,
|
||||
ThirdParty = 3,
|
||||
}
|
||||
|
||||
impl TryFrom<c_ulong> for SecurityDomain {
|
||||
type Error = ();
|
||||
fn try_from(value: c_ulong) -> Result<Self, Self::Error> {
|
||||
SecurityDomain::from_u64(value).ok_or(())
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<SecurityDomain> for c_ulong {
|
||||
type Error = ();
|
||||
fn try_from(value: SecurityDomain) -> Result<Self, Self::Error> {
|
||||
SecurityDomain::to_u64(&value).ok_or(())
|
||||
}
|
||||
}
|
28
src/pkcs11/session_state.rs
Normal file
28
src/pkcs11/session_state.rs
Normal file
@ -0,0 +1,28 @@
|
||||
use std::convert::TryFrom;
|
||||
use std::os::raw::c_ulong;
|
||||
|
||||
use num_derive::{FromPrimitive, ToPrimitive};
|
||||
use num_traits::{FromPrimitive, ToPrimitive};
|
||||
|
||||
#[derive(Debug, FromPrimitive, ToPrimitive)]
|
||||
pub enum SessionState {
|
||||
RoPublicSession = 0,
|
||||
RoUserFunctions = 1,
|
||||
RwPublicSession = 2,
|
||||
RwUserFunctions = 3,
|
||||
RwSoFunctions = 4,
|
||||
}
|
||||
|
||||
impl TryFrom<c_ulong> for SessionState {
|
||||
type Error = ();
|
||||
fn try_from(value: c_ulong) -> Result<Self, Self::Error> {
|
||||
SessionState::from_u64(value).ok_or(())
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<SessionState> for c_ulong {
|
||||
type Error = ();
|
||||
fn try_from(value: SessionState) -> Result<Self, Self::Error> {
|
||||
SessionState::to_u64(&value).ok_or(())
|
||||
}
|
||||
}
|
769
src/pkcs11/types.rs
Normal file
769
src/pkcs11/types.rs
Normal file
@ -0,0 +1,769 @@
|
||||
use std::os::raw::{c_uchar, c_ulong, c_void};
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct Version {
|
||||
pub major: c_uchar,
|
||||
pub minor: c_uchar,
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct Info {
|
||||
pub cryptoki_version: Version,
|
||||
pub manufacturer_id: [c_uchar; 32usize],
|
||||
pub flags: c_ulong,
|
||||
pub library_description: [c_uchar; 32usize],
|
||||
pub library_version: Version,
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct SlotInfo {
|
||||
pub slot_description: [c_uchar; 64usize],
|
||||
pub manufacturer_id: [c_uchar; 32usize],
|
||||
pub flags: c_ulong,
|
||||
pub hardware_version: Version,
|
||||
pub firmware_version: Version,
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct TokenInfo {
|
||||
pub label: [c_uchar; 32usize],
|
||||
pub manufacturer_id: [c_uchar; 32usize],
|
||||
pub model: [c_uchar; 16usize],
|
||||
pub serial_number: [c_uchar; 16usize],
|
||||
pub flags: c_ulong,
|
||||
pub max_session_count: c_ulong,
|
||||
pub session_count: c_ulong,
|
||||
pub max_rw_session_count: c_ulong,
|
||||
pub rw_session_count: c_ulong,
|
||||
pub max_pin_len: c_ulong,
|
||||
pub min_pin_len: c_ulong,
|
||||
pub total_public_memory: c_ulong,
|
||||
pub free_public_memory: c_ulong,
|
||||
pub total_private_memory: c_ulong,
|
||||
pub free_private_memory: c_ulong,
|
||||
pub hardware_version: Version,
|
||||
pub firmware_version: Version,
|
||||
pub utc_time: [c_uchar; 16usize],
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct SessionInfo {
|
||||
pub slot_id: c_ulong,
|
||||
pub state: c_ulong,
|
||||
pub flags: c_ulong,
|
||||
pub device_error: c_ulong,
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct Attribute {
|
||||
pub type_: c_ulong,
|
||||
pub value: *mut c_void,
|
||||
pub value_len: c_ulong,
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct Date {
|
||||
pub year: [c_uchar; 4usize],
|
||||
pub month: [c_uchar; 2usize],
|
||||
pub day: [c_uchar; 2usize],
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct Mechanism {
|
||||
pub mechanism: c_ulong,
|
||||
pub parameter: *mut c_void,
|
||||
pub parameter_len: c_ulong,
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct MechanismInfo {
|
||||
pub min_key_size: c_ulong,
|
||||
pub max_key_size: c_ulong,
|
||||
pub flags: c_ulong,
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct CInitializeArgs {
|
||||
pub create_mutex: Option<unsafe extern "C" fn(*mut *mut c_void) -> c_ulong>,
|
||||
pub destroy_mutex: Option<unsafe extern "C" fn(*mut c_void) -> c_ulong>,
|
||||
pub lock_mutex: Option<unsafe extern "C" fn(*mut c_void) -> c_ulong>,
|
||||
pub unlockmutex: Option<unsafe extern "C" fn(*mut c_void) -> c_ulong>,
|
||||
pub flags: c_ulong,
|
||||
pub reserved: *mut c_void,
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct RsaPkcsOaepParams {
|
||||
pub hash_alg: c_ulong,
|
||||
pub mgf: c_ulong,
|
||||
pub source: c_ulong,
|
||||
pub source_data: *mut c_void,
|
||||
pub source_data_len: c_ulong,
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct RsaPkcsPssParams {
|
||||
pub hash_alg: c_ulong,
|
||||
pub mgf: c_ulong,
|
||||
pub len: c_ulong,
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct Ecdh1DeriveParams {
|
||||
pub kdf: c_ulong,
|
||||
pub shared_data_len: c_ulong,
|
||||
pub shared_data: *mut c_uchar,
|
||||
pub public_data_len: c_ulong,
|
||||
pub public_data: *mut c_uchar,
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct Ecdh2DeriveParams {
|
||||
pub kdf: c_ulong,
|
||||
pub shared_data_len: c_ulong,
|
||||
pub shared_data: *mut c_uchar,
|
||||
pub public_data_len: c_ulong,
|
||||
pub public_data: *mut c_uchar,
|
||||
pub private_data_len: c_ulong,
|
||||
pub private_data: c_ulong,
|
||||
pub public_data_len2: c_ulong,
|
||||
pub public_data2: *mut c_uchar,
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct EcmqvDeriveParams {
|
||||
pub kdf: c_ulong,
|
||||
pub shared_data_len: c_ulong,
|
||||
pub shared_data: *mut c_uchar,
|
||||
pub public_data_len: c_ulong,
|
||||
pub public_data: *mut c_uchar,
|
||||
pub private_data_len: c_ulong,
|
||||
pub private_data: c_ulong,
|
||||
pub public_data_len2: c_ulong,
|
||||
pub public_data2: *mut c_uchar,
|
||||
pub public_key: c_ulong,
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct X942Dh1DeriveParams {
|
||||
pub kdf: c_ulong,
|
||||
pub other_info_len: c_ulong,
|
||||
pub other_info: *mut c_uchar,
|
||||
pub public_data_len: c_ulong,
|
||||
pub public_data: *mut c_uchar,
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct X942Dh2DeriveParams {
|
||||
pub kdf: c_ulong,
|
||||
pub other_info_len: c_ulong,
|
||||
pub other_info: *mut c_uchar,
|
||||
pub public_data_len: c_ulong,
|
||||
pub public_data: *mut c_uchar,
|
||||
pub private_data_len: c_ulong,
|
||||
pub private_data: c_ulong,
|
||||
pub public_data_len2: c_ulong,
|
||||
pub public_data2: *mut c_uchar,
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct X942MqvDeriveParams {
|
||||
pub kdf: c_ulong,
|
||||
pub other_info_len: c_ulong,
|
||||
pub other_info: *mut c_uchar,
|
||||
pub public_data_len: c_ulong,
|
||||
pub public_data: *mut c_uchar,
|
||||
pub private_data_len: c_ulong,
|
||||
pub private_data: c_ulong,
|
||||
pub public_data_len2: c_ulong,
|
||||
pub public_data2: *mut c_uchar,
|
||||
pub public_key: c_ulong,
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct KeaDeriveParams {
|
||||
pub is_sender: c_uchar,
|
||||
pub random_len: c_ulong,
|
||||
pub random_a: *mut c_uchar,
|
||||
pub random_b: *mut c_uchar,
|
||||
pub public_data_len: c_ulong,
|
||||
pub public_data: *mut c_uchar,
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct Rc2CbcParams {
|
||||
pub effective_bits: c_ulong,
|
||||
pub iv: [c_uchar; 8usize],
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct Rc2MacGeneralParams {
|
||||
pub effective_bits: c_ulong,
|
||||
pub mac_length: c_ulong,
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct Rc5Params {
|
||||
pub wordsize: c_ulong,
|
||||
pub rounds: c_ulong,
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct Rc5CbcParams {
|
||||
pub wordsize: c_ulong,
|
||||
pub rounds: c_ulong,
|
||||
pub iv: *mut c_uchar,
|
||||
pub iv_len: c_ulong,
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct Rc5MacGeneralParams {
|
||||
pub wordsize: c_ulong,
|
||||
pub rounds: c_ulong,
|
||||
pub mac_length: c_ulong,
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct DesCbcEncryptDataParams {
|
||||
pub iv: [c_uchar; 8usize],
|
||||
pub data: *mut c_uchar,
|
||||
pub length: c_ulong,
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct AesCbcEncryptDataParams {
|
||||
pub iv: [c_uchar; 16usize],
|
||||
pub data: *mut c_uchar,
|
||||
pub length: c_ulong,
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct SkipjackPrivateWrapParams {
|
||||
pub password_len: c_ulong,
|
||||
pub password: *mut c_uchar,
|
||||
pub public_data_len: c_ulong,
|
||||
pub public_data: *mut c_uchar,
|
||||
pub p_and_g_len: c_ulong,
|
||||
pub q_len: c_ulong,
|
||||
pub random_len: c_ulong,
|
||||
pub random_a: *mut c_uchar,
|
||||
pub prime_p: *mut c_uchar,
|
||||
pub base_g: *mut c_uchar,
|
||||
pub subprime_q: *mut c_uchar,
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct SkipjackRelayxParams {
|
||||
pub old_wrapped_x_len: c_ulong,
|
||||
pub old_wrapped_x: *mut c_uchar,
|
||||
pub old_password_len: c_ulong,
|
||||
pub old_password: *mut c_uchar,
|
||||
pub old_public_data_len: c_ulong,
|
||||
pub old_public_data: *mut c_uchar,
|
||||
pub old_pandom_len: c_ulong,
|
||||
pub old_random_a: *mut c_uchar,
|
||||
pub new_password_len: c_ulong,
|
||||
pub new_password: *mut c_uchar,
|
||||
pub new_public_data_len: c_ulong,
|
||||
pub new_public_data: *mut c_uchar,
|
||||
pub new_random_len: c_ulong,
|
||||
pub new_random_a: *mut c_uchar,
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct PbeParams {
|
||||
pub init_vector: *mut c_uchar,
|
||||
pub password: *mut c_uchar,
|
||||
pub password_len: c_ulong,
|
||||
pub salt: *mut c_uchar,
|
||||
pub salt_len: c_ulong,
|
||||
pub iteration: c_ulong,
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct KeyWrapSetOaepParams {
|
||||
pub bc: c_uchar,
|
||||
pub x: *mut c_uchar,
|
||||
pub x_len: c_ulong,
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct Ssl3RandomData {
|
||||
pub client_random: *mut c_uchar,
|
||||
pub client_random_len: c_ulong,
|
||||
pub server_random: *mut c_uchar,
|
||||
pub server_random_len: c_ulong,
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct Ssl3MasterKeyDeriveParams {
|
||||
pub random_info: Ssl3RandomData,
|
||||
pub version: *mut Version,
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct Ssl3KeyMatOut {
|
||||
pub client_mac_secret: c_ulong,
|
||||
pub server_mac_secret: c_ulong,
|
||||
pub client_key: c_ulong,
|
||||
pub server_key: c_ulong,
|
||||
pub iv_client: *mut c_uchar,
|
||||
pub iv_server: *mut c_uchar,
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct Ssl3KeyMatParams {
|
||||
pub mac_size_in_bits: c_ulong,
|
||||
pub key_size_in_bits: c_ulong,
|
||||
pub iv_size_in_bits: c_ulong,
|
||||
pub is_export: c_uchar,
|
||||
pub random_info: Ssl3RandomData,
|
||||
pub returned_key_material: *mut Ssl3KeyMatOut,
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct TlsPrfParams {
|
||||
pub seed: *mut c_uchar,
|
||||
pub seed_len: c_ulong,
|
||||
pub label: *mut c_uchar,
|
||||
pub label_len: c_ulong,
|
||||
pub output: *mut c_uchar,
|
||||
pub output_len: *mut c_ulong,
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct WtlsRandomData {
|
||||
pub client_random: *mut c_uchar,
|
||||
pub client_random_len: c_ulong,
|
||||
pub server_random: *mut c_uchar,
|
||||
pub server_random_len: c_ulong,
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct WtlsMasterKeyDeriveParams {
|
||||
pub digest_mechanism: c_ulong,
|
||||
pub random_info: WtlsRandomData,
|
||||
pub version: *mut c_uchar,
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct WtlsPrfParams {
|
||||
pub digest_mechanism: c_ulong,
|
||||
pub seed: *mut c_uchar,
|
||||
pub seed_len: c_ulong,
|
||||
pub label: *mut c_uchar,
|
||||
pub label_len: c_ulong,
|
||||
pub output: *mut c_uchar,
|
||||
pub output_len: *mut c_ulong,
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct WtlsKeyMatOut {
|
||||
pub mac_secret: c_ulong,
|
||||
pub key: c_ulong,
|
||||
pub iv: *mut c_uchar,
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct WtlsKeyMatParams {
|
||||
pub digest_mechanism: c_ulong,
|
||||
pub mac_size_in_bits: c_ulong,
|
||||
pub key_size_in_bits: c_ulong,
|
||||
pub iv_size_in_bits: c_ulong,
|
||||
pub sequence_number: c_ulong,
|
||||
pub is_export: c_uchar,
|
||||
pub random_info: WtlsRandomData,
|
||||
pub returned_key_material: *mut WtlsKeyMatOut,
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct CmsSigParams {
|
||||
pub certificate_handle: c_ulong,
|
||||
pub signing_mechanism: *mut Mechanism,
|
||||
pub digest_mechanism: *mut Mechanism,
|
||||
pub content_type: *mut c_uchar,
|
||||
pub requested_attributes: *mut c_uchar,
|
||||
pub requested_attributes_len: c_ulong,
|
||||
pub required_attributes: *mut c_uchar,
|
||||
pub required_attributes_len: c_ulong,
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct KeyDerivationStringData {
|
||||
pub data: *mut c_uchar,
|
||||
pub len: c_ulong,
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct Pkcs5Pbkd2Params {
|
||||
pub salt_source: c_ulong,
|
||||
pub salt_source_data: *mut c_void,
|
||||
pub salt_source_data_len: c_ulong,
|
||||
pub iterations: c_ulong,
|
||||
pub prf: c_ulong,
|
||||
pub prf_data: *mut c_void,
|
||||
pub prf_data_len: c_ulong,
|
||||
pub password: *mut c_uchar,
|
||||
pub password_len: *mut c_ulong,
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct Pkcs5Pbkd2Params2 {
|
||||
pub salt_source: c_ulong,
|
||||
pub salt_source_data: *mut c_void,
|
||||
pub salt_source_data_len: c_ulong,
|
||||
pub iterations: c_ulong,
|
||||
pub prf: c_ulong,
|
||||
pub prf_data: *mut c_void,
|
||||
pub prf_data_len: c_ulong,
|
||||
pub password: *mut c_uchar,
|
||||
pub password_len: c_ulong,
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct OtpParam {
|
||||
pub type_: c_ulong,
|
||||
pub value: *mut c_void,
|
||||
pub value_len: c_ulong,
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct OtpParams {
|
||||
pub params: *mut OtpParam,
|
||||
pub count: c_ulong,
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct OtpSignatureInfo {
|
||||
pub params: *mut OtpParam,
|
||||
pub count: c_ulong,
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct KipParams {
|
||||
pub mechanism: *mut Mechanism,
|
||||
pub key: c_ulong,
|
||||
pub seed: *mut c_uchar,
|
||||
pub seed_len: c_ulong,
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct AesCtrParams {
|
||||
pub counter_bits: c_ulong,
|
||||
pub cb: [c_uchar; 16usize],
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct GcmParams {
|
||||
pub iv: *mut c_uchar,
|
||||
pub iv_len: c_ulong,
|
||||
pub iv_bits: c_ulong,
|
||||
pub aad: *mut c_uchar,
|
||||
pub aad_len: c_ulong,
|
||||
pub tag_bits: c_ulong,
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct CcmParams {
|
||||
pub data_len: c_ulong,
|
||||
pub nonce: *mut c_uchar,
|
||||
pub nonce_len: c_ulong,
|
||||
pub aad: *mut c_uchar,
|
||||
pub aad_len: c_ulong,
|
||||
pub mac_len: c_ulong,
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct AesGcmParams {
|
||||
pub iv: *mut c_uchar,
|
||||
pub iv_len: c_ulong,
|
||||
pub iv_bits: c_ulong,
|
||||
pub aad: *mut c_uchar,
|
||||
pub aad_len: c_ulong,
|
||||
pub tag_bits: c_ulong,
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct AesCcmParams {
|
||||
pub data_len: c_ulong,
|
||||
pub nonce: *mut c_uchar,
|
||||
pub nonce_len: c_ulong,
|
||||
pub aad: *mut c_uchar,
|
||||
pub aad_len: c_ulong,
|
||||
pub mac_len: c_ulong,
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct CamelliaCtrParams {
|
||||
pub counter_bits: c_ulong,
|
||||
pub cb: [c_uchar; 16usize],
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct CamelliaCbcEncryptDataParams {
|
||||
pub iv: [c_uchar; 16usize],
|
||||
pub data: *mut c_uchar,
|
||||
pub length: c_ulong,
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct AriaCbcEncryptDataParams {
|
||||
pub iv: [c_uchar; 16usize],
|
||||
pub data: *mut c_uchar,
|
||||
pub length: c_ulong,
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct DsaParameterGenParam {
|
||||
pub hash: c_ulong,
|
||||
pub seed: *mut c_uchar,
|
||||
pub seed_len: c_ulong,
|
||||
pub index: c_ulong,
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct EcdhAesKeyWrapParams {
|
||||
pub aes_key_bits: c_ulong,
|
||||
pub kdf: c_ulong,
|
||||
pub shared_data_len: c_ulong,
|
||||
pub shared_data: *mut c_uchar,
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct RsaAesKeyWrapParams {
|
||||
pub aes_key_bits: c_ulong,
|
||||
pub oaep_params: *mut RsaPkcsOaepParams,
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct Tls12MasterKeyDeriveParams {
|
||||
pub random_info: Ssl3RandomData,
|
||||
pub version: *mut Version,
|
||||
pub prf_hash_mechanism: c_ulong,
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct Tls12KeyMatParams {
|
||||
pub mac_size_in_bits: c_ulong,
|
||||
pub key_size_in_bits: c_ulong,
|
||||
pub iv_size_in_bits: c_ulong,
|
||||
pub is_export: c_uchar,
|
||||
pub random_info: Ssl3RandomData,
|
||||
pub returned_key_material: *mut Ssl3KeyMatOut,
|
||||
pub hash_mechanism: c_ulong,
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct TlsKdfParams {
|
||||
pub mechanism: c_ulong,
|
||||
pub label: *mut c_uchar,
|
||||
pub label_length: c_ulong,
|
||||
pub random_info: Ssl3RandomData,
|
||||
pub context_data: *mut c_uchar,
|
||||
pub context_data_length: c_ulong,
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct TlsMacParams {
|
||||
pub hash_mechanism: c_ulong,
|
||||
pub mac_length: c_ulong,
|
||||
pub server_or_client: c_ulong,
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct Gostr3410DeriveParams {
|
||||
pub kdf: c_ulong,
|
||||
pub public_data: *mut c_uchar,
|
||||
pub public_data_len: c_ulong,
|
||||
pub ukm: *mut c_uchar,
|
||||
pub ukm_len: c_ulong,
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct Gostr3410KeyWrapParams {
|
||||
pub wrap_oid: *mut c_uchar,
|
||||
pub wrap_oid_len: c_ulong,
|
||||
pub ukm: *mut c_uchar,
|
||||
pub ukm_len: c_ulong,
|
||||
pub key: c_ulong,
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct SeedCbcEncryptDataParams {
|
||||
pub iv: [c_uchar; 16usize],
|
||||
pub data: *mut c_uchar,
|
||||
pub length: c_ulong,
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct FunctionList {
|
||||
pub version: Version,
|
||||
pub initialize: Option<unsafe extern "C" fn(*mut c_void) -> c_ulong>,
|
||||
pub finalize: Option<unsafe extern "C" fn(*mut c_void) -> c_ulong>,
|
||||
pub get_info: Option<unsafe extern "C" fn(*mut Info) -> c_ulong>,
|
||||
pub get_function_list: Option<unsafe extern "C" fn(*mut *mut FunctionList) -> c_ulong>,
|
||||
pub get_slot_list: Option<unsafe extern "C" fn(c_uchar, *mut c_ulong, *mut c_ulong) -> c_ulong>,
|
||||
pub get_slot_info: Option<unsafe extern "C" fn(c_ulong, *mut SlotInfo) -> c_ulong>,
|
||||
pub get_token_info: Option<unsafe extern "C" fn(c_ulong, *mut TokenInfo) -> c_ulong>,
|
||||
pub get_mechanism_list:
|
||||
Option<unsafe extern "C" fn(c_ulong, *mut c_ulong, *mut c_ulong) -> c_ulong>,
|
||||
pub get_mechanism_info:
|
||||
Option<unsafe extern "C" fn(c_ulong, c_ulong, *mut MechanismInfo) -> c_ulong>,
|
||||
pub init_token:
|
||||
Option<unsafe extern "C" fn(c_ulong, *mut c_uchar, c_ulong, *mut c_uchar) -> c_ulong>,
|
||||
pub init_pin: Option<unsafe extern "C" fn(c_ulong, *mut c_uchar, c_ulong) -> c_ulong>,
|
||||
pub set_pin: Option<
|
||||
unsafe extern "C" fn(c_ulong, *mut c_uchar, c_ulong, *mut c_uchar, c_ulong) -> c_ulong,
|
||||
>,
|
||||
pub open_session: Option<
|
||||
unsafe extern "C" fn(
|
||||
c_ulong,
|
||||
c_ulong,
|
||||
*mut c_void,
|
||||
Option<unsafe extern "C" fn(c_ulong, c_ulong, *mut c_void) -> c_ulong>,
|
||||
*mut c_ulong,
|
||||
) -> c_ulong,
|
||||
>,
|
||||
pub close_session: Option<unsafe extern "C" fn(c_ulong) -> c_ulong>,
|
||||
pub close_all_sessions: Option<unsafe extern "C" fn(c_ulong) -> c_ulong>,
|
||||
pub get_session_info: Option<unsafe extern "C" fn(c_ulong, *mut SessionInfo) -> c_ulong>,
|
||||
pub get_operation_state:
|
||||
Option<unsafe extern "C" fn(c_ulong, *mut c_uchar, *mut c_ulong) -> c_ulong>,
|
||||
pub set_operation_state:
|
||||
Option<unsafe extern "C" fn(c_ulong, *mut c_uchar, c_ulong, c_ulong, c_ulong) -> c_ulong>,
|
||||
pub login: Option<unsafe extern "C" fn(c_ulong, c_ulong, *mut c_uchar, c_ulong) -> c_ulong>,
|
||||
pub logout: Option<unsafe extern "C" fn(c_ulong) -> c_ulong>,
|
||||
pub create_object:
|
||||
Option<unsafe extern "C" fn(c_ulong, *mut Attribute, c_ulong, *mut c_ulong) -> c_ulong>,
|
||||
pub copy_object: Option<
|
||||
unsafe extern "C" fn(c_ulong, c_ulong, *mut Attribute, c_ulong, *mut c_ulong) -> c_ulong,
|
||||
>,
|
||||
pub destroy_object: Option<unsafe extern "C" fn(c_ulong, c_ulong) -> c_ulong>,
|
||||
pub get_object_size: Option<unsafe extern "C" fn(c_ulong, c_ulong, *mut c_ulong) -> c_ulong>,
|
||||
pub get_attribute_value:
|
||||
Option<unsafe extern "C" fn(c_ulong, c_ulong, *mut Attribute, c_ulong) -> c_ulong>,
|
||||
pub set_attribute_value:
|
||||
Option<unsafe extern "C" fn(c_ulong, c_ulong, *mut Attribute, c_ulong) -> c_ulong>,
|
||||
pub find_objects_init:
|
||||
Option<unsafe extern "C" fn(c_ulong, *mut Attribute, c_ulong) -> c_ulong>,
|
||||
pub find_objects:
|
||||
Option<unsafe extern "C" fn(c_ulong, *mut c_ulong, c_ulong, *mut c_ulong) -> c_ulong>,
|
||||
pub find_objects_final: Option<unsafe extern "C" fn(c_ulong) -> c_ulong>,
|
||||
pub encrypt_init: Option<unsafe extern "C" fn(c_ulong, *mut Mechanism, c_ulong) -> c_ulong>,
|
||||
pub encrypt: Option<
|
||||
unsafe extern "C" fn(c_ulong, *mut c_uchar, c_ulong, *mut c_uchar, *mut c_ulong) -> c_ulong,
|
||||
>,
|
||||
pub encrypt_update: Option<
|
||||
unsafe extern "C" fn(c_ulong, *mut c_uchar, c_ulong, *mut c_uchar, *mut c_ulong) -> c_ulong,
|
||||
>,
|
||||
pub encrypt_final: Option<unsafe extern "C" fn(c_ulong, *mut c_uchar, *mut c_ulong) -> c_ulong>,
|
||||
pub decrypt_init: Option<unsafe extern "C" fn(c_ulong, *mut Mechanism, c_ulong) -> c_ulong>,
|
||||
pub decrypt: Option<
|
||||
unsafe extern "C" fn(c_ulong, *mut c_uchar, c_ulong, *mut c_uchar, *mut c_ulong) -> c_ulong,
|
||||
>,
|
||||
pub decrypt_update: Option<
|
||||
unsafe extern "C" fn(c_ulong, *mut c_uchar, c_ulong, *mut c_uchar, *mut c_ulong) -> c_ulong,
|
||||
>,
|
||||
pub decrypt_final: Option<unsafe extern "C" fn(c_ulong, *mut c_uchar, *mut c_ulong) -> c_ulong>,
|
||||
pub digest_init: Option<unsafe extern "C" fn(c_ulong, *mut Mechanism) -> c_ulong>,
|
||||
pub digest: Option<
|
||||
unsafe extern "C" fn(c_ulong, *mut c_uchar, c_ulong, *mut c_uchar, *mut c_ulong) -> c_ulong,
|
||||
>,
|
||||
pub digest_update: Option<unsafe extern "C" fn(c_ulong, *mut c_uchar, c_ulong) -> c_ulong>,
|
||||
pub digest_key: Option<unsafe extern "C" fn(c_ulong, c_ulong) -> c_ulong>,
|
||||
pub digest_final: Option<unsafe extern "C" fn(c_ulong, *mut c_uchar, *mut c_ulong) -> c_ulong>,
|
||||
pub sign_init: Option<unsafe extern "C" fn(c_ulong, *mut Mechanism, c_ulong) -> c_ulong>,
|
||||
pub sign: Option<
|
||||
unsafe extern "C" fn(c_ulong, *mut c_uchar, c_ulong, *mut c_uchar, *mut c_ulong) -> c_ulong,
|
||||
>,
|
||||
pub sign_update: Option<unsafe extern "C" fn(c_ulong, *mut c_uchar, c_ulong) -> c_ulong>,
|
||||
pub sign_final: Option<unsafe extern "C" fn(c_ulong, *mut c_uchar, *mut c_ulong) -> c_ulong>,
|
||||
pub sign_recover_init:
|
||||
Option<unsafe extern "C" fn(c_ulong, *mut Mechanism, c_ulong) -> c_ulong>,
|
||||
pub sign_recover: Option<
|
||||
unsafe extern "C" fn(c_ulong, *mut c_uchar, c_ulong, *mut c_uchar, *mut c_ulong) -> c_ulong,
|
||||
>,
|
||||
pub verify_init: Option<unsafe extern "C" fn(c_ulong, *mut Mechanism, c_ulong) -> c_ulong>,
|
||||
pub verify: Option<
|
||||
unsafe extern "C" fn(c_ulong, *mut c_uchar, c_ulong, *mut c_uchar, c_ulong) -> c_ulong,
|
||||
>,
|
||||
pub verify_update: Option<unsafe extern "C" fn(c_ulong, *mut c_uchar, c_ulong) -> c_ulong>,
|
||||
pub verify_final: Option<unsafe extern "C" fn(c_ulong, *mut c_uchar, c_ulong) -> c_ulong>,
|
||||
pub verify_recover_init:
|
||||
Option<unsafe extern "C" fn(c_ulong, *mut Mechanism, c_ulong) -> c_ulong>,
|
||||
pub verify_recover: Option<
|
||||
unsafe extern "C" fn(c_ulong, *mut c_uchar, c_ulong, *mut c_uchar, *mut c_ulong) -> c_ulong,
|
||||
>,
|
||||
pub digest_encrypt_update: Option<
|
||||
unsafe extern "C" fn(c_ulong, *mut c_uchar, c_ulong, *mut c_uchar, *mut c_ulong) -> c_ulong,
|
||||
>,
|
||||
pub decrypt_digest_update: Option<
|
||||
unsafe extern "C" fn(c_ulong, *mut c_uchar, c_ulong, *mut c_uchar, *mut c_ulong) -> c_ulong,
|
||||
>,
|
||||
pub sign_encrypt_update: Option<
|
||||
unsafe extern "C" fn(c_ulong, *mut c_uchar, c_ulong, *mut c_uchar, *mut c_ulong) -> c_ulong,
|
||||
>,
|
||||
pub decrypt_verify_update: Option<
|
||||
unsafe extern "C" fn(c_ulong, *mut c_uchar, c_ulong, *mut c_uchar, *mut c_ulong) -> c_ulong,
|
||||
>,
|
||||
pub generate_key: Option<
|
||||
unsafe extern "C" fn(
|
||||
c_ulong,
|
||||
*mut Mechanism,
|
||||
*mut Attribute,
|
||||
c_ulong,
|
||||
*mut c_ulong,
|
||||
) -> c_ulong,
|
||||
>,
|
||||
pub generate_key_pair: Option<
|
||||
unsafe extern "C" fn(
|
||||
c_ulong,
|
||||
*mut Mechanism,
|
||||
*mut Attribute,
|
||||
c_ulong,
|
||||
*mut Attribute,
|
||||
c_ulong,
|
||||
*mut c_ulong,
|
||||
*mut c_ulong,
|
||||
) -> c_ulong,
|
||||
>,
|
||||
pub wrap_key: Option<
|
||||
unsafe extern "C" fn(
|
||||
c_ulong,
|
||||
*mut Mechanism,
|
||||
c_ulong,
|
||||
c_ulong,
|
||||
*mut c_uchar,
|
||||
*mut c_ulong,
|
||||
) -> c_ulong,
|
||||
>,
|
||||
pub unwrap_key: Option<
|
||||
unsafe extern "C" fn(
|
||||
c_ulong,
|
||||
*mut Mechanism,
|
||||
c_ulong,
|
||||
*mut c_uchar,
|
||||
c_ulong,
|
||||
*mut Attribute,
|
||||
c_ulong,
|
||||
*mut c_ulong,
|
||||
) -> c_ulong,
|
||||
>,
|
||||
pub derive_key: Option<
|
||||
unsafe extern "C" fn(
|
||||
c_ulong,
|
||||
*mut Mechanism,
|
||||
c_ulong,
|
||||
*mut Attribute,
|
||||
c_ulong,
|
||||
*mut c_ulong,
|
||||
) -> c_ulong,
|
||||
>,
|
||||
pub seed_random: Option<unsafe extern "C" fn(c_ulong, *mut c_uchar, c_ulong) -> c_ulong>,
|
||||
pub generate_random: Option<unsafe extern "C" fn(c_ulong, *mut c_uchar, c_ulong) -> c_ulong>,
|
||||
pub get_function_status: Option<unsafe extern "C" fn(c_ulong) -> c_ulong>,
|
||||
pub cancel_function: Option<unsafe extern "C" fn(c_ulong) -> c_ulong>,
|
||||
pub wait_for_slot_event:
|
||||
Option<unsafe extern "C" fn(c_ulong, *mut c_ulong, *mut c_void) -> c_ulong>,
|
||||
}
|
26
src/pkcs11/user_type.rs
Normal file
26
src/pkcs11/user_type.rs
Normal file
@ -0,0 +1,26 @@
|
||||
use std::convert::TryFrom;
|
||||
use std::os::raw::c_ulong;
|
||||
|
||||
use num_derive::{FromPrimitive, ToPrimitive};
|
||||
use num_traits::{FromPrimitive, ToPrimitive};
|
||||
|
||||
#[derive(Debug, FromPrimitive, ToPrimitive)]
|
||||
pub enum UserType {
|
||||
So = 0,
|
||||
User = 1,
|
||||
ContextSpecific = 2,
|
||||
}
|
||||
|
||||
impl TryFrom<c_ulong> for UserType {
|
||||
type Error = ();
|
||||
fn try_from(value: c_ulong) -> Result<Self, Self::Error> {
|
||||
UserType::from_u64(value).ok_or(())
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<UserType> for c_ulong {
|
||||
type Error = ();
|
||||
fn try_from(value: UserType) -> Result<Self, Self::Error> {
|
||||
UserType::to_u64(&value).ok_or(())
|
||||
}
|
||||
}
|
@ -1,52 +0,0 @@
|
||||
mod request;
|
||||
mod response;
|
||||
|
||||
use std::io::{Read, Write, Result};
|
||||
use byteorder::{BE, ReadBytesExt, WriteBytesExt};
|
||||
|
||||
use super::KeyStore;
|
||||
use super::key::Algorithm;
|
||||
use self::request::SignRequest;
|
||||
|
||||
/// Parses a request to sign some data, and returns a struct
|
||||
/// that represents this request. Returns None if the
|
||||
/// corresponding key was not found in the keystore.
|
||||
pub fn read_request<'a>(store: &'a KeyStore, stream: &mut Read) -> Result<Option<SignRequest<'a>>> {
|
||||
// total length and message type is already read by the main function
|
||||
// next up, blob length
|
||||
let blob_length = stream.read_u32::<BE>()?;
|
||||
let mut blob: Vec<u8> = Vec::new();
|
||||
blob.write_u32::<BE>(blob_length)?;
|
||||
stream.take(blob_length.into()).read_to_end(&mut blob)?;
|
||||
|
||||
// data to be signed
|
||||
let data_length = stream.read_u32::<BE>()?;
|
||||
let mut data: Vec<u8> = Vec::new();
|
||||
stream.take(data_length.into()).read_to_end(&mut data)?;
|
||||
|
||||
// finally, flags
|
||||
let flags = stream.read_u32::<BE>()?;
|
||||
|
||||
// while SSH agent protocol relies on blobs heavily
|
||||
// it is easier to work with key structs in our context
|
||||
if let Some(key) = store.get(blob.as_slice()) {
|
||||
Ok(Some(SignRequest::new(key, data, flags)))
|
||||
} else {
|
||||
// key not found
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
|
||||
/// Outputs a sign response given a key and a signature received from `termux-api`.
|
||||
pub fn write_response(request: &SignRequest, signature: &[u8], stream: &mut Write) -> Result<()> {
|
||||
let name = request.ssh_name(); // name to use in the header
|
||||
match &request.key().algorithm {
|
||||
Algorithm::Rsa => {
|
||||
response::write_rsa_response(name, signature, stream)
|
||||
},
|
||||
Algorithm::Ec(_) => {
|
||||
// curve is already in name
|
||||
response::write_ec_response(name, signature, stream)
|
||||
},
|
||||
}
|
||||
}
|
@ -1,61 +0,0 @@
|
||||
use ::key::{Key, Algorithm, Curve};
|
||||
|
||||
// defined in the specification document
|
||||
const SSH_AGENT_RSA_SHA2_256: u32 = 2;
|
||||
const SSH_AGENT_RSA_SHA2_512: u32 = 4;
|
||||
|
||||
/// Represents a request for signing send by a client.
|
||||
pub struct SignRequest<'a> {
|
||||
key: &'a Key,
|
||||
data: Vec<u8>,
|
||||
flags: u32,
|
||||
}
|
||||
|
||||
impl<'a> SignRequest<'a> {
|
||||
pub fn new(key: &Key, data: Vec<u8>, flags: u32) -> SignRequest {
|
||||
SignRequest { key, data, flags }
|
||||
}
|
||||
|
||||
pub fn key(&self) -> &Key {
|
||||
&self.key
|
||||
}
|
||||
|
||||
pub fn data(&self) -> &[u8] {
|
||||
&self.data
|
||||
}
|
||||
|
||||
/// Returns the tuple of keystore name and ssh name for this key.
|
||||
fn name(&self) -> (&'static str, &'static str) {
|
||||
match self.key.algorithm {
|
||||
Algorithm::Rsa => {
|
||||
// other implementations also have this order
|
||||
if self.flags & SSH_AGENT_RSA_SHA2_256 != 0 {
|
||||
("SHA256withRSA", "rsa-sha2-256")
|
||||
} else if self.flags & SSH_AGENT_RSA_SHA2_512 != 0 {
|
||||
("SHA512withRSA", "rsa-sha2-512")
|
||||
} else {
|
||||
("SHA1withRSA", "ssh-rsa")
|
||||
}
|
||||
},
|
||||
Algorithm::Ec(ref curve) => {
|
||||
match curve {
|
||||
Curve::P256 => ("SHA256withECDSA", "ecdsa-sha2-nistp256"),
|
||||
Curve::P384 => ("SHA386withECDSA", "ecdsa-sha2-nistp384"),
|
||||
Curve::P521 => ("SHA512withECDSA", "ecdsa-sha2-nistp521"),
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the name to be used when communicating with the
|
||||
/// Android keystore.
|
||||
pub fn keystore_name(&self) -> &'static str {
|
||||
self.name().0
|
||||
}
|
||||
|
||||
/// Returns the name to be used when communicating with an
|
||||
/// ssh-agent client.
|
||||
pub fn ssh_name(&self) -> &'static str {
|
||||
self.name().1
|
||||
}
|
||||
}
|
@ -1,74 +0,0 @@
|
||||
use std::io::{Write, Result};
|
||||
use byteorder::{BE, WriteBytesExt};
|
||||
|
||||
// defined in the specification document
|
||||
const SSH_AGENT_SIGN_RESPONSE: u8 = 14;
|
||||
|
||||
/// Write a RSA sign response to a given stream.
|
||||
/// Name should contain the hash algorithm used to sign the data
|
||||
/// (e.g. "rsa-sha2-512").
|
||||
pub fn write_rsa_response(name: &str, signature: &[u8], stream: &mut Write) -> Result<()> {
|
||||
// the RSA signature received from Android keystore only
|
||||
// contains the signature, no parsing is necessary
|
||||
|
||||
let length = signature.len() as u32;
|
||||
|
||||
// total length
|
||||
stream.write_u32::<BE>(length + 25)?;
|
||||
// message type
|
||||
stream.write_u8(SSH_AGENT_SIGN_RESPONSE)?;
|
||||
// size for the rest of the packet
|
||||
stream.write_u32::<BE>(length + 20)?;
|
||||
// signature type
|
||||
stream.write_u32::<BE>(12)?;
|
||||
stream.write_all(name.as_bytes())?;
|
||||
// signature
|
||||
stream.write_u32::<BE>(length)?;
|
||||
stream.write_all(&signature)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Write an EC sign response to a given stream.
|
||||
/// Name should contain the hash algorithm associate with
|
||||
/// the key size (e.g. "ecdsa-sha2-nistp256")
|
||||
pub fn write_ec_response(name: &str, signature: &[u8], stream: &mut Write) -> Result<()> {
|
||||
// the EC signature received from Android keystore is formatted
|
||||
// in ASN.1 DER format.
|
||||
// TODO: replace these crude calculations with a proper DER parser
|
||||
// first byte is always 0x30
|
||||
assert_eq!(0x30, signature[0]);
|
||||
// if the second byte is 0x81, we have a longer response (for P-521)
|
||||
let r_start = if signature[1] == 0x81 { 3 } else { 2 };
|
||||
// 0x02 means integer
|
||||
assert_eq!(0x02, signature[r_start]);
|
||||
// the next byte is the length of the integer
|
||||
let r_length = signature[r_start+1] as usize;
|
||||
// repeat for the other value
|
||||
let s_start = r_start+2+r_length;
|
||||
assert_eq!(0x02, signature[s_start]);
|
||||
let s_length = signature[s_start+1] as usize;
|
||||
|
||||
// acquire the values
|
||||
let r = &signature[r_start+2..s_start];
|
||||
let s = &signature[s_start+2..s_start+2+s_length];
|
||||
|
||||
let rs_length = (r_length + s_length) as u32;
|
||||
|
||||
// total packet size
|
||||
stream.write_u32::<BE>(rs_length + 40)?;
|
||||
// message type
|
||||
stream.write_u8(SSH_AGENT_SIGN_RESPONSE)?;
|
||||
// size for the rest of the packet
|
||||
stream.write_u32::<BE>(rs_length + 35)?;
|
||||
// signature type
|
||||
stream.write_u32::<BE>(19)?;
|
||||
stream.write_all(name.as_bytes())?;
|
||||
// total size of values
|
||||
stream.write_u32::<BE>(rs_length + 8)?;
|
||||
// values
|
||||
stream.write_u32::<BE>(r_length as u32)?;
|
||||
stream.write_all(r)?;
|
||||
stream.write_u32::<BE>(s_length as u32)?;
|
||||
stream.write_all(s)?;
|
||||
Ok(())
|
||||
}
|
122
src/startup.rs
122
src/startup.rs
@ -1,122 +0,0 @@
|
||||
use std::env;
|
||||
use std::fs;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::{Command, Stdio};
|
||||
use std::process;
|
||||
use rand::distributions::Alphanumeric;
|
||||
use rand::{thread_rng, Rng};
|
||||
use signal_hook;
|
||||
|
||||
/// Root folder for the created socket.
|
||||
/// A subfolder will be created inside this folder.
|
||||
const SOCKET_FOLDER: &str = "/data/data/com.termux/files/usr/tmp/";
|
||||
|
||||
/// Returns true if the application was started in
|
||||
/// the foreground mode.
|
||||
pub fn is_foreground() -> bool {
|
||||
env::args().any(|a| a == "-D")
|
||||
}
|
||||
|
||||
/// Get the socket path to use.
|
||||
/// If available, the path given with the "-a" parameter is used.
|
||||
/// Otherwise a new path is generated.
|
||||
pub fn get_socket() -> PathBuf {
|
||||
// check if a path is given in the command line
|
||||
let mut args = env::args();
|
||||
while let Some(arg) = args.next() {
|
||||
if arg == "-a" {
|
||||
let path = args.next().expect("-a argument requires a path");
|
||||
return PathBuf::from(path);
|
||||
}
|
||||
};
|
||||
|
||||
// generate a new path
|
||||
let rand_string: String = thread_rng()
|
||||
.sample_iter(&Alphanumeric)
|
||||
.take(12)
|
||||
.collect();
|
||||
|
||||
let mut path = PathBuf::from(SOCKET_FOLDER);
|
||||
path.push(format!("ssh-{}", rand_string));
|
||||
path.push(format!("agent.{}", process::id()));
|
||||
path
|
||||
}
|
||||
|
||||
/// Initializes the socket by creating the parent folder,
|
||||
/// and setting up triggers to cleanup the socket and the folder
|
||||
/// when the application exists.
|
||||
pub fn initialize_socket(socket: &Path) {
|
||||
// TODO: this function will fail with user-provided socket paths
|
||||
|
||||
socket.parent().and_then(|f| fs::create_dir(f).ok())
|
||||
.expect("Could not create the parent folder for the socket");
|
||||
|
||||
register_cleanup(signal_hook::SIGINT, socket);
|
||||
register_cleanup(signal_hook::SIGTERM, socket);
|
||||
}
|
||||
|
||||
/// Register a signal hook to remove the folder and the socket.
|
||||
fn register_cleanup(signal: i32, socket: &Path) {
|
||||
let socket = socket.to_owned();
|
||||
let folder = socket.parent().unwrap().to_owned();
|
||||
|
||||
unsafe {
|
||||
signal_hook::register(signal, move || {
|
||||
fs::remove_file(&socket).unwrap();
|
||||
fs::remove_dir(&folder).unwrap();
|
||||
process::exit(0);
|
||||
}).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the PID of this process.
|
||||
pub fn get_pid() -> u32 { process::id() }
|
||||
|
||||
/// Executes a child process, with the appropriate parameters
|
||||
/// passed so that the process reuses the same socket path,
|
||||
/// and runs in foreground mode. Returns None in case of an error.
|
||||
pub fn spawn_child(socket: &Path) -> Option<u32> {
|
||||
let socket = socket.to_str()?;
|
||||
let command = env::args().next()?;
|
||||
let child = Command::new(command)
|
||||
.args(&["-a", socket, "-D"])
|
||||
.stdin(Stdio::null())
|
||||
.stdout(Stdio::null())
|
||||
.spawn().ok()?;
|
||||
Some(child.id())
|
||||
}
|
||||
|
||||
/// Builds commands that should be executed in the user's shell
|
||||
/// so that the socket path and agent PID is easily accessible.
|
||||
/// If the "-c" is passed, c-shell style commands are generated,
|
||||
/// if not, bash commands are generated.
|
||||
pub fn create_shell_commands(socket: &Path, pid: u32) -> String {
|
||||
let socket = socket.to_str().expect("Socket path is invalid.");
|
||||
let c_style = env::args().any(|a| a == "-c");
|
||||
if c_style {
|
||||
format!("setenv SSH_AUTH_SOCK {};
|
||||
setenv SSH_AGENT_PID {};
|
||||
echo Agent pid {};", socket, pid, pid)
|
||||
} else {
|
||||
format!("SSH_AUTH_SOCK={}; export SSH_AUTH_SOCK;
|
||||
SSH_AGENT_PID={}; export SSH_AGENT_PID;
|
||||
echo Agent pid {};", socket, pid, pid)
|
||||
}
|
||||
}
|
||||
|
||||
/// Prints the short help documentation to the console if one of the
|
||||
/// arguments is "-h". Returns true if this was the case and the help
|
||||
/// was printed, false otherwise.
|
||||
pub fn print_help() -> bool {
|
||||
if env::args().any(|a| a == "-h") {
|
||||
println!("usage: tergent [-c] [-D] [-a bind_address]
|
||||
Options:
|
||||
-c Print C-shell style commands.
|
||||
-D Foreground mode, do not fork to background.
|
||||
-a Use the given socket address instead of a
|
||||
randomly generated one.");
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
79
src/state/mod.rs
Normal file
79
src/state/mod.rs
Normal file
@ -0,0 +1,79 @@
|
||||
//! Provides functionality to store the library state.
|
||||
|
||||
use crate::bridge;
|
||||
use crate::key::{self, Key};
|
||||
|
||||
mod store;
|
||||
pub use store::*;
|
||||
|
||||
/// Represents the state of the library. Each session should
|
||||
/// have a single state associated with it.
|
||||
pub struct State {
|
||||
keys: Vec<Key>,
|
||||
search_index: usize,
|
||||
search_for_keys: bool,
|
||||
search_id: Option<String>,
|
||||
sign_index: usize,
|
||||
}
|
||||
|
||||
impl State {
|
||||
/// Initializes the library state by fetching the keys from termux keystore.
|
||||
/// Returns `None` if this fetch has failed.
|
||||
fn from_bridge() -> Option<Self> {
|
||||
let json = bridge::list_keys().ok()?;
|
||||
let keys = key::json_to_list(json)?;
|
||||
Some(State {
|
||||
keys,
|
||||
search_index: 0,
|
||||
search_for_keys: false,
|
||||
search_id: None,
|
||||
sign_index: 0,
|
||||
})
|
||||
}
|
||||
|
||||
/// Initializes the search operation. `search_for_keys` indicates if the search
|
||||
/// is for public/private keys, false will mean it is searching for something else,
|
||||
/// such as certificates.
|
||||
/// The optional field `id` limits the search to the given label.
|
||||
pub fn find_init(&mut self, search_for_keys: bool, id: Option<String>) {
|
||||
self.search_index = 0;
|
||||
self.search_for_keys = search_for_keys;
|
||||
self.search_id = id;
|
||||
}
|
||||
|
||||
/// Continues a previously initiated search, returning the next key. Returns `None`
|
||||
/// if there are no more results left.
|
||||
pub fn find_next(&mut self) -> Option<usize> {
|
||||
let index = self
|
||||
.keys
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter(|&_| self.search_for_keys)
|
||||
.filter(|&k| match &self.search_id {
|
||||
Some(id) => k.1.label() == id,
|
||||
None => true,
|
||||
})
|
||||
.skip(self.search_index)
|
||||
.next()
|
||||
.map(|(i, &_)| i);
|
||||
if let Some(i) = index {
|
||||
self.search_index = i + 1;
|
||||
}
|
||||
index
|
||||
}
|
||||
|
||||
/// Fetches a key by its index.
|
||||
pub fn get_key(&self, index: usize) -> Option<&Key> {
|
||||
self.keys.get(index)
|
||||
}
|
||||
|
||||
/// Sets up the store so that it can be used to sign with the provided key later.
|
||||
pub fn sign_init(&mut self, index: usize) {
|
||||
self.sign_index = index;
|
||||
}
|
||||
|
||||
/// Fetches the signing key which was previously set by `sign_init`.
|
||||
pub fn get_sign_key(&self) -> Option<&Key> {
|
||||
self.keys.get(self.sign_index)
|
||||
}
|
||||
}
|
52
src/state/store.rs
Normal file
52
src/state/store.rs
Normal file
@ -0,0 +1,52 @@
|
||||
//! Holds a static state store. This static store is required as the PKCS#11
|
||||
//! interface does not let the libraries to pass around a pointer. Therefore the
|
||||
//! application cannot keep track of the state, the library need to do it instead.
|
||||
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use once_cell::sync::OnceCell;
|
||||
|
||||
use super::State;
|
||||
|
||||
/// The instance that holds all the states.
|
||||
static INSTANCE: OnceCell<Mutex<HashMap<u64, Arc<Mutex<State>>>>> = OnceCell::new();
|
||||
|
||||
/// Creates a new library state. Returns the index of the newly created state.
|
||||
/// Returns `None` if the initialization failed, for example
|
||||
/// if the termux keystore is not reachable.
|
||||
pub fn new() -> Option<u64> {
|
||||
let states = INSTANCE.get_or_init(|| Mutex::new(HashMap::new()));
|
||||
let mut states = states.lock().ok()?;
|
||||
let keys: HashSet<u64> = states.keys().copied().collect();
|
||||
let index = (0..u64::MAX).filter(|i| !&keys.contains(i)).next()?;
|
||||
let state = State::from_bridge()?;
|
||||
states.insert(index, Arc::new(Mutex::new(state)));
|
||||
Some(index)
|
||||
}
|
||||
|
||||
/// Returns the state associated with the given index.
|
||||
pub fn get(index: u64) -> Option<Arc<Mutex<State>>> {
|
||||
let states = INSTANCE.get_or_init(|| Mutex::new(HashMap::new()));
|
||||
let states = states.lock().ok()?;
|
||||
let state = states.get(&index)?;
|
||||
Some(Arc::clone(state))
|
||||
}
|
||||
|
||||
/// Removed the state associated with the index, allowing its resources
|
||||
/// to be freed.
|
||||
pub fn remove(index: u64) -> Option<Arc<Mutex<State>>> {
|
||||
let states = INSTANCE.get_or_init(|| Mutex::new(HashMap::new()));
|
||||
let mut states = states.lock().ok()?;
|
||||
states.remove(&index)
|
||||
}
|
||||
|
||||
/// Returns the current number of open states.
|
||||
pub fn count() -> usize {
|
||||
let states = INSTANCE.get_or_init(|| Mutex::new(HashMap::new()));
|
||||
let states = states.lock();
|
||||
match states {
|
||||
Ok(states) => states.len(),
|
||||
Err(_) => 0,
|
||||
}
|
||||
}
|
@ -1,64 +0,0 @@
|
||||
use std::io::{Write, Result};
|
||||
use byteorder::{BE, WriteBytesExt};
|
||||
|
||||
use ::key::Curve;
|
||||
|
||||
const EC_UNCOMPRESSED_POINT: u8 = 4;
|
||||
// compressed points are not supported
|
||||
|
||||
/// Create a RSA key blob with the given modulus.
|
||||
/// Note that the exponent is hardcoded as 65537 for now.
|
||||
pub fn from_rsa(modulus: Vec<u8>) -> Result<Vec<u8>> {
|
||||
let length = modulus.len() as u32;
|
||||
|
||||
let mut blob = Vec::new();
|
||||
// blob total size
|
||||
blob.write_u32::<BE>(length + 23)?;
|
||||
// header
|
||||
blob.write_u32::<BE>(7)?;
|
||||
blob.write_all("ssh-rsa".as_bytes())?;
|
||||
// exponent
|
||||
blob.write_u32::<BE>(3)?;
|
||||
blob.write_all(&[1, 0, 1])?;
|
||||
// modulus
|
||||
blob.write_u32::<BE>(length + 1)?;
|
||||
blob.write_u8(0)?; // modulus is positive (see https://crypto.stackexchange.com/q/30608)
|
||||
blob.write_all(&modulus)?;
|
||||
Ok(blob)
|
||||
}
|
||||
|
||||
/// Create an EC key blob with the given parameters.
|
||||
pub fn from_ec(curve: &Curve, x: Vec<u8>, y: Vec<u8>) -> Result<Vec<u8>> {
|
||||
// both parameters must have these lengths
|
||||
let xy_length = match curve {
|
||||
Curve::P256 => 32,
|
||||
Curve::P384 => 48,
|
||||
Curve::P521 => 66,
|
||||
};
|
||||
// will need to prepend with zeroes to make sure
|
||||
// the parameters have these sizes
|
||||
let x_padding = xy_length as usize - x.len();
|
||||
let y_padding = xy_length as usize - y.len();
|
||||
|
||||
// curve name, e.g. "nistp256"
|
||||
let curve = curve.name().as_bytes();
|
||||
|
||||
let mut blob = Vec::new();
|
||||
// blob total size
|
||||
blob.write_u32::<BE>(xy_length * 2 + 40)?;
|
||||
// header, algorithm name
|
||||
blob.write_u32::<BE>(19)?;
|
||||
blob.write_all("ecdsa-sha2-".as_bytes())?;
|
||||
blob.write_all(curve)?;
|
||||
// curve name
|
||||
blob.write_u32::<BE>(8)?;
|
||||
blob.write_all(curve)?;
|
||||
// parameters
|
||||
blob.write_u32::<BE>(xy_length * 2 + 1)?;
|
||||
blob.write_u8(EC_UNCOMPRESSED_POINT)?;
|
||||
for _ in 0..x_padding { blob.write_u8(0)?; };
|
||||
blob.write_all(&x)?;
|
||||
for _ in 0..y_padding { blob.write_u8(0)?; };
|
||||
blob.write_all(&y)?;
|
||||
Ok(blob)
|
||||
}
|
@ -1,72 +0,0 @@
|
||||
mod blob;
|
||||
|
||||
use hex;
|
||||
use serde_json;
|
||||
use serde_json::Value;
|
||||
|
||||
use super::KeyStore;
|
||||
use super::key;
|
||||
use super::key::{Key, Algorithm};
|
||||
|
||||
/// Removes all the keys from the store, and fills it back
|
||||
/// using the data contained in the JSON string.
|
||||
///
|
||||
/// The input should ideally come from `termux-api`.
|
||||
pub fn load_all(store: &mut KeyStore, json: String) {
|
||||
// expecting a well-formed JSON with an array at the root
|
||||
let keys = serde_json::from_str::<Value>(&json).ok()
|
||||
.and_then(|v| if let Value::Array(vec) = v { Some(vec) } else { None })
|
||||
.expect("Cannot read the JSON input.");
|
||||
|
||||
// panic if any of the objects inside the array is malformed
|
||||
let keys = keys.iter()
|
||||
.map(|k| parse_key(k).expect("Cannot read one of the keys."));
|
||||
|
||||
store.clear();
|
||||
store.extend(keys);
|
||||
}
|
||||
|
||||
/// Parse a single JSON object containing information about a key.
|
||||
fn parse_key(object: &Value) -> Option<(Vec<u8>, key::Key)> {
|
||||
let alias = object.get("alias")?.as_str()?;
|
||||
let algorithm = object.get("algorithm")?.as_str()?;
|
||||
let size = object.get("size")?.as_u64()?;
|
||||
|
||||
let key = Key {
|
||||
algorithm: Algorithm::parse(algorithm, size)?,
|
||||
alias: String::from(alias),
|
||||
};
|
||||
|
||||
let blob = match key.algorithm {
|
||||
Algorithm::Rsa => {
|
||||
let modulus = object.get("modulus")?.as_hex()?;
|
||||
blob::from_rsa(modulus)
|
||||
},
|
||||
Algorithm::Ec(ref curve) => {
|
||||
let x = object.get("x")?.as_hex()?;
|
||||
let y = object.get("y")?.as_hex()?;
|
||||
blob::from_ec(curve, x, y)
|
||||
},
|
||||
}.ok()?;
|
||||
|
||||
Some((blob, key))
|
||||
}
|
||||
|
||||
trait HexValue {
|
||||
fn as_hex(&self) -> Option<Vec<u8>>;
|
||||
}
|
||||
|
||||
/// Extend the JSON value struct to support parsing base16 integers.
|
||||
impl HexValue for Value {
|
||||
fn as_hex(&self) -> Option<Vec<u8>> {
|
||||
let value = self.as_str()?;
|
||||
|
||||
if value.len() % 2 == 1 {
|
||||
// hex module will fail if the number of letters is odd
|
||||
// prepend a zero to get the result without failing
|
||||
hex::decode(format!("0{}", value)).ok()
|
||||
} else {
|
||||
hex::decode(value).ok()
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user