2016-01-10 20:58:11 +00:00
|
|
|
import os
|
2015-07-13 18:49:08 +00:00
|
|
|
from Crypto.PublicKey import RSA
|
|
|
|
|
2016-01-10 20:58:11 +00:00
|
|
|
from oidc_provider import settings
|
2015-10-17 21:02:37 +00:00
|
|
|
from django.core.management.base import BaseCommand
|
2015-07-13 18:49:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Command(BaseCommand):
|
|
|
|
help = 'Randomly generate a new RSA key for the OpenID server'
|
|
|
|
|
|
|
|
def handle(self, *args, **options):
|
|
|
|
try:
|
|
|
|
key = RSA.generate(1024)
|
2016-01-10 20:58:11 +00:00
|
|
|
file_path = os.path.join(settings.get('OIDC_RSA_KEY_FOLDER'), 'OIDC_RSA_KEY.pem')
|
2015-10-17 21:12:15 +00:00
|
|
|
with open(file_path, 'wb') as f:
|
2015-07-13 18:49:08 +00:00
|
|
|
f.write(key.exportKey('PEM'))
|
|
|
|
self.stdout.write('RSA key successfully created at: ' + file_path)
|
|
|
|
except Exception as e:
|
2015-10-17 21:06:41 +00:00
|
|
|
self.stdout.write('Something goes wrong: {0}'.format(e))
|