Author: atsushi
Date: 2007-02-26 09:56:17 -0500 (Mon, 26 Feb 2007)
New Revision: 73431
Added:
trunk/olive/samples/services/secure-message/samplecli9.cs
trunk/olive/samples/services/secure-message/samplesvc3.exe.config
trunk/olive/samples/services/secure-message/samplesvc8.exe.config
trunk/olive/samples/services/secure-message/samplesvc9.cs
trunk/olive/samples/services/secure-message/samplesvc9.exe.config
trunk/olive/samples/services/secure-message/test.cer
trunk/olive/samples/services/secure-message/test2.pfx
Modified:
trunk/olive/samples/services/secure-message/ChangeLog
trunk/olive/samples/services/secure-message/Makefile
Log:
2007-02-26 Atsushi Enomoto <[EMAIL PROTECTED]>
* samplesvc3.exe.config, samplesvc8.exe.config,
samplesvc9.exe.config : trace helpers.
* test.cer, test2.pfx : forgot to add.
* samplesvc9.cs, samplecli9.cs : SignedEncrypted token sample.
* Makefile : added new test.
Modified: trunk/olive/samples/services/secure-message/ChangeLog
===================================================================
--- trunk/olive/samples/services/secure-message/ChangeLog 2007-02-26
14:52:01 UTC (rev 73430)
+++ trunk/olive/samples/services/secure-message/ChangeLog 2007-02-26
14:56:17 UTC (rev 73431)
@@ -1,3 +1,11 @@
+2007-02-26 Atsushi Enomoto <[EMAIL PROTECTED]>
+
+ * samplesvc3.exe.config, samplesvc8.exe.config,
+ samplesvc9.exe.config : trace helpers.
+ * test.cer, test2.pfx : forgot to add.
+ * samplesvc9.cs, samplecli9.cs : SignedEncrypted token sample.
+ * Makefile : added new test.
+
2007-02-20 Atsushi Enomoto <[EMAIL PROTECTED]>
* samplecli4.cs : make it more strict to verify x509 tokens.
Modified: trunk/olive/samples/services/secure-message/Makefile
===================================================================
--- trunk/olive/samples/services/secure-message/Makefile 2007-02-26
14:52:01 UTC (rev 73430)
+++ trunk/olive/samples/services/secure-message/Makefile 2007-02-26
14:56:17 UTC (rev 73431)
@@ -6,8 +6,15 @@
samplesvc5.exe samplecli5.exe \
samplesvc6.exe samplecli6.exe \
samplesvc7.exe samplecli7.exe \
- samplesvc8.exe samplecli8.exe
+ samplesvc8.exe samplecli8.exe \
+ samplesvc9.exe samplecli9.exe
+samplesvc9.exe : samplesvc9.cs
+ gmcs -pkg:olive samplesvc9.cs Inspector.cs
+
+samplecli9.exe : samplecli9.cs
+ gmcs -pkg:olive samplecli9.cs Inspector.cs
+
samplesvc8.exe : samplesvc8.cs
gmcs -pkg:olive samplesvc8.cs Inspector.cs
@@ -65,4 +72,5 @@
rm -f samplesvc6.exe samplesvc6.exe.mdb samplecli6.exe
samplecli6.exe.mdb
rm -f samplesvc7.exe samplesvc7.exe.mdb samplecli7.exe
samplecli7.exe.mdb
rm -f samplesvc8.exe samplesvc8.exe.mdb samplecli8.exe
samplecli8.exe.mdb
+ rm -f samplesvc9.exe samplesvc9.exe.mdb samplecli9.exe
samplecli9.exe.mdb
Added: trunk/olive/samples/services/secure-message/samplecli9.cs
===================================================================
--- trunk/olive/samples/services/secure-message/samplecli9.cs 2007-02-26
14:52:01 UTC (rev 73430)
+++ trunk/olive/samples/services/secure-message/samplecli9.cs 2007-02-26
14:56:17 UTC (rev 73431)
@@ -0,0 +1,133 @@
+using System;
+using System.IO;
+using System.Net;
+using System.Net.Security;
+using System.Xml;
+using System.Security.Cryptography;
+using System.Security.Cryptography.X509Certificates;
+using System.IdentityModel.Selectors;
+using System.IdentityModel.Tokens;
+using System.ServiceModel;
+using System.ServiceModel.Channels;
+using System.ServiceModel.Security;
+using System.ServiceModel.Security.Tokens;
+
+public class Tset
+{
+ public static void Main ()
+ {
+ try {
+ Run ();
+ } catch (MessageSecurityException ex) {
+ Console.WriteLine ("MessageSecurityException::::::");
+ FaultException f = ex.InnerException as FaultException;
+ if (f != null)
+ using (XmlWriter w = XmlWriter.Create
(Console.Out)) {
+ f.CreateMessageFault ().WriteTo (w,
EnvelopeVersion.Soap12);
+ }
+ else
+ Console.WriteLine (ex);
+ } catch (WebException ex) {
+ Console.WriteLine (ex);
+ using (StreamReader sr = new StreamReader
(ex.Response.GetResponseStream ()))
+ Console.WriteLine (sr.ReadToEnd ());
+ }
+ }
+
+ 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 = "rupert";
+ proxy.Endpoint.Behaviors.Add (new StdErrInspectionBehavior ());
+ proxy.Open ();
+ Console.WriteLine (proxy.Echo ("TEST FOR ECHO"));
+ }
+
+ class XBE : BindingElement
+ {
+ public override bool CanBuildChannelFactory<T> (BindingContext
ctx)
+ {
+ return ctx.CanBuildInnerChannelFactory<T> ();
+ }
+
+ public override bool CanBuildChannelListener<T> (BindingContext
ctx)
+ {
+ return ctx.CanBuildInnerChannelListener<T> ();
+ }
+
+ void DumpParts (ScopedMessagePartSpecification smp)
+ {
+ foreach (string name in smp.Actions) {
+ MessagePartSpecification mp;
+ smp.TryGetParts (name, out mp);
+ Console.WriteLine ("{0}: {1}", name,
mp.IsBodyIncluded);
+ foreach (XmlQualifiedName qn in mp.HeaderTypes)
+ Console.WriteLine (qn);
+ }
+ Console.WriteLine ("ChannelParts: {0}",
smp.ChannelParts.IsBodyIncluded);
+ foreach (XmlQualifiedName qn in
smp.ChannelParts.HeaderTypes)
+ Console.WriteLine (qn);
+ }
+
+ public override IChannelFactory<T> BuildChannelFactory<T>
(BindingContext ctx)
+ {
+ ChannelProtectionRequirements cp =
ctx.BindingParameters.Find<ChannelProtectionRequirements> ();
+ DumpParts (cp.IncomingEncryptionParts);
+ DumpParts (cp.IncomingSignatureParts);
+ DumpParts (cp.OutgoingEncryptionParts);
+ DumpParts (cp.OutgoingSignatureParts);
+ return ctx.BuildInnerChannelFactory<T> ();
+ }
+
+ public override IChannelListener<T> BuildChannelListener<T>
(BindingContext ctx)
+ {
+ return ctx.BuildInnerChannelListener<T> ();
+ }
+
+ public override BindingElement Clone ()
+ {
+ return this;
+ }
+
+ public override T GetProperty<T> (BindingContext ctx)
+ {
+ return ctx.GetInnerProperty<T> ();
+ }
+ }
+}
+
+//[ServiceContract (ProtectionLevel = ProtectionLevel.None)]// (SessionMode =
SessionMode.NotAllowed)]
+[ServiceContract]
+public interface IFoo
+{
+ [OperationContract]
+ string Echo (string msg);
+}
+
+public class FooProxy : ClientBase<IFoo>, IFoo
+{
+ public FooProxy (Binding binding, EndpointAddress address)
+ : base (binding, address)
+ {
+ }
+
+ public string Echo (string msg)
+ {
+ return Channel.Echo (msg);
+ }
+}
+
Added: trunk/olive/samples/services/secure-message/samplesvc3.exe.config
===================================================================
--- trunk/olive/samples/services/secure-message/samplesvc3.exe.config
2007-02-26 14:52:01 UTC (rev 73430)
+++ trunk/olive/samples/services/secure-message/samplesvc3.exe.config
2007-02-26 14:56:17 UTC (rev 73431)
@@ -0,0 +1,15 @@
+<configuration>
+ <system.diagnostics>
+ <sources>
+ <source name="System.ServiceModel"
+ switchValue="Warning"
+ propagateActivity="true">
+ <listeners>
+ <add name="traceListener"
+ type="System.Diagnostics.TextWriterTraceListener"
+ initializeData= "Traces.svclog" />
+ </listeners>
+ </source>
+ </sources>
+ </system.diagnostics>
+</configuration>
Added: trunk/olive/samples/services/secure-message/samplesvc8.exe.config
===================================================================
--- trunk/olive/samples/services/secure-message/samplesvc8.exe.config
2007-02-26 14:52:01 UTC (rev 73430)
+++ trunk/olive/samples/services/secure-message/samplesvc8.exe.config
2007-02-26 14:56:17 UTC (rev 73431)
@@ -0,0 +1,15 @@
+<configuration>
+ <system.diagnostics>
+ <sources>
+ <source name="System.ServiceModel"
+ switchValue="Warning"
+ propagateActivity="true">
+ <listeners>
+ <add name="traceListener"
+ type="System.Diagnostics.TextWriterTraceListener"
+ initializeData= "Traces.svclog" />
+ </listeners>
+ </source>
+ </sources>
+ </system.diagnostics>
+</configuration>
Added: trunk/olive/samples/services/secure-message/samplesvc9.cs
===================================================================
--- trunk/olive/samples/services/secure-message/samplesvc9.cs 2007-02-26
14:52:01 UTC (rev 73430)
+++ trunk/olive/samples/services/secure-message/samplesvc9.cs 2007-02-26
14:56:17 UTC (rev 73431)
@@ -0,0 +1,85 @@
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Security.Cryptography.X509Certificates;
+using System.IdentityModel.Selectors;
+using System.IdentityModel.Tokens;
+using System.ServiceModel;
+using System.ServiceModel.Channels;
+using System.ServiceModel.Description;
+using System.ServiceModel.Dispatcher;
+using System.ServiceModel.Security;
+using System.ServiceModel.Security.Tokens;
+
+ public class GodUserNamePasswordValidator : UserNamePasswordValidator
+ {
+ public override void Validate (string userName, string password)
+ {
+ // God allows everyone.
+ }
+ }
+
+public class Test
+{
+ public static void Main ()
+ {
+ SymmetricSecurityBindingElement sbe =
+ new SymmetricSecurityBindingElement ();
+ //sbe.MessageSecurityVersion =
MessageSecurityVersion.WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10;
+ //sbe.RequireSignatureConfirmation = true;
+
+ sbe.ProtectionTokenParameters =
+ new X509SecurityTokenParameters
(X509KeyIdentifierClauseType.Thumbprint, SecurityTokenInclusionMode.Never);
+ UserNameSecurityTokenParameters p =
+ new UserNameSecurityTokenParameters ();
+ p.RequireDerivedKeys = false;
+ sbe.EndpointSupportingTokenParameters.SignedEncrypted.Add (p);
+ //sbe.EndpointSupportingTokenParameters.Signed.Add (p);
+ ServiceHost host = new ServiceHost (typeof (Foo));
+ HttpTransportBindingElement hbe =
+ new HttpTransportBindingElement ();
+ CustomBinding binding = new CustomBinding (sbe, hbe);
+ binding.ReceiveTimeout = TimeSpan.FromSeconds (5);
+ host.AddServiceEndpoint ("IFoo",
+ binding, new Uri ("http://localhost:8080"));
+ ServiceCredentials cred = new ServiceCredentials ();
+ cred.ServiceCertificate.Certificate =
+ new X509Certificate2 ("test.pfx", "mono");
+ cred.UserNameAuthentication.UserNamePasswordValidationMode =
+ UserNamePasswordValidationMode.Custom;
+ cred.UserNameAuthentication.CustomUserNamePasswordValidator =
+ new GodUserNamePasswordValidator ();
+ host.Description.Behaviors.Add (cred);
+ host.Description.Behaviors.Find<ServiceDebugBehavior> ()
+ .IncludeExceptionDetailInFaults = true;
+ foreach (ServiceEndpoint se in host.Description.Endpoints)
+ se.Behaviors.Add (new StdErrInspectionBehavior ());
+ ServiceMetadataBehavior smb = new ServiceMetadataBehavior ();
+ smb.HttpGetEnabled = true;
+ smb.HttpGetUrl = new Uri ("http://localhost:8080/wsdl");
+ host.Description.Behaviors.Add (smb);
+ host.Open ();
+ Console.WriteLine ("Hit [CR] key to close ...");
+ Console.ReadLine ();
+ host.Close ();
+ }
+}
+
+[ServiceContract]// (SessionMode = SessionMode.NotAllowed)]
+public interface IFoo
+{
+ [OperationContract]
+ string Echo (string msg);
+}
+
+[ServiceBehavior (IncludeExceptionDetailInFaults = true)]
+class Foo : IFoo
+{
+ public string Echo (string msg)
+ {
+Console.WriteLine (msg);
+ return msg + msg;
+ //throw new NotImplementedException ();
+ }
+}
+
Added: trunk/olive/samples/services/secure-message/samplesvc9.exe.config
===================================================================
--- trunk/olive/samples/services/secure-message/samplesvc9.exe.config
2007-02-26 14:52:01 UTC (rev 73430)
+++ trunk/olive/samples/services/secure-message/samplesvc9.exe.config
2007-02-26 14:56:17 UTC (rev 73431)
@@ -0,0 +1,15 @@
+<configuration>
+ <system.diagnostics>
+ <sources>
+ <source name="System.ServiceModel"
+ switchValue="Warning"
+ propagateActivity="true">
+ <listeners>
+ <add name="traceListener"
+ type="System.Diagnostics.TextWriterTraceListener"
+ initializeData= "Traces.svclog" />
+ </listeners>
+ </source>
+ </sources>
+ </system.diagnostics>
+</configuration>
Added: trunk/olive/samples/services/secure-message/test.cer
===================================================================
--- trunk/olive/samples/services/secure-message/test.cer 2007-02-26
14:52:01 UTC (rev 73430)
+++ trunk/olive/samples/services/secure-message/test.cer 2007-02-26
14:56:17 UTC (rev 73431)
@@ -0,0 +1,12 @@
+-----BEGIN CERTIFICATE-----
+MIIBxTCCAS6gAwIBAgIQdpYkgiI1/kOLutzrMY5i1DANBgkqhkiG9w0BAQUFADAg
+MR4wHAYDVQQDExVNb25vIFRlc3QgUm9vdCBBZ2VuY3kwHhcNMDYwNzIxMDYzODUz
+WhcNMzkxMjMxMDk1OTU5WjAkMSIwIAYDVQQDExlQb3Vwb3Uncy1Tb2Z0d2FyZS1G
+YWN0b3J5MIGdMA0GCSqGSIb3DQEBAQUAA4GLADCBhwKBgQDSD0FU/Ymimao4JYiq
+VsgMYCVM1iRrfWtQwJ1/qUMfGj8GgmXyBcGxUz/cjpkn5n/TlzNVanjnNRYJS0FZ
+ifd4AbRnA3kON3R+YHKjWwzPqwoFHA7UQgRrrR7/QmuHOlXBPDOd/SgKjRtz6uWN
+2er0nYkwJyp/ihUktx1PLu7CWQIBETANBgkqhkiG9w0BAQUFAAOBgQCJzIlI/aUc
+M6/KHi6pgBJ77YbUcTXAlVFF7IPvOcVggC+OTXiRGK4tw5Q76QJK86HBE4QdUOd0
+1eASPfJwCFNCq3X8g0bWRAukny8YON7XcLNP3psXRvNp2rudvSFJr51Eq1XtngZH
+MPDAFYCl4cBXvnlQZBwaHaWMGgngRCKnNA==
+-----END CERTIFICATE-----
Added: trunk/olive/samples/services/secure-message/test2.pfx
===================================================================
(Binary files differ)
Property changes on: trunk/olive/samples/services/secure-message/test2.pfx
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches