Example #1
0
    static void Run()
    {
        SymmetricSecurityBindingElement sbe =
            new SymmetricSecurityBindingElement();

        sbe.MessageSecurityVersion       = MessageSecurityVersion.WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10;
        sbe.RequireSignatureConfirmation = true;
        //sbe.IncludeTimestamp = false;

        X509SecurityTokenParameters p =
            new X509SecurityTokenParameters(X509KeyIdentifierClauseType.Thumbprint, SecurityTokenInclusionMode.AlwaysToRecipient);

        p.RequireDerivedKeys = false;
        sbe.EndpointSupportingTokenParameters.Endorsing.Add(p);
        sbe.ProtectionTokenParameters =
            new X509SecurityTokenParameters(X509KeyIdentifierClauseType.Thumbprint, SecurityTokenInclusionMode.Never);
        //sbe.SetKeyDerivation (false);
        //sbe.MessageProtectionOrder = MessageProtectionOrder.SignBeforeEncrypt;
        HttpTransportBindingElement hbe =
            new HttpTransportBindingElement();
        CustomBinding    binding = new CustomBinding(new XBE(), sbe, hbe);
        X509Certificate2 cert    = new X509Certificate2("test.pfx", "mono");
        X509Certificate2 cert2   = cert;      //new X509Certificate2 ("test2.cer");
        FooProxy         proxy   = new FooProxy(binding,
                                                new EndpointAddress(new Uri("http://localhost:8080"), new X509CertificateEndpointIdentity(cert2)));

        //proxy.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None;
        proxy.ClientCredentials.ClientCertificate.Certificate = cert;
        proxy.Endpoint.Behaviors.Add(new StdErrInspectionBehavior());
        proxy.Open();
        Console.WriteLine(proxy.Echo("TEST FOR ECHO"));
    }
Example #2
0
    static void Run()
    {
        SymmetricSecurityBindingElement sbe =
            new SymmetricSecurityBindingElement();

        //sbe.IncludeTimestamp = false;
        //sbe.LocalClientSettings.DetectReplays = false;

        //X509SecurityTokenParameters p = new X509SecurityTokenParameters ();
        //sbe.EndpointSupportingTokenParameters.Endorsing.Add (p);
        sbe.ProtectionTokenParameters = new X509SecurityTokenParameters();
        sbe.ProtectionTokenParameters.InclusionMode = SecurityTokenInclusionMode.Never;
        sbe.SetKeyDerivation(false);
        sbe.MessageProtectionOrder = MessageProtectionOrder.SignBeforeEncrypt;
        HttpTransportBindingElement hbe =
            new HttpTransportBindingElement();
        CustomBinding    binding = new CustomBinding(new XBE(), sbe, hbe);
        X509Certificate2 cert    = new X509Certificate2("test.pfx", "mono");
        X509Certificate2 cert2   = cert;      //new X509Certificate2 ("test2.cer");
        FooProxy         proxy   = new FooProxy(binding,
                                                new EndpointAddress(new Uri("http://localhost:8080"), new X509CertificateEndpointIdentity(cert2)));

        //proxy.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None;
        proxy.ClientCredentials.ClientCertificate.Certificate = cert;
        proxy.Endpoint.Behaviors.Add(new StdErrInspectionBehavior());
        proxy.Open();
        Console.WriteLine(proxy.Echo(Message.CreateMessage(MessageVersion.Default, "http://tempuri.org/IFoo/Echo", "Request Input text.")));
    }
Example #3
0
    public static void Main()
    {
        FooProxy proxy = new FooProxy(String.Empty);

        proxy.Open();
        Console.WriteLine(proxy.Echo("TEST FOR ECHO"));
    }
