public void CanParseCreatedArtifact() { // Arrange var sourceIdUrl = "https://kleopatra.safewhere.local/Saml2ExtWeb/artifact.ashx"; var sourceIdHash = ArtifactUtil.GenerateSourceIdHash(sourceIdUrl); var messageHandle = ArtifactUtil.GenerateMessageHandle(); short typeCode = 4; short endpointIndex = 1; // Act var artifact = ArtifactUtil.CreateArtifact(typeCode, endpointIndex, sourceIdHash, messageHandle); short parsedTypeCode = -1; short parsedEndpointIndex = -1; var parsedSourceIdHash = new byte[20]; var parsedMessageHandle = new byte[20]; var result = ArtifactUtil.TryParseArtifact(artifact, ref parsedTypeCode, ref parsedEndpointIndex, ref parsedSourceIdHash, ref parsedMessageHandle); // Assert Assert.True(result, "Unable to parse artifact"); Assert.True(typeCode == parsedTypeCode, "Original and parsed typeCode did not match"); Assert.True(endpointIndex == parsedEndpointIndex, "Original and parsed endpointIndex did not match"); Assert.Equal(sourceIdHash, parsedSourceIdHash); //Assert.Fail("Original and parsed sourceIdHash are not identical"); Assert.Equal(messageHandle, parsedMessageHandle); //Assert.Fail("Original and parsed messageHandle are not identical"); }
public void TryParseError3() { Int16 parsedTypeCode = -1; Int16 parsedEndpointIndex = -1; byte[] parsedSourceIdHash = new byte[20]; byte[] parsedMessageHandle = new byte[20]; string artifact = string.Empty; bool result = ArtifactUtil.TryParseArtifact(artifact, ref parsedTypeCode, ref parsedEndpointIndex, ref parsedSourceIdHash, ref parsedMessageHandle); Assert.That(!result, "TryParseArtifact did not fail as expected"); }
public void ReturnsFalseOnMessageHandleLengthMismatch() { // Arrange short parsedTypeCode = -1; short parsedEndpointIndex = -1; var parsedSourceIdHash = new byte[20]; var parsedMessageHandle = new byte[19]; var artifact = string.Empty; // Act var result = ArtifactUtil.TryParseArtifact(artifact, ref parsedTypeCode, ref parsedEndpointIndex, ref parsedSourceIdHash, ref parsedMessageHandle); // Assert Assert.That(!result, "TryParseArtifact did not fail as expected"); }
public void ArtifactCreateParse() { string sourceIdUrl = "https://kleopatra.safewhere.local/Saml2ExtWeb/artifact.ashx"; byte[] sourceIdHash = ArtifactUtil.GenerateSourceIdHash(sourceIdUrl); Assert.That(sourceIdHash.Length == 20, "Unexpected hash length"); byte[] messageHandle = ArtifactUtil.GenerateMessageHandle(); Assert.That(messageHandle.Length == 20, "Unexpected hash length"); Int16 typeCode = 4; Int16 endpointIndex = 1; string artifact = ArtifactUtil.CreateArtifact(typeCode, endpointIndex, sourceIdHash, messageHandle); Int16 parsedTypeCode = -1; Int16 parsedEndpointIndex = -1; byte[] parsedSourceIdHash = new byte[20]; byte[] parsedMessageHandle = new byte[20]; Assert.That( ArtifactUtil.TryParseArtifact(artifact, ref parsedTypeCode, ref parsedEndpointIndex, ref parsedSourceIdHash, ref parsedMessageHandle), "Unable to parse artifact"); Assert.That(typeCode == parsedTypeCode, "Original and parsed typeCode did not match"); Assert.That(endpointIndex == parsedEndpointIndex, "Original and parsed endpointIndex did not match"); for (int i = 0; i < 20; i++) { if (sourceIdHash[i] != parsedSourceIdHash[i]) { Assert.Fail("Original and parsed sourceIdHash are not identical"); } } for (int i = 0; i < 20; i++) { if (messageHandle[i] != parsedMessageHandle[i]) { Assert.Fail("Original and parsed messageHandle are not identical"); } } }
/// <summary> /// Determines which IdP an artifact has been sent from. /// </summary> /// <param name="artifact">The artifact.</param> /// <returns>An IdP configuration element</returns> private IdentityProvider DetermineIdp(string artifact) { short typeCodeValue = -1; short endPointIndex = -1; var sourceIdHash = new byte[20]; var messageHandle = new byte[20]; if (ArtifactUtil.TryParseArtifact(artifact, ref typeCodeValue, ref endPointIndex, ref sourceIdHash, ref messageHandle)) { foreach (IdentityProvider ep in config.IdentityProviders) { var hash = ArtifactUtil.GenerateSourceIdHash(ep.Id); if (ByteArraysAreEqual(sourceIdHash, hash)) { return(ep); } } } return(null); }
/// <summary> /// Determines which IdP an artifact has been sent from. /// </summary> /// <param name="artifact">The artifact.</param> /// <returns>An IdP configuration element</returns> private IDPEndPoint DetermineIdp(string artifact) { SAML20FederationConfig config = SAML20FederationConfig.GetConfig(); short typeCodeValue = -1; short endPointIndex = -1; byte[] sourceIdHash = new byte[20]; byte[] messageHandle = new byte[20]; if (ArtifactUtil.TryParseArtifact(artifact, ref typeCodeValue, ref endPointIndex, ref sourceIdHash, ref messageHandle)) { foreach(IDPEndPoint ep in config.IDPEndPoints) { byte[] hash = ArtifactUtil.GenerateSourceIdHash(ep.Id); if (AreEqual(sourceIdHash, hash)) return ep; } } return null; }