示例#1
0
	def getLogEntriesCount(self, pinHex):
		self._makeBLEConnection()
		keyturnerUSDIOHandle = self.device.get_handle("a92ee202-5501-11e4-916c-0800200c9a66")
		self.device.subscribe('a92ee202-5501-11e4-916c-0800200c9a66', self._handleCharWriteResponse, indication=True))
		challengeReq = nuki_messages.Nuki_REQ('0004')
		challengeReqEncrypted = nuki_messages.Nuki_EncryptedCommand(authID=self.config.get(self.macAddress, 'authorizationID'), nukiCommand=challengeReq, publicKey=self.config.get(self.macAddress, 'publicKeyNuki'), privateKey=self.config.get(self.macAddress, 'privateKeyHex'))
		challengeReqEncryptedCommand = challengeReqEncrypted.generate()
		self._charWriteResponse = ""
		print "Requesting CHALLENGE: %s" % challengeReqEncrypted.generate("HEX")
		self.device.char_write_handle(keyturnerUSDIOHandle,challengeReqEncryptedCommand,True,5)
		print "Nuki CHALLENGE Request sent: %s" % challengeReq.show() 
		time.sleep(2)
		commandParsed = self.parser.decrypt(self._charWriteResponse,self.config.get(self.macAddress, 'publicKeyNuki'),self.config.get(self.macAddress, 'privateKeyHex'))[8:]
		if self.parser.isNukiCommand(commandParsed) == False:
			sys.exit("Error while requesting Nuki CHALLENGE: %s" % commandParsed)
		commandParsed = self.parser.parse(commandParsed)
		if commandParsed.command != '0004':
			sys.exit("Nuki returned unexpected response (expecting Nuki CHALLENGE): %s" % commandParsed.show())
		print "Challenge received: %s" % commandParsed.nonce
		logEntriesReq = nuki_messages.Nuki_LOG_ENTRIES_REQUEST()
		logEntriesReq.createPayload(0, commandParsed.nonce, self.byteSwapper.swap(pinHex))
		logEntriesReqEncrypted = nuki_messages.Nuki_EncryptedCommand(authID=self.config.get(self.macAddress, 'authorizationID'), nukiCommand=logEntriesReq, publicKey=self.config.get(self.macAddress, 'publicKeyNuki'), privateKey=self.config.get(self.macAddress, 'privateKeyHex'))
		logEntriesReqEncryptedCommand = logEntriesReqEncrypted.generate()
		self._charWriteResponse = ""
		self.device.char_write_handle(keyturnerUSDIOHandle,logEntriesReqEncryptedCommand,True,4)
		print "Nuki Log Entries Request sent: %s" % logEntriesReq.show() 
		time.sleep(2)
		commandParsed = self.parser.decrypt(self._charWriteResponse,self.config.get(self.macAddress, 'publicKeyNuki'),self.config.get(self.macAddress, 'privateKeyHex'))[8:]
		if self.parser.isNukiCommand(commandParsed) == False:
			sys.exit("Error while requesting Nuki Log Entries: %s" % commandParsed)
		commandParsed = self.parser.parse(commandParsed)
		if commandParsed.command != '0026':
			sys.exit("Nuki returned unexpected response (expecting Nuki LOG ENTRY): %s" % commandParsed.show())
		print "%s" % commandParsed.show()
		return int(commandParsed.logCount, 16)
示例#2
0
 def getLogEntries(self, count, pinHex):
     self._makeBLEConnection()
     keyturnerUSDIOHandle = self.device.get_handle(DEVICE_HANDLEID2)
     self.device.subscribe(DEVICE_HANDLEID2,
                           self._handleCharWriteResponse,
                           indication=True)
     challengeReq = nuki_messages.Nuki_REQ(
         nuki_messages.Nuki_CHALLENGE.command)
     challengeReqEncrypted = nuki_messages.Nuki_EncryptedCommand(
         authID=self.config.get(self.macAddress, 'authorizationID'),
         nukiCommand=challengeReq,
         publicKey=self.config.get(self.macAddress, 'publicKeyNuki'),
         privateKey=self.config.get(self.macAddress, 'privateKeyHex'))
     challengeReqEncryptedCommand = challengeReqEncrypted.generate()
     print(f"Requesting CHALLENGE: {challengeReqEncrypted.generate('HEX')}")
     self._charWriteResponse = ""
     self.device.char_write_handle(keyturnerUSDIOHandle,
                                   challengeReqEncryptedCommand, True, 5)
     print("Nuki CHALLENGE Request sent: %s" % challengeReq.show())
     # time.sleep(2)
     commandParsed = self.parser.decrypt(
         self._charWriteResponse,
         self.config.get(self.macAddress, 'publicKeyNuki'),
         self.config.get(self.macAddress, 'privateKeyHex'))[8:]
     if self.parser.isNukiCommand(commandParsed) == False:
         sys.exit("Error while requesting Nuki CHALLENGE: %s" %
                  commandParsed)
     commandParsed = self.parser.parse(commandParsed)
     if type(commandParsed) != nuki_messages.Nuki_CHALLENGE:
         sys.exit(
             "Nuki returned unexpected response (expecting Nuki CHALLENGE): %s"
             % commandParsed.show())
     print("Challenge received: %s" % commandParsed.nonce)
     logEntriesReq = nuki_messages.Nuki_LOG_ENTRIES_REQUEST()
     logEntriesReq.createPayload(count, commandParsed.nonce,
                                 self.byteSwapper.swap(pinHex))
     logEntriesReqEncrypted = nuki_messages.Nuki_EncryptedCommand(
         authID=self.config.get(self.macAddress, 'authorizationID'),
         nukiCommand=logEntriesReq,
         publicKey=self.config.get(self.macAddress, 'publicKeyNuki'),
         privateKey=self.config.get(self.macAddress, 'privateKeyHex'))
     logEntriesReqEncryptedCommand = logEntriesReqEncrypted.generate()
     self._charWriteResponse = ""
     self.device.char_write_handle(keyturnerUSDIOHandle,
                                   logEntriesReqEncryptedCommand, True, 6)
     print("Nuki Log Entries Request sent: %s" % logEntriesReq.show())
     # time.sleep(2)
     messages = self.parser.splitEncryptedMessages(self._charWriteResponse)
     print("Received %d messages" % len(messages))
     logMessages = []
     for message in messages:
         print(f"Decrypting message {message}")
         try:
             commandParsed = self.parser.decrypt(
                 message, self.config.get(self.macAddress, 'publicKeyNuki'),
                 self.config.get(self.macAddress, 'privateKeyHex'))[8:]
             if self.parser.isNukiCommand(commandParsed) == False:
                 sys.exit(
                     f"Error while requesting Nuki Log Entries: {commandParsed}"
                 )
             commandParsed = self.parser.parse(commandParsed)
             if type(commandParsed) not in [
                     nuki_messages.Nuki_LOG_ENTRY,
                     nuki_messages.Nuki_LOG_ENTRY_COUNT,
                     nuki_messages.Nuki_STATUS
             ]:
                 sys.exit(
                     "Nuki returned unexpected response (expecting Nuki LOG ENTRY): %s"
                     % commandParsed.show())
             print("%s" % commandParsed.show())
             if type(commandParsed) == nuki_messages.Nuki_LOG_ENTRY:
                 logMessages.append(commandParsed)
         except:
             print("Unable to decrypt message")
     return logMessages
示例#3
0
 def getLogEntries(self, count, pinHex):
     self._makeBLEConnection()
     keyturnerUSDIOHandle = self.device.get_handle(
         "a92ee202-5501-11e4-916c-0800200c9a66")
     self.device.subscribe('a92ee202-5501-11e4-916c-0800200c9a66',
                           self._handleCharWriteResponse)
     challengeReq = nuki_messages.Nuki_REQ('0004')
     challengeReqEncrypted = nuki_messages.Nuki_EncryptedCommand(
         authID=self.config.get(self.macAddress, 'authorizationID'),
         nukiCommand=challengeReq,
         publicKey=self.config.get(self.macAddress, 'publicKeyNuki'),
         privateKey=self.config.get(self.macAddress, 'privateKeyHex'))
     challengeReqEncryptedCommand = challengeReqEncrypted.generate()
     print "Requesting CHALLENGE: %s" % challengeReqEncrypted.generate(
         "HEX")
     self._charWriteResponse = ""
     self.device.char_write_handle(keyturnerUSDIOHandle,
                                   challengeReqEncryptedCommand, True, 5)
     print "Nuki CHALLENGE Request sent: %s" % challengeReq.show()
     commandParsed = self.parser.decrypt(
         self._charWriteResponse,
         self.config.get(self.macAddress, 'publicKeyNuki'),
         self.config.get(self.macAddress, 'privateKeyHex'))[8:]
     if self.parser.isNukiCommand(commandParsed) == False:
         sys.exit("Error while requesting Nuki CHALLENGE: %s" %
                  commandParsed)
     commandParsed = self.parser.parse(commandParsed)
     if commandParsed.command != '0004':
         sys.exit(
             "Nuki returned unexpected response (expecting Nuki CHALLENGE): %s"
             % commandParsed.show())
     print "Challenge received: %s" % commandParsed.nonce
     logEntriesReq = nuki_messages.Nuki_LOG_ENTRIES_REQUEST()
     logEntriesReq.createPayload(count, commandParsed.nonce,
                                 self.byteSwapper.swap(pinHex))
     logEntriesReqEncrypted = nuki_messages.Nuki_EncryptedCommand(
         authID=self.config.get(self.macAddress, 'authorizationID'),
         nukiCommand=logEntriesReq,
         publicKey=self.config.get(self.macAddress, 'publicKeyNuki'),
         privateKey=self.config.get(self.macAddress, 'privateKeyHex'))
     logEntriesReqEncryptedCommand = logEntriesReqEncrypted.generate()
     self._charWriteResponse = ""
     self.device.char_write_handle(keyturnerUSDIOHandle,
                                   logEntriesReqEncryptedCommand, True, 6)
     print "Nuki Log Entries Request sent: %s" % logEntriesReq.show()
     messages = self.parser.splitEncryptedMessages(self._charWriteResponse)
     print "Received %d messages" % len(messages)
     logMessages = []
     for message in messages:
         print "Decrypting message %s" % message
         try:
             commandParsed = self.parser.decrypt(
                 message, self.config.get(self.macAddress, 'publicKeyNuki'),
                 self.config.get(self.macAddress, 'privateKeyHex'))[8:]
             if self.parser.isNukiCommand(commandParsed) == False:
                 sys.exit("Error while requesting Nuki Log Entries: %s" %
                          commandParsed)
             commandParsed = self.parser.parse(commandParsed)
             if commandParsed.command != '0024' and commandParsed.command != '0026' and commandParsed.command != '000E':
                 sys.exit(
                     "Nuki returned unexpected response (expecting Nuki LOG ENTRY): %s"
                     % commandParsed.show())
             print "%s" % commandParsed.show()
             if commandParsed.command == '0024':
                 logMessages.append(commandParsed)
         except:
             print "Unable to decrypt message"
     return logMessages
