Skip to content

Commit b79a60a

Browse files
Vzor-ebourg
authored andcommitted
Added multiple files support to the Ant task
1 parent 5db73aa commit b79a60a

File tree

5 files changed

+64
-3
lines changed

5 files changed

+64
-3
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ See https://ebourg.github.io/jsign for more information.
4242

4343
#### Version 4.1 (in development)
4444

45+
* The Ant task can now sign multiple files by defining a fileset (contributed by Kyle Berezin)
4546
* Fixed the _"Map failed"_ OutOfMemoryError when signing large MSI files
4647

4748
#### Version 4.0 (2021-08-09)

TODO.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ TODO
55
- Support private keys exported with PKCS#8
66
- Detect the type of the keystore automatically (guess from the extension and try all the other types as a fallback)
77
- Support unauthenticated blobs
8-
- Sign multiple files (fileset)
98
- Support generating MsiDigitalSignatureEx entries when signing MSI files (requires access to the streams metadata in POI)
109
- load password from the environment (CLI syntax: env:VARIABLE_NAME)
1110
- AWS KMS integration

jsign-ant/src/main/java/net/jsign/JsignTask.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import org.apache.tools.ant.BuildException;
2222
import org.apache.tools.ant.Task;
23+
import org.apache.tools.ant.types.FileSet;
2324

2425
/**
2526
* Ant task for signing files with Authenticode.
@@ -32,6 +33,9 @@ public class JsignTask extends Task {
3233
/** The file to be signed. */
3334
private File file;
3435

36+
/** The set of files to be signed. */
37+
private FileSet fileset;
38+
3539
/** The program name embedded in the signature. */
3640
private String name;
3741

@@ -87,6 +91,10 @@ public void setFile(File file) {
8791
this.file = file;
8892
}
8993

94+
public void addFileset(FileSet fileset) {
95+
this.fileset = fileset;
96+
}
97+
9098
public void setName(String name) {
9199
this.name = name;
92100
}
@@ -177,8 +185,14 @@ public void execute() throws BuildException {
177185
helper.replace(replace);
178186
helper.encoding(encoding);
179187
helper.detached(detached);
180-
181-
helper.sign(file);
188+
189+
if (fileset != null) {
190+
for(String fileElement : fileset.getDirectoryScanner().getIncludedFiles()) {
191+
helper.sign(new File(fileset.getDir(), fileElement));
192+
}
193+
} else {
194+
helper.sign(file);
195+
}
182196
} catch (Exception e) {
183197
throw new BuildException(e.getMessage(), e, getLocation());
184198
}

jsign-ant/src/test/java/net/jsign/JsignTaskTest.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,37 @@ public void testSigning() throws Exception {
187187
}
188188
}
189189

190+
@Test
191+
public void testSigningMultipleFiles() throws Exception {
192+
FileUtils.copyFile(sourceFile, targetFile);
193+
194+
project.executeTarget("signing-multiple-files");
195+
196+
File targetFile2 = new File("target/test-classes/wineyes-multiple-files-test.exe");
197+
198+
assertTrue("The file " + targetFile + " wasn't changed", SOURCE_FILE_CRC32 != FileUtils.checksumCRC32(targetFile));
199+
assertTrue("The file " + targetFile2 + " wasn't changed", SOURCE_FILE_CRC32 != FileUtils.checksumCRC32(targetFile2));
200+
201+
try (PEFile peFile = new PEFile(targetFile)) {
202+
List<CMSSignedData> signatures = peFile.getSignatures();
203+
assertNotNull(signatures);
204+
assertEquals(1, signatures.size());
205+
206+
CMSSignedData signature = signatures.get(0);
207+
208+
assertNotNull(signature);
209+
}
210+
try (PEFile peFile = new PEFile(targetFile2)) {
211+
List<CMSSignedData> signatures = peFile.getSignatures();
212+
assertNotNull(signatures);
213+
assertEquals(1, signatures.size());
214+
215+
CMSSignedData signature = signatures.get(0);
216+
217+
assertNotNull(signature);
218+
}
219+
}
220+
190221
@Test
191222
public void testSigningPowerShell() throws Exception {
192223
File sourceFile = new File("target/test-classes/hello-world.ps1");

jsign-ant/src/test/resources/testbuild.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,22 @@
8888
keypass="${keypass}"/>
8989
</target>
9090

91+
<target name="signing-multiple-files">
92+
<copy file="wineyes.exe" tofile="wineyes-multiple-files-test.exe" overwrite="true"/>
93+
<jsign name="WinEyes"
94+
url="http://www.steelblue.com/WinEyes"
95+
alg="SHA-1"
96+
keystore="${keystore}"
97+
alias="${alias}"
98+
keypass="${keypass}"
99+
tsmode="authenticode">
100+
<fileset dir="./">
101+
<include name="wineyes-multiple-files-test.exe"/>
102+
<include name="wineyes-signed-with-ant.exe"/>
103+
</fileset>
104+
</jsign>
105+
</target>
106+
91107
<target name="signing-powershell">
92108
<jsign file="hello-world-signed-with-ant.ps1"
93109
alg="SHA-1"

0 commit comments

Comments
 (0)