Skip to content
Open
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
4 changes: 4 additions & 0 deletions src/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ pub fn edit(
notes: Option<&str>,
folder_uuid: Option<&str>,
history: &[crate::db::HistoryEntry],
key: Option<&str>,
) -> Result<(Option<String>, ())> {
with_exchange_refresh_token(access_token, refresh_token, |access_token| {
edit_once(
Expand All @@ -216,6 +217,7 @@ pub fn edit(
notes,
folder_uuid,
history,
key,
)
})
}
Expand All @@ -230,6 +232,7 @@ fn edit_once(
notes: Option<&str>,
folder_uuid: Option<&str>,
history: &[crate::db::HistoryEntry],
key: Option<&str>,
) -> Result<()> {
let (client, _) = api_client()?;
client.edit(
Expand All @@ -242,6 +245,7 @@ fn edit_once(
notes,
folder_uuid,
history,
key,
)?;
Ok(())
}
Expand Down
3 changes: 3 additions & 0 deletions src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,7 @@ struct CiphersPutReq {
secure_note: Option<CipherSecureNote>,
#[serde(rename = "passwordHistory")]
password_history: Vec<CiphersPutReqHistory>,
key: Option<String>,
}

#[derive(serde::Serialize, Debug)]
Expand Down Expand Up @@ -1328,6 +1329,7 @@ impl Client {
notes: Option<&str>,
folder_uuid: Option<&str>,
history: &[crate::db::HistoryEntry],
key: Option<&str>,
) -> Result<()> {
let mut req = CiphersPutReq {
ty: match data {
Expand Down Expand Up @@ -1361,6 +1363,7 @@ impl Client {
password: entry.password.clone(),
})
.collect(),
key: key.map(std::string::ToString::to_string),
};
match data {
crate::db::EntryData::Login {
Expand Down
15 changes: 14 additions & 1 deletion src/bin/rbw-agent/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,7 @@ pub async fn encrypt(
sock: &mut crate::sock::Sock,
state: std::sync::Arc<tokio::sync::Mutex<crate::state::State>>,
plaintext: &str,
entry_key: Option<&str>,
org_id: Option<&str>,
) -> anyhow::Result<()> {
let state = state.lock().await;
Expand All @@ -700,8 +701,20 @@ pub async fn encrypt(
"failed to find encryption keys in in-memory state"
));
};
let entry_keys = if let Some(entry_key) = entry_key {
let key_cipherstring =
rbw::cipherstring::CipherString::new(entry_key)
.context("failed to parse individual item encryption key")?;
Some(rbw::locked::Keys::new(
key_cipherstring.decrypt_locked_symmetric(keys).context(
"failed to decrypt individual item encryption key",
)?,
))
} else {
None
};
let cipherstring = rbw::cipherstring::CipherString::encrypt_symmetric(
keys,
entry_keys.as_ref().unwrap_or(keys),
plaintext.as_bytes(),
)
.context("failed to encrypt plaintext secret")?;
Expand Down
7 changes: 6 additions & 1 deletion src/bin/rbw-agent/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,16 @@ async fn handle_request(
.await?;
true
}
rbw::protocol::Action::Encrypt { plaintext, org_id } => {
rbw::protocol::Action::Encrypt {
plaintext,
entry_key,
org_id,
} => {
crate::actions::encrypt(
sock,
state.clone(),
plaintext,
entry_key.as_deref(),
org_id.as_deref(),
)
.await?;
Expand Down
2 changes: 2 additions & 0 deletions src/bin/rbw/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,15 @@ pub fn decrypt(

pub fn encrypt(
plaintext: &str,
entry_key: Option<&str>,
org_id: Option<&str>,
) -> anyhow::Result<String> {
let mut sock = connect()?;
sock.send(&rbw::protocol::Request::new(
get_environment(),
rbw::protocol::Action::Encrypt {
plaintext: plaintext.to_string(),
entry_key: entry_key.map(std::string::ToString::to_string),
org_id: org_id.map(std::string::ToString::to_string),
},
))?;
Expand Down
36 changes: 23 additions & 13 deletions src/bin/rbw/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1569,26 +1569,26 @@ pub fn add(
let mut access_token = db.access_token.as_ref().unwrap().clone();
let refresh_token = db.refresh_token.as_ref().unwrap();

let name = crate::actions::encrypt(name, None)?;
let name = crate::actions::encrypt(name, None, None)?;

let username = username
.map(|username| crate::actions::encrypt(username, None))
.map(|username| crate::actions::encrypt(username, None, None))
.transpose()?;

let contents = rbw::edit::edit("", HELP_PW)?;

let (password, notes) = parse_editor(&contents);
let password = password
.map(|password| crate::actions::encrypt(&password, None))
.map(|password| crate::actions::encrypt(&password, None, None))
.transpose()?;
let notes = notes
.map(|notes| crate::actions::encrypt(&notes, None))
.map(|notes| crate::actions::encrypt(&notes, None, None))
.transpose()?;
let uris: Vec<_> = uris
.iter()
.map(|uri| {
Ok(rbw::db::Uri {
uri: crate::actions::encrypt(&uri.0, None)?,
uri: crate::actions::encrypt(&uri.0, None, None)?,
match_type: uri.1,
})
})
Expand Down Expand Up @@ -1621,7 +1621,7 @@ pub fn add(
let (new_access_token, id) = rbw::actions::create_folder(
&access_token,
refresh_token,
&crate::actions::encrypt(folder_name, None)?,
&crate::actions::encrypt(folder_name, None, None)?,
)?;
if let Some(new_access_token) = new_access_token {
access_token.clone_from(&new_access_token);
Expand Down Expand Up @@ -1674,16 +1674,16 @@ pub fn generate(
let mut access_token = db.access_token.as_ref().unwrap().clone();
let refresh_token = db.refresh_token.as_ref().unwrap();

let name = crate::actions::encrypt(name, None)?;
let name = crate::actions::encrypt(name, None, None)?;
let username = username
.map(|username| crate::actions::encrypt(username, None))
.map(|username| crate::actions::encrypt(username, None, None))
.transpose()?;
let password = crate::actions::encrypt(&password, None)?;
let password = crate::actions::encrypt(&password, None, None)?;
let uris: Vec<_> = uris
.iter()
.map(|uri| {
Ok(rbw::db::Uri {
uri: crate::actions::encrypt(&uri.0, None)?,
uri: crate::actions::encrypt(&uri.0, None, None)?,
match_type: uri.1,
})
})
Expand Down Expand Up @@ -1716,7 +1716,7 @@ pub fn generate(
let (new_access_token, id) = rbw::actions::create_folder(
&access_token,
refresh_token,
&crate::actions::encrypt(folder_name, None)?,
&crate::actions::encrypt(folder_name, None, None)?,
)?;
if let Some(new_access_token) = new_access_token {
access_token.clone_from(&new_access_token);
Expand Down Expand Up @@ -1787,13 +1787,18 @@ pub fn edit(
.map(|password| {
crate::actions::encrypt(
&password,
entry.key.as_deref(),
entry.org_id.as_deref(),
)
})
.transpose()?;
let notes = notes
.map(|notes| {
crate::actions::encrypt(&notes, entry.org_id.as_deref())
crate::actions::encrypt(
&notes,
entry.key.as_deref(),
entry.org_id.as_deref(),
)
})
.transpose()?;
let mut history = entry.history.clone();
Expand Down Expand Up @@ -1842,7 +1847,11 @@ pub fn edit(

let notes = notes
.map(|notes| {
crate::actions::encrypt(&notes, entry.org_id.as_deref())
crate::actions::encrypt(
&notes,
entry.key.as_deref(),
entry.org_id.as_deref(),
)
})
.transpose()?;

Expand All @@ -1866,6 +1875,7 @@ pub fn edit(
notes.as_deref(),
entry.folder_id.as_deref(),
&history,
entry.key.as_deref(),
)? {
db.access_token = Some(access_token);
save_db(&db)?;
Expand Down
1 change: 1 addition & 0 deletions src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ pub enum Action {
},
Encrypt {
plaintext: String,
entry_key: Option<String>,
org_id: Option<String>,
},
ClipboardStore {
Expand Down
Loading