Skip to content

Commit

Permalink
Update for single device refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
wvdhaute committed Mar 26, 2014
1 parent d9c97d7 commit 2cfa8a6
Show file tree
Hide file tree
Showing 19 changed files with 219 additions and 282 deletions.
Binary file modified linkid-example/linkid-example.suo
Binary file not shown.
2 changes: 0 additions & 2 deletions linkid-example/linkid-example/LinkIDLogin.aspx
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
<form id="form1" runat="server" method="post" autocomplete="off" target="_self">

<asp:HiddenField ID="SAMLRequest" runat="server" />
<asp:HiddenField ID="LoginMode" runat="server" />
<asp:HiddenField ID="StartPage" runat="server" />
<asp:HiddenField ID="LanguageField" runat="server" />

<noscript>
Expand Down
2 changes: 1 addition & 1 deletion linkid-example/linkid-example/LinkIDLogin.aspx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ protected void Page_Load(object sender, EventArgs e)

LoginConfig.handleLinkIDWithPOST(Request, Response, Session, SESSION_AUTH_CONTEXT, LINKID_HOST,
APP_NAME, language, LOGINPAGE_LOCATION, KEY_APP, CERT_APP, CERT_LINKID,
this.form1, this.SAMLRequest, this.LoginMode, this.StartPage, this.LanguageField);
this.form1, this.SAMLRequest, this.LanguageField);

}
}
Expand Down
20 changes: 1 addition & 19 deletions linkid-example/linkid-example/LinkIDLogin.aspx.designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion linkid-example/linkid-example/LoginMobile.aspx.designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
<Compile Include="src\test\cs\TestNotificationClient.cs" />
<Compile Include="src\test\cs\TestPingClient.cs" />
<Compile Include="src\test\cs\TestSaml.cs" />
<Compile Include="src\test\cs\TestSessionTrackingClient.cs" />
<Compile Include="src\test\cs\WebServerTest.cs" />
</ItemGroup>
<ItemGroup>
Expand Down
275 changes: 139 additions & 136 deletions linkid-sdk-dotnet/linkid-sdk-dotnet-test/src/test/cs/TestSaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,108 +27,110 @@

namespace safe_online_sdk_dotnet.test.cs
{
[TestFixture]
public class TestSaml
{
[Test]
public void TestMethod()
{
string[] attributeValues = {"test-value"};
SamlAttribute samlAttribute = new SamlAttribute("urn:namespace", "attributeName", attributeValues);
Console.WriteLine("saml attribute: " + samlAttribute);

SamlAuthenticationStatement samlStatement = new SamlAuthenticationStatement();

SamlAssertion samlAssertion = new SamlAssertion();
samlAssertion.Statements.Add(samlStatement);
}

[Test]
public void TestAuthnRequest() {
AuthnRequestType authnRequest = new AuthnRequestType();
authnRequest.ID = "test-id";
authnRequest.AssertionConsumerServiceURL = "http://test.assertion.consumer";
authnRequest.Destination = "http://destination";
authnRequest.ForceAuthn = true;
authnRequest.ProtocolBinding = "urn:test:protocol:binding";
authnRequest.Version = "2.0";
authnRequest.IssueInstant = DateTime.Now.ToUniversalTime();

NameIDType issuer = new NameIDType();
issuer.Value = "test-issuer";
authnRequest.Issuer = issuer;

NameIDPolicyType nameIdPolicy = new NameIDPolicyType();
nameIdPolicy.AllowCreate = true;
nameIdPolicy.AllowCreateSpecified = true;
authnRequest.NameIDPolicy = nameIdPolicy;

XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
ns.Add("samlp", "urn:oasis:names:tc:SAML:2.0:protocol");
ns.Add("saml", "urn:oasis:names:tc:SAML:2.0:assertion");
//ns.Add("ds", "http://www.w3.org/2000/09/xmldsig#");

XmlRootAttribute xRoot = new XmlRootAttribute();
xRoot.ElementName = "AuthnRequest";
xRoot.Namespace = "urn:oasis:names:tc:SAML:2.0:protocol";
XmlSerializer serializer = new XmlSerializer(typeof(AuthnRequestType), xRoot);
MemoryStream memoryStream = new MemoryStream();
XmlTextWriter xmlTextWriter = new XmlTextWriter(memoryStream, Encoding.UTF8);
serializer.Serialize(xmlTextWriter, authnRequest, ns);
memoryStream = (MemoryStream)xmlTextWriter.BaseStream;
string result = new UTF8Encoding().GetString(memoryStream.ToArray());
Console.WriteLine("result: " + result);

XmlDocument document = new XmlDocument();
memoryStream.Seek(0, SeekOrigin.Begin);
document.Load(memoryStream);
String xmlString = document.OuterXml;
Console.WriteLine("DOM result: " + xmlString);

RSACryptoServiceProvider Key = new RSACryptoServiceProvider();

SignedXml signedXml = new SignedXml(document);
signedXml.SigningKey = Key;
Signature signature = signedXml.Signature;
signature.SignedInfo.CanonicalizationMethod = SignedXml.XmlDsigExcC14NTransformUrl;
Reference reference = new Reference("#" + authnRequest.ID);
XmlDsigEnvelopedSignatureTransform env = new XmlDsigEnvelopedSignatureTransform();
reference.AddTransform(env);
XmlDsigExcC14NTransform excC14NTransform = new XmlDsigExcC14NTransform("ds saml samlp");
reference.AddTransform(excC14NTransform);
signature.SignedInfo.AddReference(reference);

signedXml.ComputeSignature();

XmlElement xmlDigitalSignature = signedXml.GetXml();
document.DocumentElement.AppendChild(document.ImportNode(xmlDigitalSignature, true));

result = document.OuterXml;
Console.WriteLine("result: " + result);

XmlTextWriter xmltw = new XmlTextWriter(TestConstants.workDir + "\\test.xml", new UTF8Encoding(false));
document.WriteTo(xmltw);
xmltw.Close();
}

[Test]
public void TestSaml2AuthUtil() {
RSACryptoServiceProvider key = new RSACryptoServiceProvider();

Saml2AuthUtil testedInstance = new Saml2AuthUtil(key);

string spUrl = "http://service.provider.com";
string idpUrl = "http://identity.provider.com";
string applicationId = "urn:application:id";
string[] devices = new string[] {"test-device-1", "test-device-2"};
[TestFixture]
public class TestSaml
{
[Test]
public void TestMethod()
{
string[] attributeValues = { "test-value" };
SamlAttribute samlAttribute = new SamlAttribute("urn:namespace", "attributeName", attributeValues);
Console.WriteLine("saml attribute: " + samlAttribute);

SamlAuthenticationStatement samlStatement = new SamlAuthenticationStatement();

SamlAssertion samlAssertion = new SamlAssertion();
samlAssertion.Statements.Add(samlStatement);
}

[Test]
public void TestAuthnRequest()
{
AuthnRequestType authnRequest = new AuthnRequestType();
authnRequest.ID = "test-id";
authnRequest.AssertionConsumerServiceURL = "http://test.assertion.consumer";
authnRequest.Destination = "http://destination";
authnRequest.ForceAuthn = true;
authnRequest.ProtocolBinding = "urn:test:protocol:binding";
authnRequest.Version = "2.0";
authnRequest.IssueInstant = DateTime.Now.ToUniversalTime();

NameIDType issuer = new NameIDType();
issuer.Value = "test-issuer";
authnRequest.Issuer = issuer;

NameIDPolicyType nameIdPolicy = new NameIDPolicyType();
nameIdPolicy.AllowCreate = true;
nameIdPolicy.AllowCreateSpecified = true;
authnRequest.NameIDPolicy = nameIdPolicy;

XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
ns.Add("samlp", "urn:oasis:names:tc:SAML:2.0:protocol");
ns.Add("saml", "urn:oasis:names:tc:SAML:2.0:assertion");
//ns.Add("ds", "http://www.w3.org/2000/09/xmldsig#");

XmlRootAttribute xRoot = new XmlRootAttribute();
xRoot.ElementName = "AuthnRequest";
xRoot.Namespace = "urn:oasis:names:tc:SAML:2.0:protocol";
XmlSerializer serializer = new XmlSerializer(typeof(AuthnRequestType), xRoot);
MemoryStream memoryStream = new MemoryStream();
XmlTextWriter xmlTextWriter = new XmlTextWriter(memoryStream, Encoding.UTF8);
serializer.Serialize(xmlTextWriter, authnRequest, ns);
memoryStream = (MemoryStream)xmlTextWriter.BaseStream;
string result = new UTF8Encoding().GetString(memoryStream.ToArray());
Console.WriteLine("result: " + result);

XmlDocument document = new XmlDocument();
memoryStream.Seek(0, SeekOrigin.Begin);
document.Load(memoryStream);
String xmlString = document.OuterXml;
Console.WriteLine("DOM result: " + xmlString);

RSACryptoServiceProvider Key = new RSACryptoServiceProvider();

SignedXml signedXml = new SignedXml(document);
signedXml.SigningKey = Key;
Signature signature = signedXml.Signature;
signature.SignedInfo.CanonicalizationMethod = SignedXml.XmlDsigExcC14NTransformUrl;
Reference reference = new Reference("#" + authnRequest.ID);
XmlDsigEnvelopedSignatureTransform env = new XmlDsigEnvelopedSignatureTransform();
reference.AddTransform(env);
XmlDsigExcC14NTransform excC14NTransform = new XmlDsigExcC14NTransform("ds saml samlp");
reference.AddTransform(excC14NTransform);
signature.SignedInfo.AddReference(reference);

signedXml.ComputeSignature();

XmlElement xmlDigitalSignature = signedXml.GetXml();
document.DocumentElement.AppendChild(document.ImportNode(xmlDigitalSignature, true));

result = document.OuterXml;
Console.WriteLine("result: " + result);

XmlTextWriter xmltw = new XmlTextWriter(TestConstants.workDir + "\\test.xml", new UTF8Encoding(false));
document.WriteTo(xmltw);
xmltw.Close();
}

[Test]
public void TestSaml2AuthUtil()
{
RSACryptoServiceProvider key = new RSACryptoServiceProvider();

Saml2AuthUtil testedInstance = new Saml2AuthUtil(key);

string spUrl = "http://service.provider.com";
string idpUrl = "http://identity.provider.com";
string applicationId = "urn:application:id";
string[] devices = new string[] { "test-device-1", "test-device-2" };

// device context
Dictionary<string, string> deviceContextMap = new Dictionary<string, string>();
deviceContextMap.Add(RequestConstants.DEVICE_CONTEXT_TITLE, "Test device context");

// attribute suggestions
Dictionary<string, List<Object>> attributeSuggestions = new Dictionary<string, List<object>>();
attributeSuggestions.Add("test.attribute.string", new List<Object>{"test"});
attributeSuggestions.Add("test.attribute.string", new List<Object> { "test" });
attributeSuggestions.Add("test.attribute.date", new List<Object> { new DateTime() });
attributeSuggestions.Add("test.attribute.boolean", new List<Object> { true });
attributeSuggestions.Add("test.attribute.integer", new List<Object> { 69 });
Expand All @@ -137,46 +139,47 @@ public void TestSaml2AuthUtil() {
// payment context
PaymentContext paymentContext = new PaymentContext(1, Currency.EUR);

string result = testedInstance.generateAuthnRequest(applicationId, null, null, spUrl, idpUrl, null, false,
deviceContextMap, attributeSuggestions, paymentContext);
Console.WriteLine("result document: " + result);

XmlDocument xmlDocument = new XmlDocument();
xmlDocument.LoadXml(result);

SignedXml signedXml = new SignedXml(xmlDocument);
XmlNodeList nodeList = xmlDocument.GetElementsByTagName("Signature");
signedXml.LoadXml((XmlElement)nodeList[0]);

bool verificationResult = signedXml.CheckSignature(key);
Console.WriteLine("verification result: " + verificationResult);
Assert.IsTrue(verificationResult);
}

[Test]
public void TestSaml2LogoutUtil() {
RSACryptoServiceProvider key = new RSACryptoServiceProvider();

Saml2LogoutUtil testedInstance = new Saml2LogoutUtil(key);

string idpUrl = "http://identity.provider.com";
string applicationId = "urn:application:id";
string subjectName = "test-subject";

string result = testedInstance.generateLogoutRequest(subjectName, applicationId, idpUrl);
Console.WriteLine("result document: " + result);

XmlDocument xmlDocument = new XmlDocument();
xmlDocument.LoadXml(result);

SignedXml signedXml = new SignedXml(xmlDocument);
XmlNodeList nodeList = xmlDocument.GetElementsByTagName("Signature");
signedXml.LoadXml((XmlElement)nodeList[0]);

bool verificationResult = signedXml.CheckSignature(key);
Console.WriteLine("verification result: " + verificationResult);
Assert.IsTrue(verificationResult);
}
string result = testedInstance.generateAuthnRequest(applicationId, null, null, spUrl, idpUrl, false,
deviceContextMap, attributeSuggestions, paymentContext);
Console.WriteLine("result document: " + result);

XmlDocument xmlDocument = new XmlDocument();
xmlDocument.LoadXml(result);

SignedXml signedXml = new SignedXml(xmlDocument);
XmlNodeList nodeList = xmlDocument.GetElementsByTagName("Signature");
signedXml.LoadXml((XmlElement)nodeList[0]);

bool verificationResult = signedXml.CheckSignature(key);
Console.WriteLine("verification result: " + verificationResult);
Assert.IsTrue(verificationResult);
}

[Test]
public void TestSaml2LogoutUtil()
{
RSACryptoServiceProvider key = new RSACryptoServiceProvider();

Saml2LogoutUtil testedInstance = new Saml2LogoutUtil(key);

string idpUrl = "http://identity.provider.com";
string applicationId = "urn:application:id";
string subjectName = "test-subject";

string result = testedInstance.generateLogoutRequest(subjectName, applicationId, idpUrl);
Console.WriteLine("result document: " + result);

XmlDocument xmlDocument = new XmlDocument();
xmlDocument.LoadXml(result);

SignedXml signedXml = new SignedXml(xmlDocument);
XmlNodeList nodeList = xmlDocument.GetElementsByTagName("Signature");
signedXml.LoadXml((XmlElement)nodeList[0]);

bool verificationResult = signedXml.CheckSignature(key);
Console.WriteLine("verification result: " + verificationResult);
Assert.IsTrue(verificationResult);
}

[Test]
public void TestPaymentResponseDeserialization()
Expand Down Expand Up @@ -205,5 +208,5 @@ public void TestPaymentResponseDeserialization()
XmlSerializer serializer = new XmlSerializer(typeof(PaymentResponseType), xRoot);
PaymentResponseType paymentResponseType = (PaymentResponseType)serializer.Deserialize(new XmlTextReader(new StringReader(xml)));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public byte[] initiateAuthentication()
{
string encodedSamlRequest = this.saml2AuthUtil.generateEncodedAuthnRequest(TestConstants.testApplicationName,
null, null, "http://" + TestConstants.localhost + ":8080",
TestConstants.linkidAuthEntry, null, false, null, null, null);
TestConstants.linkidAuthEntry, false, null, null, null);
byte[] response = generateSamlRequestForm("Authenticate", TestConstants.linkidAuthEntry, encodedSamlRequest);
Console.WriteLine("initiateAuthentication response: {0}", response);
return response;
Expand Down
Binary file modified linkid-sdk-dotnet/linkid-sdk-dotnet.suo
Binary file not shown.
Loading

0 comments on commit 2cfa8a6

Please sign in to comment.