예제 #1
0
		public void TestMultiFragment (TestContext ctx, [TestHost] IEncryptionTestHost host)
		{
			// Padding will push us above the maximum fragment size.
			var size = MAX_FRAGMENT_SIZE - host.MinExtraEncryptedBytes + 1;
			var encryptedSize = host.GetEncryptedSize (size);
			ctx.Assert (encryptedSize, Is.GreaterThan (MAX_FRAGMENT_SIZE));

			var buffer = GetBuffer (MultiFragmentName, 0, size);
			var output = new TlsStream ();
			host.EncryptRecord (ContentType.ApplicationData, buffer, output);
			ctx.Assert (output.Position, Is.GreaterThanOrEqualTo (size + 2 * host.MinExtraEncryptedBytes + 10), "#2a");
			ctx.Assert (output.Position, Is.LessThanOrEqualTo (size + 2 * host.MaxExtraEncryptedBytes + 10), "#2b");
			ctx.Assert (output.Offset, Is.EqualTo (0), "#3");

			output.Position = 0;
			ctx.Assert (output.ReadByte (), Is.EqualTo ((byte)ContentType.ApplicationData), "#4a");
			ctx.Assert (output.ReadInt16 (), Is.EqualTo ((short)TlsProtocolCode.Tls12), "#4b");

			var firstChunkSize = (int)output.ReadInt16 ();
			ctx.Assert (firstChunkSize, Is.GreaterThanOrEqualTo (MAX_FRAGMENT_SIZE - host.MaxExtraEncryptedBytes - 1), "#4c");
			ctx.Assert (firstChunkSize, Is.LessThanOrEqualTo (MAX_FRAGMENT_SIZE), "#4d");

			output.Position += firstChunkSize;

			ctx.Assert (output.ReadByte (), Is.EqualTo ((byte)ContentType.ApplicationData), "#5a");
			ctx.Assert (output.ReadInt16 (), Is.EqualTo ((short)TlsProtocolCode.Tls12), "#5b");

			var secondChunkSize = (int)output.ReadInt16 ();
			ctx.Assert (secondChunkSize, Is.GreaterThanOrEqualTo (encryptedSize - firstChunkSize + host.MinExtraEncryptedBytes), "#5c");
			ctx.Assert (secondChunkSize, Is.LessThanOrEqualTo (encryptedSize - firstChunkSize + host.MaxExtraEncryptedBytes), "#5d");
			output.Position += secondChunkSize;

			WriteAndCheckOutput (ctx, MultiFragmentResult, new BufferOffsetSize (output.Buffer, 0, output.Position));
		}
예제 #2
0
		public void TestRecord (TestContext ctx, [TestHost] IEncryptionTestHost host)
		{
			var buffer = GetBuffer (TestDataName);

			var output = new TlsStream ();
			host.EncryptRecord (ContentType.ApplicationData, buffer, output);

			ctx.Assert (output.Position, Is.GreaterThanOrEqualTo (buffer.Size + host.MinExtraEncryptedBytes + 5), "#2a");
			ctx.Assert (output.Position, Is.LessThanOrEqualTo (buffer.Size + host.MaxExtraEncryptedBytes + 5), "#2b");

			var encryptedSize = host.GetEncryptedSize (buffer.Size);
			ctx.Assert (output.Position, Is.EqualTo (encryptedSize + 5), "#2c");

			output.Position = 0;
			ctx.Assert (output.ReadByte (), Is.EqualTo ((byte)ContentType.ApplicationData), "#4a");
			ctx.Assert (output.ReadInt16 (), Is.EqualTo ((short)TlsProtocolCode.Tls12), "#4b");
			ctx.Assert (output.ReadInt16 (), Is.EqualTo ((short)encryptedSize), "#4c");
			output.Position += encryptedSize;

			WriteAndCheckOutput (ctx, RecordResult, new BufferOffsetSize (output.Buffer, 0, output.Position));
		}