new document and out device and components
This commit is contained in:
parent
7ed05f0932
commit
96268c8caf
16
did/views.py
16
did/views.py
|
@ -4,6 +4,7 @@ import logging
|
||||||
from django.http import JsonResponse, Http404
|
from django.http import JsonResponse, Http404
|
||||||
from django.views.generic.base import TemplateView
|
from django.views.generic.base import TemplateView
|
||||||
from device.models import Device
|
from device.models import Device
|
||||||
|
from evidence.parse import Build
|
||||||
from dpp.api_dlt import ALGORITHM
|
from dpp.api_dlt import ALGORITHM
|
||||||
from dpp.models import Proof
|
from dpp.models import Proof
|
||||||
from dpp.api_dlt import PROOF_TYPE
|
from dpp.api_dlt import PROOF_TYPE
|
||||||
|
@ -93,6 +94,8 @@ class PublicDeviceWebView(TemplateView):
|
||||||
'algorithm': ALGORITHM,
|
'algorithm': ALGORITHM,
|
||||||
'components': components,
|
'components': components,
|
||||||
'manufacturer DPP': '',
|
'manufacturer DPP': '',
|
||||||
|
'device': {},
|
||||||
|
'components': [],
|
||||||
}
|
}
|
||||||
result = {
|
result = {
|
||||||
'@context': ['https://ereuse.org/dpp0.json'],
|
'@context': ['https://ereuse.org/dpp0.json'],
|
||||||
|
@ -100,7 +103,11 @@ class PublicDeviceWebView(TemplateView):
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(self.pk.split(":")) > 1:
|
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()
|
self.object.get_evidences()
|
||||||
last_dpp = Proof.objects.filter(
|
last_dpp = Proof.objects.filter(
|
||||||
|
@ -122,13 +129,18 @@ class PublicDeviceWebView(TemplateView):
|
||||||
self.object.initial()
|
self.object.initial()
|
||||||
for d in self.object.evidences:
|
for d in self.object.evidences:
|
||||||
d.get_doc()
|
d.get_doc()
|
||||||
ev = json.dumps(d.doc)
|
dev = Build(d.doc, None, check=True)
|
||||||
|
doc = dev.get_phid()
|
||||||
|
ev = json.dumps(doc)
|
||||||
rr = {
|
rr = {
|
||||||
'dpp': d.key,
|
'dpp': d.key,
|
||||||
'document': ev,
|
'document': ev,
|
||||||
'algorithm': ALGORITHM,
|
'algorithm': ALGORITHM,
|
||||||
'manufacturer DPP': '',
|
'manufacturer DPP': '',
|
||||||
|
'device': dev.device,
|
||||||
|
'components': dev.components
|
||||||
}
|
}
|
||||||
|
|
||||||
dpps.append(rr)
|
dpps.append(rr)
|
||||||
return {
|
return {
|
||||||
'@context': ['https://ereuse.org/dpp0.json'],
|
'@context': ['https://ereuse.org/dpp0.json'],
|
||||||
|
|
|
@ -2,6 +2,9 @@ import json
|
||||||
import hashlib
|
import hashlib
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
from dmidecode import DMIParse
|
||||||
|
from evidence.parse_details import ParseSnapshot
|
||||||
|
|
||||||
from evidence.models import Annotation
|
from evidence.models import Annotation
|
||||||
from evidence.xapian import index
|
from evidence.xapian import index
|
||||||
from dpp.api_dlt import register_device_dlt, register_passport_dlt
|
from dpp.api_dlt import register_device_dlt, register_passport_dlt
|
||||||
|
@ -55,6 +58,7 @@ class Build:
|
||||||
def generate_chids(self):
|
def generate_chids(self):
|
||||||
self.algorithms = {
|
self.algorithms = {
|
||||||
'hidalgo1': self.get_hid_14(),
|
'hidalgo1': self.get_hid_14(),
|
||||||
|
'legacy_dpp': self.get_chid_dpp(),
|
||||||
}
|
}
|
||||||
|
|
||||||
def get_hid_14(self):
|
def get_hid_14(self):
|
||||||
|
@ -73,6 +77,56 @@ class Build:
|
||||||
self.chid = hashlib.sha3_256(hid.encode()).hexdigest()
|
self.chid = hashlib.sha3_256(hid.encode()).hexdigest()
|
||||||
return self.chid
|
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):
|
def create_annotations(self):
|
||||||
annotation = Annotation.objects.filter(
|
annotation = Annotation.objects.filter(
|
||||||
uuid=self.uuid,
|
uuid=self.uuid,
|
||||||
|
@ -95,6 +149,26 @@ class Build:
|
||||||
value=v
|
value=v
|
||||||
)
|
)
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
|
=======
|
||||||
|
def get_chassis_dh(self):
|
||||||
|
chassis = self.get_chassis()
|
||||||
|
lower_type = chassis.lower()
|
||||||
|
for k, v in CHASSIS_DH.items():
|
||||||
|
if lower_type in v:
|
||||||
|
return k
|
||||||
|
return self.default
|
||||||
|
|
||||||
|
def get_sku(self):
|
||||||
|
return self.dmi.get("System")[0].get("SKU Number", "n/a").strip()
|
||||||
|
|
||||||
|
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')
|
||||||
|
|
||||||
|
>>>>>>> 5949049 (new document and out device and components)
|
||||||
def get_hid(self, snapshot):
|
def get_hid(self, snapshot):
|
||||||
try:
|
try:
|
||||||
self.inxi = self.json["data"]["inxi"]
|
self.inxi = self.json["data"]["inxi"]
|
||||||
|
@ -127,5 +201,7 @@ class Build:
|
||||||
return hashlib.sha3_256(json.dumps(doc).encode()).hexdigest()
|
return hashlib.sha3_256(json.dumps(doc).encode()).hexdigest()
|
||||||
|
|
||||||
def register_device_dlt(self):
|
def register_device_dlt(self):
|
||||||
register_device_dlt(self.chid, self.phid, self.uuid, self.user)
|
chid = self.algorithms.get('legacy_dpp')
|
||||||
register_passport_dlt(self.chid, self.phid, self.uuid, self.user)
|
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"
|
"sku"
|
||||||
]
|
]
|
||||||
|
|
||||||
|
LEGACY_DPP = [
|
||||||
|
"manufacturer",
|
||||||
|
"model",
|
||||||
|
"chassis",
|
||||||
|
"serialNumber",
|
||||||
|
"sku",
|
||||||
|
"type",
|
||||||
|
"version"
|
||||||
|
]
|
||||||
|
|
||||||
ALGOS = {
|
ALGOS = {
|
||||||
"hidalgo1": HID_ALGO1,
|
"hidalgo1": HID_ALGO1,
|
||||||
|
"legacy_dpp": LEGACY_DPP
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue