diff --git a/src/digid_api.rs b/src/digid_api.rs index 824dbd1..d2d320c 100644 --- a/src/digid_api.rs +++ b/src/digid_api.rs @@ -64,10 +64,18 @@ pub struct PolyDataResponse { pub result: String, } -pub async fn wid_init(session_id: &str) -> Option { +pub async fn wid_init(host: &str, session_id: &str) -> Option { + let app_host = if host == "digid.nl" { + String::from("app.digid.nl") + } else { + String::from("app-") + host + }; + + println!("host: {:?}", app_host); + let client = reqwest::Client::new(); let init_req = client - .post("https://app.digid.nl/apps/wid/new") + .post(format!("https://{}/apps/wid/new", app_host)) .json(&serde_json::json!({"app_session_id": session_id.to_owned() })) .header("API-Version", "3") .header("App-Version", "6.16.3") @@ -87,7 +95,7 @@ pub async fn wid_init(session_id: &str) -> Option { } client - .post("https://app.digid.nl/apps/wid/confirm") + .post(format!("https://{}/apps/wid/confirm", app_host)) .json(&serde_json::json!({"app_session_id": session_id.to_owned() })) .header("API-Version", "3") .header("App-Version", "6.16.3") diff --git a/src/main.rs b/src/main.rs index 39d2287..497a168 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,4 @@ -use std::{env::args, thread, time::Duration}; +use std::{collections::HashMap, env::args, thread, time::Duration}; use der::{Any, Decode, asn1::SetOfVec, oid::ObjectIdentifier}; use openssl::{bn::BigNumContext, ec::PointConversionForm, pkey::PKey}; @@ -94,6 +94,7 @@ pub trait Card { } async fn run_auth( + host: String, session_id: String, ctg_pipe: async_channel::Sender, gtc_pipe: async_channel::Receiver, @@ -105,7 +106,7 @@ async fn run_auth( service: String::from("UI Test"), } } else { - let Some(ctx) = digid_api::wid_init(&session_id).await else { + let Some(ctx) = digid_api::wid_init(&host, &session_id).await else { ctg_pipe.send(pipe::CardToGUI::ProcessingMessage { message: "Failed to initialize DigiD session.".to_owned() }).await; return Ok(()); }; @@ -497,17 +498,10 @@ fn main() { let (gtc_pipe_s, gtc_pipe_r) = async_channel::unbounded(); let s = args().nth(1).unwrap(); - let session_id = s - .split('&') - .next() - .unwrap() - .split('=') - .last() - .unwrap() - .to_owned(); + let mut parsed_url = url::form_urlencoded::parse(s.split(':').last().unwrap().as_bytes()).into_owned().collect::>(); let rt = Runtime::new().unwrap(); - rt.spawn(async { run_auth(session_id, ctg_pipe_s, gtc_pipe_r).await.unwrap() }); + rt.spawn(async move { run_auth(parsed_url.remove("host").unwrap_or_else(|| String::from("test")), parsed_url.remove("app_session_id").unwrap_or_else(|| String::from("test")), ctg_pipe_s, gtc_pipe_r).await.unwrap() }); gui::run_gui(ctg_pipe_r, gtc_pipe_s); }