replydev / cotp

Trustworthy, encrypted, command-line TOTP/HOTP authenticator app with import functionality.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Feature request] Is it possible to support some kind(s) portable mode?

PM2p5 opened this issue · comments

commented

Is it possible to support a portable mode? I think it will be much concise and easy to use if it does!

I have concluded 3 possible options:

  1. By specify the location of the the core db file ".cotp\db.cotp", to a user specified place. The command switch would be:
    cotp db --path 'path/to/the/db.cotp'.

  2. Add a portable switch, and load the db in the same folder:
    cotp --portable

  3. Check if a blank file named 'portable_mode' exists, if yes, load the db in the same folder.

Thanks in advance!

commented

I think that the most clean way to check if db.cotp file exists in the same directory as the binary executable.

Currently, this is the behaviour only if the artifact is compiled in debug mode, as I use preprocess macros.

This could be the occation to delete this debug / release dispatch and just use db.cotp if found.

Finally, we could fallback to default folder if the existing db.cotp file is corrupted.

Let me know what you think about, thank you!

commented

I think that the most clean way to check if db.cotp file exists in the same directory as the binary executable.

Currently, this is the behaviour only if the artifact is compiled in debug mode, as I use preprocess macros.

This could be the occation to delete this debug / release dispatch and just use db.cotp if found.

Finally, we could fallback to default folder if the existing db.cotp file is corrupted.

Let me know what you think about, thank you!

Hello, replydev!

Your way to deal the portable mode is more concise!

Here is my understanding of the new behavior, correct me if I was wrong: The (new) App will first check it's working directory, if there is a db file, then load it. If the db does not exist or has some kind of error in it, load another db in the old place the App used to. (eg: %userprofile% folder on Windows, the ~ folder on Linux).

If the App works like this, it will be great! Many many thanks for the amazing work!!

Have a great day!!!

commented

Here is another detail need to be taken into consideration if the App works as described above.

What if both DB corrupted(the one in the working directory and another one in the user's home folder)? Will there be some kind of warnings and prompts to allow user to create a new db? If the App is about to create a new db, will it ask the user to clarify which DB to create?

commented

Right now it will just display an error message. I would not create confusing behaviour of overwriting or deleting the file accidentally.

commented

Right now it will just display an error message. I would not create confusing behaviour of overwriting or deleting the file accidentally.

Yeah, that sounds good!
Let users to handle this corner situation is good enough for the potential target users, especially consider this is a TUI based App.

commented

@PM2p5 you can use the environment variable COTP_DB_PATH to specify a custom database file path. It is already implemented :).

Just took a look to the code today after long holidays.

@PM2p5 you can use the environment variable COTP_DB_PATH to specify a custom database file path. It is already implemented :).

Just took a look to the code today after long holidays.

Hello, replydev!

I've tested the variable of COTP_DB_PATH on Windows, it's working well!

Testing method: Set an user variable of COTP_DB_PATH on Windows, and tested following values:

Succeed:

C:\Users\Alice\Desktop\db.cotp
%userprofile%\Desktop\.cotp\db.cotp

Failed with the message:
Cannot decrypt existing database: Error during file reading: Os { code: 5, kind: PermissionDenied, message: "Access is denied." }

C:\Users\Alice\Desktop\
%userprofile%\Desktop\.cotp\
C:/Users/Alice/Desktop/
C:/Users/Alice/Desktop/db.cotp
%userprofile%/Desktop/db.cotp
%userprofile%/Desktop/.cotp/db.cotp

Now the only thing left here is to design the portable mode, allow it to work together with the COTP_DB_PATH and the default path of ~/.cotp/db.cotp

Could you please elaborate:

Now the only thing left here is to design the portable mode, allow it to work together with the COTP_DB_PATH and the default path of ~/.cotp/db.cotp

Could you please elaborate:

Now the only thing left here is to design the portable mode, allow it to work together with the COTP_DB_PATH and the default path of ~/.cotp/db.cotp

Hi, replydev!

The portable mode in my opinion could be like this:

1st, check the existence of the db.cotp in the App folder(working directory), if yes, check and load the db!
2nd, if the db.cotp doesn't exist, then it's not the portable mode! The App should work as old days when it didn't support the portable mode.
3rd, if it's not the portable mode, check the COTP_DB_PATH variable, check and load the db!
4th, if the COTP_DB_PATH doesn't exist, check and load the db from the default path of ~/.cotp/db.cotp.

I've peeked the branch of portable mode from here https://github.com/replydev/cotp/tree/feat/portable_mode
The code form your commit of 2079ea6

pub fn is_portable_mode() -> bool {
    PathBuf::from("db.cotp").exists()
}

This seems to be the same idea as I wrote in the 1st and 2nd steps.
After some quick tests with the debug artifacts, the current behavior is to check the COTP_DB_PATH variable 1st, then check the db.cotp in the App folder(working directory), and finally the default path of ~/.cotp/db.cotp. Which seems okay!

Tell me something about your idea!

Ok, i see that it's more or less already implemented. I will push a PR.

Hi @PM2p5, I merged #325.

Now we support db.cotp file in working directory.
I think we can consider this issued closed.