public Configuration( string tempDir, ITaskItem[] itemsToSign, Dictionary <string, List <SignInfo> > strongNameInfo, Dictionary <ExplicitCertificateKey, string> fileSignInfo, Dictionary <string, List <SignInfo> > extensionSignInfo, ITaskItem[] dualCertificates, TaskLoggingHelper log, bool useHashInExtractionPath = false) { Debug.Assert(tempDir != null); Debug.Assert(itemsToSign != null && !itemsToSign.Any(i => i == null)); Debug.Assert(strongNameInfo != null); Debug.Assert(fileSignInfo != null); _pathToContainerUnpackingDirectory = Path.Combine(tempDir, "ContainerSigning"); _useHashInExtractionPath = useHashInExtractionPath; _log = log; _strongNameInfo = strongNameInfo; _fileSignInfo = fileSignInfo; _fileExtensionSignInfo = extensionSignInfo; _filesToSign = new List <FileSignInfo>(); _wixPacks = new List <WixPackInfo>(); _filesToCopy = new List <KeyValuePair <string, string> >(); _zipDataMap = new Dictionary <SignedFileContentKey, ZipData>(); _filesByContentKey = new Dictionary <SignedFileContentKey, FileSignInfo>(); _itemsToSign = itemsToSign; _dualCertificates = dualCertificates == null ? new ITaskItem[0] : dualCertificates; _whichPackagesTheFileIsIn = new Dictionary <SignedFileContentKey, HashSet <string> >(); _errors = new Dictionary <SigningToolErrorCode, HashSet <SignedFileContentKey> >(); _wixPacks = _itemsToSign.Where(w => WixPackInfo.IsWixPack(w.ItemSpec))?.Select(s => new WixPackInfo(s.ItemSpec)).ToList(); _hashToCollisionIdMap = new Dictionary <SignedFileContentKey, string>(); }
private FileSignInfo TrackFile(PathWithHash file, PathWithHash parentContainer, string collisionPriorityId) { bool isNested = parentContainer != null; _log.LogMessage($"Tracking file '{file.FullPath}' isNested={isNested}"); // If there's a wixpack in ItemsToSign which corresponds to this file, pass along the path of // the wixpack so we can associate the wixpack with the item var wixPack = _wixPacks.SingleOrDefault(w => w.Moniker.Equals(file.FileName, StringComparison.OrdinalIgnoreCase)); var fileSignInfo = ExtractSignInfo(file, parentContainer, collisionPriorityId, wixPack.FullPath); if (_filesByContentKey.TryGetValue(fileSignInfo.FileContentKey, out var existingSignInfo)) { // If we saw this file already we wouldn't call TrackFile unless this is a top-level file. Debug.Assert(!isNested); // Copy the signed content to the destination path. _filesToCopy.Add(new KeyValuePair <string, string>(existingSignInfo.FullPath, file.FullPath)); return(fileSignInfo); } if (fileSignInfo.IsContainer()) { if (fileSignInfo.IsZipContainer()) { if (TryBuildZipData(fileSignInfo, out var zipData)) { _zipDataMap[fileSignInfo.FileContentKey] = zipData; } } else if (fileSignInfo.IsWixContainer()) { _log.LogMessage($"Trying to gather data for wix container {fileSignInfo.FullPath}"); if (TryBuildWixData(fileSignInfo, out var msiData)) { _zipDataMap[fileSignInfo.FileContentKey] = msiData; } } } _log.LogMessage(MessageImportance.Low, $"Caching file {fileSignInfo.FileContentKey.FileName} {fileSignInfo.FileContentKey.StringHash}"); _filesByContentKey.Add(fileSignInfo.FileContentKey, fileSignInfo); bool hasSignableParts = false; if (fileSignInfo.IsContainer()) { // Only sign containers if the file itself is unsigned, or // an item in the container is unsigned. hasSignableParts = _zipDataMap[fileSignInfo.FileContentKey].NestedParts.Values.Any(b => b.FileSignInfo.SignInfo.ShouldSign || b.FileSignInfo.HasSignableParts); if (hasSignableParts) { // If the file has contents that need to be signed, then re-evaluate the signing info fileSignInfo = fileSignInfo.WithSignableParts(); _filesByContentKey[fileSignInfo.FileContentKey] = fileSignInfo; } } if (fileSignInfo.ShouldTrack) { // We never sign wixpacks if (!WixPackInfo.IsWixPack(fileSignInfo.FileName)) { _filesToSign.Add(fileSignInfo); } } return(fileSignInfo); }