Example #1
0
        public void TestDecryptData13(TestContext ctx, [TestHost] IEncryptionTestHost host)
        {
            var input  = GetBuffer(Data13Result);
            var output = host.Decrypt(input);

            ctx.Assert(output.Size, Is.EqualTo(13), "#1");
            ctx.Assert(TlsBuffer.Compare(output, GetBuffer(TestDataName, 0, 13)), "#2");
        }
Example #2
0
        public void TestDecryptWithExtraPadding(TestContext ctx, [TestHost] IEncryptionTestHost host)
        {
            var input  = GetBuffer(ExtraPaddingResult);
            var output = host.Decrypt(input);

            var data = GetBuffer(TestDataName);

            ctx.Assert(output.Size, Is.EqualTo(data.Size), "#1");
            ctx.Assert(TlsBuffer.Compare(output, data), "#2");
        }
Example #3
0
        public override bool ProcessClient(TlsContext context)
        {
            if (context.IsServer)
            {
                throw new InvalidOperationException();
            }

            if (!context.HandshakeParameters.RequestedSecureNegotiation)
            {
                throw new TlsException(AlertDescription.HandshakeFailure);
            }

            if (!context.Session.SecureRenegotiation)
            {
                // Initial handshake
                if (Data != null && Data.Size > 0)
                {
                    throw new TlsException(AlertDescription.HandshakeFailure);
                }
                context.HandshakeParameters.SecureNegotiationSupported = true;
                return(true);
            }

            var clientData = context.Session.ClientVerifyData;
            var serverData = context.Session.ServerVerifyData;

                        #if DEBUG_FULL
            if (context.EnableDebugging)
            {
                DebugHelper.WriteLine("CHECKING CLIENT DATA", clientData);
                DebugHelper.WriteLine("CHECKING SERVER DATA", serverData);
                DebugHelper.WriteLine("CHECKING WHAT WE GOT", Data);
            }
                        #endif
            var expectedLength = clientData.Size + serverData.Size;
            if (Data.Size != expectedLength)
            {
                throw new TlsException(AlertDescription.DecodeError);
            }

            if (!TlsBuffer.Compare(clientData.Buffer, 0, clientData.Size, Data.Buffer, 0, clientData.Size))
            {
                throw new TlsException(AlertDescription.HandshakeFailure);
            }
            if (!TlsBuffer.Compare(serverData.Buffer, 0, serverData.Size, Data.Buffer, clientData.Size, serverData.Size))
            {
                throw new TlsException(AlertDescription.HandshakeFailure);
            }

            context.HandshakeParameters.SecureNegotiationSupported = true;
            return(true);
        }
Example #4
0
        protected virtual void HandleFinished(TlsFinished message)
        {
            var digest = HandshakeParameters.HandshakeMessages.GetHash(Session.Read.Cipher.HandshakeHashType);
            var hash   = Session.Read.Cipher.PRF.ComputeClientHash(Session.Read.MasterSecret, digest);

            // Check server prf against client prf
            if (!TlsBuffer.Compare(message.Hash, hash))
            {
                throw new TlsException(AlertDescription.HandshakeFailure);
            }

            Session.ClientVerifyData = hash;
        }
Example #5
0
        public override TlsExtension ProcessServer(TlsContext context)
        {
            if (!context.IsServer)
            {
                throw new InvalidOperationException();
            }

            if (context.Session.SecureRenegotiation)
            {
                if (!TlsBuffer.Compare(context.Session.ClientVerifyData, Data))
                {
                    throw new TlsException(AlertDescription.HandshakeFailure);
                }
            }
            else
            {
                if (Data != null && Data.Size != 0)
                {
                    throw new TlsException(AlertDescription.HandshakeFailure);
                }
                context.HandshakeParameters.RequestedSecureNegotiation = true;
                context.HandshakeParameters.SecureNegotiationSupported = true;
                context.Session.SecureRenegotiation = true;
                return(new RenegotiationExtension(new SecureBuffer(0)));
            }

            var clientData = context.Session.ClientVerifyData;
            var serverData = context.Session.ServerVerifyData;

                        #if DEBUG_FULL
            if (context.EnableDebugging)
            {
                DebugHelper.WriteLine("WRITING CLIENT DATA", clientData);
                DebugHelper.WriteLine("WRITING SERVER DATA", serverData);
            }
                        #endif
            var data = new SecureBuffer(clientData.Size + serverData.Size);
            Buffer.BlockCopy(clientData.Buffer, 0, data.Buffer, 0, clientData.Size);
            Buffer.BlockCopy(serverData.Buffer, 0, data.Buffer, clientData.Size, serverData.Size);

            return(new RenegotiationExtension(data));
        }