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 );
@@ -226,7 +227,7 @@ public void testSigningMultipleFiles() throws Exception {
226
227
public void testSigningMultipleFilesWithListFile () throws Exception {
227
228
File listFile = new File ("target/test-classes/files.txt" );
228
229
Files .write (listFile .toPath (), Arrays .asList ("# first file" , '"' + targetFile .getPath () + '"' , " " , "# second file" , targetFile .getAbsolutePath ()));
229
-
230
+
230
231
cli .execute ("--name=WinEyes" , "--url=http://www.steelblue.com/WinEyes" , "--alg=SHA-1" , "--keystore=target/test-classes/keystores/" + keystore , "--keypass=" + keypass , "@" + listFile );
231
232
232
233
assertTrue ("The file " + targetFile + " wasn't changed" , SOURCE_FILE_CRC32 != FileUtils .checksumCRC32 (targetFile ));
@@ -278,7 +279,7 @@ public void testSigningPowerShell() throws Exception {
278
279
File sourceFile = new File ("target/test-classes/hello-world.ps1" );
279
280
File targetFile = new File ("target/test-classes/hello-world-signed-with-cli.ps1" );
280
281
FileUtils .copyFile (sourceFile , targetFile );
281
-
282
+
282
283
cli .execute ("--alg=SHA-1" , "--replace" , "--encoding=ISO-8859-1" , "--keystore=target/test-classes/keystores/" + keystore , "--alias=" + alias , "--keypass=" + keypass , "" + targetFile );
283
284
284
285
PowerShellScript script = new PowerShellScript (targetFile );
@@ -291,7 +292,7 @@ public void testSigningPowerShellWithDefaultEncoding() throws Exception {
291
292
File sourceFile = new File ("target/test-classes/hello-world.ps1" );
292
293
File targetFile = new File ("target/test-classes/hello-world-signed-with-cli.ps1" );
293
294
FileUtils .copyFile (sourceFile , targetFile );
294
-
295
+
295
296
cli .execute ("--alg=SHA-1" , "--replace" , "--keystore=target/test-classes/keystores/" + keystore , "--alias=" + alias , "--keypass=" + keypass , "" + targetFile );
296
297
297
298
PowerShellScript script = new PowerShellScript (targetFile );
@@ -304,7 +305,7 @@ public void testSigningMSI() throws Exception {
304
305
File sourceFile = new File ("target/test-classes/minimal.msi" );
305
306
File targetFile = new File ("target/test-classes/minimal-signed-with-cli.msi" );
306
307
FileUtils .copyFile (sourceFile , targetFile );
307
-
308
+
308
309
cli .execute ("--alg=SHA-1" , "--replace" , "--keystore=target/test-classes/keystores/" + keystore , "--alias=" + alias , "--keypass=" + keypass , "" + targetFile );
309
310
310
311
try (MSIFile file = new MSIFile (targetFile )) {
@@ -315,7 +316,7 @@ public void testSigningMSI() throws Exception {
315
316
@ Test
316
317
public void testSigningPKCS12 () throws Exception {
317
318
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 );
318
-
319
+
319
320
assertTrue ("The file " + targetFile + " wasn't changed" , SOURCE_FILE_CRC32 != FileUtils .checksumCRC32 (targetFile ));
320
321
321
322
try (PEFile peFile = new PEFile (targetFile )) {
@@ -337,7 +338,7 @@ public void testSigningJCEKS() throws Exception {
337
338
@ Test
338
339
public void testSigningPVKSPC () throws Exception {
339
340
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 );
340
-
341
+
341
342
assertTrue ("The file " + targetFile + " wasn't changed" , SOURCE_FILE_CRC32 != FileUtils .checksumCRC32 (targetFile ));
342
343
343
344
try (PEFile peFile = new PEFile (targetFile )) {
@@ -348,7 +349,7 @@ public void testSigningPVKSPC() throws Exception {
348
349
@ Test
349
350
public void testSigningPEM () throws Exception {
350
351
cli .execute ("--certfile=target/test-classes/keystores/jsign-test-certificate.pem" , "--keyfile=target/test-classes/keystores/privatekey.pkcs8.pem" , "--keypass=password" , "" + targetFile );
351
-
352
+
352
353
assertTrue ("The file " + targetFile + " wasn't changed" , SOURCE_FILE_CRC32 != FileUtils .checksumCRC32 (targetFile ));
353
354
354
355
try (PEFile peFile = new PEFile (targetFile )) {
@@ -359,7 +360,7 @@ public void testSigningPEM() throws Exception {
359
360
@ Test
360
361
public void testSigningEncryptedPEM () throws Exception {
361
362
cli .execute ("--certfile=target/test-classes/keystores/jsign-test-certificate.pem" , "--keyfile=target/test-classes/keystores/privatekey-encrypted.pkcs1.pem" , "--keypass=password" , "" + targetFile );
362
-
363
+
363
364
assertTrue ("The file " + targetFile + " wasn't changed" , SOURCE_FILE_CRC32 != FileUtils .checksumCRC32 (targetFile ));
364
365
365
366
try (PEFile peFile = new PEFile (targetFile )) {
@@ -369,7 +370,7 @@ public void testSigningEncryptedPEM() throws Exception {
369
370
370
371
@ Test
371
372
public void testSigningWithYubikey () throws Exception {
372
- Assume .assumeTrue ("No Yubikey detected" , YubiKey .isPresent ());
373
+ Assume .assumeTrue ("No Yubikey detected" , YubiKeyKeyStore .isPresent ());
373
374
374
375
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 );
375
376
}
@@ -379,7 +380,7 @@ public void testTimestampingAuthenticode() throws Exception {
379
380
File targetFile2 = new File ("target/test-classes/wineyes-timestamped-with-cli-authenticode.exe" );
380
381
FileUtils .copyFile (sourceFile , targetFile2 );
381
382
cli .execute ("--keystore=target/test-classes/keystores/" + keystore , "--alias=" + alias , "--keypass=" + keypass , "--tsaurl=http://timestamp.sectigo.com" , "--tsmode=authenticode" , "" + targetFile2 );
382
-
383
+
383
384
assertTrue ("The file " + targetFile2 + " wasn't changed" , SOURCE_FILE_CRC32 != FileUtils .checksumCRC32 (targetFile2 ));
384
385
385
386
try (PEFile peFile = new PEFile (targetFile2 )) {
@@ -412,18 +413,18 @@ public HttpFilters filterRequest(HttpRequest originalRequest) {
412
413
}
413
414
})
414
415
.start ();
415
-
416
+
416
417
try {
417
418
File targetFile2 = new File ("target/test-classes/wineyes-timestamped-with-cli-rfc3161-proxy-unauthenticated.exe" );
418
419
FileUtils .copyFile (sourceFile , targetFile2 );
419
420
cli .execute ("--keystore=target/test-classes/keystores/" + keystore , "--alias=" + alias , "--keypass=" + keypass ,
420
421
"--tsaurl=http://timestamp.sectigo.com" , "--tsmode=rfc3161" , "--tsretries=1" , "--tsretrywait=1" ,
421
422
"--proxyUrl=localhost:" + proxy .getListenAddress ().getPort (),
422
423
"" + targetFile2 );
423
-
424
+
424
425
assertTrue ("The file " + targetFile2 + " wasn't changed" , SOURCE_FILE_CRC32 != FileUtils .checksumCRC32 (targetFile2 ));
425
426
assertTrue ("The proxy wasn't used" , proxyUsed .get ());
426
-
427
+
427
428
try (PEFile peFile = new PEFile (targetFile2 )) {
428
429
SignatureAssert .assertSigned (peFile , SHA256 );
429
430
}
@@ -465,10 +466,10 @@ public String getRealm() {
465
466
"--proxyUser=jsign" ,
466
467
"--proxyPass=jsign" ,
467
468
"" + targetFile2 );
468
-
469
+
469
470
assertTrue ("The file " + targetFile2 + " wasn't changed" , SOURCE_FILE_CRC32 != FileUtils .checksumCRC32 (targetFile2 ));
470
471
assertTrue ("The proxy wasn't used" , proxyUsed .get ());
471
-
472
+
472
473
try (PEFile peFile = new PEFile (targetFile2 )) {
473
474
SignatureAssert .assertSigned (peFile , SHA256 );
474
475
}
@@ -482,11 +483,11 @@ public void testReplaceSignature() throws Exception {
482
483
File targetFile2 = new File ("target/test-classes/wineyes-re-signed.exe" );
483
484
FileUtils .copyFile (sourceFile , targetFile2 );
484
485
cli .execute ("--keystore=target/test-classes/keystores/" + keystore , "--alias=" + alias , "--keypass=" + keypass , "" + targetFile2 );
485
-
486
+
486
487
assertTrue ("The file " + targetFile2 + " wasn't changed" , SOURCE_FILE_CRC32 != FileUtils .checksumCRC32 (targetFile2 ));
487
-
488
+
488
489
cli .execute ("--keystore=target/test-classes/keystores/" + keystore , "--alias=" + alias , "--keypass=" + keypass , "--alg=SHA-512" , "--replace" , "" + targetFile2 );
489
-
490
+
490
491
try (PEFile peFile = new PEFile (targetFile2 )) {
491
492
SignatureAssert .assertSigned (peFile , SHA512 );
492
493
}
@@ -525,7 +526,7 @@ public Integer getStatus() {
525
526
}
526
527
527
528
public void checkPermission (Permission perm ) { }
528
-
529
+
529
530
public void checkPermission (Permission perm , Object context ) { }
530
531
531
532
public void checkExit (int status ) {
0 commit comments