Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incorrect RSA SHA digest algorithm #1482

Open
wants to merge 2 commits into
base: v2
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,31 @@ namespace Sustainsys.Saml2
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "SHA")]
public abstract class ManagedRSASignatureDescription : SignatureDescription
{
public abstract string HashAlgorithm { get; }
public string HashAlgorithm { get; }

/// <summary>
/// Ctor
/// </summary>
public ManagedRSASignatureDescription()
public ManagedRSASignatureDescription(int keyLength)
{
KeyAlgorithm = typeof(RSACryptoServiceProvider).FullName;
DigestAlgorithm = typeof(SHA256Managed).FullName;
switch (keyLength)
{
case 256:
HashAlgorithm = "sha256";
DigestAlgorithm = typeof(SHA256Managed).FullName;
break;
case 384:
HashAlgorithm = "sha384";
DigestAlgorithm = typeof(SHA384Managed).FullName;
break;
case 512:
HashAlgorithm = "sha512";
DigestAlgorithm = typeof(SHA512Managed).FullName;
break;
default:
throw new InvalidOperationException($"Unexpected SHA key length= {keyLength}");
}
}

/// <summary>
Expand Down Expand Up @@ -64,16 +80,22 @@ public override AsymmetricSignatureFormatter CreateFormatter(AsymmetricAlgorithm

public class ManagedRSASHA256SignatureDescription : ManagedRSASignatureDescription
{
public override string HashAlgorithm => "sha256";
public ManagedRSASHA256SignatureDescription() : base(256)
{
}
}

public class ManagedRSASHA384SignatureDescription : ManagedRSASignatureDescription
{
public override string HashAlgorithm => "sha384";
public ManagedRSASHA384SignatureDescription() : base(384)
{
}
}

public class ManagedRSASHA512SignatureDescription : ManagedRSASignatureDescription
{
public override string HashAlgorithm => "sha512";
public ManagedRSASHA512SignatureDescription() : base(512)
{
}
}
}