Ejemplo n.º 1
0
def create_cryptoken(aes_key, data):

    if len(aes_key) >= 32:
        aes_key = aes_key[:32]
    elif len(aes_key) >= 16:
        aes_key = aes_key[:16]
    elif len(aes_key) >= 8:
        aes_key = aes_key[:8]
    else:
        raise AuthorizationFailure()

    if crypto_version.startswith('2.0'):

        prng = randpool.RandomPool()
        iv = prng.get_bytes(256)
        cipher = AES.new(aes_key, AES.MODE_CFB)
        tmpbuf = cipher.encrypt(iv)
        tmpbuf += cipher.encrypt(data)
        return base64.b64encode(tmpbuf)

    else:

        prng = Random.new()
        iv = prng.read(16)
        cipher = AES.new(aes_key, AES.MODE_CFB, iv)
        return base64.b64encode(iv + cipher.encrypt(data))
def create_cryptoken(aes_key, data):

    if len(aes_key) >= 32:
        aes_key = aes_key[:32]
    elif len(aes_key) >= 16:
        aes_key = aes_key[:16]
    elif len(aes_key) >= 8:
        aes_key = aes_key[:8]
    else:
        raise AuthorizationFailure()

    if crypto_version.startswith("2.0"):

        prng = randpool.RandomPool()
        iv = prng.get_bytes(256)
        cipher = AES.new(aes_key, AES.MODE_CFB)
        tmpbuf = cipher.encrypt(iv)
        tmpbuf += cipher.encrypt(data)
        return base64.b64encode(tmpbuf)

    else:

        prng = Random.new()
        iv = prng.read(16)
        cipher = AES.new(aes_key, AES.MODE_CFB, iv)
        return base64.b64encode(iv + cipher.encrypt(data))
def generate_pwd():
    if crypto_version.startswith('2.0'):
        prng = randpool.RandomPool()
        iv = prng.get_bytes(256)
    else:
        prng = Random.new()
        iv = prng.read(16)
    return base64.b64encode(iv)
Ejemplo n.º 4
0
def generate_pwd():
    if crypto_version.startswith('2.0'):
        prng = randpool.RandomPool()
        iv = prng.get_bytes(256)
    else:
        prng = Random.new()
        iv = prng.read(16)
    return base64.b64encode(iv)
Ejemplo n.º 5
0
    def _parse_cryptoken(self, data):
        if self.aes_key == None:
            raise Exception("Wrong secret key")

        if crypto_version.startswith('2.0'):
            cipher = AES.new(self.aes_key, AES.MODE_CFB)
            b64msg = base64.b64decode(data)
            return cipher.decrypt(b64msg)[256:]
        
        prng = Random.new()
        iv = prng.read(16)
        cipher = AES.new(self.aes_key, AES.MODE_CFB, iv)
        b64msg = base64.b64decode(data)
        return cipher.decrypt(b64msg)[16:]
#  http://www.apache.org/licenses/LICENSE-2.0
#
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#  License for the specific language governing permissions and limitations
#  under the License. 

import sys
import re
import logging
import base64
from datetime import datetime, timedelta

from Crypto import __version__ as crypto_version
if crypto_version.startswith('2.0'):
    from Crypto.Util import randpool
else:
    from Crypto import Random

from horizon import forms
from horizon import messages

from django.db import transaction
from django.conf import settings
from django.forms import ValidationError
from django.forms.widgets import HiddenInput
from django.forms.extras.widgets import SelectDateWidget
from django.views.decorators.debug import sensitive_variables
from django.utils.translation import ugettext as _
Ejemplo n.º 7
0
#  http://www.apache.org/licenses/LICENSE-2.0
#
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#  License for the specific language governing permissions and limitations
#  under the License.

import sys
import re
import logging
import base64
from datetime import datetime, timedelta

from Crypto import __version__ as crypto_version
if crypto_version.startswith('2.0'):
    from Crypto.Util import randpool
else:
    from Crypto import Random

from horizon import forms
from horizon import messages

from django.db import transaction
from django.conf import settings
from django.forms import ValidationError
from django.forms.widgets import HiddenInput
from django.forms.extras.widgets import SelectDateWidget
from django.views.decorators.debug import sensitive_variables
from django.utils.translation import ugettext as _
#
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#  License for the specific language governing permissions and limitations
#  under the License.


import logging
import base64
import json

from Crypto.Cipher import AES
from Crypto import __version__ as crypto_version

if crypto_version.startswith("2.0"):
    from Crypto.Util import randpool
else:
    from Crypto import Random

from django.conf import settings
from django.utils.translation import ugettext as _

from keystoneclient.exceptions import AuthorizationFailure
from keystoneclient.exceptions import Unauthorized
from keystoneclient.exceptions import NotFound
from keystoneclient.exceptions import ClientException
from keystoneclient.v3.client import Client as BaseClient

from openstack_auth import backend as base_backend
from openstack_auth.exceptions import KeystoneAuthException