diff --git a/controller/PostgreSQL.cpp b/controller/PostgreSQL.cpp index 28bd7b844..66075fd1e 100644 --- a/controller/PostgreSQL.cpp +++ b/controller/PostgreSQL.cpp @@ -459,7 +459,7 @@ AuthInfo PostgreSQL::getSSOAuthInfo(const nlohmann::json &member, const std::str info.ssoClientID = client_id; info.issuerURL = issuer; info.ssoNonce = nonce; - info.ssoState = std::string(state_hex); + info.ssoState = std::string(state_hex) + "_" +networkId; info.centralAuthURL = redirectURL; fprintf( stderr, diff --git a/service/OneService.cpp b/service/OneService.cpp index cd6e524ce..26636351c 100644 --- a/service/OneService.cpp +++ b/service/OneService.cpp @@ -1648,7 +1648,12 @@ public: fprintf(stderr, "sso get\n"); fprintf(stderr, "path: %s\n", path.c_str()); fprintf(stderr, "body: %s\n", body.c_str()); - scode = 200; scode = 200; + + const char* state = zeroidc::zeroidc_get_state_param_value(path.c_str()); + const char* nwid = zeroidc::zeroidc_network_id_from_state(state); + fprintf(stderr, "state: %s\n", state); + fprintf(stderr, "nwid: %s\n", nwid); + scode = 200; } else { scode = 401; // isAuth == false && !sso } @@ -1791,13 +1796,6 @@ public: scode = _controller->handleControlPlaneHttpPOST(std::vector(ps.begin()+1,ps.end()),urlArgs,headers,body,responseBody,responseContentType); else scode = 404; } - - } else if (ps[0] == "sso") { - // sso post handling - fprintf(stderr, "sso post\n"); - fprintf(stderr, "path: %s\n", path.c_str()); - fprintf(stderr, "body: %s\n", body.c_str()); - scode = 200; } else { scode = 401; // isAuth == false diff --git a/zeroidc/Cargo.lock b/zeroidc/Cargo.lock index 24479eaaf..e729b2147 100644 --- a/zeroidc/Cargo.lock +++ b/zeroidc/Cargo.lock @@ -28,12 +28,6 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" -[[package]] -name = "base64" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3441f0f7b02788e948e47f457ca01f1d7e6d92c693bc132c22b087d3141c03ff" - [[package]] name = "base64" version = "0.13.0" @@ -108,7 +102,6 @@ dependencies = [ "num-integer", "num-traits", "serde", - "time", "winapi", ] @@ -251,17 +244,6 @@ dependencies = [ "version_check", ] -[[package]] -name = "getrandom" -version = "0.1.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" -dependencies = [ - "cfg-if", - "libc", - "wasi 0.9.0+wasi-snapshot-preview1", -] - [[package]] name = "getrandom" version = "0.2.3" @@ -271,7 +253,7 @@ dependencies = [ "cfg-if", "js-sys", "libc", - "wasi 0.10.2+wasi-snapshot-preview1", + "wasi", "wasm-bindgen", ] @@ -512,6 +494,17 @@ dependencies = [ "winapi", ] +[[package]] +name = "num-bigint" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f93ab6289c7b344a8a9f60f88d80aa20032336fe78da341afc91c8a2341fc75f" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + [[package]] name = "num-integer" version = "0.1.44" @@ -547,11 +540,11 @@ version = "4.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "80e47cfc4c0a1a519d9a025ebfbac3a2439d1b5cdf397d72dcb79b11d9920dab" dependencies = [ - "base64 0.13.0", + "base64", "chrono", - "getrandom 0.2.3", + "getrandom", "http", - "rand 0.8.4", + "rand", "reqwest", "serde", "serde_json", @@ -575,17 +568,18 @@ checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" [[package]] name = "openidconnect" -version = "2.1.0" +version = "2.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a42ff51db0f23ae55dd6f234a15ed7bb468bc97938670693a3eaa42869110167" +checksum = "7d523cf32bdf7696f36bc4198a42c34b65f0227b97f2f501ebfbe016baa5bc52" dependencies = [ - "base64 0.12.3", + "base64", "chrono", "http", "itertools", "log", + "num-bigint", "oauth2", - "rand 0.7.3", + "rand", "ring", "serde", "serde-value", @@ -660,19 +654,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "rand" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" -dependencies = [ - "getrandom 0.1.16", - "libc", - "rand_chacha 0.2.2", - "rand_core 0.5.1", - "rand_hc 0.2.0", -] - [[package]] name = "rand" version = "0.8.4" @@ -680,19 +661,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2e7573632e6454cf6b99d7aac4ccca54be06da05aca2ef7423d22d27d4d4bcd8" dependencies = [ "libc", - "rand_chacha 0.3.1", - "rand_core 0.6.3", - "rand_hc 0.3.1", -] - -[[package]] -name = "rand_chacha" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" -dependencies = [ - "ppv-lite86", - "rand_core 0.5.1", + "rand_chacha", + "rand_core", + "rand_hc", ] [[package]] @@ -702,16 +673,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" dependencies = [ "ppv-lite86", - "rand_core 0.6.3", -] - -[[package]] -name = "rand_core" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" -dependencies = [ - "getrandom 0.1.16", + "rand_core", ] [[package]] @@ -720,16 +682,7 @@ version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7" dependencies = [ - "getrandom 0.2.3", -] - -[[package]] -name = "rand_hc" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" -dependencies = [ - "rand_core 0.5.1", + "getrandom", ] [[package]] @@ -738,7 +691,7 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d51e9f596de227fda2ea6c84607f5558e196eeaf43c986b724ba4fb8fdf497e7" dependencies = [ - "rand_core 0.6.3", + "rand_core", ] [[package]] @@ -765,7 +718,7 @@ version = "0.11.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "66d2927ca2f685faf0fc620ac4834690d29e7abb153add10f5812eef20b5e280" dependencies = [ - "base64 0.13.0", + "base64", "bytes", "encoding_rs", "futures-core", @@ -816,7 +769,7 @@ version = "0.19.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "35edb675feee39aec9c99fa5ff985081995a06d594114ae14cbe797ad7b7a6d7" dependencies = [ - "base64 0.13.0", + "base64", "log", "ring", "sct", @@ -961,7 +914,7 @@ checksum = "dac1c663cfc93810f88aed9b8941d48cabf856a1b111c29a40439018d870eb22" dependencies = [ "cfg-if", "libc", - "rand 0.8.4", + "rand", "redox_syscall", "remove_dir_all", "winapi", @@ -996,16 +949,6 @@ dependencies = [ "syn", ] -[[package]] -name = "time" -version = "0.1.43" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438" -dependencies = [ - "libc", - "winapi", -] - [[package]] name = "tinyvec" version = "1.5.0" @@ -1183,12 +1126,6 @@ dependencies = [ "try-lock", ] -[[package]] -name = "wasi" -version = "0.9.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" - [[package]] name = "wasi" version = "0.10.2+wasi-snapshot-preview1" @@ -1325,7 +1262,7 @@ dependencies = [ name = "zeroidc" version = "0.1.0" dependencies = [ - "base64 0.13.0", + "base64", "cbindgen", "openidconnect", "url", diff --git a/zeroidc/Cargo.toml b/zeroidc/Cargo.toml index 41ac73029..28f96b774 100644 --- a/zeroidc/Cargo.toml +++ b/zeroidc/Cargo.toml @@ -12,7 +12,7 @@ crate-type = ["staticlib","rlib"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -openidconnect = "2.1.0" +openidconnect = "2.1.2" base64 = "0.13.0" url = "2.2.2" diff --git a/zeroidc/src/ext.rs b/zeroidc/src/ext.rs index d6f451378..22e7d9418 100644 --- a/zeroidc/src/ext.rs +++ b/zeroidc/src/ext.rs @@ -1,5 +1,6 @@ use std::ffi::{CStr, CString}; use std::os::raw::c_char; +use url::{Url, ParseError}; use crate::{AuthInfo, ZeroIDC}; @@ -167,3 +168,65 @@ pub extern "C" fn zeroidc_get_auth_url(ptr: *mut AuthInfo) -> *const c_char { let s = CString::new(ai.url.to_string()).unwrap(); return s.into_raw(); } + +#[no_mangle] +pub extern "C" fn zeroidc_token_exchange(idc: *mut ZeroIDC, ai: *mut AuthInfo, code: *const c_char ) { + if idc.is_null() { + println!("idc is null"); + return + } + if ai.is_null() { + println!("ai is null"); + return + } + let idc = unsafe { + &mut *idc + }; + let ai = unsafe { + &mut *ai + }; + + +} + +#[no_mangle] +pub extern "C" fn zeroidc_get_state_param_value(path: *const c_char) -> *const c_char { + if path.is_null() { + println!("path is null"); + return std::ptr::null(); + } + + let path = unsafe {CStr::from_ptr(path)}.to_str().unwrap(); + + let url = "http://localhost:9993".to_string() + path; + let url = Url::parse(&url).unwrap(); + + let mut pairs = url.query_pairs(); + for p in pairs { + if p.0 == "state" { + let s = CString::new(p.1.into_owned()).unwrap(); + return s.into_raw() + } + } + + return std::ptr::null(); +} + +#[no_mangle] +pub extern "C" fn zeroidc_network_id_from_state(state: *const c_char) -> *const c_char { + if state.is_null() { + println!("state is null"); + return std::ptr::null(); + } + + let state = unsafe{CStr::from_ptr(state)}.to_str().unwrap(); + + let split = state.split("_"); + let split = split.collect::>(); + if split.len() != 2 { + return std::ptr::null(); + } + + let s = CString::new(split[1]).unwrap(); + return s.into_raw(); +} \ No newline at end of file