[[[ Picseal ]]]

"crypto key sharing using your photos"
"exif data providing photo integrity, ownership, and crypto key"


[[ Formats]]
@ http://stackoverflow.com/questions/12749858/rsa-public-key-format
@ http://security.stackexchange.com/questions/57043/most-popular-rsa-key-format

DER: binary encoded format, sometimes Asn.1 BER-encoded
PEM: base64 format of the same DER-encoded file with header&footer lines
XML: xml format

-----BEGIN RSA PUBLIC KEY-----
-----END RSA PUBLIC KEY-----

---- BEGIN SSH2 PUBLIC KEY ----
---- END SSH2 PUBLIC KEY ----



[[ WolfSSL ]]

[ Compile Mac ]
@ https://www.wolfssl.com/wolfSSL/Docs-wolfssl-manual-toc.html
@ https://www.wolfssl.com/wolfSSL/Docs-wolfssl-manual-2-building-wolfssl.html
@ https://wolfssl.github.io/wolfcrypt-py/

$ brew install  autoconf  automake  libtool
$ glibtoolize
$ git clone https://github.com/wolfssl/wolfssl.git
$ cd wolfssl/
$ ./autogen.sh
$ ./configure --help
$ ./configure --enable-sha512
$ make


"In order to prevent conflicts with Apple's own libtool we have prepended a "g"
so, you have instead: glibtool and glibtoolize.""



[[ gexiv2 ]]
# gobject wrapper of the libexiv2 library (which is the engine for exiv2)
@ https://wiki.gnome.org/Projects/gexiv2
@ http://wiki.gnome.org/GObjectIntrospection
@ http://wiki.gnome.org/PyGObject/IntrospectionPorting

# API docs
@ http://lazka.github.io/pgi-docs/#GExiv2-0.10

[ XMP ]
# adding new XMP namespaces
@ http://dev.exiv2.org/boards/3/topics/1039


[ install ubuntu ]
$ sudo apt-get install libexiv2-dev  libgexiv2-dev  gir1.2-gexiv2-0.10

[ install mac ]
# install globally (python2)
$ brew install  exiv2  gexiv2  pygobject3

# install for python3
$ brew reinstall pygobject3 --with-python3


[ build ]
$ git clone git://git.gnome.org/gexiv2
$ sudo apt-get install gobject-introspection
$ sudo apt-get install glib  libgirepository1.0-dev
$ sudo apt-get install libglib2.0-dev  libexiv2-dev  python-gobject-dev
$ 
$ ./autogen.sh
$ ./configure --enable-introspection



[[ EXIF ]]

[ exiv2 ]
# BUILD
http://dev.exiv2.org/projects/exiv2/wiki/How_do_I_build_Exiv2_on_the_XYZ_platform

[ pyexiv2 ]
@ http://tilloy.net/dev/pyexiv2/


[ exiftool]
# perl program
@ http://www.sno.phy.queensu.ca/~phil/exiftool/

$ brew install exiftool


[[ exiftool]]
# perl program
# http://www.sno.phy.queensu.ca/~phil/exiftool/

$ brew install exiftool




[[ Competitors ]]

[ authentication ]
https://getclef.com/



[[ Debug ]]

$ exiv2 -ps image.jpg


[[ Crypto ]]

[ Public Key ]

# encrypt
@ https://pythonhosted.org/pycrypto/Crypto.Cipher.PKCS1_v1_5.PKCS115_Cipher-class.html#encrypt


[ OpenSSL ]

openssl genrsa -out ~/myTestKey.pem -passout pass:"f00bar" -des3 2048
openssl rsa -pubout -in ~/myTestKey.pem -passin pass:"f00bar" -out ~/myTestKey.pub


[ Cryptography.io ]
Fernet (Public Key)
@ https://cryptography.io/en/latest/fernet/



[[ MVP Plan ]]

[ C ]
libexiv --> exif read/write
libwolfss --> crypto generation

[ Functions ]
# load image file
picseal.init(image_file)

# create pub/priv key pair
# add new public key to exif
# store priv key in memory
picseal.add_new_key(CIPHER_TYPE)

# hash the image, encrypt hash with priv-key
# hash the image & specific exif tags, encrypt hash with priv-key
# add signatures to exif
picseal.seal_image(HASH_TYPE)

# write the image with public key, and signature
picseal.write_pub(FILE_HANDLE)


# write the image with private key, and signature
# ADD PIN??
picseal.write_priv(FILE_HANDLE)

[ seal ]
sha-512,public-key


[[ Libraries ]]
libexiv2-14 (= 0.25-2.1), libc6 (>= 2.14), libgcc1 (>= 1:4.1.1), libstdc++6 (>= 5.2)


[[ Crypto ]]
@ http://security.stackexchange.com/
@ http://security.stackexchange.com/questions/135946/when-should-i-generate-new-public-private-keys-using-rsa




[[ Images ]]

[ PIL Pillow ]
# use pillow, a PIL fork
@ https://github.com/python-pillow/Pillow
@ http://pillow.readthedocs.io/en/3.0.x/handbook/tutorial.html#reading-and-writing-images

# no python 3 version :(
ver 1.1.7, for Python 2.7, Nov 15 2009


[[ JPG ]]
@ http://stackoverflow.com/questions/4550296/how-to-identify-contents-of-a-byte-is-a-jpeg?rq=1
@ https://en.wikipedia.org/wiki/Magic_number_%28programming%29
@ http://www.effbot.org/imagingbook/image.htm#tag-Image.Image.tobitmap



[[ Testing ]]


[ crypto test ]
b'-----BEGIN PUBLIC KEY-----\nMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAnvdAyn5JuiRcoL8s+rAV\nMpoEUioB1NTV97EDG4z/R5pm89v86UkH0xeeB6OS2EacsPHmbIY6oY0IXKA+0EX6\nSZdVSya2vv36fy/CByfHgZsDUxpzMnRZLdYbITBwil7keCTOC4EfnYIMUDsvrx6s\nA+BSEbR1rUkIXMe7NJ2Qssj68lXKMOfhrJ9wUgPLVSTIiDytiX4Wd+yAuo9lUqUk\nxt7FwjEEBV5Nj0yKZp2sJZnqp+pL5dsLsYz9xKNQHonMkGuj+3IthenTkfuXm9a6\nx+Qm3B+6AN4qBd7Uz65tffS2e2OQCzSRVoqEaRUrQKvQcSfJv+w0lh4xoZs41CJE\nc8XmmJeaDqt/zYBQWWYJlvZfpq0oh3mKGmHRtNOnKQmMd+FRJj/5fUvG7WedcHt1\noAkUg1qKu/HBgPNTVN9PWaikM1fA1E8T1koCYN0ecP29Zo8SHwcL6g82ou+fGtae\nSrXW0bFKV1JbF+hF3nBzCw+xDPAXXpUGPTwSXYZa6Gvgfckk4qP17vfFaR9f+hiL\nmW8GUmgfupvbapcG189M+UB9nDUSj3557TJpqItdbH5m4FGNv9tcMRYSwIniVVxw\n+F5FuT7nhd8vC+simwyjlB3hteICya1c7tVo5rav/LBBzHYg9ywPJCdZKUvN3qRE\n4Txbp7DC99x/xZhGck2Cpj8CAwEAAQ==\n-----END PUBLIC KEY-----'
privkey==
b'-----BEGIN RSA PRIVATE KEY-----\nMIIJKAIBAAKCAgEAnvdAyn5JuiRcoL8s+rAVMpoEUioB1NTV97EDG4z/R5pm89v8\n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