You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

accountreg.go 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Copyright (c) 2016-2017 Daniel Oaks <daniel@danieloaks.net>
  2. // released under the MIT license
  3. package irc
  4. import (
  5. "fmt"
  6. "github.com/tidwall/buntdb"
  7. )
  8. // AccountRegistration manages the registration of accounts.
  9. type AccountRegistration struct {
  10. Enabled bool
  11. EnabledCallbacks []string
  12. EnabledCredentialTypes []string
  13. AllowMultiplePerConnection bool
  14. }
  15. // AccountCredentials stores the various methods for verifying accounts.
  16. type AccountCredentials struct {
  17. PassphraseSalt []byte
  18. PassphraseHash []byte
  19. Certificate string // fingerprint
  20. }
  21. // NewAccountRegistration returns a new AccountRegistration, configured correctly.
  22. func NewAccountRegistration(config AccountRegistrationConfig) (accountReg AccountRegistration) {
  23. if config.Enabled {
  24. accountReg.Enabled = true
  25. accountReg.AllowMultiplePerConnection = config.AllowMultiplePerConnection
  26. for _, name := range config.EnabledCallbacks {
  27. // we store "none" as "*" internally
  28. if name == "none" {
  29. name = "*"
  30. }
  31. accountReg.EnabledCallbacks = append(accountReg.EnabledCallbacks, name)
  32. }
  33. // no need to make this configurable, right now at least
  34. accountReg.EnabledCredentialTypes = []string{
  35. "passphrase",
  36. "certfp",
  37. }
  38. }
  39. return accountReg
  40. }
  41. // removeFailedAccRegisterData removes the data created by ACC REGISTER if the account creation fails early.
  42. func removeFailedAccRegisterData(store *buntdb.DB, account string) {
  43. // error is ignored here, we can't do much about it anyways
  44. store.Update(func(tx *buntdb.Tx) error {
  45. tx.Delete(fmt.Sprintf(keyAccountExists, account))
  46. tx.Delete(fmt.Sprintf(keyAccountRegTime, account))
  47. tx.Delete(fmt.Sprintf(keyAccountCredentials, account))
  48. return nil
  49. })
  50. }