Skip to content

Commit aee2da2

Browse files
committed
Use the term passphrase instead of token for the browser extension.
1 parent 06b5c6c commit aee2da2

4 files changed

Lines changed: 38 additions & 38 deletions

File tree

src/api/mod.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ impl RklContent {
7979
let dropbox_conf = dropbox::DropboxConfiguration::new(tup.2.decrypted_token()?);
8080
let system_conf =
8181
SystemConfiguration::new(tup.3.saved_at, tup.3.version, tup.3.last_sync_version);
82-
let general_configuration = GeneralConfiguration::new(tup.4.browser_extension_token.clone());
82+
let general_configuration = GeneralConfiguration::new(tup.4.browser_extension_passphrase.clone());
8383

8484
Ok(RklContent::new(
8585
entries,
@@ -221,30 +221,30 @@ impl Default for SystemConfiguration {
221221
/// General configuration
222222
#[derive(Debug, PartialEq, Clone)]
223223
pub struct GeneralConfiguration {
224-
/// Token to be used for securing the communication with browser extensions
225-
pub browser_extension_token: Option<String>,
224+
/// Passphrase to be used for securing the communication with browser extensions
225+
pub browser_extension_passphrase: Option<String>,
226226
}
227227

228228
impl GeneralConfiguration {
229-
pub fn new(browser_extension_token: Option<String>) -> GeneralConfiguration {
229+
pub fn new(browser_extension_passphrase: Option<String>) -> GeneralConfiguration {
230230
GeneralConfiguration {
231-
browser_extension_token,
231+
browser_extension_passphrase,
232232
}
233233
}
234234

235235
pub fn from_table(table: &Table) -> Result<GeneralConfiguration, errors::RustKeylockError> {
236-
let browser_extension_token = table
237-
.get("browser_extension_token")
236+
let browser_extension_passphrase = table
237+
.get("browser_extension_passphrase")
238238
.and_then(|value| value.as_str().and_then(|str_ref| Some(str_ref.to_string())));
239-
Ok(GeneralConfiguration::new(browser_extension_token))
239+
Ok(GeneralConfiguration::new(browser_extension_passphrase))
240240
}
241241

242242
pub fn to_table(&self) -> errors::Result<Table> {
243243
let mut table = Table::new();
244-
if self.browser_extension_token.is_some() {
244+
if self.browser_extension_passphrase.is_some() {
245245
table.insert(
246-
"browser_extension_token".to_string(),
247-
toml::Value::String(self.browser_extension_token.clone().unwrap()),
246+
"browser_extension_passphrase".to_string(),
247+
toml::Value::String(self.browser_extension_passphrase.clone().unwrap()),
248248
);
249249
}
250250
Ok(table)
@@ -254,7 +254,7 @@ impl GeneralConfiguration {
254254
impl Default for GeneralConfiguration {
255255
fn default() -> GeneralConfiguration {
256256
GeneralConfiguration {
257-
browser_extension_token: None,
257+
browser_extension_passphrase: None,
258258
}
259259
}
260260
}
@@ -647,8 +647,8 @@ pub enum UserSelection {
647647
GeneratePassphrase(Option<usize>, Entry),
648648
/// The user wants to check the passwords status quality.
649649
CheckPasswords,
650-
/// The user wants to generate a new Browser Extension token
651-
GenerateBrowserExtensionToken,
650+
/// The user wants to generate a new Browser Extension passphrase
651+
GenerateBrowserExtensionPassphrase,
652652
}
653653

654654
impl UserSelection {
@@ -698,7 +698,7 @@ impl UserSelection {
698698
UserSelection::AddToClipboard(_) => 12,
699699
UserSelection::GeneratePassphrase(_, _) => 13,
700700
UserSelection::CheckPasswords => 14,
701-
UserSelection::GenerateBrowserExtensionToken => 15,
701+
UserSelection::GenerateBrowserExtensionPassphrase => 15,
702702
}
703703
}
704704
}

src/file_handler.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ mod test_file_handler {
599599
let nc_conf = NextcloudConfiguration::new("nc_url".to_string(), "nc_user".to_string(), "nc_pass".to_string(), true).unwrap();
600600
let dbx_conf = DropboxConfiguration::new("token".to_string()).unwrap();
601601
let sys_conf = SystemConfiguration::new(Some(0), Some(1), Some(2));
602-
let gen_conf = GeneralConfiguration::new(Some("aToken".to_string()));
602+
let gen_conf = GeneralConfiguration::new(Some("aPassphrase".to_string()));
603603

604604
assert!(super::save(
605605
super::RklContent::new(vec, nc_conf, dbx_conf, sys_conf, gen_conf),
@@ -775,7 +775,7 @@ mod test_file_handler {
775775
let nc_conf = NextcloudConfiguration::new("nc_url".to_string(), "nc_user".to_string(), "nc_pass".to_string(), true).unwrap();
776776
let dbx_conf = DropboxConfiguration::new("token".to_string()).unwrap();
777777
let sys_conf = SystemConfiguration::new(Some(0), Some(1), Some(2));
778-
let gen_conf = GeneralConfiguration::new(Some("aToken".to_string()));
778+
let gen_conf = GeneralConfiguration::new(Some("aPassphrase".to_string()));
779779

780780
let mut cryptor = super::create_bcryptor(filename, password.clone(), BCRYPT_COST, salt_position, false, true).unwrap();
781781
assert!(super::save(super::RklContent::new(entries.clone(), nc_conf, dbx_conf, sys_conf, gen_conf), filename, &cryptor, true).is_ok());
@@ -791,7 +791,7 @@ mod test_file_handler {
791791
let new_nc_conf = NextcloudConfiguration::new("nc_url".to_string(), "nc_user".to_string(), "nc_pass".to_string(), true).unwrap();
792792
let new_dbx_conf = DropboxConfiguration::new("newtoken".to_string()).unwrap();
793793
let new_sys_conf = SystemConfiguration::new(Some(0), Some(1), Some(2));
794-
let new_gen_conf = GeneralConfiguration::new(Some("otherNewToken".to_string()));
794+
let new_gen_conf = GeneralConfiguration::new(Some("otherNewPassphrase".to_string()));
795795
assert!(super::save(
796796
super::RklContent::new(entries, new_nc_conf, new_dbx_conf, new_sys_conf, new_gen_conf),
797797
filename,
@@ -824,7 +824,7 @@ mod test_file_handler {
824824
let nc_conf = NextcloudConfiguration::new("nc_url".to_string(), "nc_user".to_string(), "nc_pass".to_string(), true).unwrap();
825825
let dbx_conf = DropboxConfiguration::new("token".to_string()).unwrap();
826826
let sys_conf = SystemConfiguration::new(Some(0), Some(1), Some(2));
827-
let gen_conf = GeneralConfiguration::new(Some("aToken".to_string()));
827+
let gen_conf = GeneralConfiguration::new(Some("aPassphrase".to_string()));
828828

829829
let mut cryptor = super::create_bcryptor(filename, password.clone(), BCRYPT_COST, salt_position, false, true).unwrap();
830830
assert!(super::save(super::RklContent::new(entries.clone(), nc_conf, dbx_conf, sys_conf, gen_conf), filename, &cryptor, true).is_ok());
@@ -839,7 +839,7 @@ mod test_file_handler {
839839
let new_nc_conf = NextcloudConfiguration::new("nc_url".to_string(), "nc_user".to_string(), "nc_pass".to_string(), true).unwrap();
840840
let new_dbx_conf = DropboxConfiguration::new("newtoken".to_string()).unwrap();
841841
let new_sys_conf = SystemConfiguration::new(Some(0), Some(1), Some(2));
842-
let new_gen_conf = GeneralConfiguration::new(Some("aToken".to_string()));
842+
let new_gen_conf = GeneralConfiguration::new(Some("aPassphrase".to_string()));
843843
assert!(super::save(
844844
super::RklContent::new(entries, new_nc_conf, new_dbx_conf, new_sys_conf, new_gen_conf),
845845
filename,
@@ -879,7 +879,7 @@ mod test_file_handler {
879879
)
880880
.unwrap();
881881
let dbx_conf_import = DropboxConfiguration::new("token_import".to_string()).unwrap();
882-
let gen_conf_import = GeneralConfiguration::new(Some("browser_extension_token_import".to_string()));
882+
let gen_conf_import = GeneralConfiguration::new(Some("browser_extension_passphrase_import".to_string()));
883883

884884
let tmp_cryptor_import =
885885
super::create_bcryptor(filename_import, password_import.clone(), BCRYPT_COST, salt_position_import, false, false).unwrap();
@@ -909,7 +909,7 @@ mod test_file_handler {
909909
let nc_conf = NextcloudConfiguration::new("nc_url".to_string(), "nc_user".to_string(), "nc_pass".to_string(), false).unwrap();
910910
let dbx_conf = DropboxConfiguration::new("token".to_string()).unwrap();
911911
let sys_conf = SystemConfiguration::new(Some(2), Some(3), Some(2));
912-
let gen_conf = GeneralConfiguration::new(Some("anothertoken".to_string()));
912+
let gen_conf = GeneralConfiguration::new(Some("anotherPassphrase".to_string()));
913913

914914
let mut cryptor = super::create_bcryptor(filename, password.clone(), BCRYPT_COST, salt_position, false, true).unwrap();
915915
assert!(super::save(
@@ -989,7 +989,7 @@ mod test_file_handler {
989989
let nc_conf = NextcloudConfiguration::new("nc_url".to_string(), "nc_user".to_string(), "nc_pass".to_string(), true).unwrap();
990990
let dbx_conf = DropboxConfiguration::new("token".to_string()).unwrap();
991991
let sys_conf = SystemConfiguration::new(Some(0), Some(1), Some(2));
992-
let gen_conf = GeneralConfiguration::new(Some("anothertoken".to_string()));
992+
let gen_conf = GeneralConfiguration::new(Some("anotherPassphrase".to_string()));
993993

994994
let mut cryptor = super::create_bcryptor(filename, password.clone(), BCRYPT_COST, salt_position, false, true).unwrap();
995995
assert!(super::save(super::RklContent::new(entries.clone(), nc_conf, dbx_conf, sys_conf, gen_conf), filename, &cryptor, true).is_ok());

src/lib.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,12 @@ pub async fn execute_async(editor: Box<dyn AsyncEditor>) {
123123
if let Err(e) = rest_server_clone.update_safe(executor.get_safe()) {
124124
error!("Could not update the safe for the HTTP server: {e}");
125125
}
126-
let token = executor
126+
let passphrase = executor
127127
.get_configuration()
128128
.general
129-
.browser_extension_token
129+
.browser_extension_passphrase
130130
.unwrap_or_default();
131-
if let Err(e) = rest_server_clone.update_token(token.to_string()) {
131+
if let Err(e) = rest_server_clone.update_passphrase(passphrase.to_string()) {
132132
error!("Could not update the safe for the HTTP server: {e}");
133133
}
134134
let (new_executor, stop) = executor.handle().await.unwrap();
@@ -709,14 +709,14 @@ Warning: Saving will discard all the entries that could not be recovered.
709709
s.configuration.general.clone(),
710710
)
711711
}
712-
UserSelection::GenerateBrowserExtensionToken => {
713-
debug!("UserSelection::GenerateBrowserExtensionToken");
714-
let new_token = rs_password_utils::dice::generate_with_separator(
712+
UserSelection::GenerateBrowserExtensionPassphrase => {
713+
debug!("UserSelection::GenerateBrowserExtensionPassphrase");
714+
let new_passphrase = rs_password_utils::dice::generate_with_separator(
715715
s.props.generated_passphrases_words_count() as usize,
716716
"_",
717717
);
718718
let mut updated_gen_conf = s.configuration.general.clone();
719-
updated_gen_conf.browser_extension_token = Some(new_token);
719+
updated_gen_conf.browser_extension_passphrase = Some(new_passphrase);
720720
s.editor.show_configuration(
721721
s.configuration.nextcloud.clone(),
722722
s.configuration.dropbox.clone(),

src/rest_server.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ fn get_lost_counts() -> MutexGuard<'static, Vec<Counter>> {
7878
pub(crate) struct RestService {
7979
listener_opt: Arc<Option<TcpListener>>,
8080
safe: Arc<Mutex<Option<Safe>>>,
81-
token: Arc<Mutex<String>>,
81+
passphrase: Arc<Mutex<String>>,
8282
}
8383

8484
impl RestService {
@@ -98,7 +98,7 @@ impl RestService {
9898
Ok(RestService {
9999
listener_opt: Arc::new(listener_opt),
100100
safe: Arc::new(Mutex::new(None)),
101-
token: Arc::new(Mutex::new("".to_string())),
101+
passphrase: Arc::new(Mutex::new("".to_string())),
102102
})
103103
}
104104

@@ -122,8 +122,8 @@ impl RestService {
122122
Ok(())
123123
}
124124

125-
pub(crate) fn update_token(&self, token: String) -> errors::Result<()> {
126-
*self.token.lock()? = token;
125+
pub(crate) fn update_passphrase(&self, passphrase: String) -> errors::Result<()> {
126+
*self.passphrase.lock()? = passphrase;
127127
Ok(())
128128
}
129129
}
@@ -185,12 +185,12 @@ impl Service<Request<IncomingBody>> for RestService {
185185
}
186186

187187
let safe_opt = self.safe.lock().expect("Safe poisoned").clone();
188-
let token_clone = self.token.lock().expect("Token poisoned").clone();
188+
let passphrase_clone = self.passphrase.lock().expect("Passphrase poisoned").clone();
189189
let res = async move {
190190
match (req.method(), req.uri().path(), req.uri().query()) {
191191
(&Method::POST, "/pake", _) => {
192192
debug!("Initializing pake...");
193-
let outbound_key = do_pake(req, &token_clone).await?;
193+
let outbound_key = do_pake(req, &passphrase_clone).await?;
194194

195195
let mut counter = get_counter();
196196
let random_initial_counter = thread_rng().gen_range(0..100000);
@@ -310,11 +310,11 @@ fn handle_headers(
310310
Ok(())
311311
}
312312

313-
async fn do_pake(req: Request<IncomingBody>, token: &str) -> errors::Result<Vec<u8>> {
313+
async fn do_pake(req: Request<IncomingBody>, passphrase: &str) -> errors::Result<Vec<u8>> {
314314
debug!("Executing PAKE");
315315
let inbound_msg = req.collect().await?.to_bytes();
316316
let (s1, outbound_msg) = Spake2::<Ed25519Group>::start_b(
317-
&Password::new(token),
317+
&Password::new(passphrase),
318318
&Identity::new(b"rust-keylock-browser-extension"),
319319
&Identity::new(b"rust-keylock-lib"),
320320
);

0 commit comments

Comments
 (0)