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

Added the ability to get TOTP tokens #11

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Mystic-Ivy
Copy link

@Mystic-Ivy Mystic-Ivy commented Jan 29, 2024

Hi all,

I have fixed the quick 'hack' and now added the ability to Opt-In to get a TOTP token.
Furthermore, it was not possible to get the new token with get_attributes() after the time has run out.
I also tried reloading the whole database which did not seem to work.
As such, I had to include a library which generates the TOTP when pressing Ctrl + t.

The feature can be activated by setting view_totp = True.

The following library is needed to generate the TOTP: pyotp
It is to note, that the library is only needed when copying a TOTP token and would not be needed if deactivated. (Check source code)

Cheers

@@ -595,6 +595,35 @@ def get_secret(self) -> str:
self.item.load_secret_sync()
return self.item.get_secret().get_text()


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove superfluous newline :)


Returns:
TOTP token

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove superfluous newline :)

if otp_value[0] == "secret":
return pyotp.TOTP(otp_value[1]).now()


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove superfluous newline :)

return

if "totp" in self.item.get_attributes().get('otp'):
otp_value = self.item.get_attributes().get('otp').split("?")[1].split("&")[0].split("=")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the actual format here? Is this always the same? Can you provide a example string?

@qtc-de
Copy link
Member

qtc-de commented Mar 16, 2024

It is really unfortunate that one cannot obtain the current OTP via KeePass directly and has to use an additional library. However, I agree that this is probably the best workaround 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants