Ejemplo n.º 1
0
        private static void ValidateEncryptedToken(IHttpContext context, Decrypted input, List <ValidationFailures> failures, List <string> messages)
        {
            if (input != null)
            {
                try
                {
                    EncryptedTokenValidationStatus tokenStatus = ApiEncryptionValidation.ValidateEncryptedToken(context, input.Value);
                    switch (tokenStatus)
                    {
                    case EncryptedTokenValidationStatus.Unkown:
                        failures.Add(ServiceProxy.ValidationFailures.UnknownTokenValidationResult);
                        messages.Add("ApiEncryptionValidation.ValidateToken failed");
                        break;

                    case EncryptedTokenValidationStatus.HashFailed:
                        failures.Add(ServiceProxy.ValidationFailures.TokenHashFailed);
                        messages.Add("ApiEncryptionValidation.ValidateToken failed: TokenHashFailed");
                        break;

                    case EncryptedTokenValidationStatus.NonceFailed:
                        failures.Add(ServiceProxy.ValidationFailures.TokenNonceFailed);
                        messages.Add("ApiEncryptionValidation.ValidateToken failed: TokenNonceFailed");
                        break;

                    case EncryptedTokenValidationStatus.Success:
                        break;
                    }
                }
                catch (Exception ex)
                {
                    failures.Add(ServiceProxy.ValidationFailures.TokenValidationError);
                    messages.Add(ex.Message);
                }
            }
        }
Ejemplo n.º 2
0
        public void Validation_ShouldBeAbleToValidateToken()
        {
            Prepare();

            IHttpContext  context    = CreateFakeContext(MethodBase.GetCurrentMethod().Name);
            SecureSession session    = SecureSession.Get(context);
            string        postString = ApiParameters.ParametersToJsonParamsObjectString("random information");

            EncryptedValidationToken token = ApiEncryptionValidation.CreateEncryptedValidationToken(postString, session);

            Expect.AreEqual(EncryptedTokenValidationStatus.Success, ApiEncryptionValidation.ValidateEncryptedToken(session, token, postString));
        }
Ejemplo n.º 3
0
        public void Validation_ShouldBeAbleToSetAndValidateValidationToken()
        {
            Prepare();

            SecureSession session = SecureSession.Get(SecureSession.GenerateId());

            string postString = ApiParameters.ParametersToJsonParamsObjectString("random info");
            SecureServiceProxyClient <Echo> client = new SecureServiceProxyClient <Echo>("http://blah.com");

            HttpWebRequest request = client.GetServiceProxyRequest("Send");

            ApiEncryptionValidation.SetEncryptedValidationToken(request.Headers, postString, session.PublicKey);

            Cookie cookie = new Cookie(SecureSession.CookieName, session.Identifier, "", "blah.cxm");

            request.CookieContainer.Add(cookie);
            request.Headers[Headers.SecureSession] = session.Identifier;

            Expect.IsNotNull(request.Headers);
            Expect.IsNotNull(request.Headers[Headers.Nonce]);
            Expect.IsNotNull(request.Headers[Headers.ValidationToken]);

            Expect.AreEqual(EncryptedTokenValidationStatus.Success, ApiEncryptionValidation.ValidateEncryptedToken(request.Headers, postString));
        }