This repository has been archived on 2021-04-21. You can view files and clone it, but cannot push or open issues or pull requests.
djangoldp-webpushnotification/djangoldp_webpushnotification/management/commands/gen_vapid_keys.py

23 lines
625 B
Python
Raw Normal View History

import ecdsa
from ecdsa import SigningKey
from base64 import urlsafe_b64encode
from django.core.management.base import BaseCommand
from djangoldp_notification.models import VAPIDKeyset
class Command(BaseCommand):
help = "Generate VAPID key pair"
def handle(self, *args, **options):
priv_key = SigningKey.generate(curve=ecdsa.NIST256p)
pub_key = priv_key.get_verifying_key()
VAPIDKeyset.objects.create(
public_key=urlsafe_b64encode(b"\x04" + pub_key.to_string()).strip(b"="),
private_key=urlsafe_b64encode(priv_key.to_string()).strip(b"=")
)
self.stdout.write("VAPID Keyset succesfully generated")
exit(0)