コード例 #1
0
        public void OioWsTrustTokenServiceCacheGivesDifferentTokenTest()
        {
            // Arrange
            IStsTokenService stsTokenService =
                new StsTokenService(
                    TokenServiceConfigurationFactory.CreateConfiguration()
                    );

            var securityToken = stsTokenService.GetToken();

            Thread.Sleep(230000); // Sleep 4 minutes - 10 seconds ... 4 minutes due to default clock skew of 1 minut

            // Act 1
            var securityToken2 = stsTokenService.GetToken();

            // Assert 1
            Assert.AreEqual(securityToken, securityToken2, "Expected that tokens was the same");

            // Act 2
            Thread.Sleep(20000); // Sleep 20 seconds more and token should be expired.
            var securityToken3 = stsTokenService.GetToken();

            // Assert 2
            Assert.AreNotEqual(securityToken, securityToken3, "Expected that tokens was Not the same");
        }
コード例 #2
0
ファイル: TrustTests.cs プロジェクト: openmedicus/OIOIDWS.Net
        public void OioWsTrustTokenServiceGivesDifferentTokensTest()
        {
            // Arrange
            IStsTokenService stsTokenService =
                new StsTokenService(
                    TokenServiceConfigurationFactory.CreateConfiguration()
                    );
            var securityToken = stsTokenService.GetToken();

            // Act
            var securityToken2 = stsTokenService.GetToken();

            // Assert
            Assert.AreNotEqual(securityToken, securityToken2, "Expected that tokens was NOT the same");
        }
コード例 #3
0
ファイル: TrustTests.cs プロジェクト: openmedicus/OIOIDWS.Net
        public void OioWsTrustRequestFailDueToReplayAttackTest()
        {
            // Arrange
            IStsTokenService stsTokenService =
                new StsTokenService(
                    TokenServiceConfigurationFactory.CreateConfiguration()
                    );

            byte[] recordedRequest = null;
            _fiddlerApplicationOnBeforeRequest = delegate(Session oS)
            {
                // Only act on requests to WSP
                if (StsHostName != oS.hostname)
                {
                    return;
                }

                // For some reason there are two calls where the first call has en empty body.
                if (oS.RequestBody.Length > 0)
                {
                    if (recordedRequest == null)
                    {
                        // record request
                        recordedRequest = oS.RequestBody;
                    }
                    else
                    {
                        // Replay
                        oS.RequestBody = recordedRequest;
                    }
                }
            };
            FiddlerApplication.BeforeRequest += _fiddlerApplicationOnBeforeRequest;

            stsTokenService.GetToken();

            // Act
            try
            {
                stsTokenService.GetToken();
                Assert.IsTrue(false, "Expected exception was not thrown!!!");
            }
            catch (FaultException fe)
            {
                // Assert
                Assert.AreEqual("The specified request failed", fe.Message);
            }
        }
コード例 #4
0
ファイル: TrustTests.cs プロジェクト: openmedicus/OIOIDWS.Net
        public void OioWsTrustRequestFailDueToBodyTamperingTest()
        {
            // Arrange
            IStsTokenService stsTokenService =
                new StsTokenService(
                    TokenServiceConfigurationFactory.CreateConfiguration()
                    );

            _fiddlerApplicationOnBeforeRequest = delegate(Session oS)
            {
                // Only act on requests to WSP
                if (StsHostName != oS.hostname)
                {
                    return;
                }

                oS.utilReplaceInRequest("<trust:Lifetime>", "<trust:Lifetime testAttribute=\"Tampered\">");
            };
            FiddlerApplication.BeforeRequest += _fiddlerApplicationOnBeforeRequest;

            // Act
            try
            {
                stsTokenService.GetToken();
                Assert.IsTrue(false, "Expected exception was not thrown!!!");
            }
            catch (FaultException fe)
            {
                // Assert
                Assert.AreEqual("Authentication failed", fe.Message);
            }
        }
