示例#1
2
 protected override Binding GetBinding()
 {
     var binding = new BasicHttpsBinding(BasicHttpsSecurityMode.Transport);
     binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Ntlm;
     binding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName;
     return binding;
 }
示例#2
1
    // Asking for PeerTrust alone should succeed
    // if the certificate is in the TrustedPeople store.  For this test
    // we use a certificate we know is in the TrustedPeople store.
    public static void Https_SecModeTrans_CertValMode_PeerTrust_Succeeds_In_TrustedPeople()
    {
        EndpointAddress endpointAddress = null;
        string testString = "Hello";
        ChannelFactory<IWcfService> factory = null;
        IWcfService serviceProxy = null;

        try
        {
            // *** SETUP *** \\
            BasicHttpsBinding binding = new BasicHttpsBinding(BasicHttpsSecurityMode.Transport);
            binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;

            endpointAddress = new EndpointAddress(
                                new Uri(Endpoints.Https_SecModeTrans_ClientCredTypeNone_ServerCertValModePeerTrust_Address));

            factory = new ChannelFactory<IWcfService>(binding, endpointAddress);
            factory.Credentials.ServiceCertificate.SslCertificateAuthentication = new X509ServiceCertificateAuthentication();
            factory.Credentials.ServiceCertificate.SslCertificateAuthentication.CertificateValidationMode = X509CertificateValidationMode.PeerTrust;

            serviceProxy = factory.CreateChannel();

            // *** EXECUTE *** \\
            string result = serviceProxy.Echo(testString);

            // *** VALIDATE *** \\
            Assert.Equal(testString, result);

            // *** CLEANUP *** \\
            ((ICommunicationObject)serviceProxy).Close();
            factory.Close();
        }
        finally
        {
            // *** ENSURE CLEANUP *** \\
            ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)serviceProxy, factory);
        }
    }
示例#3
1
    public static void Https_SecModeTrans_ClientCredTypeNone_ServerCertValModePeerOrChainTrust_EchoString()
    {
#if FULLXUNIT_NOTSUPPORTED
        bool root_Certificate_Installed = Root_Certificate_Installed();
        bool client_Certificate_Installed = Client_Certificate_Installed();
        if (!root_Certificate_Installed || !client_Certificate_Installed)
        {
            Console.WriteLine("---- Test SKIPPED --------------");
            Console.WriteLine("Attempting to run the test in ToF, a ConditionalFact evaluated as FALSE.");
            Console.WriteLine("Root_Certificate_Installed evaluated as {0}", root_Certificate_Installed);
            Console.WriteLine("Client_Certificate_Installed evaluated as {0}", client_Certificate_Installed);
            return;
        }
#endif
        EndpointAddress endpointAddress = null;
        string testString = "Hello";
        ChannelFactory<IWcfService> factory = null;
        IWcfService serviceProxy = null;

        try
        {
            // *** SETUP *** \\
            BasicHttpsBinding binding = new BasicHttpsBinding(BasicHttpsSecurityMode.Transport);
            binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
            endpointAddress = new EndpointAddress(new Uri(Endpoints.Https_SecModeTrans_ClientCredTypeNone_ServerCertValModePeerTrust_Address));

            factory = new ChannelFactory<IWcfService>(binding, endpointAddress);
            factory.Credentials.ServiceCertificate.SslCertificateAuthentication = new X509ServiceCertificateAuthentication();
            factory.Credentials.ServiceCertificate.SslCertificateAuthentication.CertificateValidationMode = X509CertificateValidationMode.PeerOrChainTrust;

            serviceProxy = factory.CreateChannel();

            // *** EXECUTE *** \\
            string result = serviceProxy.Echo(testString);

            // *** VALIDATE *** \\
            Assert.Equal(testString, result);

            // *** CLEANUP *** \\
            ((ICommunicationObject)serviceProxy).Close();
            factory.Close();
        }
        finally
        {
            // *** ENSURE CLEANUP *** \\
            ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)serviceProxy, factory);
        }
    }
        public static EmailStatusServiceClient proxy(string scheme)
        {
            EmailStatusServiceClient c = null;

            UriBuilder ub = new UriBuilder();

            ub.Scheme = scheme;
            ub.Path = PATH_STATUS;
            ub.Host = HOST;

            EndpointAddress endPoint = new EndpointAddress(ub.Uri, new SpnEndpointIdentity(string.Empty));

            BasicHttpsBinding binding = new BasicHttpsBinding();
            binding.Security.Mode = BasicHttpsSecurityMode.Transport;
            binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;

            c = new EmailStatusServiceClient(binding, endPoint);
            c.ClientCredentials.UserName.UserName = EmailStatusService.UserName;
            c.ClientCredentials.UserName.Password = EmailStatusService.Password;

            c.Open();

            if (c.InnerChannel != null)
            {
                c.InnerChannel.OperationTimeout = TimeSpan.FromMinutes(60);
            }

            return c;
        }
