Skip to content

Commit

Permalink
restore: activation: always put offline requests into offline_request…
Browse files Browse the repository at this point in the history
…s subdir
  • Loading branch information
doronz88 committed Aug 26, 2021
1 parent 69e098c commit fbf43fd
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
5 changes: 3 additions & 2 deletions pymobiledevice3/cli/activation.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ def state(lockdown):

@activation.command(cls=Command)
@click.option('--offline', is_flag=True, help='Allow to send and receive requests manually')
def activate(lockdown, offline):
@click.option('--now', is_flag=True, help='when --offline is used, dont wait for next nonce cycle')
def activate(lockdown, offline, now):
""" Activate device """
MobileActivationService(lockdown, offline).activate()
MobileActivationService(lockdown, offline, now).activate()


@activation.command(cls=Command)
Expand Down
2 changes: 1 addition & 1 deletion pymobiledevice3/restore/tss.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from pymobiledevice3.restore.img4 import img4_get_component_tag

TSS_CLIENT_VERSION_STRING = 'libauthinstall-776.60.1'
TICKETS_SUBDIR = Path('tickets')
TICKETS_SUBDIR = Path('offline_requests')

OFFLINE_REQUEST_SCRIPT = """#!/bin/sh
curl -d "@{request}" -H 'Cache-Control: no-cache' -H 'Content-type: text/xml; charset="utf-8"' -H 'User-Agent: InetURL/1.0' -H 'Expect: ' 'http://gs.apple.com/TSS/controller?action=2' | tee {response}
Expand Down
21 changes: 12 additions & 9 deletions pymobiledevice3/services/mobile_activation.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,18 @@
'Expect': '100-continue',
}

ACTIVATION_REQUESTS_SUBDIR = Path('activation')
ACTIVATION_REQUESTS_SUBDIR = Path('offline_requests')
NONCE_CYCLE_INTERVAL = 60 * 5


class MobileActivationService:
SERVICE_NAME = 'com.apple.mobileactivationd'

def __init__(self, lockdown: LockdownClient, offline=True):
def __init__(self, lockdown: LockdownClient, offline=True, now=False):
self.logger = logging.getLogger(__name__)
self.lockdown = lockdown
self.offline = offline
self._now = now
self._offline_start = 0
self._offline_end = 0

Expand All @@ -41,7 +42,7 @@ def state(self):
def activate(self):
blob = self.create_activation_session_info()

if self.offline:
if self.offline and not self._now:
self.logger.info('waiting for the next 5 minutes cycle')

handshake_request_message = blob['HandshakeRequestMessage']
Expand Down Expand Up @@ -123,13 +124,15 @@ def post(self, url, data, headers=None):
request.chmod(0o755)

self.logger.info(f'Run the following shell script ({request.name})')

# Check for plist response.
pb = tqdm.tqdm(total=int(self._offline_end - self._offline_start), desc='Time Left')
pb.update(int(time.time() - self._offline_start))
while not response.exists() or b'</plist>' not in response.read_bytes():
time.sleep(1)
pb.update(1)
pb.close()
if not self._now:
pb = tqdm.tqdm(total=int(self._offline_end - self._offline_start), desc='Time Left')
pb.update(int(time.time() - self._offline_start))
while not response.exists() or b'</plist>' not in response.read_bytes():
time.sleep(1)
pb.update(1)
pb.close()

# Check for headers.
while not headers.exists() or ': ' not in headers.read_text():
Expand Down

0 comments on commit fbf43fd

Please sign in to comment.