Changeset - b0e2c949c34b
[Not reviewed]
beta
0 3 0
Marcin Kuzminski - 15 years ago 2011-03-09 19:08:34
marcin@python-works.com
Fixed Windows installation based on work of Mantis406 fork: "Replace py-bcrypt to make Windows installation easier"
RhodeCode will now detect the platform and use sha256 hashes when used on Windows.
3 files changed with 58 insertions and 12 deletions:
0 comments (0 inline, 0 general)
rhodecode/__init__.py
Show inline comments
 
@@ -16,37 +16,38 @@
 
# as published by the Free Software Foundation; version 2
 
# of the License or (at your opinion) any later version of the license.
 
# 
 
# This program is distributed in the hope that it will be useful,
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
# GNU General Public License for more details.
 
# 
 
# You should have received a copy of the GNU General Public License
 
# along with this program; if not, write to the Free Software
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 
# MA  02110-1301, USA.
 

	
 
import platform
 

	
 
VERSION = (1, 2, 0, 'beta')
 
__version__ = '.'.join((str(each) for each in VERSION[:4]))
 
__dbversion__ = 3 #defines current db version for migrations
 
__platform__ = platform.system()
 

	
 
try:
 
    from rhodecode.lib.utils import get_current_revision
 
    _rev = get_current_revision()
 
except ImportError:
 
    #this is needed when doing some setup.py operations
 
    _rev = False
 

	
 
if len(VERSION) > 3 and _rev:
 
    __version__ += ' [rev:%s]' % _rev[0]
 

	
 
def get_version():
 
    """Returns shorter version (digit parts only) as string."""
 

	
 
    return '.'.join((str(each) for each in VERSION[:3]))
 

	
 
BACKENDS = {
 
    'hg': 'Mercurial repository',
 
   #'git': 'Git repository',
 
    #'git': 'Git repository',
 
}
rhodecode/lib/auth.py
Show inline comments
 
@@ -15,36 +15,44 @@
 
# of the License or (at your opinion) any later version of the license.
 
# 
 
# This program is distributed in the hope that it will be useful,
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
# GNU General Public License for more details.
 
# 
 
# You should have received a copy of the GNU General Public License
 
# along with this program; if not, write to the Free Software
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 
# MA  02110-1301, USA.
 

	
 
import bcrypt
 
import random
 
import logging
 
import traceback
 
import hashlib
 

	
 
from tempfile import _RandomNameSequence
 
from decorator import decorator
 

	
 
from pylons import config, session, url, request
 
from pylons.controllers.util import abort, redirect
 
from pylons.i18n.translation import _
 

	
 
from rhodecode import __platform__
 

	
 
if __platform__ == 'Windows':
 
    from hashlib import sha256
 
if __platform__ in ('Linux', 'Darwin'):
 
    import bcrypt
 

	
 

	
 
from rhodecode.lib.exceptions import LdapPasswordError, LdapUsernameError
 
from rhodecode.lib.utils import get_repo_slug
 
from rhodecode.lib.auth_ldap import AuthLdap
 

	
 
from rhodecode.model import meta
 
from rhodecode.model.user import UserModel
 
from rhodecode.model.db import Permission
 

	
 

	
 
log = logging.getLogger(__name__)
 

	
 
class PasswordGenerator(object):
 
@@ -63,41 +71,74 @@ class PasswordGenerator(object):
 
    ALPHABETS_ALPHANUM = ALPHABETS_BIG + ALPHABETS_SMALL + ALPHABETS_NUM#[5]
 
    ALPHABETS_BIG_SMALL = ALPHABETS_BIG + ALPHABETS_SMALL
 
    ALPHABETS_ALPHANUM_BIG = ALPHABETS_BIG + ALPHABETS_NUM#[6]
 
    ALPHABETS_ALPHANUM_SMALL = ALPHABETS_SMALL + ALPHABETS_NUM#[7]
 

	
 
    def __init__(self, passwd=''):
 
        self.passwd = passwd
 

	
 
    def gen_password(self, len, type):
 
        self.passwd = ''.join([random.choice(type) for _ in xrange(len)])
 
        return self.passwd
 

	
 
