feat: add SRP authentication, improve security
- Replace RSA key exchange with SRP (Secure Remote Password) - Password never transmitted over network - Add unit tests for endpoints - Fix datetime.UTC compatibility for Python < 3.11 - Fix logger.exception usage - Update README with new auth flow diagram
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
from dataclasses import dataclass, field
|
||||
from uuid import uuid4
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timezone
|
||||
from typing import Optional
|
||||
|
||||
|
||||
@@ -8,7 +8,9 @@ from typing import Optional
|
||||
class Message:
|
||||
id: str = field(default_factory=lambda: str(uuid4()))
|
||||
text: str = ""
|
||||
timestamp: str = field(default_factory=lambda: datetime.utcnow().isoformat())
|
||||
timestamp: str = field(
|
||||
default_factory=lambda: datetime.now(timezone.utc).isoformat()
|
||||
)
|
||||
user_ip: str = ""
|
||||
username: str = ""
|
||||
|
||||
@@ -19,13 +21,17 @@ class UserSession:
|
||||
ip: str
|
||||
username: str = "unknown"
|
||||
fernet_key: Optional[bytes] = None
|
||||
created_at: str = field(default_factory=lambda: datetime.utcnow().isoformat())
|
||||
last_activity: str = field(default_factory=lambda: datetime.utcnow().isoformat())
|
||||
created_at: str = field(
|
||||
default_factory=lambda: datetime.now(timezone.utc).isoformat()
|
||||
)
|
||||
last_activity: str = field(
|
||||
default_factory=lambda: datetime.now(timezone.utc).isoformat()
|
||||
)
|
||||
active: bool = True
|
||||
|
||||
def update_activity(self):
|
||||
self.last_activity = datetime.utcnow().isoformat()
|
||||
self.last_activity = datetime.now(timezone.utc).isoformat()
|
||||
|
||||
def is_stale(self, timeout_seconds: int = 3600) -> bool:
|
||||
last = datetime.fromisoformat(self.last_activity)
|
||||
return (datetime.utcnow() - last).total_seconds() > timeout_seconds
|
||||
return (datetime.now(timezone.utc) - last).total_seconds() > timeout_seconds
|
||||
|
||||
Reference in New Issue
Block a user