示例#4
0
 def getLogEntriesCount(self, pinHex):
     self._makeBLEConnection()
     keyturnerUSDIOHandle = self.device.get_handle(DEVICE_HANDLEID2)
     self.device.subscribe(DEVICE_HANDLEID2,
                           self._handleCharWriteResponse,
                           indication=True)
     challengeReq = nuki_messages.Nuki_REQ(
         nuki_messages.Nuki_CHALLENGE.command)
     challengeReqEncrypted = nuki_messages.Nuki_EncryptedCommand(
         authID=self.config.get(self.macAddress, 'authorizationID'),
         nukiCommand=challengeReq,
         publicKey=self.config.get(self.macAddress, 'publicKeyNuki'),
         privateKey=self.config.get(self.macAddress, 'privateKeyHex'))
     challengeReqEncryptedCommand = challengeReqEncrypted.generate()
     self._charWriteResponse = ""
     print(f"Requesting CHALLENGE: {challengeReqEncrypted.generate('HEX')}")
     self.device.char_write_handle(keyturnerUSDIOHandle,
                                   challengeReqEncryptedCommand, True, 5)
     print("Nuki CHALLENGE Request sent: %s" % challengeReq.show())
     # time.sleep(2)
     commandParsed = self.parser.decrypt(
         self._charWriteResponse,
         self.config.get(self.macAddress, 'publicKeyNuki'),
         self.config.get(self.macAddress, 'privateKeyHex'))[8:]
     if self.parser.isNukiCommand(commandParsed) == False:
         sys.exit(f"Error while requesting Nuki CHALLENGE: {commandParsed}")
     commandParsed = self.parser.parse(commandParsed)
     if type(commandParsed) != nuki_messages.Nuki_CHALLENGE:
         sys.exit(
             f"Nuki returned unexpected response (expecting Nuki CHALLENGE): {commandParsed.show()}"
         )
     print(f"Challenge received: {commandParsed.nonce}")
     logEntriesReq = nuki_messages.Nuki_LOG_ENTRIES_REQUEST()
     logEntriesReq.createPayload(0, commandParsed.nonce,
                                 self.byteSwapper.swap(pinHex))
     logEntriesReqEncrypted = nuki_messages.Nuki_EncryptedCommand(
         authID=self.config.get(self.macAddress, 'authorizationID'),
         nukiCommand=logEntriesReq,
         publicKey=self.config.get(self.macAddress, 'publicKeyNuki'),
         privateKey=self.config.get(self.macAddress, 'privateKeyHex'),
     )
     logEntriesReqEncryptedCommand = logEntriesReqEncrypted.generate()
     self._charWriteResponse = ""
     self.device.char_write_handle(keyturnerUSDIOHandle,
                                   logEntriesReqEncryptedCommand, True, 4)
     print(f"Nuki Log Entries Request sent: {logEntriesReq.show()}")
     # time.sleep(2)
     commandParsed = self.parser.decrypt(
         self._charWriteResponse,
         self.config.get(self.macAddress, 'publicKeyNuki'),
         self.config.get(self.macAddress, 'privateKeyHex'))[8:]
     if self.parser.isNukiCommand(commandParsed) == False:
         sys.exit(
             f"Error while requesting Nuki Log Entries: {commandParsed}")
     commandParsed = self.parser.parse(commandParsed)
     if type(commandParsed) != nuki_messages.Nuki_LOG_ENTRY_COUNT:
         sys.exit(
             f"Nuki returned unexpected response (expecting Nuki LOG ENTRY): {commandParsed.show()}"
         )
     print("%s" % commandParsed.show())
     return int(commandParsed.logCount, 16)