示例#5
0
        protected override void ProcessRecord()
        {
            base.ProcessRecord();



            var             remoteAddress = new System.ServiceModel.EndpointAddress(SapiUrl);
            HttpBindingBase binding;

            if (remoteAddress.Uri.Scheme == "https")
            {
                binding = new System.ServiceModel.BasicHttpsBinding();
            }
            else
            {
                binding = new System.ServiceModel.BasicHttpBinding();
            }
            SapiClients.client = new SapiClient(binding, remoteAddress);
            var behaviour = new CustomAuthenticationBehaviour();

            SapiClients.client.Endpoint.EndpointBehaviors.Add(behaviour);

            pscConnectOptions pscOptions = new pscConnectOptions
            {
                base64     = Base64,
                authServer = Server,
                user       = User,
                password   = Password
            };

            if (PortSet)
            {
                pscOptions.portSpecified = true;
                pscOptions.port          = PortValue;
            }

            var loginResult = SapiClients.client.login(pscOptions);

            behaviour.ApplyAuthenticationToken(loginResult.token);
            var actionTask = SapiClients.client.connectAsync();

            var result      = Progress("Connect", actionTask);
            var finalResult = new SapiConnectResult(result);

            // For Interval in Seconds
            // This Scheduler will start after 0 hour and 15 minutes call after every 15 minutes
            // IntervalInSeconds(start_hour, start_minute, seconds)
            MyScheduler.IntervalInMinutes(0, 15, 15,
                                          () =>
            {
                SapiClients.client.keepalive();
            });
            WriteObject(finalResult); // This is what actually "returns" output.
        }
示例#6
0
        public static void Run(string xmlFilename, string xsdFilename)
        {
            var http = new BasicHttpBinding ();
            http.OpenTimeout = TimeSpan.FromHours (3);
            http.MaxBufferSize = 8192;
            http.HostNameComparisonMode = HostNameComparisonMode.WeakWildcard;
            http.AllowCookies = true;
            http.Security.Mode = BasicHttpSecurityMode.Transport;
            http.TransferMode = TransferMode.StreamedRequest;

            #if !MOBILE || MOBILE_BAULIG
            var https = new BasicHttpsBinding ();
            https.MaxBufferSize = 32768;
            #endif

            #if !MOBILE_FIXME
            var netTcp = new NetTcpBinding ();
            #endif

            var custom = new CustomBinding ();
            custom.Name = "myCustomBinding";
            var text = new TextMessageEncodingBindingElement ();
            text.MessageVersion = MessageVersion.Soap12WSAddressingAugust2004;
            custom.Elements.Add (text);
            custom.Elements.Add (new HttpTransportBindingElement ());

            var root = new Configuration ();
            root.AddBinding (http);
            #if !MOBILE || MOBILE_BAULIG
            root.AddBinding (https);
            #endif
            #if !MOBILE_FIXME
            root.AddBinding (netTcp);
            #endif
            root.AddBinding (custom);

            var contract = new ContractDescription ("MyContract");
            var endpointUri = "custom://localhost:8888/MyService";
            var endpointAddress = new EndpointAddress (endpointUri);

            var endpoint = new ServiceEndpoint (contract, custom, endpointAddress);

            root.AddEndpoint (endpoint);

            Generator.Write (xmlFilename, xsdFilename, root);

            Utils.Dump (xsdFilename);
            Utils.Dump (xmlFilename);

            Utils.ValidateSchema (xmlFilename, xsdFilename);
        }
        public void LoadClient(string certificado)
        {

            Certificado = new LoadCertificado().FindCert(certificado);

            BasicHttpsBinding binding = new BasicHttpsBinding();
            binding.Name = "LoteNFeSoapHttps";
            binding.Security.Mode = BasicHttpsSecurityMode.Transport;
            binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;

            EndpointAddress endpoitAddress = new EndpointAddress("https://nfe.prefeitura.sp.gov.br/ws/lotenfe.asmx");

            LoteNFeClient = new LoteNFeSoapClient(remoteAddress: endpoitAddress, binding: binding);
            LoteNFeClient.Endpoint.Binding = binding;
            LoteNFeClient.ChannelFactory.Credentials.ClientCertificate.Certificate = Certificado;
        }
 protected override Binding GetBinding()
 {
     var binding = new BasicHttpsBinding(BasicHttpsSecurityMode.Transport);
     binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Digest;
     return binding;
 }
