Skip to content

Commit

Permalink
Regression Bug fix: RunPowerShellScript activity fails to parse Power…
Browse files Browse the repository at this point in the history
…Shell user password as the ParseIfExpression check leads to an exception if the password is not a WAL expression.
  • Loading branch information
Nilesh Ghodekar committed Jul 23, 2020
1 parent addd2ef commit 32b72c1
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 14 deletions.
13 changes: 7 additions & 6 deletions src/Scripts/EncryptData.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,20 @@
NOTE: Edit the Version and PublicKeyToken of the WAL AssemblyName to match the one that you have deployed in GAC.
Also edit the $encryptionCertThumbprint of cert to be used for certificate based encryption.
Finding Assembly verion and PublicKeyToken
gacutil.exe -l | findstr WorkflowActivityLibrary
Creatinig a self signed certificate for MIMWAL (You can use a legacy CSP such as Microsoft Strong Cryptographic Provider as shown in the example below)
To find Assembly verion and PublicKeyToken
.\gacutil.exe -l | findstr WorkflowActivityLibrary
To create a self-signed certificate for MIMWAL, you must use a legacy CSP (as .NET 3.5 only supports legacy CSPs).
You can use a legacy CSP such as Microsoft Strong Cryptographic Provider as shown in the example below:
$cert = New-SelfSignedCertificate -DnsName "MIMWAL Encryption (Do Not Delete)" -CertStoreLocation "cert:\LocalMachine\My" -Provider "Microsoft Strong Cryptographic Provider" -NotAfter (Get-Date).AddYears(20)
$cert.Thumbprint
As of version v2.18.1110.0, only FIMService account needs read access to the private key of the MIMWAL certificate created above.
#>

$Error.Clear()

$walAssemblyVersion = "2.20.0523.0"
$walAssemblyPublicKeyToken = "31bf3856ad364e35"
$encryptionCertThumbprint = "9C697919FB2FB2D6324ADE42D5F8CB49E8778C08" # cert to be used for encryption (from the cert:\localmachine\my\ store).
$walAssemblyVersion = "2.20.0723.0" # edit appropriately
$walAssemblyPublicKeyToken = "31bf3856ad364e35" # edit appropriately
$encryptionCertThumbprint = "9C697919FB2FB2D6324ADE42D5F8CB49E8778C08" # cert to be used for encryption (from the cert:\localmachine\my\ store). Edit appropriately

Add-Type -AssemblyName "System.Security"
# use the full name for WAL assembly to eliminate need to assembly redirects for dependent assemblies.
Expand Down
4 changes: 2 additions & 2 deletions src/VersionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ internal static class VersionInfo
/// Build Number (MMDD)
/// Revision (if any on the same day)
/// </summary>
internal const string Version = "2.20.0523.0";
internal const string Version = "2.20.0723.0";

/// <summary>
/// File Version information for the assembly consists of the following four values:
Expand All @@ -31,6 +31,6 @@ internal static class VersionInfo
/// Build Number (MMDD)
/// Revision (if any on the same day)
/// </summary>
internal const string FileVersion = "2.20.0523.0";
internal const string FileVersion = "2.20.0723.0";
}
}
44 changes: 40 additions & 4 deletions src/WorkflowActivityLibrary/Common/ExpressionEvaluator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,18 @@ public static ParameterType DetermineParameterType(string parameter, bool suppre
// Function: contains ( and ends with )
// Lookup: starts with [// and ends with ]
// Variable: starts with $ and does not contain invalid characters
if (IdentifyExpressionComponents(parameter).Count > 1)
ArrayList components = IdentifyExpressionComponents(parameter, suppressValidationError);
if (components.Count > 1)
{
parameterType = ParameterType.Expression;
foreach (string component in components)
{
if (DetermineParameterType(component, suppressValidationError) == ParameterType.Unknown)
{
parameterType = ParameterType.Unknown;
break;
}
}
}
else if (long.TryParse(parameter, out parseInteger))
{
Expand Down Expand Up @@ -449,8 +458,9 @@ public void PublishVariable(string variable, object value, UpdateMode mode)
/// Identifies the expression components.
/// </summary>
/// <param name="expression">The expression.</param>
/// <param name="suppressValidationError">Indicates whether to suppress the validation error or not.</param>
/// <returns>The ArrayList of expression components.</returns>
private static ArrayList IdentifyExpressionComponents(string expression)
private static ArrayList IdentifyExpressionComponents(string expression, bool suppressValidationError)
{
Logger.Instance.WriteMethodEntry(EventIdentifier.ExpressionEvaluatorIdentifyExpressionComponents, "Expression: '{0}'.", expression);

Expand Down Expand Up @@ -484,12 +494,28 @@ private static ArrayList IdentifyExpressionComponents(string expression)
// parentheses characters do not match, throw an exception
if (openString)
{
throw Logger.Instance.ReportError(EventIdentifier.ExpressionEvaluatorIdentifyExpressionComponentsQuotesValidationError, new InvalidExpressionException(Messages.ExpressionEvaluator_ExpressionQuotesValidationError, expression));
if (suppressValidationError)
{
Logger.Instance.WriteVerbose(EventIdentifier.ExpressionEvaluatorIdentifyExpressionComponentsQuotesValidationError, Messages.ExpressionEvaluator_ExpressionQuotesValidationError, expression);
return components;
}
else
{
throw Logger.Instance.ReportError(EventIdentifier.ExpressionEvaluatorIdentifyExpressionComponentsQuotesValidationError, new InvalidExpressionException(Messages.ExpressionEvaluator_ExpressionQuotesValidationError, expression));
}
}

if (openFunctions != 0)
{
throw Logger.Instance.ReportError(EventIdentifier.ExpressionEvaluatorIdentifyExpressionComponentsParenthesisValidationError, new InvalidExpressionException(Messages.ExpressionEvaluator_ExpressionParenthesisValidationError, expression));
if (suppressValidationError)
{
Logger.Instance.WriteVerbose(EventIdentifier.ExpressionEvaluatorIdentifyExpressionComponentsParenthesisValidationError, Messages.ExpressionEvaluator_ExpressionParenthesisValidationError, expression);
return components;
}
else
{
throw Logger.Instance.ReportError(EventIdentifier.ExpressionEvaluatorIdentifyExpressionComponentsParenthesisValidationError, new InvalidExpressionException(Messages.ExpressionEvaluator_ExpressionParenthesisValidationError, expression));
}
}

// The function expression could contain + characters which are wrapped in quotations
Expand Down Expand Up @@ -546,6 +572,16 @@ private static ArrayList IdentifyExpressionComponents(string expression)
}
}

/// <summary>
/// Identifies the expression components.
/// </summary>
/// <param name="expression">The expression.</param>
/// <returns>The ArrayList of expression components.</returns>
private static ArrayList IdentifyExpressionComponents(string expression)
{
return IdentifyExpressionComponents(expression, false);
}

/// <summary>
/// Escapes the string.
/// A string is escaped by removing the quotation marks at its start and finish and
Expand Down
3 changes: 1 addition & 2 deletions src/WorkflowActivityLibrary/Common/ExpressionFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2500,7 +2500,7 @@ private object DateTimeToFileTimeUtc()
}

/// <summary>
/// This function is used to convert a date to the local time or specifed time zone.
/// This function is used to convert a date to the local time or specified time zone.
/// Function Syntax: DateTimeUtcToLocalTime(date:DateTime [, TimeZoneId])
/// </summary>
/// <returns>The value of the specified UTC date expressed in the local time or specified time zone.</returns>
Expand Down Expand Up @@ -2848,7 +2848,6 @@ private int IndexByValue()
index += 1;
}
}

}

Logger.Instance.WriteVerbose(EventIdentifier.ExpressionFunctionIndexByValue, "IndexByValue('{0}', '{1}') returned '{2}'.", this.parameters[0], this.parameters[1], result);
Expand Down

0 comments on commit 32b72c1

Please sign in to comment.