Skip to content

Commit f18937d

Browse files
server: Add GNOME feature
Always disabling the prompter
1 parent 31dbec7 commit f18937d

3 files changed

Lines changed: 42 additions & 23 deletions

File tree

server/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ version.workspace = true
1111

1212
[dependencies]
1313
ashpd = {workspace = true, features = ["backend", "tracing"]}
14-
base64 = "0.22"
14+
base64 = {version = "0.22", optional = true}
1515
caps = "0.5"
1616
clap.workspace = true
1717
enumflags2 = "0.7"
@@ -37,12 +37,15 @@ zeroize.workspace = true
3737

3838
[features]
3939
default = ["native_crypto"]
40+
gnome = ["dep:base64"]
4041
native_crypto = [
42+
"gnome",
4143
"dep:hkdf",
4244
"dep:sha2",
4345
"oo7/native_crypto"
4446
]
4547
openssl_crypto = [
48+
"gnome",
4649
"dep:openssl",
4750
"oo7/openssl_crypto"
4851
]

server/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
mod capability;
22
mod collection;
33
mod error;
4+
#[cfg(feature = "gnome")]
45
mod gnome;
56
mod item;
67
mod pam_listener;

server/src/tests.rs

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
use std::{collections::HashMap, sync::Arc};
22

3+
#[cfg(feature = "gnome")]
34
use base64::Engine;
45
use oo7::{Secret, crypto, dbus};
56
use zbus::zvariant::{ObjectPath, Optional, Value};
67

7-
use crate::{
8-
gnome::{
9-
prompter::{PromptType, Properties, Reply},
10-
secret_exchange,
11-
},
12-
service::Service,
8+
#[cfg(feature = "gnome")]
9+
use crate::gnome::{
10+
prompter::{PromptType, Properties, Reply},
11+
secret_exchange,
1312
};
13+
use crate::service::Service;
1414

1515
/// Helper to create a peer-to-peer connection pair using Unix socket
1616
async fn create_p2p_connection()
@@ -40,6 +40,7 @@ pub(crate) struct TestServiceSetup {
4040
pub server_public_key: Option<oo7::Key>,
4141
pub keyring_secret: Option<oo7::Secret>,
4242
pub aes_key: Option<Arc<oo7::Key>>,
43+
#[cfg(feature = "gnome")]
4344
pub mock_prompter: MockPrompterService,
4445
}
4546

@@ -71,12 +72,14 @@ impl TestServiceSetup {
7172
let server = Service::run_with_connection(server_conn.clone(), secret.clone()).await?;
7273

7374
// Create and serve the mock prompter
74-
let mock_prompter = MockPrompterService::new();
75-
client_conn
76-
.object_server()
77-
.at("/org/gnome/keyring/Prompter", mock_prompter.clone())
78-
.await?;
79-
75+
#[cfg(feature = "gnome")]
76+
{
77+
let mock_prompter = MockPrompterService::new();
78+
client_conn
79+
.object_server()
80+
.at("/org/gnome/keyring/Prompter", mock_prompter.clone())
81+
.await?;
82+
};
8083
// Give the server a moment to fully initialize
8184
tokio::time::sleep(tokio::time::Duration::from_millis(50)).await;
8285

@@ -96,6 +99,7 @@ impl TestServiceSetup {
9699
collections,
97100
server_public_key,
98101
aes_key: None,
102+
#[cfg(feature = "gnome")]
99103
mock_prompter,
100104
})
101105
}
@@ -114,11 +118,14 @@ impl TestServiceSetup {
114118
let server = Service::run_with_connection(server_conn.clone(), secret.clone()).await?;
115119

116120
// Create and serve the mock prompter
117-
let mock_prompter = MockPrompterService::new();
118-
client_conn
119-
.object_server()
120-
.at("/org/gnome/keyring/Prompter", mock_prompter.clone())
121-
.await?;
121+
#[cfg(feature = "gnome")]
122+
{
123+
let mock_prompter = MockPrompterService::new();
124+
client_conn
125+
.object_server()
126+
.at("/org/gnome/keyring/Prompter", mock_prompter.clone())
127+
.await?;
128+
};
122129

123130
// Give the server a moment to fully initialize
124131
tokio::time::sleep(tokio::time::Duration::from_millis(50)).await;
@@ -147,6 +154,7 @@ impl TestServiceSetup {
147154
collections,
148155
server_public_key,
149156
aes_key: Some(Arc::new(aes_key)),
157+
#[cfg(feature = "gnome")]
150158
mock_prompter,
151159
})
152160
}
@@ -173,11 +181,14 @@ impl TestServiceSetup {
173181
let discovered = service.discover_keyrings(secret.clone()).await?;
174182
service.initialize(server_conn, discovered, false).await?;
175183

176-
let mock_prompter = MockPrompterService::new();
177-
client_conn
178-
.object_server()
179-
.at("/org/gnome/keyring/Prompter", mock_prompter.clone())
180-
.await?;
184+
#[cfg(feature = "gnome")]
185+
{
186+
let mock_prompter = MockPrompterService::new();
187+
client_conn
188+
.object_server()
189+
.at("/org/gnome/keyring/Prompter", mock_prompter.clone())
190+
.await?;
191+
};
181192

182193
tokio::time::sleep(tokio::time::Duration::from_millis(50)).await;
183194

@@ -197,6 +208,7 @@ impl TestServiceSetup {
197208
collections,
198209
server_public_key,
199210
aes_key: None,
211+
#[cfg(feature = "gnome")]
200212
mock_prompter,
201213
})
202214
}
@@ -206,6 +218,7 @@ impl TestServiceSetup {
206218
///
207219
/// This simulates the GNOME System Prompter for testing without requiring
208220
/// the actual GNOME keyring prompter service to be running.
221+
#[cfg(feature = "gnome")]
209222
#[derive(Debug, Clone)]
210223
pub(crate) struct MockPrompterService {
211224
/// The password to use for unlock prompts (simulates user input)
@@ -216,6 +229,7 @@ pub(crate) struct MockPrompterService {
216229
password_queue: Arc<tokio::sync::Mutex<Vec<oo7::Secret>>>,
217230
}
218231

232+
#[cfg(feature = "gnome")]
219233
impl MockPrompterService {
220234
pub fn new() -> Self {
221235
Self {
@@ -237,6 +251,7 @@ impl MockPrompterService {
237251
}
238252
}
239253

254+
#[cfg(feature = "gnome")]
240255
#[zbus::interface(name = "org.gnome.keyring.internal.Prompter")]
241256
impl MockPrompterService {
242257
async fn begin_prompting(

0 commit comments

Comments
 (0)