mirror of
https://github.com/yuezk/GlobalProtect-openconnect.git
synced 2026-11-30 17:56:13 -05:00
Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
341e74683f | ||
|
|
e63de466b3 | ||
|
|
5662aa16d6 |
No files matched your search
@@ -0,0 +1,22 @@
|
|||||||
|
name: Windows adapter DNS check
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ci/windows-adapter-dns-native]
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
jobs:
|
||||||
|
network:
|
||||||
|
runs-on: windows-11-arm
|
||||||
|
timeout-minutes: 15
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v6
|
||||||
|
- uses: dtolnay/[email protected]
|
||||||
|
- name: Test native Wintun adapter configuration
|
||||||
|
shell: pwsh
|
||||||
|
run: |
|
||||||
|
$zip = Join-Path $env:RUNNER_TEMP 'wintun.zip'
|
||||||
|
Invoke-WebRequest 'https://www.wintun.net/builds/wintun-0.14.1.zip' -OutFile $zip
|
||||||
|
if ((Get-FileHash $zip).Hash -ne '07C256185D6EE3652E09FA55C0B673E2624B565E02C4B9091C79CA7D2F24EF51') { throw 'Wintun checksum mismatch' }
|
||||||
|
Expand-Archive $zip $env:RUNNER_TEMP
|
||||||
|
$env:GP_TEST_WINTUN_DLL = Join-Path $env:RUNNER_TEMP 'wintun/bin/arm64/wintun.dll'
|
||||||
|
cargo +1.97.0 test --locked -p gpvpnc --test windows_network -- --ignored --nocapture --test-threads=1
|
||||||
@@ -129,49 +129,6 @@ async fn cached_tunnel_authentication_does_not_require_portal_discovery() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
|
||||||
async fn explicit_user_skips_another_users_cached_gateway_and_portal_credentials() {
|
|
||||||
let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap();
|
|
||||||
let origin = format!("http://{}", listener.local_addr().unwrap());
|
|
||||||
let directory = tempfile::tempdir().unwrap();
|
|
||||||
let cache = directory.path().join("cookie.json");
|
|
||||||
let args = TestArgs::parse_from([
|
|
||||||
"test",
|
|
||||||
&origin,
|
|
||||||
"--user",
|
|
||||||
"bob",
|
|
||||||
"--cookie-cache",
|
|
||||||
cache.to_str().unwrap(),
|
|
||||||
])
|
|
||||||
.connect;
|
|
||||||
let lock = directory.path().join("client.pid");
|
|
||||||
let verbose = gpapi::clap::InfoLevelVerbosity::new(0, 0);
|
|
||||||
let shared = SharedArgs {
|
|
||||||
ignore_tls_errors: true,
|
|
||||||
lock_file: &lock,
|
|
||||||
verbose: &verbose,
|
|
||||||
log_format: LogFormat::Text,
|
|
||||||
};
|
|
||||||
let handler = ConnectHandler::new(&args, &shared);
|
|
||||||
cookie_store::save(
|
|
||||||
&cache,
|
|
||||||
&StoredCookie::new(
|
|
||||||
args.server.clone(),
|
|
||||||
"alice".into(),
|
|
||||||
handler.os_profile.borrow().host_identity().host_id().into(),
|
|
||||||
origin,
|
|
||||||
AuthCookieCredential::new("alice", "portal-cookie", ""),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
assert!(handler.cached_portal_credential(&args.server).is_none());
|
|
||||||
tokio::select! {
|
|
||||||
result = handler.try_cached_cookie(&args.server) => assert!(result.is_none()),
|
|
||||||
_ = listener.accept() => panic!("a mismatched cache entry must be skipped before contacting the gateway"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn unreachable_gateway_keeps_cached_cookie() {
|
async fn unreachable_gateway_keeps_cached_cookie() {
|
||||||
// Nothing listens here: the cached gateway login gets no answer at all.
|
// Nothing listens here: the cached gateway login gets no answer at all.
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ impl ConnectHandler<'_> {
|
|||||||
pub(super) async fn try_cached_cookie(&self, server: &str) -> Option<anyhow::Result<()>> {
|
pub(super) async fn try_cached_cookie(&self, server: &str) -> Option<anyhow::Result<()>> {
|
||||||
let path = cookie_cache_path(self.args)?;
|
let path = cookie_cache_path(self.args)?;
|
||||||
let host_id = self.os_profile.borrow().host_identity().host_id().to_string();
|
let host_id = self.os_profile.borrow().host_identity().host_id().to_string();
|
||||||
let stored = cookie_store::load(&path, server, &host_id, self.args.user.as_deref())?;
|
let stored = cookie_store::load(&path, server, &host_id)?;
|
||||||
if !stored.auth_cookie.can_authenticate_gateway() {
|
if !stored.auth_cookie.can_authenticate_gateway() {
|
||||||
cookie_store::clear(&path);
|
cookie_store::clear(&path);
|
||||||
return None;
|
return None;
|
||||||
@@ -145,7 +145,7 @@ impl ConnectHandler<'_> {
|
|||||||
}
|
}
|
||||||
let path = cookie_cache_path(self.args)?;
|
let path = cookie_cache_path(self.args)?;
|
||||||
let host_id = self.os_profile.borrow().host_identity().host_id().to_string();
|
let host_id = self.os_profile.borrow().host_identity().host_id().to_string();
|
||||||
let stored = cookie_store::load(&path, server, &host_id, self.args.user.as_deref())?;
|
let stored = cookie_store::load(&path, server, &host_id)?;
|
||||||
if !stored.auth_cookie.can_authenticate_gateway() {
|
if !stored.auth_cookie.can_authenticate_gateway() {
|
||||||
cookie_store::clear(&path);
|
cookie_store::clear(&path);
|
||||||
return None;
|
return None;
|
||||||
|
|||||||
@@ -59,15 +59,12 @@ pub fn cookie_path(custom: Option<&str>) -> Option<PathBuf> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn load(path: &Path, server: &str, host_id: &str, requested_user: Option<&str>) -> Option<StoredCookie> {
|
pub fn load(path: &Path, server: &str, host_id: &str) -> Option<StoredCookie> {
|
||||||
let bytes = zeroize::Zeroizing::new(platform::decode(fs::read(path).ok()?).ok()?);
|
let bytes = zeroize::Zeroizing::new(platform::decode(fs::read(path).ok()?).ok()?);
|
||||||
let stored: StoredCookie = serde_json::from_slice(&bytes).ok()?;
|
let stored: StoredCookie = serde_json::from_slice(&bytes).ok()?;
|
||||||
if stored.version != STORE_VERSION || stored.server != server || stored.host_id != host_id {
|
if stored.version != STORE_VERSION || stored.server != server || stored.host_id != host_id {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
if requested_user.is_some_and(|user| user != stored.auth_cookie.username()) {
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
Some(stored)
|
Some(stored)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,7 +116,7 @@ mod tests {
|
|||||||
.windows(b"prelogon-auth".len())
|
.windows(b"prelogon-auth".len())
|
||||||
.any(|part| part == b"prelogon-auth")
|
.any(|part| part == b"prelogon-auth")
|
||||||
);
|
);
|
||||||
assert!(load(&path, "vpn.example.com", "host-1", None).is_some());
|
assert!(load(&path, "vpn.example.com", "host-1").is_some());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -135,35 +132,24 @@ mod tests {
|
|||||||
assert_eq!(fs::metadata(&path).unwrap().permissions().mode() & 0o777, 0o600);
|
assert_eq!(fs::metadata(&path).unwrap().permissions().mode() & 0o777, 0o600);
|
||||||
}
|
}
|
||||||
|
|
||||||
let loaded = load(&path, "vpn.example.com", "host-1", None).unwrap();
|
let loaded = load(&path, "vpn.example.com", "host-1").unwrap();
|
||||||
assert_eq!(loaded.username, "alice");
|
assert_eq!(loaded.username, "alice");
|
||||||
assert_eq!(loaded.host_id, "host-1");
|
assert_eq!(loaded.host_id, "host-1");
|
||||||
assert_eq!(loaded.last_gateway, "gw1.example.com");
|
assert_eq!(loaded.last_gateway, "gw1.example.com");
|
||||||
assert_eq!(loaded.auth_cookie.user_auth_cookie(), "user-auth");
|
assert_eq!(loaded.auth_cookie.user_auth_cookie(), "user-auth");
|
||||||
|
|
||||||
assert!(
|
assert!(
|
||||||
load(&path, "other.example.com", "host-1", None).is_none(),
|
load(&path, "other.example.com", "host-1").is_none(),
|
||||||
"must reject mismatched server"
|
"must reject mismatched server"
|
||||||
);
|
);
|
||||||
assert!(
|
assert!(
|
||||||
load(&path, "vpn.example.com", "host-2", None).is_none(),
|
load(&path, "vpn.example.com", "host-2").is_none(),
|
||||||
"must reject mismatched host id"
|
"must reject mismatched host id"
|
||||||
);
|
);
|
||||||
clear(&path);
|
clear(&path);
|
||||||
assert!(!path.exists());
|
assert!(!path.exists());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn matches_explicit_user_against_cached_credential() {
|
|
||||||
let dir = tempfile::tempdir().unwrap();
|
|
||||||
let path = dir.path().join("cookie.json");
|
|
||||||
let stored = sample();
|
|
||||||
save(&path, &stored).unwrap();
|
|
||||||
|
|
||||||
assert!(load(&path, &stored.server, &stored.host_id, Some("bob")).is_none());
|
|
||||||
assert!(load(&path, &stored.server, &stored.host_id, Some("alice")).is_some());
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn rejects_version_mismatch() {
|
fn rejects_version_mismatch() {
|
||||||
let dir = tempfile::tempdir().unwrap();
|
let dir = tempfile::tempdir().unwrap();
|
||||||
@@ -171,6 +157,6 @@ mod tests {
|
|||||||
let mut s = sample();
|
let mut s = sample();
|
||||||
s.version = STORE_VERSION + 1;
|
s.version = STORE_VERSION + 1;
|
||||||
save(&path, &s).unwrap();
|
save(&path, &s).unwrap();
|
||||||
assert!(load(&path, "vpn.example.com", "host-1", None).is_none());
|
assert!(load(&path, "vpn.example.com", "host-1").is_none());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -290,6 +290,53 @@ fn adapter_servers(index: u32) -> Vec<String> {
|
|||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore = "requires an isolated Windows test host and signed Wintun"]
|
||||||
|
fn lookup_without_an_nrpt_rule() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
use std::net::UdpSocket;
|
||||||
|
let adapter = Adapter::create()?;
|
||||||
|
let index = adapter.index;
|
||||||
|
let run = |script: &str| {
|
||||||
|
let out = std::process::Command::new("powershell.exe")
|
||||||
|
.args(["-NoProfile","-NonInteractive","-Command",script]).output().unwrap();
|
||||||
|
assert!(out.status.success(), "{}", String::from_utf8_lossy(&out.stderr));
|
||||||
|
String::from_utf8(out.stdout).unwrap()
|
||||||
|
};
|
||||||
|
run(&format!("Set-DnsClientServerAddress -ErrorAction Stop -InterfaceIndex {index} -ServerAddresses ('198.18.0.99','fd42:1235::99')"));
|
||||||
|
let baseline = adapter_servers(index);
|
||||||
|
assert!(baseline.iter().any(|s| s == "fd42:1235::99"));
|
||||||
|
let mut config = environment(index);
|
||||||
|
config.retain(|(key,_)| key != "CISCO_SPLIT_DNS");
|
||||||
|
config.iter_mut().find(|(key,_)| key=="INTERNAL_IP4_DNS").unwrap().1 = Some("192.0.2.2 198.18.0.53 fd42:1235::53".into());
|
||||||
|
let key = format!(r"SOFTWARE\GP Connect\Tests\Network{}", uuid::Uuid::new_v4().simple());
|
||||||
|
let mut net = NetworkConfigurator::new(&key)?;
|
||||||
|
net.configure("connect",&config)?;
|
||||||
|
run(&format!("$ErrorActionPreference='Stop'; Get-DnsClientNrptRule | Where-Object Comment -eq 'GPConnectJournal:{key}' | ForEach-Object {{ Remove-DnsClientNrptRule -Name $_.Name -Force }}; if (Get-DnsClientNrptPolicy -Effective | Where-Object {{ $_.Namespace -contains '.' }}) {{ throw 'Unexpected root rule' }}"));
|
||||||
|
let socket = UdpSocket::bind("192.0.2.2:53")?;
|
||||||
|
socket.set_read_timeout(Some(std::time::Duration::from_secs(20)))?;
|
||||||
|
let server = std::thread::spawn(move || -> io::Result<()> {
|
||||||
|
let mut buf = [0u8; 2048];
|
||||||
|
let qname = b"\x0bsupport-dns\x04test\x00\x00\x01\x00\x01";
|
||||||
|
loop {
|
||||||
|
let (n,from) = socket.recv_from(&mut buf)?;
|
||||||
|
if n < 12 + qname.len() || &buf[12..12+qname.len()] != qname { continue; }
|
||||||
|
let mut answer = buf[..2].to_vec();
|
||||||
|
answer.extend_from_slice(&[0x81,0x80,0,1,0,1,0,0,0,0]);
|
||||||
|
answer.extend_from_slice(qname);
|
||||||
|
answer.extend_from_slice(&[0xc0,0x0c,0,1,0,1,0,0,0,0,0,4,198,51,100,55]);
|
||||||
|
socket.send_to(&answer,from)?;
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
let result = run("(Resolve-DnsName support-dns.test. -Type A -DnsOnly -NoHostsFile -ErrorAction Stop).IPAddress");
|
||||||
|
assert_eq!(result.trim(), "198.51.100.55");
|
||||||
|
server.join().unwrap()?;
|
||||||
|
net.configure("disconnect",&[])?;
|
||||||
|
assert_eq!(adapter_servers(index),baseline);
|
||||||
|
println!("PASS: Windows resolved the fixture hostname through adapter DNS with no effective catch-all rule and restored pre-existing static IPv4 and IPv6 settings");
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
fn check_adapter_resolvers(index: u32, key: &str) -> io::Result<()> {
|
fn check_adapter_resolvers(index: u32, key: &str) -> io::Result<()> {
|
||||||
let split = environment(index);
|
let split = environment(index);
|
||||||
let mut full = split.clone();
|
let mut full = split.clone();
|
||||||
|
|||||||
Reference in new issue
Block a user