Example #4
0
    public static void Main()
    {
        WSHttpBinding binding = new WSHttpBinding();

        binding.Security.Transport.ClientCredentialType     = HttpClientCredentialType.None;
        binding.Security.Message.EstablishSecurityContext   = false;
        binding.Security.Message.NegotiateServiceCredential = false;
        binding.Security.Message.ClientCredentialType       = MessageCredentialType.UserName;
        X509Certificate2 cert  = new X509Certificate2("test.pfx", "mono");
        FooProxy         proxy = new FooProxy(binding,
                                              new EndpointAddress(new Uri("http://localhost:8080/"), new X509CertificateEndpointIdentity(cert)));

        //proxy.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None;
        //proxy.ClientCredentials.ClientCertificate.Certificate = cert;
        proxy.ClientCredentials.UserName.UserName = "******";
        proxy.Endpoint.Behaviors.Add(new StdErrInspectionBehavior());
        proxy.Open();
        try {
            Console.WriteLine(proxy.Echo("TEST FOR ECHO"));
        } catch (MessageSecurityException ex) {
            FaultException inner = ex.InnerException as FaultException;
            if (inner == null)
            {
                throw;
            }
            Console.WriteLine(inner.Reason);
            Console.WriteLine(ex);
        }
    }
Example #5
0
    public static void Main()
    {
        FooProxy proxy = new FooProxy(
            new BasicHttpBinding(),
            new EndpointAddress("http://localhost:8080/"));

        proxy.Open();
        Console.WriteLine(proxy.Echo("TEST FOR ECHO"));
        Console.WriteLine(proxy.Add(1000, 2000));
        Console.WriteLine("done");
    }
Example #6
0
    public static void Main(string [] args)
    {
        bool     bar     = args.FirstOrDefault(s => s == "--bar") != null;
        var      binding = new BasicHttpBinding();
        FooProxy proxy   = new FooProxy(binding,
                                        new EndpointAddress("http://localhost:8080/samplesvc3.svc/" + (bar ? "bar" : "foo")));

        proxy.Open();
        Console.WriteLine(proxy.Echo("TEST FOR ECHO"));
        Console.WriteLine(proxy.Add(1000, 2000));
        Console.WriteLine("done");
    }
Example #7
0
    static void Run()
    {
        var binding = new NetTcpBinding();

        binding.Security.Mode = SecurityMode.Message;
        binding.Security.Message.ClientCredentialType = MessageCredentialType.Certificate;
        X509Certificate2 cert  = new X509Certificate2("test.pfx", "mono");
        FooProxy         proxy = new FooProxy(binding,
                                              new EndpointAddress(new Uri("net.tcp://localhost:8080/"), new X509CertificateEndpointIdentity(cert)));

        proxy.ClientCredentials.ClientCertificate.Certificate = cert;
        proxy.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None;
        proxy.Open();
        Console.WriteLine(proxy.Echo("TEST FOR ECHO"));
    }
Example #8
0
    static void Run()
    {
        FooProxy proxy = new FooProxy(
            new BasicHttpBinding(),
            new EndpointAddress("http://localhost:8080/"));

        proxy.Open();

        Message req = Message.CreateMessage(MessageVersion.Soap11, "http://tempuri.org/IFoo/Echo");
        Message res = proxy.Echo(req);

        using (XmlWriter w = XmlWriter.Create(Console.Out)) {
            res.WriteMessage(w);
        }
    }
Example #9
0
    static void Run()
    {
        WSHttpBinding binding = new WSHttpBinding();

        binding.Security.Message.EstablishSecurityContext   = false;
        binding.Security.Message.NegotiateServiceCredential = false;
        binding.Security.Message.ClientCredentialType       = MessageCredentialType.Certificate;
        X509Certificate2 cert  = new X509Certificate2("test.pfx", "mono");
        FooProxy         proxy = new FooProxy(binding,
                                              new EndpointAddress(new Uri("http://localhost:8080/"), new X509CertificateEndpointIdentity(cert)));

        proxy.Endpoint.Behaviors.Add(new StdErrInspectionBehavior());
        proxy.ClientCredentials.ClientCertificate.Certificate = cert;
        proxy.Open();
        Console.WriteLine(proxy.Echo("TEST FOR ECHO"));
    }
