Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use cryptography instead of pycrypto #11

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 26 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,31 @@
# Config file for automatic testing at travis-ci.org

language: python
env:
- TOXENV=py26
- TOXENV=py27
- TOXENV=py33
- TOXENV=py34

# command to install dependencies, e.g. pip install -r requirements.txt --use-mirrors
install: pip install tox
matrix:
include:
- python: 2.7
env: TOXENV=py27
- python: 3.3
env: TOXENV=py33
- python: 3.4
env: TOXENV=py34
- python: pypy
env: TOXENV=pypy

install:
- |
if [ "$TRAVIS_PYTHON_VERSION" = "pypy" ]; then
export PYENV_ROOT="$HOME/.pyenv"
if [ -f "$PYENV_ROOT/bin/pyenv" ]; then
pushd "$PYENV_ROOT" && git pull && popd
else
rm -rf "$PYENV_ROOT" && git clone --depth 1 https://github.com/yyuu/pyenv.git "$PYENV_ROOT"
fi
export PYPY_VERSION="5.1.1"
"$PYENV_ROOT/bin/pyenv" install --skip-existing "pypy-$PYPY_VERSION"
virtualenv --python="$PYENV_ROOT/versions/pypy-$PYPY_VERSION/bin/python" "$HOME/virtualenvs/pypy-$PYPY_VERSION"
source "$HOME/virtualenvs/pypy-$PYPY_VERSION/bin/activate"
fi
- pip install tox

# command to run tests, e.g. python setup.py test
# script: py.test tests
script: tox
after_failure: cat .tox/log/tox-*.log
35 changes: 24 additions & 11 deletions pycookiecheat/pycookiecheat.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
'''pyCookieCheat.py
"""pyCookieCheat.py
See relevant post at http://n8h.me/HufI1w

Use your browser's cookies to make grabbing data from login-protected sites
Expand All @@ -10,18 +10,19 @@

Adapted from my code at http://n8h.me/HufI1w

Helpful Links:
* Chromium Mac os_crypt: http://n8h.me/QWRgK8
* Chromium Linux os_crypt: http://n8h.me/QWTglz
* Python Crypto: http://n8h.me/QWTqte
'''
"""

import sqlite3
import os.path
import keyring
import sys
from Crypto.Cipher import AES
from Crypto.Protocol.KDF import PBKDF2

from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives.ciphers import Cipher
from cryptography.hazmat.primitives.ciphers.algorithms import AES
from cryptography.hazmat.primitives.ciphers.modes import CBC
from cryptography.hazmat.primitives.hashes import SHA1
from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC

try:
from urllib.parse import urlparse
Expand Down Expand Up @@ -50,8 +51,13 @@ def clean(x):
else:
return x[:-ord(last)].decode('utf8')

cipher = AES.new(key, AES.MODE_CBC, IV=iv)
decrypted = cipher.decrypt(encrypted_value)
cipher = Cipher(
algorithm=AES(key),
mode=CBC(iv),
backend=default_backend(),
)
decryptor = cipher.decryptor()
decrypted = decryptor.update(encrypted_value) + decryptor.finalize()

return clean(decrypted)

Expand All @@ -75,7 +81,14 @@ def clean(x):
raise OSError("This script only works on OSX or Linux.")

# Generate key from values above
key = PBKDF2(my_pass, salt, length, iterations)
kdf = PBKDF2HMAC(
algorithm=SHA1(),
length=length,
salt=salt,
iterations=iterations,
backend=default_backend(),
)
key = kdf.derive(bytes(my_pass))

# Part of the domain name that will help the sqlite3 query pick it from the
# Chrome cookies
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
keyring>=5.0
pycrypto>=2.6.1
cryptography==1.3.2
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[tox]
envlist = py27, py34
envlist = py27, py34, pypy

[testenv]
passenv = TRAVIS
setenv =
PYTHONPATH = {toxinidir}:{toxinidir}/pycookiecheat
commands =
commands =
py.test -v tests --showlocals
flake8
deps =
Expand Down