aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichał Górny <mgorny@gentoo.org>2013-08-21 23:14:40 +0200
committerMichał Górny <mgorny@gentoo.org>2013-08-21 23:54:06 +0200
commit0ba365730e33d30e24b77b440cea5ca3425d87aa (patch)
tree2364ac8a9fc71c3982f278e3b00e471db3f0c727
parent'Pack' session id into binary string before encrypting. (diff)
downloadidentity.gentoo.org-0ba365730e33d30e24b77b440cea5ca3425d87aa.tar.gz
identity.gentoo.org-0ba365730e33d30e24b77b440cea5ca3425d87aa.tar.bz2
identity.gentoo.org-0ba365730e33d30e24b77b440cea5ca3425d87aa.zip
Move crypto-related stuff to okupy.crypto.
-rw-r--r--okupy/accounts/forms.py2
-rw-r--r--okupy/accounts/models.py2
-rw-r--r--okupy/accounts/views.py4
-rw-r--r--okupy/common/ldap_helpers.py2
-rw-r--r--okupy/crypto/__init__.py0
-rw-r--r--okupy/crypto/ciphers.py (renamed from okupy/common/crypto.py)25
-rw-r--r--okupy/crypto/codecs.py27
-rw-r--r--okupy/crypto/models.py (renamed from okupy/common/models.py)3
-rw-r--r--okupy/otp/totp/models.py2
-rw-r--r--okupy/settings/__init__.py2
-rw-r--r--okupy/tests/settings.py2
-rw-r--r--okupy/tests/unit/test_cipher.py2
-rw-r--r--okupy/tests/unit/test_login.py2
-rw-r--r--okupy/tests/unit/test_secondary_password.py2
14 files changed, 40 insertions, 37 deletions
diff --git a/okupy/accounts/forms.py b/okupy/accounts/forms.py
index a36cf53..be6e1e8 100644
--- a/okupy/accounts/forms.py
+++ b/okupy/accounts/forms.py
@@ -3,7 +3,7 @@
from django import forms
from .models import OpenID_Attributes
-from ..common.crypto import sessionrefcipher
+from ..crypto.ciphers import sessionrefcipher
class LoginForm(forms.Form):
diff --git a/okupy/accounts/models.py b/okupy/accounts/models.py
index db5c0c7..3f41705 100644
--- a/okupy/accounts/models.py
+++ b/okupy/accounts/models.py
@@ -6,7 +6,7 @@ from ldapdb.models.fields import (CharField, IntegerField, ListField,
FloatField, ACLField, DateField)
import ldapdb.models
-from ..common.models import EncryptedPKModel
+from ..crypto.models import EncryptedPKModel
class Queue(EncryptedPKModel):
diff --git a/okupy/accounts/views.py b/okupy/accounts/views.py
index 0a8b8ee..103b267 100644
--- a/okupy/accounts/views.py
+++ b/okupy/accounts/views.py
@@ -34,11 +34,11 @@ from .openid_store import DjangoDBOpenIDStore
from ..common.ldap_helpers import (get_bound_ldapuser,
set_secondary_password,
remove_secondary_password)
-from ..common.crypto import sessionrefcipher
from ..common.decorators import strong_auth_required, anonymous_required
from ..common.exceptions import OkupyError
from ..common.log import log_extra_data
-from ..common.models import RevokedToken
+from ..crypto.ciphers import sessionrefcipher
+from ..crypto.models import RevokedToken
from ..otp import init_otp
from ..otp.sotp.models import SOTPDevice
from ..otp.totp.models import TOTPDevice
diff --git a/okupy/common/ldap_helpers.py b/okupy/common/ldap_helpers.py
index 1bcfa69..4970e6a 100644
--- a/okupy/common/ldap_helpers.py
+++ b/okupy/common/ldap_helpers.py
@@ -4,7 +4,7 @@ from base64 import b64encode
from Crypto import Random
from passlib.hash import ldap_md5_crypt
-from .crypto import cipher
+from ..crypto.ciphers import cipher
from ..accounts.models import LDAPUser
diff --git a/okupy/crypto/__init__.py b/okupy/crypto/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/okupy/crypto/__init__.py
diff --git a/okupy/common/crypto.py b/okupy/crypto/ciphers.py
index 1efb00f..0414fb3 100644
--- a/okupy/common/crypto.py
+++ b/okupy/crypto/ciphers.py
@@ -8,32 +8,9 @@ from Crypto.Hash.SHA256 import SHA256Hash
import Crypto.Random
-import base64
import struct
-
-def ub32encode(text):
- """ Encode text as unpadded base32. """
- return base64.b32encode(text).rstrip('=')
-
-
-def ub32decode(text):
- """ Decode text from unpadded base32. """
- # add missing padding if necessary
- text += '=' * (-len(text) % 8)
- return base64.b32decode(text, casefold=True)
-
-
-def ub64encode(text):
- """ Encode text as unpadded base64. """
- return base64.b64encode(text).rstrip('=')
-
-
-def ub64decode(text):
- """ decode text from unpadded base64. """
- # add missing padding if necessary
- text += '=' * (-len(text) % 4)
- return base64.b64decode(text)
+from .codecs import ub32encode, ub32decode, ub64encode, ub64decode
class OkupyCipher(object):
diff --git a/okupy/crypto/codecs.py b/okupy/crypto/codecs.py
new file mode 100644
index 0000000..98c822b
--- /dev/null
+++ b/okupy/crypto/codecs.py
@@ -0,0 +1,27 @@
+# vim:fileencoding=utf8:et:ts=4:sts=4:sw=4:ft=python
+
+import base64
+
+
+def ub32encode(text):
+ """ Encode text as unpadded base32. """
+ return base64.b32encode(text).rstrip('=')
+
+
+def ub32decode(text):
+ """ Decode text from unpadded base32. """
+ # add missing padding if necessary
+ text += '=' * (-len(text) % 8)
+ return base64.b32decode(text, casefold=True)
+
+
+def ub64encode(text):
+ """ Encode text as unpadded base64. """
+ return base64.b64encode(text).rstrip('=')
+
+
+def ub64decode(text):
+ """ decode text from unpadded base64. """
+ # add missing padding if necessary
+ text += '=' * (-len(text) % 4)
+ return base64.b64decode(text)
diff --git a/okupy/common/models.py b/okupy/crypto/models.py
index 545d369..b2eaa08 100644
--- a/okupy/common/models.py
+++ b/okupy/crypto/models.py
@@ -1,11 +1,10 @@
# vim:fileencoding=utf8:et:ts=4:sts=4:sw=4:ft=python
-from django.conf import settings
from django.contrib.auth.models import User
from django.db import models, IntegrityError
from django.utils.timezone import now
-from .crypto import idcipher
+from .ciphers import idcipher
from datetime import timedelta
diff --git a/okupy/otp/totp/models.py b/okupy/otp/totp/models.py
index b9c3cec..72f5e3d 100644
--- a/okupy/otp/totp/models.py
+++ b/okupy/otp/totp/models.py
@@ -4,7 +4,7 @@ from django_otp import oath
from django_otp.models import Device
from ...accounts.models import LDAPUser
-from ...common.crypto import ub32decode, ub32encode
+from ...crypto.codecs import ub32decode, ub32encode
import Crypto.Random
diff --git a/okupy/settings/__init__.py b/okupy/settings/__init__.py
index edf93aa..767bb22 100644
--- a/okupy/settings/__init__.py
+++ b/okupy/settings/__init__.py
@@ -50,7 +50,7 @@ INSTALLED_APPS = (
'django.contrib.messages',
'django.contrib.staticfiles',
'okupy.accounts',
- 'okupy.common',
+ 'okupy.crypto',
'okupy.otp.sotp',
'okupy.otp.totp',
)
diff --git a/okupy/tests/settings.py b/okupy/tests/settings.py
index b2e1787..ac4e9df 100644
--- a/okupy/tests/settings.py
+++ b/okupy/tests/settings.py
@@ -53,7 +53,7 @@ INSTALLED_APPS = (
'django_otp',
'discover_runner',
'okupy.accounts',
- 'okupy.common',
+ 'okupy.crypto',
'okupy.otp.sotp',
'okupy.otp.totp',
'okupy.tests',
diff --git a/okupy/tests/unit/test_cipher.py b/okupy/tests/unit/test_cipher.py
index aebc05a..0589dfd 100644
--- a/okupy/tests/unit/test_cipher.py
+++ b/okupy/tests/unit/test_cipher.py
@@ -5,7 +5,7 @@ from unittest import TestCase, SkipTest
from django.contrib.sessions.backends.cache import SessionStore
-from ...common.crypto import cipher, sessionrefcipher
+from ...crypto.ciphers import cipher, sessionrefcipher
class OkupyCipherTests(TestCase):
diff --git a/okupy/tests/unit/test_login.py b/okupy/tests/unit/test_login.py
index 58c01ea..8aaf2c1 100644
--- a/okupy/tests/unit/test_login.py
+++ b/okupy/tests/unit/test_login.py
@@ -15,8 +15,8 @@ from mockldap import MockLdap
from .. import vars
from ...accounts.views import login, logout
from ...accounts.forms import LoginForm
-from ...common.crypto import cipher
from ...common.test_helpers import OkupyTestCase, set_request, no_database, ldap_users, set_search_seed
+from ...crypto.ciphers import cipher
class LoginUnitTests(OkupyTestCase):
diff --git a/okupy/tests/unit/test_secondary_password.py b/okupy/tests/unit/test_secondary_password.py
index 8338827..baef415 100644
--- a/okupy/tests/unit/test_secondary_password.py
+++ b/okupy/tests/unit/test_secondary_password.py
@@ -9,9 +9,9 @@ from mockldap import MockLdap
from passlib.hash import ldap_md5_crypt
from .. import vars
-from ...common.crypto import cipher
from ...common.ldap_helpers import set_secondary_password, remove_secondary_password
from ...common.test_helpers import set_request, set_search_seed, ldap_users
+from ...crypto.ciphers import cipher
class SecondaryPassword(TestCase):