forked from quarkiverse/quarkus-jsch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
quarkiverse#105 added integration test using KeyPair.
- Loading branch information
1 parent
4bda37f
commit 7faa419
Showing
4 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
integration-tests/src/main/java/io/quarkus/it/jsch/KeyPairResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package io.quarkus.it.jsch; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
|
||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.core.Response; | ||
|
||
import com.jcraft.jsch.JSch; | ||
import com.jcraft.jsch.JSchException; | ||
import com.jcraft.jsch.KeyPair; | ||
|
||
@Path("/key") | ||
public class KeyPairResource { | ||
|
||
@GET | ||
public Response checkKey() throws Exception { | ||
try (var is = getClass().getResourceAsStream(("/id_rsa.pem"))) { | ||
return Response.ok(verifyPemEncodedPrivateKey(is.readAllBytes(), "PrettyPlease")).build(); | ||
} | ||
} | ||
|
||
/** | ||
* Verify that the private key is valid and can be decrypted with the given passphrase. | ||
* | ||
* @param privateKeyBytes The private key file (PEM encoded) as raw bytes. | ||
* @param passphrase The passphrase, may be null for plain text keys. | ||
* @return finger print. | ||
*/ | ||
private String verifyPemEncodedPrivateKey(byte[] privateKeyBytes, String passphrase) { | ||
KeyPair keyPair; | ||
try { | ||
keyPair = KeyPair.load(new JSch(), privateKeyBytes, null); | ||
} catch (JSchException e) { | ||
throw new RuntimeException("Failed to parse SSH private key", e); | ||
} | ||
if (keyPair.isEncrypted()) { | ||
keyPair.decrypt(passphrase.getBytes(StandardCharsets.UTF_8)); | ||
} | ||
return keyPair.getFingerPrint(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
-----BEGIN OPENSSH PRIVATE KEY----- | ||
b3BlbnNzaC1rZXktdjEAAAAACmFlczI1Ni1jdHIAAAAGYmNyeXB0AAAAGAAAABB8KarbgH | ||
gP3XEK+fsZmlP5AAAAEAAAAAEAAAGXAAAAB3NzaC1yc2EAAAADAQABAAABgQDWavxs+pOy | ||
y/66A+id4U94005jFHk4+mtqsZcPY3x5xuXviqWjzhyEa1vL+gKe9DywinxBWVl51R8OSE | ||
BZ1H/mz77u4qaVkUlu0a/r3eYFlELIjDFGzODkEGdvptYt2FPPAdsoCCpB8pqNky8R873A | ||
SvA316fhY3Y801x30OGNcjNhYmrEk+vAV37VnJJKJ1IgGWAFg7ZAoGDaund/2Liif9yC3c | ||
UPSPZolkduDyCqBW4YlIe+FYCeBV8F8dBQCip4jjQIEqwSrJbpCqI5txORtfJhwHPaXan/ | ||
JhjH5vIZ5zjhSPOcpVQxFJbc1eTAPhoSE/za6mLgA4t+IkSg06BRDpEpVIbxr3eVtIMELG | ||
4pZmZsi6X8LcA2DI/8vdpcwVTDzpdZ1LMuEzfZFFxBk4L1U996U/FVzEhyE1U8t5ZLButT | ||
pC8OXuEe58IyT/aLtksWKUN9g5VjVl/Bm0R5HviyUvvClkWM6nN5hWtI0AzQ7Q+VBlRF+3 | ||
38cXR9tOmPFZMAAAWQDMCOotnrWCkAHoRWqMMEfjlMLn+laGd5xkxP9lkRcBSjIdqWQ7N5 | ||
CXeM1QX/0soKzWKS5raMx0AcwkdkTGjLKV3LcjAX7xmJ6KQxZWBL+PPStIvz4UhvfVHXy2 | ||
b9ZI8cWAaIuTldNgUVRqFixtaaWyIfA0bZGgK8HuMXSgthAGtvNwxYsPt6bDDnmnJI1y+I | ||
q99Xr98N/QyzktZQH17jZFZCICDEG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8AjFqTlHOz61iXa18xe | ||
ucGI+X/NjP80Ym+FWwtnLzMYK4zLIX+/OJAXN8SfccgorLBq/t75uKFWJlgbsK2KG1cvJf | ||
9EJnpxTedhLYPSY9EI6+xs3cT0FGxD2u57+iD2ejl0DuQU1VqANMxGM8pfYxTYXlurJRbw | ||
Xedychxls++wgIlA40l8FWfaDHBtYeAVKuGbAx+osyWB/gvgo48NXqvhz6KPl95wvDbqUf | ||
L8R23rLTt6QZkuE5L20kMhVARJLgS0g38IaVeoev8Nl723oxRb6ZDFamkME4mUnpmkKYUo | ||
KTACH0+CijxbzROl41b9AsKswJxZHzGqecfUXQS+jFJO6DNdM/P3m7/DJorsr71WvWGQFO | ||
mzNgZkFv/DUgR4FNChTi4jdOY+DRdkJbt4hTjT2dcyiurZDXUkgPJiQd7scMZfIQYVIzAm | ||
z6/hXwOXxSUowDfl3hMQoJRr8rjV+ZpS1OFfC/G4PkWi5zyOaRvvuCzzMglTvgVvleCbPN | ||
NtpQV8SqvveYJJf2hKOx1lN+yxqVTgppB1dU3btzwJegWTXRZbRgyTAFeE1ZMiE1cSf8nW | ||
Vs3LYvEo2D+CoHD4dMnd6YpyqV+lagK+4dx8RSwivOpB/D/aUBcwGF6XugvVGdfdh/2Dnw | ||
MsrQcO3ZafSW9TJbAo/JOneZccY= | ||
-----END OPENSSH PRIVATE KEY----- |
17 changes: 17 additions & 0 deletions
17
integration-tests/src/test/java/io/quarkus/it/jsch/KeyPairTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package io.quarkus.it.jsch; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static org.hamcrest.core.Is.is; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import io.quarkus.test.junit.QuarkusTest; | ||
|
||
@QuarkusTest | ||
public class KeyPairTest { | ||
|
||
@Test | ||
void shouldBeAbleToDecryptKey() { | ||
given().get("/key").then().statusCode(is(200)); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
integration-tests/src/test/java/io/quarkus/it/jsch/NativeKeyPairIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package io.quarkus.it.jsch; | ||
|
||
import io.quarkus.test.junit.QuarkusIntegrationTest; | ||
|
||
@QuarkusIntegrationTest | ||
public class NativeKeyPairIT extends KeyPairTest { | ||
} |