~ubuntu-branches/ubuntu/precise/keystone/precise-proposed

« back to all changes in this revision

Viewing changes to keystone/backends/backendutils.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short, Chuck Short, Joseph Heck, Adam Gandelman, Dave Walker, Andrew Glen-Young
  • Date: 2012-03-02 09:55:24 UTC
  • mfrom: (1.1.11)
  • Revision ID: package-import@ubuntu.com-20120302095524-koae5li138f7uesh
Tags: 2012.1~e4-0ubuntu1
[ Chuck Short ]
* New upstream release. 
* debian/keystone.upstart: Update for ksl.
* debian/control: Add python-keystoneclient as dependency.
* debian/control: Fix typo.
* debian/keystone.postinst: Update due to redux branch change.
* debian/keystone.templates, debian/keystone.preinst, debian/kestone.postinst,
  debian/keystone.config, debian/README.Debian: Make keystone installation 
  less interactive. (LP: #931236)
* debian/keystone.postinst: Don't create users or run a database sync
  since its not working correctly.
* debian/control: Dropped python-coverage and python-nosexcover.
* debian/changelog: Fixed changelog.
* debian/keystone.templates: Set it to false.
* debian/control: Fix lintian warnings.
* debian/patches/keystone-auth.patch: Backport auth token improvements,
  this can be dropped in the next snapshot.
* debian/control: Add python-memcache as a build dependency.
* debian/keystone-doc.docs: Fix keystone doc builds.
* debian/rules: Temporarily disable doc install.
* debian/control: Add python-ldap and python-lxml.

[ Joseph Heck ]
* debian/control: Dropped python-cli.

[ Adam Gandelman ]
* debian/control: Alphabetize python depends 
* debian/control: Add python-{eventlet, greenlet, passlib} to keystone
  depends
* debian/control: Add python-lxml to python-keystone Depends
* Drop 0001-Fix-keystone-all-failure-to-start.patch
* debian/logging.conf: Temporarily use old logging.conf until upstream
  ships something usable
* debain/patches/sql_connection.patch: Switch backends to use SQL backends
* debian/keystone.preinst: Create directories
* debian/keystone.postinst: Remove create_users stuff, add call to 'db_sync'
  on install

[ Dave Walker ]
* debian/patches/sql_connection.patch: Refreshed and reintroduced DEP-3
  headers.
* debian/control: Added Vcs-Bzr field.

[ Andrew Glen-Young ]
* debian/keystone.preinst: Set the primary group to keystone. (LP: #941905)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
import logging
2
 
logger = logging.getLogger(__name__)  # pylint: disable=C0103
3
 
 
4
 
from keystone.backends import models
5
 
import keystone.backends as backends
6
 
# pylint: disable=E0611
7
 
try:
8
 
    from passlib.hash import sha512_crypt as sc
9
 
except ImportError as exc:
10
 
    logger.exception(exc)
11
 
    raise exc
12
 
 
13
 
 
14
 
def __get_hashed_password(password):
15
 
    if password:
16
 
        return __make_password(password)
17
 
    else:
18
 
        return None
19
 
 
20
 
 
21
 
def set_hashed_password(values):
22
 
    """
23
 
    Sets hashed password for password.
24
 
    """
25
 
    if backends.SHOULD_HASH_PASSWORD:
26
 
        if isinstance(values, dict) and 'password' in values.keys():
27
 
            values['password'] = __get_hashed_password(values['password'])
28
 
        elif isinstance(values, models.User):
29
 
            values.password = __get_hashed_password(values.password)
30
 
        else:
31
 
            logger.warn("Could not hash password on unsupported type: %s" %
32
 
                        type(values))
33
 
 
34
 
 
35
 
def check_password(raw_password, enc_password):
36
 
    """
37
 
    Compares raw password and encoded password.
38
 
    """
39
 
    if not raw_password:
40
 
        return False
41
 
    if backends.SHOULD_HASH_PASSWORD:
42
 
        return sc.verify(raw_password, enc_password)
43
 
    else:
44
 
        return enc_password == raw_password
45
 
 
46
 
 
47
 
def __make_password(raw_password):
48
 
    """
49
 
     Produce a new encoded password.
50
 
    """
51
 
    if raw_password is None:
52
 
        return None
53
 
    hsh = __get_hexdigest(raw_password)
54
 
    return '%s' % (hsh)
55
 
 
56
 
 
57
 
#Refer http://packages.python.org/passlib/lib/passlib.hash.sha512_crypt.html
58
 
#Using the default properties as of now.Salt gets generated automatically.
59
 
def __get_hexdigest(raw_password):
60
 
    return sc.encrypt(raw_password)