pyvckit #1
|
@ -12,7 +12,7 @@ from django.http import QueryDict
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
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 pyvckit.verify_vp import verify_vp
|
||||||
|
|
||||||
|
|
||||||
SALT_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
|
SALT_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
|
||||||
|
@ -22,7 +22,7 @@ def gen_salt(length: int) -> str:
|
||||||
"""Generate a random string of SALT_CHARS with specified ``length``."""
|
"""Generate a random string of SALT_CHARS with specified ``length``."""
|
||||||
if length <= 0:
|
if length <= 0:
|
||||||
raise ValueError("Salt length must be positive")
|
raise ValueError("Salt length must be positive")
|
||||||
|
|
||||||
return "".join(secrets.choice(SALT_CHARS) for _ in range(length))
|
return "".join(secrets.choice(SALT_CHARS) for _ in range(length))
|
||||||
|
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ class Organization(models.Model):
|
||||||
For use the packages requests we need use my_client_id
|
For use the packages requests we need use my_client_id
|
||||||
For use in the get or post method of a View, then we need use client_id
|
For use in the get or post method of a View, then we need use client_id
|
||||||
and secret_id.
|
and secret_id.
|
||||||
main is a field which indicates the organization of this idhub
|
main is a field which indicates the organization of this idhub
|
||||||
"""
|
"""
|
||||||
name = models.CharField(max_length=250)
|
name = models.CharField(max_length=250)
|
||||||
domain = models.CharField(max_length=250, null=True, default=None)
|
domain = models.CharField(max_length=250, null=True, default=None)
|
||||||
|
@ -130,7 +130,7 @@ class Organization(models.Model):
|
||||||
sb = secret.SecretBox(sb_key)
|
sb = secret.SecretBox(sb_key)
|
||||||
if not isinstance(data, bytes):
|
if not isinstance(data, bytes):
|
||||||
data = data.encode('utf-8')
|
data = data.encode('utf-8')
|
||||||
|
|
||||||
return base64.b64encode(sb.encrypt(data)).decode('utf-8')
|
return base64.b64encode(sb.encrypt(data)).decode('utf-8')
|
||||||
|
|
||||||
def get_salt(self):
|
def get_salt(self):
|
||||||
|
@ -173,7 +173,7 @@ class Organization(models.Model):
|
||||||
sb = secret.SecretBox(sb_key)
|
sb = secret.SecretBox(sb_key)
|
||||||
if not isinstance(data, bytes):
|
if not isinstance(data, bytes):
|
||||||
data = data.encode('utf-8')
|
data = data.encode('utf-8')
|
||||||
|
|
||||||
encrypted_data = base64.b64encode(sb.encrypt(data)).decode('utf-8')
|
encrypted_data = base64.b64encode(sb.encrypt(data)).decode('utf-8')
|
||||||
self.encrypted_sensitive_data = encrypted_data
|
self.encrypted_sensitive_data = encrypted_data
|
||||||
|
|
||||||
|
@ -261,7 +261,7 @@ class OAuth2VPToken(models.Model):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
code = kwargs.pop("code", None)
|
code = kwargs.pop("code", None)
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
self.authorization = Authorization.objects.filter(code=code).first()
|
self.authorization = Authorization.objects.filter(code=code).first()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -271,7 +271,7 @@ class OAuth2VPToken(models.Model):
|
||||||
return self.authorization.code
|
return self.authorization.code
|
||||||
|
|
||||||
def verifing(self):
|
def verifing(self):
|
||||||
self.result_verify = verify_presentation(self.vp_token)
|
self.result_verify = verify_vp(self.vp_token)
|
||||||
|
|
||||||
def get_result_verify(self):
|
def get_result_verify(self):
|
||||||
if not self.result_verify:
|
if not self.result_verify:
|
||||||
|
@ -284,11 +284,10 @@ class OAuth2VPToken(models.Model):
|
||||||
"redirect_uri": "",
|
"redirect_uri": "",
|
||||||
"response": "",
|
"response": "",
|
||||||
}
|
}
|
||||||
verification = json.loads(self.result_verify)
|
if not self.result_verify:
|
||||||
if verification.get('errors') or verification.get('warnings'):
|
|
||||||
response["verify"] = "Error, {}".format(_("Failed verification"))
|
response["verify"] = "Error, {}".format(_("Failed verification"))
|
||||||
return response
|
return response
|
||||||
|
|
||||||
response["verify"] = "Ok, {}".format(_("Correct verification"))
|
response["verify"] = "Ok, {}".format(_("Correct verification"))
|
||||||
url = self.get_redirect_url()
|
url = self.get_redirect_url()
|
||||||
if url:
|
if url:
|
||||||
|
|
Loading…
Reference in a new issue