28
28
import java .util .concurrent .atomic .AtomicBoolean ;
29
29
30
30
import io .netty .handler .codec .http .HttpRequest ;
31
+ import net .jsign .ks .YubiKeyKeyStore ;
31
32
import org .apache .commons .cli .ParseException ;
32
33
import org .apache .commons .io .ByteOrderMark ;
33
34
import org .apache .commons .io .FileUtils ;
@@ -54,7 +55,7 @@ public class JsignCLITest {
54
55
private JsignCLI cli ;
55
56
private File sourceFile = new File ("target/test-classes/wineyes.exe" );
56
57
private File targetFile = new File ("target/test-classes/wineyes-signed-with-cli.exe" );
57
-
58
+
58
59
private String keystore = "keystore.jks" ;
59
60
private String alias = "test" ;
60
61
private String keypass = "password" ;
@@ -64,12 +65,12 @@ public class JsignCLITest {
64
65
@ Before
65
66
public void setUp () throws Exception {
66
67
cli = new JsignCLI ();
67
-
68
+
68
69
// remove the files signed previously
69
70
if (targetFile .exists ()) {
70
71
assertTrue ("Unable to remove the previously signed file" , targetFile .delete ());
71
72
}
72
-
73
+
73
74
assertEquals ("Source file CRC32" , SOURCE_FILE_CRC32 , FileUtils .checksumCRC32 (sourceFile ));
74
75
Thread .sleep (100 );
75
76
FileUtils .copyFile (sourceFile , targetFile );
@@ -218,7 +219,7 @@ public void testSigningMultipleFiles() throws Exception {
218
219
public void testSigningMultipleFilesWithListFile () throws Exception {
219
220
File listFile = new File ("target/test-classes/files.txt" );
220
221
Files .write (listFile .toPath (), Arrays .asList ("# first file" , '"' + targetFile .getPath () + '"' , " " , "# second file" , targetFile .getAbsolutePath ()));
221
-
222
+
222
223
cli .execute ("--name=WinEyes" , "--url=http://www.steelblue.com/WinEyes" , "--alg=SHA-1" , "--keystore=target/test-classes/keystores/" + keystore , "--keypass=" + keypass , "@" + listFile );
223
224
224
225
assertTrue ("The file " + targetFile + " wasn't changed" , SOURCE_FILE_CRC32 != FileUtils .checksumCRC32 (targetFile ));
@@ -270,7 +271,7 @@ public void testSigningPowerShell() throws Exception {
270
271
File sourceFile = new File ("target/test-classes/hello-world.ps1" );
271
272
File targetFile = new File ("target/test-classes/hello-world-signed-with-cli.ps1" );
272
273
FileUtils .copyFile (sourceFile , targetFile );
273
-
274
+
274
275
cli .execute ("--alg=SHA-1" , "--replace" , "--encoding=ISO-8859-1" , "--keystore=target/test-classes/keystores/" + keystore , "--alias=" + alias , "--keypass=" + keypass , "" + targetFile );
275
276
276
277
PowerShellScript script = new PowerShellScript (targetFile );
@@ -283,7 +284,7 @@ public void testSigningPowerShellWithDefaultEncoding() throws Exception {
283
284
File sourceFile = new File ("target/test-classes/hello-world.ps1" );
284
285
File targetFile = new File ("target/test-classes/hello-world-signed-with-cli.ps1" );
285
286
FileUtils .copyFile (sourceFile , targetFile );
286
-
287
+
287
288
cli .execute ("--alg=SHA-1" , "--replace" , "--keystore=target/test-classes/keystores/" + keystore , "--alias=" + alias , "--keypass=" + keypass , "" + targetFile );
288
289
289
290
PowerShellScript script = new PowerShellScript (targetFile );
@@ -296,7 +297,7 @@ public void testSigningMSI() throws Exception {
296
297
File sourceFile = new File ("target/test-classes/minimal.msi" );
297
298
File targetFile = new File ("target/test-classes/minimal-signed-with-cli.msi" );
298
299
FileUtils .copyFile (sourceFile , targetFile );
299
-
300
+
300
301
cli .execute ("--alg=SHA-1" , "--replace" , "--keystore=target/test-classes/keystores/" + keystore , "--alias=" + alias , "--keypass=" + keypass , "" + targetFile );
301
302
302
303
try (MSIFile file = new MSIFile (targetFile )) {
@@ -307,7 +308,7 @@ public void testSigningMSI() throws Exception {
307
308
@ Test
308
309
public void testSigningPKCS12 () throws Exception {
309
310
cli .execute ("--name=WinEyes" , "--url=http://www.steelblue.com/WinEyes" , "--alg=SHA-256" , "--keystore=target/test-classes/keystores/keystore.p12" , "--alias=test" , "--storepass=password" , "" + targetFile );
310
-
311
+
311
312
assertTrue ("The file " + targetFile + " wasn't changed" , SOURCE_FILE_CRC32 != FileUtils .checksumCRC32 (targetFile ));
312
313
313
314
try (PEFile peFile = new PEFile (targetFile )) {
@@ -329,7 +330,7 @@ public void testSigningJCEKS() throws Exception {
329
330
@ Test
330
331
public void testSigningPVKSPC () throws Exception {
331
332
cli .execute ("--url=http://www.steelblue.com/WinEyes" , "--certfile=target/test-classes/keystores/jsign-test-certificate-full-chain.spc" , "--keyfile=target/test-classes/keystores/privatekey-encrypted.pvk" , "--storepass=password" , "" + targetFile );
332
-
333
+
333
334
assertTrue ("The file " + targetFile + " wasn't changed" , SOURCE_FILE_CRC32 != FileUtils .checksumCRC32 (targetFile ));
334
335
335
336
try (PEFile peFile = new PEFile (targetFile )) {
@@ -340,7 +341,7 @@ public void testSigningPVKSPC() throws Exception {
340
341
@ Test
341
342
public void testSigningPEM () throws Exception {
342
343
cli .execute ("--certfile=target/test-classes/keystores/jsign-test-certificate.pem" , "--keyfile=target/test-classes/keystores/privatekey.pkcs8.pem" , "--keypass=password" , "" + targetFile );
343
-
344
+
344
345
assertTrue ("The file " + targetFile + " wasn't changed" , SOURCE_FILE_CRC32 != FileUtils .checksumCRC32 (targetFile ));
345
346
346
347
try (PEFile peFile = new PEFile (targetFile )) {
@@ -351,7 +352,7 @@ public void testSigningPEM() throws Exception {
351
352
@ Test
352
353
public void testSigningEncryptedPEM () throws Exception {
353
354
cli .execute ("--certfile=target/test-classes/keystores/jsign-test-certificate.pem" , "--keyfile=target/test-classes/keystores/privatekey-encrypted.pkcs1.pem" , "--keypass=password" , "" + targetFile );
354
-
355
+
355
356
assertTrue ("The file " + targetFile + " wasn't changed" , SOURCE_FILE_CRC32 != FileUtils .checksumCRC32 (targetFile ));
356
357
357
358
try (PEFile peFile = new PEFile (targetFile )) {
@@ -361,7 +362,7 @@ public void testSigningEncryptedPEM() throws Exception {
361
362
362
363
@ Test
363
364
public void testSigningWithYubikey () throws Exception {
364
- Assume .assumeTrue ("No Yubikey detected" , YubiKey .isPresent ());
365
+ Assume .assumeTrue ("No Yubikey detected" , YubiKeyKeyStore .isPresent ());
365
366
366
367
cli .execute ("--storetype=YUBIKEY" , "--certfile=target/test-classes/keystores/jsign-test-certificate-full-chain.spc" , "--storepass=123456" , "--alias=X.509 Certificate for Digital Signature" , "" + targetFile , "" + targetFile );
367
368
}
@@ -371,7 +372,7 @@ public void testTimestampingAuthenticode() throws Exception {
371
372
File targetFile2 = new File ("target/test-classes/wineyes-timestamped-with-cli-authenticode.exe" );
372
373
FileUtils .copyFile (sourceFile , targetFile2 );
373
374
cli .execute ("--keystore=target/test-classes/keystores/" + keystore , "--alias=" + alias , "--keypass=" + keypass , "--tsaurl=http://timestamp.sectigo.com" , "--tsmode=authenticode" , "" + targetFile2 );
374
-
375
+
375
376
assertTrue ("The file " + targetFile2 + " wasn't changed" , SOURCE_FILE_CRC32 != FileUtils .checksumCRC32 (targetFile2 ));
376
377
377
378
try (PEFile peFile = new PEFile (targetFile2 )) {
@@ -404,18 +405,18 @@ public HttpFilters filterRequest(HttpRequest originalRequest) {
404
405
}
405
406
})
406
407
.start ();
407
-
408
+
408
409
try {
409
410
File targetFile2 = new File ("target/test-classes/wineyes-timestamped-with-cli-rfc3161-proxy-unauthenticated.exe" );
410
411
FileUtils .copyFile (sourceFile , targetFile2 );
411
412
cli .execute ("--keystore=target/test-classes/keystores/" + keystore , "--alias=" + alias , "--keypass=" + keypass ,
412
413
"--tsaurl=http://timestamp.sectigo.com" , "--tsmode=rfc3161" , "--tsretries=1" , "--tsretrywait=1" ,
413
414
"--proxyUrl=localhost:" + proxy .getListenAddress ().getPort (),
414
415
"" + targetFile2 );
415
-
416
+
416
417
assertTrue ("The file " + targetFile2 + " wasn't changed" , SOURCE_FILE_CRC32 != FileUtils .checksumCRC32 (targetFile2 ));
417
418
assertTrue ("The proxy wasn't used" , proxyUsed .get ());
418
-
419
+
419
420
try (PEFile peFile = new PEFile (targetFile2 )) {
420
421
SignatureAssert .assertSigned (peFile , SHA256 );
421
422
}
@@ -457,10 +458,10 @@ public String getRealm() {
457
458
"--proxyUser=jsign" ,
458
459
"--proxyPass=jsign" ,
459
460
"" + targetFile2 );
460
-
461
+
461
462
assertTrue ("The file " + targetFile2 + " wasn't changed" , SOURCE_FILE_CRC32 != FileUtils .checksumCRC32 (targetFile2 ));
462
463
assertTrue ("The proxy wasn't used" , proxyUsed .get ());
463
-
464
+
464
465
try (PEFile peFile = new PEFile (targetFile2 )) {
465
466
SignatureAssert .assertSigned (peFile , SHA256 );
466
467
}
@@ -474,11 +475,11 @@ public void testReplaceSignature() throws Exception {
474
475
File targetFile2 = new File ("target/test-classes/wineyes-re-signed.exe" );
475
476
FileUtils .copyFile (sourceFile , targetFile2 );
476
477
cli .execute ("--keystore=target/test-classes/keystores/" + keystore , "--alias=" + alias , "--keypass=" + keypass , "" + targetFile2 );
477
-
478
+
478
479
assertTrue ("The file " + targetFile2 + " wasn't changed" , SOURCE_FILE_CRC32 != FileUtils .checksumCRC32 (targetFile2 ));
479
-
480
+
480
481
cli .execute ("--keystore=target/test-classes/keystores/" + keystore , "--alias=" + alias , "--keypass=" + keypass , "--alg=SHA-512" , "--replace" , "" + targetFile2 );
481
-
482
+
482
483
try (PEFile peFile = new PEFile (targetFile2 )) {
483
484
SignatureAssert .assertSigned (peFile , SHA512 );
484
485
}
@@ -514,7 +515,7 @@ public Integer getStatus() {
514
515
}
515
516
516
517
public void checkPermission (Permission perm ) { }
517
-
518
+
518
519
public void checkPermission (Permission perm , Object context ) { }
519
520
520
521
public void checkExit (int status ) {
0 commit comments