mirror of
https://github.com/henrybear327/Proton-API-Bridge.git
synced 2026-02-23 10:28:31 -05:00
Merge pull request #14 from henrybear327/feat/two_password_mode
Add two-password mode
This commit is contained in:
@@ -30,9 +30,10 @@ type Config struct {
|
||||
}
|
||||
|
||||
type FirstLoginCredentialData struct {
|
||||
Username string
|
||||
Password string
|
||||
TwoFA string
|
||||
Username string
|
||||
Password string
|
||||
MailboxPassword string
|
||||
TwoFA string
|
||||
}
|
||||
|
||||
type ReusableCredentialData struct {
|
||||
@@ -50,9 +51,10 @@ func NewConfigWithDefaultValues() *Config {
|
||||
UserAgent: "",
|
||||
|
||||
FirstLoginCredential: &FirstLoginCredentialData{
|
||||
Username: "",
|
||||
Password: "",
|
||||
TwoFA: "",
|
||||
Username: "",
|
||||
Password: "",
|
||||
MailboxPassword: "",
|
||||
TwoFA: "",
|
||||
},
|
||||
ReusableCredential: &ReusableCredentialData{
|
||||
UID: "",
|
||||
@@ -100,9 +102,10 @@ func NewConfigForIntegrationTests() *Config {
|
||||
UserAgent: userAgent,
|
||||
|
||||
FirstLoginCredential: &FirstLoginCredentialData{
|
||||
Username: username,
|
||||
Password: password,
|
||||
TwoFA: twoFA,
|
||||
Username: username,
|
||||
Password: password,
|
||||
MailboxPassword: "",
|
||||
TwoFA: twoFA,
|
||||
},
|
||||
ReusableCredential: &ReusableCredentialData{
|
||||
UID: uid,
|
||||
|
||||
@@ -8,4 +8,5 @@ var (
|
||||
|
||||
ErrUsernameAndPasswordRequired = errors.New("username and password are required")
|
||||
Err2FACodeRequired = errors.New("this account requires a 2FA code")
|
||||
ErrMailboxPasswordRequired = errors.New("this account requires a mailbox password")
|
||||
)
|
||||
|
||||
@@ -106,9 +106,20 @@ func Login(ctx context.Context, config *Config, authHandler proton.AuthHandler,
|
||||
}
|
||||
}
|
||||
|
||||
var keyPass []byte
|
||||
if auth.PasswordMode == proton.TwoPasswordMode {
|
||||
if config.FirstLoginCredential.MailboxPassword != "" {
|
||||
keyPass = []byte(config.FirstLoginCredential.MailboxPassword)
|
||||
} else {
|
||||
return nil, nil, nil, nil, nil, nil, ErrMailboxPasswordRequired
|
||||
}
|
||||
} else {
|
||||
keyPass = []byte(config.FirstLoginCredential.Password)
|
||||
}
|
||||
|
||||
// decrypt keyring
|
||||
var saltedKeyPassByteArr []byte
|
||||
userKR, addrKRs, addr, saltedKeyPassByteArr, err = getAccountKRs(ctx, c, []byte(password), nil)
|
||||
userKR, addrKRs, addr, saltedKeyPassByteArr, err = getAccountKRs(ctx, c, keyPass, nil)
|
||||
if err != nil {
|
||||
return nil, nil, nil, nil, nil, nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user