示例#9
0
    public static void ClientCertificate_EchoString()
    {
#if FULLXUNIT_NOTSUPPORTED
        bool root_Certificate_Installed = Root_Certificate_Installed();
        bool client_Certificate_Installed = Client_Certificate_Installed();
        bool server_Accepts_Certificates = Server_Accepts_Certificates();
        if (!root_Certificate_Installed || !client_Certificate_Installed || server_Accepts_Certificates)
        {
            Console.WriteLine("---- Test SKIPPED --------------");
            Console.WriteLine("Attempting to run the test in ToF, a ConditionalFact evaluated as FALSE.");
            Console.WriteLine("Root_Certificate_Installed evaluated as {0}", root_Certificate_Installed);
            Console.WriteLine("Client_Certificate_Installed evaluated as {0}", client_Certificate_Installed);
            Console.WriteLine("Server_Accepts_Certificates evaluated as {0}", server_Accepts_Certificates);
            return;
        }
#endif
        string clientCertThumb = null;
        EndpointAddress endpointAddress = null;
        string testString = "Hello";
        ChannelFactory<IWcfService> factory = null;
        IWcfService serviceProxy = null;

        try
        {
            // *** SETUP *** \\
            BasicHttpsBinding basicHttpsBinding = new BasicHttpsBinding(BasicHttpsSecurityMode.Transport);
            basicHttpsBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;

            endpointAddress = new EndpointAddress(new Uri(Endpoints.Https_ClientCertificateAuth_Address));
            clientCertThumb = ServiceUtilHelper.ClientCertificate.Thumbprint;

            factory = new ChannelFactory<IWcfService>(basicHttpsBinding, endpointAddress);
            factory.Credentials.ClientCertificate.SetCertificate(
                StoreLocation.CurrentUser,
                StoreName.My,
                X509FindType.FindByThumbprint,
                clientCertThumb);

            serviceProxy = factory.CreateChannel();

            // *** EXECUTE *** \\
            string result = serviceProxy.Echo(testString);

            // *** VALIDATE *** \\
            Assert.Equal(testString, result);

            // *** CLEANUP *** \\
            ((ICommunicationObject)serviceProxy).Close();
            factory.Close();
        }
        finally
        {
            // *** ENSURE CLEANUP *** \\
            ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)serviceProxy, factory);
        }
    }
示例#10
0
		public static MetadataSet BasicHttps_TransportWithMessageCredential ()
		{
			var exporter = new WsdlExporter ();
			
			var cd = new ContractDescription ("MyContract");
			
			var binding = new BasicHttpsBinding (BasicHttpsSecurityMode.TransportWithMessageCredential);
			
			exporter.ExportEndpoint (new ServiceEndpoint (
				cd, binding, new EndpointAddress (HttpsUri)));
			
			var doc = exporter.GetGeneratedMetadata ();
			return doc;
		}
示例#11
0
		public static MetadataSet BasicHttps_Certificate ()
		{
			var exporter = new WsdlExporter ();
			
			var cd = new ContractDescription ("MyContract");
			
			var binding = new BasicHttpsBinding ();
			binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;
			
			exporter.ExportEndpoint (new ServiceEndpoint (
				cd, binding, new EndpointAddress (HttpsUri)));
			
			var doc = exporter.GetGeneratedMetadata ();
			return doc;
		}
