#!/usr/bin/python # import sys from glob import glob import subprocess import re import os import argparse parser = argparse.ArgumentParser(description='Reset your iCloud Keychain account') parser.add_argument('icloudpassword', help='iCloud password') parser.add_argument('passcode', help='passcode or password of the local device') args = vars(parser.parse_args()) iCloudPassword = args['icloudpassword'] passcode = args['passcode'] def set_security_mac_cmd(): return 'security2' def set_security_ios_cmd(): return 'security' def security_cmd_by_platform(): swVers = subprocess.check_output(["sw_vers"]) deviceInformation = str(swVers, 'utf-8') if "Mac OS X" in deviceInformation: print("using security2 command on macosx") return set_security_mac_cmd() elif "iPhone OS" in deviceInformation: print("using security command on ios") return set_security_ios_cmd() else: print("unsupported platform") sys.exit(1) security_cmd = security_cmd_by_platform() print("resetting octagon") subprocess.check_output(["otctl", "resetoctagon"]) print("resetting ckks") subprocess.check_output(["ckksctl", "reset-cloudkit"]) print("resetting SOS") subprocess.check_output([security_cmd, "sync", "-C"]) subprocess.check_output([security_cmd, "sync", "-P", "$iCloudPassword"]) subprocess.check_output([security_cmd, "sync", "-O"]) print("deleting all escrow records") subprocess.check_output(["stingrayutil", "--deleteAll", "ReallyDeleteAll"]) print("creating new escrow record") subprocess.check_output(["sbdtool", "passcode_request_trigger"]) subprocess.check_output(["sbdtool", "passcode_request_provide_passcode", "$passcode"])