summaryrefslogtreecommitdiffstats
path: root/src/lockdown-cu.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lockdown-cu.c')
-rw-r--r--src/lockdown-cu.c35
1 files changed, 20 insertions, 15 deletions
diff --git a/src/lockdown-cu.c b/src/lockdown-cu.c
index cdaf02c..c457cb2 100644
--- a/src/lockdown-cu.c
+++ b/src/lockdown-cu.c
@@ -29,7 +29,11 @@
#define __USE_GNU 1
#include <stdio.h>
#include <ctype.h>
+
+#ifndef _MSC_VER
#include <unistd.h>
+#endif
+
#include <plist/plist.h>
#include "idevice.h"
@@ -62,6 +66,7 @@
#include <sys/sysctl.h>
#include <SystemConfiguration/SystemConfiguration.h>
#include <CoreFoundation/CoreFoundation.h>
+#include <TargetConditionals.h>
#endif
#include "property_list_service.h"
@@ -293,7 +298,7 @@ poly1305_update_with_pad16(poly1305_state *poly1305,
static void chacha20_poly1305_encrypt_96(unsigned char* key, unsigned char* nonce, unsigned char* ad, size_t ad_len, unsigned char* in, size_t in_len, unsigned char* out, size_t* out_len)
{
#if defined(HAVE_OPENSSL)
-#if defined(LIBRESSL_VERSION_NUMBER)
+#if defined(LIBRESSL_VERSION_NUMBER) && (LIBRESSL_VERSION_NUMBER < 0x3050000fL)
#if (LIBRESSL_VERSION_NUMBER >= 0x2040000fL)
const EVP_AEAD *aead = EVP_aead_chacha20_poly1305();
EVP_AEAD_CTX ctx;
@@ -377,7 +382,7 @@ static void chacha20_poly1305_encrypt_64(unsigned char* key, unsigned char* nonc
static void chacha20_poly1305_decrypt_96(unsigned char* key, unsigned char* nonce, unsigned char* ad, size_t ad_len, unsigned char* in, size_t in_len, unsigned char* out, size_t* out_len)
{
#if defined(HAVE_OPENSSL)
-#if defined(LIBRESSL_VERSION_NUMBER)
+#if defined(LIBRESSL_VERSION_NUMBER) && (LIBRESSL_VERSION_NUMBER < 0x3050000fL)
#if (LIBRESSL_VERSION_NUMBER >= 0x2040000fL)
const EVP_AEAD *aead = EVP_aead_chacha20_poly1305();
EVP_AEAD_CTX ctx;
@@ -489,7 +494,7 @@ static void chacha20_poly1305_decrypt_64(unsigned char* key, unsigned char* nonc
#endif /* HAVE_WIRELESS_PAIRING */
-LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_cu_pairing_create(lockdownd_client_t client, lockdownd_cu_pairing_cb_t pairing_callback, void* cb_user_data, plist_t host_info, plist_t acl)
+lockdownd_error_t lockdownd_cu_pairing_create(lockdownd_client_t client, lockdownd_cu_pairing_cb_t pairing_callback, void* cb_user_data, plist_t host_info, plist_t acl)
{
#ifdef HAVE_WIRELESS_PAIRING
if (!client || !pairing_callback || (host_info && plist_get_node_type(host_info) != PLIST_DICT) || (acl && plist_get_node_type(acl) != PLIST_DICT))
@@ -504,7 +509,7 @@ LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_cu_pairing_create(lockdownd_cli
char *s_version = NULL;
plist_get_string_val(p_version, &s_version);
if (s_version && sscanf(s_version, "%d.%d.%d", &vers[0], &vers[1], &vers[2]) >= 2) {
- client->device->version = DEVICE_VERSION(vers[0], vers[1], vers[2]);
+ client->device->version = IDEVICE_DEVICE_VERSION(vers[0], vers[1], vers[2]);
}
free(s_version);
}
@@ -647,12 +652,12 @@ LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_cu_pairing_create(lockdownd_cli
/* HOST INFORMATION */
char hostname[256];
-#ifdef __APPLE__
+#if defined(__APPLE__) && !defined(TARGET_OS_IPHONE)
CFStringRef cname = SCDynamicStoreCopyComputerName(NULL, NULL);
CFStringGetCString(cname, hostname, sizeof(hostname), kCFStringEncodingUTF8);
CFRelease(cname);
#else
-#ifdef WIN32
+#ifdef _WIN32
DWORD hostname_len = sizeof(hostname);
GetComputerName(hostname, &hostname_len);
#else
@@ -931,7 +936,7 @@ debug_buffer(data, data_len);
#endif
}
-LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_cu_send_request_and_get_reply(lockdownd_client_t client, const char* request, plist_t request_payload, plist_t* reply)
+lockdownd_error_t lockdownd_cu_send_request_and_get_reply(lockdownd_client_t client, const char* request, plist_t request_payload, plist_t* reply)
{
#ifdef HAVE_WIRELESS_PAIRING
if (!client || !request)
@@ -956,12 +961,12 @@ LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_cu_send_request_and_get_reply(l
hkdf_md(MD_ALGO_SHA512, (unsigned char*)READ_KEY_SALT_MDLD, sizeof(READ_KEY_SALT_MDLD)-1, (unsigned char*)READ_KEY_INFO_MDLD, sizeof(READ_KEY_INFO_MDLD)-1, client->cu_key, client->cu_key_len, cu_read_key, &cu_read_key_len);
// 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".
- unsigned char cu_nonce[12] = "sendone01234"; // guaranteed to be random by fair dice troll
- if (client->device->version >= DEVICE_VERSION(11,2,0)) {
+ unsigned char cu_nonce[] = "sendone01234"; // guaranteed to be random by fair dice troll
+ if (client->device->version >= IDEVICE_DEVICE_VERSION(11,2,0)) {
#if defined(HAVE_OPENSSL)
- RAND_bytes(cu_nonce, sizeof(cu_nonce));
+ RAND_bytes(cu_nonce, sizeof(cu_nonce)-1);
#elif defined(HAVE_GCRYPT)
- gcry_create_nonce(cu_nonce, sizeof(cu_nonce));
+ gcry_create_nonce(cu_nonce, sizeof(cu_nonce)-1);
#endif
}
@@ -1031,7 +1036,7 @@ LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_cu_send_request_and_get_reply(l
plist_free(dict);
dict = NULL;
- plist_from_memory((const char*)decrypted, decrypted_len, &dict);
+ plist_from_memory((const char*)decrypted, decrypted_len, &dict, NULL);
if (!dict) {
ret = LOCKDOWN_E_PLIST_ERROR;
debug_info("Failed to parse PLIST from decrypted payload:");
@@ -1056,7 +1061,7 @@ LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_cu_send_request_and_get_reply(l
#endif
}
-LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_get_value_cu(lockdownd_client_t client, const char* domain, const char* key, plist_t* value)
+lockdownd_error_t lockdownd_get_value_cu(lockdownd_client_t client, const char* domain, const char* key, plist_t* value)
{
#ifdef HAVE_WIRELESS_PAIRING
if (!client)
@@ -1096,7 +1101,7 @@ LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_get_value_cu(lockdownd_client_t
#endif
}
-LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_pair_cu(lockdownd_client_t client)
+lockdownd_error_t lockdownd_pair_cu(lockdownd_client_t client)
{
#ifdef HAVE_WIRELESS_PAIRING
if (!client)
@@ -1127,7 +1132,7 @@ LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_pair_cu(lockdownd_client_t clie
plist_free(pubkey);
plist_t pair_record_plist = plist_new_dict();
- pair_record_generate_keys_and_certs(pair_record_plist, public_key);
+ pair_record_generate_keys_and_certs(pair_record_plist, public_key, client->device->version);
char* host_id = NULL;
char* system_buid = NULL;