def pair(self): self.DevicePublicKey = self.getValue("", "DevicePublicKey") if self.DevicePublicKey == '': return print "Got device public key" print "Creating host key & certificate" certPem, privateKeyPem, DeviceCertificate = ca_do_everything(self.DevicePublicKey) pair_record = {"DevicePublicKey": plistlib.Data(self.DevicePublicKey), "DeviceCertificate": plistlib.Data(DeviceCertificate), "HostCertificate": plistlib.Data(certPem), "HostID": self.hostID, "RootCertificate": plistlib.Data(certPem), "SystemBUID": "30142955-444094379208051516" } Pair = {"Request": "Pair", "PairRecord": pair_record} self.c.sendPlist(Pair) Pair = self.c.recvPlist() if Pair and Pair.get("Result") == "Success" or Pair.has_key("EscrowBag"): #print "Pairing OK" pair_record["HostPrivateKey"] = plistlib.Data(privateKeyPem) if Pair.has_key("EscrowBag"): pair_record["EscrowBag"] = Pair["EscrowBag"] writeHomeFile(HOMEFOLDER, "%s.plist" % self.identifier, plistlib.writePlistToString(pair_record)) return True print "Pairing error", Pair return False
def pair(self): print "Creating host key & certificate" hostCertificate, hostPrivateKey, deviceCertificate = generateCertificates(self.devicePublicKey) pair_record = {'DevicePublicKey': plistlib.Data(self.devicePublicKey), 'DeviceCertificate': plistlib.Data(deviceCertificate), 'HostCertificate': plistlib.Data(hostCertificate), 'HostPrivateKey': plistlib.Data(hostPrivateKey), 'HostID': self.hostID, 'RootCertificate': plistlib.Data(hostCertificate), 'SystemBUID': '30142955-444094379208051516'} Pair = self.service.sendRequest({ 'Request': 'Pair', 'PairRecord': pair_record }) if self.osVersion[0] == '7' and Pair.get('Error') == 'PasswordProtected': raise NotTrustedError if Pair and Pair.get('Result') == 'Success' or 'EscrowBag' in Pair: if 'EscrowBag' in Pair: pair_record['EscrowBag'] = Pair['EscrowBag'] writeHomeFile(HOMEFOLDER, '%s.plist' % self.udid, plistlib.writePlistToString(pair_record)) else: raise PairingError
def pair(self): print "Creating host key & certificate" hostCertificate, hostPrivateKey, deviceCertificate = generateCertificates( self.devicePublicKey) pair_record = { 'DevicePublicKey': plistlib.Data(self.devicePublicKey), 'DeviceCertificate': plistlib.Data(deviceCertificate), 'HostCertificate': plistlib.Data(hostCertificate), 'HostPrivateKey': plistlib.Data(hostPrivateKey), 'HostID': self.hostID, 'RootCertificate': plistlib.Data(hostCertificate), 'SystemBUID': '30142955-444094379208051516' } Pair = self.service.sendRequest({ 'Request': 'Pair', 'PairRecord': pair_record }) if self.osVersion[0] == '7' and Pair.get( 'Error') == 'PasswordProtected': raise NotTrustedError if Pair and Pair.get('Result') == 'Success' or 'EscrowBag' in Pair: if 'EscrowBag' in Pair: pair_record['EscrowBag'] = Pair['EscrowBag'] writeHomeFile(HOMEFOLDER, '%s.plist' % self.udid, plistlib.writePlistToString(pair_record)) else: raise PairingError
def pair(self): self.DevicePublicKey = self.getValue("", "DevicePublicKey") if self.DevicePublicKey == '': return print "Got device public key" print "Creating host key & certificate" certPem, privateKeyPem, DeviceCertificate = ca_do_everything( self.DevicePublicKey) pair_record = { "DevicePublicKey": plistlib.Data(self.DevicePublicKey), "DeviceCertificate": plistlib.Data(DeviceCertificate), "HostCertificate": plistlib.Data(certPem), "HostID": self.hostID, "RootCertificate": plistlib.Data(certPem), "SystemBUID": "30142955-444094379208051516" } Pair = {"Request": "Pair", "PairRecord": pair_record} self.c.sendPlist(Pair) Pair = self.c.recvPlist() if Pair and Pair.get("Result") == "Success" or Pair.has_key( "EscrowBag"): #print "Pairing OK" pair_record["HostPrivateKey"] = plistlib.Data(privateKeyPem) if Pair.has_key("EscrowBag"): pair_record["EscrowBag"] = Pair["EscrowBag"] writeHomeFile(HOMEFOLDER, "%s.plist" % self.identifier, plistlib.writePlistToString(pair_record)) return True print "Pairing error", Pair return False
def validate_pairing(self): record = readHomeFile(HOMEFOLDER, '%s.plist' % self.udid) if record: pair_record = plistlib.readPlistFromString(record) hostCertificate = pair_record['HostCertificate'].data hostPrivateKey = pair_record['HostPrivateKey'].data print "Found pairing record for device %s" % self.udid else: print "No pairing record found for device %s" % self.udid return False ValidatePair = self.service.sendRequest({ 'Request': 'ValidatePair', 'PairRecord': pair_record }) if not ValidatePair or 'Error' in ValidatePair: pair_record = None return False StartSession = self.service.sendRequest({ 'Request': 'StartSession', 'HostID': pair_record.get('HostID', self.hostID) }) self.SessionID = StartSession.get('SessionID') if StartSession.get('EnableSessionSSL'): keyfile = writeHomeFile(HOMEFOLDER, self.udid + "_ssl.txt", hostCertificate + '\n' + hostPrivateKey) self.service.start_ssl(keyfile) self.allValues = self.getValue() # iDevice gives more information after being trusted return True
def validate_pairing(self): record = readHomeFile(HOMEFOLDER, '%s.plist' % self.udid) if record: pair_record = plistlib.readPlistFromString(record) hostCertificate = pair_record['HostCertificate'].data hostPrivateKey = pair_record['HostPrivateKey'].data print "Found pairing record for device %s" % self.udid else: print "No pairing record found for device %s" % self.udid return False ValidatePair = self.service.sendRequest({ 'Request': 'ValidatePair', 'PairRecord': pair_record }) if not ValidatePair or 'Error' in ValidatePair: pair_record = None return False StartSession = self.service.sendRequest({ 'Request': 'StartSession', 'HostID': pair_record.get('HostID', self.hostID) }) self.SessionID = StartSession.get('SessionID') if StartSession.get('EnableSessionSSL'): keyfile = writeHomeFile(HOMEFOLDER, self.udid + "_ssl.txt", hostCertificate + '\n' + hostPrivateKey) self.service.start_ssl(keyfile) self.allValues = self.getValue( ) # iDevice gives more information after being trusted return True
def pair(self): self.DevicePublicKey = self.getValue("", "DevicePublicKey") if self.DevicePublicKey == '': print "Unable to retreive DevicePublicKey" return False print "Creating host key & certificate" certPem, privateKeyPem, DeviceCertificate = ca_do_everything( self.DevicePublicKey) pair_record = { "DevicePublicKey": plistlib.Data(self.DevicePublicKey), "DeviceCertificate": plistlib.Data(DeviceCertificate), "HostCertificate": plistlib.Data(certPem), "HostID": self.hostID, "RootCertificate": plistlib.Data(certPem), "SystemBUID": "30142955-444094379208051516" } tries = 0 while tries < MAXTRIES: pair = {"Request": "Pair", "PairRecord": pair_record} self.c = PlistService(62078, self.udid) self.c.sendPlist(pair) pair = self.c.recvPlist() if pair and pair.get("Result") == "Success" or pair.has_key( "EscrowBag"): pair_record["HostPrivateKey"] = plistlib.Data(privateKeyPem) if pair.has_key("EscrowBag"): pair_record["EscrowBag"] = pair["EscrowBag"] writeHomeFile(HOMEFOLDER, "%s.plist" % self.identifier, plistlib.writePlistToString(pair_record)) print "Pairing OK" break elif pair and pair.get("Error") == "PasswordProtected": tries += 1 print "Please unlock your device and click trust in order to allow pairring. (%d/10)" % tries self.c.close() time.sleep(2) else: print "Pairing error", pair self.c.close() return False self.paired = True return True
def pair(self): self.DevicePublicKey = self.getValue("", "DevicePublicKey") if self.DevicePublicKey == '': print "Unable to retreive DevicePublicKey" return False print "Creating host key & certificate" certPem, privateKeyPem, DeviceCertificate = ca_do_everything( self.DevicePublicKey) pair_record = { "DevicePublicKey": plistlib.Data(self.DevicePublicKey), "DeviceCertificate": plistlib.Data(DeviceCertificate), "HostCertificate": plistlib.Data(certPem), "HostID": self.hostID, "RootCertificate": plistlib.Data(certPem), "SystemBUID": "30142955-444094379208051516" } pair = { "Label": self.label, "Request": "Pair", "PairRecord": pair_record } self.c = PlistService(62078, self.udid) self.c.sendPlist(pair) pair = self.c.recvPlist() if pair and pair.get("Result") == "Success" or pair.has_key( "EscrowBag"): pair_record["HostPrivateKey"] = plistlib.Data(privateKeyPem) pair_record["EscrowBag"] = pair.get("EscrowBag") writeHomeFile(HOMEFOLDER, "%s.plist" % self.identifier, plistlib.writePlistToString(pair_record)) self.paired = True return True elif pair and pair.get("Error") == "PasswordProtected": self.c.close() raise NotTrustedError else: print pair.get("Error") self.c.close() raise PairingError
def validate_pairing(self): pair_record = None certPem = None privateKeyPem = None if sys.platform == "win32": folder = os.environ["ALLUSERSPROFILE"] + "/Apple/Lockdown/" elif sys.platform == "darwin": folder = "/var/db/lockdown/" elif len(sys.platform) >= 5: if sys.platform[0:5] == "linux": folder = "/var/lib/lockdown/" try: pair_record = plistlib.readPlist(folder + "%s.plist" % self.identifier) except: pair_record = None if pair_record: print "Using iTunes pair record: %s.plist" % self.identifier certPem = pair_record["HostCertificate"].data privateKeyPem = pair_record["HostPrivateKey"].data else: print "No iTunes pairing record found for device %s" % self.identifier print "Looking for pymobiledevice pairing record" record = readHomeFile(HOMEFOLDER, "%s.plist" % self.identifier) if record: pair_record = plistlib.readPlistFromString(record) print "Found pymobiledevice pairing record for device %s" % self.udid certPem = pair_record["HostCertificate"].data privateKeyPem = pair_record["HostPrivateKey"].data else: print "No pymobiledevice pairing record found for device %s" % self.identifier return False self.record = pair_record ValidatePair = {"Label": self.label, "Request": "ValidatePair", "PairRecord": pair_record} self.c = PlistService(62078,self.udid) self.c.sendPlist(ValidatePair) r = self.c.recvPlist() if not r or r.has_key("Error"): pair_record = None print "ValidatePair fail", ValidatePair return False self.hostID = pair_record.get("HostID", self.hostID) self.SystemBUID = pair_record.get("SystemBUID", self.SystemBUID) d = {"Label": self.label, "Request": "StartSession", "HostID": self.hostID, 'SystemBUID': self.SystemBUID} self.c.sendPlist(d) startsession = self.c.recvPlist() self.SessionID = startsession.get("SessionID") if startsession.get("EnableSessionSSL"): sslfile = self.identifier + "_ssl.txt" sslfile = writeHomeFile(HOMEFOLDER, sslfile, certPem + "\n" + privateKeyPem) self.c.ssl_start(sslfile, sslfile) self.paired = True return True
def validate_pairing(self): pair_record = None certPem = None privateKeyPem = None if sys.platform == "win32": folder = os.environ["ALLUSERSPROFILE"] + "/Apple/Lockdown/" elif sys.platform == "darwin": folder = "/var/db/lockdown/" pair_record = plistlib.readPlist(folder + "%s.plist" % self.identifier) if pair_record: print "Using iTunes pair record: %s.plist" % self.identifier certPem = pair_record["HostCertificate"].data privateKeyPem = pair_record["HostPrivateKey"].data else: print "No iTunes pairing record found for device %s" % self.identifier print "Lokking for pymobiledevice pairing record" record = readHomeFile(HOMEFOLDER, "%s.plist" % self.identifier) if record: pair_record = plistlib.readPlistFromString(record) print "Found pymobiledevice pairing record for device %s" % self.udid certPem = pair_record["HostCertificate"].data privateKeyPem = pair_record["HostPrivateKey"].data else: print "No pymobiledevice pairing record found for device %s" % self.identifier return False ValidatePair = {"Request": "ValidatePair", "PairRecord": pair_record} self.c = PlistService(62078, self.udid) self.c.sendPlist(ValidatePair) r = self.c.recvPlist() if not r or r.has_key("Error"): pair_record = None print "ValidatePair fail", ValidatePair return False d = { "Request": "StartSession", "HostID": pair_record.get("HostID", self.hostID) } self.c.sendPlist(d) startsession = self.c.recvPlist() self.SessionID = startsession.get("SessionID") if startsession.get("EnableSessionSSL"): sslfile = self.identifier + "_ssl.txt" sslfile = writeHomeFile(HOMEFOLDER, sslfile, certPem + "\n" + privateKeyPem) self.c.ssl_start(sslfile, sslfile) self.udid = self.getValue("", "UniqueDeviceID") self.allValues = self.getValue("", "") self.paired = True return True
def pair(self): self.DevicePublicKey = self.getValue("", "DevicePublicKey") if self.DevicePublicKey == '': print "Unable to retreive DevicePublicKey" return False print "Creating host key & certificate" certPem, privateKeyPem, DeviceCertificate = ca_do_everything(self.DevicePublicKey) pair_record = {"DevicePublicKey": plistlib.Data(self.DevicePublicKey), "DeviceCertificate": plistlib.Data(DeviceCertificate), "HostCertificate": plistlib.Data(certPem), "HostID": self.hostID, "RootCertificate": plistlib.Data(certPem), "SystemBUID": "30142955-444094379208051516" } tries = 0 while tries < MAXTRIES : pair = {"Request": "Pair", "PairRecord": pair_record} self.c = PlistService(62078,self.udid) self.c.sendPlist(pair) pair = self.c.recvPlist() if pair and pair.get("Result") == "Success" or pair.has_key("EscrowBag"): pair_record["HostPrivateKey"] = plistlib.Data(privateKeyPem) if pair.has_key("EscrowBag"): pair_record["EscrowBag"] = pair["EscrowBag"] writeHomeFile(HOMEFOLDER, "%s.plist" % self.identifier, plistlib.writePlistToString(pair_record)) print "Pairing OK" break elif pair and pair.get("Error") == "PasswordProtected": tries += 1 print "Please unlock your device and click trust in order to allow pairring. (%d/10)" % tries self.c.close() time.sleep(2) else: print "Pairing error", pair self.c.close() return False self.paired = True return True
def pair(self): self.DevicePublicKey = self.getValue("", "DevicePublicKey") if self.DevicePublicKey == "": print "Unable to retreive DevicePublicKey" return False print "Creating host key & certificate" certPem, privateKeyPem, DeviceCertificate = ca_do_everything(self.DevicePublicKey) pair_record = { "DevicePublicKey": plistlib.Data(self.DevicePublicKey), "DeviceCertificate": plistlib.Data(DeviceCertificate), "HostCertificate": plistlib.Data(certPem), "HostID": self.hostID, "RootCertificate": plistlib.Data(certPem), "SystemBUID": "30142955-444094379208051516", } pair = {"Label": self.label, "Request": "Pair", "PairRecord": pair_record} self.c = PlistService(62078, self.udid) self.c.sendPlist(pair) pair = self.c.recvPlist() if pair and pair.get("Result") == "Success" or pair.has_key("EscrowBag"): pair_record["HostPrivateKey"] = plistlib.Data(privateKeyPem) pair_record["EscrowBag"] = pair.get("EscrowBag") writeHomeFile(HOMEFOLDER, "%s.plist" % self.identifier, plistlib.writePlistToString(pair_record)) self.paired = True return True elif pair and pair.get("Error") == "PasswordProtected": self.c.close() raise NotTrustedError else: self.c.close() raise PairingError
def validate_pairing(self): pair_record = None certPem = None privateKeyPem = None record = readHomeFile(HOMEFOLDER, "%s.plist" % self.identifier) if record: pair_record = plistlib.readPlistFromString(record) certPem = pair_record["HostCertificate"].data privateKeyPem = pair_record["HostPrivateKey"].data print "Found pairing record for device %s" % self.udid else: print "No pairing record found for device %s" % self.identifier return if False: if sys.platform == "win32": folder = os.environ["ALLUSERSPROFILE"] + "/Apple/Lockdown/" elif sys.platform == "darwin": folder = "/var/db/lockdown/" pair_record = plistlib.readPlist(folder + "%s.plist" % self.identifier) print "Using iTunes pair record" ValidatePair = {"Request": "ValidatePair", "PairRecord": pair_record} self.c.sendPlist(ValidatePair) ValidatePair = self.c.recvPlist() if not ValidatePair or ValidatePair.has_key("Error"): pair_record =None print "ValidatePair fail", ValidatePair return False self.paired = True #print "Validate Pairing OK", ValidatePair d = {"Request": "StartSession", "HostID": pair_record.get("HostID", self.hostID)} self.c.sendPlist(d) startsession = self.c.recvPlist() #print "Starting session",startsession self.SessionID = startsession.get("SessionID") if startsession.get("EnableSessionSSL"): sslfile = self.identifier + "_ssl.txt" sslfile = writeHomeFile(HOMEFOLDER, sslfile, certPem + "\n" + privateKeyPem) self.c.ssl_start(sslfile, sslfile) #print "SSL started" self.udid = self.getValue("", "UniqueDeviceID") self.allValues = self.getValue("", "") #print "UDID", self.udid return True
if domain: req["Domain"] = domain if key: req["Key"] = key self.c.sendPlist(req) res = self.c.recvPlist() print res return res def startService(self, name): if not self.paired: print "NotPaired" raise NotPairedError self.c.sendPlist({"Label": self.label, "Request": "StartService", "Service": name}) StartService = self.c.recvPlist() if not StartService or StartService.get("Error"): print StartService raise StartServiceError return PlistService(StartService.get("Port")) if __name__ == "__main__": l = LockdownClient() if l: n = writeHomeFile(HOMEFOLDER, "%s_infos.plist" % l.udid, plistlib.writePlistToString(l.allValues)) print "Wrote infos to %s" % n else: print "Unable to connect to device"
self.c.sendPlist(req) res = self.c.recvPlist() print res return res def startService(self, name): if not self.paired: print "NotPaired" raise NotPairedError self.c.sendPlist({ "Label": self.label, "Request": "StartService", "Service": name }) StartService = self.c.recvPlist() if not StartService or StartService.get("Error"): print StartService raise StartServiceError return PlistService(StartService.get("Port")) if __name__ == "__main__": l = LockdownClient() if l: n = writeHomeFile(HOMEFOLDER, "%s_infos.plist" % l.udid, plistlib.writePlistToString(l.allValues)) print "Wrote infos to %s" % n else: print "Unable to connect to device"