2024-07-11 15:40:45 +00:00
|
|
|
import os
|
|
|
|
import json
|
|
|
|
import shutil
|
|
|
|
import hashlib
|
2024-07-01 10:17:23 +00:00
|
|
|
|
2024-07-11 15:40:45 +00:00
|
|
|
from datetime import datetime
|
2024-10-04 15:32:53 +00:00
|
|
|
from evidence.xapian import index
|
2024-07-26 15:59:34 +00:00
|
|
|
from evidence.models import Evidence, Annotation
|
2024-07-18 15:21:22 +00:00
|
|
|
from utils.constants import ALGOS
|
2024-07-11 15:40:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Build:
|
2024-07-31 11:28:46 +00:00
|
|
|
def __init__(self, evidence_json, user, check=False):
|
2024-07-26 15:59:34 +00:00
|
|
|
self.json = evidence_json
|
2024-07-18 15:21:22 +00:00
|
|
|
self.uuid = self.json['uuid']
|
2024-07-11 15:40:45 +00:00
|
|
|
self.user = user
|
|
|
|
self.hid = None
|
2024-07-31 11:28:46 +00:00
|
|
|
self.generate_chids()
|
|
|
|
|
|
|
|
if check:
|
|
|
|
return
|
2024-07-11 15:40:45 +00:00
|
|
|
|
2024-07-15 14:23:14 +00:00
|
|
|
self.index()
|
2024-07-18 15:21:22 +00:00
|
|
|
self.create_annotations()
|
2024-07-11 15:40:45 +00:00
|
|
|
|
2024-07-15 14:23:14 +00:00
|
|
|
def index(self):
|
|
|
|
snap = json.dumps(self.json)
|
2024-10-04 15:32:53 +00:00
|
|
|
index(self.user.institution, self.uuid, snap)
|
2024-07-15 14:23:14 +00:00
|
|
|
|
2024-07-31 11:28:46 +00:00
|
|
|
def generate_chids(self):
|
|
|
|
self.algorithms = {
|
|
|
|
'hidalgo1': self.get_hid_14(),
|
|
|
|
}
|
|
|
|
|
2024-07-15 14:23:14 +00:00
|
|
|
def get_hid_14(self):
|
|
|
|
device = self.json['device']
|
|
|
|
manufacturer = device.get("manufacturer", '')
|
|
|
|
model = device.get("model", '')
|
|
|
|
chassis = device.get("chassis", '')
|
|
|
|
serial_number = device.get("serialNumber", '')
|
|
|
|
sku = device.get("sku", '')
|
|
|
|
hid = f"{manufacturer}{model}{chassis}{serial_number}{sku}"
|
|
|
|
return hashlib.sha3_256(hid.encode()).hexdigest()
|
|
|
|
|
2024-07-18 15:21:22 +00:00
|
|
|
def create_annotations(self):
|
|
|
|
|
2024-07-31 11:28:46 +00:00
|
|
|
for k, v in self.algorithms.items():
|
2024-07-18 15:21:22 +00:00
|
|
|
Annotation.objects.create(
|
|
|
|
uuid=self.uuid,
|
2024-10-04 15:32:53 +00:00
|
|
|
owner=self.user.institution,
|
|
|
|
user=self.user,
|
2024-07-18 15:21:22 +00:00
|
|
|
type=Annotation.Type.SYSTEM,
|
|
|
|
key=k,
|
|
|
|
value=v
|
|
|
|
)
|