Skip to content
Snippets Groups Projects
Verified Commit 27e91982 authored by Frank Sauerburger's avatar Frank Sauerburger
Browse files

Add draft version of HKP and WKD

parent b23c2c48
No related branches found
No related tags found
1 merge request!2Resolve "Decode OpenPGP and display details"
from django.contrib import admin
# Register your models here.
from django.apps import AppConfig
class HkpConfig(AppConfig):
name = 'hkp'
from django.db import models
# Create your models here.
from django.test import TestCase
# Create your tests here.
"""keys URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/3.1/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.urls import path
from . import views
urlpatterns = [
path("lookup", views.lookup, name="hkp-lookup"),
]
from django.shortcuts import render, get_object_or_404
from django.http import HttpResponse
from django.views.decorators.http import require_safe
from pgp import models
class HttpNotImplementedError(HttpResponse):
status_code = 501
@require_safe
def lookup(request):
op = request.GET.get('op', None)
search = request.GET.get('search', None)
if op not in ["get"]:
return HttpNotImplementedError("Not implemented")
if search.startswith("0x"):
search = search[2:]
key = get_object_or_404(models.PublicKey, keyid__endswith=search)
return HttpResponse(key.armor, content_type="application/pgp-keys")
......@@ -21,5 +21,6 @@ urlpatterns = [
path('pgp/', include('pgp.urls')),
path('ssh/', include('ssh.urls')),
path('pks/', include('hkp.urls')),
path('.well-known/openpgpkey/', include('wkd.urls')),
path('admin/', admin.site.urls),
]
......@@ -7,6 +7,6 @@ class Command(BaseCommand):
print("Setting key ids")
for key in PublicKey.objects.filter(keyid__isnull=True):
print(f" Update {key.details().fingerprint}")
key.keyid = key.set_keyid()
key.set_keyid()
key.save()
print("Done")
from django.core.management.base import BaseCommand
from pgp.models import PublicKey
class Command(BaseCommand):
def handle(self, *args, **options):
print("Setting WKD ids")
for key in PublicKey.objects.filter(wkdid__isnull=True):
print(f" Update {key.email}")
key.set_wkdid()
key.save()
print("Done")
# Generated by Django 3.1.3 on 2021-02-21 16:25
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('pgp', '0002_publickey_keyid'),
]
operations = [
migrations.AddField(
model_name='publickey',
name='wkdid',
field=models.CharField(blank=True, max_length=32, null=True),
),
]
import re
import hashlib
from django.db import models
import pgpy
from . import zbase32
class PublicKey(models.Model):
email = models.CharField(max_length=128)
armor = models.TextField()
keyid = models.CharField(max_length=40, null=True, blank=True)
wkdid = models.CharField(max_length=32, null=True, blank=True)
def __init__(self, *args, **kwds):
super().__init__(*args, **kwds)
......@@ -16,9 +20,17 @@ class PublicKey(models.Model):
fingerprint = self.decoded.fingerprint
self.keyid = re.sub("\s+", "", fingerprint).lower()
def set_wkdid(self):
local, domain = self.email.rsplit("@", 1)
digest = hashlib.sha1(local.encode()).digest()
self.wkdid = zbase32.encode(digest).decode()
def save(self, *args, **kwds):
if not self.keyid:
self.set_keyid()
if not self.wkdid:
self.set_wkdid()
super().save(*args, **kwds)
......
import base64
original_alph = b"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"
zbase_alph = b"ybndrfg8ejkmcpqxot1uwisza345h769"
encode_trans = bytes.maketrans(original_alph, zbase_alph)
decode_trans = bytes.maketrans(zbase_alph, original_alph)
def encode(value):
encoded = base64.b32encode(value)
return encoded.translate(encode_trans)
def decode(value):
translated = value.translate(decode_trans)
return base64.b32decode(translated)
from django.contrib import admin
# Register your models here.
from django.apps import AppConfig
class WkdConfig(AppConfig):
name = 'wkd'
from django.db import models
# Create your models here.
from django.test import TestCase
# Create your tests here.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment