Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 52 additions & 3 deletions src/Sign.Core/DataFormatSigners/ClickOnceSigner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Globalization;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using System.Xml;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.FileSystemGlobbing.Abstractions;
using Microsoft.Extensions.Logging;
Expand Down Expand Up @@ -126,8 +127,8 @@ await Parallel.ForEachAsync(files, _parallelOptions, async (file, state) =>

// Inner files are now signed
// now look for the manifest file and sign that if we have one

FileInfo? manifestFile = filteredFiles.SingleOrDefault(f => ".manifest".Equals(f.Extension, StringComparison.OrdinalIgnoreCase));
var appManifestFromDeploymentManifest = GetApplicationManifestForDeploymentManifest(file);
FileInfo? manifestFile = filteredFiles.SingleOrDefault(f => f.Name.Equals(appManifestFromDeploymentManifest, StringComparison.OrdinalIgnoreCase));
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is avoidable if appManifestFromDeploymentManifest is null.

Also, can we rename manifestFile to applicationManifestFile since now we're dealing with potentially many different kinds of manifest files. We had deployment and application manifests, but now we're dealing with other manifests (like assembly manifests).


string fileArgs = $@"-update ""{manifestFile}"" {args}";

Expand Down Expand Up @@ -273,5 +274,53 @@ public void CopySigningDependencies(FileInfo deploymentManifestFile, DirectoryIn
}
}
}

/// <summary>
/// Try and find the application manifest (.manifest) file from a clickonce application manifest (.application / .vsto
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't it be:

Suggested change
/// Try and find the application manifest (.manifest) file from a clickonce application manifest (.application / .vsto
/// Try and find the application manifest (.manifest) file from a clickonce deployment manifest (.application / .vsto

