Changeset 6c756ba in trunk


Ignore:
Timestamp:
2015-01-06T18:10:41Z (10 years ago)
Author:
Daira Hopwood <daira@…>
Branches:
master
Children:
6194ab9
Parents:
102d581
Message:

Simplify key checking code by inlining _allowedKey and _correctSignature. refs #1141

Signed-off-by: Daira Hopwood <daira@…>

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified src/allmydata/frontends/auth.py

    r102d581 r6c756ba  
    8383        return d
    8484
    85     def _allowedKey(self, creds):
    86         """
    87         Determine whether the public key indicated by the given credentials is
    88         one allowed to authenticate the username in those credentials.
    89 
    90         Returns True if so, False otherwise.
    91         """
    92         return creds.blob == self.pubkeys.get(creds.username)
    93 
    94     def _correctSignature(self, creds):
    95         """
    96         Determine whether the signature in the given credentials is the correct
    97         signature for the data in those credentials.
    98 
    99         Returns True if so, False otherwise.
    100         """
    101         key = keys.Key.fromString(creds.blob)
    102         return key.verify(creds.signature, creds.sigData)
    103 
    10485    def _checkKey(self, creds):
    10586        """
     
    11091        UnauthorizedLogin failure otherwise.
    11192        """
    112         if self._allowedKey(creds):
     93
     94        # Is the public key indicated by the given credentials allowed to
     95        # authenticate the username in those credentials?
     96        if creds.blob == self.pubkeys.get(creds.username):
    11397            if creds.signature is None:
    11498                return defer.fail(conch_error.ValidPublicKey())
    115             if self._correctSignature(creds):
     99
     100            # Is the signature in the given credentials the correct
     101            # signature for the data in those credentials?
     102            key = keys.Key.fromString(creds.blob)
     103            if key.verify(creds.signature, creds.sigData):
    116104                return defer.succeed(self._avatarId(creds.username))
     105
    117106        return defer.fail(error.UnauthorizedLogin())
    118107
Note: See TracChangeset for help on using the changeset viewer.