Skip to content

Commit 6ca8010

Browse files
authored
Merge pull request #192 from hug-dev/socket-path
Modify socket path
2 parents 73da496 + 5892795 commit 6ca8010

File tree

8 files changed

+1693
-26
lines changed

8 files changed

+1693
-26
lines changed

Cargo.lock

+1,666
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

e2e_tests/src/lib.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use parsec_client::core::interface::operations::psa_key_attributes::{
1919
Attributes, Lifetime, Policy, Type, UsageFlags,
2020
};
2121
use parsec_client::core::interface::requests::{Opcode, ProviderID, ResponseStatus, Result};
22+
use parsec_client::core::secrecy::{ExposeSecret, Secret};
2223
use parsec_client::error::Error;
2324
use std::collections::HashSet;
2425
use std::time::Duration;
@@ -48,7 +49,9 @@ impl TestClient {
4849
/// a call to `list_providers`, followed by choosing the first non-Core provider.
4950
pub fn new() -> TestClient {
5051
let mut client = TestClient {
51-
basic_client: BasicClient::new(AuthenticationData::AppIdentity(String::from("root"))),
52+
basic_client: BasicClient::new(AuthenticationData::AppIdentity(Secret::new(
53+
String::from("root"),
54+
))),
5255
created_keys: Some(HashSet::new()),
5356
};
5457

@@ -88,13 +91,13 @@ impl TestClient {
8891
/// Set the client authentication string.
8992
pub fn set_auth(&mut self, auth: String) {
9093
self.basic_client
91-
.set_auth_data(AuthenticationData::AppIdentity(auth));
94+
.set_auth_data(AuthenticationData::AppIdentity(Secret::new(auth)));
9295
}
9396

9497
/// Get client authentication string.
9598
pub fn auth(&self) -> String {
9699
if let AuthenticationData::AppIdentity(app_name) = self.basic_client.auth_data() {
97-
app_name
100+
app_name.expose_secret().to_string()
98101
} else {
99102
panic!("Client should always be using AppIdentity-based authentication");
100103
}
@@ -162,7 +165,7 @@ impl TestClient {
162165
data: Vec<u8>,
163166
) -> Result<()> {
164167
self.basic_client
165-
.psa_import_key(key_name.clone(), data, attributes)
168+
.psa_import_key(key_name.clone(), &data, attributes)
166169
.map_err(convert_error)?;
167170

168171
let provider = self.provider().unwrap();
@@ -239,7 +242,7 @@ impl TestClient {
239242
hash: Vec<u8>,
240243
) -> Result<Vec<u8>> {
241244
self.basic_client
242-
.psa_sign_hash(key_name, hash, alg)
245+
.psa_sign_hash(key_name, &hash, alg)
243246
.map_err(convert_error)
244247
}
245248

@@ -263,7 +266,7 @@ impl TestClient {
263266
signature: Vec<u8>,
264267
) -> Result<()> {
265268
self.basic_client
266-
.psa_verify_hash(key_name, hash, alg, signature)
269+
.psa_verify_hash(key_name, &hash, alg, &signature)
267270
.map_err(convert_error)
268271
}
269272

e2e_tests/src/raw_request.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const MAX_BODY_SIZE: usize = 1 << 31;
1313
#[derive(Copy, Clone, Debug)]
1414
pub struct RawRequestClient;
1515

16-
static SOCKET_PATH: &str = "/tmp/security-daemon-socket";
16+
static SOCKET_PATH: &str = "/tmp/parsec/parsec.sock";
1717
const TIMEOUT: Duration = Duration::from_secs(5);
1818

1919
#[allow(clippy::new_without_default)]

e2e_tests/tests/per_provider/normal_tests/create_destroy_key.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,7 @@ fn generate_public_rsa_check_modulus() -> Result<()> {
104104
fn failed_created_key_should_be_removed() -> Result<()> {
105105
let mut client = TestClient::new();
106106
let key_name = String::from("failed_created_key_should_be_removed");
107-
const GARBAGE_IMPORT_DATA: [u8; 1] = [
108-
48,
109-
];
107+
const GARBAGE_IMPORT_DATA: [u8; 1] = [48];
110108

111109
// The data being imported is garbage, should fail
112110
let _ = client

e2e_tests/tests/per_provider/normal_tests/ping.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ fn mangled_ping() {
2424
let mut req = Request::new();
2525
req.header.provider = ProviderID::Core;
2626
req.header.opcode = Opcode::Ping;
27-
req.auth = RequestAuth::from_bytes(Vec::from("root"));
27+
req.auth = RequestAuth::new(Vec::from("root"));
2828

2929
req.body = RequestBody::_from_bytes(vec![0x11, 0x22, 0x33, 0x44, 0x55]);
3030

src/front/domain_socket.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ use listener::Listen;
99
use listener::ReadWrite;
1010
use log::error;
1111
use std::fs;
12+
use std::fs::Permissions;
1213
use std::io::{Error, ErrorKind, Result};
14+
use std::os::unix::fs::PermissionsExt;
1315
use std::os::unix::io::FromRawFd;
1416
use std::os::unix::net::UnixListener;
1517
use std::path::Path;
1618
use std::time::Duration;
1719

18-
static SOCKET_PATH: &str = "/tmp/security-daemon-socket";
20+
static SOCKET_PATH: &str = "/tmp/parsec/parsec.sock";
1921

2022
/// Unix Domain Socket IPC manager
2123
///
@@ -52,6 +54,11 @@ impl DomainSocketListener {
5254
let listener = UnixListener::bind(SOCKET_PATH)?;
5355
listener.set_nonblocking(true)?;
5456

57+
// Set the socket's permission to 666 to allow clients of different user to
58+
// connect.
59+
let permissions = Permissions::from_mode(0o666);
60+
fs::set_permissions(SOCKET_PATH, permissions)?;
61+
5562
listener
5663
}
5764
1 => {
@@ -61,6 +68,7 @@ impl DomainSocketListener {
6168
// Safe as listen_fds gives us the information that one file descriptor was
6269
// received and its value starts from SD_LISTEN_FDS_START.
6370
unsafe { UnixListener::from_raw_fd(nfd) }
71+
// Expect the socket created by systemd to be 666 on permissions.
6472
}
6573
n => {
6674
error!(

systemd-daemon/parsec.service

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
[Unit]
2-
Description=PARSEC Service
3-
Documentation=https://github.com/parallaxsecond/parsec
2+
Description=Parsec Service
3+
Documentation=https://parallaxsecond.github.io/parsec-book/parsec_service/install_parsec_linux.html
44

55
[Service]
6-
Type=notify
7-
NonBlocking=true
8-
Environment=RUST_LOG=info
6+
WorkingDirectory=/home/parsec/
97
ExecStart=/home/parsec/.cargo/bin/parsec
8+
9+
[Install]
10+
WantedBy=default.target

systemd-daemon/parsec.socket

-9
This file was deleted.

0 commit comments

Comments
 (0)