Skip to content

Commit

Permalink
Unamrked HMAC SHA based algorithms as insecure and obsolete (#478)
Browse files Browse the repository at this point in the history
* Reverted #384.
* Bumped version to 10.1.0
* Updated changelog
  • Loading branch information
abatishchev authored Aug 11, 2023
1 parent 906002e commit 2c76ee0
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 37 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Unreleased

- TBD
# 10.1.0

- Unmarked HMAC SHA based algorithms as insecure and obsolete (was done in 9.0.0-beta4)

# 10.0.3

Expand Down
4 changes: 1 addition & 3 deletions src/JWT/Algorithms/HMACSHA256Algorithm.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
using System;
using System.Security.Cryptography;
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: 1 addition & 3 deletions src/JWT/Algorithms/HMACSHA384Algorithm.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
using System;
using System.Security.Cryptography;
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: 1 addition & 3 deletions src/JWT/Algorithms/HMACSHA512Algorithm.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
using System;
using System.Security.Cryptography;
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
46 changes: 21 additions & 25 deletions src/JWT/Algorithms/HMACSHAAlgorithm.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
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 switching 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);
}
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);
}
}
1 change: 0 additions & 1 deletion src/JWT/Algorithms/HMACSHAAlgorithmFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
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 @@ -25,7 +25,7 @@
</PropertyGroup>

<PropertyGroup>
<Version>10.0.3</Version>
<Version>10.1.0</Version>
<FileVersion>10.0.0.0</FileVersion>
<AssemblyVersion>10.0.0.0</AssemblyVersion>
</PropertyGroup>
Expand Down

0 comments on commit 2c76ee0

Please sign in to comment.