コード例 #5
0
        public void OioWsTrustRequestExpiredTest()
        {
            // Arrange
            IStsTokenService stsTokenService =
                new StsTokenService(
                    TokenServiceConfigurationFactory.CreateConfiguration()
                    );

            _fiddlerApplicationOnBeforeRequest = delegate(Session oS)
            {
                // Only act on requests to WSP
                if (StsHostName != oS.hostname)
                {
                    return;
                }

                Thread.Sleep(_wait);
            };
            FiddlerApplication.BeforeRequest += _fiddlerApplicationOnBeforeRequest;

            // Act
            try
            {
                stsTokenService.GetToken();
                Assert.IsTrue(false, "Expected exception was not thrown!!!");
            }
            catch (MessageSecurityException mse)
            {
                // Assert
                var fe = mse.InnerException as FaultException;
                Assert.IsNotNull(fe, "Expected inner fault exception");
                Assert.AreEqual("An error occurred when verifying security for the message.", fe.Message);
            }
        }
コード例 #6
0
ファイル: TrustTests.cs プロジェクト: openmedicus/OIOIDWS.Net
        public void OioWsTrustRequestFailDueToTokenTamperingTest()
        {
            // Arrange
            IStsTokenService stsTokenService =
                new StsTokenService(
                    TokenServiceConfigurationFactory.CreateConfiguration()
                    );

            _fiddlerApplicationOnBeforeRequest = delegate(Session oS)
            {
                // Only act on requests to WSP
                if (StsHostName != oS.hostname)
                {
                    return;
                }

                // Use xml version instead of utilReplaceInRequest(...) because message id is dynamically
                // For some reason there are two calls where the first call has en empty body.
                if (oS.RequestBody.Length > 0)
                {
                    var bodyAsString     = Encoding.UTF8.GetString(oS.RequestBody);
                    var bodyAsXml        = XDocument.Load(new StringReader(bodyAsString));
                    var namespaceManager = new XmlNamespaceManager(new NameTable());
                    namespaceManager.AddNamespace("s", "http://schemas.xmlsoap.org/soap/envelope/");
                    namespaceManager.AddNamespace("o",
                                                  "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");
                    var binarySecurityTokenElement =
                        bodyAsXml.XPathSelectElement(
                            "/s:Envelope/s:Header/o:Security/o:BinarySecurityToken",
                            namespaceManager);
                    // Følgende er en gammel udgave af Morten Mortensen MOCES certifikatet. Det får STS til at svare med "The request was invalid or malformed"
                    //binarySecurityTokenElement.Value =
                    //    "MIIGLjCCBRagAwIBAgIEUw9wBzANBgkqhkiG9w0BAQsFADBHMQswCQYDVQQGEwJESzESMBAGA1UECgwJVFJVU1QyNDA4MSQwIgYDVQQDDBtUUlVTVDI0MDggU3lzdGVtdGVzdCBYSVggQ0EwHhcNMTQxMTEwMTQwMTQxWhcNMTcxMTEwMTQwMTMxWjB2MQswCQYDVQQGEwJESzEqMCgGA1UECgwhw5hrb25vbWlzdHlyZWxzZW4gLy8gQ1ZSOjEwMjEzMjMxMTswFwYDVQQDDBBNb3J0ZW4gTW9ydGVuc2VuMCAGA1UEBRMZQ1ZSOjEwMjEzMjMxLVJJRDo5Mzk0NzU1MjCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALDVoVZz4QT+WP43mTl28pM9+Jy4JtBFV4R/LP2d2xLrAUGnDXn8dkAnTn4xcDll7t1kzCceI4/0ngN/CGw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MFcxCzAJBgNVBAYTAkRLMRIwEAYDVQQKDAlUUlVTVDI0MDgxJDAiBgNVBAMMG1RSVVNUMjQwOCBTeXN0ZW10ZXN0IFhJWCBDQTEOMAwGA1UEAwwFQ1JMMTYwHwYDVR0jBBgwFoAUzAJVDOSBdK8gVNURFFeckVI4f6AwHQYDVR0OBBYEFKuH3e+mCu7y3/brN7zXSkvo6MwKMAkGA1UdEwQCMAAwDQYJKoZIhvcNAQELBQADggEBAESudYwnM/vbo5cMrUvgnpSgJUZhsQnSzLMwJTsT45OS3O+yct1ci9vPI1ExFZeAisC0bROV3tlsPuDiAVgmErgrHbrz1CmNqIxNcQvkqeL1sQtsrMSRicyILvU7Ve0N0gryR/axG+7D3U488X3oxXtJlS/9WZd33FVDnTIo7Asb+c1clqlUa/DSeBBdZ19L4DbfEkamLA96trEkH1hUTZfRXLFvYW5w8w+muaBu7eL84zzTxpGZxYM14ap+cQHuq+uczDsGDDUKc/BHUmN1UuQ0QCCxHegMHUDD8KXVsosj5wUXOLzd8WwKjPyUTxKPAI5xv9/Bim4mAA7eYc+3lXs=";
                    // Følgende er den nye udgave af Morten Mortensen MOCES certifikatet. Det får STS til at svare korrekt med "The request was invalid or malformed".
                    binarySecurityTokenElement.Value =
                        "MIIGJzCCBQ+gAwIBAgIEVp5ySzANBgkqhkiG9w0BAQsFADBHMQswCQYDVQQGEwJESzESMBAGA1UECgwJVFJVU1QyNDA4MSQwIgYDVQQDDBtUUlVTVDI0MDggU3lzdGVtdGVzdCBYSVggQ0EwHhcNMTYwNTE3MTE1NDM0WhcNMTkwNTE3MTE1NDE4WjB2MQswCQYDVQQGEwJESzEqMCgGA1UECgwhw5hrb25vbWlzdHlyZWxzZW4gLy8gQ1ZSOjEwMjEzMjMxMTswFwYDVQQDDBBNb3J0ZW4gTW9ydGVuc2VuMCAGA1UEBRMZQ1ZSOjEwMjEzMjMxLVJJRDo5Mzk0NzU1MjCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBA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XN0ZW10ZXN0MTkudHJ1c3QyNDA4LmNvbS9zeXN0ZW10ZXN0MTkuY3JsMF+gXaBbpFkwVzELMAkGA1UEBhMCREsxEjAQBgNVBAoMCVRSVVNUMjQwODEkMCIGA1UEAwwbVFJVU1QyNDA4IFN5c3RlbXRlc3QgWElYIENBMQ4wDAYDVQQDDAVDUkw2NDAfBgNVHSMEGDAWgBTMAlUM5IF0ryBU1REUV5yRUjh/oDAdBgNVHQ4EFgQUEWdFrMEb7hG5I2QaLQx4eevxXD8wCQYDVR0TBAIwADANBgkqhkiG9w0BAQsFAAOCAQEAetwAPoeMMHE9zRSVcGsK3TTo6+YqORR78HXFel4Yg4j7SE3HLSHcrOYaVT/ouUcLqufEWiKRVDpZ4QShSV1hfcF3UhufKCLhMf/sNuc97e/ptOVciN76q+6jNJ+1fAtwNk+myf8lqR1r5CGCk5TDZZv64GR3Q5nhQTBG6wCCUE2vP22bDjY9h+ibfSl4eQG56rNXsDSMMnOB6Fqm9mwPXKUedF8ezHJeRAb1JQtDxkt0oy94i53EaCj6Hd6LzI4Gfq7ReorkuVJvqv+pcpPfZN9FkbbK/o62DMTw3wb+uGh/8VehGOpV05EkafClZ0lqwXpndnI+dbS6PvJpmoqElg==";
                    oS.RequestBody = Encoding.UTF8.GetBytes(bodyAsXml.ToString(SaveOptions.DisableFormatting));
                }
            };
            FiddlerApplication.BeforeRequest += _fiddlerApplicationOnBeforeRequest;

            // Act
            try
            {
                stsTokenService.GetToken();
                Assert.IsTrue(false, "Expected exception was not thrown!!!");
            }
            catch (FaultException fe)
            {
                // Assert
                Assert.AreEqual("Authentication failed", fe.Message);
            }
        }
