Fixes #329 outdated iOS version error

This commit is contained in:
tek 2023-02-14 11:51:38 -05:00
parent 8ce6b31299
commit 95842ac449
3 changed files with 44 additions and 5 deletions

View File

@ -9,7 +9,7 @@ import plistlib
from typing import Optional
from mvt.common.module import DatabaseNotFoundError
from mvt.ios.versions import get_device_desc_from_id, latest_ios_version
from mvt.ios.versions import get_device_desc_from_id, is_ios_version_outdated
from ..base import IOSExtraction
@ -63,7 +63,4 @@ class BackupInfo(IOSExtraction):
self.results[field] = value
if "Product Version" in info:
latest = latest_ios_version()
if info["Product Version"] != latest["version"]:
self.log.warning("This phone is running an outdated iOS version: %s (latest is %s)",
info["Product Version"], latest['version'])
is_ios_version_outdated(info["Product Version"], log=self.log)

View File

@ -2,6 +2,10 @@
# Copyright (c) 2021-2023 Claudio Guarnieri.
# Use of this software is governed by the MVT License 1.1 that can be found at
# https://license.mvt.re/1.1/
from logging import Logger
from typing import Optional
import packaging
IPHONE_MODELS = [
{"identifier": "iPhone4,1", "description": "iPhone 4S"},
@ -279,3 +283,27 @@ def find_version_by_build(build: str) -> str:
def latest_ios_version() -> str:
return IPHONE_IOS_VERSIONS[-1]
def is_ios_version_outdated(version: str, log: Optional[Logger] = None) -> bool:
"""
Check if the given version is below the latest version
version can be a build number or version number
Returns true if outdated for sure, false otherwise
"""
# Check if it is a build
if "." not in version:
version = find_version_by_build(version)
# If we can't find it
if version == "":
return False
latest_parsed = packaging.version.parse(latest_ios_version()["version"])
current_parsed = packaging.version.parse(version)
if current_parsed < latest_parsed:
if log:
log.warning("This phone is running an outdated iOS version: %s (latest is %s)",
version,
latest_ios_version()["version"])
return True
return False

View File

@ -0,0 +1,14 @@
# Mobile Verification Toolkit (MVT)
# Copyright (c) 2021-2023 Claudio Guarnieri.
# Use of this software is governed by the MVT License 1.1 that can be found at
# https://license.mvt.re/1.1/
from mvt.ios.versions import is_ios_version_outdated
class TestIosVersions:
def test_is_ios_version_outdated(self):
assert is_ios_version_outdated("20B110") is True
assert is_ios_version_outdated("16.3") is True
assert is_ios_version_outdated("38.2") is False