class RhodeCodeCrypto(object):
 

	
 
    @classmethod
 
    def hash_string(cls, str_):
 
        """
 
        Cryptographic function used for password hashing based on pybcrypt
 
        or pycrypto in windows
 
        
 
        :param password: password to hash
 
        """
 
        if __platform__ == 'Windows':
 
            return sha256(str_).hexdigest()
 
        elif __platform__ in ('Linux', 'Darwin'):
 
            return bcrypt.hashpw(str_, bcrypt.gensalt(10))
 
        else:
 
            raise Exception('Unknown or unsupoprted platform %s' % __platform__)
 

	
 
    @classmethod
 
    def hash_check(cls, password, hashed):
 
        """
 
        Checks matching password with it's hashed value, runs different
 
        implementation based on platform it runs on
 
        
 
        :param password: password
 
        :param hashed: password in hashed form
 
        """
 

	
 
        if __platform__ == 'Windows':
 
            return sha256(password).hexdigest() == hashed
 
        elif __platform__ in ('Linux', 'Darwin'):
 
            return bcrypt.hashpw(password, hashed) == hashed
 
        else:
 
            raise Exception('Unknown or unsupoprted platform %s' % __platform__)
 

	
 

	
 

	
 

	
 

	
 
def get_crypt_password(password):
 
    """Cryptographic function used for password hashing based on pybcrypt
 
    
 
    :param password: password to hash
 
    """
 
    return bcrypt.hashpw(password, bcrypt.gensalt(10))
 
    return RhodeCodeCrypto.hash_string(password)
 

	
 
def check_password(password, hashed):
 
    return RhodeCodeCrypto.hash_check(password, hashed)
 

	
 
def generate_api_key(username, salt=None):
 
    if salt is None:
 
        salt = _RandomNameSequence().next()
 

	
 
    return hashlib.sha1(username + salt).hexdigest()
 

	
 
def check_password(password, hashed):
 
    return bcrypt.hashpw(password, hashed) == hashed
 

	
 
def authfunc(environ, username, password):
 
    """Dummy authentication function used in Mercurial/Git/ and access control,
 
    
 
    :param environ: needed only for using in Basic auth
 
    """
 
    return authenticate(username, password)
 

	
 

	
 
def authenticate(username, password):
 
    """Authentication function used for access control,
 
    firstly checks for db authentication then if ldap is enabled for ldap
 
    authentication, also creates ldap user if not in database
setup.py
Show inline comments
 
import sys
 
from rhodecode import get_version
 
from rhodecode import __platform__
 

	
 
py_version = sys.version_info
 

	
 
requirements = [
 
        "Pylons==1.0.0",
 
        "WebHelpers>=1.2",
 
        "SQLAlchemy>=0.6.6",
 
        "Mako>=0.4.0",
 
        "vcs>=0.2.0",
 
        "pygments>=1.4",
 
        "mercurial>=1.7.5",
 
        "whoosh>=1.3.4",
 
        "celery>=2.2.4",
 
        "py-bcrypt",
 
        "babel",
 
    ]
 

	
 
classifiers = ['Development Status :: 4 - Beta',
 
               'Environment :: Web Environment',
 
               'Framework :: Pylons',
 
               'Intended Audience :: Developers',
 
               'License :: OSI Approved :: BSD License',
 
               'Operating System :: OS Independent',
 
               'Programming Language :: Python', ]
 

	
 
if py_version < (2, 6):
 
    requirements.append("simplejson")
 
    requirements.append("pysqlite")
 

	
 
if __platform__ in ('Linux', 'Darwin'):
 
    requirements.append("py-bcrypt")
 

	
 

	
 
#additional files from project that goes somewhere in the filesystem
 
#relative to sys.prefix
 
data_files = []
 

	
 
#additional files that goes into package itself
 
package_data = {'rhodecode': ['i18n/*/LC_MESSAGES/*.mo', ], }
 

	
 
description = ('Mercurial repository browser/management with '
 
               'build in push/pull server and full text search')
 
keywords = ' '.join (['rhodecode', 'rhodiumcode', 'mercurial', 'git',
 
                      'repository management', 'hgweb replacement'
 
                      'hgwebdir', 'gitweb replacement', 'serving hgweb',
0 comments (0 inline, 0 general)