コード例 #7
0
ファイル: TrustTests.cs プロジェクト: openmedicus/OIOIDWS.Net
        public void OioWsTrustRequestFailDueToHeaderSecurityTamperingTest()
        {
            // Arrange
            IStsTokenService stsTokenService =
                new StsTokenService(
                    TokenServiceConfigurationFactory.CreateConfiguration()
                    );

            _fiddlerApplicationOnBeforeRequest = delegate(Session oS)
            {
                // Only act on requests to WSP
                if (StsHostName != oS.hostname)
                {
                    return;
                }

                // Use xml version instead of utilReplaceInRequest(...) because message id is dynamically
                // For some reason there are two calls where the first call has en empty body.
                if (oS.RequestBody.Length > 0)
                {
                    var bodyAsString     = Encoding.UTF8.GetString(oS.RequestBody);
                    var bodyAsXml        = XDocument.Load(new StringReader(bodyAsString));
                    var namespaceManager = new XmlNamespaceManager(new NameTable());
                    namespaceManager.AddNamespace("s", "http://schemas.xmlsoap.org/soap/envelope/");
                    namespaceManager.AddNamespace("o",
                                                  "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");
                    namespaceManager.AddNamespace("u",
                                                  "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd");
                    var createdTimestampElement =
                        bodyAsXml.XPathSelectElement("/s:Envelope/s:Header/o:Security/u:Timestamp/u:Created",
                                                     namespaceManager);
                    var dateTime       = DateTime.Parse(createdTimestampElement.Value);
                    var addMinutes     = dateTime.AddMinutes(1);
                    var longDateString = addMinutes.ToUniversalTime().ToString(TimeFormat);
                    createdTimestampElement.Value = longDateString;
                    oS.RequestBody = Encoding.UTF8.GetBytes(bodyAsXml.ToString(SaveOptions.DisableFormatting));
                }
            };
            FiddlerApplication.BeforeRequest += _fiddlerApplicationOnBeforeRequest;

            // Act
            try
            {
                stsTokenService.GetToken();
                Assert.IsTrue(false, "Expected exception was not thrown!!!");
            }
            catch (FaultException fe)
            {
                // Assert
                Assert.AreEqual("Authentication failed", fe.Message);
            }
        }
コード例 #8
0
ファイル: TrustTests.cs プロジェクト: openmedicus/OIOIDWS.Net
        public void TotalFlowSucessTest()
        {
            // Arrange
            IStsTokenService stsTokenService =
                new StsTokenService(
                    TokenServiceConfigurationFactory.CreateConfiguration()
                    );

            // Act
            var securityToken = stsTokenService.GetToken();

            // Assert
            Assert.IsNotNull(securityToken);
        }
コード例 #9
0
ファイル: TrustTests.cs プロジェクト: openmedicus/OIOIDWS.Net
        public void OioWsTrustResponseFailDueToHeaderActionTamperingTest()
        {
            // Arrange
            IStsTokenService stsTokenService =
                new StsTokenService(
                    TokenServiceConfigurationFactory.CreateConfiguration()
                    );

            _fiddlerApplicationOnBeforeRequest = delegate(Session oS)
            {
                // Only act on requests to WSP
                if (StsHostName != oS.hostname)
                {
                    return;
                }

                // In order to enable response tampering, buffering mode must
                // be enabled; this allows FiddlerCore to permit modification of
                // the response in the BeforeResponse handler rather than streaming
                // the response to the client as the response comes in.
                oS.bBufferResponse = true;
            };
            FiddlerApplication.BeforeRequest += _fiddlerApplicationOnBeforeRequest;


            _fiddlerApplicationOnBeforeResponse = delegate(Session oS)
            {
                // Only act on requests to WSP
                if (StsHostName != oS.hostname)
                {
                    return;
                }

                oS.utilReplaceInResponse("<wsa:Action", "<wsa:Action testAttribute=\"Tampered\"");
            };
            FiddlerApplication.BeforeResponse += _fiddlerApplicationOnBeforeResponse;

            // Act
            try
            {
                stsTokenService.GetToken();
                Assert.IsTrue(false, "Expected exception was not thrown!!!");
            }
            catch (InvalidOperationException ioe)
            {
                // Assert
                Assert.AreEqual("SOAP signature recieved from STS does not validate!", ioe.Message);
            }
        }
コード例 #10
0
        public void OioWsTrustResponseExpiredTest()
        {
            // Arrange
            IStsTokenService stsTokenService =
                new StsTokenService(
                    TokenServiceConfigurationFactory.CreateConfiguration()
                    );

            _fiddlerApplicationOnBeforeRequest = delegate(Session oS)
            {
                // Only act on requests to WSP
                if (StsHostName != oS.hostname)
                {
                    return;
                }

                // it not set then Thread.Sleep is ignored on the response.
                oS.bBufferResponse = true;
            };
            FiddlerApplication.BeforeRequest += _fiddlerApplicationOnBeforeRequest;

            _fiddlerApplicationOnBeforeResponse = delegate(Session oS)
            {
                // Only act on requests to WSP
                if (StsHostName != oS.hostname)
                {
                    return;
                }

                Thread.Sleep(_wait);
            };
            FiddlerApplication.BeforeResponse += _fiddlerApplicationOnBeforeResponse;

            // Act
            try
            {
                stsTokenService.GetToken();
                Assert.IsTrue(false, "Expected exception was not thrown!!!");
            }
            catch (MessageSecurityException mse)
            {
                // Assert
                Assert.IsTrue(mse.Message.StartsWith("The security timestamp is stale because its expiration time"));
            }
        }
コード例 #11
0
ファイル: TrustTests.cs プロジェクト: openmedicus/OIOIDWS.Net
        public void OioWsTrustRequestFailDueToHeaderMessageIdTamperingTest()
        {
            // Arrange
            IStsTokenService stsTokenService = new StsTokenService(TokenServiceConfigurationFactory.CreateConfiguration());

            _fiddlerApplicationOnBeforeRequest = delegate(Session oS)
            {
                // Only act on requests to WSP
                if (StsHostName != oS.hostname)
                {
                    return;
                }

                // Use xml version instead of utilReplaceInRequest(...) because message id is dynamically
                // For some reason there are two calls where the first call has en empty body.
                if (oS.RequestBody.Length > 0)
                {
                    var bodyAsString     = Encoding.UTF8.GetString(oS.RequestBody);
                    var bodyAsXml        = XDocument.Load(new StringReader(bodyAsString));
                    var namespaceManager = new XmlNamespaceManager(new NameTable());
                    namespaceManager.AddNamespace("s", "http://schemas.xmlsoap.org/soap/envelope/");
                    namespaceManager.AddNamespace("a", "http://www.w3.org/2005/08/addressing");
                    var messageIdElement = bodyAsXml.XPathSelectElement("/s:Envelope/s:Header/a:MessageID",
                                                                        namespaceManager);
                    messageIdElement.Value = "uuid:0e07468e-42b2-4813-b837-6c2c6122a9c9";
                    oS.RequestBody         = Encoding.UTF8.GetBytes(bodyAsXml.ToString(SaveOptions.DisableFormatting));
                }
            };
            FiddlerApplication.BeforeRequest += _fiddlerApplicationOnBeforeRequest;

            // Act
            try
            {
                stsTokenService.GetToken();
                Assert.IsTrue(false, "Expected exception was not thrown!!!");
            }
            catch (FaultException fe)
            {
                // Assert
                Assert.AreEqual("Authentication failed", fe.Message);
            }
        }
