Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sign tool explicit files #410

Merged
merged 3 commits into from
Aug 20, 2018
Merged

Sign tool explicit files #410

merged 3 commits into from
Aug 20, 2018

Conversation

JohnTortugo
Copy link
Contributor

@JohnTortugo JohnTortugo commented Aug 1, 2018

Closes: #396

  • SignToolTask will receive a list of files to be signed ExplicitSignItems, a list of files to be ignored ExplicitExcludeItems
  • SignToolTask will receive a mapping of PublicKeyToken + CertificateName + StrongName
  • The SignTool can operate using only these new parameters or with the usual SignToolData.json or both methods; Once these changes are stable and working we'll probably disable support to SignToolData.json
  • Adding support for overriding the signing certificate for specific File+TargetFramework combinations.
  • Removing support for SignToolData.json file
  • Adding unit test cases

@@ -70,14 +87,30 @@ private void ExecuteImpl()
}
}

var mapTokenToSignInfo = new Dictionary<string, SignInfo>();

This comment was marked as spam.

@@ -43,6 +44,22 @@ public class SignToolTask : Task
[Required]
public string MicroBuildCorePath { get; set; }

/// <summary>
/// Explicit list of containers / files to be signed.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

var map = new Dictionary<string, SignInfo>(StringComparer.OrdinalIgnoreCase);
foreach (var item in fileJson.SignList)
var mapFileToSignInfo = new Dictionary<string, SignInfo>(StringComparer.OrdinalIgnoreCase);
List<string> excludeList = new List<string>();

This comment was marked as spam.

{
if (IsManaged(filePath) == true)
{
var fileAsm = System.Reflection.Assembly.LoadFile(filePath);

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

else
{
log.LogError($"SignInfo for Public Key Token {publicKeyToken} not found.");
return new SignInfo(null, null);

This comment was marked as spam.

Copy link
Member

@jaredpar jaredpar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to address the LoadFile issue.

/// <summary>
/// Explicit list of containers / files to NOT be signed.
/// </summary>
public string[] ExplicitExcludeItems { get; set; }

This comment was marked as spam.

@JohnTortugo
Copy link
Contributor Author

PTAL

using Microsoft.DotNet.SignTool.Json;
using Microsoft.Build.Utilities;
using System.Reflection.Metadata;

This comment was marked as spam.


/// <summary>
/// Mapping relating PublicKeyToken, Certificate and Strong Name.
/// During signing Certificate and Strong Name will be looked up here based on PublicKeyToken.

This comment was marked as spam.

/// Mapping relating PublicKeyToken, Certificate and Strong Name.
/// During signing Certificate and Strong Name will be looked up here based on PublicKeyToken.
/// </summary>
public ITaskItem[] StrongNameSignInfo { get; set; }

This comment was marked as spam.


mapTokenToSignInfo.Add(publicKeyToken, signInfo);
}
}

This comment was marked as spam.


mapFileAndTargetFrameworkToCertificate.Add(new Tuple<string, string>(fileName, targetFramework), certificateName);
}
}

This comment was marked as spam.

var targetFramework = item.GetMetadata("TargetFramework").ToLower();
var certificateName = item.GetMetadata("CertificateName").ToLower();

mapFileAndTargetFrameworkToCertificate.Add(new Tuple<string, string>(fileName, targetFramework), certificateName);

This comment was marked as spam.

}
}

var mapFileAndTargetFrameworkToCertificate = new Dictionary<Tuple<string, string>, string>();

This comment was marked as spam.

foreach (var item in FileSignInfo)
{
var fileName = item.ItemSpec;
var targetFramework = item.GetMetadata("TargetFramework").ToLower();

This comment was marked as spam.

{
var fileName = item.ItemSpec;
var targetFramework = item.GetMetadata("TargetFramework").ToLower();
var certificateName = item.GetMetadata("CertificateName").ToLower();

This comment was marked as spam.

internal static BatchSignInput TryReadConfigFile(TaskLoggingHelper log, TextReader configReader, string outputPath)
internal static BatchSignInput ParseConfigInfo(TaskLoggingHelper log, TextReader configReader, string outputPath, string[] explicitSignList,
Dictionary<string, SignInfo> mapTokenToSignInfo,
Dictionary<Tuple<string, string>, string> mapFileAndTargetFrameworkToCertificate)

This comment was marked as spam.

foreach (var item in fileJson.SignList)
var mapFileToSignInfo = new Dictionary<string, SignInfo>(StringComparer.OrdinalIgnoreCase);
var excludeList = new List<string>();
var publishUrl = "unset";

This comment was marked as spam.

@tmat
Copy link
Member

tmat commented Aug 3, 2018

    public string ConfigFilePath { get; set; }

Remove this. The json file is no longer needed.


Refers to: src/Microsoft.DotNet.SignTool/src/SignToolTask.cs:27 in fea3a1b. [](commit_id = fea3a1b, deletion_comment = False)

var excludeList = new List<string>();
var publishUrl = "unset";

if (configReader != null)

This comment was marked as spam.

{
foreach (var item in FileSignInfo)
{
var fileName = item.ItemSpec;

This comment was marked as spam.

{
log.LogError($"Duplicate file entry: {relativeFileName}");
log.LogError($"Duplicate file entry: {filePath}");
}
else

This comment was marked as spam.

/// </summary>
internal ImmutableArray<FileName> AssemblyNames { get; }
private readonly Dictionary<(string, string, string), string> _fileAndTokenToOverridingInfos;

This comment was marked as spam.

This comment was marked as spam.


/// Do we need to override the default certificate this file ?
if (_fileAndTokenToOverridingInfos.TryGetValue(keyForAllTargets, out overridingCertificate) ||
_fileAndTokenToOverridingInfos.TryGetValue(keyForSpecificTarget, out overridingCertificate))

This comment was marked as spam.

_fileAndTokenToOverridingInfos.TryGetValue(keyForSpecificTarget, out overridingCertificate))
{
/// If has overriding info, is it for ignoring the file?
if (overridingCertificate != null && overridingCertificate.Equals(SignToolConstants.IgnoreFileCertificateSentinel))

This comment was marked as spam.

This comment was marked as spam.

/// </summary>
internal ImmutableArray<FileName> ZipContainerNames { get; }
private readonly Dictionary<string, SignInfo> _mapTokenToSignInfo;

This comment was marked as spam.

namespace Microsoft.DotNet.SignTool
{
internal struct SignInfo
internal class SignInfo

This comment was marked as spam.

This comment was marked as spam.

return signInfo;
}
else
{

This comment was marked as spam.


if (!string.IsNullOrEmpty(matchingFile))
if (IsManaged(fileFullPath) == true)

This comment was marked as spam.

var util = new BatchSignUtil(task.BuildEngine, task.Log, signTool, signingInput, null);

/// There is a validation inside this method that checks that the files where actually signed
/// so it's not duplicated here.

This comment was marked as spam.

{
foreach (var item in ((FakeBuildEngine)task.BuildEngine).LogErrorEvents)
{
Console.WriteLine(item.Message);

This comment was marked as spam.

candidate.SignInfo.Certificate == expected.SignInfo.Certificate &&
candidate.SignInfo.StrongName == expected.SignInfo.StrongName))
{
task.Log.LogError($"Expected this file ({expected.FullPath}) to be signed with this " +

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

}
}

if (expectedToBeSigned.Count != signingInput.FilesToSign.Count)

This comment was marked as spam.

- Added Assert for checking the .proj that is generated as side-effect of the signing.
- Renamed some variables and some general refactoring.
- Added new test case where a overriding certificate is informed.
@JohnTortugo
Copy link
Contributor Author

Hey, I'd like to merge this PR today, can you PTAL and advise if there are any blocking issues? I'm willing to work on other changes but I'd like to merge this one so I can start working on some other things.

I've just tested the tool by patching Sign.proj as suggested by @tmat #464 and it is able to find all files that we have listed to be signed in our current SignToolData.json file.

/// </summary>
internal ImmutableArray<string> ExternalFileNames { get; }
internal Dictionary<FileName, ZipData> ZipDataMap { get; set; }

This comment was marked as spam.

internal ImmutableDictionary<FileName, FileSignInfo> FileSignInfoMap { get; }

private ContentUtil contentUtil = new ContentUtil();
public List<FileName> FilesToSign = new List<FileName>();

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

@jaredpar
Copy link
Member

    internal string GetChecksum(string filePath)

This is an instance method reading from a static cache (_filePathCache). This cache should be made instance as well.


Refers to: src/Microsoft.DotNet.SignTool/src/ContentUtil.cs:26 in e1693b8. [](commit_id = e1693b8, deletion_comment = False)

namespace Microsoft.DotNet.SignTool
{
struct ExplicitCertificateKey
{

This comment was marked as spam.

{
public string FileName;
public string PublicKeyToken;
public string TargetFramework;

This comment was marked as spam.


namespace Microsoft.DotNet.SignTool
{
internal struct FileName : IEquatable<FileName>
internal class FileName : IEquatable<FileName>

This comment was marked as spam.

- Adding back Configuration file/class
- Making BatchSignInput a wrapper around Immutable properties
- Fixes around coding convention
@JohnTortugo
Copy link
Contributor Author

Hey, I've addressed all your comments already. I'm planning to merge this today after lunch, unless there is a blocking concern/comment. All non-blocking concerns I'll address in a future PR. @jaredpar @tmat

@jaredpar jaredpar dismissed their stale review August 20, 2018 20:12

Looks like most of my feedback was addressed

@JohnTortugo JohnTortugo merged commit 569feb9 into dotnet:master Aug 20, 2018
@JohnTortugo JohnTortugo deleted the SignToolExplicitFiles branch August 20, 2018 20:57
{
Log.LogError($"File '{MSBuildPath}' not found.");
Log.LogError($"MSBuild was not found at this path: '{MSBuildPath}'.");

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

foreach (var item in FileSignInfo)
{
var fileName = item.ItemSpec;
var targetFramework = item.GetMetadata("TargetFramework");

This comment was marked as spam.

This comment was marked as spam.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants