Commit 1f452783 by Paul Kilgo

fix referencing problems to sshkey_fingerprint

Move sshkey_fingerprint from models.py to util.py. util.py cannot import from
models.py without Django complaining about DJANGO_SETTINGS_MODULE; this is
required by the scripts. The reverse can happen fine though.
parent a5b8402c
...@@ -17,9 +17,8 @@ ...@@ -17,9 +17,8 @@
from django.core.management.base import BaseCommand, CommandError from django.core.management.base import BaseCommand, CommandError
from django.conf import settings from django.conf import settings
from django_sshkey.models import sshkey_fingerprint, UserKey from django_sshkey.models import UserKey
import base64 from django_sshkey.util import sshkey_fingerprint
import hashlib
import sys import sys
class Command(BaseCommand): class Command(BaseCommand):
......
...@@ -18,17 +18,11 @@ ...@@ -18,17 +18,11 @@
from django.db import models from django.db import models
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
import base64 from django_sshkey.util import sshkey_fingerprint
import hashlib
import re import re
sshkey_re = re.compile(r'(?P<type>[\w-]+)\s+(?P<b64key>\S+)(?:\s+(?P<comment>\S+))?$') sshkey_re = re.compile(r'(?P<type>[\w-]+)\s+(?P<b64key>\S+)(?:\s+(?P<comment>\S+))?$')
def sshkey_fingerprint(b64key):
key = base64.b64decode(b64key)
fp_plain = hashlib.md5(key).hexdigest()
return ':'.join(a+b for a,b in zip(fp_plain[::2], fp_plain[1::2]))
class UserKey(models.Model): class UserKey(models.Model):
user = models.ForeignKey(User, db_index=True) user = models.ForeignKey(User, db_index=True)
name = models.CharField(max_length=50, blank=True) name = models.CharField(max_length=50, blank=True)
......
...@@ -15,6 +15,13 @@ ...@@ -15,6 +15,13 @@
# You should have received a copy of the GNU Lesser General Public License # You should have received a copy of the GNU Lesser General Public License
# along with django-sshkey. If not, see <http://www.gnu.org/licenses/>. # along with django-sshkey. If not, see <http://www.gnu.org/licenses/>.
def sshkey_fingerprint(b64key):
import base64
import hashlib
key = base64.b64decode(b64key)
fp_plain = hashlib.md5(key).hexdigest()
return ':'.join(a+b for a,b in zip(fp_plain[::2], fp_plain[1::2]))
def lookup_command(args): def lookup_command(args):
import sys import sys
import urllib import urllib
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment