1
0
mirror of https://github.com/bitwarden/browser synced 2026-02-21 03:43:58 +00:00
This commit is contained in:
Bernd Schoolmann
2025-10-17 10:00:20 +02:00
parent 51a1d52b4f
commit e21304ce67
4 changed files with 20 additions and 29 deletions

View File

@@ -85,18 +85,6 @@ impl KnownHostsReader {
Ok(entries)
}
/// Finds host entries by hostname pattern
pub fn find_host(entries: &[KnownHostEntry], hostname: &str) -> Option<KnownHostEntry> {
entries
.iter()
.find(|entry| {
entry.hostname.split(',').any(|h| {
h == hostname || h == "*" || h.starts_with("*.") && hostname.ends_with(&h[1..])
})
})
.cloned()
}
}
#[cfg(test)]

View File

@@ -72,7 +72,7 @@ async fn handle_connection(
};
let response = match request {
Request::IdentitiesRequest => {
Request::Identities => {
span.in_scope(|| info!("Received IdentitiesRequest"));
let Ok(true) = agent.request_can_list(connection).await else {
@@ -86,7 +86,7 @@ async fn handle_connection(
.encode()
.map_err(|e| anyhow::anyhow!("Failed to encode identities reply: {e}"))
}
Request::SignRequest(sign_request) => {
Request::Sign(sign_request) => {
span.in_scope(|| info!("Received SignRequest {:?}", sign_request));
let Ok(true) = agent
@@ -115,7 +115,7 @@ async fn handle_connection(
}
.map_err(|e| anyhow::anyhow!("Failed to create sign reply: {e}"))
}
Request::SessionBindRequest(request) => {
Request::SessionBind(request) => {
span.in_scope(|| info!("Received SessionBind {:?}", request));
connection.set_host_key(request.host_key().clone());
info!(

View File

@@ -47,11 +47,11 @@ pub(crate) enum SshSignFlags {
#[derive(Debug)]
pub(crate) enum Request {
/// Request the list of keys the agent is holding
IdentitiesRequest,
Identities,
/// Sign an authentication request or SSHSIG request
SignRequest(SshSignRequest),
Sign(SshSignRequest),
/// Session bind request
SessionBindRequest(SessionBindRequest),
SessionBind(SessionBindRequest),
}
impl TryFrom<&[u8]> for Request {
@@ -74,9 +74,9 @@ impl TryFrom<&[u8]> for Request {
let contents = message[1..].to_vec();
match r#type {
RequestType::SSH_AGENTC_REQUEST_IDENTITIES => Ok(Request::IdentitiesRequest),
RequestType::SSH_AGENTC_REQUEST_IDENTITIES => Ok(Request::Identities),
RequestType::SSH_AGENTC_SIGN_REQUEST => {
Ok(Request::SignRequest(contents.as_slice().try_into()?))
Ok(Request::Sign(contents.as_slice().try_into()?))
}
RequestType::SSH_AGENTC_EXTENSION => {
// Only support session bind for now
@@ -85,7 +85,7 @@ impl TryFrom<&[u8]> for Request {
info!("Invalid session bind signature");
return Err(anyhow::anyhow!("Invalid session bind signature"));
}
Ok(Request::SessionBindRequest(extension_request))
Ok(Request::SessionBind(extension_request))
}
_ => Err(anyhow::anyhow!("Unsupported request type: {:?}", r#type)),
}
@@ -355,13 +355,13 @@ mod tests {
#[test]
fn test_parse_identities_request() {
let req = Request::try_from(TEST_VECTOR_REQUEST_LIST).expect("Should parse");
assert!(matches!(req, Request::IdentitiesRequest));
assert!(matches!(req, Request::Identities));
}
#[test]
fn test_parse_sign_request() {
let req = Request::try_from(TEST_VECTOR_REQUEST_SIGN).expect("Should parse");
assert!(matches!(req, Request::SignRequest { .. }));
assert!(matches!(req, Request::Sign { .. }));
}
#[test]

View File

@@ -1,4 +1,5 @@
use std::fmt::Debug;
use std::fmt::Display;
use std::fmt::Formatter;
use base64::prelude::BASE64_STANDARD;
@@ -334,13 +335,15 @@ impl PublicKey {
let blob = read_bytes(&mut bytes)?;
Ok(PublicKey { alg, blob })
}
}
fn to_string(&self) -> String {
impl Display for PublicKey {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let mut buf = Vec::new();
self.alg().as_bytes().encode(&mut buf).unwrap();
self.blob().encode(&mut buf).unwrap();
let buf_b64 = BASE64_STANDARD.encode(&buf);
format!("{} {}", self.alg(), buf_b64)
// Failure to encode is ignored
let _ = self.alg().as_bytes().encode(&mut buf);
let _ = self.blob().encode(&mut buf);
write!(f, "{}", BASE64_STANDARD.encode(&buf))
}
}
@@ -377,7 +380,7 @@ impl TryFrom<String> for PublicKey {
impl Debug for PublicKey {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "SshPublicKey(\"{}\")", self.to_string())
write!(f, "SshPublicKey(\"{}\")", self)
}
}