NEW: writing of PicSeal file COMPLETE. markers verified by Synalize It grammer reading
This commit is contained in:
parent
6bf3a684a1
commit
9e403dc268
|
@ -10,12 +10,11 @@ class Signature:
|
||||||
|
|
||||||
#
|
#
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
key_data = None
|
self.key_data = None
|
||||||
pub_key = None
|
self.pub_key = None
|
||||||
sig_data = None
|
self.sig_data = None
|
||||||
hash_data = None
|
self.hash_data = None
|
||||||
hh = None
|
self.hh = SHA512.new()
|
||||||
self.hh = SHA512.new()
|
|
||||||
self.genKeys()
|
self.genKeys()
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -37,20 +36,43 @@ class Signature:
|
||||||
logging.debug("public key==\n{}".format(self.pub_key.exportKey('PEM')))
|
logging.debug("public key==\n{}".format(self.pub_key.exportKey('PEM')))
|
||||||
logging.debug("private key (and pub, other info)==\n{}".format(self.key_data.exportKey('PEM')))
|
logging.debug("private key (and pub, other info)==\n{}".format(self.key_data.exportKey('PEM')))
|
||||||
|
|
||||||
|
#
|
||||||
|
def importPubKey(self, bin_pubkey):
|
||||||
|
self.pub_key = RSA.importKey(bin_pubkey)
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
def importPvtKey(self, bin_pvtkey):
|
||||||
|
self.key_data = RSA.importKey(bin_pvtkey)
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Private key also includes public key data...SO ANNOYING!
|
# Private key also includes public key data...SO ANNOYING!
|
||||||
#
|
#
|
||||||
def getPrivKeyPEM(self):
|
def getPvtKeyPEM(self):
|
||||||
return self.key_data.exportKey('PEM')
|
return self.key_data.exportKey('PEM')
|
||||||
|
|
||||||
#
|
#
|
||||||
def getPubKeyPEM(self):
|
def getPubKeyPEM(self):
|
||||||
return self.pub_key.exportKey('PEM')
|
return self.pub_key.exportKey('PEM')
|
||||||
|
|
||||||
|
#
|
||||||
|
def getPvtKeyDER(self):
|
||||||
|
return self.key_data.exportKey('DER')
|
||||||
|
|
||||||
|
#
|
||||||
|
def getPubKeyDER(self):
|
||||||
|
return self.pub_key.exportKey('DER')
|
||||||
|
|
||||||
#
|
#
|
||||||
def getSignature(self):
|
def getSignature(self):
|
||||||
return sig_data
|
return sig_data
|
||||||
|
|
||||||
|
#
|
||||||
|
def getNewHashHandle(self):
|
||||||
|
self.hh = SHA512.new()
|
||||||
|
return self.hh
|
||||||
|
|
||||||
#
|
#
|
||||||
def hashBin(self, bin_data):
|
def hashBin(self, bin_data):
|
||||||
hshh = SHA512.new()
|
hshh = SHA512.new()
|
||||||
|
|
|
@ -5,7 +5,8 @@ class JpgBinWrite:
|
||||||
|
|
||||||
soi_marker = b'\xff\xd8'
|
soi_marker = b'\xff\xd8'
|
||||||
eof_marker = b'\xff\xd9'
|
eof_marker = b'\xff\xd9'
|
||||||
picseal_marker = b'\xff\xe0'
|
picseal_marker = b'\xff\xef'
|
||||||
|
# picseal_marker = b'\xff\xe0'
|
||||||
|
|
||||||
#
|
#
|
||||||
def __init__(self, jpg_in, jpg_out):
|
def __init__(self, jpg_in, jpg_out):
|
||||||
|
@ -17,8 +18,8 @@ class JpgBinWrite:
|
||||||
#
|
#
|
||||||
def writeJpgPicSealPub(self, crypto_sig, fp):
|
def writeJpgPicSealPub(self, crypto_sig, fp):
|
||||||
self.__writeJpgHeader()
|
self.__writeJpgHeader()
|
||||||
|
|
||||||
# write picseal serialize data
|
self.__writeJpgPicSeal(crypto_sig, crypto_sig.getPubKeyDER())
|
||||||
|
|
||||||
self.__writeJpgImg(fp)
|
self.__writeJpgImg(fp)
|
||||||
|
|
||||||
|
@ -28,10 +29,26 @@ class JpgBinWrite:
|
||||||
def writeJpgPicSealPvt(self, crypto_sig, fp):
|
def writeJpgPicSealPvt(self, crypto_sig, fp):
|
||||||
self.__writeJpgHeader()
|
self.__writeJpgHeader()
|
||||||
|
|
||||||
# write picseal serialize data
|
self.__writeJpgPicSeal(crypto_sig, crypto_sig.getPvtKeyDER())
|
||||||
|
|
||||||
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 picseal marker
|
||||||
|
self.fhw.write(JpgBinWrite.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):
|
||||||
|
|
|
@ -43,6 +43,7 @@ class JpgProc:
|
||||||
# hash the jpg image data
|
# hash the jpg image data
|
||||||
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
|
||||||
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))
|
||||||
return img_hash
|
return img_hash
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue