Skip to content

Commit

Permalink
Merge branch 'deps'
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkusPettersson98 committed Apr 25, 2024
2 parents 2865a03 + 33063c8 commit 84a249b
Show file tree
Hide file tree
Showing 18 changed files with 1,311 additions and 1,240 deletions.
1,270 changes: 673 additions & 597 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ log = "0.4"
shadowsocks = { version = "1.16" }
shadowsocks-service = { version = "1.16" }

windows-sys = "0.48.0"
windows-sys = "0.52.0"

chrono = { version = "0.4.26", default-features = false}
clap = { version = "4.4.18", features = ["cargo", "derive"] }
Expand Down
2 changes: 1 addition & 1 deletion mullvad-daemon/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ objc = { version = "0.2.7", features = ["exception", "verify_message"] }
[target.'cfg(windows)'.dependencies]
ctrlc = "3.0"
windows-service = "0.6.0"
winapi = { version = "0.3", features = ["winnt", "excpt"] }
winapi = { version = "0.3", features = ["winnt", "excpt", "winerror"] }
dirs = "5.0.1"
talpid-windows = { path = "../talpid-windows" }

Expand Down
5 changes: 2 additions & 3 deletions mullvad-daemon/src/migrations/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,12 @@ mod windows {
use talpid_types::ErrorExt;
use tokio::fs;
use windows_sys::Win32::{
Foundation::{ERROR_SUCCESS, HANDLE, PSID},
Foundation::{LocalFree, ERROR_SUCCESS, HLOCAL, PSID},
Security::{
Authorization::{GetNamedSecurityInfoW, SE_FILE_OBJECT, SE_OBJECT_TYPE},
IsWellKnownSid, WinBuiltinAdministratorsSid, WinLocalSystemSid,
OWNER_SECURITY_INFORMATION, SECURITY_DESCRIPTOR, SID, WELL_KNOWN_SID_TYPE,
},
System::Memory::LocalFree,
};

#[allow(non_camel_case_types)]
Expand Down Expand Up @@ -386,7 +385,7 @@ mod windows {

impl Drop for SecurityInformation {
fn drop(&mut self) {
unsafe { LocalFree(self.security_descriptor as HANDLE) };
unsafe { LocalFree(self.security_descriptor as HLOCAL) };
}
}

Expand Down
17 changes: 9 additions & 8 deletions mullvad-management-interface/src/types/conversions/account.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::types;
use chrono::TimeZone;
use chrono::DateTime;
use mullvad_types::account::{AccountData, VoucherSubmission};

use super::FromProtobufTypeError;
Expand All @@ -23,12 +23,12 @@ impl TryFrom<types::VoucherSubmission> for VoucherSubmission {
let new_expiry = submission
.new_expiry
.ok_or(FromProtobufTypeError::InvalidArgument("missing expiry"))?;
let ndt =
chrono::NaiveDateTime::from_timestamp_opt(new_expiry.seconds, new_expiry.nanos as u32)
.unwrap();

let new_expiry = DateTime::from_timestamp(new_expiry.seconds, new_expiry.nanos as u32)
.ok_or(FromProtobufTypeError::InvalidArgument("invalid timestamp"))?;

Ok(VoucherSubmission {
new_expiry: chrono::Utc.from_utc_datetime(&ndt),
new_expiry,
time_added: submission.seconds_added,
})
}
Expand All @@ -53,12 +53,13 @@ impl TryFrom<types::AccountData> for AccountData {
let expiry = data
.expiry
.ok_or(FromProtobufTypeError::InvalidArgument("missing expiry"))?;
let ndt =
chrono::NaiveDateTime::from_timestamp_opt(expiry.seconds, expiry.nanos as u32).unwrap();

let expiry = DateTime::from_timestamp(expiry.seconds, expiry.nanos as u32)
.ok_or(FromProtobufTypeError::InvalidArgument("invalid timestamp"))?;

Ok(AccountData {
id: data.id,
expiry: chrono::Utc.from_utc_datetime(&ndt),
expiry,
})
}
}
25 changes: 12 additions & 13 deletions mullvad-management-interface/src/types/conversions/device.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
use crate::types::{conversions::bytes_to_pubkey, proto, FromProtobufTypeError};
use chrono::TimeZone;
use chrono::DateTime;
use prost_types::Timestamp;

impl TryFrom<proto::Device> for mullvad_types::device::Device {
type Error = FromProtobufTypeError;

fn try_from(device: proto::Device) -> Result<Self, Self::Error> {
let created_seconds = device
.created
.ok_or(FromProtobufTypeError::InvalidArgument(
"missing 'created' field",
))?
.seconds;

let created = DateTime::from_timestamp(created_seconds, 0)
.ok_or(FromProtobufTypeError::InvalidArgument("invalid timestamp"))?;

Ok(mullvad_types::device::Device {
id: device.id,
name: device.name,
pubkey: bytes_to_pubkey(&device.pubkey)?,
hijack_dns: device.hijack_dns,
created: chrono::Utc.from_utc_datetime(
&chrono::NaiveDateTime::from_timestamp_opt(
device
.created
.ok_or(FromProtobufTypeError::InvalidArgument(
"missing 'created' field",
))?
.seconds,
0,
)
.unwrap(),
),
created,
})
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::FromProtobufTypeError;
use crate::types::proto;
use chrono::TimeZone;
use chrono::DateTime;
use prost_types::Timestamp;

impl From<mullvad_types::wireguard::PublicKey> for proto::PublicKey {
Expand All @@ -24,13 +24,14 @@ impl TryFrom<proto::PublicKey> for mullvad_types::wireguard::PublicKey {
.ok_or(FromProtobufTypeError::InvalidArgument(
"missing 'created' timestamp",
))?;
let ndt = chrono::NaiveDateTime::from_timestamp_opt(created.seconds, created.nanos as u32)
.unwrap();

let created = DateTime::from_timestamp(created.seconds, created.nanos as u32)
.ok_or(FromProtobufTypeError::InvalidArgument("invalid timestamp"))?;

Ok(mullvad_types::wireguard::PublicKey {
key: talpid_types::net::wireguard::PublicKey::try_from(public_key.key.as_slice())
.map_err(|_| FromProtobufTypeError::InvalidArgument("invalid wireguard key"))?,
created: chrono::Utc.from_utc_datetime(&ndt),
created,
})
}
}
Expand Down
10 changes: 5 additions & 5 deletions mullvad-paths/src/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ use windows_sys::{
core::{GUID, PWSTR},
Win32::{
Foundation::{
CloseHandle, ERROR_INSUFFICIENT_BUFFER, ERROR_SUCCESS, GENERIC_ALL, GENERIC_READ,
HANDLE, INVALID_HANDLE_VALUE, LUID, S_OK,
CloseHandle, LocalFree, ERROR_INSUFFICIENT_BUFFER, ERROR_SUCCESS, GENERIC_ALL,
GENERIC_READ, HANDLE, INVALID_HANDLE_VALUE, LUID, S_OK,
},
Security::{
self, AdjustTokenPrivileges,
Expand All @@ -31,7 +31,6 @@ use windows_sys::{
Storage::FileSystem::MAX_SID_SIZE,
System::{
Com::CoTaskMemFree,
Memory::LocalFree,
ProcessStatus::EnumProcesses,
Threading::{
GetCurrentThread, OpenProcess, OpenProcessToken, OpenThreadToken,
Expand Down Expand Up @@ -244,7 +243,7 @@ fn set_security_permissions(path: &Path) -> Result<()> {
)
};

unsafe { LocalFree(new_dacl as isize) };
unsafe { LocalFree(new_dacl.cast()) };

if result != ERROR_SUCCESS {
Err(Error::SetDirPermissionFailed(
Expand Down Expand Up @@ -402,7 +401,8 @@ fn get_known_folder_path(
user_token: HANDLE,
) -> std::io::Result<PathBuf> {
let mut folder_path: PWSTR = ptr::null_mut();
let status = unsafe { SHGetKnownFolderPath(folder_id, flags, user_token, &mut folder_path) };
let status =
unsafe { SHGetKnownFolderPath(folder_id, flags as u32, user_token, &mut folder_path) };
let result = if status == S_OK {
let path = unsafe { WideCStr::from_ptr_str(folder_path) };
Ok(PathBuf::from(path.to_os_string()))
Expand Down
6 changes: 2 additions & 4 deletions talpid-core/src/dns/windows/iphlpapi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@ use windows_sys::{
core::GUID,
s, w,
Win32::{
Foundation::{ERROR_PROC_NOT_FOUND, WIN32_ERROR},
Foundation::{FreeLibrary, ERROR_PROC_NOT_FOUND, WIN32_ERROR},
NetworkManagement::IpHelper::{
DNS_INTERFACE_SETTINGS, DNS_INTERFACE_SETTINGS_VERSION1, DNS_SETTING_IPV6,
DNS_SETTING_NAMESERVER,
},
System::LibraryLoader::{
FreeLibrary, GetProcAddress, LoadLibraryExW, LOAD_LIBRARY_SEARCH_SYSTEM32,
},
System::LibraryLoader::{GetProcAddress, LoadLibraryExW, LOAD_LIBRARY_SEARCH_SYSTEM32},
},
};

Expand Down
3 changes: 1 addition & 2 deletions talpid-core/src/split_tunnel/windows/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ use std::{
};
use windows_sys::Win32::{
Foundation::{CloseHandle, ERROR_INSUFFICIENT_BUFFER, FILETIME, HANDLE},
Storage::FileSystem::{GetFinalPathNameByHandleW, QueryDosDeviceW},
Storage::FileSystem::{GetFinalPathNameByHandleW, QueryDosDeviceW, VOLUME_NAME_NT},
System::{
ProcessStatus::GetProcessImageFileNameW,
Threading::{GetProcessTimes, OpenProcess, PROCESS_QUERY_LIMITED_INFORMATION},
WindowsProgramming::VOLUME_NAME_NT,
},
};

Expand Down
6 changes: 2 additions & 4 deletions talpid-openvpn/src/wintun.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ use widestring::{U16CStr, U16CString};
use windows_sys::{
core::GUID,
Win32::{
Foundation::HMODULE,
Foundation::{FreeLibrary, HMODULE},
NetworkManagement::{IpHelper::ConvertInterfaceLuidToGuid, Ndis::NET_LUID_LH},
System::{
Com::StringFromGUID2,
LibraryLoader::{
FreeLibrary, GetProcAddress, LoadLibraryExW, LOAD_WITH_ALTERED_SEARCH_PATH,
},
LibraryLoader::{GetProcAddress, LoadLibraryExW, LOAD_WITH_ALTERED_SEARCH_PATH},
Registry::REG_SAM_FLAGS,
},
},
Expand Down
2 changes: 1 addition & 1 deletion talpid-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ workspace = true
[dependencies]
serde = { version = "1.0", features = ["derive"] }
ipnetwork = "0.16"
base64 = "0.13"
base64 = "0.22.0"
x25519-dalek = { version = "2.0.1", features = ["static_secrets", "zeroize", "getrandom"] }
thiserror = { workspace = true }
zeroize = "1.5.7"
Expand Down
13 changes: 7 additions & 6 deletions talpid-types/src/net/wireguard.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::net::{Endpoint, GenericTunnelOptions, TransportProtocol};
use base64::{engine::general_purpose::STANDARD, Engine};
use ipnetwork::IpNetwork;
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use std::{
Expand Down Expand Up @@ -105,7 +106,7 @@ impl PrivateKey {
}

pub fn to_base64(&self) -> String {
base64::encode(self.0.to_bytes())
STANDARD.encode(self.0.to_bytes())
}

pub fn from_base64(key: &str) -> Result<Self, InvalidKey> {
Expand Down Expand Up @@ -135,7 +136,7 @@ impl fmt::Debug for PrivateKey {

impl fmt::Display for PrivateKey {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", &base64::encode((self.0).to_bytes()))
write!(f, "{}", &STANDARD.encode((self.0).to_bytes()))
}
}

Expand Down Expand Up @@ -177,7 +178,7 @@ impl PublicKey {
}

pub fn to_base64(&self) -> String {
base64::encode(self.as_bytes())
STANDARD.encode(self.as_bytes())
}

pub fn from_base64(key: &str) -> Result<Self, InvalidKey> {
Expand Down Expand Up @@ -272,15 +273,15 @@ impl From<Box<[u8; 32]>> for PresharedKey {

impl fmt::Debug for PresharedKey {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", &base64::encode(self.as_bytes()))
write!(f, "{}", &STANDARD.encode(self.as_bytes()))
}
}

fn serialize_key<S>(key: &[u8; 32], serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
serializer.serialize_str(&base64::encode(key))
serializer.serialize_str(&STANDARD.encode(key))
}

fn deserialize_key<'de, D, K>(deserializer: D) -> Result<K, D::Error>
Expand All @@ -295,7 +296,7 @@ where
}

fn key_from_base64<K: From<[u8; 32]>>(key: &str) -> Result<K, InvalidKey> {
let bytes = base64::decode(key).map_err(InvalidKey::Format)?;
let bytes = STANDARD.decode(key).map_err(InvalidKey::Format)?;
if bytes.len() != 32 {
return Err(InvalidKey::Length(bytes.len()));
}
Expand Down
1 change: 0 additions & 1 deletion talpid-wireguard/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ workspace = true

[dependencies]
thiserror = { workspace = true }
base64 = "0.13"
futures = "0.3.15"
hex = "0.4"
ipnetwork = "0.16"
Expand Down
2 changes: 1 addition & 1 deletion talpid-wireguard/src/ping_monitor/icmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl Pinger {
// Asserting that `index` is non-zero since otherwise `if_nametoindex` would have return
// an error
socket
.bind_device_by_index(std::num::NonZeroU32::new(index))
.bind_device_by_index_v4(std::num::NonZeroU32::new(index))
.map_err(Error::BindSocketByDevice)?;

Ok(())
Expand Down
6 changes: 2 additions & 4 deletions talpid-wireguard/src/wireguard_nt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,12 @@ use widestring::{U16CStr, U16CString};
use windows_sys::{
core::GUID,
Win32::{
Foundation::{BOOL, ERROR_MORE_DATA, HMODULE},
Foundation::{FreeLibrary, BOOL, ERROR_MORE_DATA, HMODULE},
NetworkManagement::Ndis::NET_LUID_LH,
Networking::WinSock::{
ADDRESS_FAMILY, AF_INET, AF_INET6, IN6_ADDR, IN_ADDR, SOCKADDR_INET,
},
System::LibraryLoader::{
FreeLibrary, GetProcAddress, LoadLibraryExW, LOAD_WITH_ALTERED_SEARCH_PATH,
},
System::LibraryLoader::{GetProcAddress, LoadLibraryExW, LOAD_WITH_ALTERED_SEARCH_PATH},
},
};

Expand Down
Loading

0 comments on commit 84a249b

Please sign in to comment.