Ejemplo n.º 1
0
    def testServerChallengeRespHashEncryption(self):
        sha1 = Sha1PairingHash()
        saltAsHex = "10A5CEFEAFE3BEACB892DEFAE5317C30"
        pin = "1234"
        salt = PairingManager.hex_to_bytes(saltAsHex)
        saltAndPin = PairingManager.salt_pin(salt, pin)
        aesKey = PairingManager.generate_aes_key(sha1, saltAndPin)

        getCertResponse = "<?xml version=\"1.0\" encoding=\"UTF-16\"?><root protocol_version=\"0.1\" query=\"pair\" status_code=\"200\" status_message=\"OK\"><challengeresponse></challengeresponse><encodedcipher></encodedcipher><isBusy>0</isBusy><paired>1</paired><pairingsecret></pairingsecret><plaincert>2D2D2D2D2D424547494E2043455254494649434154452D2D2D2D2D0A4D494943776A434341616F434351436C616B502F47746678367A414E42676B71686B694739773042415155464144416A4D53457748775944565151444442684F0A566B6C4553554567523246745A564E30636D5668625342545A584A325A5849774868634E4D5459774E4441794D54497A4D7A49775768634E4D7A59774E4441790A4D54497A4D7A4977576A416A4D53457748775944565151444442684F566B6C4553554567523246745A564E30636D5668625342545A584A325A584977676745690A4D4130474353714753496233445145424151554141344942447741776767454B416F49424151446F6A70315167732F6242472F4E75377449366E326B4D7658390A3871656A3866486A46746B70534A6A654B4B45714F456D6F51564E674F6E4B4641757A364B6550497544592F4D694265315070675A6A726651336C4B454449510A4D51497676496163706A4135557839625A4F454B524B4C6C534237485A4D4A73676562414459786731624A484677463475443373477A41304E675955546F49430A79694E794C41757655676C726E50523348503771574D527641395373314A4A7476327159624C6F76484930507A534842524F5058384C6F6F6243366C6C7153760A346774646C6846674858463962644779467372786246634568476E6458715834752B39376C6159484E7A35446A3338504F712F7365647A6B55684631434274480A36546972502F766765306B2B667A6F4C4272775A772F6E6C705759646B68694A4D5579446A737158597544796B48524F78593253524A33764C45583941674D420A414145774451594A4B6F5A496876634E415145464251414467674542414D5A433378794A5048335673483637564764574F4B64656B57645154747771766531710A39517555694138746A5151514B38656372584E417642415A4276743530574749472B7236646D34434A4F5838774A416A46546873467A6A6F306D3852714148550A36526C6D6D70627952454F7130434C627361416B63466D5558724C44694E5A665A55584F736A4342735147597A524A47646F6C34446953496264574C4758496B0A6D3254464845314155636977734B454836342F4E376E54344E4A4633512B3464726D2B3361515274622B6543354B49694B3552627A706D7577445261517744700A334D714532736C595A4C5755316D6C6A2F6C56704B4854473855626D486B2B7330694F4F566A7A4241353236696D644F412F736E4E43746B707735596E64385A0A48354C3174745649357A33777567415073345461515972503865364146412F2F7131394C505056712B5564306B44696D4F61733D0A2D2D2D2D2D454E442043455254494649434154452D2D2D2D2D0A</plaincert></root>"
        cert, sig = PairingManager.extract_plain_cert(getCertResponse)
        serverSignature = PairingManager.hex_to_bytes(sig)

        challengeResponse = "<?xml version=\"1.0\" encoding=\"UTF-16\"?><root protocol_version=\"0.1\" query=\"pair\" status_code=\"200\" status_message=\"OK\"><challengeresponse>271FE1A71E0B66C53A819D8C61DF3E8ED18545F7A9CD3EBC4D84FB5929ACF78A6DCA6581834D27870DB4F2BD6F0BAB22</challengeresponse><encodedcipher></encodedcipher><isBusy>0</isBusy><paired>1</paired><pairingsecret></pairingsecret><plaincert></plaincert></root>"

        encryptedChallengeResponse = PairingManager.hex_to_bytes(NvHTTP.get_xml_string(challengeResponse, "challengeresponse"))
        decryptedChallengeResponse = PairingManager.decrypt_aes(encryptedChallengeResponse, aesKey)

        serverResponse = decryptedChallengeResponse[0:sha1.get_hash_length()]
        serverChallenge = decryptedChallengeResponse[sha1.get_hash_length():sha1.get_hash_length()+16]

        clientSecretAsHex = "7E72A5BFEB5679B35060E3C805CA233E"
        clientSecret = PairingManager.hex_to_bytes(clientSecretAsHex)

        challengeRespHash = sha1.hash_data(PairingManager.concat_bytes(PairingManager.concat_bytes(serverChallenge, serverSignature), clientSecret))
        challengeRespHashEnc = PairingManager.encrypt_aes(challengeRespHash, aesKey)
        challengeRespHashDec = PairingManager.decrypt_aes(challengeRespHashEnc, aesKey)

        self.assertEqual("B0B23931FE7F7412030B26DA943B81F93A2C59F5", PairingManager.bytes_to_hex(challengeRespHash))
        self.assertEqual("D983D0362EEEF36A6F7A877F8400B668E5C35B6D6DF58D7EE5B6DD230C57A2EC", PairingManager.bytes_to_hex(challengeRespHashEnc))
        self.assertEqual("B0B23931FE7F7412030B26DA943B81F93A2C59F5000000000000000000000000", PairingManager.bytes_to_hex(challengeRespHashDec))
