Exemple #1
0
        // The main processing loop
        //
        // Unlike in normal C# we do not throw exceptions, instead we return
        // an error code to the calling client
        public override BoundResponse Request(BoundRequest BoundRequest)
        {
            bool Authenticated = false;
            Response Response = null;
            TicketData TicketData = null;

            try {
                if (BoundRequest.Ticket != null) {
                    TicketData = Context.GetTicketData (BoundRequest.Ticket);
                    // Check that the MAC code evaluates under the ticket
                    //
                    bool valid = true; //BoundRequest.VerifyMAC(TicketData.Authentication, TicketData.MasterKey);
                    if (!valid) {
                        return ErrorBadMac;
                        }
                    Authenticated = true;
                    }

                Request Request;
                try {
                    Request.Deserialize(BoundRequest.Payload, out Request);
                    Request.TicketData = TicketData;
                    }
                catch {
                    return ErrorSyntax;
                    }

                // The only time we will accept a message without authentication
                // is if it is an initial connection
                if (!Authenticated & Request.Authenticate ()) {
                    return ErrorBadMac;
                    }

                Response = Request.Dispatch (Context, TicketData);

                if (Response == null) {
                    return ErrorUnknown;
                    }

                BoundResponse BoundResponse;
                if (TicketData == null) {
                    BoundResponse = new BoundResponse  (Response.ToString());
                    }
                else {
                    BoundResponse = new BoundResponse (Response.ToString(),
                        BoundRequest.Ticket, TicketData.Authentication, TicketData.MasterKey);
                    }

                BoundResponse.Status = Response.Status;
                BoundResponse.StatusDescription = Response.StatusDescription;

                return BoundResponse;
                }
            catch {
                return ErrorUnknown;
                }
        }
        public void HandleContext(HttpListenerContext Context)
        {
            HttpListenerRequest Request = Context.Request;

            Console.WriteLine("Request: {0} {1}  Length {2}",
                Request.HttpMethod, Request.RawUrl, Request.ContentLength64);

            string Content;

            string[] IntegrityHeaders = Request.Headers.GetValues (HTTPIntegrityHeader);
            if (IntegrityHeaders != null) {
                foreach (string IntegrityHeader in IntegrityHeaders) {
                    Console.WriteLine("Integrity: {0}", IntegrityHeader);
                    }
                }
            else {
                Console.WriteLine("No Integrity header");
                }

            // Get the content
            Stream body = Request.InputStream;
            Encoding encoding = Request.ContentEncoding;
            StreamReader Reader = new StreamReader(body, encoding);
            Content = Reader.ReadToEnd();
            Console.WriteLine(Content);
            Console.WriteLine("-----------");

            BoundRequest BoundRequest = new BoundRequest (Content);

            // Will need to fix this at some point defaults to just the first
            // service in the list
            ServiceInstance Instance = GetInstance (Request.RawUrl);
            Server ThisServer = Instance.Server;

            BoundResponse BoundResponse = ThisServer.Request (BoundRequest);

            HttpListenerResponse Response = Context.Response;
            Response.StatusCode = BoundResponse.Status;
            Response.StatusDescription = BoundResponse.StatusDescription;

            byte[] buffer = System.Text.Encoding.UTF8.GetBytes(BoundResponse.Payload);

            Response.ContentLength64 = buffer.Length;

            Stream output = Response.OutputStream;
            output.Write(buffer, 0, buffer.Length);
            // You must close the output stream.
            output.Close();
        }
Exemple #3
0
 public abstract BoundResponse Request(BoundRequest BoundRequest);
Exemple #4
0
        public override BoundResponse Request(BoundRequest BoundRequest)
        {
            bool Authenticated = false;
            QResponse Response = null;
            TicketData TicketData = null;

            try {
                if (BoundRequest.Ticket != null) {
                    TicketData = Context.GetTicketData (BoundRequest.Ticket);
                    Authenticated = true; // Otherwise an exception would have been thrown
                    }

                QRequest Request;
                try {
                    QRequest.Deserialize(BoundRequest.Payload, out Request);
                    Request.TicketData = TicketData;
                    }
                catch {
                    return ErrorSyntax;
                    }

                // The only time we will accept a message without authentication
                // is if it is an initial connection
                if (!Authenticated & Request.Authenticate ()) {
                    return ErrorBadMac;
                    }

                Response = Request.Dispatch (Context, TicketData);

                if (Response == null) {
                    return ErrorUnknown;
                    }

                BoundResponse BoundResponse;
                if (TicketData == null) {
                    BoundResponse = new BoundResponse(Response.ToString());
                    }
                else {
                    BoundResponse = new BoundResponse(Response.ToString(),
                        BoundRequest.Ticket, TicketData.Authentication, TicketData.MasterKey);
                    }
                BoundResponse.Status = Response.Status;
                BoundResponse.StatusDescription = Response.StatusDescription;
                return BoundResponse;
                }
            catch {
                return ErrorUnknown;
                }
        }
Exemple #5
0
 public override void Request(QRequest Request)
 {
     BoundRequest BoundRequest = new BoundRequest (Request.ToString (), Cryptographic);
     Messages.Add (BoundRequest);
     Console.WriteLine (BoundRequest.HTTPBinding);
     PendingResponse =  QueryServer.Request (BoundRequest);
     Messages.Add (PendingResponse);
 }