diff --git a/Cargo.lock b/Cargo.lock index ecb6599..5d07843 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3,16 +3,20 @@ version = 3 [[package]] -name = "autocfg" -version = "1.1.0" +name = "aead" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +checksum = "d122413f284cf2d62fb1b7db97e02edb8cda96d769b16e443a4f6195e35662b0" +dependencies = [ + "crypto-common", + "generic-array", +] [[package]] -name = "base16ct" -version = "0.2.0" +name = "autocfg" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "base64ct" @@ -20,6 +24,12 @@ version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + [[package]] name = "block-buffer" version = "0.10.4" @@ -30,10 +40,10 @@ dependencies = [ ] [[package]] -name = "byteorder" -version = "1.4.3" +name = "bytes" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" +checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" [[package]] name = "cfg-if" @@ -41,6 +51,41 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "chacha20" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3613f74bd2eac03dad61bd53dbe620703d4371614fe0bc3b9f04dd36fe4e818" +dependencies = [ + "cfg-if", + "cipher", + "cpufeatures", +] + +[[package]] +name = "chacha20poly1305" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10cd79432192d1c0f4e1a0fef9527696cc039165d729fb41b3f4f4f354c2dc35" +dependencies = [ + "aead", + "chacha20", + "cipher", + "poly1305", + "zeroize", +] + +[[package]] +name = "cipher" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad" +dependencies = [ + "crypto-common", + "inout", + "zeroize", +] + [[package]] name = "const-oid" version = "0.9.2" @@ -63,28 +108,45 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" dependencies = [ "generic-array", + "rand_core", "typenum", ] [[package]] -name = "der" -version = "0.6.1" +name = "curve25519-dalek" +version = "4.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1a467a65c5e759bce6e65eaf91cc29f466cdc57cb65777bd646872a8a1fd4de" +checksum = "e89b8c6a2e4b1f45971ad09761aafb85514a84744b67a95e32c3cc1352d1f65c" dependencies = [ - "const-oid", - "pem-rfc7468 0.6.0", + "cfg-if", + "cpufeatures", + "curve25519-dalek-derive", + "digest", + "fiat-crypto", + "platforms", + "rustc_version", + "subtle", "zeroize", ] +[[package]] +name = "curve25519-dalek-derive" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "der" -version = "0.7.6" +version = "0.7.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56acb310e15652100da43d130af8d97b509e95af61aab1c5a7939ef24337ee17" +checksum = "fffa369a668c8af7dbf8b5e56c9f744fbd399949ed171606040001947de40b1c" dependencies = [ "const-oid", - "pem-rfc7468 0.7.0", "zeroize", ] @@ -95,10 +157,40 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8168378f4e5023e7218c89c891c0fd8ecdb5e5e4f18cb78f38cf245dd021e76f" dependencies = [ "block-buffer", - "const-oid", "crypto-common", ] +[[package]] +name = "ed25519" +version = "2.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "115531babc129696a58c64a4fef0a8bf9e9698629fb97e9e40767d235cfbcd53" +dependencies = [ + "pkcs8", + "signature", +] + +[[package]] +name = "ed25519-dalek" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f628eaec48bfd21b865dc2950cfa014450c01d2fa2b69a86c2fd5844ec523c0" +dependencies = [ + "curve25519-dalek", + "ed25519", + "rand_core", + "serde", + "sha2", + "subtle", + "zeroize", +] + +[[package]] +name = "fiat-crypto" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "27573eac26f4dd11e2b1916c3fe1baa56407c83c71a773a8ba17ec0bca03b6b7" + [[package]] name = "generic-array" version = "0.14.7" @@ -121,12 +213,18 @@ dependencies = [ ] [[package]] -name = "lazy_static" -version = "1.4.0" +name = "hermit-abi" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +checksum = "5d3d0e0f38255e7fa3cf31335b3a56f05febd18025f4db5ef7a0cfb4f8da651f" + +[[package]] +name = "inout" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0c10553d664a4d0bcff9f4215d0aac67a639cc68ef660840afe309b807bc9f5" dependencies = [ - "spin", + "generic-array", ] [[package]] @@ -136,10 +234,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3304a64d199bb964be99741b7a14d26972741915b3649639149b2479bb46f4b5" [[package]] -name = "libm" -version = "0.2.6" +name = "lock_api" +version = "0.4.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "348108ab3fba42ec82ff6e9564fc4ca0247bdccdc68dd8af9764bbc79c3c8ffb" +checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" +dependencies = [ + "autocfg", + "scopeguard", +] [[package]] name = "loki-client" @@ -156,7 +258,7 @@ version = "0.1.0" dependencies = [ "loki-shared", "protolok", - "rsa 0.9.2", + "tokio", ] [[package]] @@ -168,112 +270,86 @@ name = "lokui" version = "0.1.0" [[package]] -name = "num-bigint-dig" -version = "0.8.2" +name = "mio" +version = "0.8.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2399c9463abc5f909349d8aa9ba080e0b88b3ce2885389b60b993f39b1a56905" +checksum = "927a765cd3fc26206e66b296465fa9d3e5ab003e651c1b3c060e7956d96b19d2" dependencies = [ - "byteorder", - "lazy_static", - "libm", - "num-integer", - "num-iter", - "num-traits", - "rand", - "smallvec", - "zeroize", -] - -[[package]] -name = "num-integer" -version = "0.1.45" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" -dependencies = [ - "autocfg", - "num-traits", + "libc", + "wasi", + "windows-sys", ] [[package]] -name = "num-iter" -version = "0.1.43" +name = "num_cpus" +version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d03e6c028c5dc5cac6e2dec0efda81fc887605bb3d884578bb6d6bf7514e252" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" dependencies = [ - "autocfg", - "num-integer", - "num-traits", + "hermit-abi", + "libc", ] [[package]] -name = "num-traits" -version = "0.2.15" +name = "opaque-debug" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" -dependencies = [ - "autocfg", - "libm", -] +checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" [[package]] -name = "pem-rfc7468" -version = "0.6.0" +name = "parking_lot" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24d159833a9105500e0398934e205e0773f0b27529557134ecfc51c27646adac" +checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" dependencies = [ - "base64ct", + "lock_api", + "parking_lot_core", ] [[package]] -name = "pem-rfc7468" -version = "0.7.0" +name = "parking_lot_core" +version = "0.9.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88b39c9bfcfc231068454382784bb460aae594343fb030d46e9f50a645418412" +checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e" dependencies = [ - "base64ct", + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets", ] [[package]] -name = "pkcs1" -version = "0.4.1" +name = "pin-project-lite" +version = "0.2.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eff33bdbdfc54cc98a2eca766ebdec3e1b8fb7387523d5c9c9a2891da856f719" -dependencies = [ - "der 0.6.1", - "pkcs8 0.9.0", - "spki 0.6.0", - "zeroize", -] +checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" [[package]] -name = "pkcs1" -version = "0.7.5" +name = "pkcs8" +version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8ffb9f10fa047879315e6625af03c164b16962a5368d724ed16323b68ace47f" +checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" dependencies = [ - "der 0.7.6", - "pkcs8 0.10.2", - "spki 0.7.2", + "der", + "spki", ] [[package]] -name = "pkcs8" -version = "0.9.0" +name = "platforms" +version = "3.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9eca2c590a5f85da82668fa685c09ce2888b9430e83299debf1f34b65fd4a4ba" -dependencies = [ - "der 0.6.1", - "spki 0.6.0", -] +checksum = "626dec3cac7cc0e1577a2ec3fc496277ec2baa084bebad95bb6fdbfae235f84c" [[package]] -name = "pkcs8" -version = "0.10.2" +name = "poly1305" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" +checksum = "8159bd90725d2df49889a078b54f4f79e87f1f8a8444194cdca81d38f5393abf" dependencies = [ - "der 0.7.6", - "spki 0.7.2", + "cpufeatures", + "opaque-debug", + "universal-hash", ] [[package]] @@ -282,14 +358,33 @@ version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" +[[package]] +name = "proc-macro2" +version = "1.0.78" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" +dependencies = [ + "unicode-ident", +] + [[package]] name = "protolok" version = "0.1.0" dependencies = [ - "base16ct", + "chacha20poly1305", + "ed25519-dalek", "rand", - "rsa 0.8.2", "sha2", + "x25519-dalek", +] + +[[package]] +name = "quote" +version = "1.0.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +dependencies = [ + "proc-macro2", ] [[package]] @@ -323,45 +418,53 @@ dependencies = [ ] [[package]] -name = "rsa" -version = "0.8.2" +name = "redox_syscall" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55a77d189da1fee555ad95b7e50e7457d91c0e089ec68ca69ad2989413bbdab4" +checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" dependencies = [ - "byteorder", - "digest", - "num-bigint-dig", - "num-integer", - "num-iter", - "num-traits", - "pkcs1 0.4.1", - "pkcs8 0.9.0", - "rand_core", - "signature", - "subtle", - "zeroize", + "bitflags", ] [[package]] -name = "rsa" -version = "0.9.2" +name = "rustc_version" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ab43bb47d23c1a631b4b680199a45255dce26fa9ab2fa902581f624ff13e6a8" +checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" dependencies = [ - "byteorder", - "const-oid", - "digest", - "num-bigint-dig", - "num-integer", - "num-iter", - "num-traits", - "pkcs1 0.7.5", - "pkcs8 0.10.2", - "rand_core", - "signature", - "spki 0.7.2", - "subtle", - "zeroize", + "semver", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "semver" +version = "1.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b97ed7a9823b74f99c7742f5336af7be5ecd3eeafcb1507d1fa93347b1d589b0" + +[[package]] +name = "serde" +version = "1.0.196" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "870026e60fa08c69f064aa766c10f10b1d62db9ccd4d0abb206472bee0ce3b32" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.196" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33c85360c95e7d137454dc81d9a4ed2b8efd8fbe19cee57357b32b9771fccb67" +dependencies = [ + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -376,45 +479,44 @@ dependencies = [ ] [[package]] -name = "signature" -version = "2.1.0" +name = "signal-hook-registry" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e1788eed21689f9cf370582dfc467ef36ed9c707f073528ddafa8d83e3b8500" +checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1" dependencies = [ - "digest", - "rand_core", + "libc", ] [[package]] -name = "smallvec" -version = "1.10.0" +name = "signature" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" +checksum = "5e1788eed21689f9cf370582dfc467ef36ed9c707f073528ddafa8d83e3b8500" [[package]] -name = "spin" -version = "0.5.2" +name = "smallvec" +version = "1.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" +checksum = "e6ecd384b10a64542d77071bd64bd7b231f4ed5940fba55e98c3de13824cf3d7" [[package]] -name = "spki" -version = "0.6.0" +name = "socket2" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67cf02bbac7a337dc36e4f5a693db6c21e7863f45070f7064577eb4367a3212b" +checksum = "64a4a911eed85daf18834cfaa86a79b7d266ff93ff5ba14005426219480ed662" dependencies = [ - "base64ct", - "der 0.6.1", + "libc", + "winapi", ] [[package]] name = "spki" -version = "0.7.2" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d1e996ef02c474957d681f1b05213dfb0abab947b446a62d37770b23500184a" +checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" dependencies = [ "base64ct", - "der 0.7.6", + "der", ] [[package]] @@ -423,12 +525,69 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" +[[package]] +name = "syn" +version = "2.0.48" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tokio" +version = "1.28.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94d7b1cfd2aa4011f2de74c2c4c63665e27a71006b0a192dcd2710272e73dfa2" +dependencies = [ + "autocfg", + "bytes", + "libc", + "mio", + "num_cpus", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "windows-sys", +] + +[[package]] +name = "tokio-macros" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "typenum" version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "universal-hash" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc1de2c688dc15305988b563c3854064043356019f97a4b46276fe734c4f07ea" +dependencies = [ + "crypto-common", + "subtle", +] + [[package]] name = "version_check" version = "0.9.4" @@ -441,8 +600,122 @@ version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +[[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" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "x25519-dalek" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb66477291e7e8d2b0ff1bcb900bf29489a9692816d79874bea351e7a8b6de96" +dependencies = [ + "curve25519-dalek", + "rand_core", + "serde", + "zeroize", +] + [[package]] name = "zeroize" version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2a0956f1ba7c7909bfb66c2e9e4124ab6f6482560f6628b5aaeba39207c9aad9" +dependencies = [ + "zeroize_derive", +] + +[[package]] +name = "zeroize_derive" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] diff --git a/loki-server/Cargo.toml b/loki-server/Cargo.toml index be40a56..aefc871 100644 --- a/loki-server/Cargo.toml +++ b/loki-server/Cargo.toml @@ -8,3 +8,4 @@ edition = "2021" [dependencies] loki-shared = { path = "../loki-shared" } protolok = { path = "../protolok" } +tokio = { version = "1", features = ["full"] } diff --git a/loki-server/src/main.rs b/loki-server/src/main.rs index a30eb95..077d060 100644 --- a/loki-server/src/main.rs +++ b/loki-server/src/main.rs @@ -1,3 +1,7 @@ -fn main() { +use tokio::io::{AsyncRead, AsyncWrite}; +use tokio::net::TcpListener; + +#[tokio::main] +async fn main() { println!("Hello, world!"); } diff --git a/loki-shared/src/lib.rs b/loki-shared/src/lib.rs index 06d268d..e69de29 100644 --- a/loki-shared/src/lib.rs +++ b/loki-shared/src/lib.rs @@ -1,14 +0,0 @@ -pub fn add(left: usize, right: usize) -> usize { - left + right -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn it_works() { - let result = add(2, 2); - assert_eq!(result, 4); - } -} diff --git a/protolok/Cargo.toml b/protolok/Cargo.toml index 022943f..95d92c5 100644 --- a/protolok/Cargo.toml +++ b/protolok/Cargo.toml @@ -6,7 +6,8 @@ version = "0.1.0" edition = "2021" [dependencies] -base16ct = "0.2" rand = "0.8.5" -rsa = "0.8" sha2 = "0.10" +chacha20poly1305 = "0.10" +ed25519-dalek = { version="2.1", features=["rand_core"] } +x25519-dalek = { version="2.0", features=["reusable_secrets"] } diff --git a/protolok/src/channel.rs b/protolok/src/channel.rs index e843716..265524f 100644 --- a/protolok/src/channel.rs +++ b/protolok/src/channel.rs @@ -1,4 +1,4 @@ -use crate::message::{Message, MessageContent}; +use crate::Message; pub trait Channel { fn fetch_newest_messages( @@ -6,5 +6,5 @@ pub trait Channel { amount: u32, begin_at_id: Option, ) -> Result, ErrorType>; - fn send_message(&self, message: MessageContent, ctx: Ctx) -> Result; + fn send_message(&self, message: Message, ctx: Ctx) -> Result<(), ErrorType>; } diff --git a/protolok/src/crypto.rs b/protolok/src/crypto.rs deleted file mode 100644 index 257ee62..0000000 --- a/protolok/src/crypto.rs +++ /dev/null @@ -1,49 +0,0 @@ -use std::collections::HashMap; - -use rand::{CryptoRng, RngCore}; -use rsa::{Pkcs1v15Encrypt, PublicKey, RsaPrivateKey}; - -use crate::ids::{make_id, Object, ServerMeta}; - -pub struct ClientKeypair { - pub(crate) rsa_pair: RsaPrivateKey, - pub rng: R, - id: u64, -} - -impl Object for ClientKeypair { - fn initialize(&mut self, meta: &ServerMeta) { - self.id = make_id(meta); - } - - fn get_id(&self) -> u64 { - self.id - } -} - -trait Decrypt { - fn decrypt_content(&self, data: Vec) -> Option>; -} - -trait Encrypt { - fn encrypt_content(&mut self, data: Vec) -> Option>; -} - -impl Decrypt for ClientKeypair { - fn decrypt_content(&self, data: Vec) -> Option> { - self.rsa_pair.decrypt(Pkcs1v15Encrypt, &data).ok() - } -} - -impl Encrypt for ClientKeypair { - fn encrypt_content(&mut self, data: Vec) -> Option> { - self.rsa_pair - .encrypt(&mut self.rng, Pkcs1v15Encrypt, &data) - .ok() - } -} - -pub struct ClientCrypto { - pub keystore: HashMap>, - pub channel_keys: HashMap, -} diff --git a/protolok/src/id.rs b/protolok/src/id.rs new file mode 100644 index 0000000..078c29b --- /dev/null +++ b/protolok/src/id.rs @@ -0,0 +1,74 @@ +use std::{ + sync::Mutex, + time::{Duration, SystemTime, UNIX_EPOCH}, +}; + +const EPOCH: Duration = Duration::from_millis(1672531200000); + +const fn mask(amount: u64) -> u64 { + (1 << amount) - 1 +} + +pub struct SnowflakeGenerator { + last_evoked: u64, + count: Mutex, +} + +impl SnowflakeGenerator { + pub fn new() -> SnowflakeGenerator { + SnowflakeGenerator { + last_evoked: 0, + count: Mutex::new(0), + } + } + + pub fn generate(&mut self, worker_id: u16) -> u64 { + let timestamp = SystemTime::now() + .duration_since(UNIX_EPOCH + EPOCH) + .expect("Time went backwards") + .as_millis() as u64 + & mask(42); + + let mut count = self.count.lock().expect("Poisoned mutex"); + + if self.last_evoked > timestamp { + *count = 0; + self.last_evoked = timestamp; + } + + let id = timestamp << 22 | (worker_id as u64 & mask(10)) << 12 | (*count as u64 & mask(12)); + + *count += 1; + + id + } +} + +pub trait Object { + fn get_id(&self) -> u64; + fn creation_time(&self) -> SystemTime { + UNIX_EPOCH + EPOCH + Duration::from_millis(self.get_id() >> 22) + } + + fn serialize(&self) -> Vec; + fn deserialize(data: &[u8]) -> Self; +} + +#[cfg(test)] +mod tests { + use super::SnowflakeGenerator; + + #[test] + fn test_snowflake_count() { + let mut snowflake = SnowflakeGenerator::new(); + + assert_ne!(snowflake.generate(0), snowflake.generate(0)); + } + + #[test] + fn test_snowflake_worker() { + let mut snowflake = SnowflakeGenerator::new(); + + assert_ne!(snowflake.generate(1), snowflake.generate(0)); + } +} diff --git a/protolok/src/ids.rs b/protolok/src/ids.rs deleted file mode 100644 index 3029a86..0000000 --- a/protolok/src/ids.rs +++ /dev/null @@ -1,153 +0,0 @@ -use std::{ - collections::HashMap, - sync::{Mutex, RwLock}, - thread::{self, ThreadId}, - time::{Duration, SystemTime}, -}; - -/// 2023-01-01 00:00:00.000 GMT -const JAN_1_2023: u64 = 1672531200000; - -pub struct Count { - pub count: u64, - pub time_ms: u64, -} - -pub struct Timekeeper { - last_invoked: SystemTime, - current_count: u16, -} - -impl Timekeeper { - pub fn new() -> Self { - Self { - last_invoked: SystemTime::now(), - current_count: 0, - } - } -} - -impl Default for Timekeeper { - fn default() -> Self { - Self::new() - } -} - -impl Iterator for Timekeeper { - type Item = Count; - - /// Never returns None. - fn next(&mut self) -> Option { - let cnt = self.current_count; - self.current_count += 1; - let time = SystemTime::now(); - if time - .duration_since(self.last_invoked) - .expect("time should not go backwards!!!!!") - .as_millis() > 0 - { - self.current_count = 0; - } - Some(Count { - count: cnt as u64, - time_ms: time - .duration_since(SystemTime::UNIX_EPOCH + Duration::from_millis(JAN_1_2023)) - .expect("unix epoch should be minimum") - .as_millis() as u64, - }) - } -} - -pub struct ServerMeta { - pub server_domain: &'static str, - pub worker_id: RwLock>, - pub timekeeper: RwLock>>, - pub next_tid: Mutex, -} - -impl ServerMeta { - pub fn new(server_domain: &'static str) -> Self { - Self { - server_domain, - worker_id: RwLock::new(HashMap::new()), - timekeeper: RwLock::new(HashMap::new()), - next_tid: Mutex::new(0), - } - } - - fn next_tid(&self) -> u16 { - let mut n = self.next_tid.lock().expect("poisoned mutex"); - let tid: u16 = *n; - *n += 1; - tid - } - - pub fn get_id(&self) -> u16 { - let key = thread::current().id(); - let tid = self.next_tid(); - if self.worker_id.read().unwrap().get(&key).is_none() { - self.worker_id.write().unwrap().insert(key, tid); - } - *self.worker_id.read().unwrap().get(&key).unwrap() // SAFETY: Checked above - } - - pub fn count(&self) -> Count { - let key = thread::current().id(); - if self.timekeeper.read().unwrap().get(&key).is_none() { - self.timekeeper - .write() - .unwrap() - .insert(key, Mutex::new(Timekeeper::new())); - } - self.timekeeper - .read() - .unwrap() - .get(&key) - .unwrap() // SAFETY: checked above - .lock() - .unwrap() - .next() - .unwrap() // SAFETY: Never None. - } -} - -const fn bit_mask(amount: u64) -> u64 { - let mut m = 0; - let mut i = 0; - while i < amount { - m <<= 1; - m += 1; - i += 1; - } - m -} - -pub fn make_id(meta: &ServerMeta) -> u64 { - let count = meta.count(); - ((count.time_ms & bit_mask(42)) << (10 + 12)) - + ((meta.get_id() as u64 & bit_mask(10)) << 10) - + (count.count & bit_mask(12)) -} - -pub fn id_to_parts(id: u64) -> (u64, u16, u16) { - let count = id & bit_mask(12); - let worker = (id >> 12) & bit_mask(10); - let time = (id >> (12 + 10)) & bit_mask(42); - (time, worker as u16, count as u16) -} - -pub fn to_unix_time(time: u64) -> u128 { - time as u128 + JAN_1_2023 as u128 -} - -pub trait Object { - fn initialize(&mut self, meta: &ServerMeta); - fn get_id(&self) -> u64; - fn id_to_parts(&self) -> (u64, u16, u16) { - id_to_parts(self.get_id()) - } - fn get_time(&self) -> SystemTime { - SystemTime::UNIX_EPOCH - + Duration::from_millis(to_unix_time(id_to_parts(self.get_id()).0) as u64) - } -} diff --git a/protolok/src/instance.rs b/protolok/src/instance.rs new file mode 100644 index 0000000..9fa4076 --- /dev/null +++ b/protolok/src/instance.rs @@ -0,0 +1,6 @@ +use crate::Object; + +pub trait Instance { + /// Gets an object from its Snowflake ID + fn from_object(&self, id: u64) -> impl Object; +} diff --git a/protolok/src/lib.rs b/protolok/src/lib.rs index 42b7dc5..3cddd87 100644 --- a/protolok/src/lib.rs +++ b/protolok/src/lib.rs @@ -1,12 +1,13 @@ pub mod channel; -pub mod crypto; -pub mod ids; -pub mod message; +pub mod instance; pub mod place; pub mod user; +pub mod message; +pub mod id; pub use channel::*; -pub use ids::*; -pub use message::*; pub use place::*; pub use user::*; +pub use message::*; +pub use id::*; +pub use instance::*; diff --git a/protolok/src/message.rs b/protolok/src/message.rs index c542722..a30dc9a 100644 --- a/protolok/src/message.rs +++ b/protolok/src/message.rs @@ -1,73 +1,62 @@ -use rsa::{Pkcs1v15Encrypt, PublicKey, RsaPrivateKey, RsaPublicKey}; +use crate::{Object, User}; -use crate::{ - ids::{make_id, Object, ServerMeta}, - user::UserHandle, -}; - -#[derive(Clone, Debug, PartialEq, Eq)] -pub struct UnencryptedContent { - pub hash: String, - pub text: String, -} -#[derive(Clone, Debug, PartialEq, Eq)] -pub struct EncryptedContent { - pub hash: String, - pub enc_text: Vec, +#[derive(Clone, PartialEq, Eq, Debug)] +pub struct Message { + data: Vec, + author: User, + id: u64, } -#[derive(Clone, Debug, PartialEq, Eq)] -pub enum MessageContent { - Encrypted(EncryptedContent), - Unencrypted(UnencryptedContent), -} -impl MessageContent { - pub fn is_encrypted(&self) -> bool { - matches!(self, &MessageContent::Encrypted { .. }) +impl Object for Message { + fn get_id(&self) -> u64 { + self.id } - pub fn decrypt(&self, key: &RsaPrivateKey) -> Result { - match self { - MessageContent::Encrypted(EncryptedContent { hash, enc_text }) => { - key.decrypt(Pkcs1v15Encrypt, enc_text).map(|x| { - Self::Unencrypted(UnencryptedContent { - hash: hash.to_owned(), - text: String::from_utf8(x).unwrap_or_else(|_| "INVALID UTF8".to_owned()), - }) - }) - } - MessageContent::Unencrypted(x) => Ok(Self::Unencrypted(x.clone())), - } + fn serialize(&self) -> Vec { + [(self.data.len() as u32).to_le_bytes().to_vec(), self.data.clone(), self.id.to_le_bytes().to_vec(), self.author.serialize()].concat() } -} -#[derive(Clone, Debug, PartialEq, Eq)] -pub struct Message { - pub id: u64, - pub from: Option, - pub content: MessageContent, -} + fn deserialize(data: &[u8]) -> Self { + let message_len = u32::from_le_bytes(data[0..4].try_into().unwrap()) as usize; + let message = data[4..message_len + 4].to_vec(); -pub fn encrypt( - unencrypted: UnencryptedContent, - key: &RsaPublicKey, -) -> Result { - Ok(MessageContent::Encrypted(EncryptedContent { - hash: unencrypted.hash, - enc_text: key.encrypt( - &mut rand::thread_rng(), - Pkcs1v15Encrypt, - unencrypted.text.as_bytes(), - )?, - })) -} + let id = u64::from_le_bytes(data[message_len + 4..message_len + 4 + 8].try_into().unwrap()); -impl Object for Message { - fn initialize(&mut self, meta: &ServerMeta) { - self.id = make_id(meta); - } + let author = User::deserialize(&data[message_len + 4 + 8..]); - fn get_id(&self) -> u64 { - self.id + Message { + data: message, + author, + id, + } } } + +#[cfg(test)] +mod tests { + use crate::Object; + use crate::User; + + use super::Message; + + #[test] + fn test_serialize() { + let user1 = User::from( + "tudbut".to_owned(), + "test.lokichat.xyz".to_owned(), + false, + 0, + ); + + let message = Message { + data: Vec::new(), + author: user1, + id: 0, + }; + + let serialized = message.serialize(); + let deserialized = Message::deserialize(&serialized); + + assert_eq!(deserialized, message) + } +} diff --git a/protolok/src/user.rs b/protolok/src/user.rs index c1482e6..c48e8c9 100644 --- a/protolok/src/user.rs +++ b/protolok/src/user.rs @@ -1,44 +1,106 @@ -use crate::ids::{make_id, Object, ServerMeta}; +use crate::Object; #[derive(Clone, Debug, PartialEq, Eq)] -pub struct UserHandle { +pub struct User { pub name: String, pub home: String, pub bot: bool, pub id: u64, } -impl Object for UserHandle { - fn initialize(&mut self, meta: &ServerMeta) { - self.id = make_id(meta); +impl User { + pub fn from(name: String, home: String, bot: bool, id: u64) -> User { + User { + name, + home, + bot, + id, + } } +} +impl Object for User { fn get_id(&self) -> u64 { self.id } + + fn serialize(&self) -> Vec { + [ + &(self.name.len() as u16).to_le_bytes(), + self.name.as_bytes(), + &(self.home.len() as u16).to_le_bytes(), + self.home.as_bytes(), + &[self.bot as u8], + &self.id.to_le_bytes(), + ] + .concat() + } + + fn deserialize(data: &[u8]) -> Self { + let username_len = u16::from_le_bytes(data[0..2].try_into().unwrap()) as usize; + + let mut start = 2; + + let username = String::from_utf8(data[start..start + username_len].to_vec()).unwrap(); + + start += username_len; + + let home_len = u16::from_le_bytes( + data[start..start + 2].try_into().unwrap() + ) as usize; + + start += 2; + + let home = + String::from_utf8(data[start..start + home_len].to_vec()) + .unwrap(); + + start += home_len; + + let bot = data[start] != 0; + + let id = u64::from_le_bytes(data[start + 1..].try_into().unwrap()); + + User::from(username, home, bot, id) + } } #[cfg(test)] mod tests { - use std::sync::OnceLock; + use crate::Object; - use crate::ids::{id_to_parts, to_unix_time, Object, ServerMeta}; + use super::User; - use super::UserHandle; + #[test] + fn test_equivalent() { + let user1 = User::from( + "tudbut".to_owned(), + "test.lokichat.xyz".to_owned(), + false, + 0, + ); + let user2 = User::from( + "tudbut".to_owned(), + "test.lokichat.xyz".to_owned(), + false, + 0, + ); + + assert_eq!(user1, user2); + } #[test] - fn init_test() { - static META: OnceLock = OnceLock::new(); - META.get_or_init(|| ServerMeta::new("test.lokichat.xyz")); - let mut handle = UserHandle { - name: "TudbuT".to_owned(), - home: "test.lokichat.xyz".to_owned(), - bot: false, - id: 0, - }; - handle.initialize(META.get().unwrap()); - dbg!(handle.id); - dbg!(id_to_parts(handle.id)); - dbg!(to_unix_time(id_to_parts(handle.id).0)); + fn test_serialize() { + let user1 = User::from( + "tudbut".to_owned(), + "test.lokichat.xyz".to_owned(), + false, + 0, + ); + let serialized = user1.serialize(); + + let user2 = User::deserialize(&serialized); + + assert_eq!(user1, user2); } }