WIP: reading of picseal jpg file...
This commit is contained in:
parent
f114f0ed61
commit
5fe92beedb
|
@ -18,10 +18,9 @@ class Signature:
|
||||||
self.genKeys()
|
self.genKeys()
|
||||||
|
|
||||||
#
|
#
|
||||||
def genSig(self, hshh):
|
def genSig(self):
|
||||||
signer = PKCS1_v1_5.new(self.key_data)
|
signer = PKCS1_v1_5.new(self.key_data)
|
||||||
self.sig_data = signer.sign(hshh)
|
self.sig_data = signer.sign(self.hh)
|
||||||
return self.sig_data
|
|
||||||
|
|
||||||
#
|
#
|
||||||
def verifySig(self, hshh, bin_sig):
|
def verifySig(self, hshh, bin_sig):
|
||||||
|
@ -87,14 +86,20 @@ class Signature:
|
||||||
|
|
||||||
#
|
#
|
||||||
def _test():
|
def _test():
|
||||||
|
#logging.basicConfig(level=logging.DEBUG)
|
||||||
|
|
||||||
msg = b'Hieee, this is a test =)'
|
msg = b'Hieee, this is a test =)'
|
||||||
|
|
||||||
sig = Signature()
|
sig = Signature()
|
||||||
sig_data = sig.genSig(msg)
|
sig.hh.update(msg)
|
||||||
print("Signature created")
|
sig.hash_data = sig.hh.digest()
|
||||||
print("sig_data=={}".format(sig_data))
|
sig.genSig()
|
||||||
|
print("Hash created:\n{}".format(sig.hash_data))
|
||||||
|
print("Size=={}".format(str(len(sig.hash_data))))
|
||||||
|
print("Signature created:\n{}".format(sig.sig_data))
|
||||||
|
print("Size=={}".format(str(len(sig.sig_data))))
|
||||||
|
|
||||||
isVerified = sig.verifySig(msg, sig_data)
|
isVerified = sig.verifySig(sig.hh, sig.sig_data)
|
||||||
print("isVerified=={}".format(str(isVerified)))
|
print("isVerified=={}".format(str(isVerified)))
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,8 @@ class JpgBin:
|
||||||
self.prev_mstr = "DUH!"
|
self.prev_mstr = "DUH!"
|
||||||
self.prev_imgData = False
|
self.prev_imgData = False
|
||||||
|
|
||||||
self.jpg_fp = JpgFingerprint()
|
self.jpg_fp = JpgFingerprint()
|
||||||
|
self.picseal = None
|
||||||
|
|
||||||
#
|
#
|
||||||
# check for JPG file type marker
|
# check for JPG file type marker
|
||||||
|
@ -146,17 +147,20 @@ class JpgBin:
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
def markerAppData(self, marker_hex):
|
def markerAppData(self, marker_hex):
|
||||||
|
seek = True
|
||||||
self.__addPrevMarkerData(marker_hex, "APP ", False)
|
self.__addPrevMarkerData(marker_hex, "APP ", False)
|
||||||
if (0xffef == marker_hex):
|
if (0xffef == marker_hex):
|
||||||
pass
|
if (self.__processPicSeal()):
|
||||||
|
seek = False
|
||||||
rec_len = self.__calcSeekBytes()
|
|
||||||
logging.info("length=={}".format(str(rec_len)))
|
if (seek):
|
||||||
|
(rec_len,) = self.__calcSeekBytes()
|
||||||
|
logging.info("length=={}".format(str(rec_len)))
|
||||||
|
|
||||||
#
|
#
|
||||||
def markerComment(self, marker_hex):
|
def markerComment(self, marker_hex):
|
||||||
self.__addPrevMarkerData(marker_hex, "COM ", False)
|
self.__addPrevMarkerData(marker_hex, "COM ", False)
|
||||||
rec_len = self.__calcSeekBytes()
|
self.__calcSeekBytes()
|
||||||
|
|
||||||
#
|
#
|
||||||
# Image Data
|
# Image Data
|
||||||
|
@ -175,7 +179,7 @@ class JpgBin:
|
||||||
#
|
#
|
||||||
def markerDQT(self, marker_hex):
|
def markerDQT(self, marker_hex):
|
||||||
self.__addPrevMarkerData(marker_hex, "DQT ")
|
self.__addPrevMarkerData(marker_hex, "DQT ")
|
||||||
rec_len = self.__calcSeekBytes()
|
self.__calcSeekBytes()
|
||||||
|
|
||||||
#
|
#
|
||||||
def markerDRI(self, marker_hex):
|
def markerDRI(self, marker_hex):
|
||||||
|
@ -185,16 +189,16 @@ class JpgBin:
|
||||||
#
|
#
|
||||||
def markerSOF0(self, marker_hex):
|
def markerSOF0(self, marker_hex):
|
||||||
self.__addPrevMarkerData(marker_hex, "SOF0")
|
self.__addPrevMarkerData(marker_hex, "SOF0")
|
||||||
rec_len = self.__calcSeekBytes()
|
self.__calcSeekBytes()
|
||||||
|
|
||||||
#
|
#
|
||||||
def markerSOF2(self, marker_hex):
|
def markerSOF2(self, marker_hex):
|
||||||
self.__addPrevMarkerData(marker_hex, "SOF2")
|
self.__addPrevMarkerData(marker_hex, "SOF2")
|
||||||
rec_len = self.__calcSeekBytes()
|
self.__calcSeekBytes()
|
||||||
|
|
||||||
def markerDHT(self, marker_hex):
|
def markerDHT(self, marker_hex):
|
||||||
self.__addPrevMarkerData(marker_hex, "DHT ")
|
self.__addPrevMarkerData(marker_hex, "DHT ")
|
||||||
rec_len = self.__calcSeekBytes()
|
self.__calcSeekBytes()
|
||||||
|
|
||||||
#
|
#
|
||||||
# end of file marker is never added to the marker array list (same as start of image marker)
|
# end of file marker is never added to the marker array list (same as start of image marker)
|
||||||
|
@ -235,15 +239,17 @@ class JpgBin:
|
||||||
# move the index 2 bytes, then read the 2 bytes to get the length
|
# move the index 2 bytes, then read the 2 bytes to get the length
|
||||||
#
|
#
|
||||||
def __calcSeekBytes(self):
|
def __calcSeekBytes(self):
|
||||||
|
prev_buf = None
|
||||||
self.data_idx += 2
|
self.data_idx += 2
|
||||||
(rec_len,) = struct.unpack('>H', self.data_buf[self.data_idx:self.data_idx+2])
|
(rec_len,) = struct.unpack('>H', self.data_buf[self.data_idx:self.data_idx+2])
|
||||||
remain_bytes = self.data_len - self.data_idx
|
remain_bytes = self.data_len - self.data_idx
|
||||||
if (rec_len >= remain_bytes):
|
if (rec_len >= remain_bytes):
|
||||||
|
prev_buf = self.data_buf[self.data_idx:]
|
||||||
rec_diff = rec_len - remain_bytes
|
rec_diff = rec_len - remain_bytes
|
||||||
self.__seekBytes(rec_diff)
|
self.__seekBytes(rec_diff)
|
||||||
else:
|
else:
|
||||||
self.data_idx += rec_len
|
self.data_idx += rec_len
|
||||||
return rec_len
|
return rec_len, prev_buf
|
||||||
|
|
||||||
#
|
#
|
||||||
def __seekBytes(self, num_bytes):
|
def __seekBytes(self, num_bytes):
|
||||||
|
@ -252,6 +258,31 @@ class JpgBin:
|
||||||
logging.debug("SEEK: seek=={}, cur_loc=={}".format(num_bytes, pos))
|
logging.debug("SEEK: seek=={}, cur_loc=={}".format(num_bytes, pos))
|
||||||
return pos
|
return pos
|
||||||
|
|
||||||
|
#
|
||||||
|
def __getBuf(self, buf_size):
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# [app_rec_header:2|len:2|picseal_header:7]
|
||||||
|
#
|
||||||
|
def __processPicSeal(self):
|
||||||
|
self.picseal = JpgPicSeal()
|
||||||
|
rec_hdr = 4
|
||||||
|
ps_hdr_size = rec_hdr+len(JpgPicSeal.picseal_marker)
|
||||||
|
remain_buf = self.data_len-(self.data_idx+ps_hdr_size)
|
||||||
|
if (remain_buf > ps_hdr_size):
|
||||||
|
if (self.picseal.isPicSeal(self.data_buf[self.data_idx+rec_hdr:self.data_idx+ps_hdr_size])):
|
||||||
|
#
|
||||||
|
# calculate size, check buffer, maybe read more bytes from file
|
||||||
|
#
|
||||||
|
|
||||||
|
print("*** *** GOT HERE MOFO *** ***")
|
||||||
|
self.picseal.deserialize(buf)
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
def printMarkerImg(self):
|
def printMarkerImg(self):
|
||||||
return self.jpg_fp.printImgMarkers()
|
return self.jpg_fp.printImgMarkers()
|
||||||
|
|
|
@ -5,8 +5,8 @@
|
||||||
# Has: JPG fingerprint
|
# Has: JPG fingerprint
|
||||||
#
|
#
|
||||||
# Big-endian
|
# Big-endian
|
||||||
# Pub: [picseal:7|type:1|hash:64|pubkey:550]
|
# Pub: [picseal:7|type:1|sig:512|pubkey:550]
|
||||||
# Pvt: [picseal:7|type:1|hash:64|pvtkey:2347]
|
# Pvt: [picseal:7|type:1|sig:512|pvtkey:2347]
|
||||||
#
|
#
|
||||||
import struct
|
import struct
|
||||||
import logging
|
import logging
|
||||||
|
@ -19,24 +19,26 @@ class JpgPicSeal:
|
||||||
picseal_marker = b'\x70\x69\x63\x73\x65\x61\x6C'
|
picseal_marker = b'\x70\x69\x63\x73\x65\x61\x6C'
|
||||||
|
|
||||||
|
|
||||||
def __init__(self, sig):
|
def __init__(self, sig=None):
|
||||||
self.sig = sig
|
self.sig = sig
|
||||||
|
self.sig_data = None
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# READ
|
# READ
|
||||||
#
|
#
|
||||||
|
|
||||||
|
def isPicSeal(self, buf):
|
||||||
|
if (buf == JpgPicSeal.picseal_marker):
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
#
|
#
|
||||||
def deserialize(self, fhr):
|
def deserialize(self, fhr):
|
||||||
buf = fhr.read(7)
|
# read type 0x01 is public key, 0x02 private key
|
||||||
ps_marker = struct.unpack('>HHHB', buf)
|
|
||||||
if (JpgPicSeal.picseal_marker == ps_marker):
|
|
||||||
logging.info("*** *** matched picseal marker *** ***")
|
|
||||||
buf = fhr.read(1)
|
buf = fhr.read(1)
|
||||||
pubpvt = struct.unpack('>B', buf)
|
pubpvt = struct.unpack('>B', buf)
|
||||||
buf = fhr.read(64)
|
self.sig_data = fhr.read(512)
|
||||||
|
|
||||||
if (pubpvt == b'\x01'):
|
if (pubpvt == b'\x01'):
|
||||||
#pub
|
#pub
|
||||||
buf = fhr.read(550)
|
buf = fhr.read(550)
|
||||||
|
|
|
@ -44,9 +44,8 @@ class JpgProc:
|
||||||
self.sig = Signature()
|
self.sig = Signature()
|
||||||
img_hash = self.jpg.genHash(self.sig.hh)
|
img_hash = self.jpg.genHash(self.sig.hh)
|
||||||
self.sig.hash_data = img_hash
|
self.sig.hash_data = img_hash
|
||||||
logging.info("img_hash-size=={}, img_hash=={}".format(len(img_hash), img_hash))
|
self.sig.genSig()
|
||||||
self.sig.genSig(img_hash)
|
#logging.info("img_hash-size=={}, img_hash=={}".format(len(img_hash), img_hash))
|
||||||
return img_hash
|
|
||||||
|
|
||||||
#
|
#
|
||||||
def writePicSealJpg(self, fname=None):
|
def writePicSealJpg(self, fname=None):
|
||||||
|
|
|
@ -16,8 +16,8 @@ write_picseal = False
|
||||||
def processImage(image_fn):
|
def processImage(image_fn):
|
||||||
jpg_proc = JpgProc()
|
jpg_proc = JpgProc()
|
||||||
jpg_proc.process(image_fn)
|
jpg_proc.process(image_fn)
|
||||||
jpg_proc.hash()
|
|
||||||
if (write_picseal):
|
if (write_picseal):
|
||||||
|
jpg_proc.hash()
|
||||||
print("Writing PicSeal JPG files...")
|
print("Writing PicSeal JPG files...")
|
||||||
jpg_proc.writePicSealJpg()
|
jpg_proc.writePicSealJpg()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue