Skip to content

Commit

Permalink
Add extra salt
Browse files Browse the repository at this point in the history
closes #47
  • Loading branch information
sfan5 committed Jul 20, 2024
1 parent 192c13d commit 2c1e5b3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
5 changes: 5 additions & 0 deletions config.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ bot_token: "BOT_TOKEN_HERE"
# both take a single argument which is the database file path
database: [sqlite, "secretlounge.sqlite"]

# salt used for obfuscating user IDs (optional)
# Needs to be a hexadecimal string, use e.g. `openssl rand -hex 6` to generate.
# It is recommended to set this. Reusing it between different bots is allowed.
#secret_salt: ""

# relay contacts
allow_contacts: false
# relay arbitrary documents/files (GIFs always work)
Expand Down
3 changes: 3 additions & 0 deletions secretlounge_ng/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ def init(config: dict, _db, _ch):
if config.get("locale"):
rp.localization = import_module("..replies_" + config["locale"], __name__).localization

if config.get("secret_salt"):
User.setSalt(bytes.fromhex(config["secret_salt"]))

# initialize db if empty
if db.getSystemConfig() is None:
c = SystemConfig()
Expand Down
9 changes: 8 additions & 1 deletion secretlounge_ng/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ def defaults(self):

class User():
__slots__ = USER_PROPS
global_salt = b""

id: int
username: Optional[str]
realname: str
Expand All @@ -43,6 +45,11 @@ class User():
hideKarma: bool
debugEnabled: bool
tripcode: Optional[str]

@staticmethod
def setSalt(salt):
assert all(isinstance(v, int) for v in salt)
User.global_salt = salt
def __init__(self):
for k in USER_PROPS:
setattr(self, k, None)
Expand All @@ -68,7 +75,7 @@ def isBlacklisted(self):
return self.rank < 0
def getObfuscatedId(self):
salt = date.today().toordinal()
value = fnv32a([self.id, salt], [])
value = fnv32a([self.id, salt], [User.global_salt])
# stringify 20 bits
return ''.join(ID_ALPHA[n%32] for n in (value, value>>5, value>>10, value>>15))
def getObfuscatedKarma(self):
Expand Down

0 comments on commit 2c1e5b3

Please sign in to comment.