Example #10
0
    static void Run(string user, string pass)
    {
        var binding = new BasicHttpBinding();

        binding.Security.Mode =
            BasicHttpSecurityMode.TransportCredentialOnly;
        binding.Security.Transport.ClientCredentialType =
            HttpClientCredentialType.Basic;
        FooProxy proxy = new FooProxy(binding,
                                      new EndpointAddress("http://localhost:8080/auth.svc"));

        proxy.ClientCredentials.UserName.UserName = user;
        proxy.ClientCredentials.UserName.Password = pass;
        proxy.Open();
        Console.WriteLine(proxy.Echo("TEST FOR ECHO"));
        Console.WriteLine(proxy.Add(1000, 2000));
        Console.WriteLine("done");
    }
Example #11
0
    static void Run()
    {
        SymmetricSecurityBindingElement sbe =
            new SymmetricSecurityBindingElement();

        sbe.ProtectionTokenParameters =
            new SspiSecurityTokenParameters();
        HttpTransportBindingElement hbe =
            new HttpTransportBindingElement();
        CustomBinding    binding = new CustomBinding(sbe, hbe);
        X509Certificate2 cert    = new X509Certificate2("test.cer");
        FooProxy         proxy   = new FooProxy(binding,
                                                //new EndpointAddress (new Uri ("http://localhost:8080")));
                                                new EndpointAddress(new Uri("http://localhost:8080"), new UpnEndpointIdentity("PC\\atsushi")));

        //new EndpointAddress (new Uri ("http://localhost:8080"), new SpnEndpointIdentity ("PC/atsushi")));
        proxy.Open();
        Console.WriteLine(proxy.Echo("TEST FOR ECHO"));
    }
Example #12
0
    static void Run()
    {
        SymmetricSecurityBindingElement sbe =
            new SymmetricSecurityBindingElement();

        sbe.ProtectionTokenParameters =
            new SslSecurityTokenParameters();
        HttpTransportBindingElement hbe =
            new HttpTransportBindingElement();
        CustomBinding    binding = new CustomBinding(sbe, hbe);
        X509Certificate2 cert    = new X509Certificate2("test.cer");
        FooProxy         proxy   = new FooProxy(binding,
                                                new EndpointAddress(new Uri("http://localhost:8080"), new X509CertificateEndpointIdentity(cert)));

        proxy.ClientCredentials.ServiceCertificate.Authentication
        .CertificateValidationMode =
            X509CertificateValidationMode.None;
//		proxy.Endpoint.Behaviors.Add (new StdErrInspectionBehavior ());
        proxy.Open();
        Console.WriteLine(proxy.Echo("TEST FOR ECHO"));
    }
Example #13
0
    static void Run()
    {
        WSHttpBinding binding = new WSHttpBinding();

        //binding.Security.Message.EstablishSecurityContext = false;
        binding.Security.Message.NegotiateServiceCredential = false;
        binding.Security.Message.ClientCredentialType       =
            MessageCredentialType.IssuedToken;
        X509Certificate2 cert2 = new X509Certificate2("test.cer");
        // DefaultCertificate does not work here...
        FooProxy proxy = new FooProxy(binding,
                                      new EndpointAddress(new Uri("http://localhost:8080"),
                                                          new X509CertificateEndpointIdentity(cert2)));

        proxy.ClientCredentials.ServiceCertificate.Authentication
        .CertificateValidationMode =
            X509CertificateValidationMode.None;
        proxy.ClientCredentials.ServiceCertificate.Authentication
        .RevocationMode = X509RevocationMode.NoCheck;
        //proxy.Open ();
        Console.WriteLine(proxy.Echo("TEST FOR ECHO"));
    }
Example #14
0
    static void Run(string issuerUri, string issuerCertFile)
    {
        SymmetricSecurityBindingElement sbe =
            new SymmetricSecurityBindingElement();
        IssuedSecurityTokenParameters ip =
            new IssuedSecurityTokenParameters();

        ip.ClaimTypeRequirements.Add(new ClaimTypeRequirement(
                                         ClaimTypes.PPID));
        //ClaimTypes.Email));
        if (issuerUri != null)
        {
            // if exists, then a managed card is required.
            ip.IssuerAddress = new EndpointAddress(new Uri(issuerUri),
                                                   new X509CertificateEndpointIdentity(new X509Certificate2(issuerCertFile)));
        }
        X509Certificate2 cert2  = new X509Certificate2("test.cer");
        EndpointAddress  target =
            new EndpointAddress(new Uri("http://localhost:8080"),
                                new X509CertificateEndpointIdentity(cert2));

        sbe.ProtectionTokenParameters            = ip;
        sbe.LocalClientSettings.IdentityVerifier =
            new MyVerifier();
        HttpTransportBindingElement hbe =
            new HttpTransportBindingElement();
        CustomBinding binding = new CustomBinding(sbe, hbe);
        // DefaultCertificate does not work here...
        FooProxy proxy = new FooProxy(binding, target);

        proxy.ClientCredentials.ServiceCertificate.Authentication
        .CertificateValidationMode =
            X509CertificateValidationMode.None;
        proxy.ClientCredentials.ServiceCertificate.Authentication
        .RevocationMode = X509RevocationMode.NoCheck;
        //proxy.ClientCredentials.IssuedToken.LocalIssuerAddress = ip.IssuerAddress;
        //proxy.ClientCredentials.IssuedToken.LocalIssuerBinding = ip.IssuerBinding;
        Console.WriteLine(proxy.Echo("TEST FOR ECHO"));
    }
Example #15
0
    static void Run()
    {
        SymmetricSecurityBindingElement sbe =
            new SymmetricSecurityBindingElement();

        //sbe.IncludeTimestamp = false;
        //sbe.LocalClientSettings.DetectReplays = false;

        sbe.ProtectionTokenParameters = new X509SecurityTokenParameters();
        sbe.ProtectionTokenParameters.InclusionMode = SecurityTokenInclusionMode.Never;
        sbe.SetKeyDerivation(false);
        sbe.MessageProtectionOrder = MessageProtectionOrder.SignBeforeEncrypt;
        HttpTransportBindingElement hbe =
            new HttpTransportBindingElement();
        CustomBinding    binding = new CustomBinding(new XBE(), sbe, hbe);
        X509Certificate2 cert    = new X509Certificate2("test.cer");
        FooProxy         proxy   = new FooProxy(binding,
                                                new EndpointAddress(new Uri("http://localhost:8080"), new X509CertificateEndpointIdentity(cert)));

        proxy.Endpoint.Behaviors.Add(new StdErrInspectionBehavior());
        proxy.Open();
        Console.WriteLine(proxy.Echo("TEST FOR ECHO"));
    }
Example #16
0
    static void Run()
    {
        SymmetricSecurityBindingElement sbe =
            new SymmetricSecurityBindingElement();

        UserNameSecurityTokenParameters p =
            new UserNameSecurityTokenParameters();

        p.RequireDerivedKeys = false;
        sbe.EndpointSupportingTokenParameters.SignedEncrypted.Add(p);
        sbe.ProtectionTokenParameters =
            new X509SecurityTokenParameters(X509KeyIdentifierClauseType.Thumbprint, SecurityTokenInclusionMode.Never);
        HttpTransportBindingElement hbe =
            new HttpTransportBindingElement();
        CustomBinding    binding = new CustomBinding(new XBE(), sbe, hbe);
        X509Certificate2 cert    = new X509Certificate2("test.pfx", "mono");
        FooProxy         proxy   = new FooProxy(binding,
                                                new EndpointAddress(new Uri("http://localhost:8080"), new X509CertificateEndpointIdentity(cert)));

        proxy.ClientCredentials.UserName.UserName = "******";
        proxy.Endpoint.Behaviors.Add(new StdErrInspectionBehavior());
        proxy.Open();
        Console.WriteLine(proxy.Echo("TEST FOR ECHO"));
    }