work, api alpha3
/ build_arm64 (push) Waiting to run Details
/ build_win64 (push) Waiting to run Details
/ build (push) Successful in 1m32s Details
/ build_x64 (push) Has been cancelled Details

This commit is contained in:
core 2024-01-23 19:34:46 -05:00
parent 0b807b351d
commit 12a24b135a
Signed by: core
GPG Key ID: FDBF740DADDCEECF
13 changed files with 316 additions and 9 deletions

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="DataSourceManagerImpl" format="xml" multifile-model="true"> <component name="DataSourceManagerImpl" format="xml" multifile-model="true">
<data-source source="LOCAL" name="trifid@localhost" uuid="39c81b89-3fc4-493f-b203-7a00527cffe6"> <data-source source="LOCAL" name="trifidapi@localhost" uuid="39c81b89-3fc4-493f-b203-7a00527cffe6">
<driver-ref>postgresql</driver-ref> <driver-ref>postgresql</driver-ref>
<synchronize>true</synchronize> <synchronize>true</synchronize>
<jdbc-driver>org.postgresql.Driver</jdbc-driver> <jdbc-driver>org.postgresql.Driver</jdbc-driver>

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<module type="CPP_MODULE" version="4"> <module type="CPP_MODULE" version="4">
<component name="Go" enabled="true" />
<component name="NewModuleRootManager"> <component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$"> <content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/tfclient/src" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/tfclient/src" isTestSource="false" />

142
Cargo.lock generated
View File

@ -286,9 +286,9 @@ dependencies = [
[[package]] [[package]]
name = "anstream" name = "anstream"
version = "0.6.5" version = "0.6.11"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d664a92ecae85fd0a7392615844904654d1d5f5514837f471ddef4a057aba1b6" checksum = "6e2e1ebcb11de5c03c67de28a7df593d32191b44939c482e97702baaaa6ab6a5"
dependencies = [ dependencies = [
"anstyle", "anstyle",
"anstyle-parse", "anstyle-parse",
@ -679,8 +679,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7c64043d6c7b7a4c58e39e7efccfdea7b93d885a795d0c054a69dbbf4dd52686" checksum = "7c64043d6c7b7a4c58e39e7efccfdea7b93d885a795d0c054a69dbbf4dd52686"
dependencies = [ dependencies = [
"crossterm 0.27.0", "crossterm 0.27.0",
"strum", "strum 0.25.0",
"strum_macros", "strum_macros 0.25.3",
"unicode-width", "unicode-width",
] ]
@ -1033,6 +1033,12 @@ dependencies = [
"url", "url",
] ]
[[package]]
name = "dyn-clone"
version = "1.0.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "545b22097d44f8a9581187cdf93de7a71e4722bf51200cfaba810865b49a495d"
[[package]] [[package]]
name = "ed25519" name = "ed25519"
version = "2.2.3" version = "2.2.3"
@ -1086,6 +1092,16 @@ dependencies = [
"syn 2.0.43", "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]] [[package]]
name = "env_logger" name = "env_logger"
version = "0.10.1" version = "0.10.1"
@ -1099,6 +1115,19 @@ dependencies = [
"termcolor", "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]] [[package]]
name = "equivalent" name = "equivalent"
version = "1.0.1" version = "1.0.1"
@ -1121,6 +1150,12 @@ version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7" checksum = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7"
[[package]]
name = "fastrand"
version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5"
[[package]] [[package]]
name = "fiat-crypto" name = "fiat-crypto"
version = "0.2.5" version = "0.2.5"
@ -1551,6 +1586,23 @@ dependencies = [
"generic-array", "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]] [[package]]
name = "ipconfig" name = "ipconfig"
version = "0.3.2" version = "0.3.2"
@ -1765,6 +1817,12 @@ dependencies = [
"webpki-roots 0.26.0", "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]] [[package]]
name = "match_cfg" name = "match_cfg"
version = "0.1.0" version = "0.1.0"
@ -1863,6 +1921,15 @@ dependencies = [
"cc", "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]] [[package]]
name = "nix" name = "nix"
version = "0.27.1" version = "0.27.1"
@ -2717,6 +2784,17 @@ version = "0.9.8"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" 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]] [[package]]
name = "spki" name = "spki"
version = "0.7.3" version = "0.7.3"
@ -2744,12 +2822,34 @@ version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
[[package]]
name = "strum"
version = "0.24.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "063e6045c0e62079840579a7e47a355ae92f60eb74daaf156fb1e84ba164e63f"
dependencies = [
"strum_macros 0.24.3",
]
[[package]] [[package]]
name = "strum" name = "strum"
version = "0.25.0" version = "0.25.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "290d54ea6f91c969195bdbcd7442c8c2a2ba87da8bf60a7ee86a235d4bc1e125" 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]] [[package]]
name = "strum_macros" name = "strum_macros"
version = "0.25.3" version = "0.25.3"
@ -2812,6 +2912,19 @@ dependencies = [
"libc", "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]] [[package]]
name = "termcolor" name = "termcolor"
version = "1.4.0" version = "1.4.0"
@ -3147,7 +3260,7 @@ dependencies = [
"diesel-async", "diesel-async",
"diesel_migrations", "diesel_migrations",
"dnapi-rs", "dnapi-rs",
"env_logger", "env_logger 0.10.1",
"hex", "hex",
"ipnet", "ipnet",
"log", "log",
@ -3187,6 +3300,19 @@ dependencies = [
"x25519-dalek", "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]] [[package]]
name = "try-lock" name = "try-lock"
version = "0.2.5" version = "0.2.5"
@ -3220,6 +3346,12 @@ dependencies = [
"tinyvec", "tinyvec",
] ]
[[package]]
name = "unicode-segmentation"
version = "1.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36"
[[package]] [[package]]
name = "unicode-width" name = "unicode-width"
version = "0.1.11" version = "0.1.11"

View File

@ -7,7 +7,8 @@ members = [
"nebula-ffi", "nebula-ffi",
"nebula-config", "nebula-config",
"trifid-api", "trifid-api",
"trifid-api-derive" "trifid-api-derive",
"trifid_mobile_bridge"
] ]
resolver = "2" resolver = "2"

View File

@ -0,0 +1,5 @@
package main
func main() {
}

24
tfclient-go/config.go Normal file
View File

@ -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"
}
}

10
tfclient-go/go.mod Normal file
View File

@ -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

12
tfclient-go/go.sum Normal file
View File

@ -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=

12
tfclient-go/socket.go Normal file
View File

@ -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"
}
}

View File

@ -1,6 +1,6 @@
[package] [package]
name = "trifid-api" name = "trifid-api"
version = "0.3.0-alpha2" version = "0.3.0-alpha3"
authors = ["core <core@e3t.cc>"] authors = ["core <core@e3t.cc>"]
edition = "2021" edition = "2021"
description = "An open-source reimplementation of the Defined Networking API server" description = "An open-source reimplementation of the Defined Networking API server"

View File

@ -136,7 +136,7 @@ async fn main() {
HttpResponse::BadRequest().json(err2), HttpResponse::BadRequest().json(err2),
) )
}) })
})) }).content_type_required(false))
.service(routes::v1::signup::signup_req) .service(routes::v1::signup::signup_req)
.service(routes::v1::auth::verify_magic_link::verify_link_req) .service(routes::v1::auth::verify_magic_link::verify_link_req)
.service(routes::v1::auth::magic_link::login_req) .service(routes::v1::auth::magic_link::login_req)

View File

@ -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"

View File

@ -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 <enroll|update>
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: {} <path_to_config> <enroll|update|settings>", 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: {} <path_to_config> <enroll|update|settings>", args.next().unwrap());
std::process::exit(1);
}
}
fn wait_enter() {
stdout().flush().unwrap();
let _ = stdin().read(&mut [0u8]).unwrap();
}