Browse code

Support timezones in date format.

Also use non-naive datetime objects.

Xavier G authored on11/05/2020 20:42:31
Showing2 changed files

... ...
@@ -19,7 +19,7 @@ entries:
19 19
     - application.example.com
20 20
     realm: EXAMPLE.COM
21 21
   kvno: 42
22
-  date: '2020-04-28T14:04:12Z'
22
+  date: '2020-04-28T14:04:12+0000'
23 23
   enctype: AES256_CTS_HMAC_SHA1_96
24 24
   key: 0123456789abcdeffedcba9876543210abcdeffedcba9876543210abcdef1234
25 25
 ```
... ...
@@ -41,9 +41,9 @@ yamltab offers several "data layouts" for its YAML/JSON output:
41 41
 $ yamltab -l raw -f json example.keytab | jq '.records[0].entry.timestamp'
42 42
 1588082652
43 43
 $ yamltab -l full -f json example.keytab | jq '.records[0].entry.date'
44
-"2020-04-28T14:04:12Z"
44
+"2020-04-28T14:04:12+0000"
45 45
 $ yamltab -l simple -f json example.keytab | jq '.entries[0].date'
46
-"2020-04-28T14:04:12Z"
46
+"2020-04-28T14:04:12+0000"
47 47
 ```
48 48
 
49 49
 ## YAML/JSON input, keytab output
... ...
@@ -70,7 +70,7 @@ The simple format is liable to expose two overlapping properties: `spn` and `pri
70 70
 
71 71
 `name_type_raw`, `enc_type_raw` and `timestamp` override `name_type`, `enc_type` and `date` respectively.
72 72
 
73
-Dates handling is NOT clever. Stick to the `YYYY-mm-DDTHHMMSSZ` format. That said, it is possible to  write `date: now` in simple mode.
73
+Date handling is NOT clever. Stick to the `YYYY-mm-DDTHHMMSS+ZZZZ` format. That said, it is possible to  write `date: now` in simple mode.
74 74
 
75 75
 In *simple* mode,`kvno_in_tail: True` can be used to force storage of the key version number as a 32-bit unsigned integer in the tail (i.e. after the entry). `extra_tail` can be used to inject arbitrary data in the tail.
76 76
 In *full* mode, the following keys strive to reflect kvno:
... ...
@@ -26,7 +26,7 @@ DATA_LAYOUT_FULL = 1
26 26
 DATA_LAYOUT_SIMPLE = 2
27 27
 DATA_LAYOUTS = {'raw': DATA_LAYOUT_RAW, 'full': DATA_LAYOUT_FULL, 'simple': DATA_LAYOUT_SIMPLE}
28 28
 
29
-DATE_TIME_FORMAT = '%Y-%m-%dT%H:%M:%SZ'
29
+DATE_TIME_FORMAT = '%Y-%m-%dT%H:%M:%S%z'
30 30
 
31 31
 KEYTAB_FIRST_BYTE = 0x05
32 32
 # Default prefix for struct's format strings, defining big-endian byte order:
... ...
@@ -231,7 +231,7 @@ def enrich_keytab(keytab):
231 231
 		if 'entry' not in record:
232 232
 			continue
233 233
 		entry = record['entry']
234
-		entry['date'] = datetime.utcfromtimestamp(entry['timestamp']).strftime(DATE_TIME_FORMAT)
234
+		entry['date'] = datetime.fromtimestamp(entry['timestamp'], tz=timezone.utc).strftime(DATE_TIME_FORMAT)
235 235
 		if 'name_type_raw' in entry['principal']:
236 236
 			entry['principal']['name_type'] = int_to_name_type(entry['principal']['name_type_raw'])
237 237
 		spn = principal_to_spn(entry['principal'])