Skip to content

Commit

Permalink
protondrive: implement two-password mode (rclone#7279)
Browse files Browse the repository at this point in the history
  • Loading branch information
henrybear327 authored Sep 8, 2023
1 parent 071c3f2 commit ed755bf
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
30 changes: 25 additions & 5 deletions backend/protondrive/protondrive.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,23 @@ func init() {
NewFs: NewFs,
Options: []fs.Option{{
Name: "username",
Help: `The username of your proton drive account`,
Help: `The username of your proton account`,
Required: true,
}, {
Name: "password",
Help: "The password of your proton drive account.",
Help: "The password of your proton account.",
Required: true,
IsPassword: true,
}, {
Name: "mailboxPassword",
Help: `The mailbox password of your two-password proton account.
For more information regarding the mailbox password, please check the
following official knowledge base article:
https://proton.me/support/the-difference-between-the-mailbox-password-and-login-password
`,
IsPassword: true,
Advanced: true,
}, {
Name: "2fa",
Help: `The 2FA code
Expand Down Expand Up @@ -149,9 +159,10 @@ then we might have a problem with caching the stale data.`,

// Options defines the configuration for this backend
type Options struct {
Username string `config:"username"`
Password string `config:"password"`
TwoFA string `config:"2fa"`
Username string `config:"username"`
Password string `config:"password"`
MailboxPassword string `config:"mailboxPassword"`
TwoFA string `config:"2fa"`

// advanced
Enc encoder.MultiEncoder `config:"encoding"`
Expand Down Expand Up @@ -313,6 +324,7 @@ func newProtonDrive(ctx context.Context, f *Fs, opt *Options, m configmap.Mapper
config.UseReusableLogin = false
config.FirstLoginCredential.Username = opt.Username
config.FirstLoginCredential.Password = opt.Password
config.FirstLoginCredential.MailboxPassword = opt.MailboxPassword
config.FirstLoginCredential.TwoFA = opt.TwoFA
protonDrive, auth, err := protonDriveAPI.NewProtonDrive(ctx, config, authHandler, deAuthHandler)
if err != nil {
Expand Down Expand Up @@ -344,6 +356,14 @@ func NewFs(ctx context.Context, name, root string, m configmap.Mapper) (fs.Fs, e
}
}

if opt.MailboxPassword != "" {
var err error
opt.MailboxPassword, err = obscure.Reveal(opt.MailboxPassword)
if err != nil {
return nil, fmt.Errorf("couldn't decrypt mailbox password: %w", err)
}
}

ci := fs.GetConfig(ctx)

root = strings.Trim(root, "/")
Expand Down
6 changes: 5 additions & 1 deletion docs/content/protondrive.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ To copy a local directory to an Proton Drive directory called backup

### Modified time

Proton Drive Bridge does not support modification times yet.
Proton Drive Bridge does not support updating modification times yet.

### Restricted filename characters

Expand All @@ -103,6 +103,10 @@ Proton Drive can not have two files with exactly the same name and path. If the
conflict occurs, depending on the advanced config, the file might or might not
be overwritten.

### [Mailbox password](https://proton.me/support/the-difference-between-the-mailbox-password-and-login-password)

Please set your mailbox password in the advanced config section.

### Caching

The cache is currently built for the case when the rclone is the only instance
Expand Down

0 comments on commit ed755bf

Please sign in to comment.