Skip to content

Commit 15f9d31

Browse files
authored
Merge pull request #181 from EC-DIGIT-CSIRC/sysdiagnose_date
chg: [init] sysdiagnose date in UTC, not local time.
2 parents de2921b + 34ece52 commit 15f9d31

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

src/sysdiagnose/__init__.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import os
77
import re
88
import tarfile
9+
from datetime import timezone
910
from sysdiagnose.utils.base import BaseInterface, BaseParserInterface, BaseAnalyserInterface, SysdiagnoseConfig
1011
from sysdiagnose.utils.logger import set_json_logging, logger
1112
from io import TextIOWrapper
@@ -178,13 +179,14 @@ def create_case(self, sysdiagnose_file: str, force: bool = False, case_id: bool
178179
return case
179180

180181
@staticmethod
181-
def get_case_metadata(source_file: str) -> str:
182+
def get_case_metadata(source_file: str) -> dict | None:
182183
"""
183-
Returns the sha256 hash of the sysdiagnose source file/folder.
184-
The hash is calculated by concatenating the contents of the case metadata: udid, serial, ios version and date.
184+
Returns the metadata related to the given sysdiagnose file/folder.
185+
This includes serial number, unique device ID, iOS version, model, date of sysdiagnose creation,
186+
and a case ID based on the serial number and date.
185187
186188
:param source_file: Path to the sysdiagnose file/folder
187-
:return: sha256 hash of the file/folder
189+
:return: dictionary with metadata or None if the file is invalid
188190
"""
189191
from sysdiagnose.parsers.remotectl_dumpstate import RemotectlDumpstateParser
190192
from sysdiagnose.parsers.sys import SystemVersionParser
@@ -239,7 +241,8 @@ def get_case_metadata(source_file: str) -> str:
239241
return None
240242

241243
# Time to obtain the metadata
242-
244+
# Turn the sysdiagnose date into UTC
245+
sysdiagnose_date_utc = sysdiagnose_date.astimezone(timezone.utc)
243246
if remotectl_dumpstate_json and 'error' not in remotectl_dumpstate_json:
244247
if 'Local device' in remotectl_dumpstate_json:
245248
try:
@@ -249,8 +252,8 @@ def get_case_metadata(source_file: str) -> str:
249252
'unique_device_id': remotectl_dumpstate_json['Local device']['Properties']['UniqueDeviceID'],
250253
'ios_version': remotectl_dumpstate_json['Local device']['Properties']['OSVersion'],
251254
'model': remotectl_dumpstate_json['Local device']['Properties']['ProductType'],
252-
'date': sysdiagnose_date.isoformat(timespec='microseconds'),
253-
'case_id': f"{serial_number}_{sysdiagnose_date.strftime('%Y%m%d_%H%M%S')}",
255+
'date': sysdiagnose_date_utc.isoformat(timespec='microseconds'),
256+
'case_id': f"{serial_number}_{sysdiagnose_date_utc.strftime('%Y%m%d_%H%M%S')}",
254257
'source_file': source_file,
255258
'source_sha256': ''
256259
}
@@ -270,8 +273,8 @@ def get_case_metadata(source_file: str) -> str:
270273
'unique_device_id': 'unknown',
271274
'ios_version': sys_json['ProductVersion'],
272275
'model': 'unknown', # FIXME figure out a way to get the model from sysdiagnose
273-
'date': sysdiagnose_date.isoformat(timespec='microseconds'),
274-
'case_id': f"{serial_number}_{sysdiagnose_date.strftime('%Y%m%d_%H%M%S')}",
276+
'date': sysdiagnose_date_utc.isoformat(timespec='microseconds'),
277+
'case_id': f"{serial_number}_{sysdiagnose_date_utc.strftime('%Y%m%d_%H%M%S')}",
275278
'source_file': source_file,
276279
'source_sha256': ''
277280
}

tests/test_sysdiagnose.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,16 @@ def test_case_metadata_remotectl(self):
8989
'unique_device_id': 'e22f7f830e5dcc1287a1690a2622c2b12afaa33c',
9090
'ios_version': '15.7.6',
9191
'model': 'iPhone9,3',
92-
'date': '2023-05-24T13:29:15.000000-07:00',
93-
'case_id': 'F4GT2K24HG7K_20230524_132915',
92+
'date': '2023-05-24T20:29:15.000000+00:00',
93+
'case_id': 'F4GT2K24HG7K_20230524_202915',
9494
'source_file': 'tests/testdata/iOS15/sysdiagnose_2023.05.24_13-29-15-0700_iPhone-OS_iPhone_19H349.tar.gz',
95-
'source_sha256': '78054acba2a27820c2b7a360b512754d05cc831c5427191f47798ec1d1dd5add',
95+
'source_sha256': '870dc007c0ee7b04960e6e88c1d25c11461b0f1f5fba0914a1d2a7947045dbf2',
9696
}
9797
metadata = Sysdiagnose.get_case_metadata('tests/testdata/iOS15/sysdiagnose_2023.05.24_13-29-15-0700_iPhone-OS_iPhone_19H349.tar.gz')
9898
self.assertEqual(metadata, expected_metadata)
9999

100100
# check signature
101-
expected_hash = '78054acba2a27820c2b7a360b512754d05cc831c5427191f47798ec1d1dd5add'
101+
expected_hash = '870dc007c0ee7b04960e6e88c1d25c11461b0f1f5fba0914a1d2a7947045dbf2'
102102
hash = Sysdiagnose.calculate_metadata_signature(metadata)
103103
self.assertEqual(hash, expected_hash)
104104

0 commit comments

Comments
 (0)