public void Validation_ShouldBeAbleToCreateToken()
        {
            Prepare();

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

            EncryptedValidationToken token = ApiEncryptionValidation.CreateEncryptedValidationToken(postString, session);
        }
Exemplo n.º 2
0
        public void Securesession_ShouldBeAbleToGetSecureSession()
        {
            ConsoleLogger logger = new ConsoleLogger();

            SecureChannel.InitializeDatabase(logger);
            Cookie        cookie  = new Cookie(SecureSession.CookieName, "TestSecureSessionId");
            SecureSession session = SecureSession.Get(cookie);

            Expect.IsNotNull(session);
        }
Exemplo n.º 3
0
        public void ShouldBeAbleToEncryptAndDecryptWithSecureSession()
        {
            InitializeSecureChannelSchema();

            SecureSession testObject = SecureSession.Get(new ServiceProxyTestHelpers.FormUrlEncodedTestRequest(), A.Fake <IResponse>());
            string        data       = "Monkey";
            string        cipher     = testObject.EncryptWithPublicKey(data);
            string        decrypted  = testObject.DecryptWithPrivateKey(cipher);

            Expect.AreEqual(data, decrypted);
        }
Exemplo n.º 4
0
 /// <summary>
 /// Decrypt the input string of the specified ExecutionRequest
 /// if it is intended for the SecureChannel
 /// </summary>
 /// <param name="execRequest"></param>
 public static void DecryptSecureChannelInvoke(ExecutionRequest execRequest)
 {
     if (execRequest.Instance != null &&
         execRequest.Instance.GetType() == typeof(SecureChannel) &&
         execRequest.MethodName.Equals(nameof(SecureChannel.Invoke)))
     {
         execRequest.InputString = SecureSession.Get(execRequest.Context).Decrypt(execRequest.InputString);
         HttpArgs args = new HttpArgs();
         args.ParseJson(execRequest.InputString);
         execRequest.JsonParams = args["jsonParams"];
     }
 }
Exemplo n.º 5
0
        public void Securesession_ShouldBeAbleToEncryptAndDecryptWithSecureSession()
        {
            SecureChannelConfig config = new SecureChannelConfig();
            Exception           ex;

            config.SchemaInitializer.Initialize(new ConsoleLogger(), out ex);
            Expect.IsNull(ex);

            SecureSession testObject = SecureSession.Get(new ServiceProxyTestHelpers.FormUrlEncodedTestRequest(), A.Fake <IResponse>());
            string        data       = "Monkey";
            string        cipher     = testObject.EncryptWithPublicKey(data);
            string        decrypted  = testObject.DecryptWithPrivateKey(cipher);

            Expect.AreEqual(data, decrypted);
        }
Exemplo n.º 6
0
        public void Securesession_ShouldBeAbleToSetValidationToken()
        {
            ConsoleLogger logger = new ConsoleLogger();

            SecureChannel.InitializeDatabase(logger);

            IRequest      request = CreateFakeRequest();
            SecureSession session = SecureSession.Get(request);

            ApiEncryptionValidation.SetEncryptedValidationToken(request.Headers, "Some random data", session.PublicKey);

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

            OutLine(request.Headers[CustomHeaders.ValidationToken]);
        }
        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));
        }