1
0
mirror of https://github.com/samba-team/samba.git synced 2025-02-08 05:57:51 +03:00

tests/krb5: Add get_EpochFromKerberosTime()

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14817
(cherry picked from commit bab7503e3043002b1422b00f40cd03a0a29538aa)
This commit is contained in:
Joseph Sutton 2021-07-22 16:27:17 +12:00 committed by Jule Anger
parent 29aa10b93a
commit 300ac82e72
2 changed files with 14 additions and 9 deletions

View File

@ -732,15 +732,9 @@ class KDCBaseTest(RawKerberosTest):
cred.client = cprincipal
cred.server = sprincipal
cred.keyblock = keyblock
cred.authtime = int(datetime.strptime(authtime.decode(),
"%Y%m%d%H%M%SZ")
.replace(tzinfo=timezone.utc).timestamp())
cred.starttime = int(datetime.strptime(starttime.decode(),
"%Y%m%d%H%M%SZ")
.replace(tzinfo=timezone.utc).timestamp())
cred.endtime = int(datetime.strptime(endtime.decode(),
"%Y%m%d%H%M%SZ")
.replace(tzinfo=timezone.utc).timestamp())
cred.authtime = self.get_EpochFromKerberosTime(authtime)
cred.starttime = self.get_EpochFromKerberosTime(starttime)
cred.endtime = self.get_EpochFromKerberosTime(endtime)
# Account for clock skew of up to five minutes.
self.assertLess(cred.authtime - 5 * 60,

View File

@ -861,6 +861,17 @@ class RawKerberosTest(TestCaseInTempDir):
(s, _) = self.get_KerberosTimeWithUsec(epoch=epoch, offset=offset)
return s
def get_EpochFromKerberosTime(self, kerberos_time):
if isinstance(kerberos_time, bytes):
kerberos_time = kerberos_time.decode()
epoch = datetime.datetime.strptime(kerberos_time,
'%Y%m%d%H%M%SZ')
epoch = epoch.replace(tzinfo=datetime.timezone.utc)
epoch = int(epoch.timestamp())
return epoch
def get_Nonce(self):
nonce_min = 0x7f000000
nonce_max = 0x7fffffff