mirror of
https://github.com/rustdesk/rustdesk.git
synced 2026-11-03 16:32:22 +00:00
Allow trusted devices for direct IP connections (#16778)
* Allow trusted devices for direct IP connections Signed-off-by: fufesou <linlong1266@gmail.com> * test: preserve existing V2 trusted-device credentials Signed-off-by: fufesou <linlong1266@gmail.com> --------- Signed-off-by: fufesou <linlong1266@gmail.com>
This commit is contained in:
1 parent
94c321d05c
commit
c5201d600b
4 files changed
+47
-5
No files matched your search
@@ -9,7 +9,7 @@ use base::message_proto::LoginResponse;
|
||||
impl Connection {
|
||||
pub(super) async fn begin_trusted_device(&mut self) -> bool {
|
||||
if self.conn_audit_primary_auth != ConnAuditPrimaryAuth::PermanentPassword
|
||||
|| !self.stream.is_secured()
|
||||
|| (!self.stream.is_secured() && !crate::common::is_direct_ip_access(&self.lr.username))
|
||||
|| self.require_2fa.is_none()
|
||||
|| self.from_switch
|
||||
|| !hbb_common::config::Config::get_bool_option(
|
||||
|
||||
@@ -52,6 +52,12 @@ impl Session {
|
||||
secured: bool,
|
||||
key: Option<&[u8]>,
|
||||
) -> ResultType<Self> {
|
||||
if crate::common::is_direct_ip_access(login.get_id()) {
|
||||
return Ok(Self {
|
||||
credentials: Some(Credentials::direct_ip(login.get_id())),
|
||||
..Default::default()
|
||||
});
|
||||
}
|
||||
let Some(key) = key.filter(|_| secured) else {
|
||||
return Ok(Self::default());
|
||||
};
|
||||
@@ -137,7 +143,7 @@ impl Session {
|
||||
#[derive(Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
struct Issuer {
|
||||
namespace: String,
|
||||
public_key: [u8; TOKEN_BYTES],
|
||||
public_key: Option<[u8; TOKEN_BYTES]>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
@@ -153,14 +159,26 @@ pub(super) struct Credentials {
|
||||
}
|
||||
|
||||
impl Credentials {
|
||||
fn direct_ip(peer_id: &str) -> Self {
|
||||
Self {
|
||||
peer_id: peer_id.to_owned(),
|
||||
issuer: Issuer {
|
||||
namespace: format!("direct-ip:{peer_id}"),
|
||||
public_key: None,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new(peer_id: String, namespace: String, public_key: &[u8]) -> ResultType<Self> {
|
||||
Ok(Self {
|
||||
peer_id,
|
||||
issuer: Issuer {
|
||||
namespace,
|
||||
public_key: public_key
|
||||
.try_into()
|
||||
.map_err(|_| anyhow!("Invalid trusted host public key"))?,
|
||||
public_key: Some(
|
||||
public_key
|
||||
.try_into()
|
||||
.map_err(|_| anyhow!("Invalid trusted host public key"))?,
|
||||
),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ use hbb_common::{
|
||||
use std::fs;
|
||||
|
||||
mod configuration;
|
||||
mod credentials;
|
||||
mod recovery;
|
||||
|
||||
const PASSWORD: &str = "permanent-test-password";
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
use super::*;
|
||||
use hbb_common::password_security::symmetric_crypt;
|
||||
|
||||
#[test]
|
||||
fn id_credentials_saved_before_direct_ip_support_remain_readable() {
|
||||
const NAMESPACE: &str = "[\"rs.example.com\"]";
|
||||
const PUBLIC_KEY: [u8; TOKEN_BYTES] = [1; TOKEN_BYTES];
|
||||
|
||||
initialize_config();
|
||||
let peer_id = uuid::Uuid::new_v4().to_string();
|
||||
let token = random_token().unwrap();
|
||||
let saved = serde_json::json!({
|
||||
"issuer": {
|
||||
"namespace": NAMESPACE,
|
||||
"public_key": PUBLIC_KEY,
|
||||
},
|
||||
"ciphertext": symmetric_crypt(&token, true).unwrap(),
|
||||
});
|
||||
PeerConfig::set_trusted_device_v2(&peer_id, saved.to_string(), Default::default()).unwrap();
|
||||
|
||||
let credentials = Credentials::new(peer_id, NAMESPACE.into(), &PUBLIC_KEY).unwrap();
|
||||
assert_eq!(credentials.load().unwrap(), Some(token.to_vec()));
|
||||
}
|
||||
Reference in new issue
Block a user