public void Egress_update_chunks_should_not_matter() { byte[] a1 = new byte[160]; byte[] b1 = new byte[160]; byte[] egressUpdate = new byte[32]; for (int i = 0; i < egressUpdate.Length; i++) { egressUpdate[i] = (byte)i; } var secretsA = NetTestVectors.BuildSecretsWithSameIngressAndEgress(); secretsA.EgressMac.BlockUpdate(egressUpdate.Slice(0, 16), 0, 16); secretsA.EgressMac.BlockUpdate(egressUpdate.Slice(16, 16), 0, 16); FrameMacProcessor macProcessorA = new FrameMacProcessor(TestItem.PublicKeyA, secretsA); macProcessorA.AddMac(a1, 0, 16, false); var secretsB = NetTestVectors.BuildSecretsWithSameIngressAndEgress(); secretsB.EgressMac.BlockUpdate(egressUpdate, 0, 32); FrameMacProcessor macProcessorB = new FrameMacProcessor(TestItem.PublicKeyA, secretsB); macProcessorB.AddMac(b1, 0, 16, false); Assert.AreEqual(a1.Slice(16, 16), b1.Slice(16, 16)); }
private void SetupAll(bool useLimboOutput = false) { var secrets = NetTestVectors.GetSecretsPair(); FrameCipher frameCipher = new FrameCipher(secrets.A.AesSecret); FrameMacProcessor frameMacProcessor = new FrameMacProcessor(TestItem.IgnoredPublicKey, secrets.A); _zeroSplitter = new TestZeroSplitter(); _zeroSplitter.DisableFraming(); _zeroEncoder = new TestZeroEncoder(frameCipher, frameMacProcessor); _zeroSnappyEncoder = new TestZeroSnappy(); Transaction a = Build.A.Transaction.TestObject; Transaction b = Build.A.Transaction.TestObject; _block = Build.A.Block.WithTransactions(a, b).TestObject; _newBlockMessageSerializer = new NewBlockMessageSerializer(); if (useLimboOutput) { _outputBuffer = new MockBuffer(); } _newBlockMessage = new NewBlockMessage(); _newBlockMessage.Block = _block; _serializationService = new MessageSerializationService(); _serializationService.Register(_newBlockMessageSerializer); _packetSender = new PacketSender(_serializationService, LimboLogs.Instance); ResourceLeakDetector.Level = ResourceLeakDetector.DetectionLevel.Paranoid; }
public void Setup() { var secrets = NetTestVectors.GetSecretsPair(); _frameCipher = new FrameCipher(secrets.A.AesSecret); _macProcessor = new FrameMacProcessor(TestItem.IgnoredPublicKey, secrets.A); }
public void Can_add_and_check_header_mac() { byte[] header = new byte[32]; FrameMacProcessor macProcessor = new FrameMacProcessor(NetTestVectors.BuildSecretsWithSameIngressAndEgress()); macProcessor.AddMac(header, 0, 16, true); macProcessor.CheckMac(header, 0, 16, true); }
public void Can_add_and_check_frame_mac() { byte[] frame = new byte[128]; FrameMacProcessor macProcessor = new FrameMacProcessor(NetTestVectors.BuildSecretsWithSameIngressAndEgress()); macProcessor.AddMac(frame, 0, 112, false); macProcessor.CheckMac(frame, 0, 112, false); }
public void Can_add_and_check_header_mac() { byte[] header = new byte[32]; FrameMacProcessor macProcessorA = new(TestItem.PublicKeyA, NetTestVectors.GetSecretsPair().A); FrameMacProcessor macProcessorB = new(TestItem.PublicKeyA, NetTestVectors.GetSecretsPair().B); macProcessorA.AddMac(header, 0, 16, true); macProcessorB.CheckMac(header, 0, 16, true); }
public void Can_add_and_check_frame_mac() { byte[] frame = new byte[128]; FrameMacProcessor macProcessorA = new(TestItem.PublicKeyA, NetTestVectors.GetSecretsPair().A); FrameMacProcessor macProcessorB = new(TestItem.PublicKeyA, NetTestVectors.GetSecretsPair().B); macProcessorA.AddMac(frame, 0, 112, false); macProcessorB.CheckMac(frame, 0, 112, false); }
public void Can_add_and_check_both() { byte[] full = new byte[160]; FrameMacProcessor macProcessor = new FrameMacProcessor(NetTestVectors.BuildSecretsWithSameIngressAndEgress()); macProcessor.AddMac(full, 0, 16, true); macProcessor.AddMac(full, 32, 112, false); macProcessor.CheckMac(full, 0, 16, true); macProcessor.CheckMac(full, 32, 112, false); }
public void Can_add_and_check_both() { byte[] full = new byte[160]; FrameMacProcessor macProcessorA = new(TestItem.PublicKeyA, NetTestVectors.GetSecretsPair().A); FrameMacProcessor macProcessorB = new(TestItem.PublicKeyA, NetTestVectors.GetSecretsPair().B); macProcessorA.AddMac(full, 0, 16, true); macProcessorA.AddMac(full, 32, 112, false); macProcessorB.CheckMac(full, 0, 16, true); macProcessorB.CheckMac(full, 32, 112, false); }
public void Setup() { var secrets = NetTestVectors.GetSecretsPair(); _frameCipherA = new FrameCipher(secrets.A.AesSecret); _macProcessorA = new FrameMacProcessor(TestItem.IgnoredPublicKey, secrets.A); _frameCipherB = new FrameCipher(secrets.B.AesSecret); _macProcessorB = new FrameMacProcessor(TestItem.IgnoredPublicKey, secrets.B); _frame = new byte[16 + 16 + 16 + 16]; _frame[2] = 16; // size }
public void Setup() { var secrets = NetTestVectors.GetSecretsPair(); _frameCipher = new FrameCipher(secrets.B.AesSecret); _macProcessor = new FrameMacProcessor(TestItem.IgnoredPublicKey, secrets.B); _frame = new byte[16 + 16 + LongFrameSize + 16]; // header | header MAC | packet type | data | padding | frame MAC _frame[2] = LongFrameSize - 15; // size (total - padding) _shortFrame = new byte[16 + 16 + 1 + ShortFrameSize + 15 + 16]; // header | header MAC | packet type | data | padding | frame MAC _shortFrame[2] = ShortFrameSize - 15; // size (total - padding) }
public void Setup() { var secrets = NetTestVectors.GetSecretsPair(); _frameCipherA = new FrameCipher(secrets.A.AesSecret); _macProcessorA = new FrameMacProcessor(TestItem.IgnoredPublicKey, secrets.A); _frameCipherB = new FrameCipher(secrets.B.AesSecret); _macProcessorB = new FrameMacProcessor(TestItem.IgnoredPublicKey, secrets.B); _frame = new byte[16 + 16 + 16 + 16]; _frame[2] = 16; // size InternalLoggerFactory.DefaultFactory.AddProvider(new ConsoleLoggerProvider(new ConsoleLoggerOptionsMonitor( new ConsoleLoggerOptions { FormatterName = ConsoleFormatterNames.Simple, LogToStandardErrorThreshold = LogLevel.Trace }))); ResourceLeakDetector.Level = ResourceLeakDetector.DetectionLevel.Paranoid; }
public void Setup() { _ip2PSession = Substitute.For <IP2PSession>(); _pipeline = Substitute.For <IChannelPipeline>(); _channel = Substitute.For <IChannel>(); _channel.Pipeline.Returns(_pipeline); _channel.RemoteAddress.Returns(new IPEndPoint(new IPAddress(new byte[] { 127, 0, 0, 1 }), 8003)); _channelHandlerContext = Substitute.For <IChannelHandlerContext>(); _channelHandlerContext.Channel.Returns(_channel); _service = Substitute.For <IEncryptionHandshakeService>(); _service.Auth(Arg.Any <NodeId>(), Arg.Any <EncryptionHandshake>()).Returns(_authPacket); _service.Ack(Arg.Any <EncryptionHandshake>(), Arg.Any <Packet>()).Returns(_ackPacket).AndDoes(ci => ci.Arg <EncryptionHandshake>().Secrets = NetTestVectors.BuildSecretsWithSameIngressAndEgress()); _service.When(s => s.Agree(Arg.Any <EncryptionHandshake>(), Arg.Any <Packet>())).Do(ci => ci.Arg <EncryptionHandshake>().Secrets = NetTestVectors.BuildSecretsWithSameIngressAndEgress()); _logger = NullLogManager.Instance; _remotePublicKey = new NodeId(NetTestVectors.StaticKeyB.PublicKey); }
public void Setup() { _session = Substitute.For <ISession>(); _pipeline = Substitute.For <IChannelPipeline>(); _group = new SingleThreadEventLoop(); _serializationService = new MessageSerializationService(); _channel = Substitute.For <IChannel>(); _channel.Pipeline.Returns(_pipeline); _channel.RemoteAddress.Returns(new IPEndPoint(IPAddress.Loopback, 8003)); _channelHandlerContext = Substitute.For <IChannelHandlerContext>(); _channelHandlerContext.Channel.Returns(_channel); _handshakeService = Substitute.For <IHandshakeService>(); _handshakeService.Auth(Arg.Any <PublicKey>(), Arg.Any <EncryptionHandshake>()).Returns(_authPacket); _handshakeService.Ack(Arg.Any <EncryptionHandshake>(), Arg.Any <Packet>()).Returns(_ackPacket).AndDoes(ci => ci.Arg <EncryptionHandshake>().Secrets = NetTestVectors.BuildSecretsWithSameIngressAndEgress()); _handshakeService.When(s => s.Agree(Arg.Any <EncryptionHandshake>(), Arg.Any <Packet>())).Do(ci => ci.Arg <EncryptionHandshake>().Secrets = NetTestVectors.BuildSecretsWithSameIngressAndEgress()); _logger = NullLogManager.Instance; _session.RemoteNodeId.Returns(NetTestVectors.StaticKeyB.PublicKey); }