Skip to content

Commit

Permalink
Fix ssh agent on flatpak and mac app store
Browse files Browse the repository at this point in the history
  • Loading branch information
quexten committed Feb 9, 2025
1 parent 1d71212 commit 3fa4ad8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,17 @@ impl Stream for PeercredUnixListenerStream {
Ok(peer) => match peer.pid() {
Some(pid) => pid,
None => {
return Poll::Ready(Some(Err(io::Error::new(
io::ErrorKind::Other,
"Failed to get peer PID",
))));
return Poll::Ready(Some(Ok((stream, PeerInfo::unknown()))));

Check warning on line 34 in apps/desktop/desktop_native/core/src/ssh_agent/peercred_unix_listener_stream.rs

View check run for this annotation

Codecov / codecov/patch

apps/desktop/desktop_native/core/src/ssh_agent/peercred_unix_listener_stream.rs#L34

Added line #L34 was not covered by tests
}
},
Err(err) => {
return Poll::Ready(Some(Err(io::Error::new(
io::ErrorKind::Other,
format!("Failed to get peer credentials: {}", err),
))));
Err(_) => {
return Poll::Ready(Some(Ok((stream, PeerInfo::unknown()))));

Check warning on line 38 in apps/desktop/desktop_native/core/src/ssh_agent/peercred_unix_listener_stream.rs

View check run for this annotation

Codecov / codecov/patch

apps/desktop/desktop_native/core/src/ssh_agent/peercred_unix_listener_stream.rs#L38

Added line #L38 was not covered by tests
}
};
let peer_info = peerinfo::gather::get_peer_info(pid as u32);
match peer_info {
Ok(info) => Poll::Ready(Some(Ok((stream, info)))),
Err(err) => Poll::Ready(Some(Err(io::Error::new(
io::ErrorKind::Other,
format!("Failed to get peer info: {}", err),
)))),
Err(_) => Poll::Ready(Some(Ok((stream, PeerInfo::unknown())))),

Check warning on line 44 in apps/desktop/desktop_native/core/src/ssh_agent/peercred_unix_listener_stream.rs

View check run for this annotation

Codecov / codecov/patch

apps/desktop/desktop_native/core/src/ssh_agent/peercred_unix_listener_stream.rs#L44

Added line #L44 was not covered by tests
}
}
Poll::Ready(Err(err)) => Poll::Ready(Some(Err(err))),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,8 @@ impl PeerInfo {
pub fn process_name(&self) -> &str {
&self.process_name
}

pub fn unknown() -> Self {
Self::new(0, 0, "Unknown application".to_string())
}

Check warning on line 35 in apps/desktop/desktop_native/core/src/ssh_agent/peerinfo/models.rs

View check run for this annotation

Codecov / codecov/patch

apps/desktop/desktop_native/core/src/ssh_agent/peerinfo/models.rs#L33-L35

Added lines #L33 - L35 were not covered by tests
}
20 changes: 15 additions & 5 deletions apps/desktop/desktop_native/core/src/ssh_agent/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,21 @@ impl BitwardenDesktopAgent {
return;
}
};
ssh_agent_directory
.join(".bitwarden-ssh-agent.sock")
.to_str()
.expect("Path should be valid")
.to_owned()

let is_flatpak = std::env::var("container") == Ok("flatpak".to_string());
if !is_flatpak {
ssh_agent_directory
.join(".bitwarden-ssh-agent.sock")
.to_str()
.expect("Path should be valid")
.to_owned()

Check warning on line 57 in apps/desktop/desktop_native/core/src/ssh_agent/unix.rs

View check run for this annotation

Codecov / codecov/patch

apps/desktop/desktop_native/core/src/ssh_agent/unix.rs#L51-L57

Added lines #L51 - L57 were not covered by tests
} else {
ssh_agent_directory
.join(".var/app/com.bitwarden.desktop/data/.bitwarden-ssh-agent.sock")
.to_str()
.expect("Path should be valid")
.to_owned()

Check warning on line 63 in apps/desktop/desktop_native/core/src/ssh_agent/unix.rs

View check run for this annotation

Codecov / codecov/patch

apps/desktop/desktop_native/core/src/ssh_agent/unix.rs#L59-L63

Added lines #L59 - L63 were not covered by tests
}
}
};

Expand Down

0 comments on commit 3fa4ad8

Please sign in to comment.