Skip to content

Commit 4c12071

Browse files
authored
Merge pull request #392 from DefGuard/dev
Merge dev -> main (v1.2.2)
2 parents d57ee2a + 1f79b47 commit 4c12071

File tree

12 files changed

+226
-19
lines changed

12 files changed

+226
-19
lines changed

flake.lock

+92
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
{
2+
inputs = {
3+
nixpkgs.url = "nixpkgs";
4+
flake-utils.url = "github:numtide/flake-utils";
5+
rust-overlay.url = "github:oxalica/rust-overlay";
6+
};
7+
8+
outputs = { self, nixpkgs, flake-utils, rust-overlay }:
9+
flake-utils.lib.eachDefaultSystem (system:
10+
let
11+
pkgs = import nixpkgs {
12+
inherit system;
13+
overlays = [ rust-overlay.overlays.default ];
14+
};
15+
16+
toolchain = pkgs.rust-bin.stable.latest.default.override {
17+
extensions = ["rust-analyzer" "rust-src" "rustfmt" "clippy"];
18+
targets = ["wasm32-unknown-unknown"];
19+
};
20+
packages = with pkgs; [
21+
cargo
22+
cargo-tauri
23+
toolchain
24+
rust-analyzer-unwrapped
25+
nodejs_18
26+
nodePackages.pnpm
27+
trunk
28+
];
29+
nativeBuildPackages = with pkgs; [
30+
pkg-config
31+
dbus
32+
openssl
33+
glib
34+
gtk3
35+
libsoup
36+
webkitgtk_4_0
37+
librsvg
38+
protobuf
39+
libayatana-appindicator
40+
];
41+
libraries = with pkgs; [
42+
gtk3
43+
cairo
44+
gdk-pixbuf
45+
glib
46+
dbus
47+
openssl
48+
librsvg
49+
libsoup_3
50+
webkitgtk_4_0
51+
libayatana-appindicator
52+
];
53+
in {
54+
devShells.default = pkgs.mkShell {
55+
buildInputs = packages;
56+
nativeBuildInputs = nativeBuildPackages;
57+
shellHook = with pkgs; ''
58+
export LD_LIBRARY_PATH="${
59+
lib.makeLibraryPath libraries
60+
}:$LD_LIBRARY_PATH"
61+
export OPENSSL_INCLUDE_DIR="${openssl.dev}/include/openssl"
62+
export OPENSSL_LIB_DIR="${openssl.out}/lib"
63+
export OPENSSL_ROOT_DIR="${openssl.out}"
64+
export RUST_SRC_PATH="${toolchain}/lib/rustlib/src/rust/library"
65+
'';
66+
};
67+
});
68+
}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "defguard-client",
33
"private": false,
4-
"version": "1.2.1",
4+
"version": "1.2.2",
55
"type": "module",
66
"scripts": {
77
"dev": "npm-run-all --parallel vite typesafe-i18n",

src-tauri/Cargo.lock

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src-tauri/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ edition = "2021"
1111
homepage = "https://github.com/DefGuard/client"
1212
license-file = "../LICENSE.md"
1313
rust-version = "1.80"
14-
version = "1.2.1"
14+
version = "1.2.2"
1515

1616
[package]
1717
name = "defguard-client"

src-tauri/src/periodic/connection.rs

+21-10
Original file line numberDiff line numberDiff line change
@@ -134,17 +134,28 @@ pub async fn verify_active_connections(app_handle: AppHandle) {
134134
latest_stat.collected_at,
135135
peer_alive_period,
136136
) {
137-
// Check if there was any traffic since the connection was established.
138-
// If not, consider the location dead and disconnect it later without reconnecting.
137+
// Check if there was any traffic since the connection was established
138+
// If not and the connection was established longer than the peer_alive_period,
139+
// consider the location dead and disconnect it later without reconnecting.
140+
let time_since_connection = Utc::now() - con.start.and_utc();
139141
if latest_stat.collected_at < con.start {
140-
debug!(
141-
"There wasn't any activity for Location {} since its \
142-
connection at {}; considering it being dead and possibly \
143-
broken. It will be disconnected without a further automatic \
144-
reconnect.",
145-
con.location_id, con.start
146-
);
147-
locations_to_disconnect.push((con.location_id, false));
142+
if time_since_connection > peer_alive_period {
143+
debug!(
144+
"There wasn't any activity for Location {} since its \
145+
connection at {}; considering it being dead and possibly \
146+
broken. It will be terminated without a further automatic \
147+
reconnect.",
148+
con.location_id, con.start
149+
);
150+
locations_to_disconnect.push((con.location_id, false));
151+
} else {
152+
debug!(
153+
"There wasn't any activity for Location {} since its \
154+
connection at {}; The amount of time passed since the connection \
155+
is {time_since_connection}, the connection will be terminated when it reaches \
156+
{peer_alive_period}",
157+
con.location_id, con.start);
158+
}
148159
} else {
149160
debug!(
150161
"There wasn't any activity for Location {} for the last \

src-tauri/src/utils.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -842,8 +842,8 @@ async fn check_connection(
842842
) -> Result<(), Error> {
843843
let appstate = app_handle.state::<AppState>();
844844
let interface_name = get_interface_name(name);
845-
let service_name = format!("WireGuardTunnel${}", name);
846-
let service = match service_manager.open_service(&service_name, ServiceAccess::QUERY_CONFIG) {
845+
let service_name = format!("WireGuardTunnel${}", interface_name);
846+
let service = match service_manager.open_service(&service_name, ServiceAccess::QUERY_STATUS) {
847847
Ok(service) => service,
848848
Err(windows_service::Error::Winapi(err))
849849
if err.raw_os_error() == Some(ERROR_SERVICE_DOES_NOT_EXIST as i32) =>

src-tauri/tauri.conf.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
},
99
"package": {
1010
"productName": "defguard-client",
11-
"version": "1.2.1"
11+
"version": "1.2.2"
1212
},
1313
"tauri": {
1414
"systemTray": {

src/i18n/en/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ const en = {
5454
'Configuration for instance {instance: string} has changed. Disconnect from all locations to apply changes.',
5555
deadConDropped:
5656
'Detected that the {con_type: string} {interface_name: string} has disconnected, trying to reconnect...',
57+
noCookie: 'No defguard_proxy set-cookie received',
5758
},
5859
},
5960
components: {

src/i18n/i18n-types.ts

+8
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,10 @@ type RootTranslation = {
165165
* @param {string} interface_name
166166
*/
167167
deadConDropped: RequiredParams<'con_type' | 'interface_name'>
168+
/**
169+
* N​o​ ​d​e​f​g​u​a​r​d​_​p​r​o​x​y​ ​s​e​t​-​c​o​o​k​i​e​ ​r​e​c​e​i​v​e​d
170+
*/
171+
noCookie: string
168172
}
169173
}
170174
components: {
@@ -1762,6 +1766,10 @@ export type TranslationFunctions = {
17621766
* Detected that the {con_type} {interface_name} has disconnected, trying to reconnect...
17631767
*/
17641768
deadConDropped: (arg: { con_type: string, interface_name: string }) => LocalizedString
1769+
/**
1770+
* No defguard_proxy set-cookie received
1771+
*/
1772+
noCookie: () => LocalizedString
17651773
}
17661774
}
17671775
components: {

src/pages/client/pages/ClientAddInstancePage/components/AddInstanceFormCard/components/AddInstanceInitForm/AddInstanceInitForm.tsx

+18-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ export const AddInstanceInitForm = ({ nextStep }: Props) => {
102102
body: Body.json(data),
103103
})
104104
.then(async (res: Response<EnrollmentStartResponse | EnrollmentError>) => {
105-
const authCookie = res.headers['set-cookie'];
106105
if (!res.ok) {
107106
setIsLoading(false);
108107
error(JSON.stringify(res.data));
@@ -122,6 +121,24 @@ export const AddInstanceInitForm = ({ nextStep }: Props) => {
122121
}
123122
}
124123
}
124+
// There may be other set-cookies, set by e.g. a proxy
125+
// Get only the defguard_proxy cookie
126+
const authCookie = res.rawHeaders['set-cookie'].find((cookie) =>
127+
cookie.startsWith('defguard_proxy='),
128+
);
129+
if (!authCookie) {
130+
setIsLoading(false);
131+
error(
132+
LL.common.messages.errorWithMessage({
133+
message: LL.common.messages.noCookie(),
134+
}),
135+
);
136+
throw Error(
137+
LL.common.messages.errorWithMessage({
138+
message: LL.common.messages.noCookie(),
139+
}),
140+
);
141+
}
125142
debug('Response received with status OK');
126143
const r = res.data as EnrollmentStartResponse;
127144
// get client registered instances

src/pages/client/pages/ClientInstancePage/modals/UpdateInstanceModal/components/UpdateInstanceModalForm.tsx

+11-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,17 @@ export const UpdateInstanceModalForm = () => {
108108
proxy_api_url = proxy_api_url + '/api/v1';
109109
const instance = clientInstances.find((i) => i.uuid === enrollmentData.instance.id);
110110
if (instance) {
111-
const authCookie = res.headers['set-cookie'];
111+
const authCookie = res.rawHeaders['set-cookie'].find((cookie) =>
112+
cookie.startsWith('defguard_proxy='),
113+
);
114+
if (!authCookie) {
115+
toaster.error(
116+
LL.common.messages.errorWithMessage({
117+
message: LL.common.messages.noCookie(),
118+
}),
119+
);
120+
return;
121+
}
112122
headers['Cookie'] = authCookie;
113123
const instanceInfoResponse = await fetch<CreateDeviceResponse>(
114124
`${proxy_api_url}/enrollment/network_info`,

0 commit comments

Comments
 (0)