Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make ssh key fields non-optional #13

Merged
merged 5 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions crates/bitwarden-exporters/src/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,9 @@ impl From<Identity> for JsonIdentity {
#[derive(serde::Serialize)]
#[serde(rename_all = "camelCase")]
struct JsonSshKey {
private_key: Option<String>,
public_key: Option<String>,
fingerprint: Option<String>,
private_key: String,
public_key: String,
fingerprint: String,
}

impl From<SshKey> for JsonSshKey {
Expand Down Expand Up @@ -629,9 +629,9 @@ mod tests {
notes: None,

r#type: CipherType::SshKey(Box::new(SshKey {
private_key: Some("private".to_string()),
public_key: Some("public".to_string()),
fingerprint: Some("fingerprint".to_string()),
private_key: "private".to_string(),
public_key: "public".to_string(),
fingerprint: "fingerprint".to_string(),
})),

favorite: false,
Expand Down Expand Up @@ -837,9 +837,9 @@ mod tests {
notes: None,

r#type: CipherType::SshKey(Box::new(SshKey {
private_key: Some("-----BEGIN OPENSSH PRIVATE KEY-----\nb3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW\nQyNTUxOQAAACBinNE5chMtCHh3BV0H1+CpPlEQBwR5cD+Xb9i8MaHGiwAAAKAy48fwMuPH\n8AAAAAtzc2gtZWQyNTUxOQAAACBinNE5chMtCHh3BV0H1+CpPlEQBwR5cD+Xb9i8MaHGiw\nAAAEAYUCIdfLI14K3XIy9V0FDZLQoZ9gcjOnvFjb4uA335HmKc0TlyEy0IeHcFXQfX4Kk+\nURAHBHlwP5dv2LwxocaLAAAAHHF1ZXh0ZW5ATWFjQm9vay1Qcm8tMTYubG9jYWwB\n-----END OPENSSH PRIVATE KEY-----".to_string()),
public_key: Some("ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGKc0TlyEy0IeHcFXQfX4Kk+URAHBHlwP5dv2LwxocaL".to_string()),
fingerprint: Some("SHA256:1JjFjvPRkj1Gbf2qRP1dgHiIzEuNAEvp+92x99jw3K0".to_string()),
private_key: "-----BEGIN OPENSSH PRIVATE KEY-----\nb3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW\nQyNTUxOQAAACBinNE5chMtCHh3BV0H1+CpPlEQBwR5cD+Xb9i8MaHGiwAAAKAy48fwMuPH\n8AAAAAtzc2gtZWQyNTUxOQAAACBinNE5chMtCHh3BV0H1+CpPlEQBwR5cD+Xb9i8MaHGiw\nAAAEAYUCIdfLI14K3XIy9V0FDZLQoZ9gcjOnvFjb4uA335HmKc0TlyEy0IeHcFXQfX4Kk+\nURAHBHlwP5dv2LwxocaLAAAAHHF1ZXh0ZW5ATWFjQm9vay1Qcm8tMTYubG9jYWwB\n-----END OPENSSH PRIVATE KEY-----".to_string(),
public_key: "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGKc0TlyEy0IeHcFXQfX4Kk+URAHBHlwP5dv2LwxocaL".to_string(),
fingerprint: "SHA256:1JjFjvPRkj1Gbf2qRP1dgHiIzEuNAEvp+92x99jw3K0".to_string(),
})),

favorite: false,
Expand Down
6 changes: 3 additions & 3 deletions crates/bitwarden-exporters/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ pub struct Identity {

pub struct SshKey {
/// [OpenSSH private key](https://github.com/openssh/openssh-portable/blob/master/PROTOCOL.key), in PEM encoding.
pub private_key: Option<String>,
pub private_key: String,
/// Ssh public key (ed25519/rsa) according to [RFC4253](https://datatracker.ietf.org/doc/html/rfc4253#section-6.6)
pub public_key: Option<String>,
pub public_key: String,
/// SSH fingerprint using SHA256 in the format: `SHA256:BASE64_ENCODED_FINGERPRINT`
pub fingerprint: Option<String>,
pub fingerprint: String,
}
11 changes: 6 additions & 5 deletions crates/bitwarden-vault/src/cipher/cipher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,7 @@ impl Cipher {
return Ok(String::new());
};

ssh_key
.fingerprint
Some(ssh_key.fingerprint.clone())
.as_ref()
.map(|c| c.decrypt_with_key(key))
.transpose()?
Expand Down Expand Up @@ -1191,6 +1190,8 @@ mod tests {
let key = SymmetricCryptoKey::try_from(key).unwrap();
let original_subtitle = "SHA256:1JjFjvPRkj1Gbf2qRP1dgHiIzEuNAEvp+92x99jw3K0".to_string();
let fingerprint_encrypted = original_subtitle.to_owned().encrypt_with_key(&key).unwrap();
let private_key_encrypted = "".to_string().encrypt_with_key(&key).unwrap();
let public_key_encrypted = "".to_string().encrypt_with_key(&key).unwrap();
let ssh_key_cipher = Cipher {
id: Some("090c19ea-a61a-4df6-8963-262b97bc6266".parse().unwrap()),
organization_id: None,
Expand All @@ -1208,9 +1209,9 @@ mod tests {
card: None,
secure_note: None,
ssh_key: Some(SshKey {
private_key: None,
public_key: None,
fingerprint: Some(fingerprint_encrypted),
private_key: private_key_encrypted,
public_key: public_key_encrypted,
fingerprint: fingerprint_encrypted,
}),
favorite: false,
reprompt: CipherRepromptType::None,
Expand Down
18 changes: 9 additions & 9 deletions crates/bitwarden-vault/src/cipher/ssh_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@
#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
pub struct SshKey {
/// SSH private key (ed25519/rsa) in unencrypted openssh private key format [OpenSSH private key](https://github.com/openssh/openssh-portable/blob/master/PROTOCOL.key)
pub private_key: Option<EncString>,
pub private_key: EncString,
/// SSH public key (ed25519/rsa) according to [RFC4253](https://datatracker.ietf.org/doc/html/rfc4253#section-6.6)
pub public_key: Option<EncString>,
pub public_key: EncString,
/// SSH fingerprint using SHA256 in the format: `SHA256:BASE64_ENCODED_FINGERPRINT`
pub fingerprint: Option<EncString>,
pub fingerprint: EncString,
}

#[derive(Serialize, Deserialize, Debug, JsonSchema, Clone)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
pub struct SshKeyView {
/// SSH private key (ed25519/rsa) in unencrypted openssh private key format [OpenSSH private key](https://github.com/openssh/openssh-portable/blob/master/PROTOCOL.key)
pub private_key: Option<String>,
pub private_key: String,
/// SSH public key (ed25519/rsa) according to [RFC4253](https://datatracker.ietf.org/doc/html/rfc4253#section-6.6)
pub public_key: Option<String>,
pub public_key: String,
/// SSH fingerprint using SHA256 in the format: `SHA256:BASE64_ENCODED_FINGERPRINT`
pub fingerprint: Option<String>,
pub fingerprint: String,
}

impl KeyEncryptable<SymmetricCryptoKey, SshKey> for SshKeyView {
Expand All @@ -41,9 +41,9 @@
impl KeyDecryptable<SymmetricCryptoKey, SshKeyView> for SshKey {
fn decrypt_with_key(&self, key: &SymmetricCryptoKey) -> Result<SshKeyView, CryptoError> {
Ok(SshKeyView {
private_key: self.private_key.decrypt_with_key(key).ok().flatten(),
public_key: self.public_key.decrypt_with_key(key).ok().flatten(),
fingerprint: self.fingerprint.decrypt_with_key(key).ok().flatten(),
private_key: self.private_key.decrypt_with_key(key)?,
public_key: self.public_key.decrypt_with_key(key)?,
fingerprint: self.fingerprint.decrypt_with_key(key)?,

Check warning on line 46 in crates/bitwarden-vault/src/cipher/ssh_key.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-vault/src/cipher/ssh_key.rs#L44-L46

Added lines #L44 - L46 were not covered by tests
})
}
}
Loading