diff --git a/.gitignore b/.gitignore index 99f1c49..de70d08 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,11 @@ +# Project specific files +# +# binaries +*.jpg + + +# Python Files +# # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] @@ -37,11 +45,8 @@ coverage.xml *.mo *.pot -# Django stuff: *.log # Sphinx documentation docs/_build/ -#binaries -*.jpg diff --git a/docs/ps_agile b/docs/ps_agile new file mode 100644 index 0000000..f843db4 --- /dev/null +++ b/docs/ps_agile @@ -0,0 +1,26 @@ +[[[ PicSeal Agile ]]] + + +[[ BACKLOG ]] + +[ current (ver 1.0) ] + + + +[ future ] +* add option "-d" to decrypt file +* add option "-e" to encrypt file +* add option "-ex" to export the key to .PEM file +* add visual stamp to the file so that a picseal photo can be recognized + + + + +[[ COMPLETED ]] + +[ current (ver 1.0) ] +* reads a picseal .jpg file, understands pub/pvt keys from file +* writes new .jpg files with crypto keys +* verbose output of image data chunks +* reads .jpg file, parses data tags + diff --git a/docs/README_DSN b/docs/ps_proj_design similarity index 74% rename from docs/README_DSN rename to docs/ps_proj_design index 8b01621..c5c05f5 100644 --- a/docs/README_DSN +++ b/docs/ps_proj_design @@ -1,3 +1,4 @@ +[[[ PicSeal Design Document ]]] [[ JPG file parse Pseudo Code ]] @@ -10,7 +11,7 @@ 2) Generate Hash a. hash all image data 3) Digital Signature - a. generate new public keys + a. generate new public key pair b. sign hash data with priv key 4) Write new PicSeal Public file a. write encrypted original metadata @@ -23,9 +24,31 @@ c. write image data -[[ PicSeal Metadata ]] -JSON Format +[[ PicSeal Metadata ]] + +[ binary data blob format ] +# Pub: [app15:2|size:2|'picseal':7|type:1|sig:512|pubkey:550] +# Pvt: [app15:2|size:2|'picseal':7|type:1|sig:512|pvtkey:2347] + + # 1. app15 jpg marker + app15_marker = b'\xff\xef' + + # 2. ascii code for "picseal" + picseal_marker = b'\x70\x69\x63\x73\x65\x61\x6C' + + # 3. type + pub_marker = b'\x01' + pvt_marker = b'\x02' + + # 4. signature is the hash of the image, signed by the private key + + # 5. JSON crypto blob data + + + +[ crypto blob format ] +JSON: { "format_ver": "50", "pubkey_alg": "rsa", diff --git a/docs/README_DEV b/docs/ps_proj_dev similarity index 99% rename from docs/README_DEV rename to docs/ps_proj_dev index e8a27d0..edd5a48 100644 --- a/docs/README_DEV +++ b/docs/ps_proj_dev @@ -38,7 +38,7 @@ $ make "In order to prevent conflicts with Apple's own libtool we have prepended a "g" -so, you have instead: glibtool and glibtoolize."" +so, you have instead: glibtool and glibtoolize." diff --git a/libs/jpg_bin_mem.py b/libs/jpg_bin_mem.py new file mode 100644 index 0000000..2c1c046 --- /dev/null +++ b/libs/jpg_bin_mem.py @@ -0,0 +1,79 @@ +# +# I tihnk this is support for the website =) +# instead of reading from a file, read from memory +# goal is to avoid reading/writing to the file system +# +from libs.jpg_bin import JpgBin +from libs.jpg_picseal import JpgPicSeal + + +class JpgBinWriteMem: + + + # + def __init__(self, jpg_in): + self.fhr = jpg_in + self.mem = none + + # + # input is the Crypto Sig class + # + def writeJpgPicSealPub(self, crypto_sig, fp): + self.__writeJpgHeader() + + ps = JpgPicSeal(crypto_sig) + ps.writePub(self.fhw) + + self.__writeJpgImg(fp) + + # + # input is the Crypto Sig class + # + def writeJpgPicSealPvt(self, crypto_sig, fp): + self.__writeJpgHeader() + + ps = JpgPicSeal(crypto_sig) + ps.writePvt(self.fhw) + + self.__writeJpgImg(fp) + + + # + def __writeJpgImg(self, fp): + self.__writeJpgMetadata(fp.markers_meta) + self.__writeJpgImgData(fp.markers_img) + self.__writeJpgFooter() + self.fhw.flush() + self.fhw.close() + + # + # array of the marker information + # + def __writeJpgMetadata(self, markers): + for marker in markers: + self.fhr.seek(marker.fpos) + data = self.fhr.read(marker.len) + self.fhw.write(data) + self.fhw.flush() + + # + # array of the marker information + # + def __writeJpgImgData(self, markers): + for marker in markers: + # most of the image data is sequential + cpos = self.fhr.tell() + if (marker.fpos != cpos): + self.fhr.seek(marker.fpos) + + data = self.fhr.read(marker.len) + self.fhw.write(data) + self.fhw.flush() + + # + def __writeJpgHeader(self): + self.fhw.write(bytes(JpgBin.soi_marker)) + + # + def __writeJpgFooter(self): + self.fhw.write(bytes(JpgBin.eof_marker)) diff --git a/libs/jpg_fp.py b/libs/jpg_fp.py index 2a10c54..019aac8 100644 --- a/libs/jpg_fp.py +++ b/libs/jpg_fp.py @@ -1,5 +1,5 @@ # -# This Class contains information for the jpg markers, length, an position in the file +# This Class contains information for the jpg markers, length, and position in the file # class JpgFingerprint: diff --git a/picseal.py b/picseal.py index c2f75b1..e9e47f7 100644 --- a/picseal.py +++ b/picseal.py @@ -84,10 +84,10 @@ def parseArgs(): if (args.file): processImage(args.file) else: - print('Create PicSeal images') - print(' picseal.py -i ') - print('\n***** ***** ***** *****\n') - parser.print_help() + print('***** ***** ***** *****') + print('ERROR: missing image file') + print(' picseal.py -f ') + print('***** ***** ***** *****')