Author: atsushi
Date: 2007-04-05 03:31:44 -0400 (Thu, 05 Apr 2007)
New Revision: 75416
Added:
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel/EndpointIdentityTest.cs
Modified:
trunk/olive/class/System.ServiceModel/System.ServiceModel/ChangeLog
trunk/olive/class/System.ServiceModel/System.ServiceModel/Constants.cs
trunk/olive/class/System.ServiceModel/System.ServiceModel/EndpointAddress.cs
trunk/olive/class/System.ServiceModel/System.ServiceModel/EndpointIdentity.cs
trunk/olive/class/System.ServiceModel/System.ServiceModel/X509CertificateEndpointIdentity.cs
trunk/olive/class/System.ServiceModel/System.ServiceModel_test.dll.sources
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel/ChangeLog
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel/EndpointAddressTest.cs
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel/WSHttpBindingTest.cs
Log:
2007-04-05 Atsushi Enomoto <[EMAIL PROTECTED]>
* Constants.cs : added WsaIdentityUri.
* EndpointIdentity.cs : implemented ToString().
* X509CertificateEndpointIdentity.cs : Initialize() was missing.
* EndpointAddress.cs : implemented WriteContentsTo(), which is
actually what WriteTo() should just call. Handle X509 identity
as its own way to be serialized.
* EndpointAddressTest.cs : added WriteContentsTo and WriteTo tests
with WSAddressing10 mode.
* WSHttpBindingTest.cs : added test for IssuedToken security.
* EndpointIdentityTest.cs : new test (not working yet).
Modified: trunk/olive/class/System.ServiceModel/System.ServiceModel/ChangeLog
===================================================================
--- trunk/olive/class/System.ServiceModel/System.ServiceModel/ChangeLog
2007-04-05 07:25:34 UTC (rev 75415)
+++ trunk/olive/class/System.ServiceModel/System.ServiceModel/ChangeLog
2007-04-05 07:31:44 UTC (rev 75416)
@@ -1,3 +1,12 @@
+2007-04-05 Atsushi Enomoto <[EMAIL PROTECTED]>
+
+ * Constants.cs : added WsaIdentityUri.
+ * EndpointIdentity.cs : implemented ToString().
+ * X509CertificateEndpointIdentity.cs : Initialize() was missing.
+ * EndpointAddress.cs : implemented WriteContentsTo(), which is
+ actually what WriteTo() should just call. Handle X509 identity
+ as its own way to be serialized.
+
2007-04-02 Atsushi Enomoto <[EMAIL PROTECTED]>
* ClientCredentialsSecurityTokenManager.cs : support mutual sslnego.
Modified: trunk/olive/class/System.ServiceModel/System.ServiceModel/Constants.cs
===================================================================
--- trunk/olive/class/System.ServiceModel/System.ServiceModel/Constants.cs
2007-04-05 07:25:34 UTC (rev 75415)
+++ trunk/olive/class/System.ServiceModel/System.ServiceModel/Constants.cs
2007-04-05 07:31:44 UTC (rev 75416)
@@ -36,6 +36,7 @@
public const string WSBasicSecurityProfileCore1 =
"http://ws-i.org/profiles/basic-security/core/1.0";
public const string WsaAnonymousUri =
"http://www.w3.org/2005/08/addressing/anonymous";
+ public const string WsaIdentityUri =
"http://schemas.xmlsoap.org/ws/2006/02/addressingidentity";
public const string MSSerialization =
"http://schemas.microsoft.com/2003/10/Serialization/";
Modified:
trunk/olive/class/System.ServiceModel/System.ServiceModel/EndpointAddress.cs
===================================================================
---
trunk/olive/class/System.ServiceModel/System.ServiceModel/EndpointAddress.cs
2007-04-05 07:25:34 UTC (rev 75415)
+++
trunk/olive/class/System.ServiceModel/System.ServiceModel/EndpointAddress.cs
2007-04-05 07:31:44 UTC (rev 75416)
@@ -30,6 +30,9 @@
using System.IO;
using System.Reflection;
using System.Resources;
+using System.Runtime.Serialization;
+using System.Security.Cryptography.X509Certificates;
+using System.Security.Cryptography.Xml;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;
@@ -296,19 +299,42 @@
AddressingVersion addressingVersion,
XmlDictionaryWriter writer)
{
- throw new NotImplementedException ();
+ if (addressingVersion ==
AddressingVersion.WSAddressing10) {
+ writer.WriteStartElement ("Address",
addressingVersion.Namespace);
+ writer.WriteString (Uri.AbsoluteUri);
+ writer.WriteEndElement ();
+
+ if (Identity == null)
+ return;
+
+ writer.WriteStartElement ("Identity",
Constants.WsaIdentityUri);
+ X509CertificateEndpointIdentity x509 =
+ Identity as
X509CertificateEndpointIdentity;
+ if (x509 != null) {
+ KeyInfo ki = new KeyInfo ();
+ KeyInfoX509Data x = new KeyInfoX509Data
();
+ foreach (X509Certificate2 cert in
x509.Certificates)
+ x.AddCertificate (cert);
+ ki.AddClause (x);
+ ki.GetXml ().WriteTo (writer);
+ } else {
+ DataContractSerializer ds = new
DataContractSerializer (Identity.IdentityClaim.GetType ());
+ ds.WriteObject (writer,
Identity.IdentityClaim);
+ }
+ writer.WriteEndElement ();
+ } else {
+ writer.WriteString (Uri.AbsoluteUri);
+ }
}
- [MonoTODO]
public void WriteContentsTo (
AddressingVersion addressingVersion,
XmlWriter writer)
{
- WriteTo (addressingVersion,
+ WriteContentsTo (addressingVersion,
XmlDictionaryWriter.CreateDictionaryWriter
(writer));
}
- [MonoTODO]
public void WriteTo (
AddressingVersion addressingVersion,
XmlDictionaryWriter writer)
@@ -316,7 +342,6 @@
WriteTo (addressingVersion, writer,
"EndpointReference", addressingVersion.Namespace);
}
- [MonoTODO]
public void WriteTo (
AddressingVersion addressingVersion, XmlWriter writer)
{
@@ -324,7 +349,6 @@
XmlDictionaryWriter.CreateDictionaryWriter
(writer));
}
- [MonoTODO]
public void WriteTo (
AddressingVersion addressingVersion,
XmlDictionaryWriter writer,
@@ -332,17 +356,16 @@
XmlDictionaryString ns)
{
writer.WriteStartElement (localname, ns);
- writer.WriteString (Uri.AbsoluteUri);
+ WriteContentsTo (addressingVersion, writer);
writer.WriteEndElement ();
}
- [MonoTODO]
public void WriteTo (
AddressingVersion addressingVersion,
XmlWriter writer, string localname, string ns)
{
writer.WriteStartElement (localname, ns);
- writer.WriteString (Uri.AbsoluteUri);
+ WriteContentsTo (addressingVersion, writer);
writer.WriteEndElement ();
}
}
Modified:
trunk/olive/class/System.ServiceModel/System.ServiceModel/EndpointIdentity.cs
===================================================================
---
trunk/olive/class/System.ServiceModel/System.ServiceModel/EndpointIdentity.cs
2007-04-05 07:25:34 UTC (rev 75415)
+++
trunk/olive/class/System.ServiceModel/System.ServiceModel/EndpointIdentity.cs
2007-04-05 07:31:44 UTC (rev 75416)
@@ -121,10 +121,9 @@
return comparer.GetHashCode (claim);
}
- [MonoTODO]
public override string ToString ()
{
- return base.ToString ();
+ return String.Concat ("identity(", claim, ")");
}
protected void Initialize (Claim claim)
Modified:
trunk/olive/class/System.ServiceModel/System.ServiceModel/X509CertificateEndpointIdentity.cs
===================================================================
---
trunk/olive/class/System.ServiceModel/System.ServiceModel/X509CertificateEndpointIdentity.cs
2007-04-05 07:25:34 UTC (rev 75415)
+++
trunk/olive/class/System.ServiceModel/System.ServiceModel/X509CertificateEndpointIdentity.cs
2007-04-05 07:31:44 UTC (rev 75416)
@@ -45,6 +45,7 @@
if (cert == null)
throw new ArgumentNullException ("cert");
primary = cert;
+ Initialize (Claim.CreateThumbprintClaim
(cert.GetCertHash ()));
}
public X509CertificateEndpointIdentity (
Modified:
trunk/olive/class/System.ServiceModel/System.ServiceModel_test.dll.sources
===================================================================
--- trunk/olive/class/System.ServiceModel/System.ServiceModel_test.dll.sources
2007-04-05 07:25:34 UTC (rev 75415)
+++ trunk/olive/class/System.ServiceModel/System.ServiceModel_test.dll.sources
2007-04-05 07:31:44 UTC (rev 75416)
@@ -84,6 +84,7 @@
System.ServiceModel/EndpointAddressBuilderTest.cs
System.ServiceModel/EndpointAddressTest.cs
System.ServiceModel/EndpointBehaviorCollectionTest.cs
+System.ServiceModel/EndpointIdentityTest.cs
System.ServiceModel/FaultCodeTest.cs
System.ServiceModel/FaultReasonTest.cs
System.ServiceModel/IntegratedConnectionTest.cs
Modified:
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel/ChangeLog
===================================================================
--- trunk/olive/class/System.ServiceModel/Test/System.ServiceModel/ChangeLog
2007-04-05 07:25:34 UTC (rev 75415)
+++ trunk/olive/class/System.ServiceModel/Test/System.ServiceModel/ChangeLog
2007-04-05 07:31:44 UTC (rev 75416)
@@ -1,3 +1,10 @@
+2007-04-05 Atsushi Enomoto <[EMAIL PROTECTED]>
+
+ * EndpointAddressTest.cs : added WriteContentsTo and WriteTo tests
+ with WSAddressing10 mode.
+ * WSHttpBindingTest.cs : added test for IssuedToken security.
+ * EndpointIdentityTest.cs : new test (not working yet).
+
2007-04-03 Atsushi Enomoto <[EMAIL PROTECTED]>
* IntegratedConnectionTest.cs, ClientBaseTest.cs :
Modified:
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel/EndpointAddressTest.cs
===================================================================
---
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel/EndpointAddressTest.cs
2007-04-05 07:25:34 UTC (rev 75415)
+++
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel/EndpointAddressTest.cs
2007-04-05 07:31:44 UTC (rev 75416)
@@ -29,13 +29,15 @@
using System;
using System.Collections.Generic;
using System.IO;
+using System.Security.Cryptography.X509Certificates;
+using System.Security.Cryptography.Xml;
using System.ServiceModel;
+using System.ServiceModel.Channels;
using System.Text;
using System.Xml;
using System.Xml.Schema;
-using System.ServiceModel.Channels;
+using System.Xml.Serialization;
using NUnit.Framework;
-using System.Xml.Serialization;
namespace MonoTests.System.ServiceModel
{
@@ -74,17 +76,8 @@
Assert.IsTrue (address.IsNone, "#3");
}
-/* it does not exist anymore
[Test]
[ExpectedException (typeof (ArgumentNullException))]
- public void ConstructorNullUri ()
- {
- new EndpointAddress ((Uri) null);
- }
-*/
-
- [Test]
- [ExpectedException (typeof (ArgumentNullException))]
public void ConstructorNullString ()
{
new EndpointAddress ((string) null);
@@ -311,7 +304,7 @@
}
[Test]
- public void WriteTo ()
+ public void WriteToAddressingNone ()
{
EndpointAddress a = new EndpointAddress
("http://localhost:8080");
StringWriter sw = new StringWriter ();
@@ -331,6 +324,51 @@
Assert.AreEqual ("<EndpointReference
xmlns=\"http://schemas.microsoft.com/ws/2005/05/addressing/none\">http://localhost:8080/</EndpointReference>",
sw.ToString (), "#2");
}
+ string identity1 = "<Identity
xmlns=\"http://schemas.xmlsoap.org/ws/2006/02/addressingidentity\"><KeyInfo
xmlns=\"http://www.w3.org/2000/09/xmldsig#\"><X509Data><X509Certificate>MIIBxTCCAS6gAwIBAgIQEOvBwzgWq0aTzEi0qgWLBTANBgkqhkiG9w0BAQUFADAgMR4wHAYDVQQDExVNb25vIFRlc3QgUm9vdCBBZ2VuY3kwHhcNMDYwNzMxMDYxMDI4WhcNMzkxMjMxMDk1OTU5WjAkMSIwIAYDVQQDExlQb3Vwb3Uncy1Tb2Z0d2FyZS1GYWN0b3J5MIGdMA0GCSqGSIb3DQEBAQUAA4GLADCBhwKBgQCJI5sOaaEOCuXg2Itq+IVym/g13KwFYlyqJXPcBBs91qO1dpBDxUl19GSLFqHXfbIo4UYJZmEdLcS48yHx1w3AbC1raeH6bYhXqS3Mjj6ZnsJI0CyaUNjQkj4fwC3W8q80CuULmORUa6WJiugl5JT80s8s1iCymLtO1cbL1F+6DwIBETANBgkqhkiG9w0BAQUFAAOBgQA5IxtEKCgG0o6YxVDKRRTfiQY4QiCkHxqgfP2E+Cm6guuHykAFvWFqMUtGZq3yco8u83ZgXtjPphhPuzl8fdJsLTXieERsAbfZwcbp6cssTwsSl4JJviHSN17G3qbo0LH9u1QJHesBaH52Hz2iZaBfClxgUQGeWvO0SW+hZo75hg==</X509Certificate></X509Data></KeyInfo></Identity>";
+
+ string C14N (string xml)
+ {
+ XmlDsigExcC14NTransform t = new XmlDsigExcC14NTransform
();
+ XmlDocument doc = new XmlDocument ();
+ doc.LoadXml (xml);
+ t.LoadInput (doc);
+ return new StreamReader (t.GetOutput () as
Stream).ReadToEnd ();
+ }
+
+ [Test]
+ public void WriteToWSA10 ()
+ {
+ X509Certificate2 cert = new X509Certificate2
("Test/Resources/test.cer");
+ EndpointAddress a = new EndpointAddress (
+ new Uri ("http://localhost:8080"),
+ new X509CertificateEndpointIdentity (cert));
+ StringWriter sw = new StringWriter ();
+ XmlWriterSettings xws = new XmlWriterSettings ();
+ xws.OmitXmlDeclaration = true;
+ using (XmlDictionaryWriter xw =
XmlDictionaryWriter.CreateDictionaryWriter (XmlWriter.Create (sw, xws))) {
+ a.WriteTo (AddressingVersion.WSAddressing10,
xw);
+ }
+ Assert.AreEqual (C14N ("<EndpointReference
xmlns=\"http://www.w3.org/2005/08/addressing\"><Address>http://localhost:8080/</Address>"
+ identity1 + "</EndpointReference>"), C14N (sw.ToString ()), "#2");
+ }
+
+ [Test]
+ public void WriteContentsToWSA10 ()
+ {
+ X509Certificate2 cert = new X509Certificate2
("Test/Resources/test.cer");
+ EndpointAddress a = new EndpointAddress (
+ new Uri ("http://localhost:8080"),
+ new X509CertificateEndpointIdentity (cert));
+ StringWriter sw = new StringWriter ();
+ XmlWriterSettings xws = new XmlWriterSettings ();
+ xws.OmitXmlDeclaration = true;
+ using (XmlDictionaryWriter xw =
XmlDictionaryWriter.CreateDictionaryWriter (XmlWriter.Create (sw, xws))) {
+ xw.WriteStartElement ("root");
+ a.WriteContentsTo
(AddressingVersion.WSAddressing10, xw);
+ xw.WriteEndElement ();
+ }
+ Assert.AreEqual (C14N ("<root><Address
xmlns=\"http://www.w3.org/2005/08/addressing\">http://localhost:8080/</Address>"
+ identity1 + "</root>"), C14N (sw.ToString ()), "#2");
+ }
+
/* GetSchema() does not exist anymore
[Test]
public void GetSchemaTest ()
Added:
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel/EndpointIdentityTest.cs
===================================================================
---
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel/EndpointIdentityTest.cs
2007-04-05 07:25:34 UTC (rev 75415)
+++
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel/EndpointIdentityTest.cs
2007-04-05 07:31:44 UTC (rev 75416)
@@ -0,0 +1,74 @@
+//
+// EndpointIdentityTest.cs
+//
+// Author:
+// Atsushi Enomoto <[EMAIL PROTECTED]>
+//
+// Copyright (C) 2007 Novell, Inc. http://www.novell.com
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+using System;
+using System.IO;
+using System.IdentityModel.Claims;
+using System.Runtime.Serialization;
+using System.Security.Cryptography.X509Certificates;
+using System.Security.Cryptography.Xml;
+using System.ServiceModel;
+using System.Xml;
+using NUnit.Framework;
+
+namespace MonoTests.System.ServiceModel
+{
+ [TestFixture]
+ public class EndpointIdentityTest
+ {
+ static readonly X509Certificate2 cert = new X509Certificate2
("Test/Resources/test.cer");
+
+ [Test]
+ [Category ("NotWorking")] // DataContractSerializer+base64 issue
+ public void CreateX509CertificateIdentity ()
+ {
+ X509CertificateEndpointIdentity identity =
+ EndpointIdentity.CreateX509CertificateIdentity
(cert)
+ as X509CertificateEndpointIdentity;
+ Claim c = identity.IdentityClaim;
+ Assert.IsNotNull (c, "#1");
+ Assert.AreEqual (ClaimTypes.Thumbprint, c.ClaimType,
"#2");
+ DataContractSerializer ser = new DataContractSerializer
(c.GetType ());
+ StringWriter sw = new StringWriter ();
+ XmlWriter xw = XmlWriter.Create (sw);
+ ser.WriteObject (xw, c);
+ xw.Close ();
+ string xml = @"<?xml version=""1.0""
encoding=""utf-16""?><Claim
xmlns:i=""http://www.w3.org/2001/XMLSchema-instance""
xmlns=""http://schemas.xmlsoap.org/ws/2005/05/identity""><ClaimType>http://schemas.xmlsoap.org/ws/2005/05/identity/claims/thumbprint</ClaimType><Resource
xmlns:d2p1=""http://www.w3.org/2001/XMLSchema""
i:type=""d2p1:base64Binary"">GQ3YHlGQhDF1bvMixHliX4uLjlY=</Resource><Right>http://schemas.xmlsoap.org/ws/2005/05/identity/right/possessproperty</Right></Claim>";
+ Assert.AreEqual (C14N (xml), C14N (sw.ToString ()),
"#3");
+ Assert.AreEqual ("identity(" + c + ")",
identity.ToString (), "#4");
+ }
+
+ string C14N (string xml)
+ {
+ XmlDsigExcC14NTransform t = new XmlDsigExcC14NTransform
();
+ XmlDocument doc = new XmlDocument ();
+ doc.LoadXml (xml);
+ t.LoadInput (doc);
+ return new StreamReader (t.GetOutput () as
Stream).ReadToEnd ();
+ }
+ }
+}
Modified:
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel/WSHttpBindingTest.cs
===================================================================
---
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel/WSHttpBindingTest.cs
2007-04-05 07:25:34 UTC (rev 75415)
+++
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel/WSHttpBindingTest.cs
2007-04-05 07:31:44 UTC (rev 75416)
@@ -29,6 +29,7 @@
using System.Collections.ObjectModel;
using System.Net;
using System.Net.Security;
+using System.IdentityModel.Claims;
using System.IdentityModel.Selectors;
using System.IdentityModel.Tokens;
using System.ServiceModel;
@@ -418,6 +419,31 @@
}
[Test]
+ public void MessageSecurityIssuedToken ()
+ {
+ WSHttpBinding binding = new WSHttpBinding ();
+ binding.Security.Message.EstablishSecurityContext =
false;
+ binding.Security.Message.ClientCredentialType =
+ MessageCredentialType.IssuedToken;
+ SymmetricSecurityBindingElement sbe =
+ binding.CreateBindingElements
().Find<SymmetricSecurityBindingElement> ();
+ Assert.IsNotNull (sbe, "#1");
+ Assert.AreEqual (0,
sbe.EndpointSupportingTokenParameters.Signed.Count, "#1-1");
+ Assert.AreEqual (1,
sbe.EndpointSupportingTokenParameters.Endorsing.Count, "#1-2");
+ Assert.AreEqual (0,
sbe.EndpointSupportingTokenParameters.SignedEndorsing.Count, "#1-3");
+ Assert.AreEqual (0,
sbe.EndpointSupportingTokenParameters.SignedEncrypted.Count, "#1-4");
+ IssuedSecurityTokenParameters p =
+ sbe.EndpointSupportingTokenParameters.Endorsing
[0]
+ as IssuedSecurityTokenParameters;
+ Assert.IsNotNull (p, "#2");
+ Assert.IsNotNull (p.ClaimTypeRequirements, "#2-1");
+ Assert.AreEqual (1, p.ClaimTypeRequirements.Count,
"#2-2");
+ ClaimTypeRequirement r = p.ClaimTypeRequirements [0];
+ Assert.AreEqual (ClaimTypes.PPID, r.ClaimType, "#3-1");
+ Assert.IsFalse (r.IsOptional, "#3-2");
+ }
+
+ [Test]
[ExpectedException (typeof (InvalidOperationException))]
[Category ("NotWorking")]
public void BuildListenerWithoutServiceCertificate ()
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches