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_key.py

22 lines
571 B
Python
Raw Normal View History

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