libimobiledevice / libideviceactivation

A library to handle the activation process of iOS devices
https://libimobiledevice.org
GNU Lesser General Public License v2.1
276 stars 129 forks source link

Unable to active device on iOS 11.2 #29

Closed truonggiang0710 closed 6 years ago

truonggiang0710 commented 6 years ago

Hello @nikias ,

Lib cannot activate device on iOS 11.2. Please help me resolve it ? Here's log log.txt

nikias commented 6 years ago

It breaks down to the following error message:

ERROR: HandleActivationInfoWithSessionRequest: Request contains invalid key: ARS ({
    FunctionName = "init_lockdown_server_block_invoke";
    NSLocalizedDescription = "Request contains invalid key: ARS";
    SourceLine = 197;
})

I need to understand what the actual problem here is.

truonggiang0710 commented 6 years ago

Do you need more detail information or more time to investigate this issue ?

nikias commented 6 years ago

I could figure out what's missing and am working on a solution.

nicolassan commented 6 years ago

Yes, same problem for US, tested with iphone 5s, DFU is Ok but fail on activation.

Do you need more datas ?

truonggiang0710 commented 6 years ago

Hi @nikias ,

Any update, please ?

Thanks a lot !

nikias commented 6 years ago

Please try this patch for libimobiledevice: https://gist.github.com/nikias/679b0ae23dcd671d3cea556eb1e7928b and this one for libideviceactivation: https://gist.github.com/nikias/a8f82602453a5ff0554af61118072ba1

truonggiang0710 commented 6 years ago

I try but it's still unsuccessful. Here log log2.txt

daniel-bluesea commented 6 years ago

same as @truonggiang0710

"Failed to activate device with record."

i printed out the result plist for the mobileactivation_send_command_plist call:

<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">

Error Failed to activate device. ({ FunctionName = "init_lockdown_server_block_invoke_2"; NSLocalizedDescription = "Failed to activate device."; NSUnderlyingError = "Error Domain=com.apple.MobileActivation.ErrorDomain Code=-2 \"Invalid activation signature.\" UserInfo={NSUnderlyingError=0x100c260c0 {Error Domain=com.apple.MobileActivation.ErrorDomain Code=-3 \"Failed to verify message signature (2c3PEJbh9Tuh7P/zxVPc2A==): -42022\" UserInfo={SourceLine=444, NSLocalizedDescription=Failed to verify message signature (2c3PEJbh9Tuh7P/zxVPc2A==): -42022, FunctionName=-[MobileActivationDaemon validateActivationDataSignature:activationSignature:withError:]_block_invoke}}, SourceLine=1273, FunctionName=-[MobileActivationDaemon handleActivationInfoWithSession:activationSignature:completionBlock:], NSLocalizedDescription=Invalid activation signature.}"; SourceLine = 210; })

Failed to activate device with record.

nikias commented 6 years ago

Hmm... So the device gets the actual signature (the ARS it complained about before) but something seems still wrong. I will check again. Also @truonggiang0710 you didn't compile libimobiledevice with --enable-debug-code :)

nikias commented 6 years ago

I think it has todo on how we pass the activation data to the device. It is parsed from xml to plist format in libideviceactivation and then back to xml (and again to plist data) in libimobiledevice so my guess is that this will make the data not match with the signature.

Follow up patch for libimobiledevice:

diff --git a/src/mobileactivation.c b/src/mobileactivation.c
index 7ae35bb..a5a9841 100644
--- a/src/mobileactivation.c
+++ b/src/mobileactivation.c
@@ -91,6 +91,9 @@ LIBIMOBILEDEVICE_API mobileactivation_error_t mobileactivation_client_free(mobil

 static plist_t plist_data_from_plist(plist_t plist)
 {
+       if (plist && plist_get_node_type(plist) == PLIST_DATA) {
+               return plist_copy(plist);
+       }
        plist_t result = NULL;
        char *xml = NULL;
        uint32_t xml_len = 0;

and for libideviceactivation:

diff --git a/src/activation.c b/src/activation.c
index 0a56dc7..6105071 100644
--- a/src/activation.c
+++ b/src/activation.c
@@ -170,7 +171,7 @@ static idevice_activation_error_t idevice_activation_activation_record_from_plis
                                response->is_activation_ack = 1;
                        }
                }
-               response->activation_record = plist_copy(plist);
+               response->activation_record = plist_new_data(response->raw_content, response->raw_content_size);
        } else {
                plist_t activation_node = plist_dict_get_item(plist, "iphone-activation");
                if (!activation_node) {
nicolassan commented 6 years ago

ok, it's working with the 2 patches !

Ok to activate with iPhone 5s and IOS 11.2

I'm testing the other exe (recovery, info, DFU etc..)

nikias commented 6 years ago

Awesome. Will rework the patches a bit and push to master

nicolassan commented 6 years ago

We test all executables (deviceInfo, recovery, activation) all is ok for me, many thanks @nikias

truonggiang0710 commented 6 years ago

I test with iPhone 6, iPhone 7, iPhone 8 and iPhone X (iOS 11.2), all is ok for me, thanks @nikias

xdeng commented 6 years ago

The content returned by the request can not be changed ARS from http request header

xdeng commented 6 years ago

Don't use plist_from_xml

nikias commented 6 years ago

Changes are now it git with latest commits: libimobiledevice: https://github.com/libimobiledevice/libimobiledevice/commit/b7feed9f5a62833c1df3f503fd3693e2ed2e4738 libideviceactivation: https://github.com/libimobiledevice/libideviceactivation/commit/8b2e1679a8ce64a88640cb6722c2d00ad4b14d2e