Esempio n. 1
0
        /// <summary>
        /// Continue transaction for Message 1/2 sequence
        /// </summary>
        /// <param name="request">Client Message 1 response/2 request</param>
        /// <returns></returns>
        public static async Task <M2ResponseMessage> Message1(HttpRequestMessage request)
        {
            log.Debug("Message1(.) started.");

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

            Message1Sequence2 msg12   = new Message1Sequence2();
            Thread            oThread = new Thread(new ParameterizedThreadStart(msg12.ProcessMessage));

            oThread.Start(request);

            // wait for thread to finish
            bool failed = await Wait(oThread);

            //if WE timed out, return exception
            if (failed)
            {
                HttpResponseException e = new HttpResponseException(System.Net.HttpStatusCode.GatewayTimeout);
                options.LogThrownException(e);
                throw e;
            }

            // if Completed (no timeout), get the result
            // check for exception/error
            if (msg12.getHttpResponseException() != null)
            {
                HttpResponseException e = new HttpResponseException(msg12.getHttpResponseException().Response);
                options.LogThrownException(e);
                throw e;
            }
            else if (msg12.getThreadException() != null)
            {
                Exception e = new Exception("Provisioning request error", msg12.getThreadException().InnerException);
                options.LogThrownException(e);
                throw e;
            }
            else if (msg12.getMessage2() == null)   // Unknown reason why it failed. Should never reach here/happen
            {
                HttpResponseException e = new HttpResponseException(System.Net.HttpStatusCode.InternalServerError);
                options.LogThrownException(e);
                throw e;
            }

            // start a new thread to track whether the client is taking too long
            ThreadWait tw         = new ThreadWait();
            Thread     waitThread = new Thread(new ParameterizedThreadStart(tw.Wait));

            msg12.getWorkingClient().setTimerThread(waitThread);
            waitThread.Start(msg12.getWorkingClient());

            log.Debug("Message1(.) returning.");
            // Return challenge to client
            return(msg12.getMessage2());
        }
Esempio n. 2
0
        /// <summary>
        /// Create new Client request
        /// </summary>
        /// <param name="request">Client Provisioning request</param>
        /// <returns>Challenge Response to client</returns>
        public static async Task <ChallengeResponse> NewRequest(HttpRequestMessage request)
        {
            if (request == null)
            {
                HttpResponseException e = new HttpResponseException(System.Net.HttpStatusCode.InternalServerError);
                options.LogThrownException(e);
                throw e;
            }

            // Ignore new clients if transaction is already in progress
            if (raInProgress)
            {
                HttpResponseException e = new HttpResponseException(System.Net.HttpStatusCode.Conflict);
                options.LogThrownException(e);
                throw e;
            }

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

            lock (mLock) { raInProgress = true; }

            RemoteAttestationRequest RARequest = new RemoteAttestationRequest();
            Thread oThread = new Thread(new ParameterizedThreadStart(RARequest.CreateNewRequest));

            oThread.Start(request);

            // wait for thread to finish
            bool failed = await Wait(oThread);

            //if WE timed out, return exception
            if (failed)
            {
                HttpResponseException e = new HttpResponseException(System.Net.HttpStatusCode.GatewayTimeout);
                options.LogThrownException(e);
                throw e;
            }

            // if Completed (no timeout), get the result
            // check for exception/error
            if (RARequest.getHttpResponseException() != null)
            {
                HttpResponseException e = new HttpResponseException(RARequest.getHttpResponseException().Response);
                options.LogThrownException(e);
                throw e;
            }
            else if (RARequest.getThreadException() != null)
            {
                Exception e = new Exception("Provisioning request error", RARequest.getThreadException().InnerException);
                options.LogThrownException(e);
                throw e;
            }
            else if (RARequest.getChallengeResponse() == null)   // Unknown reason why it failed. Should never reach here/happen
            {
                HttpResponseException e = new HttpResponseException(System.Net.HttpStatusCode.InternalServerError);
                options.LogThrownException(e);
                throw e;
            }

            // start a new thread to track whether the client is taking too long
            ThreadWait tw         = new ThreadWait();
            Thread     waitThread = new Thread(new ParameterizedThreadStart(tw.Wait));

            RARequest.getWorkingClient().setTimerThread(waitThread);
            waitThread.Start(RARequest.getWorkingClient());


            log.Debug("NewRequest(.) returning.");
            // Return challenge to client
            return(RARequest.getChallengeResponse());
        }