Ejemplo n.º 2
0
    def testAesEncryptDecrypt(self):
        sha1 = Sha1PairingHash()
        saltAsHex = "10A5CEFEAFE3BEACB892DEFAE5317C30"
        pin = "1234"
        salt = PairingManager.hex_to_bytes(saltAsHex)
        saltAndPin = PairingManager.salt_pin(salt, pin)
        aesKey = PairingManager.generate_aes_key(sha1, saltAndPin)

        randomChallengeAsHex = "A0F7773477F91290C6E462A7EE9AAC25"
        randomChallenge = PairingManager.hex_to_bytes(randomChallengeAsHex)
        encryptedChallenge = PairingManager.encrypt_aes(randomChallenge, aesKey)
        decryptedChallenge = PairingManager.decrypt_aes(encryptedChallenge, aesKey)

        self.assertEqual("6DDE4DC10BE9E7AAF6ADCDB0192516CF", PairingManager.bytes_to_hex(aesKey).upper())
        self.assertEqual("2A3C2686A60F613AD2CD769ECD4677DE", PairingManager.bytes_to_hex(encryptedChallenge).upper())
        self.assertEqual(randomChallengeAsHex, PairingManager.bytes_to_hex(decryptedChallenge).upper())
Ejemplo n.º 3
0
    def testChallengeResponse(self):
        sha1 = Sha1PairingHash()
        saltAsHex = "10A5CEFEAFE3BEACB892DEFAE5317C30"
        pin = "1234"
        salt = PairingManager.hex_to_bytes(saltAsHex)
        saltAndPin = PairingManager.salt_pin(salt, pin)
        aesKey = PairingManager.generate_aes_key(sha1, saltAndPin)

        challengeResponse = "<?xml version=\"1.0\" encoding=\"UTF-16\"?><root protocol_version=\"0.1\" query=\"pair\" status_code=\"200\" status_message=\"OK\"><challengeresponse>271FE1A71E0B66C53A819D8C61DF3E8ED18545F7A9CD3EBC4D84FB5929ACF78A6DCA6581834D27870DB4F2BD6F0BAB22</challengeresponse><encodedcipher></encodedcipher><isBusy>0</isBusy><paired>1</paired><pairingsecret></pairingsecret><plaincert></plaincert></root>"
        encryptedChallengeResponse = PairingManager.hex_to_bytes(NvHTTP.get_xml_string(challengeResponse, "challengeresponse"))
        decryptedChallengeResponse = PairingManager.decrypt_aes(encryptedChallengeResponse, aesKey)

        serverResponse = decryptedChallengeResponse[0:sha1.get_hash_length()]
        serverChallenge = decryptedChallengeResponse[sha1.get_hash_length():sha1.get_hash_length()+16]

        self.assertEqual("10A5CEFEAFE3BEACB892DEFAE5317C3031323334", PairingManager.bytes_to_hex(saltAndPin))
        self.assertEqual("271FE1A71E0B66C53A819D8C61DF3E8ED18545F7A9CD3EBC4D84FB5929ACF78A6DCA6581834D27870DB4F2BD6F0BAB22", PairingManager.bytes_to_hex(encryptedChallengeResponse).upper())
        self.assertEqual("D0F88541E5198E00AA1B942B47DBF28DFB8AEA604553FBD14537D14F0407C07167EFBB134991113352E7BD01B973D82B", PairingManager.bytes_to_hex(decryptedChallengeResponse).upper())
        self.assertEqual("D0F88541E5198E00AA1B942B47DBF28DFB8AEA60", PairingManager.bytes_to_hex(serverResponse).upper())
        self.assertEqual("4553FBD14537D14F0407C07167EFBB13", PairingManager.bytes_to_hex(serverChallenge).upper())