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

Remove uses of Rijndael from EncryptedXml where possible #54238

Merged
merged 3 commits into from
Jun 16, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -6,8 +6,6 @@
<!-- DesignTimeBuild requires all the TargetFramework Derived Properties to not be present in the first property group. -->
<PropertyGroup>
<IsPartialFacadeAssembly Condition="'$(TargetFramework)' == 'net461'">true</IsPartialFacadeAssembly>
<!-- RijndaelManaged' is obsolete: 'The Rijndael and RijndaelManaged types are obsolete. Use Aes instead. https://github.com/dotnet/runtime/issues/54145. -->
<NoWarn Condition="$([MSBuild]::GetTargetFrameworkIdentifier('$(TargetFramework)')) == '.NETCoreApp'">$(NoWarn);SYSLIB0022</NoWarn>
</PropertyGroup>
<ItemGroup Condition="'$(IsPartialFacadeAssembly)' != 'true'">
<Compile Include="System\Security\Cryptography\Xml\AncestralNamespaceContextManager.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -546,13 +546,13 @@ public EncryptedData Encrypt(XmlElement inputElement, X509Certificate2 certifica
ek.KeyInfo.AddClause(new KeyInfoX509Data(certificate));

// Create a random AES session key and encrypt it with the public key associated with the certificate.
RijndaelManaged rijn = new RijndaelManaged();
ek.CipherData.CipherValue = EncryptedXml.EncryptKey(rijn.Key, rsaPublicKey, false);
Aes aes = Aes.Create();
ek.CipherData.CipherValue = EncryptedXml.EncryptKey(aes.Key, rsaPublicKey, false);

// Encrypt the input element with the random session key that we've created above.
KeyInfoEncryptedKey kek = new KeyInfoEncryptedKey(ek);
ed.KeyInfo.AddClause(kek);
ed.CipherData.CipherValue = EncryptData(inputElement, rijn, false);
ed.CipherData.CipherValue = EncryptData(inputElement, aes, false);

return ed;
}
Expand Down Expand Up @@ -595,7 +595,9 @@ public EncryptedData Encrypt(XmlElement inputElement, string keyName)
// CMS Triple DES Key Wrap
encryptionMethod = EncryptedXml.XmlEncTripleDESKeyWrapUrl;
}
#pragma warning disable SYSLIB0022 // Rijndael types are obsolete
else if (symKey is Rijndael || symKey is Aes)
#pragma warning restore SYSLIB0022
{
// FIPS AES Key Wrap
switch (symKey.KeySize)
Expand All @@ -621,13 +623,13 @@ public EncryptedData Encrypt(XmlElement inputElement, string keyName)
ek.KeyInfo.AddClause(new KeyInfoName(keyName));

// Create a random AES session key and encrypt it with the public key associated with the certificate.
RijndaelManaged rijn = new RijndaelManaged();
ek.CipherData.CipherValue = (symKey == null ? EncryptedXml.EncryptKey(rijn.Key, rsa, false) : EncryptedXml.EncryptKey(rijn.Key, symKey));
Aes aes = Aes.Create();
ek.CipherData.CipherValue = (symKey == null ? EncryptedXml.EncryptKey(aes.Key, rsa, false) : EncryptedXml.EncryptKey(aes.Key, symKey));

// Encrypt the input element with the random session key that we've created above.
KeyInfoEncryptedKey kek = new KeyInfoEncryptedKey(ek);
ed.KeyInfo.AddClause(kek);
ed.CipherData.CipherValue = EncryptData(inputElement, rijn, false);
ed.CipherData.CipherValue = EncryptData(inputElement, aes, false);

return ed;
}
Expand Down Expand Up @@ -868,7 +870,9 @@ public static byte[] EncryptKey(byte[] keyData, SymmetricAlgorithm symmetricAlgo
// CMS Triple DES Key Wrap
return SymmetricKeyWrap.TripleDESKeyWrapEncrypt(symmetricAlgorithm.Key, keyData);
}
#pragma warning disable SYSLIB0022 // Rijndael types are obsolete
else if (symmetricAlgorithm is Rijndael || symmetricAlgorithm is Aes)
#pragma warning restore SYSLIB0022
{
// FIPS AES Key Wrap
return SymmetricKeyWrap.AESKeyWrapEncrypt(symmetricAlgorithm.Key, keyData);
Expand Down Expand Up @@ -912,7 +916,9 @@ public static byte[] DecryptKey(byte[] keyData, SymmetricAlgorithm symmetricAlgo
// CMS Triple DES Key Wrap
return SymmetricKeyWrap.TripleDESKeyWrapDecrypt(symmetricAlgorithm.Key, keyData);
}
#pragma warning disable SYSLIB0022 // Rijndael types are obsolete
else if (symmetricAlgorithm is Rijndael || symmetricAlgorithm is Aes)
#pragma warning restore SYSLIB0022
{
// FIPS AES Key Wrap
return SymmetricKeyWrap.AESKeyWrapDecrypt(symmetricAlgorithm.Key, keyData);
Expand Down