diff --git a/MediaBrowser.Server.Mono/Networking/CertificateGenerator.cs b/MediaBrowser.Server.Mono/Networking/CertificateGenerator.cs index 6e37322cbd..58c5bba2d2 100644 --- a/MediaBrowser.Server.Mono/Networking/CertificateGenerator.cs +++ b/MediaBrowser.Server.Mono/Networking/CertificateGenerator.cs @@ -1,8 +1,8 @@ using MediaBrowser.Model.Logging; -using Mono.Security.X509; using System; using System.Collections; using System.Security.Cryptography; +using MediaBrowser.Server.Mono.Security; namespace MediaBrowser.Server.Mono.Networking { diff --git a/MediaBrowser.Server.Mono/Security/ASN1.cs b/MediaBrowser.Server.Mono/Security/ASN1.cs index 751a2ece4e..2fcbde7c16 100644 --- a/MediaBrowser.Server.Mono/Security/ASN1.cs +++ b/MediaBrowser.Server.Mono/Security/ASN1.cs @@ -34,18 +34,13 @@ using System.Collections; using System.IO; using System.Text; -namespace Mono.Security { +namespace MediaBrowser.Server.Mono.Security { // References: // a. ITU ASN.1 standards (free download) // http://www.itu.int/ITU-T/studygroups/com17/languages/ -#if INSIDE_CORLIB - internal -#else - public -#endif - class ASN1 { + public class ASN1 { private byte m_nTag; private byte[] m_aValue; diff --git a/MediaBrowser.Server.Mono/Security/ASN1Convert.cs b/MediaBrowser.Server.Mono/Security/ASN1Convert.cs index 3a1cf93018..f25a5275af 100644 --- a/MediaBrowser.Server.Mono/Security/ASN1Convert.cs +++ b/MediaBrowser.Server.Mono/Security/ASN1Convert.cs @@ -30,23 +30,17 @@ // using System; -using System.Collections; using System.Globalization; using System.Security.Cryptography; using System.Text; -namespace Mono.Security { +namespace MediaBrowser.Server.Mono.Security { // References: // a. ITU ASN.1 standards (free download) // http://www.itu.int/ITU-T/studygroups/com17/languages/ -#if INSIDE_CORLIB - internal -#else - public -#endif - static class ASN1Convert { + public static class ASN1Convert { // RFC3280, section 4.2.1.5 // CAs conforming to this profile MUST always encode certificate // validity dates through the year 2049 as UTCTime; certificate validity diff --git a/MediaBrowser.Server.Mono/Security/BitConverterLE.cs b/MediaBrowser.Server.Mono/Security/BitConverterLE.cs index a787f5015c..29b6ee023b 100644 --- a/MediaBrowser.Server.Mono/Security/BitConverterLE.cs +++ b/MediaBrowser.Server.Mono/Security/BitConverterLE.cs @@ -29,7 +29,7 @@ using System; -namespace Mono.Security +namespace MediaBrowser.Server.Mono.Security { internal sealed class BitConverterLE { diff --git a/MediaBrowser.Server.Mono/Security/CryptoConvert.cs b/MediaBrowser.Server.Mono/Security/CryptoConvert.cs index 3f06114dd0..62c28bd27e 100644 --- a/MediaBrowser.Server.Mono/Security/CryptoConvert.cs +++ b/MediaBrowser.Server.Mono/Security/CryptoConvert.cs @@ -32,14 +32,9 @@ using System.Globalization; using System.Security.Cryptography; using System.Text; -namespace Mono.Security.Cryptography { +namespace MediaBrowser.Server.Mono.Security { -#if INSIDE_CORLIB - internal -#else - public -#endif - sealed class CryptoConvert { + public sealed class CryptoConvert { private CryptoConvert () { @@ -166,32 +161,31 @@ namespace Mono.Security.Cryptography { 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; + 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; + } + } + return rsa; } static public DSA FromCapiPrivateKeyBlobDSA (byte[] blob) @@ -251,32 +245,31 @@ namespace Mono.Security.Cryptography { throw new CryptographicException ("Invalid blob.", e); } -#if INSIDE_CORLIB && MOBILE - DSA dsa = (DSA)DSA.Create (); - dsa.ImportParameters (dsap); -#else - DSA dsa = null; - try { - dsa = (DSA)DSA.Create (); - dsa.ImportParameters (dsap); - } - 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; - dsa = new DSACryptoServiceProvider (csp); - dsa.ImportParameters (dsap); - } - catch { - // rethrow original, not the later, exception if this fails - throw ce; - } - } -#endif - return dsa; + DSA dsa = null; + try + { + dsa = (DSA)DSA.Create(); + dsa.ImportParameters(dsap); + } + 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; + dsa = new DSACryptoServiceProvider(csp); + dsa.ImportParameters(dsap); + } + catch + { + // rethrow original, not the later, exception if this fails + throw ce; + } + } + return dsa; } static public byte[] ToCapiPrivateKeyBlob (RSA rsa) @@ -444,26 +437,23 @@ namespace Mono.Security.Cryptography { rsap.Modulus = new byte [byteLen]; Buffer.BlockCopy (blob, pos, rsap.Modulus, 0, byteLen); Array.Reverse (rsap.Modulus); -#if INSIDE_CORLIB && MOBILE - RSA rsa = RSA.Create (); - rsa.ImportParameters (rsap); -#else - RSA rsa = null; - try { - rsa = RSA.Create (); - rsa.ImportParameters (rsap); - } - catch (CryptographicException) { - // 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 - CspParameters csp = new CspParameters (); - csp.Flags = CspProviderFlags.UseMachineKeyStore; - rsa = new RSACryptoServiceProvider (csp); - rsa.ImportParameters (rsap); - } -#endif - return rsa; + RSA rsa = null; + try + { + rsa = RSA.Create(); + rsa.ImportParameters(rsap); + } + catch (CryptographicException) + { + // 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 + CspParameters csp = new CspParameters(); + csp.Flags = CspProviderFlags.UseMachineKeyStore; + rsa = new RSACryptoServiceProvider(csp); + rsa.ImportParameters(rsap); + } + return rsa; } catch (Exception e) { throw new CryptographicException ("Invalid blob.", e); diff --git a/MediaBrowser.Server.Mono/Security/PKCS1.cs b/MediaBrowser.Server.Mono/Security/PKCS1.cs index 4e579eee94..86ed6f2d8f 100644 --- a/MediaBrowser.Server.Mono/Security/PKCS1.cs +++ b/MediaBrowser.Server.Mono/Security/PKCS1.cs @@ -31,18 +31,13 @@ using System; using System.Security.Cryptography; -namespace Mono.Security.Cryptography { +namespace MediaBrowser.Server.Mono.Security { // References: // a. PKCS#1: RSA Cryptography Standard // http://www.rsasecurity.com/rsalabs/pkcs/pkcs-1/index.html -#if INSIDE_CORLIB - internal -#else - public -#endif - sealed class PKCS1 { + public sealed class PKCS1 { private PKCS1 () { diff --git a/MediaBrowser.Server.Mono/Security/PKCS12.cs b/MediaBrowser.Server.Mono/Security/PKCS12.cs index fe39b70365..f6c32421e8 100644 --- a/MediaBrowser.Server.Mono/Security/PKCS12.cs +++ b/MediaBrowser.Server.Mono/Security/PKCS12.cs @@ -37,17 +37,9 @@ using System.IO; using System.Security.Cryptography; using System.Text; -using Mono.Security; -using Mono.Security.Cryptography; +namespace MediaBrowser.Server.Mono.Security { -namespace Mono.Security.X509 { - -#if INSIDE_CORLIB - internal -#else - public -#endif - class PKCS5 { + public class PKCS5 { public const string pbeWithMD2AndDESCBC = "1.2.840.113549.1.5.1"; public const string pbeWithMD5AndDESCBC = "1.2.840.113549.1.5.3"; @@ -59,12 +51,7 @@ namespace Mono.Security.X509 { public PKCS5 () {} } -#if INSIDE_CORLIB - internal -#else - public -#endif - class PKCS9 { + public class PKCS9 { public const string friendlyName = "1.2.840.113549.1.9.20"; public const string localKeyId = "1.2.840.113549.1.9.21"; @@ -92,12 +79,7 @@ namespace Mono.Security.X509 { } -#if INSIDE_CORLIB - internal -#else - public -#endif - class PKCS12 : ICloneable { + public class PKCS12 : ICloneable { public const string pbeWithSHAAnd128BitRC4 = "1.2.840.113549.1.12.1.1"; public const string pbeWithSHAAnd40BitRC4 = "1.2.840.113549.1.12.1.2"; @@ -657,29 +639,8 @@ namespace Mono.Security.X509 { } SymmetricAlgorithm sa = null; -#if INSIDE_CORLIB && FULL_AOT_RUNTIME - // we do not want CryptoConfig to bring the whole crypto stack - // in particular Rijndael which is not supported by CommonCrypto - switch (algorithm) { - case "DES": - sa = DES.Create (); - break; - case "RC2": - sa = RC2.Create (); - break; - case "TripleDES": - sa = TripleDES.Create (); - break; - case "RC4": - sa = RC4.Create (); - break; - default: - throw new NotSupportedException (algorithm); - } -#else - sa = SymmetricAlgorithm.Create (algorithm); -#endif - sa.Key = pd.DeriveKey (keyLength); + sa = SymmetricAlgorithm.Create(algorithm); + sa.Key = pd.DeriveKey (keyLength); // IV required only for block ciphers (not stream ciphers) if (ivLength > 0) { sa.IV = pd.DeriveIV (ivLength); diff --git a/MediaBrowser.Server.Mono/Security/PKCS7.cs b/MediaBrowser.Server.Mono/Security/PKCS7.cs index d7e93569d8..7a34580e9f 100644 --- a/MediaBrowser.Server.Mono/Security/PKCS7.cs +++ b/MediaBrowser.Server.Mono/Security/PKCS7.cs @@ -33,16 +33,9 @@ using System; using System.Collections; using System.Security.Cryptography; -using Mono.Security.X509; +namespace MediaBrowser.Server.Mono.Security { -namespace Mono.Security { - -#if INSIDE_CORLIB - internal -#else - public -#endif - sealed class PKCS7 { + public sealed class PKCS7 { public class Oid { // pkcs 1 diff --git a/MediaBrowser.Server.Mono/Security/PKCS8.cs b/MediaBrowser.Server.Mono/Security/PKCS8.cs index 352e4649b0..b2f28f3188 100644 --- a/MediaBrowser.Server.Mono/Security/PKCS8.cs +++ b/MediaBrowser.Server.Mono/Security/PKCS8.cs @@ -33,14 +33,9 @@ using System; using System.Collections; using System.Security.Cryptography; -using Mono.Security.X509; +namespace MediaBrowser.Server.Mono.Security { -namespace Mono.Security.Cryptography { - -#if !INSIDE_CORLIB - public -#endif - sealed class PKCS8 { + public sealed class PKCS8 { public enum KeyInfo { PrivateKey, @@ -277,21 +272,15 @@ namespace Mono.Security.Cryptography { rsa.ImportParameters (param); } catch (CryptographicException) { -#if MONOTOUCH - // there's no machine-wide store available for iOS so we can drop the dependency on - // CspParameters (which drops other things, like XML key persistance, unless used elsewhere) - throw; -#else - // 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 - CspParameters csp = new CspParameters (); - csp.Flags = CspProviderFlags.UseMachineKeyStore; - rsa = new RSACryptoServiceProvider (csp); - rsa.ImportParameters (param); -#endif - } - return rsa; + // 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 + CspParameters csp = new CspParameters(); + csp.Flags = CspProviderFlags.UseMachineKeyStore; + rsa = new RSACryptoServiceProvider(csp); + rsa.ImportParameters(param); + } + return rsa; } /* diff --git a/MediaBrowser.Server.Mono/Security/X501Name.cs b/MediaBrowser.Server.Mono/Security/X501Name.cs index 54279c1d25..d77158e450 100644 --- a/MediaBrowser.Server.Mono/Security/X501Name.cs +++ b/MediaBrowser.Server.Mono/Security/X501Name.cs @@ -31,10 +31,7 @@ using System; using System.Globalization; using System.Text; -using Mono.Security; -using Mono.Security.Cryptography; - -namespace Mono.Security.X509 { +namespace MediaBrowser.Server.Mono.Security { // References: // 1. Information technology - Open Systems Interconnection - The Directory: Models @@ -49,12 +46,7 @@ namespace Mono.Security.X509 { * * RelativeDistinguishedName ::= SET OF AttributeTypeAndValue */ -#if INSIDE_CORLIB - internal -#else - public -#endif - sealed class X501 { + public sealed class X501 { static byte[] countryName = { 0x55, 0x04, 0x06 }; static byte[] organizationName = { 0x55, 0x04, 0x0A }; diff --git a/MediaBrowser.Server.Mono/Security/X509Builder.cs b/MediaBrowser.Server.Mono/Security/X509Builder.cs index 95926ae3fd..4801f3d8a2 100644 --- a/MediaBrowser.Server.Mono/Security/X509Builder.cs +++ b/MediaBrowser.Server.Mono/Security/X509Builder.cs @@ -33,9 +33,7 @@ using System; using System.Globalization; using System.Security.Cryptography; -using Mono.Security; - -namespace Mono.Security.X509 { +namespace MediaBrowser.Server.Mono.Security { public abstract class X509Builder { diff --git a/MediaBrowser.Server.Mono/Security/X509Certificate.cs b/MediaBrowser.Server.Mono/Security/X509Certificate.cs index 5b356e2e2c..fa817d9597 100644 --- a/MediaBrowser.Server.Mono/Security/X509Certificate.cs +++ b/MediaBrowser.Server.Mono/Security/X509Certificate.cs @@ -31,26 +31,21 @@ using System; using System.Runtime.Serialization; using System.Security.Cryptography; -using SSCX = System.Security.Cryptography.X509Certificates; using System.Security.Permissions; using System.Text; -using Mono.Security.Cryptography; -namespace Mono.Security.X509 { +namespace MediaBrowser.Server.Mono.Security { - // References: - // a. Internet X.509 Public Key Infrastructure Certificate and CRL Profile - // http://www.ietf.org/rfc/rfc3280.txt - // b. ITU ASN.1 standards (free download) - // http://www.itu.int/ITU-T/studygroups/com17/languages/ + // References: + // a. Internet X.509 Public Key Infrastructure Certificate and CRL Profile + // http://www.ietf.org/rfc/rfc3280.txt + // b. ITU ASN.1 standards (free download) + // http://www.itu.int/ITU-T/studygroups/com17/languages/ -#if INSIDE_CORLIB - internal class X509Certificate : ISerializable { -#else - public class X509Certificate : ISerializable { -#endif + public class X509Certificate : ISerializable + { - private ASN1 decoder; + private ASN1 decoder; private byte[] m_encodedcert; private DateTime m_from; diff --git a/MediaBrowser.Server.Mono/Security/X509CertificateBuilder.cs b/MediaBrowser.Server.Mono/Security/X509CertificateBuilder.cs index 3ee2816283..9b51d9e4ec 100644 --- a/MediaBrowser.Server.Mono/Security/X509CertificateBuilder.cs +++ b/MediaBrowser.Server.Mono/Security/X509CertificateBuilder.cs @@ -32,7 +32,7 @@ using System; using System.Security.Cryptography; -namespace Mono.Security.X509 { +namespace MediaBrowser.Server.Mono.Security { // From RFC3280 /* * Certificate ::= SEQUENCE { diff --git a/MediaBrowser.Server.Mono/Security/X509CertificateCollection.cs b/MediaBrowser.Server.Mono/Security/X509CertificateCollection.cs index 3fd834b0cf..6bb465b283 100644 --- a/MediaBrowser.Server.Mono/Security/X509CertificateCollection.cs +++ b/MediaBrowser.Server.Mono/Security/X509CertificateCollection.cs @@ -31,15 +31,10 @@ using System; using System.Collections; -namespace Mono.Security.X509 { +namespace MediaBrowser.Server.Mono.Security { [Serializable] -#if INSIDE_CORLIB - internal -#else - public -#endif - class X509CertificateCollection : CollectionBase, IEnumerable { + public class X509CertificateCollection : CollectionBase, IEnumerable { public X509CertificateCollection () { diff --git a/MediaBrowser.Server.Mono/Security/X509Extension.cs b/MediaBrowser.Server.Mono/Security/X509Extension.cs index 202be51320..984c3542b4 100644 --- a/MediaBrowser.Server.Mono/Security/X509Extension.cs +++ b/MediaBrowser.Server.Mono/Security/X509Extension.cs @@ -31,9 +31,7 @@ using System; using System.Globalization; using System.Text; -using Mono.Security; - -namespace Mono.Security.X509 { +namespace MediaBrowser.Server.Mono.Security { /* * Extension ::= SEQUENCE { * extnID OBJECT IDENTIFIER, @@ -41,12 +39,7 @@ namespace Mono.Security.X509 { * extnValue OCTET STRING * } */ -#if INSIDE_CORLIB - internal -#else - public -#endif - class X509Extension { + public class X509Extension { protected string extnOid; protected bool extnCritical; diff --git a/MediaBrowser.Server.Mono/Security/X509Extensions.cs b/MediaBrowser.Server.Mono/Security/X509Extensions.cs index cb8e15defa..b86fe1c401 100644 --- a/MediaBrowser.Server.Mono/Security/X509Extensions.cs +++ b/MediaBrowser.Server.Mono/Security/X509Extensions.cs @@ -32,20 +32,13 @@ using System; using System.Collections; -using Mono.Security; - -namespace Mono.Security.X509 { +namespace MediaBrowser.Server.Mono.Security { /* * Extensions ::= SEQUENCE SIZE (1..MAX) OF Extension * * Note: 1..MAX -> There shouldn't be 0 Extensions in the ASN1 structure */ -#if INSIDE_CORLIB - internal -#else - public -#endif - sealed class X509ExtensionCollection : CollectionBase, IEnumerable { + public sealed class X509ExtensionCollection : CollectionBase, IEnumerable { private bool readOnly; diff --git a/MediaBrowser.Server.Mono/Security/X520Attributes.cs b/MediaBrowser.Server.Mono/Security/X520Attributes.cs index 53ad424b51..a61d31ad9f 100644 --- a/MediaBrowser.Server.Mono/Security/X520Attributes.cs +++ b/MediaBrowser.Server.Mono/Security/X520Attributes.cs @@ -28,12 +28,9 @@ // using System; -using System.Globalization; using System.Text; -using Mono.Security; - -namespace Mono.Security.X509 { +namespace MediaBrowser.Server.Mono.Security { // References: // 1. Information technology - Open Systems Interconnection - The Directory: Selected attribute types @@ -55,12 +52,7 @@ namespace Mono.Security.X509 { * * AttributeValue ::= ANY DEFINED BY AttributeType */ -#if INSIDE_CORLIB - internal -#else - public -#endif - class X520 { + public class X520 { public abstract class AttributeTypeAndValue { private string oid;