/// There might not be one, if the user is attempting to only re-sign the deployment manifest without touching other files.
/// This is necessary because there might be multiple *.manifest files present, e.g. if a DLL that's part of the clickonce
/// package ships its own assembly manifest which isn't a clickonce application manifest.
/// </summary>
/// <param name="deploymentManifest"></param>
/// <returns>A string containing the file name of the Application manifest, or null if it couldn't be found.</returns>
/// <exception cref="InvalidDataException"></exception>
private string? GetApplicationManifestForDeploymentManifest(FileInfo deploymentManifest)
{
var xml = new XmlDocument();
xml.Load(deploymentManifest.FullName);
// there should only be a single result here, if the file is a valid clickonce manifest.
var dependentAssemblies = xml.GetElementsByTagName("dependentAssembly");
Copy link
Collaborator

Choose a reason for hiding this comment

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

We prefer using the explicit type if the implied type is not super obvious. It will facilitate understanding both in a browser and IDE.

if (dependentAssemblies.Count != 1)
{
Logger.LogDebug(Resources.ApplicationManifestNotFound);
return null;
}

var node = dependentAssemblies.Item(0);
if (node is null || node.Attributes is null)
{
Logger.LogDebug(Resources.ApplicationManifestNotFound);
return null;
}

var applicationManifestFileNameAttribute = node.Attributes["codebase"];
if (applicationManifestFileNameAttribute is null || string.IsNullOrEmpty(applicationManifestFileNameAttribute.Value))
{
Logger.LogDebug(Resources.ApplicationManifestNotFound);
return null;
}

// the codebase attribute can be a relative file path (e.g. Application Files\MyApp_1_0_0_0\MyApp.dll.manifest) or
// a URI (e.g. https://my.cdn.com/clickonce/MyApp/ApplicationFiles/MyApp_1_0_0_0/MyApp.dll.manifest) so we need to
// handle both cases and extract just the file name part.
//
// we only try and parse absolute uris, because a relative uri can just be treated like a file path for our purposes
if (Uri.TryCreate(applicationManifestFileNameAttribute.Value, UriKind.Absolute, out var uri))
{
Path.GetFileName(uri.LocalPath); // works for http(s) and file:// uris
Copy link
Collaborator

Choose a reason for hiding this comment

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

There is a bug here. I think you meant:

Suggested change
Path.GetFileName(uri.LocalPath); // works for http(s) and file:// uris
return Path.GetFileName(uri.LocalPath); // works for http(s) and file:// uris

Seems worth adding a unit test for this case. I think you can convert your new, existing unit test into a theory and parameterize codebase with both scenarios.

}

return Path.GetFileName(applicationManifestFileNameAttribute.Value);
}
}
}
}
9 changes: 9 additions & 0 deletions src/Sign.Core/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/Sign.Core/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -275,4 +275,7 @@
<data name="VSIXSignToolUnsupportedAlgorithm" xml:space="preserve">
<value>The algorithm selected is not supported.</value>
</data>
<data name="ApplicationManifestNotFound" xml:space="preserve">
<value>Did not find exactly 1 &lt;dependentAssembly&gt; element with a non-empty 'codebase' attribute within the deployment manifest.</value>
</data>
</root>
5 changes: 5 additions & 0 deletions src/Sign.Core/xlf/Resources.cs.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="cs" original="../Resources.resx">
<body>
<trans-unit id="ApplicationManifestNotFound">
<source>Did not find exactly 1 &lt;dependentAssembly&gt; element with a non-empty 'codebase' attribute within the deployment manifest.</source>
<target state="new">Did not find exactly 1 &lt;dependentAssembly&gt; element with a non-empty 'codebase' attribute within the deployment manifest.</target>
<note />
</trans-unit>
<trans-unit id="AzureSignToolSignatureProviderSigning">
<source>Signing SignTool job with {count} files.</source>
<target state="translated">Podepisování úlohy SignTool s tímto počtem souborů: {count}.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Sign.Core/xlf/Resources.de.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="de" original="../Resources.resx">
<body>
<trans-unit id="ApplicationManifestNotFound">
<source>Did not find exactly 1 &lt;dependentAssembly&gt; element with a non-empty 'codebase' attribute within the deployment manifest.</source>
<target state="new">Did not find exactly 1 &lt;dependentAssembly&gt; element with a non-empty 'codebase' attribute within the deployment manifest.</target>
<note />
</trans-unit>
<trans-unit id="AzureSignToolSignatureProviderSigning">
<source>Signing SignTool job with {count} files.</source>
<target state="translated">Der SignTool-Auftrag wird mit {count} Dateien signiert.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Sign.Core/xlf/Resources.es.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="es" original="../Resources.resx">
<body>
<trans-unit id="ApplicationManifestNotFound">
<source>Did not find exactly 1 &lt;dependentAssembly&gt; element with a non-empty 'codebase' attribute within the deployment manifest.</source>
<target state="new">Did not find exactly 1 &lt;dependentAssembly&gt; element with a non-empty 'codebase' attribute within the deployment manifest.</target>
<note />
</trans-unit>
<trans-unit id="AzureSignToolSignatureProviderSigning">
<source>Signing SignTool job with {count} files.</source>
<target state="translated">Firmando el trabajo de SignTool con {count} archivos.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Sign.Core/xlf/Resources.fr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="fr" original="../Resources.resx">
<body>
<trans-unit id="ApplicationManifestNotFound">
<source>Did not find exactly 1 &lt;dependentAssembly&gt; element with a non-empty 'codebase' attribute within the deployment manifest.</source>
<target state="new">Did not find exactly 1 &lt;dependentAssembly&gt; element with a non-empty 'codebase' attribute within the deployment manifest.</target>
<note />
</trans-unit>
<trans-unit id="AzureSignToolSignatureProviderSigning">
<source>Signing SignTool job with {count} files.</source>
<target state="translated">Signature du travail SignTool avec {count} fichiers.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Sign.Core/xlf/Resources.it.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="it" original="../Resources.resx">
<body>
<trans-unit id="ApplicationManifestNotFound">
<source>Did not find exactly 1 &lt;dependentAssembly&gt; element with a non-empty 'codebase' attribute within the deployment manifest.</source>
<target state="new">Did not find exactly 1 &lt;dependentAssembly&gt; element with a non-empty 'codebase' attribute within the deployment manifest.</target>
<note />
</trans-unit>
<trans-unit id="AzureSignToolSignatureProviderSigning">
<source>Signing SignTool job with {count} files.</source>
<target state="translated">Firma del processo SignTool con {count} file.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Sign.Core/xlf/Resources.ja.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="ja" original="../Resources.resx">
<body>
<trans-unit id="ApplicationManifestNotFound">
<source>Did not find exactly 1 &lt;dependentAssembly&gt; element with a non-empty 'codebase' attribute within the deployment manifest.</source>
<target state="new">Did not find exactly 1 &lt;dependentAssembly&gt; element with a non-empty 'codebase' attribute within the deployment manifest.</target>
<note />
</trans-unit>
<trans-unit id="AzureSignToolSignatureProviderSigning">
<source>Signing SignTool job with {count} files.</source>
<target state="translated">{count} 個のファイルを使用して SignTool ジョブに署名しています。</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Sign.Core/xlf/Resources.ko.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="ko" original="../Resources.resx">
<body>
<trans-unit id="ApplicationManifestNotFound">
<source>Did not find exactly 1 &lt;dependentAssembly&gt; element with a non-empty 'codebase' attribute within the deployment manifest.</source>
<target state="new">Did not find exactly 1 &lt;dependentAssembly&gt; element with a non-empty 'codebase' attribute within the deployment manifest.</target>
<note />
</trans-unit>
<trans-unit id="AzureSignToolSignatureProviderSigning">
<source>Signing SignTool job with {count} files.</source>
<target state="translated">{count} 파일로 SignTool 작업에 서명하는 중입니다.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Sign.Core/xlf/Resources.pl.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="pl" original="../Resources.resx">
<body>
<trans-unit id="ApplicationManifestNotFound">
<source>Did not find exactly 1 &lt;dependentAssembly&gt; element with a non-empty 'codebase' attribute within the deployment manifest.</source>
<target state="new">Did not find exactly 1 &lt;dependentAssembly&gt; element with a non-empty 'codebase' attribute within the deployment manifest.</target>
<note />
</trans-unit>
<trans-unit id="AzureSignToolSignatureProviderSigning">
<source>Signing SignTool job with {count} files.</source>
<target state="translated">Podpisywanie zadania SignTool przy użyciu {count} plików.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Sign.Core/xlf/Resources.pt-BR.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="pt-BR" original="../Resources.resx">
<body>
<trans-unit id="ApplicationManifestNotFound">
<source>Did not find exactly 1 &lt;dependentAssembly&gt; element with a non-empty 'codebase' attribute within the deployment manifest.</source>
<target state="new">Did not find exactly 1 &lt;dependentAssembly&gt; element with a non-empty 'codebase' attribute within the deployment manifest.</target>
<note />
</trans-unit>
<trans-unit id="AzureSignToolSignatureProviderSigning">
<source>Signing SignTool job with {count} files.</source>
<target state="translated">Autenticando o trabalho SignTool com {count} arquivos.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Sign.Core/xlf/Resources.ru.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="ru" original="../Resources.resx">
<body>
<trans-unit id="ApplicationManifestNotFound">
<source>Did not find exactly 1 &lt;dependentAssembly&gt; element with a non-empty 'codebase' attribute within the deployment manifest.</source>
<target state="new">Did not find exactly 1 &lt;dependentAssembly&gt; element with a non-empty 'codebase' attribute within the deployment manifest.</target>
<note />
</trans-unit>
<trans-unit id="AzureSignToolSignatureProviderSigning">
<source>Signing SignTool job with {count} files.</source>
<target state="translated">Задание подписывания SignTool с несколькими файлами ({count}).</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Sign.Core/xlf/Resources.tr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="tr" original="../Resources.resx">
<body>
<trans-unit id="ApplicationManifestNotFound">
<source>Did not find exactly 1 &lt;dependentAssembly&gt; element with a non-empty 'codebase' attribute within the deployment manifest.</source>
<target state="new">Did not find exactly 1 &lt;dependentAssembly&gt; element with a non-empty 'codebase' attribute within the deployment manifest.</target>
<note />
</trans-unit>
<trans-unit id="AzureSignToolSignatureProviderSigning">
<source>Signing SignTool job with {count} files.</source>
<target state="translated">SignTool işi {count} dosya ile imzalanıyor.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Sign.Core/xlf/Resources.zh-Hans.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="zh-Hans" original="../Resources.resx">
<body>
<trans-unit id="ApplicationManifestNotFound">
<source>Did not find exactly 1 &lt;dependentAssembly&gt; element with a non-empty 'codebase' attribute within the deployment manifest.</source>
<target state="new">Did not find exactly 1 &lt;dependentAssembly&gt; element with a non-empty 'codebase' attribute within the deployment manifest.</target>
<note />
</trans-unit>
<trans-unit id="AzureSignToolSignatureProviderSigning">
<source>Signing SignTool job with {count} files.</source>
<target state="translated">正在对包含 {count} 个文件的 SignTool 作业进行签名。</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Sign.Core/xlf/Resources.zh-Hant.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="zh-Hant" original="../Resources.resx">
<body>
<trans-unit id="ApplicationManifestNotFound">
<source>Did not find exactly 1 &lt;dependentAssembly&gt; element with a non-empty 'codebase' attribute within the deployment manifest.</source>
<target state="new">Did not find exactly 1 &lt;dependentAssembly&gt; element with a non-empty 'codebase' attribute within the deployment manifest.</target>
<note />
</trans-unit>
<trans-unit id="AzureSignToolSignatureProviderSigning">
<source>Signing SignTool job with {count} files.</source>
<target state="translated">正在簽署具有 {count} 個檔案的 SignTool 工作。</target>
Expand Down
Loading