Skip to content
Browse files

added

  • Loading branch information...
1 parent dbabd3e commit a9973e0099cef414993e11a59b1923a2dfa615ff @zopyx committed Mar 30, 2012
Showing with 55 additions and 0 deletions.
  1. +55 −0 main2.py
View
55 main2.py
@@ -0,0 +1,55 @@
+# The values have been tested with the key '629fbd46' for comparaison
+import sys
+import os
+import hashlib
+import requests
+
+filename = sys.argv[1]
+key = sys.argv[2]
+
+# sha1 of the concatenate of the md5 of filedata, with the wizard key
+filedata = file(filename, 'rb').read()
+md = hashlib.md5()
+md.update(filedata)
+md5digest = md.hexdigest()
+print ('MD5 Digest (file data)')
+print (md.hexdigest())
+# returns "9a6a93b4e183c857beaa948d68b6bc48" : correct
+
+sha = hashlib.sha1()
+#sha.update(filedata) # No
+sha.update(md5digest)
+sha.update(key)
+digest = sha.digest()
+hexdigest = sha.hexdigest()
+print ('SHA1 Digest ')
+print (repr(digest))
+print ('SHA1 Hex-Digest ')
+print (hexdigest)
+# returns "e360211727e58999b6219b3bbd5ce439e98e9763" : correct
+
+# initially[*], the 'data' parameter was the serialized value of the table [md5,hexdigest]
+# see for compatibility with php this module : http://pypi.python.org/pypi/phpserialize
+# But as there is no encoding of this array, I've just modify this so that
+# (No need for extra specific module which can be avoided)
+# So now you send explicitly the md5 and the hexdigest
+# The md5 id used on the server to check that the file received is the correct one
+
+# [*] That complex stuff was used to prepare the eventual "reverse" way
+# (from SPIP to zopyx server)
+# and with an extra layer of encryption of the 'data' parameter
+
+payload = {'action' : 'zopyx_reception',
+ 'md5' : md5digest,
+ 'data' : hexdigest}
+files = {'zipfile' : file(filename, 'rb')}
+
+#url = 'http://dev.tech-nova.fr/zopyx/+' + key
+url = 'http://dev.tech-nova.fr/zopyx/'
+print ('URL ')
+print (url)
+r = requests.post(url, data=payload, files=files)
+print ('Code')
+print (r.status_code)
+print ('Response')
+print (r.text)

0 comments on commit a9973e0

Please sign in to comment.
Something went wrong with that request. Please try again.