def setUp(self): super(TestMessage, self).setUp() transform1 = Transform(Transform.Type.INTEG, Transform.IntegId.AUTH_HMAC_SHA1_96) transform2 = Transform(Transform.Type.PRF, Transform.PrfId.PRF_HMAC_SHA1) transform3 = Transform(Transform.Type.ENCR, Transform.EncrId.ENCR_AES_CBC, 256) proposal1 = Proposal(20, Proposal.Protocol.IKE, b'aspiwhatever', [transform1, transform2, transform3]) proposal2 = Proposal(20, Proposal.Protocol.IKE, b'anotherone', [transform3]) payload_sa = PayloadSA([proposal1, proposal2]) payload_nonce = PayloadNONCE() payload_ke = PayloadKE(5, b'1234567890' * 10) payload_vendor = PayloadVENDOR(b'pyikev2-test-0.1') self.object = Message( spi_i=b'12345678', spi_r=b'12345678', major=2, minor=0, exchange_type=Message.Exchange.IKE_SA_INIT, is_response=False, can_use_higher_version=False, is_initiator=False, message_id=0, payloads=[payload_sa, payload_ke, payload_nonce, payload_vendor], encrypted_payloads=[])
def test_encrypted(self): transform1 = Transform(Transform.Type.INTEG, Transform.IntegId.AUTH_HMAC_SHA2_256_128) transform2 = Transform(Transform.Type.ENCR, Transform.EncrId.ENCR_AES_CBC, 256) proposal1 = Proposal(1, Proposal.Protocol.IKE, b'aspiwhatever', [transform1, transform2]) payload_sa = PayloadSA([proposal1]) payload_nonce = PayloadNONCE(b'123456789012341232132132131') crypto = Crypto( Cipher( Transform(Transform.Type.ENCR, Transform.EncrId.ENCR_AES_CBC, 256)), b'a' * 32, Integrity( Transform(Transform.Type.INTEG, Transform.IntegId.AUTH_HMAC_SHA2_512_256)), b'a' * 8, None, b'') message = Message(spi_i=b'12345678', spi_r=b'12345678', major=2, minor=0, exchange_type=Message.Exchange.IKE_AUTH, is_response=False, can_use_higher_version=False, is_initiator=False, message_id=0, payloads=[], encrypted_payloads=[payload_sa, payload_nonce], crypto=crypto) data = message.to_bytes() new_message = Message.parse(data, crypto=crypto) data2 = new_message.to_bytes() self.assertEqual(data, data2)
def test_parse_large(self): with self.assertRaises(InvalidSyntax): PayloadNONCE.parse(b'1234567890' * 100)
def setUp(self): super(TestPayloadNONCE, self).setUp() self.object = PayloadNONCE()