From ac29e68273755f3903d47901da19ef9dc1259a80 Mon Sep 17 00:00:00 2001 From: Simone Curzi Date: Sun, 1 Nov 2020 08:29:35 +0100 Subject: [PATCH] Revised ExtensionsContainerAttribute to constrain execution on specific clients. --- Sources/ThreatsManager.Engine/Manager.cs | 22 ++++++++++++-- .../ExtensionsContainerAttribute.cs | 30 +++++++++++++++++-- .../MicrosoftContainerAttribute.cs | 12 -------- 3 files changed, 47 insertions(+), 17 deletions(-) delete mode 100644 Sources/ThreatsManager.Interfaces/MicrosoftContainerAttribute.cs diff --git a/Sources/ThreatsManager.Engine/Manager.cs b/Sources/ThreatsManager.Engine/Manager.cs index eaf460e1..1bb4b0cc 100644 --- a/Sources/ThreatsManager.Engine/Manager.cs +++ b/Sources/ThreatsManager.Engine/Manager.cs @@ -213,11 +213,27 @@ private bool CheckVersion([NotNull] Version platformVersion, [NotNull] Assembly switch (attribute.ConstructorArguments.Count) { case 1: - attrib = new ExtensionsContainerAttribute(attribute.ConstructorArguments[0].Value.ToString()); + attrib = new ExtensionsContainerAttribute((string) attribute.ConstructorArguments[0].Value); break; case 2: - attrib = new ExtensionsContainerAttribute(attribute.ConstructorArguments[0].Value.ToString(), - attribute.ConstructorArguments[1].ToString()); + if (attribute.ConstructorArguments[1].ArgumentType == typeof(string)) + { + attrib = new ExtensionsContainerAttribute( + (string) attribute.ConstructorArguments[0].Value, + (string) attribute.ConstructorArguments[1].Value); + } + else + { + attrib = new ExtensionsContainerAttribute( + (string) attribute.ConstructorArguments[0].Value, + (uint) attribute.ConstructorArguments[1].Value); + } + break; + case 3: + attrib = new ExtensionsContainerAttribute( + (string) attribute.ConstructorArguments[0].Value, + (string) attribute.ConstructorArguments[1].Value, + (uint) attribute.ConstructorArguments[2].Value); break; } diff --git a/Sources/ThreatsManager.Interfaces/ExtensionsContainerAttribute.cs b/Sources/ThreatsManager.Interfaces/ExtensionsContainerAttribute.cs index 4a8cabd4..db8a6b41 100644 --- a/Sources/ThreatsManager.Interfaces/ExtensionsContainerAttribute.cs +++ b/Sources/ThreatsManager.Interfaces/ExtensionsContainerAttribute.cs @@ -13,9 +13,17 @@ public class ExtensionsContainerAttribute : Attribute /// Constructor to describe dependency with a specific version of the Engine. /// /// Version of the Engine. - public ExtensionsContainerAttribute([Required] string version) : this(version, version) + public ExtensionsContainerAttribute([Required] string version) : this(version, version, 0) { + } + /// + /// Constructor to describe dependency with a specific version of the Engine. + /// + /// Version of the Engine. + /// Client Identifier. + public ExtensionsContainerAttribute([Required] string version, uint clientId) : this(version, version, clientId) + { } /// @@ -23,10 +31,21 @@ public ExtensionsContainerAttribute([Required] string version) : this(version, v /// /// Minimum supported versions of the Engine. /// Maximum supported versions of the Engine. - public ExtensionsContainerAttribute([Required] string minVersion, [Required] string maxVersion) + public ExtensionsContainerAttribute([Required] string minVersion, [Required] string maxVersion) : this(minVersion, maxVersion, 0) + { + } + + /// + /// Constructor to describe dependency with a range of versions of the Engine. + /// + /// Minimum supported versions of the Engine. + /// Maximum supported versions of the Engine. + /// Client Identifier. + public ExtensionsContainerAttribute([Required] string minVersion, [Required] string maxVersion, uint clientId) { MinVersion = minVersion; MaxVersion = maxVersion; + ClientId = clientId; } /// @@ -39,6 +58,13 @@ public ExtensionsContainerAttribute([Required] string minVersion, [Required] str /// public string MaxVersion { get; set; } + /// + /// Client Identifier. + /// + /// If the Client Id is not 0, then the Extension Container requires a special client to be executed. + /// This is not a security feature! + public uint ClientId { get; set; } + /// /// Checks if the Extension supports the version of the Engine passed as argument. /// diff --git a/Sources/ThreatsManager.Interfaces/MicrosoftContainerAttribute.cs b/Sources/ThreatsManager.Interfaces/MicrosoftContainerAttribute.cs deleted file mode 100644 index 464fa769..00000000 --- a/Sources/ThreatsManager.Interfaces/MicrosoftContainerAttribute.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; - -namespace ThreatsManager.Interfaces -{ - /// - /// Attribute to be applied to the Assembly to characterize it as a container reserved for Microsoft internal consumption. - /// - [AttributeUsage(AttributeTargets.Assembly)] - public class MicrosoftContainerAttribute : Attribute - { - } -} \ No newline at end of file