47
47
import net .jsign .timestamp .TimestampingException ;
48
48
import net .jsign .timestamp .TimestampingMode ;
49
49
50
+ import static net .jsign .DigestAlgorithm .*;
50
51
import static org .junit .Assert .*;
51
52
52
53
public class PESignerTest {
@@ -220,12 +221,12 @@ public void testSigningWithMismatchingKeyAndCertificate() throws Exception {
220
221
221
222
@ Test
222
223
public void testTimestampAuthenticode () throws Exception {
223
- testTimestamp (TimestampingMode .AUTHENTICODE , DigestAlgorithm . SHA1 );
224
+ testTimestamp (TimestampingMode .AUTHENTICODE , SHA1 );
224
225
}
225
226
226
227
@ Test
227
228
public void testTimestampRFC3161 () throws Exception {
228
- testTimestamp (TimestampingMode .RFC3161 , DigestAlgorithm . SHA256 );
229
+ testTimestamp (TimestampingMode .RFC3161 , SHA256 );
229
230
}
230
231
231
232
public void testTimestamp (TimestampingMode mode , DigestAlgorithm alg ) throws Exception {
@@ -268,7 +269,7 @@ public void testWithTimestamper() throws Exception {
268
269
final HashSet <Boolean > called = new HashSet <>();
269
270
270
271
PESigner signer = new PESigner (getKeyStore (), ALIAS , PRIVATE_KEY_PASSWORD );
271
- signer .withDigestAlgorithm (DigestAlgorithm . SHA1 );
272
+ signer .withDigestAlgorithm (SHA1 );
272
273
signer .withTimestamping (true );
273
274
signer .withTimestamper (new AuthenticodeTimestamper () {
274
275
@@ -305,7 +306,7 @@ public void testSignTwice() throws Exception {
305
306
PEFile peFile = new PEFile (targetFile );
306
307
307
308
PESigner signer = new PESigner (getKeyStore (), ALIAS , PRIVATE_KEY_PASSWORD )
308
- .withDigestAlgorithm (DigestAlgorithm . SHA1 )
309
+ .withDigestAlgorithm (SHA1 )
309
310
.withTimestamping (true )
310
311
.withProgramName ("WinEyes" )
311
312
.withProgramURL ("http://www.steelblue.com/WinEyes" );
@@ -322,7 +323,7 @@ public void testSignTwice() throws Exception {
322
323
SignatureAssert .assertTimestamped ("Invalid timestamp" , signatures .get (0 ));
323
324
324
325
// second signature
325
- signer .withDigestAlgorithm (DigestAlgorithm . SHA256 );
326
+ signer .withDigestAlgorithm (SHA256 );
326
327
signer .withTimestamping (false );
327
328
signer .sign (peFile );
328
329
@@ -345,7 +346,7 @@ public void testSignThreeTimes() throws Exception {
345
346
PEFile peFile = new PEFile (targetFile );
346
347
347
348
PESigner signer = new PESigner (getKeyStore (), ALIAS , PRIVATE_KEY_PASSWORD )
348
- .withDigestAlgorithm (DigestAlgorithm . SHA1 )
349
+ .withDigestAlgorithm (SHA1 )
349
350
.withTimestamping (true )
350
351
.withProgramName ("WinEyes" )
351
352
.withProgramURL ("http://www.steelblue.com/WinEyes" );
@@ -362,7 +363,7 @@ public void testSignThreeTimes() throws Exception {
362
363
SignatureAssert .assertTimestamped ("Invalid timestamp" , signatures .get (0 ));
363
364
364
365
// second signature
365
- signer .withDigestAlgorithm (DigestAlgorithm . SHA256 );
366
+ signer .withDigestAlgorithm (SHA256 );
366
367
signer .withTimestamping (false );
367
368
signer .sign (peFile );
368
369
@@ -375,7 +376,7 @@ public void testSignThreeTimes() throws Exception {
375
376
SignatureAssert .assertTimestamped ("Timestamp corrupted after adding the second signature" , signatures .get (0 ));
376
377
377
378
// third signature
378
- signer .withDigestAlgorithm (DigestAlgorithm . SHA512 );
379
+ signer .withDigestAlgorithm (SHA512 );
379
380
signer .withTimestamping (false );
380
381
signer .sign (peFile );
381
382
@@ -398,7 +399,7 @@ public void testReplaceSignature() throws Exception {
398
399
PEFile peFile = new PEFile (targetFile );
399
400
400
401
PESigner signer = new PESigner (getKeyStore (), ALIAS , PRIVATE_KEY_PASSWORD )
401
- .withDigestAlgorithm (DigestAlgorithm . SHA1 )
402
+ .withDigestAlgorithm (SHA1 )
402
403
.withProgramName ("WinEyes" )
403
404
.withProgramURL ("http://www.steelblue.com/WinEyes" );
404
405
@@ -413,7 +414,7 @@ public void testReplaceSignature() throws Exception {
413
414
assertNotNull (signatures .get (0 ));
414
415
415
416
// second signature
416
- signer .withDigestAlgorithm (DigestAlgorithm . SHA256 );
417
+ signer .withDigestAlgorithm (SHA256 );
417
418
signer .withTimestamping (false );
418
419
signer .withSignaturesReplaced (true );
419
420
signer .sign (peFile );
@@ -425,7 +426,7 @@ public void testReplaceSignature() throws Exception {
425
426
426
427
assertNotNull (signatures .get (0 ));
427
428
428
- assertEquals ("Digest algorithm" , DigestAlgorithm . SHA256 .oid , signatures .get (0 ).getDigestAlgorithmIDs ().iterator ().next ().getAlgorithm ());
429
+ assertEquals ("Digest algorithm" , SHA256 .oid , signatures .get (0 ).getDigestAlgorithmIDs ().iterator ().next ().getAlgorithm ());
429
430
}
430
431
431
432
@ Test
@@ -447,7 +448,7 @@ public void testInvalidTimestampingAuthority(TimestampingMode mode) throws Excep
447
448
PEFile peFile = new PEFile (targetFile );
448
449
449
450
PESigner signer = new PESigner (getKeyStore (), ALIAS , PRIVATE_KEY_PASSWORD );
450
- signer .withDigestAlgorithm (DigestAlgorithm . SHA1 );
451
+ signer .withDigestAlgorithm (SHA1 );
451
452
signer .withTimestamping (true );
452
453
signer .withTimestampingMode (mode );
453
454
signer .withTimestampingAuthority ("http://www.google.com/" + mode .name ().toLowerCase ());
@@ -486,7 +487,7 @@ public void testBrokenTimestampingAuthority(TimestampingMode mode) throws Except
486
487
PEFile peFile = new PEFile (targetFile );
487
488
488
489
PESigner signer = new PESigner (getKeyStore (), ALIAS , PRIVATE_KEY_PASSWORD );
489
- signer .withDigestAlgorithm (DigestAlgorithm . SHA1 );
490
+ signer .withDigestAlgorithm (SHA1 );
490
491
signer .withTimestamping (true );
491
492
signer .withTimestampingMode (mode );
492
493
signer .withTimestampingAuthority ("http://github.com" );
@@ -510,7 +511,7 @@ public void testInvalidTimestampingURL() throws Exception {
510
511
PEFile peFile = new PEFile (new File ("target/test-classes/wineyes.exe" ));
511
512
512
513
PESigner signer = new PESigner (getKeyStore (), ALIAS , PRIVATE_KEY_PASSWORD );
513
- signer .withDigestAlgorithm (DigestAlgorithm . SHA1 );
514
+ signer .withDigestAlgorithm (SHA1 );
514
515
signer .withTimestamping (true );
515
516
signer .withTimestampingMode (TimestampingMode .RFC3161 );
516
517
signer .withTimestampingAuthority ("example://example.com" );
@@ -538,7 +539,7 @@ public void testTimestampingFailover(TimestampingMode mode, String validURL) thr
538
539
PEFile peFile = new PEFile (targetFile );
539
540
540
541
PESigner signer = new PESigner (getKeyStore (), ALIAS , PRIVATE_KEY_PASSWORD );
541
- signer .withDigestAlgorithm (DigestAlgorithm . SHA256 );
542
+ signer .withDigestAlgorithm (SHA256 );
542
543
signer .withTimestamping (true );
543
544
signer .withTimestampingMode (mode );
544
545
signer .withTimestampingRetryWait (1 );
@@ -571,7 +572,7 @@ public void testWithSignatureAlgorithmSHA1withRSA() throws Exception {
571
572
572
573
PESigner signer = new PESigner (getKeyStore (), ALIAS , PRIVATE_KEY_PASSWORD )
573
574
.withTimestamping (false )
574
- .withDigestAlgorithm (DigestAlgorithm . SHA256 )
575
+ .withDigestAlgorithm (SHA256 )
575
576
.withSignatureAlgorithm ("SHA1withRSA" );
576
577
577
578
signer .sign (peFile );
@@ -617,7 +618,7 @@ public void testWithSignatureAlgorithmSHA256withRSAandMGF1() throws Exception {
617
618
618
619
PESigner signer = new PESigner (getKeyStore (), ALIAS , PRIVATE_KEY_PASSWORD )
619
620
.withTimestamping (false )
620
- .withDigestAlgorithm (DigestAlgorithm . SHA1 )
621
+ .withDigestAlgorithm (SHA1 )
621
622
.withSignatureAlgorithm ("SHA256withRSAandMGF1" , "BC" );
622
623
623
624
signer .sign (peFile );
0 commit comments