mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2024-12-20 13:33:09 +00:00
fix the debug tool for the hashed lease secret case
This commit is contained in:
parent
8adff050a7
commit
0cd96ed713
@ -230,8 +230,8 @@ def dump_mutable_share(options):
|
|||||||
print(" ownerid: %d" % lease.owner_num, file=out)
|
print(" ownerid: %d" % lease.owner_num, file=out)
|
||||||
when = format_expiration_time(lease.get_expiration_time())
|
when = format_expiration_time(lease.get_expiration_time())
|
||||||
print(" expires in %s" % when, file=out)
|
print(" expires in %s" % when, file=out)
|
||||||
print(" renew_secret: %s" % str(base32.b2a(lease.renew_secret), "utf-8"), file=out)
|
print(" renew_secret: %s" % lease.present_renew_secret(), file=out)
|
||||||
print(" cancel_secret: %s" % str(base32.b2a(lease.cancel_secret), "utf-8"), file=out)
|
print(" cancel_secret: %s" % lease.present_cancel_secret(), file=out)
|
||||||
print(" secrets are for nodeid: %s" % idlib.nodeid_b2a(lease.nodeid), file=out)
|
print(" secrets are for nodeid: %s" % idlib.nodeid_b2a(lease.nodeid), file=out)
|
||||||
else:
|
else:
|
||||||
print("No leases.", file=out)
|
print("No leases.", file=out)
|
||||||
|
@ -25,6 +25,7 @@ from twisted.python.components import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
from allmydata.util.hashutil import timing_safe_compare
|
from allmydata.util.hashutil import timing_safe_compare
|
||||||
|
from allmydata.util import base32
|
||||||
|
|
||||||
# struct format for representation of a lease in an immutable share
|
# struct format for representation of a lease in an immutable share
|
||||||
IMMUTABLE_FORMAT = ">L32s32sL"
|
IMMUTABLE_FORMAT = ">L32s32sL"
|
||||||
@ -102,12 +103,24 @@ class ILeaseInfo(Interface):
|
|||||||
secret, ``False`` otherwise
|
secret, ``False`` otherwise
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
def present_renew_secret():
|
||||||
|
"""
|
||||||
|
:return str: Text which could reasonably be shown to a person representing
|
||||||
|
this lease's renew secret.
|
||||||
|
"""
|
||||||
|
|
||||||
def is_cancel_secret(candidate_secret):
|
def is_cancel_secret(candidate_secret):
|
||||||
"""
|
"""
|
||||||
:return bool: ``True`` if the given byte string is this lease's cancel
|
:return bool: ``True`` if the given byte string is this lease's cancel
|
||||||
secret, ``False`` otherwise
|
secret, ``False`` otherwise
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
def present_cancel_secret():
|
||||||
|
"""
|
||||||
|
:return str: Text which could reasonably be shown to a person representing
|
||||||
|
this lease's cancel secret.
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
@implementer(ILeaseInfo)
|
@implementer(ILeaseInfo)
|
||||||
@attr.s(frozen=True)
|
@attr.s(frozen=True)
|
||||||
@ -173,6 +186,13 @@ class LeaseInfo(object):
|
|||||||
"""
|
"""
|
||||||
return timing_safe_compare(self.renew_secret, candidate_secret)
|
return timing_safe_compare(self.renew_secret, candidate_secret)
|
||||||
|
|
||||||
|
def present_renew_secret(self):
|
||||||
|
# type: () -> bytes
|
||||||
|
"""
|
||||||
|
Return the renew secret, base32-encoded.
|
||||||
|
"""
|
||||||
|
return str(base32.b2a(self.renew_secret), "utf-8")
|
||||||
|
|
||||||
def is_cancel_secret(self, candidate_secret):
|
def is_cancel_secret(self, candidate_secret):
|
||||||
# type: (bytes) -> bool
|
# type: (bytes) -> bool
|
||||||
"""
|
"""
|
||||||
@ -183,6 +203,13 @@ class LeaseInfo(object):
|
|||||||
"""
|
"""
|
||||||
return timing_safe_compare(self.cancel_secret, candidate_secret)
|
return timing_safe_compare(self.cancel_secret, candidate_secret)
|
||||||
|
|
||||||
|
def present_cancel_secret(self):
|
||||||
|
# type: () -> bytes
|
||||||
|
"""
|
||||||
|
Return the cancel secret, base32-encoded.
|
||||||
|
"""
|
||||||
|
return str(base32.b2a(self.cancel_secret), "utf-8")
|
||||||
|
|
||||||
def get_grant_renew_time_time(self):
|
def get_grant_renew_time_time(self):
|
||||||
# hack, based upon fixed 31day expiration period
|
# hack, based upon fixed 31day expiration period
|
||||||
return self._expiration_time - 31*24*60*60
|
return self._expiration_time - 31*24*60*60
|
||||||
@ -267,6 +294,12 @@ class HashedLeaseInfo(proxyForInterface(ILeaseInfo, "_lease_info")): # type: ign
|
|||||||
"""
|
"""
|
||||||
return super(HashedLeaseInfo, self).is_renew_secret(self._hash(candidate_secret))
|
return super(HashedLeaseInfo, self).is_renew_secret(self._hash(candidate_secret))
|
||||||
|
|
||||||
|
def present_renew_secret(self):
|
||||||
|
"""
|
||||||
|
Present the hash of the secret with a marker indicating it is a hash.
|
||||||
|
"""
|
||||||
|
return u"hash:" + super(HashedLeaseInfo, self).present_renew_secret()
|
||||||
|
|
||||||
def is_cancel_secret(self, candidate_secret):
|
def is_cancel_secret(self, candidate_secret):
|
||||||
"""
|
"""
|
||||||
Hash the candidate secret and compare the result to the stored hashed
|
Hash the candidate secret and compare the result to the stored hashed
|
||||||
@ -288,10 +321,20 @@ class HashedLeaseInfo(proxyForInterface(ILeaseInfo, "_lease_info")): # type: ign
|
|||||||
|
|
||||||
return super(HashedLeaseInfo, self).is_cancel_secret(hashed_candidate)
|
return super(HashedLeaseInfo, self).is_cancel_secret(hashed_candidate)
|
||||||
|
|
||||||
|
def present_cancel_secret(self):
|
||||||
|
"""
|
||||||
|
Present the hash of the secret with a marker indicating it is a hash.
|
||||||
|
"""
|
||||||
|
return u"hash:" + super(HashedLeaseInfo, self).present_cancel_secret()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def owner_num(self):
|
def owner_num(self):
|
||||||
return self._lease_info.owner_num
|
return self._lease_info.owner_num
|
||||||
|
|
||||||
|
@property
|
||||||
|
def nodeid(self):
|
||||||
|
return self._lease_info.nodeid
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def cancel_secret(self):
|
def cancel_secret(self):
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user