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

Marked HMAC SHA based algorithms as insecure and obsolete #384

Merged
merged 2 commits into from
Apr 8, 2022
Merged
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion src/JWT/Algorithms/HMACSHA256Algorithm.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using System.Security.Cryptography;
using System;
using System.Security.Cryptography;

namespace JWT.Algorithms
{
/// <summary>
/// HMAC using SHA-256
/// </summary>
[Obsolete(ObsoleteMessage, error: false)]
public sealed class HMACSHA256Algorithm : HMACSHAAlgorithm
{
/// <inheritdoc />
Expand Down
4 changes: 3 additions & 1 deletion src/JWT/Algorithms/HMACSHA384Algorithm.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using System.Security.Cryptography;
using System;
using System.Security.Cryptography;

namespace JWT.Algorithms
{
/// <summary>
/// HMAC using SHA-384
/// </summary>
[Obsolete(ObsoleteMessage, error: false)]
public sealed class HMACSHA384Algorithm : HMACSHAAlgorithm
{
/// <inheritdoc />
Expand Down
4 changes: 3 additions & 1 deletion src/JWT/Algorithms/HMACSHA512Algorithm.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using System.Security.Cryptography;
using System;
using System.Security.Cryptography;

namespace JWT.Algorithms
{
/// <summary>
/// HMAC using SHA-512
/// </summary>
[Obsolete(ObsoleteMessage, error: false)]
public sealed class HMACSHA512Algorithm : HMACSHAAlgorithm
{
/// <inheritdoc />
Expand Down
48 changes: 26 additions & 22 deletions src/JWT/Algorithms/HMACSHAAlgorithm.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
using System.Security.Cryptography;

namespace JWT.Algorithms
{
public abstract class HMACSHAAlgorithm : IJwtAlgorithm
{
/// <inheritdoc />
public abstract string Name { get; }

/// <inheritdoc />
public abstract HashAlgorithmName HashAlgorithmName { get; }

/// <inheritdoc />
public byte[] Sign(byte[] key, byte[] bytesToSign)
{
using var sha = CreateAlgorithm(key);
return sha.ComputeHash(bytesToSign);
}

protected abstract HMAC CreateAlgorithm(byte[] key);
}
}
using System;
using System.Security.Cryptography;

namespace JWT.Algorithms
{
[Obsolete(ObsoleteMessage, error: false)]
public abstract class HMACSHAAlgorithm : IJwtAlgorithm
{
internal const string ObsoleteMessage = "HMAC SHA based algorithms are not secure to protect modern web applications. Consider switch to RSASSA or ECDSA.";

/// <inheritdoc />
public abstract string Name { get; }

/// <inheritdoc />
public abstract HashAlgorithmName HashAlgorithmName { get; }

/// <inheritdoc />
public byte[] Sign(byte[] key, byte[] bytesToSign)
{
using var sha = CreateAlgorithm(key);
return sha.ComputeHash(bytesToSign);
}

protected abstract HMAC CreateAlgorithm(byte[] key);
}
}
1 change: 1 addition & 0 deletions src/JWT/Algorithms/HMACSHAAlgorithmFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace JWT.Algorithms
{
/// <inheritdoc />
[Obsolete(HMACSHAAlgorithm.ObsoleteMessage, error: false)]
public class HMACSHAAlgorithmFactory : JwtAlgorithmFactory
{
protected override IJwtAlgorithm Create(JwtAlgorithmName algorithm)
Expand Down
2 changes: 1 addition & 1 deletion src/JWT/JWT.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<Authors>Alexander Batishchev, John Sheehan, Michael Lehenbauer</Authors>
<PackageTags>jwt;json;authorization</PackageTags>
<PackageLicense>CC0-1.0</PackageLicense>
<Version>9.0.0-beta3</Version>
<Version>9.0.0-beta4</Version>
<FileVersion>9.0.0.0</FileVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
<RootNamespace>JWT</RootNamespace>
Expand Down