Пример #1
0
        private byte[] UnprotectPDU(byte[] header, byte[] stub_data, AuthData auth_data)
        {
            List <SecurityBuffer> buffers = new List <SecurityBuffer>();

            buffers.Add(new SecurityBufferInOut(SecurityBufferType.Data | SecurityBufferType.ReadOnly, header));
            var stub_data_buffer = new SecurityBufferInOut(SecurityBufferType.Data, stub_data);

            buffers.Add(stub_data_buffer);
            byte[] signature = auth_data.Data;
            auth_data.Data = new byte[0];
            MemoryStream stm    = new MemoryStream();
            BinaryWriter writer = new BinaryWriter(stm);

            auth_data.Write(writer, auth_data.Padding);

            buffers.Add(new SecurityBufferInOut(SecurityBufferType.Data | SecurityBufferType.ReadOnly, stm.ToArray()));

            if (_transport_security.AuthenticationLevel == RpcAuthenticationLevel.PacketIntegrity)
            {
                if (!_auth_context.VerifySignature(buffers, signature, _recv_sequence_no))
                {
                    throw new RpcTransportException("Invalid response PDU signature.");
                }
            }
            else
            {
                _auth_context.DecryptMessage(buffers, signature, _recv_sequence_no);
                stub_data = stub_data_buffer.ToArray();
            }

            Array.Resize(ref stub_data, stub_data.Length - auth_data.Padding);

            return(stub_data);
        }