From 6f1125516c365404c0b6e5949277c8b7b227ceac Mon Sep 17 00:00:00 2001 From: kpcyrd Date: Tue, 3 Mar 2020 16:34:06 +0100 Subject: [PATCH] Add libsodium support for decryption --- Cargo.lock | 175 +++++++++++++++++++++---------- Dockerfile | 4 +- ci/setup.sh | 2 +- contrib/docker/Dockerfile.alpine | 9 +- contrib/docker/Dockerfile.debian | 8 +- docs/build.rst | 10 +- docs/install.rst | 2 +- sn0int-std/Cargo.toml | 1 + sn0int-std/src/crypto.rs | 51 +++++++++ sn0int-std/src/lib.rs | 1 + src/engine/ctx.rs | 2 + src/runtime/crypto.rs | 30 ++++++ src/runtime/mod.rs | 1 + src/worker.rs | 6 +- 14 files changed, 227 insertions(+), 75 deletions(-) create mode 100644 sn0int-std/src/crypto.rs create mode 100644 src/runtime/crypto.rs diff --git a/Cargo.lock b/Cargo.lock index 6372fb58..3ad4755b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -561,10 +561,10 @@ dependencies = [ [[package]] name = "curl" -version = "0.4.25" +version = "0.4.26" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "curl-sys 0.4.26 (registry+https://github.com/rust-lang/crates.io-index)", + "curl-sys 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.67 (registry+https://github.com/rust-lang/crates.io-index)", "openssl-probe 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "openssl-sys 0.9.54 (registry+https://github.com/rust-lang/crates.io-index)", @@ -575,7 +575,7 @@ dependencies = [ [[package]] name = "curl-sys" -version = "0.4.26" +version = "0.4.27" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cc 1.0.50 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1454,6 +1454,17 @@ name = "libc" version = "0.2.67" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "libflate" +version = "0.1.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "adler32 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", + "crc32fast 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rle-decode-fast 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "take_mut 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "libloading" version = "0.5.2" @@ -1463,6 +1474,19 @@ dependencies = [ "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "libsodium-sys" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cc 1.0.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.67 (registry+https://github.com/rust-lang/crates.io-index)", + "libflate 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "pkg-config 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)", + "tar 0.4.26 (registry+https://github.com/rust-lang/crates.io-index)", + "vcpkg 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "libsqlite3-sys" version = "0.16.0" @@ -1647,7 +1671,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "mime_guess" -version = "2.0.1" +version = "2.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "mime 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1915,7 +1939,7 @@ version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "base64 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)", - "curl 0.4.25 (registry+https://github.com/rust-lang/crates.io-index)", + "curl 0.4.26 (registry+https://github.com/rust-lang/crates.io-index)", "failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "failure_derive 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2239,26 +2263,26 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "proc-macro-error" -version = "0.4.9" +version = "0.4.11" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro-error-attr 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro-error-attr 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", "proc-macro2 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)", "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "rustversion 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "syn 1.0.16 (registry+https://github.com/rust-lang/crates.io-index)", + "version_check 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "proc-macro-error-attr" -version = "0.4.9" +version = "0.4.11" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "proc-macro2 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)", "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "rustversion 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "syn 1.0.16 (registry+https://github.com/rust-lang/crates.io-index)", "syn-mid 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "version_check 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2533,13 +2557,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "aho-corasick 0.7.9 (registry+https://github.com/rust-lang/crates.io-index)", "memchr 2.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "regex-syntax 0.6.14 (registry+https://github.com/rust-lang/crates.io-index)", + "regex-syntax 0.6.15 (registry+https://github.com/rust-lang/crates.io-index)", "thread_local 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "regex-syntax" -version = "0.6.14" +version = "0.6.15" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -2567,7 +2591,7 @@ dependencies = [ "hyper-tls 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "mime 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", - "mime_guess 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "mime_guess 2.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "native-tls 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.48 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2606,9 +2630,14 @@ dependencies = [ "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "rle-decode-fast" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "rocket" -version = "0.4.2" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "atty 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2617,8 +2646,8 @@ dependencies = [ "memchr 2.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.12.0 (registry+https://github.com/rust-lang/crates.io-index)", "pear 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "rocket_codegen 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "rocket_http 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "rocket_codegen 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", + "rocket_http 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "state 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", "toml 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2628,27 +2657,28 @@ dependencies = [ [[package]] name = "rocket_codegen" -version = "0.4.2" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "devise 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "glob 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "indexmap 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)", - "rocket_http 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "rocket_http 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "version_check 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "yansi 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "rocket_contrib" -version = "0.4.2" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "glob 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "handlebars 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "notify 4.0.15 (registry+https://github.com/rust-lang/crates.io-index)", - "rocket 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "rocket 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.48 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2658,7 +2688,7 @@ name = "rocket_failure" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "rocket 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "rocket 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "rocket_failure_errors 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2676,7 +2706,7 @@ dependencies = [ [[package]] name = "rocket_http" -version = "0.4.2" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cookie 0.11.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2684,7 +2714,7 @@ dependencies = [ "indexmap 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "pear 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "smallvec 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "state 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2744,16 +2774,6 @@ dependencies = [ "webpki 0.21.2 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "rustversion" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "proc-macro2 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 1.0.16 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "rustyline" version = "5.0.6" @@ -3117,7 +3137,7 @@ dependencies = [ "sloppy-rfc4880 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "sn0int-common 0.10.0", "sn0int-std 0.17.1", - "structopt 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", + "structopt 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)", "strum 0.17.1 (registry+https://github.com/rust-lang/crates.io-index)", "strum_macros 0.17.1 (registry+https://github.com/rust-lang/crates.io-index)", "syscallz 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3157,8 +3177,8 @@ dependencies = [ "maplit 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "oauth2 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "reqwest 0.9.24 (registry+https://github.com/rust-lang/crates.io-index)", - "rocket 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "rocket_contrib 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "rocket 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", + "rocket_contrib 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "rocket_failure 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3204,12 +3224,13 @@ dependencies = [ "serde_derive 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.48 (registry+https://github.com/rust-lang/crates.io-index)", "serde_urlencoded 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", + "sodiumoxide 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", "tokio 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)", "tungstenite 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", "url 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "webpki 0.21.2 (registry+https://github.com/rust-lang/crates.io-index)", "webpki-roots 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)", - "x509-parser 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", + "x509-parser 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", "xml-rs 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -3224,6 +3245,16 @@ dependencies = [ "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "sodiumoxide" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.67 (registry+https://github.com/rust-lang/crates.io-index)", + "libsodium-sys 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "sourcefile" version = "0.1.4" @@ -3287,21 +3318,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "structopt" -version = "0.3.9" +version = "0.3.11" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "structopt-derive 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "structopt-derive 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "structopt-derive" -version = "0.4.2" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro-error 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro-error 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", "proc-macro2 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)", "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "syn 1.0.16 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3398,7 +3429,7 @@ dependencies = [ "lazycell 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "onig 5.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "plist 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "regex-syntax 0.6.14 (registry+https://github.com/rust-lang/crates.io-index)", + "regex-syntax 0.6.15 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.48 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3418,6 +3449,22 @@ dependencies = [ "strum_macros 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "take_mut" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "tar" +version = "0.4.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "filetime 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.67 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)", + "xattr 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "tempfile" version = "3.1.0" @@ -4167,7 +4214,7 @@ dependencies = [ [[package]] name = "x509-parser" -version = "0.6.2" +version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "base64 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -4178,6 +4225,14 @@ dependencies = [ "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "xattr" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.67 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "xml-rs" version = "0.8.0" @@ -4265,8 +4320,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum cssparser-macros 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "dfae75de57f2b2e85e8768c3ea840fd159c8f33e2b6522c7835b7abac81be16e" "checksum ct-logs 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4d3686f5fa27dbc1d76c751300376e167c5a43387f44bb451fd1c24776e49113" "checksum ctrlc 3.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "7a4ba686dff9fa4c1c9636ce1010b0cf98ceb421361b0bb3d6faeec43bd217a7" -"checksum curl 0.4.25 (registry+https://github.com/rust-lang/crates.io-index)" = "06aa71e9208a54def20792d877bc663d6aae0732b9852e612c4a933177c31283" -"checksum curl-sys 0.4.26 (registry+https://github.com/rust-lang/crates.io-index)" = "0853fe2a575bb381b1f173610372c7722d9fa9bc4056512ed99fe6a644c388c6" +"checksum curl 0.4.26 (registry+https://github.com/rust-lang/crates.io-index)" = "ecb534fed9060d04bccaa8b8e1e2d3d5a0d7a9ec6d9c667691c80a3c6b7d19ef" +"checksum curl-sys 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)" = "4e97059be9b77dbac729368208bb5430cf9baf4c050ae8782a28010136cd906d" "checksum data-encoding 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "11c0346158a19b3627234e15596f5e465c360fcdb97d817bcb255e0510f5a788" "checksum data-encoding-macro 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "de6489dde5128f5ab2f71f88f8807a237cecf08d96dc7ca4be64e0730dc7d961" "checksum data-encoding-macro-internal 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "8d2d6daefd5f1d4b74a891a5d2ab7dccba028d423107c074232a0c5dc0d40a9e" @@ -4363,7 +4418,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum lazycell 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b294d6fa9ee409a054354afc4352b0b9ef7ca222c69b8812cbea9e7d2bf3783f" "checksum lexical-core 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)" = "f86d66d380c9c5a685aaac7a11818bdfa1f733198dfd9ec09c70b762cd12ad6f" "checksum libc 0.2.67 (registry+https://github.com/rust-lang/crates.io-index)" = "eb147597cdf94ed43ab7a9038716637d2d1bf2bc571da995d0028dec06bd3018" +"checksum libflate 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)" = "d9135df43b1f5d0e333385cb6e7897ecd1a43d7d11b91ac003f4d2c2d2401fdd" "checksum libloading 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f2b111a074963af1d37a139918ac6d49ad1d0d5e47f72fd55388619691a7d753" +"checksum libsodium-sys 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "1c344ff12b90ef8fa1f0fffacd348c1fd041db331841fec9eab23fdb991f5e73" "checksum libsqlite3-sys 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5e5b95e89c330291768dc840238db7f9e204fd208511ab6319b56193a7f2ae25" "checksum libz-sys 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)" = "2eb5e43362e38e2bca2fd5f5134c4d4564a23a5c28e9b95411652021a8675ebe" "checksum line-wrap 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f30344350a2a51da54c1d53be93fade8a237e545dbcc4bdbe635413f2117cab9" @@ -4387,7 +4444,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum migrations_macros 1.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "719ef0bc7f531428764c9b70661c14abd50a7f3d21f355752d9985aa21251c9e" "checksum mime 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "ba626b8a6de5da682e1caa06bdb42a335aee5a84db8e5046a3e8ab17ba0a3ae0" "checksum mime 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)" = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" -"checksum mime_guess 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1a0ed03949aef72dbdf3116a383d7b38b4768e6f960528cd6a6044aa9ed68599" +"checksum mime_guess 2.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2684d4c2e97d99848d30b324b00c8fcc7e5c897b7cbb5819b09e7c90e8baf212" "checksum miniz_oxide 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "aa679ff6578b1cddee93d7e82e263b94a575e0bfced07284eb0c037c1d2416a5" "checksum mio 0.6.21 (registry+https://github.com/rust-lang/crates.io-index)" = "302dec22bcf6bae6dfb69c647187f4b4d0fb6f535521f7bc022430ce8e12008f" "checksum mio-extras 2.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "52403fe290012ce777c4626790c8951324a2b9e3316b3143779c72b029742f19" @@ -4449,8 +4506,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum ppv-lite86 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "74490b50b9fbe561ac330df47c08f3f33073d2d00c150f719147d7c54522fa1b" "checksum pq-sys 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "6ac25eee5a0582f45a67e837e350d784e7003bd29a5f460796772061ca49ffda" "checksum precomputed-hash 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" -"checksum proc-macro-error 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)" = "052b3c9af39c7e5e94245f820530487d19eb285faedcb40e0c3275132293f242" -"checksum proc-macro-error-attr 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)" = "d175bef481c7902e63e3165627123fff3502f06ac043d3ef42d08c1246da9253" +"checksum proc-macro-error 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)" = "e7959c6467d962050d639361f7703b2051c43036d03493c36f01d440fdd3138a" +"checksum proc-macro-error-attr 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)" = "e4002d9f55991d5e019fb940a90e1a95eb80c24e77cb2462dd4dc869604d543a" "checksum proc-macro-hack 0.5.11 (registry+https://github.com/rust-lang/crates.io-index)" = "ecd45702f76d6d3c75a80564378ae228a85f0b59d2f3ed43c91b4a69eb2ebfc5" "checksum proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)" = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759" "checksum proc-macro2 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)" = "6c09721c6781493a2a492a96b5a5bf19b65917fe6728884e7c44dd0c60ca3435" @@ -4481,24 +4538,24 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)" = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84" "checksum redox_users 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "09b23093265f8d200fa7b4c2c76297f47e681c655f6f1285a8780d6a022f7431" "checksum regex 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "322cf97724bea3ee221b78fe25ac9c46114ebb51747ad5babd51a2fc6a8235a8" -"checksum regex-syntax 0.6.14 (registry+https://github.com/rust-lang/crates.io-index)" = "b28dfe3fe9badec5dbf0a79a9cccad2cfc2ab5484bdb3e44cbd1ae8b3ba2be06" +"checksum regex-syntax 0.6.15 (registry+https://github.com/rust-lang/crates.io-index)" = "7246cd0a0a6ec2239a5405b2b16e3f404fa0dcc6d28f5f5b877bf80e33e0f294" "checksum remove_dir_all 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4a83fa3702a688b9359eccba92d153ac33fd2e8462f9e0e3fdf155239ea7792e" "checksum reqwest 0.9.24 (registry+https://github.com/rust-lang/crates.io-index)" = "f88643aea3c1343c804950d7bf983bd2067f5ab59db6d613a08e05572f2714ab" "checksum resolv-conf 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b263b4aa1b5de9ffc0054a2386f96992058bb6870aab516f8cdeb8a667d56dcb" "checksum ring 0.16.11 (registry+https://github.com/rust-lang/crates.io-index)" = "741ba1704ae21999c00942f9f5944f801e977f54302af346b596287599ad1862" -"checksum rocket 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "42c1e9deb3ef4fa430d307bfccd4231434b707ca1328fae339c43ad1201cc6f7" -"checksum rocket_codegen 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "79aa1366f9b2eccddc05971e17c5de7bb75a5431eb12c2b5c66545fd348647f4" -"checksum rocket_contrib 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e0fa5c1392135adc0f96a02ba150ac4c765e27c58dbfd32aa40678e948f6e56f" +"checksum rle-decode-fast 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cabe4fa914dec5870285fa7f71f602645da47c486e68486d2b4ceb4a343e90ac" +"checksum rocket 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0aa9ab5fad4a9b366ae884f5b5461e166fe8f94d23a561a91dfaab046c2f4fde" +"checksum rocket_codegen 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c56c540f73ae2291e8c1e4f9757f92fec7015c09fd90d7bb70349386a111602c" +"checksum rocket_contrib 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "66926894ef94396204c53885f54a1b0e94a88ce6c9478c2fd403261fc0efb523" "checksum rocket_failure 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b62e0d82ae96e59ec6af6cf3dbfc6fcb71adcfbb10188909338dfeed1fe3ab50" "checksum rocket_failure_errors 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7b125cdd87ffc0c5e453153bee0224aade4c13e57dc2d2663d077d42bd0060e2" -"checksum rocket_http 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b1391457ee4e80b40d4b57fa5765c0f2836b20d73bcbee4e3f35d93cf3b80817" +"checksum rocket_http 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "968a07cbfa9f8c8a0239aba359b80e1281e85da9415795c68f3ddeb5e1d636d6" "checksum rstar 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "120bfe4837befb82c5a637a5a8c490a27d25524ac19fffec5b4e555ca6e36ee8" "checksum rust-argon2 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2bc8af4bda8e1ff4932523b94d3dd20ee30a87232323eda55903ffd71d2fb017" "checksum rustc-demangle 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783" "checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" "checksum rusticata-macros 2.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "93cca5a839ae468017da70a202f294e3deeda9e7d98f21b83fc5d23e5163b9df" "checksum rustls 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b25a18b1bf7387f0145e7f8324e700805aade3842dd3db2e74e4cdeb4677c09e" -"checksum rustversion 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b3bba175698996010c4f6dce5e7f173b6eb781fce25d2cfc45e27091ce0b79f6" "checksum rustyline 5.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "a23cb19702a8d6afb6edb3c842386e680d4883760e0df74e6848e23c2a87a635" "checksum rustyline 6.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "de64be8eecbe428b6924f1d8430369a01719fbb182c26fa431ddbb0a95f5315d" "checksum ryu 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "bfa8506c1de11c9c4e4c38863ccbe02a305c8188e85a05a784c9e11e1c3910c8" @@ -4535,6 +4592,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum smallvec 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)" = "f7b0758c52e15a8b5e3691eae6cc559f08eee9406e548a4477ba4e67770a82b6" "checksum smallvec 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5c2fb2ec9bcd216a5b0d0ccf31ab17b5ed1d627960edff65bbe95d3ce221cefc" "checksum socket2 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)" = "e8b74de517221a2cb01a53349cf54182acdc31a074727d3079068448c0676d85" +"checksum sodiumoxide 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "585232e78a4fc18133eef9946d3080befdf68b906c51b621531c37e91787fa2b" "checksum sourcefile 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "4bf77cb82ba8453b42b6ae1d692e4cdc92f9a47beaf89a847c8be83f4e328ad3" "checksum spin 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" "checksum stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8" @@ -4544,8 +4602,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum string_cache 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2940c75beb4e3bf3a494cef919a747a2cb81e52571e212bfbd185074add7208a" "checksum string_cache_codegen 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f24c8e5e19d22a726626f1a5e16fe15b132dcf21d10177fa5a45ce7962996b97" "checksum strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" -"checksum structopt 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "a1bcbed7d48956fcbb5d80c6b95aedb553513de0a1b451ea92679d999c010e98" -"checksum structopt-derive 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "095064aa1f5b94d14e635d0a5684cf140c43ae40a0fd990708d38f5d669e5f64" +"checksum structopt 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)" = "3fe43617218c0805c6eb37160119dc3c548110a67786da7218d1c6555212f073" +"checksum structopt-derive 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "c6e79c80e0f4efd86ca960218d4e056249be189ff1c42824dcd9a7f51a56f0bd" "checksum strum 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e5d1c33039533f051704951680f1adfd468fd37ac46816ded0d9ee068e60f05f" "checksum strum 0.17.1 (registry+https://github.com/rust-lang/crates.io-index)" = "530efb820d53b712f4e347916c5e7ed20deb76a4f0457943b3182fb889b06d2c" "checksum strum_macros 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)" = "47cd23f5c7dee395a00fa20135e2ec0fffcdfa151c56182966d7a3261343432e" @@ -4557,6 +4615,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum synstructure 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)" = "67656ea1dc1b41b1451851562ea232ec2e5a80242139f7e679ceccfb5d61f545" "checksum syntect 3.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "955e9da2455eea5635f7032fc3a229908e6af18c39600313866095e07db0d8b8" "checksum syscallz 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b89a416fe1f08442e7f7d01b3e30066344cf1806f07b99c5d33d3a60cd39e462" +"checksum take_mut 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f764005d11ee5f36500a149ace24e00e3da98b0158b3e2d53a7495660d3f4d60" +"checksum tar 0.4.26 (registry+https://github.com/rust-lang/crates.io-index)" = "b3196bfbffbba3e57481b6ea32249fbaf590396a52505a2615adbb79d9d826d3" "checksum tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9" "checksum tendril 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "707feda9f2582d5d680d733e38755547a3e8fb471e7ba11452ecfd9ce93a5d3b" "checksum termcolor 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb6bfa289a4d7c5766392812c0a1f4c1ba45afa1ad47803c11e1f407d846d75f" @@ -4639,7 +4699,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum winreg 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b2986deb581c4fe11b621998a5e53361efe6b48a151178d0cd9eeffa4dc6acc9" "checksum winutil 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7daf138b6b14196e3830a588acf1e86966c694d3e8fb026fb105b8b5dca07e6e" "checksum ws2_32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e" -"checksum x509-parser 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d135598be19a02522206c7243bbd25bff4c0872503e55e10619908f3ec67a9d9" +"checksum x509-parser 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)" = "c7215d1279267f57b059e5fc3814883d983a6d9c2fbc6f3c80562877509e327c" +"checksum xattr 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "244c3741f4240ef46274860397c7c74e50eb23624996930e484c16679633a54c" "checksum xml-rs 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "541b12c998c5b56aa2b4e6f18f03664eef9a4fd0a246a55594efae6cc2d964b5" "checksum yaml-rust 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "65923dd1784f44da1d2c3dbbc5e822045628c590ba72123e1c73d3c230c4434d" "checksum yansi 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d60c3b48c9cdec42fb06b3b84b5b087405e1fa1c644a1af3930e4dfafe93de48" diff --git a/Dockerfile b/Dockerfile index 38dddeb3..00f19f46 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ FROM rust:buster -RUN apt-get update -q && apt-get install -yq libsqlite3-dev libseccomp-dev \ +RUN apt-get update -q && apt-get install -yq libsqlite3-dev libseccomp-dev libsodium-dev \ && rm -rf /var/lib/apt/lists/* WORKDIR /usr/src/sn0int COPY . . @@ -7,7 +7,7 @@ RUN cargo build --release --verbose RUN strip target/release/sn0int FROM debian:buster -RUN apt-get update -q && apt-get install -yq libsqlite3-dev libseccomp-dev \ +RUN apt-get update -q && apt-get install -yq libsqlite3-dev libseccomp-dev libsodium-dev \ && rm -rf /var/lib/apt/lists/* COPY --from=0 /usr/src/sn0int/target/release/sn0int /usr/local/bin/sn0int VOLUME ["/data", "/cache"] diff --git a/ci/setup.sh b/ci/setup.sh index 88a92429..bb14c366 100755 --- a/ci/setup.sh +++ b/ci/setup.sh @@ -3,6 +3,6 @@ set -exu case "$1" in linux) sudo apt update - sudo apt install libsqlite3-dev libseccomp-dev + sudo apt install libsqlite3-dev libseccomp-dev libsodium-dev ;; esac diff --git a/contrib/docker/Dockerfile.alpine b/contrib/docker/Dockerfile.alpine index ad95a54f..29bcdcef 100644 --- a/contrib/docker/Dockerfile.alpine +++ b/contrib/docker/Dockerfile.alpine @@ -1,13 +1,14 @@ -FROM alpine:edge -RUN apk add --no-cache sqlite-dev libseccomp-dev +FROM rust:alpine3.11 +ENV RUSTFLAGS="-C target-feature=-crt-static" +RUN apk add --no-cache sqlite-dev libseccomp-dev libsodium-dev RUN apk add --no-cache --virtual .build-rust rust cargo WORKDIR /usr/src/sn0int COPY . . RUN cargo build --release --verbose RUN strip target/release/sn0int -FROM alpine:edge -RUN apk add --no-cache libgcc sqlite-libs libseccomp +FROM alpine:3.11 +RUN apk add --no-cache libgcc sqlite-libs libseccomp libsodium COPY --from=0 /usr/src/sn0int/target/release/sn0int /usr/local/bin/sn0int VOLUME ["/data", "/cache"] ENV XDG_DATA_HOME=/data \ diff --git a/contrib/docker/Dockerfile.debian b/contrib/docker/Dockerfile.debian index f06cc234..00f19f46 100644 --- a/contrib/docker/Dockerfile.debian +++ b/contrib/docker/Dockerfile.debian @@ -1,13 +1,13 @@ -FROM rust -RUN apt-get update -q && apt-get install -yq libsqlite3-dev libseccomp-dev \ +FROM rust:buster +RUN apt-get update -q && apt-get install -yq libsqlite3-dev libseccomp-dev libsodium-dev \ && rm -rf /var/lib/apt/lists/* WORKDIR /usr/src/sn0int COPY . . RUN cargo build --release --verbose RUN strip target/release/sn0int -FROM debian -RUN apt-get update -q && apt-get install -yq libsqlite3-dev libseccomp-dev \ +FROM debian:buster +RUN apt-get update -q && apt-get install -yq libsqlite3-dev libseccomp-dev libsodium-dev \ && rm -rf /var/lib/apt/lists/* COPY --from=0 /usr/src/sn0int/target/release/sn0int /usr/local/bin/sn0int VOLUME ["/data", "/cache"] diff --git a/docs/build.rst b/docs/build.rst index 18ccd49c..90727ff8 100644 --- a/docs/build.rst +++ b/docs/build.rst @@ -18,7 +18,7 @@ Archlinux .. code-block:: bash - $ pacman -S geoip2-database libseccomp publicsuffix-list sqlite + $ pacman -S geoip2-database libseccomp libsodium publicsuffix-list sqlite Mac OSX ~~~~~~~ @@ -30,7 +30,7 @@ Debian/Ubuntu/Kali .. code-block:: bash - $ apt install build-essential libsqlite3-dev libseccomp-dev publicsuffix + $ apt install build-essential libsqlite3-dev libseccomp-dev libsodium-dev publicsuffix .. warning:: On a debian based system make sure you've installed rust with rustup. @@ -40,21 +40,21 @@ Alpine .. code-block:: bash - $ apk add sqlite-dev libseccomp-dev + $ apk add sqlite-dev libseccomp-dev libsodium-dev OpenBSD ~~~~~~~ .. code-block:: bash - $ pkg_add sqlite3 geolite2-city geolite2-asn + $ pkg_add sqlite3 geolite2-city geolite2-asn libsodium Gentoo ~~~~~~ .. code-block:: bash - emerge --ask sys-libs/libseccomp dev-db/sqlite + emerge --ask sys-libs/libseccomp dev-db/sqlite dev-libs/libsodium Windows ~~~~~~~ diff --git a/docs/install.rst b/docs/install.rst index e146a125..9e1830f6 100644 --- a/docs/install.rst +++ b/docs/install.rst @@ -32,7 +32,7 @@ at the docker image as an alternative. .. code-block:: bash - $ apt install build-essential libsqlite3-dev libseccomp-dev publicsuffix + $ apt install build-essential libsqlite3-dev libseccomp-dev libsodium-dev publicsuffix $ git clone https://github.com/kpcyrd/sn0int.git $ cd sn0int $ cargo install -f --path . diff --git a/sn0int-std/Cargo.toml b/sn0int-std/Cargo.toml index c375fe6f..a90d9866 100644 --- a/sn0int-std/Cargo.toml +++ b/sn0int-std/Cargo.toml @@ -41,6 +41,7 @@ bytes = "0.4" base64 = "0.11" chrono = { version = "0.4", features = ["serde"] } mqtt-protocol = "0.8.1" +sodiumoxide = { version="0.2.5", features=["use-pkg-config"] } image = "0.23.0" kamadak-exif = "0.5.1" diff --git a/sn0int-std/src/crypto.rs b/sn0int-std/src/crypto.rs new file mode 100644 index 00000000..47bb553c --- /dev/null +++ b/sn0int-std/src/crypto.rs @@ -0,0 +1,51 @@ +use crate::errors::*; +use sodiumoxide::crypto::secretbox::{self, Key, Nonce}; +use std::iter; + +pub fn key_trunc_pad(mut key: &[u8], len: usize, pad: u8) -> Vec { + if key.len() > len { + key = &key[..len]; + } + + let mut key = key.to_vec(); + key.extend(iter::repeat(pad).take(len - key.len())); + key +} + +pub fn sodium_secretbox_open(encrypted: &[u8], key: &[u8]) -> Result> { + if encrypted.len() <= secretbox::NONCEBYTES { + bail!("Encrypted message is too short"); + } + + let key = Key::from_slice(key) + .ok_or_else(|| format_err!("Key has wrong length"))?; + let nonce = Nonce::from_slice(&encrypted[..secretbox::NONCEBYTES]) + .ok_or_else(|| format_err!("Nonce has wrong length"))?; + let ciphertext = &encrypted[secretbox::NONCEBYTES..]; + let plain = secretbox::open(&ciphertext, &nonce, &key) + .map_err(|_| format_err!("Failed to decrypt secretbox"))?; + Ok(plain) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_key_equal() { + let key = key_trunc_pad(&[1, 2, 3, 4, 5], 5, 0); + assert_eq!(key, &[1, 2, 3, 4, 5]); + } + + #[test] + fn test_key_trunc() { + let key = key_trunc_pad(&[1, 2, 3, 4, 5, 6, 7, 8, 9], 5, 0); + assert_eq!(key, &[1, 2, 3, 4, 5]); + } + + #[test] + fn test_key_pad() { + let key = key_trunc_pad(&[1, 2, 3], 5, 0); + assert_eq!(key, &[1, 2, 3, 0, 0]); + } +} diff --git a/sn0int-std/src/lib.rs b/sn0int-std/src/lib.rs index fef9ef86..4d13ed86 100644 --- a/sn0int-std/src/lib.rs +++ b/sn0int-std/src/lib.rs @@ -3,6 +3,7 @@ use hlua_badtouch as hlua; pub mod blobs; pub mod crt; +pub mod crypto; mod errors; pub mod engine; pub mod geo; diff --git a/src/engine/ctx.rs b/src/engine/ctx.rs index 60c7246b..47dd1a2e 100644 --- a/src/engine/ctx.rs +++ b/src/engine/ctx.rs @@ -524,6 +524,7 @@ pub fn ctx<'a>(env: Environment, logger: Arc>>) -> (hlua runtime::json_decode(&mut lua, state.clone()); runtime::json_decode_stream(&mut lua, state.clone()); runtime::json_encode(&mut lua, state.clone()); + runtime::key_trunc_pad(&mut lua, state.clone()); runtime::keyring(&mut lua, state.clone()); runtime::last_err(&mut lua, state.clone()); runtime::md5(&mut lua, state.clone()); @@ -564,6 +565,7 @@ pub fn ctx<'a>(env: Environment, logger: Arc>>) -> (hlua runtime::sock_recvuntil(&mut lua, state.clone()); runtime::sock_sendafter(&mut lua, state.clone()); runtime::sock_newline(&mut lua, state.clone()); + runtime::sodium_secretbox_open(&mut lua, state.clone()); runtime::status(&mut lua, state.clone()); runtime::stdin_read_line(&mut lua, state.clone()); runtime::stdin_read_to_end(&mut lua, state.clone()); diff --git a/src/runtime/crypto.rs b/src/runtime/crypto.rs new file mode 100644 index 00000000..912321e7 --- /dev/null +++ b/src/runtime/crypto.rs @@ -0,0 +1,30 @@ +use crate::errors::*; + +use crate::engine::ctx::State; +use crate::engine::structs::{byte_array, lua_bytes}; +use crate::hlua::{self, AnyLuaValue}; +use sn0int_std::crypto; +use std::sync::Arc; + +pub fn key_trunc_pad(lua: &mut hlua::Lua, state: Arc) { + lua.set("key_trunc_pad", hlua::function3(move |bytes: AnyLuaValue, len: u32, pad: u8| -> Result { + let bytes = byte_array(bytes) + .map_err(|err| state.set_error(err))?; + let bytes = crypto::key_trunc_pad(&bytes, len as usize, pad); + Ok(lua_bytes(&bytes)) + })) +} + +pub fn sodium_secretbox_open(lua: &mut hlua::Lua, state: Arc) { + lua.set("sodium_secretbox_open", hlua::function2(move |encrypted: AnyLuaValue, key: AnyLuaValue| -> Result { + let encrypted = byte_array(encrypted) + .map_err(|err| state.set_error(err))?; + let key = byte_array(key) + .map_err(|err| state.set_error(err))?; + + let plain = crypto::sodium_secretbox_open(&encrypted, &key) + .map_err(|err| state.set_error(err))?; + + Ok(lua_bytes(&plain)) + })) +} diff --git a/src/runtime/mod.rs b/src/runtime/mod.rs index 46effeba..9ac4db68 100644 --- a/src/runtime/mod.rs +++ b/src/runtime/mod.rs @@ -6,6 +6,7 @@ macro_rules! import_fns { } import_fns!(blobs); +import_fns!(crypto); import_fns!(datetime); import_fns!(db); import_fns!(dns); diff --git a/src/worker.rs b/src/worker.rs index 81630b5a..0edb9f28 100644 --- a/src/worker.rs +++ b/src/worker.rs @@ -244,7 +244,11 @@ impl DatabaseEvent { log.push_str(&format!("@ {}", object.time)); if let (Some(ref lat), Some(ref lon)) = (object.latitude, object.longitude) { - log.push_str(&format!(" ({}, {})", lat, lon)); + log.push_str(&format!(" ({}, {}", lat, lon)); + if let Some(radius) = &object.radius { + log.push_str(&format!(" | {}m", radius)); + } + log.push_str(")"); } if verbose > 0 {