Verified Commit 18ca366e authored by Baptiste Beauplat's avatar Baptiste Beauplat
Browse files

Implement HKP get operation (Closes #139)

Allow mentors to act as a keyserver.
Example: gpg --keyserver hkps://mentors.debian.net --recv-keys 0x1234567
parent 9a9dba52
# views.py - keyring view classes
#
# This file is part of debexpo
# https://salsa.debian.org/mentors.debian.net-team/debexpo
#
# Copyright © 2021 Baptiste Beauplat <lyknode@debian.org>
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation
# files (the "Software"), to deal in the Software without
# restriction, including without limitation the rights to use,
# copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following
# conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
from django.views.generic import View
from django.views.generic.detail import BaseDetailView
from django.http import HttpResponseServerError, HttpResponse, \
HttpResponseBadRequest
from django.shortcuts import get_object_or_404
from debexpo.keyring.models import Key
class HKPSearchView(BaseDetailView):
model = Key
def get(self, request, *args, **kwargs):
if 'search' not in self.request.GET:
return HttpResponseBadRequest("Missing 'search' query string")
try:
return super().get(request, *args, **kwargs)
except Key.MultipleObjectsReturned:
return HttpResponseServerError('Multiple matches found', status=500)
def get_object(self, queryset=None):
key_id = self.request.GET['search'].replace('0x', '')
return get_object_or_404(Key, fingerprint__endswith=key_id)
def render_to_response(self, context, **response_kwargs):
return HttpResponse(self.object.key + '\n')
class HKPView(View):
def get(self, request, *args, **kwargs):
if 'op' not in self.request.GET:
return HttpResponseBadRequest("Missing 'op' query string")
if self.request.GET['op'] == 'get':
return HKPSearchView.as_view()(request)
else:
return HttpResponseServerError('Not Implemented', status=501)
...@@ -41,6 +41,7 @@ from debexpo.base.views import index, contact, intro_reviewers, \ ...@@ -41,6 +41,7 @@ from debexpo.base.views import index, contact, intro_reviewers, \
intro_maintainers, qa, sponsor_overview, sponsor_guidelines, sponsor_rfs intro_maintainers, qa, sponsor_overview, sponsor_guidelines, sponsor_rfs
from debexpo.accounts.views import register, profile, EmailChangeConfirmView from debexpo.accounts.views import register, profile, EmailChangeConfirmView
from debexpo.accounts.forms import PasswordResetForm from debexpo.accounts.forms import PasswordResetForm
from debexpo.keyring.views import HKPView
from debexpo.packages.views import package, packages, packages_my, \ from debexpo.packages.views import package, packages, packages_my, \
PackagesFeed, sponsor_package, delete_package, delete_upload, \ PackagesFeed, sponsor_package, delete_package, delete_upload, \
PackageViewSet, PackageUploadViewSet PackageViewSet, PackageUploadViewSet
...@@ -167,6 +168,9 @@ urlpatterns = [ ...@@ -167,6 +168,9 @@ urlpatterns = [
url(r'^accounts/$', lambda request: HttpResponsePermanentRedirect( url(r'^accounts/$', lambda request: HttpResponsePermanentRedirect(
reverse('profile')), name='accounts'), reverse('profile')), name='accounts'),
# HPK interface
url(r'^pks/lookup$', HKPView.as_view(), name='hkp'),
# Repository # Repository
url(r'^debian/(?P<path>.*)$', serve, { url(r'^debian/(?P<path>.*)$', serve, {
'document_root': settings.REPOSITORY, 'document_root': settings.REPOSITORY,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment