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

RSA-OAEP-256 not in SupportedAlgorithms.IsSupportedRsaAlgorithm() #1293

Open
Cristallix opened this issue Nov 18, 2019 · 7 comments
Open

RSA-OAEP-256 not in SupportedAlgorithms.IsSupportedRsaAlgorithm() #1293

Cristallix opened this issue Nov 18, 2019 · 7 comments
Labels
Customer reported Indicates issue was opened by customer Enhancement The issue is a new feature P2 High, but not urgent. Needs to be addressed within the next couple of sprints

Comments

@Cristallix
Copy link

I'm trying to decrypt a JWE + JWS token and here is the first part of the token :

eyJ6aXAiOiJERUYiLCJlbmMiOiJBMjU2Q0JDLUhTNTEyIiwiYWxnIjoiUlNBLU9BRVAtMjU2In0

which after a base64ToString is giving :

{"zip":"DEF","enc":"A256CBC-HS512","alg":"RSA-OAEP-256"}

The problem is that when I'm trying to decrypt the token it goes down to the method SupportedAlgorithms.IsSupportedRsaAlgorithm() but RSA-OAEP-256 isn't listed and I can't decrypt my token. Do you plan to support it any time soon or I'm missing something ?

Thanks !

@GeoK GeoK added 5.x and 6.x Enhancement The issue is a new feature labels Nov 18, 2019
@GeoK
Copy link
Member

GeoK commented Nov 18, 2019

Hi @Cristallix - RSA-OAEP-256 is not currently supported.
I don't see a reason why we shouldn't support it in net461 and netstandard targets.

The team will triage the issue soon, but for now I'm marking it as an enhancement proposal.

@brentschmaltz brentschmaltz added the Customer reported Indicates issue was opened by customer label Nov 25, 2019
@brentschmaltz brentschmaltz added this to the 6.5.3 milestone May 1, 2020
@GeoK GeoK added the P1 More important, prioritize highly label May 27, 2020
@shjin404
Copy link

shjin404 commented Jun 22, 2020

Yes, we want to use this as well given SHA1 is now discouraged and people are recommended to use SHA2 family.

@brentschmaltz Minor, but there is a bug in the exception message as well that it shows 'System.String' as Algorithm. It should say No support for Algorithm: 'RSA-OAEP-256', ...

Microsoft.IdentityModel.Tokens.SecurityTokenEncryptionFailedException
  HResult=0x80131500
  Message=IDX10615: Encryption failed. No support for: Algorithm: 'System.String', SecurityKey: 'Microsoft.IdentityModel.Tokens.RsaSecurityKey'.
  Source=Microsoft.IdentityModel.JsonWebTokens
  StackTrace:
   at Microsoft.IdentityModel.JsonWebTokens.JsonWebTokenHandler.EncryptTokenPrivate(String innerJwt, EncryptingCredentials encryptingCredentials, String compressionAlgorithm, IDictionary`2 additionalHeaderClaims) in D:\a\1\s\src\Microsoft.IdentityModel.JsonWebTokens\JsonWebTokenHandler.cs:line 856
   at Microsoft.IdentityModel.JsonWebTokens.JsonWebTokenHandler.CreateTokenPrivate(JObject payload, SigningCredentials signingCredentials, EncryptingCredentials encryptingCredentials, String compressionAlgorithm, IDictionary`2 additionalHeaderClaims) in D:\a\1\s\src\Microsoft.IdentityModel.JsonWebTokens\JsonWebTokenHandler.cs:line 501
   at Microsoft.IdentityModel.JsonWebTokens.JsonWebTokenHandler.CreateToken(String payload, EncryptingCredentials encryptingCredentials) in D:\a\1\s\src\Microsoft.IdentityModel.JsonWebTokens\JsonWebTokenHandler.cs:line 305
   at CredentialManagement.Program.DemoJwe() in C:\Users\...\source\repos\CredentialManagement\Program.cs:line 43
   at CredentialManagement.Program.Main(String[] args) in C:\Users\...\source\repos\CredentialManagement\Program.cs:line 22

@rudeGit
Copy link

rudeGit commented Apr 12, 2021

@brentschmaltz Is this being addressed in the new release? What does v6 Next mean?

@killerjoe1990
Copy link

+1 running into exact same issue, need this added asap plz

@jlodom
Copy link

jlodom commented Jun 26, 2021

+1 This was one of two issues I ran into in the question below (I will be updating the entry in the next 24 hours to reflect solution/workaround hopefully).
https://stackoverflow.com/questions/68106472/decrypting-jsonwebtoken-using-jsonwebkey-or-jsonwebkeyset-in-c-sharp
Since the alg does have cross-platform support in dotnet generally, it would be good to have:
https://docs.microsoft.com/en-us/dotnet/standard/security/cross-platform-cryptography

@JonathanAtBitaddict
Copy link

+1
This would really be needed

@lapo-luchini
Copy link

lapo-luchini commented Mar 23, 2023

(I will be updating the entry in the next 24 hours to reflect solution/workaround hopefully

I tried the work-around and it works for OAEP-256.

(AES-GCM decryption works fine without any change, so in the end I decided it wasn't worth it to add support for AES-GCM encryption to the provider.)

using System.Security.Cryptography;
using Microsoft.IdentityModel.Tokens;

// inspired to: https://stackoverflow.com/a/68272468/166524
public class OAEP256CryptoProvider : ICryptoProvider
{
    public const string OAEP_256 = "RSA-OAEP-256";

    public bool IsSupportedAlgorithm(string algorithm, params object[] args)
    {
        return (algorithm == OAEP_256);
    }

    public object Create(string algorithm, params object[] args)
    {
        return new RsaOaepKeyWrapProvider(args[0] as SecurityKey, algorithm);
    }

    public void Release(object cryptoInstance)
    {
    }

    private class RsaOaepKeyWrapProvider : KeyWrapProvider
    {
        public RsaOaepKeyWrapProvider(SecurityKey key, string algorithm)
        {
            Key = (RsaSecurityKey) key;
            Algorithm = algorithm;
        }

        protected override void Dispose(bool disposing)
        {
        }

        public override byte[] UnwrapKey(byte[] keyBytes)
        {
            return Key.Rsa.Decrypt(keyBytes, RSAEncryptionPadding.OaepSHA256);
        }

        public override byte[] WrapKey(byte[] keyBytes)
        {
            return Key.Rsa.Encrypt(keyBytes, RSAEncryptionPadding.OaepSHA256);
        }

        public override string Algorithm { get; }
        public override string Context { get; set; }
        public override RsaSecurityKey Key { get; }
    }

}

karoberts added a commit to karoberts/azure-activedirectory-identitymodel-extensions-for-dotnet that referenced this issue Aug 7, 2023
karoberts added a commit to karoberts/azure-activedirectory-identitymodel-extensions-for-dotnet that referenced this issue Aug 7, 2023

Verified

This commit was signed with the committer’s verified signature.
radoering Randy Döring
karoberts added a commit to karoberts/azure-activedirectory-identitymodel-extensions-for-dotnet that referenced this issue Sep 12, 2023
@jennyf19 jennyf19 removed this from the v6 Backlog milestone Sep 19, 2023
karoberts added a commit to karoberts/azure-activedirectory-identitymodel-extensions-for-dotnet that referenced this issue Jan 11, 2024
karoberts added a commit to karoberts/azure-activedirectory-identitymodel-extensions-for-dotnet that referenced this issue May 31, 2024
removing obsoleted ifdefs since net452 support was removed
brentschmaltz pushed a commit that referenced this issue Jun 13, 2024
removing obsoleted ifdefs since net452 support was removed
brentschmaltz pushed a commit that referenced this issue Jun 14, 2024
This reverts commit 67da84e.
brentschmaltz pushed a commit that referenced this issue Jun 14, 2024
This reverts commit 67da84e.
@jennyf19 jennyf19 added P2 High, but not urgent. Needs to be addressed within the next couple of sprints and removed P1 More important, prioritize highly labels Oct 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Customer reported Indicates issue was opened by customer Enhancement The issue is a new feature P2 High, but not urgent. Needs to be addressed within the next couple of sprints
Projects
None yet
Development

No branches or pull requests

10 participants