fix new encrypted for oidc4vp

This commit is contained in:
Cayo Puigdefabregas 2024-02-21 12:13:08 +01:00
parent 910aa7c888
commit 79f299adda
3 changed files with 3 additions and 16 deletions

View file

@ -1,14 +1,11 @@
import json import json
import requests
from django import forms from django import forms
from django.conf import settings
from django.template.loader import get_template from django.template.loader import get_template
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
from utils.idhub_ssikit import create_verifiable_presentation from utils.idhub_ssikit import create_verifiable_presentation
from oidc4vp.models import Organization
from idhub.models import VerificableCredential from idhub.models import VerificableCredential
@ -19,7 +16,6 @@ class AuthorizeForm(forms.Form):
self.user = kwargs.pop('user', None) self.user = kwargs.pop('user', None)
self.org = kwargs.pop('org', None) self.org = kwargs.pop('org', None)
self.code = kwargs.pop('code', None) self.code = kwargs.pop('code', None)
self.pw = kwargs.pop('pw', None)
self.presentation_definition = kwargs.pop('presentation_definition', []) self.presentation_definition = kwargs.pop('presentation_definition', [])
self.subject_did = None self.subject_did = None
@ -53,7 +49,6 @@ class AuthorizeForm(forms.Form):
cred = self.user.decrypt_data( cred = self.user.decrypt_data(
c.data, c.data,
self.pw
) )
self.subject_did = c.subject_did self.subject_did = c.subject_did
self.list_credentials.append(cred) self.list_credentials.append(cred)
@ -85,5 +80,5 @@ class AuthorizeForm(forms.Form):
"verifiable_credential_list": vc_list "verifiable_credential_list": vc_list
} }
unsigned_vp = vp_template.render(context) unsigned_vp = vp_template.render(context)
key_material = did.get_key_material(self.pw) key_material = did.get_key_material()
self.vp = create_verifiable_presentation(key_material, unsigned_vp) self.vp = create_verifiable_presentation(key_material, unsigned_vp)

View file

@ -5,7 +5,6 @@ import secrets
from django.conf import settings from django.conf import settings
from django.http import QueryDict from django.http import QueryDict
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from django.shortcuts import get_object_or_404
from idhub_auth.models import User from idhub_auth.models import User
from django.db import models from django.db import models
from utils.idhub_ssikit import verify_presentation from utils.idhub_ssikit import verify_presentation

View file

@ -16,7 +16,6 @@ from idhub.mixins import UserView
from idhub.models import Event from idhub.models import Event
from oidc4vp.forms import AuthorizeForm from oidc4vp.forms import AuthorizeForm
from utils.idhub_ssikit import verify_presentation
class AuthorizeView(UserView, FormView): class AuthorizeView(UserView, FormView):
@ -39,16 +38,11 @@ class AuthorizeView(UserView, FormView):
kwargs['user'] = self.request.user kwargs['user'] = self.request.user
try: try:
vps = json.loads(self.request.GET.get('presentation_definition')) vps = json.loads(self.request.GET.get('presentation_definition'))
except: except Exception:
vps = [] vps = []
kwargs['presentation_definition'] = vps kwargs['presentation_definition'] = vps
kwargs["org"] = self.get_org() kwargs["org"] = self.get_org()
kwargs["code"] = self.request.GET.get('code') kwargs["code"] = self.request.GET.get('code')
enc_pw = self.request.session["key_did"]
kwargs['pw'] = self.request.user.decrypt_data(
enc_pw,
self.request.user.password+self.request.session._session_key
)
return kwargs return kwargs
def get_form(self, form_class=None): def get_form(self, form_class=None):
@ -64,7 +58,7 @@ class AuthorizeView(UserView, FormView):
return redirect(self.success_url) return redirect(self.success_url)
try: try:
authorization = authorization.json() authorization = authorization.json()
except: except Exception:
messages.error(self.request, _("Error sending credential!")) messages.error(self.request, _("Error sending credential!"))
return redirect(self.success_url) return redirect(self.success_url)
@ -148,7 +142,6 @@ class VerifyView(View):
if len(auth_data) == 2 and auth_data[0].lower() == 'basic': if len(auth_data) == 2 and auth_data[0].lower() == 'basic':
decoded_auth = base64.b64decode(auth_data[1]).decode('utf-8') decoded_auth = base64.b64decode(auth_data[1]).decode('utf-8')
client_id, client_secret = decoded_auth.split(':', 1) client_id, client_secret = decoded_auth.split(':', 1)
org_url = request.GET.get('demand_uri')
org = get_object_or_404( org = get_object_or_404(
Organization, Organization,
client_id=client_id, client_id=client_id,