Skip to content

Commit

Permalink
Dispose KeyWrapProvider in JwtSecurityTokenHandler
Browse files Browse the repository at this point in the history
KeyWrapProvider is an IDisposable, so we should dispose it when done
using it?

This was flagged by a static analysis tool.
  • Loading branch information
omajid committed Jun 24, 2024
1 parent 55cc10e commit 29fc204
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1867,15 +1867,15 @@ internal IEnumerable<SecurityKey> GetContentEncryptionKeys(JwtSecurityToken jwtT
string apu = jwtToken.Header.GetStandardClaim(JwtHeaderParameterNames.Apu);
string apv = jwtToken.Header.GetStandardClaim(JwtHeaderParameterNames.Apv);
SecurityKey kdf = ecdhKeyExchangeProvider.GenerateKdf(apu, apv);
var kwp = key.CryptoProviderFactory.CreateKeyWrapProviderForUnwrap(kdf, ecdhKeyExchangeProvider.GetEncryptionAlgorithm());
using var kwp = key.CryptoProviderFactory.CreateKeyWrapProviderForUnwrap(kdf, ecdhKeyExchangeProvider.GetEncryptionAlgorithm());
var unwrappedKey = kwp.UnwrapKey(Base64UrlEncoder.DecodeBytes(jwtToken.RawEncryptedKey));
unwrappedKeys.Add(new SymmetricSecurityKey(unwrappedKey));
}
else
#endif
if (key.CryptoProviderFactory.IsSupportedAlgorithm(jwtToken.Header.Alg, key))
{
var kwp = key.CryptoProviderFactory.CreateKeyWrapProviderForUnwrap(key, jwtToken.Header.Alg);
using var kwp = key.CryptoProviderFactory.CreateKeyWrapProviderForUnwrap(key, jwtToken.Header.Alg);
var unwrappedKey = kwp.UnwrapKey(Base64UrlEncoder.DecodeBytes(jwtToken.RawEncryptedKey));
unwrappedKeys.Add(new SymmetricSecurityKey(unwrappedKey));
}
Expand Down

0 comments on commit 29fc204

Please sign in to comment.