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