From: Kevin Jones Date: Wed, 16 Jun 2021 16:20:33 +0000 (-0400) Subject: Remove uses of Rijndael from EncryptedXml where possible (#54238) X-Git-Tag: submit/tizen/20210909.063632~735 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9d0be76824dd00e53115586111dc9268f85e99cf;p=platform%2Fupstream%2Fdotnet%2Fruntime.git Remove uses of Rijndael from EncryptedXml where possible (#54238) Also dispose of AES usages to match behavior of the .NET Framework. --- diff --git a/src/libraries/System.Security.Cryptography.Xml/src/System.Security.Cryptography.Xml.csproj b/src/libraries/System.Security.Cryptography.Xml/src/System.Security.Cryptography.Xml.csproj index 0522510..0f93321 100644 --- a/src/libraries/System.Security.Cryptography.Xml/src/System.Security.Cryptography.Xml.csproj +++ b/src/libraries/System.Security.Cryptography.Xml/src/System.Security.Cryptography.Xml.csproj @@ -6,8 +6,6 @@ true - - $(NoWarn);SYSLIB0022 diff --git a/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/EncryptedXml.cs b/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/EncryptedXml.cs index 7762ff9..7878659 100644 --- a/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/EncryptedXml.cs +++ b/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/EncryptedXml.cs @@ -546,13 +546,15 @@ namespace System.Security.Cryptography.Xml 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); + using (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); + // 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, aes, false); + } return ed; } @@ -595,7 +597,9 @@ namespace System.Security.Cryptography.Xml // 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) @@ -621,13 +625,15 @@ namespace System.Security.Cryptography.Xml 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)); + using (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); + // 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, aes, false); + } return ed; } @@ -868,7 +874,9 @@ namespace System.Security.Cryptography.Xml // 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); @@ -912,7 +920,9 @@ namespace System.Security.Cryptography.Xml // 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);