Repository navigation
Conversation
|
This is an impressive amount of work, thanks for sharing! It will take some time to go through, as it's quite a lot of code, but I'll try to not delay it much. @erayd do you have time to review this as well? A few initial questions & remarks, mostly based on PR description:
|
|
Many thanks for your quick response.
|
|
I am using the extension now for over two weeks and did not run into any issues so far.
Let me know if anything else should be changed. |
|
I looked into this over the holidays and it is possible to consolidate the OAuth token to one entry. While my initial implementation takes care of the issue, it is still not as nice as having a consolidated token, especially when a Yubikey with manual interaction for each encryption is used. So I think the issue needs to be fixed in Thunderbird first. I will create an issue and maybe try to fix the issue myself when I have some spare time. I will keep this thread updated. |
f48a376 to
a877887
Compare
|
I have reported the mentioned Thunderbird issue quite some time ago but did not really got feedback. In general the OAuth part in Thunderbird is the most error prone, I have only got it reliably working with this extension when enabling "Offline Support" for the calendars. The branch has been reworked since the last push. I have also adapted the original pull request description with the new changes, to not be confusing. Any feedback is welcome. Here is a summary of the changes. Password store layoutThe old layout used protocol-specific subdirectories and per-account OAuth files: This has been replaced with a flat The old layout required scope-based matching logic ( MigrationMigration is no longer automatic. A "Migrate credentials from Thunderbird" button is now available in the Add-on Preferences page (visible only in Thunderbird). Clicking it reads Thunderbird's password manager via the experiment API, translates each entry to the new This addresses the concern raised in the review about unprompted credential dumps. The user explicitly initiates migration and can see what happened. CalDAV startup OAuth windows (TB bug 2008995)The old implementation tried to close OAuth windows that appeared before the extension was initialised. This was fragile and caused issues. The new implementation adds a hook on For windows that do open before The recommended workaround for first-run CalDAV windows remains enabling offline caching (Calendar → Properties → Offline Support → Keep a local copy). Notification in OAuth browser window
YubiKey / concurrent CalDAV syncsWhen multiple CalDAV calendars sync at the same time, each triggered a separate MV3 background script lifecycleThe background script unloads after ~30 s of inactivity. Two failure modes were addressed:
The Other changes
|
|
Hi @thardeck - sorry it's taken me so long to review this PR! It's clear you've put a lot of work into it. Unfortunately, I don't think that this is really something that belongs in Browserpass - it's well outside the scope of what Browserpass is intended to be, which is a web-browser interface to a pass-style repository of gpg-encrypted website credentials. This is exacerbated somewhat by the esoteric nature of the functionality that this particular PR is intended to implement, for which I suspect the ultimate user base will be extremely small - and quite possibly limited to just yourself. With that said, as Browserpass is a project that tends to change fairly infrequently, it would likely be viable for you to maintain this patchset as an independent fork. I'm happy for us to add a link to the project README that will point any users who want this functionality in your direction (let us know if you'd like that). |
21a088c to
95ce3ec
Compare
|
Thanks for your reply. I would not call it esoteric 😅 , the goal is to have your Thunderbird credentials protected by a hardware token, but you are right that the possible user base might be quite limited.
Sure, that would be an option and quite nice. Many thanks. |
a614ad3 to
23e80f8
Compare
23e80f8 to
d8f4837
Compare
Changes since last pushI ran into some issues with newer Thunderbird versions. They should be fixed now with the latest changes.
|
Intercept Thunderbird's authentication prompts (IMAP, SMTP, POP3,
NNTP) and OAuth2 refresh token lookups (mail, CalDAV, CardDAV) and
serve the credentials from the pass store through the native host.
Pass is the only credential store; nothing is written to
Thunderbird's password manager.
Credentials live under `thunderbird/{protocol}-{hostname}`. OAuth
refresh tokens use one file per provider and account,
`thunderbird/oauth-{provider}-{login}`.
A WebExtension Experiment loads at startup and hooks `MsgAuthPrompt`,
`OAuth2Module` and `OAuth2.prototype.connect`, so calendars asking for
a token before the background script is ready still get it from pass
instead of opening a login window. Synchronous callbacks spin the
event loop while the native host decrypts; concurrent lookups of one
token share a single decrypt, and a Retry dialog is offered when a
hardware GPG key times out.
The background registers its listeners later than the startup event,
so requests arriving first would time out and show Thunderbird's own
password prompt. Hold Thunderbird offline until the first listener is
registered, then restore the configured startup state.
Require Thunderbird 152, where `getRefreshToken` is async.
Also add migration from Thunderbird's password manager, an
informational popup and Thunderbird build targets.
d8f4837 to
d1dfe7b
Compare
Summary (Edited)
This PR adds Thunderbird email client support to the Browserpass browser extension. It allows users to store and retrieve email credentials (IMAP, SMTP, POP3, NNTP) and OAuth tokens (Gmail, Microsoft, Fastmail) from their
passpassword store instead of Thunderbird's built-in password manager.I am already running the implementation locally since a few days. I have tried different setups, fixed several issues on the way and also ran into Thunderbird issues. For debugging purposes I have added quite some logging, which should not hurt and probably at least be kept until more users tried the extension.
I am interested in this feature myself and got some time to work on this. It turned out to be much more code then originally anticipated but there were a lot of edge cases to cover and will probably be some more. Any feedback is appreciated.
Features
OAuth2ModuleandOAuth2.prototype.connecthookspassvia the preferences pagepassTechnical Implementation
Why Separate Builds?
Thunderbird requires WebExtension Experiments to hook into its authentication system, which Firefox doesn't allow for non-privileged add-ons. The experiment API provides access to:
MsgAuthPrompt- Intercepts IMAP/SMTP/POP3/NNTP password promptsOAuth2Module- Intercepts OAuth token requests (getRefreshToken/setRefreshToken) for CalDAV/CardDAVOAuth2.prototype.connect- Populates refresh tokens frompassfor shared OAuth objects that were created without a tokenbrowserRequest- Monitors OAuth browser windows for autofillTherefore, the extension is built separately:
make firefox- Standard browser extensionmake thunderbird- Includes experimental credentials APIThe core extension code remains shared; only the manifest and experiment files differ.
Architecture
Key Design: Pass as Sole Credential Store
Tokens are never written to Thunderbird's built-in
loginManager. Pass is the sole persistent store. Only null tokens (auth failure / revocation) are propagated to clear staleloginManagerentries. The experiment is registered for thestartupevent, so its hooks are installed when Thunderbird starts. Thunderbird is held offline until the background script is ready, so no request falls back to Thunderbird's own prompts.Synchronous Bridge
Some Thunderbird auth callbacks (
MsgAuthPrompt.promptPassword,OAuth2.prototype.connect) are synchronous, but native messaging and the WebExtension background are async. TheawaitSync()helper spins Mozilla's event loop (Services.tm.spinEventLoopUntilOrQuit()) to bridge this gap, with abort detection for background script death.OAuth2Module.getRefreshTokenis async since Thunderbird 152, so its hook returns a promise directly.Requirements
OAuth2Module.getRefreshTokenmake hosts-thunderbird-userto registerTesting
make thunderbirdcd thunderbird && zip -r browserpass-thunderbird.xpi *Password Store Organization
All Thunderbird credentials are stored under
thunderbird/with{protocol}-{hostname}naming. OAuth tokens useoauth-{provider}-{login}, so multiple accounts at the same provider do not overwrite each other. Thehttpsentries are for OAuth identity provider login pages that appear in the OAuth browser window.Design Decisions
1. Early Hook Installation
The experiment API declares the
startupevent in the manifest, so Thunderbird loads it at application startup instead of when the background script first calls it.2. Offline Startup Control
The
startupevent only installs the hooks early. The background script still registers its credential listeners later, while Thunderbird already fires IMAP and OAuth requests. Those requests time out and Thunderbird shows its own password prompt on every start. To avoid this, the experiment forces Thunderbird offline at startup and callsOfflineStartup.onProfileStartup()once the first listener is registered, which restores the user's configured startup state. On shutdown the saved offline state is restored. AstartupReadyguard also suppresses OAuth windows opened by Thunderbird before the background is ready.3. OAuth Token Cache
An in-memory cache keeps tokens that were already decrypted during the session. Without it, parallel calendar syncs and token saves make Thunderbird trigger repeated GPG decrypts and YubiKey touches. Concurrent lookups of one token share a single decrypt.
4. Credential Migration
Migration is explicit and user-triggered via a button in the Browserpass preferences page (only visible in Thunderbird). Credentials are migrated from Thunderbird's password manager to
pass. Existingpassentries are not overwritten.5. One OAuth Token Per Provider and Account
OAuth tokens are stored as one file per provider and account (
thunderbird/oauth-{provider}-{login}.gpg). The scope is stored inside the file for reference.6. Concurrent Lookup Serialization
A
pendingLookupsset ensures only one GPG decrypt runs at a time per token key. Parallel CalDAV/CardDAV syncs spin-wait on the pending lookup rather than starting duplicate decrypts. This is critical for YubiKey users who must physically touch their key for each decrypt.7. Failed Auth Tracking
The extension detects repeated auth prompts for the same account (indicating wrong credentials) and falls back to allowing manual password entry rather than entering an infinite retry loop.
Known Limitations
Breaking Changes
None - this is additive functionality that is mainly added to the Thunderbird extension.
Related PRs
A companion PR to browserpass-native is required to register the native host for Thunderbird:
hosts-thunderbird-userandhosts-thunderbirdMakefile targetsfirefox-host.jsonnative messaging manifestReferences