Skip to content

Commit 5905354

Browse files
quextendani-garcia
andauthored
Make ssh key fields non-optional (#13)
## 🎟️ Tracking - ## 📔 Objective SSH key item fields should never be optional and are always present. All of these are set on creation / update. ## ⏰ Reminders before review - Contributor guidelines followed - All formatters and local linters executed and passed - Written new unit and / or integration tests where applicable - Protected functional changes with optionality (feature flags) - Used internationalization (i18n) for all UI strings - CI builds passed - Communicated to DevOps any deployment requirements - Updated any necessary documentation (Confluence, contributing docs) or informed the documentation team ## 🦮 Reviewer guidelines <!-- Suggested interactions but feel free to use (or not) as you desire! --> - 👍 (`:+1:`) or similar for great changes - 📝 (`:memo:`) or ℹ️ (`:information_source:`) for notes or general info - ❓ (`:question:`) for questions - 🤔 (`:thinking:`) or 💭 (`:thought_balloon:`) for more open inquiry that's not quite a confirmed issue and could potentially benefit from discussion - 🎨 (`:art:`) for suggestions / improvements - ❌ (`:x:`) or ⚠️ (`:warning:`) for more significant problems or concerns needing attention - 🌱 (`:seedling:`) or ♻️ (`:recycle:`) for future improvements or indications of technical debt - ⛏ (`:pick:`) for minor or nitpick changes --------- Co-authored-by: Daniel García <[email protected]>
1 parent 6cf25e3 commit 5905354

File tree

4 files changed

+27
-26
lines changed

4 files changed

+27
-26
lines changed

crates/bitwarden-exporters/src/json.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,9 @@ impl From<Identity> for JsonIdentity {
213213
#[derive(serde::Serialize)]
214214
#[serde(rename_all = "camelCase")]
215215
struct JsonSshKey {
216-
private_key: Option<String>,
217-
public_key: Option<String>,
218-
fingerprint: Option<String>,
216+
private_key: String,
217+
public_key: String,
218+
fingerprint: String,
219219
}
220220

221221
impl From<SshKey> for JsonSshKey {
@@ -629,9 +629,9 @@ mod tests {
629629
notes: None,
630630

631631
r#type: CipherType::SshKey(Box::new(SshKey {
632-
private_key: Some("private".to_string()),
633-
public_key: Some("public".to_string()),
634-
fingerprint: Some("fingerprint".to_string()),
632+
private_key: "private".to_string(),
633+
public_key: "public".to_string(),
634+
fingerprint: "fingerprint".to_string(),
635635
})),
636636

637637
favorite: false,
@@ -837,9 +837,9 @@ mod tests {
837837
notes: None,
838838

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

845845
favorite: false,

crates/bitwarden-exporters/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,9 @@ pub struct Identity {
137137

138138
pub struct SshKey {
139139
/// [OpenSSH private key](https://github.com/openssh/openssh-portable/blob/master/PROTOCOL.key), in PEM encoding.
140-
pub private_key: Option<String>,
140+
pub private_key: String,
141141
/// Ssh public key (ed25519/rsa) according to [RFC4253](https://datatracker.ietf.org/doc/html/rfc4253#section-6.6)
142-
pub public_key: Option<String>,
142+
pub public_key: String,
143143
/// SSH fingerprint using SHA256 in the format: `SHA256:BASE64_ENCODED_FINGERPRINT`
144-
pub fingerprint: Option<String>,
144+
pub fingerprint: String,
145145
}

crates/bitwarden-vault/src/cipher/cipher.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -340,8 +340,7 @@ impl Cipher {
340340
return Ok(String::new());
341341
};
342342

343-
ssh_key
344-
.fingerprint
343+
Some(ssh_key.fingerprint.clone())
345344
.as_ref()
346345
.map(|c| c.decrypt_with_key(key))
347346
.transpose()?
@@ -1191,6 +1190,8 @@ mod tests {
11911190
let key = SymmetricCryptoKey::try_from(key).unwrap();
11921191
let original_subtitle = "SHA256:1JjFjvPRkj1Gbf2qRP1dgHiIzEuNAEvp+92x99jw3K0".to_string();
11931192
let fingerprint_encrypted = original_subtitle.to_owned().encrypt_with_key(&key).unwrap();
1193+
let private_key_encrypted = "".to_string().encrypt_with_key(&key).unwrap();
1194+
let public_key_encrypted = "".to_string().encrypt_with_key(&key).unwrap();
11941195
let ssh_key_cipher = Cipher {
11951196
id: Some("090c19ea-a61a-4df6-8963-262b97bc6266".parse().unwrap()),
11961197
organization_id: None,
@@ -1208,9 +1209,9 @@ mod tests {
12081209
card: None,
12091210
secure_note: None,
12101211
ssh_key: Some(SshKey {
1211-
private_key: None,
1212-
public_key: None,
1213-
fingerprint: Some(fingerprint_encrypted),
1212+
private_key: private_key_encrypted,
1213+
public_key: public_key_encrypted,
1214+
fingerprint: fingerprint_encrypted,
12141215
}),
12151216
favorite: false,
12161217
reprompt: CipherRepromptType::None,

crates/bitwarden-vault/src/cipher/ssh_key.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,23 @@ use serde::{Deserialize, Serialize};
99
#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
1010
pub struct SshKey {
1111
/// SSH private key (ed25519/rsa) in unencrypted openssh private key format [OpenSSH private key](https://github.com/openssh/openssh-portable/blob/master/PROTOCOL.key)
12-
pub private_key: Option<EncString>,
12+
pub private_key: EncString,
1313
/// SSH public key (ed25519/rsa) according to [RFC4253](https://datatracker.ietf.org/doc/html/rfc4253#section-6.6)
14-
pub public_key: Option<EncString>,
14+
pub public_key: EncString,
1515
/// SSH fingerprint using SHA256 in the format: `SHA256:BASE64_ENCODED_FINGERPRINT`
16-
pub fingerprint: Option<EncString>,
16+
pub fingerprint: EncString,
1717
}
1818

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

3131
impl KeyEncryptable<SymmetricCryptoKey, SshKey> for SshKeyView {
@@ -41,9 +41,9 @@ impl KeyEncryptable<SymmetricCryptoKey, SshKey> for SshKeyView {
4141
impl KeyDecryptable<SymmetricCryptoKey, SshKeyView> for SshKey {
4242
fn decrypt_with_key(&self, key: &SymmetricCryptoKey) -> Result<SshKeyView, CryptoError> {
4343
Ok(SshKeyView {
44-
private_key: self.private_key.decrypt_with_key(key).ok().flatten(),
45-
public_key: self.public_key.decrypt_with_key(key).ok().flatten(),
46-
fingerprint: self.fingerprint.decrypt_with_key(key).ok().flatten(),
44+
private_key: self.private_key.decrypt_with_key(key)?,
45+
public_key: self.public_key.decrypt_with_key(key)?,
46+
fingerprint: self.fingerprint.decrypt_with_key(key)?,
4747
})
4848
}
4949
}

0 commit comments

Comments
 (0)