# # # import os import argparse import logging from shutil import copyfile #from subprocess import Popen, PIPE, check_call from libs.crypto_pub import Signature from libs.toolbox import Toolbox from libs.jpg_tools import JpgTools fingerprint = False printmeta = False printimage = False def main(): parseArgs() # hash the image binary data only (not metadata) # create new pub keys, sign hash # export signature & public key to a new image file def processImage(image_fn): jpg = JpgTools() jpg_bin = jpg.getJpgBin(image_fn) printImageInfo(jpg_bin) # sig = Signature() # sig.genSig(img_bin) # (pub_fn, priv_fn) = copyImage(image_fn) # writePubImg(pub_fn, sig) # writePrivImg(priv_fn, sig) # add a digital signature to the metadata def writePubImg(pub_fn, sig): pass # img = ImgExif(pub_fn) # img.addKey(sig.getPubKeyPEM()) # img.addSig(sig.sig_data) # img.saveFile() # def writePrivImg(priv_fn, sig): pass # img = ImgExif(priv_fn) # img.addKey(sig.getPrivKeyPEM()) #img.addSig(sig.sig_data) # img.saveFile() # def copyImage(image_fn): basename = os.path.basename(image_fn) (filename, ext) = Toolbox.parseFilenameIncExt(basename) pubFileName = filename + '_' + Toolbox.getTimestampStr() + ext privFileName = filename + '_' + Toolbox.getTimestampStr() + ext copyfile(image_fn, newFileName) return (pubFileName, privFileName) # def printImageInfo(jpg_bin2): if (fingerprint): print( str(jpg_bin2) ) if (printimage): print( jpg_bin2.printMarkerImg()) if (printmeta): print( jpg_bin2.printMarkerMeta()) def parseArgs(): print("***** ***** ***** *****") print(" ** Pic * Seal ** ") print("***** ***** ***** *****\n") parser = argparse.ArgumentParser() parser.add_argument('-i', '--image', required=False, help="source image file") parser.add_argument('-v', '--verbose', action='store_true', help="will set logging level to INFO") parser.add_argument('-vv', '--vverbose', action='store_true', help="will set logging level to DEBUG") parser.add_argument('-l', '--logging', action='store_true', help="will supercede the -v option and send all logging to a file, logging.DEBUG") parser.add_argument('-pm', '--printmeta', action='store_true', help="print the metadata markers") parser.add_argument('-pi', '--printimage', action='store_true', help="print the image markers") parser.add_argument('-fp', '--fingerprint', action='store_true', help="fingerprint") args = parser.parse_args() if (args.logging): logging.basicConfig(filename='dbfp.log', level=logging.DEBUG) if (args.verbose): logging.basicConfig(level=logging.INFO) elif (args.vverbose): logging.basicConfig(level=logging.DEBUG) else: logging.basicConfig(level=logging.CRITICAL) if (args.fingerprint): global fingerprint fingerprint = True if (args.printmeta): global printmeta printmeta = True if (args.printimage): global printimage printimage = True if (args.image): processImage(args.image) else: print('Create PicSeal images') print(' picseal.py -i ') print('\n***** ***** ***** *****\n') parser.print_help() if __name__ == "__main__": main() print