diff options
author | Martin Baulig <mabaul@microsoft.com> | 2019-02-27 02:17:37 +0300 |
---|---|---|
committer | Alexander Köplinger <alex.koeplinger@outlook.com> | 2019-02-27 02:17:37 +0300 |
commit | 6a3b12b622c0a80e4f5f662f2a6fe869ecae1e81 (patch) | |
tree | 2d930a2797ecb48878a8440142c4b26b727685bc /mcs/class/Mono.Security | |
parent | 48f65d5108d09a6d2b91154953642bb2f4efe191 (diff) |
Revert "[Mono.Security]: minor `CryptoConvert` changes to make it more linker-friendly." (#13202)
This reverts commit ef7e64a5beb6d6ccc4e44f0dedfd65550e7dbbab.
Diffstat (limited to 'mcs/class/Mono.Security')
-rw-r--r-- | mcs/class/Mono.Security/Mono.Security.Cryptography/CryptoConvert.cs | 81 |
1 files changed, 29 insertions, 52 deletions
diff --git a/mcs/class/Mono.Security/Mono.Security.Cryptography/CryptoConvert.cs b/mcs/class/Mono.Security/Mono.Security.Cryptography/CryptoConvert.cs index decaeca0c4c..3f06114dd0f 100644 --- a/mcs/class/Mono.Security/Mono.Security.Cryptography/CryptoConvert.cs +++ b/mcs/class/Mono.Security/Mono.Security.Cryptography/CryptoConvert.cs @@ -77,24 +77,6 @@ namespace Mono.Security.Cryptography { return null; } -#if INSIDE_CORLIB - static internal bool TryImportCapiPrivateKeyBlob (byte[] blob, int offset) - { - try { - var rsap = GetParametersFromCapiPrivateKeyBlob (blob, offset); - // Since we are only checking whether this throws an exception and - // not actually returning the `RSA` object, we can use `RSAManaged` - // here because that's what the `RSACryptoServiceProvider` implementation - // does internally. - var rsa = new RSAManaged (); - rsa.ImportParameters (rsap); - return true; - } catch (CryptographicException) { - return false; - } - } -#endif - // convert the key from PRIVATEKEYBLOB to RSA // http://msdn.microsoft.com/library/default.asp?url=/library/en-us/security/Security/private_key_blobs.asp // e.g. SNK files, PVK files @@ -105,38 +87,6 @@ namespace Mono.Security.Cryptography { static public RSA FromCapiPrivateKeyBlob (byte[] blob, int offset) { - RSAParameters rsap = GetParametersFromCapiPrivateKeyBlob (blob, offset); - -#if INSIDE_CORLIB && MOBILE - RSA rsa = RSA.Create (); - rsa.ImportParameters (rsap); -#else - RSA rsa = null; - try { - rsa = RSA.Create (); - rsa.ImportParameters (rsap); - } - catch (CryptographicException ce) { - // this may cause problem when this code is run under - // the SYSTEM identity on Windows (e.g. ASP.NET). See - // http://bugzilla.ximian.com/show_bug.cgi?id=77559 - try { - CspParameters csp = new CspParameters (); - csp.Flags = CspProviderFlags.UseMachineKeyStore; - rsa = new RSACryptoServiceProvider (csp); - rsa.ImportParameters (rsap); - } - catch { - // rethrow original, not the later, exception if this fails - throw ce; - } - } -#endif - return rsa; - } - - static RSAParameters GetParametersFromCapiPrivateKeyBlob (byte[] blob, int offset) - { if (blob == null) throw new ArgumentNullException ("blob"); if (offset >= blob.Length) @@ -211,10 +161,37 @@ namespace Mono.Security.Cryptography { Buffer.BlockCopy (blob, pos, rsap.D, 0, byteLen); Array.Reverse (rsap.D); } - return rsap; - } catch (Exception e) { + } + catch (Exception e) { throw new CryptographicException ("Invalid blob.", e); } + +#if INSIDE_CORLIB && MOBILE + RSA rsa = RSA.Create (); + rsa.ImportParameters (rsap); +#else + RSA rsa = null; + try { + rsa = RSA.Create (); + rsa.ImportParameters (rsap); + } + catch (CryptographicException ce) { + // this may cause problem when this code is run under + // the SYSTEM identity on Windows (e.g. ASP.NET). See + // http://bugzilla.ximian.com/show_bug.cgi?id=77559 + try { + CspParameters csp = new CspParameters (); + csp.Flags = CspProviderFlags.UseMachineKeyStore; + rsa = new RSACryptoServiceProvider (csp); + rsa.ImportParameters (rsap); + } + catch { + // rethrow original, not the later, exception if this fails + throw ce; + } + } +#endif + return rsa; } static public DSA FromCapiPrivateKeyBlobDSA (byte[] blob) |