diff --git a/pom.xml b/pom.xml
index b4e2ec57f81b..7767d3500525 100644
--- a/pom.xml
+++ b/pom.xml
@@ -161,7 +161,6 @@
5.5.0
2.12.5
2.2.1
- 0.1.55
20231013
1.2
2.7.0
@@ -335,11 +334,6 @@
java-ipv6
${cs.java-ipv6.version}
-
- com.jcraft
- jsch
- ${cs.jsch.version}
-
com.rabbitmq
amqp-client
diff --git a/test/integration/smoke/test_network.py b/test/integration/smoke/test_network.py
index b3e7fd3e42f4..fc60207ed7e8 100644
--- a/test/integration/smoke/test_network.py
+++ b/test/integration/smoke/test_network.py
@@ -2349,7 +2349,7 @@ def _get_ip_address_output(self, ssh):
return '\n'.join(res)
@attr(tags=["advanced", "shared"], required_hardware="true")
- def test_01_deployVMInSharedNetwork(self):
+ def test_01_deployVMInSharedNetworkWithConfigDrive(self):
try:
self.virtual_machine = VirtualMachine.create(self.apiclient, self.services["virtual_machine"],
networkids=[self.shared_network.id, self.isolated_network.id],
diff --git a/utils/pom.xml b/utils/pom.xml
index ee6df9602b8f..92bf145de388 100755
--- a/utils/pom.xml
+++ b/utils/pom.xml
@@ -78,10 +78,6 @@
org.bouncycastle
bctls-jdk15on
-
- com.jcraft
- jsch
-
org.jasypt
jasypt
diff --git a/utils/src/main/java/com/cloud/utils/ssh/SSHKeysHelper.java b/utils/src/main/java/com/cloud/utils/ssh/SSHKeysHelper.java
index f25881ca09bd..570e025196f8 100644
--- a/utils/src/main/java/com/cloud/utils/ssh/SSHKeysHelper.java
+++ b/utils/src/main/java/com/cloud/utils/ssh/SSHKeysHelper.java
@@ -20,14 +20,19 @@
package com.cloud.utils.ssh;
import java.io.ByteArrayOutputStream;
+import java.io.StringWriter;
+import java.math.BigInteger;
+import java.nio.ByteBuffer;
+import java.security.KeyPair;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
+import java.security.NoSuchProviderException;
+import java.security.interfaces.RSAPublicKey;
+import org.apache.cloudstack.utils.security.CertUtils;
import org.apache.commons.codec.binary.Base64;
-
-import com.jcraft.jsch.JSch;
-import com.jcraft.jsch.JSchException;
-import com.jcraft.jsch.KeyPair;
+import org.bouncycastle.util.io.pem.PemObject;
+import org.bouncycastle.util.io.pem.PemWriter;
public class SSHKeysHelper {
@@ -45,8 +50,8 @@ private static String toHexString(byte[] b) {
public SSHKeysHelper(Integer keyLength) {
try {
- keyPair = KeyPair.genKeyPair(new JSch(), KeyPair.RSA, keyLength);
- } catch (JSchException e) {
+ keyPair = CertUtils.generateRandomKeyPair(keyLength);
+ } catch (NoSuchAlgorithmException | NoSuchProviderException e) {
e.printStackTrace();
}
}
@@ -105,17 +110,48 @@ public static String getPublicKeyFromKeyMaterial(String keyMaterial) {
}
public String getPublicKey() {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- keyPair.writePublicKey(baos, "");
+ try {
+ RSAPublicKey rsaPublicKey = (RSAPublicKey) keyPair.getPublic();
+
+ ByteArrayOutputStream buffer = new ByteArrayOutputStream();
+
+ writeString(buffer,"ssh-rsa");
+ writeBigInt(buffer, rsaPublicKey.getPublicExponent());
+ writeBigInt(buffer, rsaPublicKey.getModulus());
- return baos.toString();
+ String base64 = Base64.encodeBase64String(buffer.toByteArray());
+
+ return "ssh-rsa " + base64;
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return null;
}
- public String getPrivateKey() {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- keyPair.writePrivateKey(baos);
+ private static void writeString(ByteArrayOutputStream out, String str) throws Exception {
+ byte[] data = str.getBytes("UTF-8");
+ out.write(ByteBuffer.allocate(4).putInt(data.length).array());
+ out.write(data);
+ }
+
+ private static void writeBigInt(ByteArrayOutputStream out, BigInteger value) throws Exception {
+ byte[] data = value.toByteArray();
+ out.write(ByteBuffer.allocate(4).putInt(data.length).array());
+ out.write(data);
+ }
- return baos.toString();
+ public String getPrivateKey() {
+ try {
+ final PemObject pemObject = new PemObject("RSA PRIVATE KEY", keyPair.getPrivate().getEncoded());
+ final StringWriter sw = new StringWriter();
+ try (final PemWriter pw = new PemWriter(sw)) {
+ pw.writeObject(pemObject);
+ }
+ return sw.toString();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return null;
}
}