Пример #1
0
        /// <summary>
        /// Process message 1 and create message 2 for the client
        /// </summary>
        /// <param name="data">Thread Data, input parameter (HttpRequestMessage) from the client</param>
        public void ProcessMessage(object data)
        {
            msg2Response = null;

            log.Debug("ProcessMessage(.) started.");

            try
            {
                if (data == null)
                {
                    HttpResponseException e = new HttpResponseException(System.Net.HttpStatusCode.InternalServerError);
                    options.LogThrownException(e);
                    throw e;
                }

                HttpRequestMessage request = (HttpRequestMessage)data;

                mClient = ClientDatabase.GetTransaction(request, Constants.msg1Str);
                if (mClient == null)
                {
                    Exception e = new HttpResponseException(System.Net.HttpStatusCode.InternalServerError);
                    options.LogThrownException(e);
                    throw e;
                }

                // kill client wait thread so we don't time out.
                mClient.killTimerThread();

                // NOTE: There is a potential race-condition where the client is removed from the database during the time that the cilent sends its response
                // Can choose to check to re-add the client here in that case


                log.Debug("\n ***** State: Starting Message 1/2 sequence for client: " + mClient.ID + "\n");

                Msg1 m1 = new Msg1();
                M2ResponseMessage m2Response = m1.ProcessMessage1(request, mClient.sigmaSequenceCheck);

                // Set Client State
                msg2Response = m2Response;
            }
            catch (HttpResponseException re)
            {
                options.LogCaughtException(re);
                httpRE = re;
            }
            catch (Exception ex)
            {
                options.LogCaughtException(ex);
                threadException = ex;
            }
            finally
            {
                log.Debug("ProcessMessage(.) returning.");
            }
        }
Пример #2
0
        /// <summary>
        /// Find the Client Transaction in the databse of clients
        /// </summary>
        /// <param name="clientID">ID of the client to find</param>
        /// <returns>Boolean whether the operation succeeded or not</returns>
        private static ClientTransaction FindClientTransaction(string clientID)
        {
            log.DebugFormat("FindClientTransaction({0}) started.", clientID);

            try
            {
                if (clientID == null || clients == null)
                {
                    log.DebugFormat("FindClientTransaction({0}) returning <null> because of null inputs.", clientID);
                    return(null);
                }

                for (int i = 0; i < clients.Count; i++)
                {
                    if (((ClientTransaction)clients[i]).ID == clientID)
                    {
                        log.DebugFormat("FindClientTransaction({0}) returning {1}.", clientID, ((ClientTransaction)clients[i]).ID);
                        return((ClientTransaction)clients[i]);
                    }
                }
            }
            catch (Exception e)
            {
                options.LogCaughtException(e);
                log.Debug("Failed searching for client transaction. " + e.Message);
                HttpResponseException newException = new HttpResponseException(System.Net.HttpStatusCode.InternalServerError);
                options.LogThrownException(newException);
                throw newException;
            }

            log.DebugFormat("FindClientTransaction({0}) returning <null>.", clientID);
            return(null);
        }
Пример #3
0
        /// <summary>
        /// Create a new Provision/Remote Attestation request
        /// Processes provision request and creates a Challenge response to send to a client
        /// </summary>
        /// <param name="data">Thread Data, input parameter (HttpRequestMessage) from the client</param>
        public void CreateNewRequest(object data)
        {
            challengeResponse = null;

            log.Debug("CreateNewRequest(.) started.");

            try
            {
                if (data == null)
                {
                    HttpResponseException e = new HttpResponseException(System.Net.HttpStatusCode.InternalServerError);
                    options.LogThrownException(e);
                    throw e;
                }

                HttpRequestMessage request = (HttpRequestMessage)data;

                var    result                     = request.Content.ReadAsStringAsync();
                string jsonMsgRequest             = result.Result;
                ProvisionRequestMessage pReceived = JsonConvert.DeserializeObject <ProvisionRequestMessage>(jsonMsgRequest);


                // Get client ID so we can track it
                string clientID = ClientDatabase.GetClientID(request, Constants.ProvisionStr);
                mClient = new ClientTransaction(clientID);
                mClient.sigmaSequenceCheck.currentNonce = pReceived.reqHeader.nonce;


                ProvisionRequest  provRequest        = new ProvisionRequest();
                ChallengeResponse tChallengeResponse = provRequest.ProcessProvisionRequest(request, mClient);

                // Add new client to request database only if successful
                if (!ClientDatabase.AddClient(mClient))
                {
                    HttpResponseException e = new HttpResponseException(System.Net.HttpStatusCode.Conflict);
                    options.LogThrownException(e);
                    throw e;
                }

                log.Info("\n ***** State: Starting Provision request for client: " + mClient.ID + "\n");

                // Update client state
                if (!mClient.sigmaSequenceCheck.UpdateState(Constants.SequenceState.Challenge))
                {
                    HttpResponseException e = new HttpResponseException(System.Net.HttpStatusCode.PreconditionFailed);
                    options.LogThrownException(e);
                    throw e;
                }

                // Set Client State
                challengeResponse = tChallengeResponse;
            }
            catch (HttpResponseException re)
            {
                options.LogCaughtException(re);
                httpRE = re;
            }
            catch (Exception ex)
            {
                options.LogCaughtException(ex);
                threadException = ex;
            }
            finally
            {
                log.Debug("CreateNewRequest(.) returning.");
            }
        }