|
18 | 18 |
|
19 | 19 | import java.io.File; |
20 | 20 | import java.io.FileOutputStream; |
| 21 | +import java.io.FileReader; |
21 | 22 | import java.net.ProxySelector; |
22 | 23 | import java.nio.charset.StandardCharsets; |
23 | 24 | import java.nio.file.Files; |
|
28 | 29 | import java.util.concurrent.atomic.AtomicBoolean; |
29 | 30 |
|
30 | 31 | import io.netty.handler.codec.http.HttpRequest; |
| 32 | +import net.jadler.Jadler; |
31 | 33 | import org.apache.commons.cli.ParseException; |
32 | 34 | import org.apache.commons.io.ByteOrderMark; |
33 | 35 | import org.apache.commons.io.FileUtils; |
@@ -481,6 +483,52 @@ public String getRealm() { |
481 | 483 | } |
482 | 484 | } |
483 | 485 |
|
| 486 | + @Test |
| 487 | + public void testSigningWithProxy() throws Exception { |
| 488 | + Jadler.initJadler().withDefaultResponseStatus(404); |
| 489 | + Jadler.onRequest() |
| 490 | + .havingMethodEqualTo("GET") |
| 491 | + .havingPathEqualTo("/certificates/test1") |
| 492 | + .havingHeaderEqualTo("Via", "1.1 JsignProxy") |
| 493 | + .respond() |
| 494 | + .withStatus(200) |
| 495 | + .withBody(IOUtils.toString(new FileReader("../jsign-crypto/src/test/resources/services/azure-certificate.json")).replaceAll("https://jsigntestkeyvault.vault.azure.net", "http://localhost:" + Jadler.port())); |
| 496 | + |
| 497 | + Jadler.onRequest() |
| 498 | + .havingMethodEqualTo("POST") |
| 499 | + .havingPathEqualTo("/keys/test1/38ca3e3560b94086ac604c5dd21aa055/sign") |
| 500 | + .havingHeaderEqualTo("Via", "1.1 JsignProxy") |
| 501 | + .havingBodyEqualTo("{\"alg\":\"RS256\",\"value\":\"kSBZhCngz7tfmw+l3j1W5vHMMcGYvpijTm++fl8zANY=\"}") |
| 502 | + .respond() |
| 503 | + .withStatus(200) |
| 504 | + .withBody("{\"kid\":\"https://jsigntestkeyvault.vault.azure.net/keys/test1/38ca3e3560b94086ac604c5dd21aa055\",\"value\":\"CzDTijE0vOEDJTzbzhaMuF5mN-yO59DI5DaA35U8Rldj1mwwmHvH2yyLn2UA_dn2U5KjjmI5CXjf_gWa_-WZDmTxr6w-yNRUlJ4TJZBUF7tdi5MI70maZgcY3MGkXzWeAxXiKf57ZLMfJWLNGxXMrMQRJDi6XlDfmwIApxK-0gsUlZhq2GjlBZWGf7IPBr1Mk6ZeOUfPzFTrPXgFs5CBS5FMYGuujePGjVDRY-ODbs2l9JpQW-wv6lRX0bFXgzn4LwVqHOM_P-_kxBLbIV37hfnBnV_uYF3aDEYkE3I-wni8JPRr3hFsqRY5wea_HzzropDD1zQ5TNLJXdbLro0S7A\"}"); |
| 505 | + |
| 506 | + HttpProxyServer proxy = DefaultHttpProxyServer.bootstrap() |
| 507 | + .withPort(12543) |
| 508 | + .withProxyAlias("JsignProxy") |
| 509 | + .start(); |
| 510 | + |
| 511 | + try { |
| 512 | + File targetFile2 = new File("target/test-classes/wineyes-signed-with-cli-proxy.exe"); |
| 513 | + FileUtils.copyFile(sourceFile, targetFile2); |
| 514 | + cli.execute("--storetype=AZUREKEYVAULT", |
| 515 | + "--keystore=http://localhost:" + Jadler.port(), |
| 516 | + "--storepass=token", |
| 517 | + "--alias=test1", |
| 518 | + "--proxyUrl=localhost:" + proxy.getListenAddress().getPort(), |
| 519 | + "" + targetFile2); |
| 520 | + |
| 521 | + assertTrue("The file " + targetFile2 + " wasn't changed", SOURCE_FILE_CRC32 != FileUtils.checksumCRC32(targetFile2)); |
| 522 | + |
| 523 | + try (PEFile peFile = new PEFile(targetFile2)) { |
| 524 | + SignatureAssert.assertSigned(peFile, SHA256); |
| 525 | + } |
| 526 | + } finally { |
| 527 | + proxy.stop(); |
| 528 | + Jadler.closeJadler(); |
| 529 | + } |
| 530 | + } |
| 531 | + |
484 | 532 | @Test |
485 | 533 | public void testReplaceSignature() throws Exception { |
486 | 534 | File targetFile2 = new File("target/test-classes/wineyes-re-signed.exe"); |
|
0 commit comments