Skip to content

Commit

Permalink
Revised ExtensionsContainerAttribute to constrain execution on specif…
Browse files Browse the repository at this point in the history
…ic clients.
  • Loading branch information
simonec73 committed Nov 1, 2020
1 parent e86e0bb commit ac29e68
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 17 deletions.
22 changes: 19 additions & 3 deletions Sources/ThreatsManager.Engine/Manager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
30 changes: 28 additions & 2 deletions Sources/ThreatsManager.Interfaces/ExtensionsContainerAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,39 @@ public class ExtensionsContainerAttribute : Attribute
/// Constructor to describe dependency with a specific version of the Engine.
/// </summary>
/// <param name="version">Version of the Engine.</param>
public ExtensionsContainerAttribute([Required] string version) : this(version, version)
public ExtensionsContainerAttribute([Required] string version) : this(version, version, 0)
{
}

/// <summary>
/// Constructor to describe dependency with a specific version of the Engine.
/// </summary>
/// <param name="version">Version of the Engine.</param>
/// <param name="clientId">Client Identifier.</param>
public ExtensionsContainerAttribute([Required] string version, uint clientId) : this(version, version, clientId)
{
}

/// <summary>
/// Constructor to describe dependency with a range of versions of the Engine.
/// </summary>
/// <param name="minVersion">Minimum supported versions of the Engine.</param>
/// <param name="maxVersion">Maximum supported versions of the Engine.</param>
public ExtensionsContainerAttribute([Required] string minVersion, [Required] string maxVersion)
public ExtensionsContainerAttribute([Required] string minVersion, [Required] string maxVersion) : this(minVersion, maxVersion, 0)
{
}

/// <summary>
/// Constructor to describe dependency with a range of versions of the Engine.
/// </summary>
/// <param name="minVersion">Minimum supported versions of the Engine.</param>
/// <param name="maxVersion">Maximum supported versions of the Engine.</param>
/// <param name="clientId">Client Identifier.</param>
public ExtensionsContainerAttribute([Required] string minVersion, [Required] string maxVersion, uint clientId)
{
MinVersion = minVersion;
MaxVersion = maxVersion;
ClientId = clientId;
}

/// <summary>
Expand All @@ -39,6 +58,13 @@ public ExtensionsContainerAttribute([Required] string minVersion, [Required] str
/// </summary>
public string MaxVersion { get; set; }

/// <summary>
/// Client Identifier.
/// </summary>
/// <remarks>If the Client Id is not 0, then the Extension Container requires a special client to be executed.
/// <para><b>This is not a security feature!</b></para></remarks>
public uint ClientId { get; set; }

/// <summary>
/// Checks if the Extension supports the version of the Engine passed as argument.
/// </summary>
Expand Down
12 changes: 0 additions & 12 deletions Sources/ThreatsManager.Interfaces/MicrosoftContainerAttribute.cs

This file was deleted.

0 comments on commit ac29e68

Please sign in to comment.