fixed key to one line
This commit is contained in:
30
app.py
30
app.py
@@ -42,7 +42,7 @@ class FlicButtonHandler:
|
||||
}
|
||||
|
||||
# Ensure subscriptions file and directory exist
|
||||
self.subscriptions_file = os.getenv('SUBSCRIPTIONS_FILE', '/app/subscriptions.json')
|
||||
self.subscriptions_file = os.getenv('SUBSCRIPTIONS_FILE', 'app/subscriptions.json')
|
||||
self._ensure_subscriptions_file()
|
||||
|
||||
# Load subscriptions
|
||||
@@ -70,26 +70,30 @@ class FlicButtonHandler:
|
||||
|
||||
def _decode_vapid_private_key(self):
|
||||
"""
|
||||
Decode and load the VAPID private key from base64 encoded string.
|
||||
Returns the PEM-formatted private key as a string.
|
||||
Load the VAPID private key from environment variable.
|
||||
Handles the \n escaped format from .env file.
|
||||
"""
|
||||
try:
|
||||
# Decode base64 private key
|
||||
private_key_pem = base64.urlsafe_b64decode(
|
||||
os.getenv('VAPID_PRIVATE_KEY', '').encode('utf-8')
|
||||
)
|
||||
# Get the key from environment
|
||||
env_key = os.getenv('VAPID_PRIVATE_KEY', '').strip()
|
||||
|
||||
# Load private key to validate it
|
||||
private_key = serialization.load_pem_private_key(
|
||||
private_key_pem,
|
||||
# Convert escaped newlines back to actual newlines
|
||||
private_pem = env_key.replace('\\n', '\n')
|
||||
|
||||
# Verify PEM format
|
||||
if not private_pem.startswith('-----BEGIN PRIVATE KEY-----'):
|
||||
raise ValueError("Invalid PEM format")
|
||||
|
||||
# Validate the key
|
||||
serialization.load_pem_private_key(
|
||||
private_pem.encode('utf-8'),
|
||||
password=None
|
||||
)
|
||||
|
||||
# Return the original PEM string (pywebpush needs this format)
|
||||
return private_key_pem.decode('utf-8')
|
||||
return private_pem
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error loading VAPID private key: {e}")
|
||||
logger.error(f"VAPID key error: {str(e)}")
|
||||
raise
|
||||
|
||||
def load_subscriptions(self) -> List[Dict]:
|
||||
|
||||
Reference in New Issue
Block a user