Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Register com.jcraft.jsch.jbcrypt.JBCrypt for reflection #106

Merged
merged 5 commits into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ ReflectiveClassBuildItem reflection() {
"com.jcraft.jsch.DHGEX512",
"com.jcraft.jsch.DHGN",
"com.jcraft.jsch.DHXEC",
"com.jcraft.jsch.jbcrypt.JBCrypt",
"com.jcraft.jsch.jce.AES128CBC",
"com.jcraft.jsch.jce.AES128CTR",
"com.jcraft.jsch.jce.AES192CBC",
Expand Down
2 changes: 2 additions & 0 deletions integration-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,14 @@
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>${native.surefire.skip}</skipTests>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.QueryParam;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;

import com.jcraft.jsch.JSch;
import com.jcraft.jsch.KeyPair;
import com.jcraft.jsch.Session;

@Path("/jsch")
Expand All @@ -21,4 +24,13 @@ public Response connect(@QueryParam("host") String host, @QueryParam("port") int
session.disconnect();
return Response.ok(serverVersion).build();
}

@GET
@Path("/keypair/decrypt")
@Produces(MediaType.TEXT_PLAIN)
public boolean decryptKeypair(@QueryParam("privateKey") String privateKey,
@QueryParam("passphrase") String passphrase) throws Exception {
KeyPair keyPair = KeyPair.load(new JSch(), privateKey, null);
return keyPair.decrypt(passphrase);
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package io.quarkus.it.jsch;

import static io.restassured.RestAssured.given;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.hamcrest.CoreMatchers.endsWith;
import static org.hamcrest.core.Is.is;

import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Path;

import org.apache.sshd.server.SshServer;
import org.apache.sshd.server.auth.hostbased.AcceptAllHostBasedAuthenticator;
Expand All @@ -15,6 +18,10 @@
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

import com.jcraft.jsch.JSch;
import com.jcraft.jsch.KeyPair;

import io.quarkus.test.junit.QuarkusTest;

Expand Down Expand Up @@ -45,6 +52,29 @@ void shouldConnect() {
.body(endsWith(sshd.getVersion()));
}

@Test
void shouldDecryptUsingKeyPair(@TempDir Path keypairDir) throws Exception {
String passphrase = "password";
// Generate a Keypair
KeyPair keyPair = KeyPair.genKeyPair(new JSch(), KeyPair.RSA, 2048);
// Save the private key
Path privateKeyPath = keypairDir.resolve("test_rsa");
try (OutputStream out = Files.newOutputStream(privateKeyPath)) {
keyPair.writePrivateKey(out, passphrase.getBytes(UTF_8));
}
// Save the public key
Path publicKeyPath = keypairDir.resolve("test_rsa.pub");
try (OutputStream out = Files.newOutputStream(publicKeyPath)) {
keyPair.writePublicKey(out, "test_rsa");
}
given().queryParam("privateKey", privateKeyPath.toAbsolutePath().toString())
.queryParam("passphrase", passphrase)
.get("/jsch/keypair/decrypt")
.then()
.statusCode(is(200))
.body(is("true"));
}

@AfterEach
void stopServer() throws Exception {
if (sshd != null) {
Expand Down