]> git.saurik.com Git - apple/security.git/blob - keychain/ResetCloudKeychainAccount/reset_ick_account
Security-59754.80.3.tar.gz
[apple/security.git] / keychain / ResetCloudKeychainAccount / reset_ick_account
1 #!/usr/local/bin/python3
2
3 import sys
4 from glob import glob
5 import subprocess
6 import re
7 import os
8 import argparse
9
10 parser = argparse.ArgumentParser(description='Reset your iCloud Keychain account')
11 parser.add_argument('icloudpassword', help='iCloud password')
12 parser.add_argument('passcode', help='passcode or password of the local device')
13 args = vars(parser.parse_args())
14
15
16 iCloudPassword = args['icloudpassword']
17 passcode = args['passcode']
18
19 def set_security_mac_cmd():
20 return 'security2'
21
22 def set_security_ios_cmd():
23 return 'security'
24
25 def security_cmd_by_platform():
26 swVers = subprocess.check_output(["sw_vers"])
27 deviceInformation = swVers.decode('utf-8')
28 if "Mac OS X" in deviceInformation or "macOS" in deviceInformation:
29 print("using security2 command on macos")
30 return set_security_mac_cmd()
31 elif "iPhone OS" in deviceInformation:
32 print("using security command on ios")
33 return set_security_ios_cmd()
34 else:
35 print("unsupported platform")
36 sys.exit(1)
37
38 security_cmd = security_cmd_by_platform()
39
40 print("deleting all escrow records")
41 subprocess.check_output(["stingrayutil", "--deleteAll", "ReallyDeleteAll"])
42
43 print("resetting SOS")
44 subprocess.check_output([security_cmd, "sync", "-C"])
45 subprocess.check_output([security_cmd, "sync", "-P", "$iCloudPassword"])
46 subprocess.check_output([security_cmd, "sync", "-O"])
47
48 print("resetting octagon")
49 subprocess.check_output(["otctl", "resetoctagon"])
50
51 print("creating new escrow record")
52 subprocess.check_output(["sbdtool", "passcode_request_trigger"])
53 subprocess.check_output(["sbdtool", "passcode_request_provide_passcode", "$passcode"])
54