Compare commits
5 Commits
ebb738445b
...
x25519-age
| Author | SHA1 | Date | |
|---|---|---|---|
| 00afc7130b | |||
| 830dc9671c | |||
| af0d286549 | |||
| 6b60e04513 | |||
| b72ea11712 |
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -1,6 +1,6 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "agent_lib"
|
||||
|
||||
@@ -8,4 +8,4 @@ edition = "2021"
|
||||
[dependencies]
|
||||
anyhow = "1.0.82"
|
||||
libc = "0.2.153"
|
||||
shared_memory_heap = { path = "../shared_memory_heap" }
|
||||
shared_memory_heap = { path = "../shared_memory_heap/" }
|
||||
|
||||
10
src/agent.rs
10
src/agent.rs
@@ -16,7 +16,7 @@ unsafe impl Send for Agent {}
|
||||
impl Agent {
|
||||
pub(crate) unsafe fn new(agent_path: &Path, keyfile_path: &Path) -> Result<Self> {
|
||||
let data_fd = get_shared_mem_fd();
|
||||
let sync_fd = memfd_create("sync\x00".as_ptr() as *const c_char, MFD_ALLOW_SEALING);
|
||||
let sync_fd = memfd_create("sync\x00".as_ptr() as *const c_char, 0);
|
||||
|
||||
if sync_fd <= 0 {
|
||||
bail!("creating memfd failed");
|
||||
@@ -36,8 +36,6 @@ impl Agent {
|
||||
0,
|
||||
) as *mut usize;
|
||||
|
||||
fcntl(sync_fd, F_ADD_SEALS, F_SEAL_FUTURE_WRITE);
|
||||
|
||||
if sync_mem == MAP_FAILED as *mut usize {
|
||||
bail!("mmap failed");
|
||||
}
|
||||
@@ -49,9 +47,9 @@ impl Agent {
|
||||
if child == 0 {
|
||||
// child
|
||||
|
||||
close(0);
|
||||
close(1);
|
||||
close(2);
|
||||
// close(0);
|
||||
// close(1);
|
||||
// close(2);
|
||||
|
||||
let path = CString::new(agent_path.as_os_str().as_encoded_bytes()).unwrap();
|
||||
let data_fd = CString::new(data_fd.to_string()).unwrap();
|
||||
|
||||
@@ -13,7 +13,7 @@ static ED25519AGENT: LazyLock<Vec<Mutex<Agent>>> = LazyLock::new(|| {
|
||||
let keyfile_path =
|
||||
std::env::var("ED25519_KEYFILE").expect("Ed25519_KEYFILE environment variable missing");
|
||||
let num_agents: usize = std::env::var("NUM_AGENTS")
|
||||
.expect("NUM_AGENTS environment variable missing")
|
||||
.unwrap_or("1".to_string())
|
||||
.parse()
|
||||
.expect("NUM_AGENTS should be an integer");
|
||||
let mut agents = Vec::with_capacity(num_agents);
|
||||
|
||||
@@ -2,13 +2,17 @@ pub use shared_memory_heap::sharedptr::SharedPtr;
|
||||
|
||||
use crate::agent::Agent;
|
||||
use std::{
|
||||
ops::Deref, path::Path, sync::{LazyLock, Mutex}
|
||||
ops::Deref,
|
||||
path::Path,
|
||||
sync::{LazyLock, Mutex},
|
||||
};
|
||||
|
||||
static X25519AGENT: LazyLock<Mutex<Agent>> = LazyLock::new(|| {
|
||||
let agent_path = std::env::var("X25519_AGENT_PATH").expect("X25519_AGENT_PATH environment variable missing");
|
||||
let keyfile_path = std::env::var("X25519_KEYFILE").expect("X25519_KEYFILE environment variable missing");
|
||||
let agent = unsafe { Agent::new(Path::new(&agent_path), Path::new(&keyfile_path)).expect("Agent failed to start") };
|
||||
let agent_path = "agent_harness";
|
||||
let keyfile_path = "/etc/x25519-agent/keyfile";
|
||||
let agent = unsafe {
|
||||
Agent::new(Path::new(&agent_path), Path::new(&keyfile_path)).expect("Agent failed to start")
|
||||
};
|
||||
Mutex::new(agent)
|
||||
});
|
||||
|
||||
@@ -61,7 +65,7 @@ impl Deref for X25519SharedKey {
|
||||
|
||||
pub fn x25519_keygen() -> (X25519PrivKey, X25519PubKey) {
|
||||
let sk = X25519PrivKey(SharedPtr::new(8).unwrap());
|
||||
let pk = X25519PubKey(SharedPtr::new(32).unwrap());
|
||||
let pk = X25519PubKey(SharedPtr::new(32).unwrap());
|
||||
|
||||
let mut agent = X25519AGENT.lock().unwrap();
|
||||
|
||||
@@ -94,7 +98,10 @@ pub fn x25519(sk: &X25519PrivKey, pk: &X25519PubKey) -> X25519SharedKey {
|
||||
let mut agent = X25519AGENT.lock().unwrap();
|
||||
|
||||
unsafe {
|
||||
agent.perform_ipc_call(2, &[out.0.get_offset(), sk.0.get_offset(), pk.0.get_offset()]);
|
||||
agent.perform_ipc_call(
|
||||
2,
|
||||
&[out.0.get_offset(), sk.0.get_offset(), pk.0.get_offset()],
|
||||
);
|
||||
}
|
||||
|
||||
drop(agent);
|
||||
|
||||
Reference in New Issue
Block a user