diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml index 7074b84..1fec8e5 100644 --- a/.idea/dataSources.xml +++ b/.idea/dataSources.xml @@ -1,7 +1,7 @@ - + postgresql true org.postgresql.Driver diff --git a/.idea/trifid.iml b/.idea/trifid.iml index 85e74e1..a5f4b95 100644 --- a/.idea/trifid.iml +++ b/.idea/trifid.iml @@ -1,5 +1,6 @@ + diff --git a/Cargo.lock b/Cargo.lock index 26cf925..f2bb8b4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -286,9 +286,9 @@ dependencies = [ [[package]] name = "anstream" -version = "0.6.5" +version = "0.6.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d664a92ecae85fd0a7392615844904654d1d5f5514837f471ddef4a057aba1b6" +checksum = "6e2e1ebcb11de5c03c67de28a7df593d32191b44939c482e97702baaaa6ab6a5" dependencies = [ "anstyle", "anstyle-parse", @@ -679,8 +679,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7c64043d6c7b7a4c58e39e7efccfdea7b93d885a795d0c054a69dbbf4dd52686" dependencies = [ "crossterm 0.27.0", - "strum", - "strum_macros", + "strum 0.25.0", + "strum_macros 0.25.3", "unicode-width", ] @@ -1033,6 +1033,12 @@ dependencies = [ "url", ] +[[package]] +name = "dyn-clone" +version = "1.0.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "545b22097d44f8a9581187cdf93de7a71e4722bf51200cfaba810865b49a495d" + [[package]] name = "ed25519" version = "2.2.3" @@ -1086,6 +1092,16 @@ dependencies = [ "syn 2.0.43", ] +[[package]] +name = "env_filter" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a009aa4810eb158359dda09d0c87378e4bbb89b5a801f016885a4707ba24f7ea" +dependencies = [ + "log", + "regex", +] + [[package]] name = "env_logger" version = "0.10.1" @@ -1099,6 +1115,19 @@ dependencies = [ "termcolor", ] +[[package]] +name = "env_logger" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9eeb342678d785662fd2514be38c459bb925f02b68dd2a3e0f21d7ef82d979dd" +dependencies = [ + "anstream", + "anstyle", + "env_filter", + "humantime", + "log", +] + [[package]] name = "equivalent" version = "1.0.1" @@ -1121,6 +1150,12 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7" +[[package]] +name = "fastrand" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5" + [[package]] name = "fiat-crypto" version = "0.2.5" @@ -1551,6 +1586,23 @@ dependencies = [ "generic-array", ] +[[package]] +name = "inquire" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c33e7c1ddeb15c9abcbfef6029d8e29f69b52b6d6c891031b88ed91b5065803b" +dependencies = [ + "bitflags 1.3.2", + "crossterm 0.25.0", + "dyn-clone", + "lazy_static", + "newline-converter", + "tempfile", + "thiserror", + "unicode-segmentation", + "unicode-width", +] + [[package]] name = "ipconfig" version = "0.3.2" @@ -1765,6 +1817,12 @@ dependencies = [ "webpki-roots 0.26.0", ] +[[package]] +name = "maplit" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e2e65a1a2e43cfcb47a895c4c8b10d1f4a61097f9f254f183aee60cad9c651d" + [[package]] name = "match_cfg" version = "0.1.0" @@ -1863,6 +1921,15 @@ dependencies = [ "cc", ] +[[package]] +name = "newline-converter" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f71d09d5c87634207f894c6b31b6a2b2c64ea3bdcf71bd5599fdbbe1600c00f" +dependencies = [ + "unicode-segmentation", +] + [[package]] name = "nix" version = "0.27.1" @@ -2717,6 +2784,17 @@ version = "0.9.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" +[[package]] +name = "spinners" +version = "4.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0ef947f358b9c238923f764c72a4a9d42f2d637c46e059dbd319d6e7cfb4f82" +dependencies = [ + "lazy_static", + "maplit", + "strum 0.24.1", +] + [[package]] name = "spki" version = "0.7.3" @@ -2744,12 +2822,34 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" +[[package]] +name = "strum" +version = "0.24.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "063e6045c0e62079840579a7e47a355ae92f60eb74daaf156fb1e84ba164e63f" +dependencies = [ + "strum_macros 0.24.3", +] + [[package]] name = "strum" version = "0.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "290d54ea6f91c969195bdbcd7442c8c2a2ba87da8bf60a7ee86a235d4bc1e125" +[[package]] +name = "strum_macros" +version = "0.24.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e385be0d24f186b4ce2f9982191e7101bb737312ad61c1f2f984f34bcf85d59" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "rustversion", + "syn 1.0.109", +] + [[package]] name = "strum_macros" version = "0.25.3" @@ -2812,6 +2912,19 @@ dependencies = [ "libc", ] +[[package]] +name = "tempfile" +version = "3.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01ce4141aa927a6d1bd34a041795abd0db1cccba5d5f24b009f694bdf3a1f3fa" +dependencies = [ + "cfg-if", + "fastrand", + "redox_syscall", + "rustix", + "windows-sys 0.52.0", +] + [[package]] name = "termcolor" version = "1.4.0" @@ -3147,7 +3260,7 @@ dependencies = [ "diesel-async", "diesel_migrations", "dnapi-rs", - "env_logger", + "env_logger 0.10.1", "hex", "ipnet", "log", @@ -3187,6 +3300,19 @@ dependencies = [ "x25519-dalek", ] +[[package]] +name = "trifid_mobile_bridge" +version = "0.1.0" +dependencies = [ + "colored", + "dnapi-rs", + "env_logger 0.11.0", + "inquire", + "serde", + "spinners", + "toml 0.8.8", +] + [[package]] name = "try-lock" version = "0.2.5" @@ -3220,6 +3346,12 @@ dependencies = [ "tinyvec", ] +[[package]] +name = "unicode-segmentation" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" + [[package]] name = "unicode-width" version = "0.1.11" diff --git a/Cargo.toml b/Cargo.toml index 082148f..e9d7210 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,8 @@ members = [ "nebula-ffi", "nebula-config", "trifid-api", - "trifid-api-derive" + "trifid-api-derive", + "trifid_mobile_bridge" ] resolver = "2" diff --git a/tfclient-go/cmd/tfclient-go/main.go b/tfclient-go/cmd/tfclient-go/main.go new file mode 100644 index 0000000..7905807 --- /dev/null +++ b/tfclient-go/cmd/tfclient-go/main.go @@ -0,0 +1,5 @@ +package main + +func main() { + +} diff --git a/tfclient-go/config.go b/tfclient-go/config.go new file mode 100644 index 0000000..1a50964 --- /dev/null +++ b/tfclient-go/config.go @@ -0,0 +1,24 @@ +package tfclient + +import ( + "crypto/ed25519" + "runtime" +) + +type TfConfig struct { + HostKey struct { + HostID string `yaml:"host_id"` + PrivateKey ed25519.PrivateKey `yaml:"private_key"` + Counter uint `yaml:"counter"` + TrustedKeys []ed25519.PublicKey `yaml:"trusted_keys"` + } +} + +func ConfigPath() string { + switch runtime.GOOS { + case "windows": + return "C:\\ProgramData\\tfclient" + default: + return "/etc/tfclient" + } +} diff --git a/tfclient-go/go.mod b/tfclient-go/go.mod new file mode 100644 index 0000000..572f047 --- /dev/null +++ b/tfclient-go/go.mod @@ -0,0 +1,10 @@ +module git.e3t.cc/core/trifid/tfclient-go + +go 1.20 + +require ( + github.com/sirupsen/logrus v1.9.3 + github.com/slackhq/nebula v1.8.2 +) + +require gopkg.in/yaml.v3 v3.0.1 // indirect diff --git a/tfclient-go/go.sum b/tfclient-go/go.sum new file mode 100644 index 0000000..a0945d1 --- /dev/null +++ b/tfclient-go/go.sum @@ -0,0 +1,12 @@ +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= +github.com/slackhq/nebula v1.8.2/go.mod h1:SVVwnlGdmLg387U0XQMOSHRrD3VlJeXqd2/x/w/vxPs= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/tfclient-go/socket.go b/tfclient-go/socket.go new file mode 100644 index 0000000..02417cc --- /dev/null +++ b/tfclient-go/socket.go @@ -0,0 +1,12 @@ +package tfclient + +import "runtime" + +func SocketPath(Name string) string { + switch runtime.GOOS { + case "windows": + return "C:\\ProgramData\\tfclient\\" + Name + ".sock" + default: + return "/tmp/tfclient-" + Name + ".sock" + } +} diff --git a/trifid-api/Cargo.toml b/trifid-api/Cargo.toml index f65dbeb..a46b97d 100644 --- a/trifid-api/Cargo.toml +++ b/trifid-api/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "trifid-api" -version = "0.3.0-alpha2" +version = "0.3.0-alpha3" authors = ["core "] edition = "2021" description = "An open-source reimplementation of the Defined Networking API server" diff --git a/trifid-api/src/main.rs b/trifid-api/src/main.rs index 9b013e4..b5c4c1a 100644 --- a/trifid-api/src/main.rs +++ b/trifid-api/src/main.rs @@ -136,7 +136,7 @@ async fn main() { HttpResponse::BadRequest().json(err2), ) }) - })) + }).content_type_required(false)) .service(routes::v1::signup::signup_req) .service(routes::v1::auth::verify_magic_link::verify_link_req) .service(routes::v1::auth::magic_link::login_req) diff --git a/trifid_mobile_bridge/Cargo.toml b/trifid_mobile_bridge/Cargo.toml new file mode 100644 index 0000000..7dff2b6 --- /dev/null +++ b/trifid_mobile_bridge/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "trifid_mobile_bridge" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +env_logger = "0.11" +dnapi-rs = { version = "0.2", path = "../dnapi-rs" } +serde = { version = "1", features = ["derive"] } +toml = "0.8" +inquire = { version = "0.6", features = ["editor"] } +spinners = "4" +colored = "2" \ No newline at end of file diff --git a/trifid_mobile_bridge/src/main.rs b/trifid_mobile_bridge/src/main.rs new file mode 100644 index 0000000..fabb39a --- /dev/null +++ b/trifid_mobile_bridge/src/main.rs @@ -0,0 +1,95 @@ +use std::io::{Read, stdin, stdout, Write}; +use std::path::PathBuf; +use std::thread::sleep; +use std::time::Duration; +use colored::Colorize; +use inquire::{Confirm, Editor, Text}; +use spinners::{Spinner, Spinners}; + +fn main() { + env_logger::init(); + + // usage: trifid_mobile_bridge path_to_config + let mut args = std::env::args(); + + println!("-=- Trifid Mobile Bridge -=-"); + + /* + + mobile_nebula config settings: + - Site Name + - Identity + - Certificate + - Certificate Contents (QR) + - CA (QR) + - Static Hosts + - Advanced + - Lighthouse interval + - Listen port + - MTU + - Cipher + - Log verbosity + - Unsafe routes + + */ + + if args.len() != 3 { + eprintln!("usage: {} ", args.next().unwrap()); + std::process::exit(1); + } + + let config_path = args.nth(1).unwrap(); + let cmd = args.next().unwrap(); + + if cmd == "enroll" { + + if PathBuf::from(config_path).exists() { + if !Confirm::new("Configuration already exists. Continuing will remove old data. Continue?").prompt().unwrap() { + println!("Aborting"); + std::process::exit(1); + } + } + let api_server = Text::new("What API server should be used to initialize this configuration?").prompt().unwrap(); + let enroll_code = Text::new("What enrollment code should be used to initialize this configuration?").prompt().unwrap(); + + println!("{}", "-- Manual configuration required --".bold().bright_yellow()); + print!("{} Open the {} app on your mobile device {}", "1.".bold().bright_yellow(), "Mobile Nebula".bright_cyan().bold(), "[enter to continue]".bright_cyan().bold()); + wait_enter(); + print!("{} Click the plus in the top left to create a new site {}", "2.".bold().bright_yellow(), "[enter to continue]".bright_cyan().bold()); + wait_enter(); + print!("{} Enter a name for the new site you are creating {}", "3.".bold().bright_yellow(), "[enter to continue]".bright_cyan().bold()); + wait_enter(); + print!("{} Tap the {} item to view the public key (at the top) {}", "4.".bold().bright_yellow(), "Certificate".bright_cyan().bold(), "[enter to continue]".bright_cyan().bold()); + wait_enter(); + + let pubkey = Editor::new("Please enter your mobile device's public key:") + .with_formatter(&|submission| { + let char_count = submission.chars().count(); + if char_count == 0 { + std::process::exit(1); + } else if char_count <= 20 { + submission.into() + } else { + let mut substr: String = submission.chars().take(17).collect(); + substr.push_str("..."); + substr + } + }) + .prompt().unwrap(); + + let mut sp = Spinner::new(Spinners::Dots, "Contacting API for enrollment".into()); + sleep(Duration::from_secs(10)); + } else if cmd == "update" { + + } else if cmd == "settings" { + + } else { + eprintln!("usage: {} ", args.next().unwrap()); + std::process::exit(1); + } +} + +fn wait_enter() { + stdout().flush().unwrap(); + let _ = stdin().read(&mut [0u8]).unwrap(); +} \ No newline at end of file