Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
name = "wiretun"
description = "WireGuard Library"
version = "0.5.0"
authors = ["zarvd <jialun.cai@pm.me>"]
authors = ["Jialun Cai <jialun.cai@pm.me>"]
keywords = ["wireguard", "networking"]
repository = "https://github.com/clnv/wiretun"
homepage = "https://github.com/clnv/wiretun"
documentation = "https://docs.rs/wiretun"
license = "Apache-2.0"
edition = "2024"
edition = "2021"

[features]
default = ["native"]
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# WireTun

[<img alt="github" height="20" src="https://img.shields.io/badge/github-zarvd/wiretun-8da0cb?style=for-the-badge&labelColor=555555&logo=github">](https://github.com/zarvd/wiretun)
[<img alt="github" height="20" src="https://img.shields.io/badge/github-clnv/wiretun-8da0cb?style=for-the-badge&labelColor=555555&logo=github">](https://github.com/clnv/wiretun)
[<img alt="crates.io" height="20" src="https://img.shields.io/crates/v/wiretun.svg?style=for-the-badge&color=fc8d62&logo=rust">](https://crates.io/crates/wiretun)
[<img alt="docs.rs" height="20" src="https://img.shields.io/docsrs/wiretun?style=for-the-badge">](https://docs.rs/wiretun)
[<img alt="build status" height="20" src="https://img.shields.io/github/actions/workflow/status/zarvd/wiretun/ci.yml?branch=master&style=for-the-badge">](https://github.com/zarvd/wiretun/actions?query%3Amaster)
[<img alt="dependency status" height="20" src="https://deps.rs/repo/github/zarvd/wiretun/status.svg?style=for-the-badge&t=0">](https://deps.rs/repo/github/zarvd/wiretun)
[<img alt="build status" height="20" src="https://img.shields.io/github/actions/workflow/status/clnv/wiretun/ci.yml?branch=master&style=for-the-badge">](https://github.com/clnv/wiretun/actions?query%3Amaster)
[<img alt="dependency status" height="20" src="https://deps.rs/repo/github/clnv/wiretun/status.svg?style=for-the-badge&t=0">](https://deps.rs/repo/github/clnv/wiretun)

This library provides a cross-platform, asynchronous (with [Tokio](https://tokio.rs/)) [WireGuard](https://www.wireguard.com/) implementation.

Expand Down
4 changes: 2 additions & 2 deletions src/device/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ use tokio::task::JoinHandle;
use tokio_util::sync::CancellationToken;
use tracing::{debug, error, warn};

use super::DeviceInner;
use super::inbound::{Endpoint, Transport};
use super::peer::InboundEvent;
use crate::Tun;
use super::DeviceInner;
use crate::noise::crypto::LocalStaticSecret;
use crate::noise::handshake::{Cookie, IncomingInitiation};
use crate::noise::protocol;
use crate::noise::protocol::Message;
use crate::Tun;

pub(super) struct DeviceHandle {
token: CancellationToken,
Expand Down
2 changes: 1 addition & 1 deletion src/device/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ use tokio::sync::Mutex as AsyncMutex;
use tokio_util::sync::CancellationToken;
use tracing::debug;

use crate::Tun;
use crate::noise::crypto::LocalStaticSecret;
use crate::noise::handshake::Cookie;
use crate::Tun;
use handle::DeviceHandle;
use inbound::Inbound;
use peer::{Peer, PeerIndex, Session};
Expand Down
6 changes: 3 additions & 3 deletions src/device/peer/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ use tokio_util::sync::CancellationToken;
use tracing::{debug, info, warn};

use super::{InboundEvent, InboundRx, OutboundEvent, OutboundRx, Peer, Session};
use crate::Tun;
use crate::device::{Endpoint, Transport};
use crate::noise::handshake::IncomingInitiation;
use crate::noise::protocol::{
self, COOKIE_REPLY_PACKET_SIZE, CookieReply, HANDSHAKE_RESPONSE_PACKET_SIZE, HandshakeResponse,
TransportData,
self, CookieReply, HandshakeResponse, TransportData, COOKIE_REPLY_PACKET_SIZE,
HANDSHAKE_RESPONSE_PACKET_SIZE,
};
use crate::Tun;

pub(crate) struct PeerHandle {
token: CancellationToken,
Expand Down
4 changes: 2 additions & 2 deletions src/device/peer/handshake.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use super::session::{Session, SessionIndex};
use crate::noise::protocol::HandshakeResponse;
use crate::noise::{
Error,
crypto::{PeerStaticSecret, kdf2},
crypto::{kdf2, PeerStaticSecret},
handshake::{
IncomingInitiation, IncomingResponse, MacGenerator, OutgoingInitiation, OutgoingResponse,
},
Error,
};

enum State {
Expand Down
2 changes: 1 addition & 1 deletion src/device/peer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ use std::time::Duration;
use tokio::sync::mpsc;
use tracing::{debug, warn};

use crate::Tun;
use crate::device::inbound::{Endpoint, Transport};
use crate::noise::crypto;
use crate::noise::crypto::PeerStaticSecret;
use crate::noise::handshake::IncomingInitiation;
use crate::noise::protocol;
use crate::Tun;
use handshake::Handshake;
use monitor::PeerMonitor;
use session::{ActiveSession, SessionIndex};
Expand Down
2 changes: 1 addition & 1 deletion src/noise/crypto.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use blake2::{
Blake2s256, Blake2sMac, Digest,
digest::{FixedOutput, Mac, Update},
Blake2s256, Blake2sMac, Digest,
};
use rand_core::OsRng;

Expand Down
2 changes: 1 addition & 1 deletion src/noise/handshake/cookie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use bytes::{BufMut, BytesMut};
use rand_core::{OsRng, RngCore};

use super::{LABEL_COOKIE, LABEL_MAC1};
use crate::noise::crypto::{LocalStaticSecret, PeerStaticSecret, hash, mac, xaead_encrypt};
use crate::noise::crypto::{hash, mac, xaead_encrypt, LocalStaticSecret, PeerStaticSecret};

const MESSAGE_TYPE_COOKIE_REPLY: u8 = 3u8;
const PACKET_SIZE: usize = 64;
Expand Down
4 changes: 2 additions & 2 deletions src/noise/handshake/initiation.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use bytes::{BufMut, BytesMut};

use super::{CONSTRUCTION, IDENTIFIER, MacGenerator};
use super::{MacGenerator, CONSTRUCTION, IDENTIFIER};
use crate::noise::crypto::{EphemeralPrivateKey, LocalStaticSecret, PeerStaticSecret, PublicKey};
use crate::noise::protocol::HandshakeInitiation;
use crate::noise::{
Error,
crypto::{aead_decrypt, aead_encrypt, gen_ephemeral_key, hash, kdf1, kdf2},
timestamp::Timestamp,
Error,
};

const MESSAGE_TYPE_HANDSHAKE_INITIATION: u8 = 1u8;
Expand Down
6 changes: 3 additions & 3 deletions src/noise/handshake/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ use bytes::{BufMut, BytesMut};
use super::{IncomingInitiation, MacGenerator, OutgoingInitiation};
use crate::noise::protocol::HandshakeResponse;
use crate::noise::{
Error,
crypto::{
EphemeralPrivateKey, PeerStaticSecret, PublicKey, aead_decrypt, aead_encrypt,
gen_ephemeral_key, hash, kdf1, kdf3,
aead_decrypt, aead_encrypt, gen_ephemeral_key, hash, kdf1, kdf3, EphemeralPrivateKey,
PeerStaticSecret, PublicKey,
},
Error,
};

const MESSAGE_TYPE_HANDSHAKE_RESPONSE: u8 = 2u8;
Expand Down
4 changes: 2 additions & 2 deletions src/tun/linux/sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use std::mem;
use std::os::fd::{AsRawFd, RawFd};

use libc::{__c_anonymous_ifr_ifru, c_char, ifreq};
use nix::fcntl::{FcntlArg, OFlag, fcntl};
use nix::sys::socket::{AddressFamily, SockFlag, SockType, socket};
use nix::fcntl::{fcntl, FcntlArg, OFlag};
use nix::sys::socket::{socket, AddressFamily, SockFlag, SockType};
use nix::{ioctl_read_bad, ioctl_write_ptr_bad};

use crate::tun::Error;
Expand Down
4 changes: 2 additions & 2 deletions src/tun/linux/tun.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ use nix::sys::stat::Mode;
use tokio::io::unix::AsyncFd;
use tracing::debug;

use crate::Tun;
use crate::tun::Error;
use crate::tun::linux::sys::{self, get_mtu, ioctl_tun_set_iff, set_mtu, set_nonblocking};
use crate::tun::Error;
use crate::Tun;

const DEVICE_PATH: &str = "/dev/net/tun";

Expand Down
2 changes: 1 addition & 1 deletion src/tun/macos/sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::os::fd::RawFd;
use std::{io, mem, ptr};

use libc::*;
use nix::fcntl::{FcntlArg, OFlag, fcntl};
use nix::fcntl::{fcntl, FcntlArg, OFlag};
use nix::{ioctl_read_bad, ioctl_write_ptr_bad};

use crate::tun::Error;
Expand Down
2 changes: 1 addition & 1 deletion src/uapi/connection.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use bytes::Bytes;
use std::collections::HashSet;
use tokio::io::{AsyncBufReadExt, AsyncReadExt, AsyncWriteExt, BufReader};
use tokio::net::UnixStream;
use tokio::net::unix::{OwnedReadHalf, OwnedWriteHalf};
use tokio::net::UnixStream;
use tracing::debug;

use super::{Error, Request, Response, SetDevice, SetPeer};
Expand Down
2 changes: 1 addition & 1 deletion src/uapi/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use std::time::SystemTime;

use bytes::{BufMut, Bytes, BytesMut};

use crate::Cidr;
use crate::noise::crypto;
use crate::Cidr;

pub enum Request {
Get,
Expand Down
2 changes: 1 addition & 1 deletion tests/support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::sync::{Arc, Mutex as StdMutex};

use async_trait::async_trait;
use rand_core::OsRng;
use tokio::sync::{Mutex, mpsc};
use tokio::sync::{mpsc, Mutex};

use wiretun::noise::crypto::LocalStaticSecret;
use wiretun::*;
Expand Down
Loading