DPP/DLT functionality #36
16
did/views.py
16
did/views.py
|
@ -4,6 +4,7 @@ import logging
|
|||
from django.http import JsonResponse, Http404
|
||||
from django.views.generic.base import TemplateView
|
||||
from device.models import Device
|
||||
from evidence.parse import Build
|
||||
from dpp.api_dlt import ALGORITHM
|
||||
from dpp.models import Proof
|
||||
from dpp.api_dlt import PROOF_TYPE
|
||||
|
@ -93,6 +94,8 @@ class PublicDeviceWebView(TemplateView):
|
|||
'algorithm': ALGORITHM,
|
||||
'components': components,
|
||||
'manufacturer DPP': '',
|
||||
'device': {},
|
||||
'components': [],
|
||||
}
|
||||
result = {
|
||||
'@context': ['https://ereuse.org/dpp0.json'],
|
||||
|
@ -100,7 +103,11 @@ class PublicDeviceWebView(TemplateView):
|
|||
}
|
||||
|
||||
if len(self.pk.split(":")) > 1:
|
||||
data['document'] = json.dumps(self.object.last_evidence.doc)
|
||||
dev = Build(self.object.last_evidence.doc, None, check=True)
|
||||
doc = dev.get_phid()
|
||||
data['document'] = json.dumps(doc)
|
||||
data['device'] = dev.device
|
||||
data['components'] = dev.components
|
||||
|
||||
self.object.get_evidences()
|
||||
last_dpp = Proof.objects.filter(
|
||||
|
@ -122,13 +129,18 @@ class PublicDeviceWebView(TemplateView):
|
|||
self.object.initial()
|
||||
for d in self.object.evidences:
|
||||
d.get_doc()
|
||||
ev = json.dumps(d.doc)
|
||||
dev = Build(d.doc, None, check=True)
|
||||
doc = dev.get_phid()
|
||||
ev = json.dumps(doc)
|
||||
rr = {
|
||||
'dpp': d.key,
|
||||
'document': ev,
|
||||
'algorithm': ALGORITHM,
|
||||
'manufacturer DPP': '',
|
||||
'device': dev.device,
|
||||
'components': dev.components
|
||||
}
|
||||
|
||||
dpps.append(rr)
|
||||
return {
|
||||
'@context': ['https://ereuse.org/dpp0.json'],
|
||||
|
|
|
@ -4,7 +4,7 @@ import logging
|
|||
|
||||
from dmidecode import DMIParse
|
||||
from json_repair import repair_json
|
||||
from evidence.parse_details import get_lshw_child
|
||||
from evidence.parse_details import get_lshw_child, ParseSnapshot
|
||||
|
||||
from evidence.models import Annotation
|
||||
from evidence.xapian import index
|
||||
|
@ -60,6 +60,7 @@ class Build:
|
|||
def generate_chids(self):
|
||||
self.algorithms = {
|
||||
'hidalgo1': self.get_hid_14(),
|
||||
'legacy_dpp': self.get_chid_dpp(),
|
||||
}
|
||||
|
||||
def get_hid_14(self):
|
||||
|
@ -78,6 +79,56 @@ class Build:
|
|||
self.chid = hashlib.sha3_256(hid.encode()).hexdigest()
|
||||
return self.chid
|
||||
|
||||
def get_chid_dpp(self):
|
||||
if self.json.get("software") == "workbench-script":
|
||||
dmidecode_raw = self.json["data"]["dmidecode"]
|
||||
dmi = DMIParse(dmidecode_raw)
|
||||
|
||||
manufacturer = dmi.manufacturer().strip()
|
||||
model = dmi.model().strip()
|
||||
chassis = self.get_chassis_dh()
|
||||
serial_number = dmi.serial_number()
|
||||
sku = self.get_sku()
|
||||
typ = chassis
|
||||
version = self.get_version()
|
||||
hid = f"{manufacturer}{model}{chassis}{serial_number}{sku}{typ}{version}"
|
||||
else:
|
||||
device = self.json['device']
|
||||
hid = self.get_id_hw_dpp(device)
|
||||
|
||||
self.chid = hashlib.sha3_256(hid.encode("utf-8")).hexdigest()
|
||||
return self.chid
|
||||
|
||||
def get_id_hw_dpp(self, d):
|
||||
manufacturer = d.get("manufacturer", '')
|
||||
model = d.get("model", '')
|
||||
chassis = d.get("chassis", '')
|
||||
serial_number = d.get("serialNumber", '')
|
||||
sku = d.get("sku", '')
|
||||
typ = d.get("type", '')
|
||||
version = d.get("version", '')
|
||||
|
||||
return f"{manufacturer}{model}{chassis}{serial_number}{sku}{typ}{version}"
|
||||
|
||||
def get_phid(self):
|
||||
if self.json.get("software") == "workbench-script":
|
||||
data = ParseSnapshot(self.json)
|
||||
self.device = data.device
|
||||
self.components = data.components
|
||||
else:
|
||||
self.device = self.json.get("device")
|
||||
self.components = self.json.get("components" [])
|
||||
|
||||
device = self.get_id_hw_dpp(self.device)
|
||||
components = self.json.get(self.components)
|
||||
components = sorted(components, key=lambda x: x.get("type"))
|
||||
doc = [("computer", device)]
|
||||
|
||||
for c in components:
|
||||
doc.append((c.get("type"), self.get_id_hw_dpp(c)))
|
||||
|
||||
return doc
|
||||
|
||||
def create_annotations(self):
|
||||
annotation = Annotation.objects.filter(
|
||||
uuid=self.uuid,
|
||||
|
@ -114,6 +165,9 @@ class Build:
|
|||
def get_chassis(self):
|
||||
return self.dmi.get("Chassis")[0].get("Type", '_virtual')
|
||||
|
||||
def get_version(self):
|
||||
return self.dmi.get("System")[0].get("Verson", '_virtual')
|
||||
|
||||
def get_hid(self, snapshot):
|
||||
dmidecode_raw = snapshot["data"]["dmidecode"]
|
||||
self.dmi = DMIParse(dmidecode_raw)
|
||||
|
@ -140,5 +194,7 @@ class Build:
|
|||
return hashlib.sha3_256(json.dumps(doc).encode()).hexdigest()
|
||||
|
||||
def register_device_dlt(self):
|
||||
register_device_dlt(self.chid, self.phid, self.uuid, self.user)
|
||||
register_passport_dlt(self.chid, self.phid, self.uuid, self.user)
|
||||
chid = self.algorithms.get('legacy_dpp')
|
||||
phid = self.get_signature(self.get_phid(self))
|
||||
register_device_dlt(chid, phid, self.uuid, self.user)
|
||||
register_passport_dlt(chid, phid, self.uuid, self.user)
|
||||
|
|
|
@ -17,8 +17,19 @@ HID_ALGO1 = [
|
|||
"sku"
|
||||
]
|
||||
|
||||
LEGACY_DPP = [
|
||||
"manufacturer",
|
||||
"model",
|
||||
"chassis",
|
||||
"serialNumber",
|
||||
"sku",
|
||||
"type",
|
||||
"version"
|
||||
]
|
||||
|
||||
ALGOS = {
|
||||
"hidalgo1": HID_ALGO1,
|
||||
"legacy_dpp": LEGACY_DPP
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue