Skip to content

Commit

Permalink
Holder of key (#3)
Browse files Browse the repository at this point in the history
* changes tests to .net core 3.1

* Adds holder-of-key support
  • Loading branch information
gislikonrad authored Sep 24, 2021
1 parent 41a4f72 commit c610a9c
Show file tree
Hide file tree
Showing 30 changed files with 402 additions and 760 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -349,3 +349,4 @@ MigrationBackup/

# Ionide (cross platform F# VS Code tools) working folder
.ionide/
*.nupkg
158 changes: 79 additions & 79 deletions src/Solid.Identity.Protocols.WsTrust.Tests/CryptoTests.cs
Original file line number Diff line number Diff line change
@@ -1,88 +1,88 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.IdentityModel.Tokens;
using Solid.Identity.Protocols.WsSecurity.Tokens;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
using Xunit;
//using Microsoft.Extensions.DependencyInjection;
//using Microsoft.IdentityModel.Tokens;
//using Solid.Identity.Protocols.WsSecurity.Tokens;
//using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Security.Cryptography;
//using System.Security.Cryptography.X509Certificates;
//using System.Text;
//using System.Threading.Tasks;
//using Xunit;

namespace Solid.Identity.Protocols.WsTrust.Tests
{
public class CryptoTests
{
private CryptoProviderFactory _factory;
//namespace Solid.Identity.Protocols.WsTrust.Tests
//{
// public class CryptoTests
// {
// private CryptoProviderFactory _factory;

public CryptoTests()
{
var services = new ServiceCollection()
.AddLogging()
.BuildServiceProvider()
;
var options = new WsTrustOptions()
.AddRsaSha1Support()
.AddSha1Support()
.AddHmacSha1Support()
;
CryptoProviderFactory.Default.CustomCryptoProvider = new CustomCryptoProvider(options, services);
_factory = CryptoProviderFactory.Default;
}
// public CryptoTests()
// {
// var services = new ServiceCollection()
// .AddLogging()
// .BuildServiceProvider()
// ;
// var options = new WsTrustOptions()
// .AddRsaSha1Support()
// .AddSha1Support()
// .AddHmacSha1Support()
// ;
// CryptoProviderFactory.Default.CustomCryptoProvider = new CustomCryptoProvider(options, services);
// _factory = CryptoProviderFactory.Default;
// }

[Theory]
[InlineData("http://www.w3.org/2000/09/xmldsig#sha1")]
[InlineData("SHA1")]
public void ShouldGetHashAlgorithm(string algorithm)
{
Assert.True(_factory.IsSupportedAlgorithm(algorithm));
// throw exception if it can't create
_ = _factory.CreateHashAlgorithm(algorithm);
}
// [Theory]
// [InlineData("http://www.w3.org/2000/09/xmldsig#sha1")]
// [InlineData("SHA1")]
// public void ShouldGetHashAlgorithm(string algorithm)
// {
// Assert.True(_factory.IsSupportedAlgorithm(algorithm));
// // throw exception if it can't create
// _ = _factory.CreateHashAlgorithm(algorithm);
// }

[Theory]
[InlineData("http://www.w3.org/2000/09/xmldsig#rsa-sha1")]
[InlineData("RS1")]
public void ShouldGetAsymmetricSignatureProvider(string algorithm)
{
var certificate = new X509Certificate2(Convert.FromBase64String(Certificates.SigningCertificteBase64));
var key = new X509SecurityKey(certificate);
// [Theory]
// [InlineData("http://www.w3.org/2000/09/xmldsig#rsa-sha1")]
// [InlineData("RS1")]
// public void ShouldGetAsymmetricSignatureProvider(string algorithm)
// {
// var certificate = new X509Certificate2(Convert.FromBase64String(Certificates.SigningCertificteBase64));
// var key = new X509SecurityKey(certificate);

Assert.True(_factory.IsSupportedAlgorithm(algorithm));
// throw exception if it can't create
_ = _factory.CreateForSigning(key, algorithm);
_ = _factory.CreateForVerifying(key, algorithm);
}
// Assert.True(_factory.IsSupportedAlgorithm(algorithm));
// // throw exception if it can't create
// _ = _factory.CreateForSigning(key, algorithm);
// _ = _factory.CreateForVerifying(key, algorithm);
// }

[Theory]
[InlineData("http://www.w3.org/2000/09/xmldsig#hmac-sha1")]
[InlineData("H1")]
public void ShouldGetSymmetricSignatureProvider(string algorithm)
{
var bytes = new byte[16];
var random = RandomNumberGenerator.Create();
random.GetNonZeroBytes(bytes);
var key = new SymmetricSecurityKey(bytes);
// [Theory]
// [InlineData("http://www.w3.org/2000/09/xmldsig#hmac-sha1")]
// [InlineData("H1")]
// public void ShouldGetSymmetricSignatureProvider(string algorithm)
// {
// var bytes = new byte[16];
// var random = RandomNumberGenerator.Create();
// random.GetNonZeroBytes(bytes);
// var key = new SymmetricSecurityKey(bytes);

Assert.True(_factory.IsSupportedAlgorithm(algorithm));
// throw exception if it can't create
_ = _factory.CreateForSigning(key, algorithm);
_ = _factory.CreateForVerifying(key, algorithm);
}
// Assert.True(_factory.IsSupportedAlgorithm(algorithm));
// // throw exception if it can't create
// _ = _factory.CreateForSigning(key, algorithm);
// _ = _factory.CreateForVerifying(key, algorithm);
// }

[Theory]
[InlineData("http://www.w3.org/2000/09/xmldsig#hmac-sha1")]
[InlineData("H1")]
public void ShouldGetKeyedHashAlgorithm(string algorithm)
{
var bytes = new byte[16];
var random = RandomNumberGenerator.Create();
random.GetNonZeroBytes(bytes);
// [Theory]
// [InlineData("http://www.w3.org/2000/09/xmldsig#hmac-sha1")]
// [InlineData("H1")]
// public void ShouldGetKeyedHashAlgorithm(string algorithm)
// {
// var bytes = new byte[16];
// var random = RandomNumberGenerator.Create();
// random.GetNonZeroBytes(bytes);

Assert.True(_factory.IsSupportedAlgorithm(algorithm));
// throw exception if it can't create
_ = _factory.CreateKeyedHashAlgorithm(bytes, algorithm);
}
}
}
// Assert.True(_factory.IsSupportedAlgorithm(algorithm));
// // throw exception if it can't create
// _ = _factory.CreateKeyedHashAlgorithm(bytes, algorithm);
// }
// }
//}
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ public static Binding WithoutTransportSecurity(this Binding binding)
if (custom == null)
custom = new CustomBinding(binding);

var security = custom.Elements.OfType<SecurityBindingElement>();
foreach (var element in security)
element.AllowInsecureTransport = true;
//var security = custom.Elements.OfType<SecurityBindingElement>();
//foreach (var element in security)
// element.AllowInsecureTransport = true;

var https = custom
.Elements
Expand Down
122 changes: 0 additions & 122 deletions src/Solid.Identity.Protocols.WsTrust.Tests/GodSecurityTokenHandler.cs

This file was deleted.

3 changes: 0 additions & 3 deletions src/Solid.Identity.Protocols.WsTrust.Tests/Host/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ public void ConfigureServices(IServiceCollection services)
options.AddSaml2SecurityTokenHandler();
options.AddSecurityTokenHandler(god, god.GetTokenTypeIdentifiers());

options.AddSha1Support();
options.AddRsaSha1Support();

options.AddIdentityProvider("urn:alpha:and:omega", idp =>
{
idp.Name = "God token";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Microsoft.IdentityModel.Tokens;
using Microsoft.IdentityModel.Tokens.Saml;
using Microsoft.IdentityModel.Tokens.Saml2;
using System;
using System.Collections.Generic;
using System.IO;
Expand Down Expand Up @@ -49,7 +51,7 @@ public IReadOnlyCollection<ClaimsIdentity> ValidateToken(SecurityToken token)
var claims = new List<Claim>
{
new Claim(ClaimTypes.NameIdentifier, god.Name, ClaimValueTypes.String, token.Issuer),
new Claim(ClaimTypes.AuthenticationMethod, System.IdentityModel.Tokens.AuthenticationMethods.Unspecified, god.Name, ClaimValueTypes.String, token.Issuer),
new Claim(ClaimTypes.AuthenticationMethod, SamlConstants.AuthenticationMethods.UnspecifiedString, god.Name, ClaimValueTypes.String, token.Issuer),
new Claim(ClaimTypes.AuthenticationInstant, XmlConvert.ToString(DateTime.UtcNow, "yyyy-MM-ddTHH:mm:ss.fffZ"), ClaimValueTypes.DateTime, token.Issuer),
new Claim("urn:god:type", god.Type, god.Name, ClaimValueTypes.String, token.Issuer)
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net472</TargetFrameworks>
<TargetFrameworks>netcoreapp3.1</TargetFrameworks>

<IsPackable>false</IsPackable>
</PropertyGroup>
Expand All @@ -16,10 +16,7 @@

<ItemGroup>
<ProjectReference Include="..\Solid.Identity.Protocols.WsTrust\Solid.Identity.Protocols.WsTrust.csproj" />
</ItemGroup>

<ItemGroup Condition="$(TargetFramework) == 'net472'">
<Reference Include="System.Net.Http" />
<ProjectReference Include="..\Solid.ServiceModel.Security.WsTrust\Solid.ServiceModel.Security.WsTrust.csproj" />
</ItemGroup>

</Project>
Loading

0 comments on commit c610a9c

Please sign in to comment.