Write certificate and json to disk

visu-type
Jean-Louis Huynen 2019-03-18 11:34:44 +01:00
parent d8a1bfd74f
commit e4bb9b21fa
No known key found for this signature in database
GPG Key ID: 4CDEBABACE9A5DC9
1 changed files with 23 additions and 10 deletions

View File

@ -7,8 +7,7 @@ import json
import redis
import datetime
import hashlib
from cryptography import x509
from cryptography.hazmat.backends import default_backend
import binascii
import pdb
from meta_types_modules.MetaTypesDefault import MetaTypesDefault
@ -25,18 +24,32 @@ class TypeHandler(MetaTypesDefault):
def handle_reconstructed_data(self, data):
self.set_last_time_saved(time.time())
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')
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
mtjson = json.loads(data)
for certificate in mtjson["Certificates"]:
# cert = x509.load_der_x509_certificate(certificate["Raw"].encode(), default_backend())
for certificate in mtjson["Certificates"] or []:
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.update(certificate["Raw"].encode())
pdb.set_trace()
certpath = os.path.join(cert_save_dir, m.hexdigest()+'.crt')
with open(certpath, 'wb') as c:
m.update(cert)
cert_path = os.path.join(cert_save_dir, m.hexdigest()+'.crt')
# write unique certificate der file to disk
with open(cert_path, 'w+b') as c:
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):
print('Class: ja3-jl')
print('Class: ja3-jl')