Ejemplo n.º 1
0
def setPsafePasswordByUUID(username, password, safeUUID, safePassword, **kw):
    """ Update the given user's personal psafe to include the password to the given safe.
      
    @param username: Requesting user's login
    @type username: string
    @param password: Requesting user's login
    @type password: string
    @param safeUUID: The database UUID of the safe that the password is for.  
    @type safeUUID: int
    @param safePassword: The password to use when decrypting the given psafe. 
    @type safePassword: string
    @return: boolean, True on success
    @raise EntryDoesntExistError: The safe you are trying to save a password for doesn't exist or the requesting user doesn't have access to it.  
    """
    try:
        # TODO: Add in better handling of more than one entry with the same UUID
        pws = PasswordSafe.objects.get(uuid=safeUUID)
    except PasswordSafe.DoesNotExist:
        raise EntryDoesntExistError

    repo = pws.repo
    if repo.user_can_access(kw['user'], mode="R"):
        # User should have access to the requested safe
        setDatabasePasswordByUser(
                                  user=kw['user'],
                                  userPassword=password,
                                  psafe=pws,
                                  psafePassword=safePassword,
                                  wait=True,
                                  )
        return True
    # User doesn't have access so it might as well not exist
    raise EntryDoesntExistError
Ejemplo n.º 2
0
 def test_get_and_set_DatabasePasswordByUser_simple(self):
     from django.conf import settings
     from psafefe.psafe.models import *
     from psafefe.psafe.functions import getUsersPersonalSafe, getDatabasePasswordByUser, setDatabasePasswordByUser
     # Create a user with read/write access to the test safe repo
     username, user = self.getUser(
                                   userClass = 'user',
                                   groups = [
                                             self.groupsByRepo['testsafes']['writes'],
                                             self.groupsByRepo['testsafes']['reads'],
                                             ],
                                   )
     userpass = self.getUserPass(user = user)
     
     mySafe = getUsersPersonalSafe(
                                   user = user,
                                   userPassword = userpass,
                                   wait = True,
                                   )
     self.assertTrue(mySafe)
     
     # Get the DB we're working with
     db = PasswordSafe.objects.get(
                                   repo = self.groupsByRepo['testsafes']['repo'],
                                   filename__endswith = "simple.psafe3",
                                   )
     
     # Save the DB password
     setDatabasePasswordByUser(
                               user = user,
                               userPassword = userpass,
                               psafe = db,
                               psafePassword = '******',
                               wait = True,
                               )
     
     # Try with ppsafe set 
     dbPassword = getDatabasePasswordByUser(
                                            user = user,
                                            userPassword = userpass,
                                            psafe = db,
                                            ppsafe = mySafe,
                                            wait = True,
                                            )  
     self.assertEqual(dbPassword, 'bogus12345', "Password for simple.psafe3 is wrong or has changed. Was trying without passing in a personal psafe to getDatabasePasswordByUser")      
     # try without ppsafe set
     dbPassword = getDatabasePasswordByUser(
                                            user = user,
                                            userPassword = userpass,
                                            psafe = db,
                                            ppsafe = None,
                                            wait = True,
                                            )
     self.assertEqual(dbPassword, 'bogus12345', "Password for simple.psafe3 is wrong or has changed. Was trying with passing in a personal psafe to getDatabasePasswordByUser")