mirror of
https://github.com/EasyTier/EasyTier.git
synced 2026-09-02 17:15:43 +00:00
Introduce secure mode (part 1) (#1808)
Use noise protocol on handshake. Check peer's public key if needed. Also support rekey and replay attack prevention. E2EE and temporary password will be implemented based on this.
This commit is contained in:
@@ -41,6 +41,9 @@ message PeerConnInfo {
|
||||
bool is_client = 8;
|
||||
string network_name = 9;
|
||||
bool is_closed = 10;
|
||||
bytes noise_local_static_pubkey = 11;
|
||||
bytes noise_remote_static_pubkey = 12;
|
||||
peer_rpc.SecureAuthLevel secure_auth_level = 13;
|
||||
}
|
||||
|
||||
message PeerInfo {
|
||||
|
||||
@@ -81,6 +81,8 @@ message NetworkConfig {
|
||||
optional common.CompressionAlgoPb data_compress_algo = 52;
|
||||
optional string encryption_algorithm = 53;
|
||||
optional bool disable_tcp_hole_punching = 54;
|
||||
|
||||
common.SecureModeConfig secure_mode = 55;
|
||||
}
|
||||
|
||||
message PortForwardConfig {
|
||||
|
||||
@@ -230,3 +230,13 @@ message LimiterConfig {
|
||||
optional uint64 fill_duration_ms =
|
||||
3; // default 10ms, the period to fill the bucket
|
||||
}
|
||||
|
||||
message SecureModeConfig {
|
||||
bool enabled = 1;
|
||||
|
||||
// base64(X25519 private key), used by shared node to present a stable identity
|
||||
optional string local_private_key = 2;
|
||||
|
||||
// base64(X25519 public key), required if local_private_key is set
|
||||
optional string local_public_key = 3;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ use std::{
|
||||
};
|
||||
|
||||
use anyhow::Context;
|
||||
use base64::{prelude::BASE64_STANDARD, Engine as _};
|
||||
|
||||
use crate::tunnel::packet_def::CompressorAlgo;
|
||||
|
||||
@@ -360,3 +361,37 @@ impl fmt::Debug for Ipv6Addr {
|
||||
write!(f, "{}", std_ipv6_addr)
|
||||
}
|
||||
}
|
||||
|
||||
impl SecureModeConfig {
|
||||
pub fn private_key(&self) -> anyhow::Result<x25519_dalek::StaticSecret> {
|
||||
let local_private_key = self
|
||||
.local_private_key
|
||||
.as_ref()
|
||||
.ok_or_else(|| anyhow::anyhow!("local private key is not set"))?;
|
||||
let k = BASE64_STANDARD
|
||||
.decode(local_private_key)
|
||||
.with_context(|| format!("failed to decode private key: {}", local_private_key))?;
|
||||
// convert vec to 32b array
|
||||
let len = k.len();
|
||||
let k: [u8; 32] = k
|
||||
.try_into()
|
||||
.map_err(|_| anyhow::anyhow!("invalid private key length: {}", len))?;
|
||||
Ok(x25519_dalek::StaticSecret::from(k))
|
||||
}
|
||||
|
||||
pub fn public_key(&self) -> anyhow::Result<x25519_dalek::PublicKey> {
|
||||
let local_public_key = self
|
||||
.local_public_key
|
||||
.as_ref()
|
||||
.ok_or_else(|| anyhow::anyhow!("local public key is not set"))?;
|
||||
let k = BASE64_STANDARD
|
||||
.decode(local_public_key)
|
||||
.with_context(|| format!("failed to decode public key: {}", local_public_key))?;
|
||||
// convert vec to 32b array
|
||||
let len = k.len();
|
||||
let k: [u8; 32] = k
|
||||
.try_into()
|
||||
.map_err(|_| anyhow::anyhow!("invalid public key length: {}", len))?;
|
||||
Ok(x25519_dalek::PublicKey::from(k))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -251,10 +251,51 @@ message HandshakeRequest {
|
||||
uint32 version = 3;
|
||||
repeated string features = 4;
|
||||
string network_name = 5;
|
||||
bytes network_secret_digrest = 6;
|
||||
bytes network_secret_digest = 6;
|
||||
}
|
||||
|
||||
message KcpConnData {
|
||||
common.SocketAddr src = 1;
|
||||
common.SocketAddr dst = 4;
|
||||
}
|
||||
|
||||
enum SecureAuthLevel {
|
||||
None = 0;
|
||||
EncryptedUnauthenticated = 1;
|
||||
SharedNodePubkeyVerified = 2;
|
||||
NetworkSecretConfirmed = 3;
|
||||
}
|
||||
|
||||
enum PeerConnSessionActionPb {
|
||||
Join = 0;
|
||||
Sync = 1;
|
||||
Create = 2;
|
||||
}
|
||||
|
||||
message PeerConnNoiseMsg1Pb {
|
||||
uint32 version = 1;
|
||||
string a_network_name = 2;
|
||||
optional uint32 a_session_generation = 3;
|
||||
common.UUID a_conn_id = 4;
|
||||
string client_encryption_algorithm = 5;
|
||||
}
|
||||
|
||||
message PeerConnNoiseMsg2Pb {
|
||||
string b_network_name = 1;
|
||||
uint32 role_hint = 2;
|
||||
PeerConnSessionActionPb action = 3;
|
||||
uint32 b_session_generation = 4;
|
||||
optional bytes root_key_32 = 5;
|
||||
uint32 initial_epoch = 6;
|
||||
common.UUID b_conn_id = 7;
|
||||
common.UUID a_conn_id_echo = 8;
|
||||
optional bytes secret_proof_32 = 9;
|
||||
string server_encryption_algorithm = 10;
|
||||
}
|
||||
|
||||
message PeerConnNoiseMsg3Pb {
|
||||
common.UUID a_conn_id_echo = 1;
|
||||
common.UUID b_conn_id_echo = 2;
|
||||
optional bytes secret_proof_32 = 3;
|
||||
bytes secret_digest = 4;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user