def pairingRequest(self, packet): if self.getStage() == BLEMitmStage.ACTIVE_MITM: io.info( ("Pairing Request (from master) : " + "\n=> outOfBand = " + ("yes" if packet.outOfBand else "no") + "\n=> inputOutputCapability = " + str( ble.InputOutputCapability( data=bytes([packet.inputOutputCapability]))) + "\n=> authentication = " + str(ble.AuthReqFlag(data=bytes([packet.authentication]))) + "\n=> maxKeySize = " + str(packet.maxKeySize) + "\n=> initiatorKeyDistribution = " + str( ble.KeyDistributionFlag( data=bytes([packet.initiatorKeyDistribution])))) + "\n=> responderKeyDistribution = " + str( ble.KeyDistributionFlag( data=bytes([packet.responderKeyDistribution])))) io.info("Storing Pairing Request's payload :" + packet.payload.hex()) self.pReq = packet.payload[::-1] io.info("Redirecting to slave ...") self.a2sEmitter.sendp( ble.BLEPairingRequest( outOfBand=packet.outOfBand, inputOutputCapability=packet.inputOutputCapability, authentication=packet.authentication, maxKeySize=packet.maxKeySize, initiatorKeyDistribution=packet.initiatorKeyDistribution, responderKeyDistribution=packet.responderKeyDistribution))
def run(self): self.finished = False interface = self.args["INTERFACE"] self.emitter = self.getEmitter(interface=interface) self.receiver = self.getReceiver(interface=interface) if not self.emitter.isConnected() and utils.booleanArg( self.args["ACTIVE"]): io.fail("A connection must be established.") return self.nok() if self.args["MODE"].lower() == "master": keyboard = utils.booleanArg(self.args["KEYBOARD"]) yesno = utils.booleanArg(self.args["YESNO"]) display = utils.booleanArg(self.args["DISPLAY"]) ct2 = utils.booleanArg(self.args["CT2"]) mitm = utils.booleanArg(self.args["MITM"]) bonding = utils.booleanArg(self.args["BONDING"]) secureConnections = utils.booleanArg( self.args["SECURE_CONNECTIONS"]) keyPress = utils.booleanArg(self.args["KEYPRESS"]) linkKey = False encKey = self.args["LTK"] != "" and self.args[ "EDIV"] != "" and self.args["RAND"] != "" idKey = self.args["IRK"] != "" and self.args[ "ADDR"] != "" and self.args["ADDR_TYPE"] signKey = self.args["CSRK"] != "" self.initiatorInputOutputCapability = ble.InputOutputCapability( keyboard=keyboard, display=display, yesno=yesno) self.initiatorAuthReq = ble.AuthReqFlag( ct2=ct2, mitm=mitm, bonding=bonding, secureConnections=secureConnections, keypress=keyPress) self.initiatorKeyDistribution = ble.KeyDistributionFlag( linkKey=linkKey, encKey=encKey, idKey=idKey, signKey=signKey) self.pairingRequest = ble.BLEPairingRequest( authentication=self.initiatorAuthReq.data[0], inputOutputCapability=self.initiatorInputOutputCapability. data[0], initiatorKeyDistribution=self.initiatorKeyDistribution.data[0], responderKeyDistribution=self.initiatorKeyDistribution.data[0]) self.pReq = self.pairingRequest.payload[::-1] self.receiver.onEvent("BLESecurityRequest", callback=self.slaveSecurityRequest) self.receiver.onEvent("BLEPairingResponse", callback=self.slavePairingResponse) self.receiver.onEvent("BLEPairingConfirm", callback=self.slavePairingConfirm) self.receiver.onEvent("BLEPairingRandom", callback=self.slavePairingRandom) self.receiver.onEvent("BLEPairingFailed", callback=self.slavePairingFailed) self.receiver.onEvent("BLEEncryptionInformation", callback=self.slaveEncryptionInformation) self.receiver.onEvent("BLEMasterIdentification", callback=self.slaveMasterIdentification) self.receiver.onEvent("BLEIdentityInformation", callback=self.slaveIdentityInformation) self.receiver.onEvent( "BLEIdentityAddressInformation", callback=self.slaveIdentityAddressInformation) self.receiver.onEvent("BLESigningInformation", callback=self.slaveSigningInformation) if utils.booleanArg(self.args["ACTIVE"]): self.pairingRequest.show() self.emitter.sendp(self.pairingRequest) while not self.finished and not self.failure: utils.wait(seconds=1) if self.failure: return self.nok() return self.ok() else: self.receiver.onEvent("BLEPairingRequest", callback=self.masterPairingRequest) self.receiver.onEvent("BLEPairingConfirm", callback=self.masterPairingConfirm) self.receiver.onEvent("BLEPairingRandom", callback=self.masterPairingRandom) self.receiver.onEvent("BLELongTermKeyRequest", callback=self.masterLongTermKeyRequest) self.receiver.onEvent("BLEPairingFailed", callback=self.masterPairingFailed) self.receiver.onEvent("BLEEncryptionInformation", callback=self.masterEncryptionInformation) self.receiver.onEvent("BLEMasterIdentification", callback=self.masterMasterIdentification) self.receiver.onEvent("BLEIdentityInformation", callback=self.masterIdentityInformation) self.receiver.onEvent( "BLEIdentityAddressInformation", callback=self.masterIdentityAddressInformation) self.receiver.onEvent("BLESigningInformation", callback=self.masterSigningInformation) ct2 = utils.booleanArg(self.args["CT2"]) mitm = utils.booleanArg(self.args["MITM"]) bonding = utils.booleanArg(self.args["BONDING"]) secureConnections = utils.booleanArg( self.args["SECURE_CONNECTIONS"]) keyPress = utils.booleanArg(self.args["KEYPRESS"]) authReq = ble.AuthReqFlag(ct2=ct2, mitm=mitm, bonding=bonding, secureConnections=secureConnections, keypress=keyPress) if utils.booleanArg(self.args["ACTIVE"]): securityRequest = ble.BLESecurityRequest( authentication=authReq.data[0]) securityRequest.show() self.emitter.sendp(securityRequest) return self.ok({"INTERFACE": self.args["INTERFACE"]})