PESigner extends AuthenticodeSigner { public PESigner withTimestamper(Timestamper timestamper) { return (PESigner) super.withTimestamper(timestamper); } PESigner(Certificate[] chain, PrivateKey privateKey);  PESigner(KeyStore keystore, String alias, String password); PESigner withProgramName(String programName); PESigner withProgramURL(String programURL); PESigner withSignaturesReplaced(boolean replace); PESigner withTimestamping(boolean timestamping); PESigner withTimestampingMode(TimestampingMode tsmode); PESigner withTimestampingAutority(String url); PESigner withTimestampingAutority(String... urls); PESigner withTimestampingAuthority(String url); PESigner withTimestampingAuthority(String... urls); PESigner withTimestamper(Timestamper timestamper); PESigner withTimestampingRetries(int timestampingRetries); PESigner withTimestampingRetryWait(int timestampingRetryWait); PESigner withDigestAlgorithm(DigestAlgorithm algorithm); PESigner withSignatureAlgorithm(String signatureAlgorithm); PESigner withSignatureAlgorithm(String signatureAlgorithm, String signatureProvider); PESigner withSignatureAlgorithm(String signatureAlgorithm, Provider signatureProvider); PESigner withSignatureProvider(Provider signatureProvider); void sign(PEFile file);  }
@Test public void testWithTimestamper() throws Exception { File sourceFile = new File("target/test-classes/wineyes.exe"); File targetFile = new File("target/test-classes/wineyes-timestamped-custom.exe"); FileUtils.copyFile(sourceFile, targetFile); PEFile peFile = new PEFile(targetFile); final HashSet<Boolean> called = new HashSet<>(); PESigner signer = new PESigner(getKeyStore(), ALIAS, PRIVATE_KEY_PASSWORD); signer.withDigestAlgorithm(DigestAlgorithm.SHA1); signer.withTimestamping(true); signer.withTimestamper(new AuthenticodeTimestamper() { @Override protected CMSSignedData timestamp(DigestAlgorithm algo, byte[] encryptedDigest) throws IOException, TimestampingException { called.add(true); return super.timestamp(algo, encryptedDigest); } }); signer.sign(peFile); peFile = new PEFile(targetFile); List<CMSSignedData> signatures = peFile.getSignatures(); assertNotNull(signatures); assertEquals(1, signatures.size()); CMSSignedData signature = signatures.get(0); assertNotNull(signature); assertTrue("expecting our Timestamper to be used", called.contains(true)); SignatureAssert.assertTimestamped("Invalid timestamp", signature); }