Exemplo n.º 1
0
        public void ClientInitiatorHasNoKeysCore(bool deriveKeys, MessageProtectionOrder order)
        {
            AsymmetricSecurityBindingElement sbe =
                new AsymmetricSecurityBindingElement();

            sbe.InitiatorTokenParameters =
                new UserNameSecurityTokenParameters();
            sbe.RecipientTokenParameters =
                new X509SecurityTokenParameters();
            sbe.SetKeyDerivation(deriveKeys);
            sbe.MessageProtectionOrder = order;
            TransportBindingElement tbe = new HandlerTransportBindingElement(delegate(Message input) {
                // funky, but .NET does not raise an error
                // until it writes the message to somewhere.
                // That is, it won't raise an error if this
                // HandlerTransportBindingElement does not
                // write the input message to somewhere.
                // It is an obvious bug.
                input.WriteMessage(XmlWriter.Create(TextWriter.Null));
                throw new Exception();
            });
            CustomBinding   binding = new CustomBinding(sbe, tbe);
            EndpointAddress address = new EndpointAddress(
                new Uri("stream:dummy"),
                new X509CertificateEndpointIdentity(cert2));
            CalcProxy proxy = new CalcProxy(binding, address);

            proxy.ClientCredentials.UserName.UserName = "******";
            proxy.Open();
            // Until here the wrong parameters are not checked.
            proxy.Sum(1, 2);
        }
Exemplo n.º 2
0
        public void VerifyX509MessageSecurityAtService()
        {
            AsymmetricSecurityBindingElement clisbe =
                new AsymmetricSecurityBindingElement();

            clisbe.InitiatorTokenParameters =
                new X509SecurityTokenParameters();
            clisbe.RecipientTokenParameters =
                new X509SecurityTokenParameters();

            AsymmetricSecurityBindingElement svcsbe =
                new AsymmetricSecurityBindingElement();

            svcsbe.InitiatorTokenParameters =
                new X509SecurityTokenParameters();
            svcsbe.RecipientTokenParameters =
                new X509SecurityTokenParameters();

            CustomBinding b_req = new CustomBinding(clisbe,
                                                    new HttpTransportBindingElement());

            b_req.ReceiveTimeout = b_req.SendTimeout = TimeSpan.FromSeconds(10);

            CustomBinding b_res = new CustomBinding(svcsbe, new HttpTransportBindingElement());

            b_res.ReceiveTimeout = b_res.SendTimeout = TimeSpan.FromSeconds(10);

            EndpointAddress remaddr = new EndpointAddress(
                new Uri("http://localhost:37564"),
                new X509CertificateEndpointIdentity(cert2));
            CalcProxy   proxy = null;
            ServiceHost host  = new ServiceHost(typeof(CalcService));

            host.AddServiceEndpoint(typeof(ICalc), b_res, "http://localhost:37564");

            ServiceCredentials cred = new ServiceCredentials();

            cred.ServiceCertificate.Certificate = cert;
            host.Description.Behaviors.Add(cred);
            try {
                host.Open();

                proxy = new CalcProxy(b_req, remaddr);
                proxy.ClientCredentials.ClientCertificate.Certificate = cert;

                // FIXME: on WinFX, when this Begin method
                // is invoked before the listener setup, it
                // somehow works, while ours doesn't.
                //IAsyncResult result = proxy.BeginSum (1, 2, null, null);
                //Assert.AreEqual (3, proxy.EndSum (result));
                Assert.AreEqual(3, proxy.Sum(1, 2));
            } finally {
                if (host.State == CommunicationState.Opened)
                {
                    host.Close();
                }
            }
        }
Exemplo n.º 3
0
        public void NonEndorsibleParameterInEndorsingSupport()
        {
            SymmetricSecurityBindingElement be =
                new SymmetricSecurityBindingElement();

            be.ProtectionTokenParameters =
                new X509SecurityTokenParameters();
            be.EndpointSupportingTokenParameters.Endorsing.Add(
                new UserNameSecurityTokenParameters());
            Binding          b      = new CustomBinding(be, new HttpTransportBindingElement());
            X509Certificate2 cert   = new X509Certificate2(TestResourceHelper.GetFullPathOfResource("Test/Resources/test.pfx"), "mono");
            EndpointAddress  ea     = new EndpointAddress(new Uri("http://localhost:" + NetworkHelpers.FindFreePort()), new X509CertificateEndpointIdentity(cert));
            CalcProxy        client = new CalcProxy(b, ea);

            client.ClientCredentials.UserName.UserName = "******";
            client.Sum(1, 2);
        }