Browse Source

add autogeneration of SCRAM credentials on successful PLAIN

tags/v2.8.0-rc1
Shivaram Lingamneni 2 years ago
parent
commit
4dd9af8f06
1 changed files with 12 additions and 3 deletions
  1. 12
    3
      irc/accounts.go

+ 12
- 3
irc/accounts.go View File

1113
 		if passwd.CompareHashAndPassword(account.Credentials.PassphraseHash, []byte(passphrase)) != nil {
1113
 		if passwd.CompareHashAndPassword(account.Credentials.PassphraseHash, []byte(passphrase)) != nil {
1114
 			err = errAccountInvalidCredentials
1114
 			err = errAccountInvalidCredentials
1115
 		}
1115
 		}
1116
+		if err == nil && account.Credentials.SCRAMCreds.Iters == 0 {
1117
+			// XXX: if the account was created prior to 2.8, it doesn't have SCRAM credentials;
1118
+			// since we temporarily have access to a valid plaintext password, create them:
1119
+			am.rehashPassword(account.Name, passphrase)
1120
+		}
1116
 	case -1:
1121
 	case -1:
1117
 		err = am.checkLegacyPassphrase(migrations.CheckAthemePassphrase, accountName, account.Credentials.PassphraseHash, passphrase)
1122
 		err = am.checkLegacyPassphrase(migrations.CheckAthemePassphrase, accountName, account.Credentials.PassphraseHash, passphrase)
1118
 	case -2:
1123
 	case -2:
1132
 		return errAccountInvalidCredentials
1137
 		return errAccountInvalidCredentials
1133
 	}
1138
 	}
1134
 	// re-hash the passphrase with the latest algorithm
1139
 	// re-hash the passphrase with the latest algorithm
1135
-	err = am.setPassword(account, passphrase, true)
1140
+	am.rehashPassword(account, passphrase)
1141
+	return nil
1142
+}
1143
+
1144
+func (am *AccountManager) rehashPassword(accountName, passphrase string) {
1145
+	err := am.setPassword(accountName, passphrase, true)
1136
 	if err != nil {
1146
 	if err != nil {
1137
-		am.server.logger.Error("internal", "could not upgrade user password", err.Error())
1147
+		am.server.logger.Error("internal", "could not upgrade user password", accountName, err.Error())
1138
 	}
1148
 	}
1139
-	return nil
1140
 }
1149
 }
1141
 
1150
 
1142
 func (am *AccountManager) loadWithAutocreation(accountName string, autocreate bool) (account ClientAccount, err error) {
1151
 func (am *AccountManager) loadWithAutocreation(accountName string, autocreate bool) (account ClientAccount, err error) {

Loading…
Cancel
Save