コード例 #1
0
ファイル: Client.cs プロジェクト: waffle-iron/nequeo
        /// <summary>
        /// CertificateStatus
        /// </summary>
        /// <param name="response">The current response stream.</param>
        /// <returns>True if error; else false.</returns>
        private bool CertificateStatus(Net.NetResponse response)
        {
            bool isError = true;

            byte[]        result             = null;
            string        actionName         = "";
            List <string> certificatesStatus = null;
            string        ocspRespStatus     = null;
            List <byte[]> serialNumbers      = null;

            MemoryStream sendBuffer = null;

            try
            {
                // If an action name was return then use it
                // else use a defualt action name.
                if (!String.IsNullOrEmpty(response.Headers["ActionName"]))
                {
                    actionName = response.Headers["ActionName"];
                }
                else
                {
                    actionName = _actionNameReference["OCSP_CS"];
                }

                // Read the response stream and write to the send buffer.
                sendBuffer = new MemoryStream();
                bool copied = Nequeo.IO.Stream.Operation.CopyStream(response.Input, sendBuffer, response.ContentLength, base.ResponseTimeout);

                // If all the data has been copied.
                if (copied)
                {
                    // Get the data read.
                    result         = sendBuffer.ToArray();
                    ocspRespStatus = GetOcspResponse(result, ref certificatesStatus, ref serialNumbers);
                    isError        = false;
                }
            }
            catch { isError = true; }
            finally
            {
                // Dispose of the buffer.
                if (sendBuffer != null)
                {
                    sendBuffer.Dispose();
                }
            }

            // Call the handler.
            object callback = null;
            object state    = null;

            if (_callback.TryGetValue(actionName, out callback))
            {
                _state.TryGetValue(actionName, out state);
                if (callback != null)
                {
                    Action <List <string>, string, List <byte[]>, object> callbackAction = (Action <List <string>, string, List <byte[]>, object>)callback;
                    callbackAction(certificatesStatus, ocspRespStatus, serialNumbers, state);
                }
            }

            // Return the result.
            return(isError);
        }
コード例 #2
0
ファイル: Client.cs プロジェクト: waffle-iron/nequeo
        /// <summary>
        /// On net context receive handler.
        /// </summary>
        /// <param name="sender">The application sender.</param>
        /// <param name="context">The current net context.</param>
        private void Client_OnNetContext(object sender, Net.NetContext context)
        {
            Net.NetRequest  request   = null;
            Net.NetResponse response  = null;
            bool            keepAlive = true;
            bool            isError   = true;

            try
            {
                string resource          = "";
                string executionMember   = "";
                string statusCode        = "";
                string statusDescription = "";

                request  = context.NetRequest;
                response = context.NetResponse;

                // Get the response headers, and set the response headers.
                List <NameValue> headers = base.ParseHeaders(response.Input, out resource, base.HeaderTimeout, base.MaximumReadLength);
                if (headers != null)
                {
                    // Set the response headers.
                    response.ReadNetResponseHeaders(headers, resource);

                    // Should the connection be kept alive.
                    keepAlive         = response.KeepAlive;
                    statusCode        = response.StatusCode.ToString();
                    statusDescription = response.StatusDescription;

                    // Get the execution member.
                    if (!String.IsNullOrEmpty(response.Headers["Member"]))
                    {
                        // Get the execution member.
                        executionMember = response.Headers["Member"].Trim();
                        switch (executionMember.ToUpper())
                        {
                        case "OCSP_CS":
                            // CertificateStatus
                            isError = CertificateStatus(response);
                            break;
                        }
                    }
                    else
                    {
                        // Find the response type sent from the server.
                        if (!String.IsNullOrEmpty(response.ContentType))
                        {
                            // If the response is ocsp.
                            if (response.ContentType.ToLower().Contains("ocsp-response"))
                            {
                                // CertificateStatus
                                isError = CertificateStatus(response);
                            }
                        }
                    }
                }
                else
                {
                    // No headers have been found.
                    keepAlive = false;
                    throw new Exception("No headers have been found.");
                }

                // If error.
                if (isError)
                {
                    // An internal client error.
                    AnyError(executionMember, statusCode, statusDescription);
                }
            }
            catch (Exception ex)
            {
                try
                {
                    // An internal client error.
                    AnyError("Error", "500", ex.Message);
                }
                catch { }
            }

            // If keep alive.
            if (keepAlive)
            {
                // Look for a new response if this one has been completed.
                if (response != null)
                {
                    try
                    {
                        // If the response stream is active.
                        if (response.Input != null)
                        {
                            // If another response is pending
                            // then start the process again.
                            if (response.Input.Length > 0)
                            {
                                Client_OnNetContext(this, context);
                            }
                        }
                    }
                    catch { }
                }
            }
        }