diff options
| author | 2025-06-07 12:09:24 +0200 | |
|---|---|---|
| committer | 2025-06-07 12:09:24 +0200 | |
| commit | e3f2d6070de7125058c343ef63961c27bc991bb6 (patch) | |
| tree | 2436f76213b34ba2e06db96a990a6f0e17106e6e | |
| parent | 2e1ee28bf1d744edcf3513859a38ac5f6615b096 (diff) | |
| download | libimobiledevice-e3f2d6070de7125058c343ef63961c27bc991bb6.tar.gz libimobiledevice-e3f2d6070de7125058c343ef63961c27bc991bb6.tar.bz2 | |
Add new idevice_get_device_version() to interface
This allows getting a numerical representation of the device's
ProductVersion string for easier version range checks
| -rw-r--r-- | include/libimobiledevice/libimobiledevice.h | 17 | ||||
| -rw-r--r-- | src/idevice.c | 16 | ||||
| -rw-r--r-- | src/idevice.h | 2 | ||||
| -rw-r--r-- | src/lockdown-cu.c | 4 | ||||
| -rw-r--r-- | src/lockdown.c | 4 | 
5 files changed, 36 insertions, 7 deletions
| diff --git a/include/libimobiledevice/libimobiledevice.h b/include/libimobiledevice/libimobiledevice.h index 8df3fed..bc57778 100644 --- a/include/libimobiledevice/libimobiledevice.h +++ b/include/libimobiledevice/libimobiledevice.h | |||
| @@ -404,6 +404,19 @@ LIBIMOBILEDEVICE_API idevice_error_t idevice_get_handle(idevice_t device, uint32 | |||
| 404 | LIBIMOBILEDEVICE_API idevice_error_t idevice_get_udid(idevice_t device, char **udid); | 404 | LIBIMOBILEDEVICE_API idevice_error_t idevice_get_udid(idevice_t device, char **udid); | 
| 405 | 405 | ||
| 406 | /** | 406 | /** | 
| 407 | * Returns the device ProductVersion in numerical form, where "X.Y.Z" | ||
| 408 | * will be returned as (X << 16) | (Y << 8) | Z . | ||
| 409 | * Use IDEVICE_DEVICE_VERSION macro for easy version comparison. | ||
| 410 | * @see IDEVICE_DEVICE_VERSION | ||
| 411 | * | ||
| 412 | * @param client Initialized device client | ||
| 413 | * | ||
| 414 | * @return A numerical representation of the X.Y.Z ProductVersion string | ||
| 415 | * or 0 if the version cannot be retrieved. | ||
| 416 | */ | ||
| 417 | LIBIMOBILEDEVICE_API unsigned int idevice_get_device_version(idevice_t device); | ||
| 418 | |||
| 419 | /** | ||
| 407 | * Gets a readable error string for a given idevice error code. | 420 | * Gets a readable error string for a given idevice error code. | 
| 408 | * | 421 | * | 
| 409 | * @param err An idevice error code | 422 | * @param err An idevice error code | 
| @@ -419,6 +432,10 @@ LIBIMOBILEDEVICE_API const char* idevice_strerror(idevice_error_t err); | |||
| 419 | */ | 432 | */ | 
| 420 | LIBIMOBILEDEVICE_API const char* libimobiledevice_version(); | 433 | LIBIMOBILEDEVICE_API const char* libimobiledevice_version(); | 
| 421 | 434 | ||
| 435 | /* macros */ | ||
| 436 | /** Helper macro to get a numerical representation of a product version tuple */ | ||
| 437 | #define IDEVICE_DEVICE_VERSION(maj, min, patch) ((((maj) & 0xFF) << 16) | (((min) & 0xFF) << 8) | ((patch) & 0xFF)) | ||
| 438 | |||
| 422 | #ifdef __cplusplus | 439 | #ifdef __cplusplus | 
| 423 | } | 440 | } | 
| 424 | #endif | 441 | #endif | 
| diff --git a/src/idevice.c b/src/idevice.c index e9c909f..1cdfef2 100644 --- a/src/idevice.c +++ b/src/idevice.c | |||
| @@ -946,6 +946,20 @@ idevice_error_t idevice_get_udid(idevice_t device, char **udid) | |||
| 946 | return IDEVICE_E_SUCCESS; | 946 | return IDEVICE_E_SUCCESS; | 
| 947 | } | 947 | } | 
| 948 | 948 | ||
| 949 | unsigned int idevice_get_device_version(idevice_t device) | ||
| 950 | { | ||
| 951 | if (!device) { | ||
| 952 | return 0; | ||
| 953 | } | ||
| 954 | if (!device->version) { | ||
| 955 | lockdownd_client_t lockdown = NULL; | ||
| 956 | lockdownd_client_new(device, &lockdown, NULL); | ||
| 957 | // we don't handle any errors here. We should have the product version cached now. | ||
| 958 | lockdownd_client_free(lockdown); | ||
| 959 | } | ||
| 960 | return device->version; | ||
| 961 | } | ||
| 962 | |||
| 949 | #if defined(HAVE_OPENSSL) || defined(HAVE_GNUTLS) | 963 | #if defined(HAVE_OPENSSL) || defined(HAVE_GNUTLS) | 
| 950 | typedef ssize_t ssl_cb_ret_type_t; | 964 | typedef ssize_t ssl_cb_ret_type_t; | 
| 951 | #elif defined(HAVE_MBEDTLS) | 965 | #elif defined(HAVE_MBEDTLS) | 
| @@ -1229,7 +1243,7 @@ idevice_error_t idevice_connection_enable_ssl(idevice_connection_t connection) | |||
| 1229 | #if OPENSSL_VERSION_NUMBER < 0x10100002L || \ | 1243 | #if OPENSSL_VERSION_NUMBER < 0x10100002L || \ | 
| 1230 | (defined(LIBRESSL_VERSION_NUMBER) && (LIBRESSL_VERSION_NUMBER < 0x2060000fL)) | 1244 | (defined(LIBRESSL_VERSION_NUMBER) && (LIBRESSL_VERSION_NUMBER < 0x2060000fL)) | 
| 1231 | /* force use of TLSv1 for older devices */ | 1245 | /* force use of TLSv1 for older devices */ | 
| 1232 | if (connection->device->version < DEVICE_VERSION(10,0,0)) { | 1246 | if (connection->device->version < IDEVICE_DEVICE_VERSION(10,0,0)) { | 
| 1233 | #ifdef SSL_OP_NO_TLSv1_1 | 1247 | #ifdef SSL_OP_NO_TLSv1_1 | 
| 1234 | SSL_CTX_set_options(ssl_ctx, SSL_OP_NO_TLSv1_1); | 1248 | SSL_CTX_set_options(ssl_ctx, SSL_OP_NO_TLSv1_1); | 
| 1235 | #endif | 1249 | #endif | 
| diff --git a/src/idevice.h b/src/idevice.h index dd72f9d..e05338e 100644 --- a/src/idevice.h +++ b/src/idevice.h | |||
| @@ -52,8 +52,6 @@ | |||
| 52 | #include "common/userpref.h" | 52 | #include "common/userpref.h" | 
| 53 | #include "libimobiledevice/libimobiledevice.h" | 53 | #include "libimobiledevice/libimobiledevice.h" | 
| 54 | 54 | ||
| 55 | #define DEVICE_VERSION(maj, min, patch) (((maj & 0xFF) << 16) | ((min & 0xFF) << 8) | (patch & 0xFF)) | ||
| 56 | |||
| 57 | #define DEVICE_CLASS_IPHONE 1 | 55 | #define DEVICE_CLASS_IPHONE 1 | 
| 58 | #define DEVICE_CLASS_IPAD 2 | 56 | #define DEVICE_CLASS_IPAD 2 | 
| 59 | #define DEVICE_CLASS_IPOD 3 | 57 | #define DEVICE_CLASS_IPOD 3 | 
| diff --git a/src/lockdown-cu.c b/src/lockdown-cu.c index 9fbd2c8..30eec99 100644 --- a/src/lockdown-cu.c +++ b/src/lockdown-cu.c | |||
| @@ -509,7 +509,7 @@ lockdownd_error_t lockdownd_cu_pairing_create(lockdownd_client_t client, lockdow | |||
| 509 | char *s_version = NULL; | 509 | char *s_version = NULL; | 
| 510 | plist_get_string_val(p_version, &s_version); | 510 | plist_get_string_val(p_version, &s_version); | 
| 511 | if (s_version && sscanf(s_version, "%d.%d.%d", &vers[0], &vers[1], &vers[2]) >= 2) { | 511 | if (s_version && sscanf(s_version, "%d.%d.%d", &vers[0], &vers[1], &vers[2]) >= 2) { | 
| 512 | client->device->version = DEVICE_VERSION(vers[0], vers[1], vers[2]); | 512 | client->device->version = IDEVICE_DEVICE_VERSION(vers[0], vers[1], vers[2]); | 
| 513 | } | 513 | } | 
| 514 | free(s_version); | 514 | free(s_version); | 
| 515 | } | 515 | } | 
| @@ -962,7 +962,7 @@ lockdownd_error_t lockdownd_cu_send_request_and_get_reply(lockdownd_client_t cli | |||
| 962 | 962 | ||
| 963 | // Starting with iOS/tvOS 11.2 and WatchOS 4.2, this nonce is random and sent along with the request. Before, the request doesn't have a nonce and it uses hardcoded nonce "sendone01234". | 963 | // Starting with iOS/tvOS 11.2 and WatchOS 4.2, this nonce is random and sent along with the request. Before, the request doesn't have a nonce and it uses hardcoded nonce "sendone01234". | 
| 964 | unsigned char cu_nonce[12] = "sendone01234"; // guaranteed to be random by fair dice troll | 964 | unsigned char cu_nonce[12] = "sendone01234"; // guaranteed to be random by fair dice troll | 
| 965 | if (client->device->version >= DEVICE_VERSION(11,2,0)) { | 965 | if (client->device->version >= IDEVICE_DEVICE_VERSION(11,2,0)) { | 
| 966 | #if defined(HAVE_OPENSSL) | 966 | #if defined(HAVE_OPENSSL) | 
| 967 | RAND_bytes(cu_nonce, sizeof(cu_nonce)); | 967 | RAND_bytes(cu_nonce, sizeof(cu_nonce)); | 
| 968 | #elif defined(HAVE_GCRYPT) | 968 | #elif defined(HAVE_GCRYPT) | 
| diff --git a/src/lockdown.c b/src/lockdown.c index 411136c..a1ad67b 100644 --- a/src/lockdown.c +++ b/src/lockdown.c | |||
| @@ -659,7 +659,7 @@ lockdownd_error_t lockdownd_client_new(idevice_t device, lockdownd_client_t *cli | |||
| 659 | char *s_version = NULL; | 659 | char *s_version = NULL; | 
| 660 | plist_get_string_val(p_version, &s_version); | 660 | plist_get_string_val(p_version, &s_version); | 
| 661 | if (s_version && sscanf(s_version, "%d.%d.%d", &vers[0], &vers[1], &vers[2]) >= 2) { | 661 | if (s_version && sscanf(s_version, "%d.%d.%d", &vers[0], &vers[1], &vers[2]) >= 2) { | 
| 662 | device->version = DEVICE_VERSION(vers[0], vers[1], vers[2]); | 662 | device->version = IDEVICE_DEVICE_VERSION(vers[0], vers[1], vers[2]); | 
| 663 | } | 663 | } | 
| 664 | free(s_version); | 664 | free(s_version); | 
| 665 | } | 665 | } | 
| @@ -733,7 +733,7 @@ lockdownd_error_t lockdownd_client_new_with_handshake(idevice_t device, lockdown | |||
| 733 | plist_free(pair_record); | 733 | plist_free(pair_record); | 
| 734 | pair_record = NULL; | 734 | pair_record = NULL; | 
| 735 | 735 | ||
| 736 | if (device->version < DEVICE_VERSION(7,0,0) && device->device_class != DEVICE_CLASS_WATCH) { | 736 | if (device->version < IDEVICE_DEVICE_VERSION(7,0,0) && device->device_class != DEVICE_CLASS_WATCH) { | 
| 737 | /* for older devices, we need to validate pairing to receive trusted host status */ | 737 | /* for older devices, we need to validate pairing to receive trusted host status */ | 
| 738 | ret = lockdownd_validate_pair(client_loc, NULL); | 738 | ret = lockdownd_validate_pair(client_loc, NULL); | 
| 739 | 739 | ||
