fixed key to one line
This commit is contained in:
@@ -31,26 +31,33 @@ def generate_vapid_keys():
|
||||
# Generate EC private key
|
||||
private_key = ec.generate_private_key(ec.SECP256R1())
|
||||
|
||||
# Serialize private key
|
||||
# Serialize private key to PEM format
|
||||
private_pem = private_key.private_bytes(
|
||||
encoding=serialization.Encoding.PEM,
|
||||
format=serialization.PrivateFormat.PKCS8,
|
||||
encryption_algorithm=serialization.NoEncryption()
|
||||
)
|
||||
).decode('utf-8')
|
||||
|
||||
# Format for .env file (replace newlines with \n)
|
||||
env_private_key = private_pem.strip().replace('\n', '\\n')
|
||||
|
||||
# Get public key
|
||||
public_key = private_key.public_key()
|
||||
public_pem = public_key.public_bytes(
|
||||
public_key_bytes = public_key.public_bytes(
|
||||
encoding=serialization.Encoding.X962,
|
||||
format=serialization.PublicFormat.UncompressedPoint
|
||||
)
|
||||
|
||||
# Base64 encode keys
|
||||
env_vars['VAPID_PRIVATE_KEY'] = base64.urlsafe_b64encode(private_pem).decode('utf-8')
|
||||
env_vars['VAPID_PUBLIC_KEY'] = base64.urlsafe_b64encode(public_pem).decode('utf-8')
|
||||
print("New VAPID keys generated and added to .env file.")
|
||||
# Store keys
|
||||
env_vars['VAPID_PRIVATE_KEY'] = env_private_key # Single-line format
|
||||
env_vars['VAPID_PUBLIC_KEY'] = base64.urlsafe_b64encode(public_key_bytes).decode('utf-8')
|
||||
|
||||
print("New VAPID keys generated in .env-compatible format.")
|
||||
else:
|
||||
print("Existing VAPID keys found in .env file - no changes made.")
|
||||
print("Existing VAPID keys found - no changes made.")
|
||||
# Verify existing key format
|
||||
if '-----BEGIN PRIVATE KEY-----' not in env_vars['VAPID_PRIVATE_KEY']:
|
||||
print("Warning: Existing private key doesn't appear to be in PEM format!")
|
||||
|
||||
# Ensure we have all required configuration variables with defaults if missing
|
||||
defaults = {
|
||||
|
||||
Reference in New Issue
Block a user