mirror of https://github.com/D4-project/d4-core
Write certificate and json to disk
parent
d8a1bfd74f
commit
e4bb9b21fa
|
@ -7,8 +7,7 @@ import json
|
||||||
import redis
|
import redis
|
||||||
import datetime
|
import datetime
|
||||||
import hashlib
|
import hashlib
|
||||||
from cryptography import x509
|
import binascii
|
||||||
from cryptography.hazmat.backends import default_backend
|
|
||||||
import pdb
|
import pdb
|
||||||
|
|
||||||
from meta_types_modules.MetaTypesDefault import MetaTypesDefault
|
from meta_types_modules.MetaTypesDefault import MetaTypesDefault
|
||||||
|
@ -25,18 +24,32 @@ class TypeHandler(MetaTypesDefault):
|
||||||
def handle_reconstructed_data(self, data):
|
def handle_reconstructed_data(self, data):
|
||||||
self.set_last_time_saved(time.time())
|
self.set_last_time_saved(time.time())
|
||||||
self.set_last_saved_date(datetime.datetime.now().strftime("%Y%m%d%H%M%S"))
|
self.set_last_saved_date(datetime.datetime.now().strftime("%Y%m%d%H%M%S"))
|
||||||
# update save path
|
|
||||||
|
# Create folders
|
||||||
cert_save_dir = os.path.join(self.get_save_dir(), 'certs')
|
cert_save_dir = os.path.join(self.get_save_dir(), 'certs')
|
||||||
|
jsons_save_dir = os.path.join(self.get_save_dir(), 'jsons')
|
||||||
|
if not os.path.exists(cert_save_dir):
|
||||||
|
os.makedirs(cert_save_dir)
|
||||||
|
if not os.path.exists(jsons_save_dir):
|
||||||
|
os.makedirs(jsons_save_dir)
|
||||||
|
|
||||||
# Extract certificates from json
|
# Extract certificates from json
|
||||||
mtjson = json.loads(data)
|
mtjson = json.loads(data)
|
||||||
for certificate in mtjson["Certificates"]:
|
for certificate in mtjson["Certificates"] or []:
|
||||||
# cert = x509.load_der_x509_certificate(certificate["Raw"].encode(), default_backend())
|
cert = binascii.a2b_base64(certificate["Raw"])
|
||||||
|
# one could also load this cert with
|
||||||
|
# xcert = x509.load_der_x509_certificate(cert, default_backend())
|
||||||
m = hashlib.sha256()
|
m = hashlib.sha256()
|
||||||
m.update(certificate["Raw"].encode())
|
m.update(cert)
|
||||||
pdb.set_trace()
|
cert_path = os.path.join(cert_save_dir, m.hexdigest()+'.crt')
|
||||||
certpath = os.path.join(cert_save_dir, m.hexdigest()+'.crt')
|
# write unique certificate der file to disk
|
||||||
with open(certpath, 'wb') as c:
|
with open(cert_path, 'w+b') as c:
|
||||||
c.write(cert)
|
c.write(cert)
|
||||||
|
|
||||||
|
# write json file to disk
|
||||||
|
jsons_path = os.path.join(jsons_save_dir, mtjson["Timestamp"]+'.json')
|
||||||
|
with open(jsons_path, 'w') as j:
|
||||||
|
j.write(data.decode())
|
||||||
|
|
||||||
def test(self):
|
def test(self):
|
||||||
print('Class: ja3-jl')
|
print('Class: ja3-jl')
|
Loading…
Reference in New Issue