示例#12
0
    // Asking for PeerTrust alone should throw SecurityNegotiationException
    // if the certificate is not in the TrustedPeople store.  For this test
    // we use a valid chain-trusted certificate that we know is not in the
    // TrustedPeople store.

    public static void Https_SecModeTrans_CertValMode_PeerTrust_Fails_Not_In_TrustedPeople()
    {
        EndpointAddress endpointAddress = null;
        string testString = "Hello";
        ChannelFactory<IWcfService> factory = null;
        IWcfService serviceProxy = null;
        CommunicationException communicationException = null;

        try
        {
            // *** SETUP *** \\
            BasicHttpsBinding binding = new BasicHttpsBinding(BasicHttpsSecurityMode.Transport);
            binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
            endpointAddress = new EndpointAddress(new Uri(
                                Endpoints.Https_SecModeTrans_ClientCredTypeNone_ServerCertValModeChainTrust_Address));

            factory = new ChannelFactory<IWcfService>(binding, endpointAddress);
            factory.Credentials.ServiceCertificate.SslCertificateAuthentication = new X509ServiceCertificateAuthentication();
            factory.Credentials.ServiceCertificate.SslCertificateAuthentication.CertificateValidationMode = X509CertificateValidationMode.PeerTrust;

            serviceProxy = factory.CreateChannel();

            // *** EXECUTE *** \\
            try
            {
                serviceProxy.Echo(testString);
            }
            catch (CommunicationException ce)
            {
                communicationException = ce;
            }

            // *** VALIDATE *** \\
            Assert.True(communicationException != null, "Expected CommunicationException but no exception was thrown.");
            Assert.True(communicationException.GetType().Name == "SecurityNegotiationException",
                        String.Format("Expected SecurityNegotiationException but received {0}",
                                      communicationException.ToString()));

            // *** CLEANUP *** \\
            ((ICommunicationObject)serviceProxy).Close();
            factory.Close();
        }
        finally
        {
            // *** ENSURE CLEANUP *** \\
            ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)serviceProxy, factory);
        }
    }
        public EmailSubmissionServiceClient proxy(string scheme, string path)
        {
            EmailSubmissionServiceClient c = null;

            UriBuilder ub = new UriBuilder();

            ub.Scheme = scheme;
            ub.Path = path;
            ub.Host = HOST;

            EndpointAddress endPoint = new EndpointAddress(ub.Uri, new SpnEndpointIdentity(string.Empty));

            HttpBindingBase binding;

            if (scheme == HTTPS_SCHEME)
            {
                 binding = new BasicHttpsBinding();
                 //((BasicHttpsBinding)binding).
                ((BasicHttpsBinding)binding).Security.Mode = BasicHttpsSecurityMode.Transport;
                ((BasicHttpsBinding)binding).Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
            }
            else
            {
                 binding = new BasicHttpBinding();
                 ((BasicHttpBinding)binding).Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
                 ((BasicHttpBinding)binding).Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
            }

            c = new EmailSubmissionServiceClient(binding, endPoint);
            c.ClientCredentials.UserName.UserName = USER;
            c.ClientCredentials.UserName.Password = PWD;

            c.Open();

            if (c.InnerChannel != null)
            {
                c.InnerChannel.OperationTimeout = TimeSpan.FromMinutes(60);
            }

            return c;
        }
示例#14
0
    public static void ClientCertificate_EchoString()
    {
        string clientCertThumb = null;
        EndpointAddress endpointAddress = null;
        string testString = "Hello";
        ChannelFactory<IWcfService> factory = null;
        IWcfService serviceProxy = null;

        try
        {
            // *** SETUP *** \\
            BasicHttpsBinding basicHttpsBinding = new BasicHttpsBinding(BasicHttpsSecurityMode.Transport);
            basicHttpsBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;

            endpointAddress = new EndpointAddress(new Uri(Endpoints.Https_ClientCertificateAuth_Address));
            clientCertThumb = ServiceUtilHelper.ClientCertificate.Thumbprint;

            factory = new ChannelFactory<IWcfService>(basicHttpsBinding, endpointAddress);
            factory.Credentials.ClientCertificate.SetCertificate(
                StoreLocation.CurrentUser,
                StoreName.My,
                X509FindType.FindByThumbprint,
                clientCertThumb);

            serviceProxy = factory.CreateChannel();

            // *** EXECUTE *** \\
            string result = serviceProxy.Echo(testString);

            // *** VALIDATE *** \\
            Assert.Equal(testString, result);

            // *** CLEANUP *** \\
            ((ICommunicationObject)serviceProxy).Close();
            factory.Close();
        }
        finally
        {
            // *** ENSURE CLEANUP *** \\
            ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)serviceProxy, factory);
        }
    }
示例#15
0
 public static void Dump(BasicHttpsBinding binding)
 {
     Console.WriteLine ("HTTPS: {0} {1} {2} {3}",
                        binding.Name, binding.OpenTimeout, binding.Security.Mode,
                        binding.TransferMode);
 }
示例#16
0
 private Binding GetBinding()
 {
     var binding = new BasicHttpsBinding(BasicHttpsSecurityMode.Transport);
     binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
     return binding;
 }