python3 datafeed implementation

I'm trying to wrap my head around decoding the RC4 encrypted feed of Foxycart. I have the php example running and have verified that the url unquoting is working correctly. As soon as i enable the encryption it starts failing though.

My posted data looks like this (url encoded):
%26%E0%A4%DBE%A8%8DD%8C%88%DE%9A%19%1D%1E%9E%A2%D7%B5%08J%60%13%A7n%B5

after url decoding and decrypting i get this python byte string:
b'C\xd3\xe4\xbb\xcftBO\x17\x17\x10'

I've looked at existing python implementations on the integrations page, but they yield the exact same result.

Did anything change in the way this should be implemented?
Comments
  • fc_marijafc_marija FoxyCart Team
    Hi @markofabrique

    We'll spend some time on this and see what we can figure out. Let us know if you make any progress in the meantime.
  • fc_marijafc_marija FoxyCart Team
    Hi @markofabrique - Can you post your code somewhere we can check it out, such as pastbin.com? The forum doesn't do whitespace in code blocks.
  • Here's my debugging version
    https://pastebin.com/krXhGvK6

  • fc_marijafc_marija FoxyCart Team
    @markofabrique

    Have you tried the ARC4 class from our Django example? I pulled it out and put it here: https://pastebin.com/raw/PQx8Nusp

    The entire example is here: https://wiki.foxycart.com/integration/django.
  • this is interesting, it seems they yield different results but no working example as of yet:

    Foxycart python ARC4:
    、f<}e;ret *tオi)g, BoMhPahE

    python Crypto ARC4:

    b"v\x04\\O\xd3[\xb8\xc0\xa9\xc3H\xdb\x81\xd7K\xc8Z\x7f\xbfB?\x86pa\xe4g@8l\xbdUv\xda\xbd\xa4\r\x9d\r\xd77\xdf#\xc9'\x17\xc7k\x00\xd6\x13"

    Does this mean the ARC4 implementation is inconsistent cross platform?
  • fc_marijafc_marija FoxyCart Team
    @markofabrique

    Still with you here! I'm using this class called FoxyData, which creates a FoxyData object containing all the Transactions in the datafeed. Perhaps I'm missing something, but I'm not seeing anything in the code you provided that does something similar. The ARC4 class that I shared with you earlier and this are in the same python file in the Python/Django example on our wiki. So, basically, we are 1. Decoding, 2. Decrypting, 3. Creating an object with for accessing the transactions

    I believe all the examples in our wiki are 2.7, so you may need to do some translation to 3. Also, I am using urllib.unquote_plus() on the returned data, but I know that 2.7 and 3 are different in that regard. I thought I would just throw that out there in case it's relevant. Here's a link to the file: https://pastebin.com/raw/4i4gqTG4

    I have the decrypting and parsing working in 2.7, so if you're interested in digging around at that let me know.

    Hope my post has some valuable info for you. Let us know how it turns out or if we can provide additional pointers.
  • Thanks for this. I've got a python2 version now working. It seems the unquote_plus function yields completely different results with Python3. The output looks a lot different. I will look into this and if i get it working will post back!
  • I've been doing some bughunting and got it working.

    It seems the Python3 ARC4 function yields a different result (it looks like a byte object). So I've used the Python2 example which does work. Next to that it is crucial that unquote_plus gets and encoding parameter. Since Python3 does utf-8 by default, and so does unquote_plus.

    So by changing this simple line it works flawlessly:
    unquote_plus(post, encoding="latin-1")

    Might be a good idea to state in the docs that the Foxycart POST data is latin-1 encoded :)
  • fc_marijafc_marija FoxyCart Team
    @markofabrique

    Glad you got it working, and thanks for your feedback. So did you use the python2 example and then get it working for python3 or did you tweak your python3 code from earlier?

    Since you now have a working python3 example, any chance you'd be willing share it on our wiki for other users?
  • Sure, however I'm not sure how I can post something on your wiki. Let me know then I can post some code.
  • fc_adamfc_adam FoxyCart Team
    edited May 18
    @markofabrique,

    Thanks! If you'd like - you can simply put it in a pastebin and we can get it added to the wiki for you.
  • Here you go! I just customised a few minor things like an extra variable etc.
    https://pastebin.com/ApdRtsB8
  • fc_marijafc_marija FoxyCart Team
    Thanks @markofabrique, that really helps our users.
Sign In or Register to comment.