コード例 #12
0
ファイル: TrustTests.cs プロジェクト: openmedicus/OIOIDWS.Net
        public void OioWsTrustResponseFailDueToReplayAttackTest()
        {
            // Arrange
            IStsTokenService stsTokenService =
                new StsTokenService(
                    TokenServiceConfigurationFactory.CreateConfiguration()
                    );

            byte[] recordedResponse = null;
            _fiddlerApplicationOnBeforeRequest = delegate(Session oS)
            {
                // Only act on requests to WSP
                if (StsHostName != oS.hostname)
                {
                    return;
                }

                // In order to enable response tampering, buffering mode must
                // be enabled; this allows FiddlerCore to permit modification of
                // the response in the BeforeResponse handler rather than streaming
                // the response to the client as the response comes in.
                oS.bBufferResponse = true;
            };
            FiddlerApplication.BeforeRequest += _fiddlerApplicationOnBeforeRequest;

            _fiddlerApplicationOnBeforeResponse = delegate(Session oS)
            {
                // Only act on requests to WSP
                if (StsHostName != oS.hostname)
                {
                    return;
                }

                // For some reason there are two calls where the first call has en empty body.
                if (oS.RequestBody.Length > 0)
                {
                    if (recordedResponse == null)
                    {
                        // record request
                        recordedResponse = oS.ResponseBody;
                    }
                    else
                    {
                        // Replay
                        oS.ResponseBody = recordedResponse;
                    }
                }
            };
            FiddlerApplication.BeforeResponse += _fiddlerApplicationOnBeforeResponse;

            stsTokenService.GetToken();

            // Act
            try
            {
                stsTokenService.GetToken();
                Assert.IsTrue(false, "Expected exception was not thrown!!!");
            }
            catch (InvalidOperationException ioe)
            {
                // Assert
                Assert.IsTrue(ioe.Message.StartsWith("Replay attack detected. Response message id:"), "Replay attack not detected!");
            }
        }
コード例 #13
0
ファイル: TrustTests.cs プロジェクト: openmedicus/OIOIDWS.Net
        public void OioWsTrustResponseFailDueToHeaderRelatesToTamperingTest()
        {
            // Arrange
            IStsTokenService stsTokenService =
                new StsTokenService(
                    TokenServiceConfigurationFactory.CreateConfiguration()
                    );

            _fiddlerApplicationOnBeforeRequest = delegate(Session oS)
            {
                // Only act on requests to WSP
                if (StsHostName != oS.hostname)
                {
                    return;
                }

                // In order to enable response tampering, buffering mode must
                // be enabled; this allows FiddlerCore to permit modification of
                // the response in the BeforeResponse handler rather than streaming
                // the response to the client as the response comes in.
                oS.bBufferResponse = true;
            };
            FiddlerApplication.BeforeRequest += _fiddlerApplicationOnBeforeRequest;


            _fiddlerApplicationOnBeforeResponse = delegate(Session oS)
            {
                // Only act on requests to WSP
                if (StsHostName != oS.hostname)
                {
                    return;
                }

                // Use xml version instead of utilReplaceInRequest(...) because message id is dynamically
                // For some reason there are two calls where the first call has en empty body.
                if (oS.RequestBody.Length > 0)
                {
                    var bodyAsString     = Encoding.UTF8.GetString(oS.ResponseBody);
                    var bodyAsXml        = XDocument.Load(new StringReader(bodyAsString));
                    var namespaceManager = new XmlNamespaceManager(new NameTable());
                    namespaceManager.AddNamespace("s", "http://schemas.xmlsoap.org/soap/envelope/");
                    namespaceManager.AddNamespace("a", "http://www.w3.org/2005/08/addressing");
                    var relatesToIdElement = bodyAsXml.XPathSelectElement("/s:Envelope/s:Header/a:RelatesTo",
                                                                          namespaceManager);
                    relatesToIdElement.Value = "urn:uuid:0e07468e-42b2-4813-b837-6c2c6122a9c9";
                    oS.ResponseBody          = Encoding.UTF8.GetBytes(bodyAsXml.ToString(SaveOptions.DisableFormatting));
                }
            };
            FiddlerApplication.BeforeResponse += _fiddlerApplicationOnBeforeResponse;

            // Act
            try
            {
                stsTokenService.GetToken();
                Assert.IsTrue(false, "Expected exception was not thrown!!!");
            }
            catch (InvalidOperationException ioe)
            {
                // Assert
                Assert.AreEqual("SOAP signature recieved from STS does not validate!", ioe.Message);
            }
        }