Package flumotion :: Package component :: Package bouncers :: Module saltsha256
[hide private]

Source Code for Module flumotion.component.bouncers.saltsha256

 1  # -*- Mode: Python; test-case-name: flumotion.test.test_saltsha256 -*- 
 2  # vi:si:et:sw=4:sts=4:ts=4 
 3   
 4  # Flumotion - a streaming media server 
 5  # Copyright (C) 2004,2005,2006,2007,2008,2009 Fluendo, S.L. 
 6  # Copyright (C) 2010,2011 Flumotion Services, S.A. 
 7  # All rights reserved. 
 8  # 
 9  # This file may be distributed and/or modified under the terms of 
10  # the GNU Lesser General Public License version 2.1 as published by 
11  # the Free Software Foundation. 
12  # This file is distributed without any warranty; without even the implied 
13  # warranty of merchantability or fitness for a particular purpose. 
14  # See "LICENSE.LGPL" in the source distribution for more information. 
15  # 
16  # Headers in this file shall remain intact. 
17   
18  """ 
19  a bouncer with a username/salt/sha256 data backend 
20  """ 
21   
22  import random 
23   
24  from twisted.internet import defer 
25   
26  from flumotion.common import keycards, log, errors 
27  from flumotion.component.bouncers import component as bcomponent 
28  from flumotion.twisted import credentials, checkers 
29   
30  __all__ = ['SaltSha256'] 
31  __version__ = "$Rev$" 
32   
33   
34 -class SaltSha256(bcomponent.ChallengeResponseBouncer):
35 """ 36 I am a bouncer that stores usernames, salts, and SHA-256 data 37 to authenticate against. 38 """ 39 40 logCategory = 'passwdsaltsha256' 41 keycardClasses = (keycards.KeycardUASPCC, ) 42 challengeResponseClasses = (keycards.KeycardUASPCC, ) 43
44 - def do_setup(self):
45 conf = self.config 46 47 # we need either a filename or data 48 props = conf['properties'] 49 filename = data = None 50 if 'filename' in props: 51 filename = props['filename'] 52 self.debug('using file %s for passwords', filename) 53 elif 'data' in props: 54 data = props['data'] 55 self.debug('using in-line data for passwords') 56 else: 57 return defer.fail(errors.ConfigError( 58 'PasswdSaltSha256 needs either a <data> or <filename> entry')) 59 # FIXME: generalize to a start method, possibly linked to mood 60 if filename: 61 try: 62 lines = open(filename).readlines() 63 except IOError, e: 64 return defer.fail(errors.ConfigError(str(e))) 65 else: 66 lines = data.split("\n") 67 68 self.setChecker(checkers.Sha256Checker()) 69 70 for line in lines: 71 if not ':' in line: 72 continue 73 # when coming from a file, it ends in \n, so strip. 74 # for data, we already splitted, so no \n, but strip is fine. 75 name, salt, sha256Data = line.strip().split(':') 76 self.addUser(name, salt, salt, sha256Data) 77 78 self.debug('parsed %s, %d lines' % (filename or '<memory>', 79 len(lines))) 80 81 return defer.succeed(None)
82