WIP: working on getting hash signature to work...
This commit is contained in:
parent
1fea208349
commit
f114f0ed61
|
@ -21,6 +21,7 @@ import re
|
||||||
import struct
|
import struct
|
||||||
import logging
|
import logging
|
||||||
from libs.jpg_fp import JpgFingerprint
|
from libs.jpg_fp import JpgFingerprint
|
||||||
|
from libs.jpg_picseal import JpgPicSeal
|
||||||
|
|
||||||
#
|
#
|
||||||
class JpgBin:
|
class JpgBin:
|
||||||
|
@ -29,9 +30,6 @@ class JpgBin:
|
||||||
|
|
||||||
soi_marker = b'\xff\xd8'
|
soi_marker = b'\xff\xd8'
|
||||||
eof_marker = b'\xff\xd9'
|
eof_marker = b'\xff\xd9'
|
||||||
app15_marker = b'\xff\xef'
|
|
||||||
# ascii code for "picseal"
|
|
||||||
picseal_marker = b'\x70\x69\x63\x73\x65\x61\x6C'
|
|
||||||
|
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -149,6 +147,9 @@ class JpgBin:
|
||||||
#
|
#
|
||||||
def markerAppData(self, marker_hex):
|
def markerAppData(self, marker_hex):
|
||||||
self.__addPrevMarkerData(marker_hex, "APP ", False)
|
self.__addPrevMarkerData(marker_hex, "APP ", False)
|
||||||
|
if (0xffef == marker_hex):
|
||||||
|
pass
|
||||||
|
|
||||||
rec_len = self.__calcSeekBytes()
|
rec_len = self.__calcSeekBytes()
|
||||||
logging.info("length=={}".format(str(rec_len)))
|
logging.info("length=={}".format(str(rec_len)))
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
from libs.jpg_bin import JpgBin
|
from libs.jpg_bin import JpgBin
|
||||||
|
from libs.jpg_picseal import JpgPicSeal
|
||||||
|
|
||||||
|
|
||||||
class JpgBinWrite:
|
class JpgBinWrite:
|
||||||
|
@ -18,7 +19,8 @@ class JpgBinWrite:
|
||||||
def writeJpgPicSealPub(self, crypto_sig, fp):
|
def writeJpgPicSealPub(self, crypto_sig, fp):
|
||||||
self.__writeJpgHeader()
|
self.__writeJpgHeader()
|
||||||
|
|
||||||
self.__writeJpgPicSeal(crypto_sig, crypto_sig.getPubKeyDER())
|
ps = JpgPicSeal(crypto_sig)
|
||||||
|
ps.writePub(self.fhw)
|
||||||
|
|
||||||
self.__writeJpgImg(fp)
|
self.__writeJpgImg(fp)
|
||||||
|
|
||||||
|
@ -28,29 +30,12 @@ class JpgBinWrite:
|
||||||
def writeJpgPicSealPvt(self, crypto_sig, fp):
|
def writeJpgPicSealPvt(self, crypto_sig, fp):
|
||||||
self.__writeJpgHeader()
|
self.__writeJpgHeader()
|
||||||
|
|
||||||
self.__writeJpgPicSeal(crypto_sig, crypto_sig.getPvtKeyDER())
|
ps = JpgPicSeal(crypto_sig)
|
||||||
|
ps.writePvt(self.fhw)
|
||||||
|
|
||||||
self.__writeJpgImg(fp)
|
self.__writeJpgImg(fp)
|
||||||
|
|
||||||
|
|
||||||
#
|
|
||||||
def __writeJpgPicSeal(self, crypto_sig, keyder):
|
|
||||||
# must include 2 bytes of length too
|
|
||||||
size = 2
|
|
||||||
size += len(crypto_sig.hash_data)
|
|
||||||
size += len(keyder)
|
|
||||||
|
|
||||||
# write app marker
|
|
||||||
self.fhw.write(JpgBin.app15_marker)
|
|
||||||
# write picseal marker
|
|
||||||
self.fhw.write(JpgBin.picseal_marker)
|
|
||||||
# write the size of picseal record
|
|
||||||
self.fhw.write(size.to_bytes(2, byteorder='big'))
|
|
||||||
# write hash of image
|
|
||||||
self.fhw.write(crypto_sig.hash_data)
|
|
||||||
# write the public key
|
|
||||||
self.fhw.write(keyder)
|
|
||||||
|
|
||||||
#
|
#
|
||||||
def __writeJpgImg(self, fp):
|
def __writeJpgImg(self, fp):
|
||||||
self.__writeJpgMetadata(fp.markers_meta)
|
self.__writeJpgMetadata(fp.markers_meta)
|
||||||
|
|
|
@ -4,19 +4,104 @@
|
||||||
# Data: public key, private key, image hash, image signature
|
# Data: public key, private key, image hash, image signature
|
||||||
# Has: JPG fingerprint
|
# Has: JPG fingerprint
|
||||||
#
|
#
|
||||||
|
# Big-endian
|
||||||
|
# Pub: [picseal:7|type:1|hash:64|pubkey:550]
|
||||||
|
# Pvt: [picseal:7|type:1|hash:64|pvtkey:2347]
|
||||||
#
|
#
|
||||||
|
import struct
|
||||||
|
import logging
|
||||||
|
from Crypto.PublicKey import RSA
|
||||||
|
|
||||||
class JpgPicSeal:
|
class JpgPicSeal:
|
||||||
|
|
||||||
def __init_(self, sig):
|
app15_marker = b'\xff\xef'
|
||||||
self.sig = None
|
# ascii code for "picseal"
|
||||||
|
picseal_marker = b'\x70\x69\x63\x73\x65\x61\x6C'
|
||||||
|
|
||||||
|
|
||||||
|
def __init__(self, sig):
|
||||||
|
self.sig = sig
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# READ
|
||||||
|
#
|
||||||
|
|
||||||
|
#
|
||||||
|
def deserialize(self, fhr):
|
||||||
|
buf = fhr.read(7)
|
||||||
|
ps_marker = struct.unpack('>HHHB', buf)
|
||||||
|
if (JpgPicSeal.picseal_marker == ps_marker):
|
||||||
|
logging.info("*** *** matched picseal marker *** ***")
|
||||||
|
buf = fhr.read(1)
|
||||||
|
pubpvt = struct.unpack('>B', buf)
|
||||||
|
buf = fhr.read(64)
|
||||||
|
|
||||||
|
if (pubpvt == b'\x01'):
|
||||||
|
#pub
|
||||||
|
buf = fhr.read(550)
|
||||||
|
self.sig.importPubKey(buf)
|
||||||
|
else:
|
||||||
|
#pvt
|
||||||
|
buf = fhr.read(2347)
|
||||||
|
self.sig.importPvtKey(buf)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def readPub(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def readPvt(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# WRITE
|
||||||
|
#
|
||||||
|
|
||||||
#
|
#
|
||||||
def serilize(self, fname):
|
def serilize(self, fname):
|
||||||
pass
|
pass
|
||||||
|
#
|
||||||
|
# input is the Crypto Sig class
|
||||||
|
#
|
||||||
|
def writePub(self, fhw):
|
||||||
|
self.__writeData(fhw, self.sig.sig_data, self.sig.getPubKeyDER(), b'\x01')
|
||||||
|
|
||||||
|
#
|
||||||
|
# input is the Crypto Sig class
|
||||||
|
#
|
||||||
|
def writePvt(self, fhw):
|
||||||
|
self.__writeData(fhw, self.sig.sig_data, self.sig.getPvtKeyDER(), b'\x02')
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
def deserialize(self, fname):
|
def __writeData(self, fhw, sig_data, keyder, pubpvt):
|
||||||
pass
|
# must include 2 bytes of length too
|
||||||
|
size = 2
|
||||||
|
size += len(JpgPicSeal.picseal_marker)
|
||||||
|
size += len(sig_data)
|
||||||
|
size += len(keyder)
|
||||||
|
|
||||||
|
logging.debug("picseal marker length: {}".format(str(len(JpgPicSeal.picseal_marker))))
|
||||||
|
logging.debug("hash size: {}".format(str(len(sig_data))))
|
||||||
|
logging.debug("key size: {}".format(str(len(keyder))))
|
||||||
|
|
||||||
|
#
|
||||||
|
# write header
|
||||||
|
# write app marker
|
||||||
|
fhw.write(JpgPicSeal.app15_marker)
|
||||||
|
# write the size of picseal record
|
||||||
|
fhw.write(size.to_bytes(2, byteorder='big'))
|
||||||
|
|
||||||
|
#
|
||||||
|
# write picseal data
|
||||||
|
# write picseal marker
|
||||||
|
fhw.write(JpgPicSeal.picseal_marker)
|
||||||
|
fhw.write(pubpvt)
|
||||||
|
# write hash of image
|
||||||
|
fhw.write(sig_data)
|
||||||
|
# write the public key data
|
||||||
|
fhw.write(keyder)
|
||||||
|
|
||||||
|
|
|
@ -45,6 +45,7 @@ class JpgProc:
|
||||||
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))
|
logging.info("img_hash-size=={}, img_hash=={}".format(len(img_hash), img_hash))
|
||||||
|
self.sig.genSig(img_hash)
|
||||||
return img_hash
|
return img_hash
|
||||||
|
|
||||||
#
|
#
|
||||||
|
|
11
picseal.py
11
picseal.py
|
@ -3,8 +3,6 @@
|
||||||
#
|
#
|
||||||
import argparse
|
import argparse
|
||||||
import logging
|
import logging
|
||||||
from shutil import copyfile
|
|
||||||
from libs.toolbox import Toolbox
|
|
||||||
from libs.jpg_proc import JpgProc
|
from libs.jpg_proc import JpgProc
|
||||||
|
|
||||||
printall = False
|
printall = False
|
||||||
|
@ -12,10 +10,6 @@ printmeta = False
|
||||||
printimage = False
|
printimage = False
|
||||||
write_picseal = False
|
write_picseal = False
|
||||||
|
|
||||||
def main():
|
|
||||||
parseArgs()
|
|
||||||
|
|
||||||
|
|
||||||
# hash the image binary data only (not metadata)
|
# hash the image binary data only (not metadata)
|
||||||
# create new pub keys, sign hash
|
# create new pub keys, sign hash
|
||||||
# export signature & public key to a new image file
|
# export signature & public key to a new image file
|
||||||
|
@ -41,7 +35,12 @@ def printImageInfo(jpg_bin):
|
||||||
print( jpg_bin.printMarkerMeta())
|
print( jpg_bin.printMarkerMeta())
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
parseArgs()
|
||||||
|
|
||||||
def parseArgs():
|
def parseArgs():
|
||||||
|
print
|
||||||
print("***** ***** ***** *****")
|
print("***** ***** ***** *****")
|
||||||
print(" ** Pic * Seal ** ")
|
print(" ** Pic * Seal ** ")
|
||||||
print("***** ***** ***** *****\n")
|
print("***** ***** ***** *****\n")
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
# Test Signature Class
|
# Test Signature Class
|
||||||
#
|
#
|
||||||
# run from root of project
|
# run from root of project
|
||||||
from libs.crypto_pub import Signature
|
from libs.crypto_sig import Signature
|
||||||
|
|
||||||
msg = b'Hieee, this is a test =)'
|
msg = b'Hieee, this is a test =)'
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue