Yaniv Bronhaim has uploaded a new change for review. Change subject: core: host-deploy: Wrap validation of fingerprint using EngineSSHClient ......................................................................
core: host-deploy: Wrap validation of fingerprint using EngineSSHClient By setting VDS object to EngineSSHClient, we initialize sshClient parameters hostname, port and ssh username and can get the stored fingerprint from the vds object for validation. Change-Id: Ie0ce892c90844bc157e9b2feaba6aeca8acad78d Signed-off-by: Yaniv Bronhaim <ybron...@redhat.com> --- M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVdsCommand.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetServerSSHKeyFingerprintQuery.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/OVirtNodeUpgrade.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/SshSoftFencingCommand.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VdsDeploy.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GetAddedGlusterServersQuery.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GetGlusterServersForImportQuery.java A backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/utils/EngineSSHClient.java R backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/utils/EngineSSHDialog.java R backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/utils/GlusterUtil.java M backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/AddVdsCommandTest.java M backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/GetServerSSHKeyFingerprintQueryTest.java M backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/gluster/GetAddedGlusterServersQueryTest.java M backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/gluster/GetGlusterServersForImportQueryTest.java R backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/utils/GlusterUtilTest.java M backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/crypt/OpenSSHUtils.java D backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ssh/EngineSSHClient.java 17 files changed, 172 insertions(+), 114 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/87/16687/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVdsCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVdsCommand.java index 7ec604e..6748100 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVdsCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVdsCommand.java @@ -17,6 +17,8 @@ import org.ovirt.engine.core.bll.job.ExecutionContext; import org.ovirt.engine.core.bll.job.ExecutionHandler; import org.ovirt.engine.core.bll.utils.ClusterUtils; +import org.ovirt.engine.core.bll.utils.EngineSSHClient; +import org.ovirt.engine.core.bll.utils.GlusterUtil; import org.ovirt.engine.core.bll.utils.PermissionSubject; import org.ovirt.engine.core.common.AuditLogType; import org.ovirt.engine.core.common.VdcObjectType; @@ -55,10 +57,7 @@ import org.ovirt.engine.core.dal.job.ExecutionMessageDirector; import org.ovirt.engine.core.dao.gluster.GlusterDBUtils; import org.ovirt.engine.core.utils.crypt.EngineEncryptionUtils; -import org.ovirt.engine.core.utils.gluster.GlusterUtil; import org.ovirt.engine.core.utils.ssh.ConstraintByteArrayOutputStream; -import org.ovirt.engine.core.utils.ssh.EngineSSHClient; -import org.ovirt.engine.core.utils.ssh.SSHClient; import org.ovirt.engine.core.utils.threadpool.ThreadPoolUtil; import org.ovirt.engine.core.utils.transaction.TransactionMethod; import org.ovirt.engine.core.utils.transaction.TransactionSupport; @@ -363,11 +362,11 @@ return ClusterUtils.getInstance(); } - public SSHClient getSSHClient() { + public EngineSSHClient getSSHClient() { Long timeout = TimeUnit.SECONDS.toMillis(Config.<Integer> GetValue(ConfigValues.ConnectToServerTimeoutInSeconds)); - SSHClient sshclient = new EngineSSHClient(); + EngineSSHClient sshclient = new EngineSSHClient(); sshclient.setHardTimeout(timeout); sshclient.setSoftTimeout(timeout); sshclient.setHost(getVds().getStaticData().getHostName(), getVds().getStaticData().getSshPort()); @@ -383,7 +382,7 @@ * * @param client - already connected ssh client */ - private String getInstalledVdsIdIfExists(SSHClient client) { + private String getInstalledVdsIdIfExists(EngineSSHClient client) { try { ByteArrayOutputStream out = new ConstraintByteArrayOutputStream(256); client.executeCommand(Config.<String> GetValue(ConfigValues.GetVdsmIdByVdsmToolCommand), @@ -402,7 +401,7 @@ protected boolean canConnect(VDS vds) { // execute the connectivity and id uniqueness validation for VDS type hosts if (vds.getVdsType() == VDSType.VDS && Config.<Boolean> GetValue(ConfigValues.InstallVds)) { - SSHClient sshclient = null; + EngineSSHClient sshclient = null; try { sshclient = getSSHClient(); sshclient.connect(); @@ -454,7 +453,7 @@ * ID of the cluster to which the server is being added. * @return true if the server is good to be added to a gluster cluster, else false. */ - private boolean isValidGlusterPeer(SSHClient sshclient, Guid clusterId) { + private boolean isValidGlusterPeer(EngineSSHClient sshclient, Guid clusterId) { if (isGlusterSupportEnabled() && clusterHasServers()) { try { // Must not allow adding a server that already is part of another gluster cluster diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetServerSSHKeyFingerprintQuery.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetServerSSHKeyFingerprintQuery.java index 9adc4aa..970d83e 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetServerSSHKeyFingerprintQuery.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetServerSSHKeyFingerprintQuery.java @@ -2,8 +2,8 @@ import org.apache.commons.lang.exception.ExceptionUtils; +import org.ovirt.engine.core.bll.utils.EngineSSHDialog; import org.ovirt.engine.core.common.queries.ServerParameters; -import org.ovirt.engine.core.utils.ssh.EngineSSHDialog; /** * Query to fetch fingerprint of the given server name diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/OVirtNodeUpgrade.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/OVirtNodeUpgrade.java index 68edfbd..2677fc1 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/OVirtNodeUpgrade.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/OVirtNodeUpgrade.java @@ -9,6 +9,7 @@ import javax.naming.TimeLimitExceededException; +import org.ovirt.engine.core.bll.utils.EngineSSHDialog; import org.ovirt.engine.core.common.businessentities.VDS; import org.ovirt.engine.core.common.businessentities.VDSStatus; import org.ovirt.engine.core.common.config.Config; @@ -16,7 +17,6 @@ import org.ovirt.engine.core.dal.dbbroker.DbFacade; import org.ovirt.engine.core.utils.log.Log; import org.ovirt.engine.core.utils.log.LogFactory; -import org.ovirt.engine.core.utils.ssh.EngineSSHDialog; import org.ovirt.engine.core.utils.ssh.SSHDialog; import org.ovirt.engine.core.utils.transaction.TransactionMethod; import org.ovirt.engine.core.utils.transaction.TransactionSupport; @@ -141,10 +141,9 @@ public void execute() throws Exception { try { _setVdsStatus(VDSStatus.Installing); - - _dialog.useDefaultKeyPair(); - _dialog.setHost(_vds.getHostName()); + _dialog.setVds(_vds); _dialog.connect(); + _dialog.useDefaultKeyPair(); _messages.post( InstallerMessages.Severity.INFO, String.format( diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/SshSoftFencingCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/SshSoftFencingCommand.java index 7d4d320..6d26b00 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/SshSoftFencingCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/SshSoftFencingCommand.java @@ -2,10 +2,10 @@ import java.io.ByteArrayOutputStream; +import org.ovirt.engine.core.bll.utils.EngineSSHClient; import org.ovirt.engine.core.common.action.VdsActionParameters; import org.ovirt.engine.core.common.config.Config; import org.ovirt.engine.core.common.config.ConfigValues; -import org.ovirt.engine.core.utils.ssh.EngineSSHClient; import org.ovirt.engine.core.vdsbroker.ResourceManager; /** @@ -40,8 +40,7 @@ VdsValidator validator = new VdsValidator(getVds()); if (validator.shouldVdsBeFenced()) { - boolean result = executeSshSoftFencingCommand(getVds().getHostName(), - getVds().getVdsGroupCompatibilityVersion().toString()); + boolean result = executeSshSoftFencingCommand(getVds().getVdsGroupCompatibilityVersion().toString()); if (result) { // SSH Soft Fencing executed without errors, tell VdsManager about it ResourceManager.getInstance().GetVdsManager(getVds().getId()).finishSshSoftFencingExecution(getVds()); @@ -63,15 +62,14 @@ * host to execute SSH Soft Fencing command on * @returns {@code true} if command has been executed successfully, {@code false} otherwise */ - private boolean executeSshSoftFencingCommand(String host, String version) { + private boolean executeSshSoftFencingCommand(String version) { boolean result = true; EngineSSHClient sshClient = null; ByteArrayOutputStream bos = null; try { sshClient = new EngineSSHClient(); - sshClient.setHost(host); - sshClient.setUser("root"); + sshClient.setVds(getVds()); sshClient.useDefaultKeyPair(); sshClient.connect(); sshClient.authenticate(); @@ -80,12 +78,10 @@ null, bos, null); - log.info("SSH Soft Fencing command executed on host " + host); + log.info("SSH Soft Fencing command executed on host " + getVds().getHostName()); + log.debug("SSH Soft Fencing command output " + bos.toString()); } catch (Exception ex) { - log.error("SSH Soft Fencing command failed on host " + host, ex); - if (bos != null) { - log.error("SSH Soft Fencing command output " + bos.toString()); - } + log.error("SSH Soft Fencing command failed on host " + getVds().getHostName(), ex); result = false; } finally { closeSshConnection(sshClient); diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VdsDeploy.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VdsDeploy.java index eda6c10..f8324b7 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VdsDeploy.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VdsDeploy.java @@ -17,6 +17,7 @@ import javax.naming.TimeLimitExceededException; import org.apache.commons.lang.StringUtils; +import org.ovirt.engine.core.bll.utils.EngineSSHDialog; import org.ovirt.engine.core.common.businessentities.VDS; import org.ovirt.engine.core.common.businessentities.VDSGroup; import org.ovirt.engine.core.common.businessentities.VDSType; @@ -32,7 +33,6 @@ import org.ovirt.engine.core.utils.linq.Predicate; import org.ovirt.engine.core.utils.log.Log; import org.ovirt.engine.core.utils.log.LogFactory; -import org.ovirt.engine.core.utils.ssh.EngineSSHDialog; import org.ovirt.engine.core.utils.ssh.SSHDialog; import org.ovirt.engine.core.utils.transaction.TransactionMethod; import org.ovirt.engine.core.utils.transaction.TransactionSupport; @@ -845,8 +845,7 @@ public void execute() throws Exception { InputStream in = null; try { - _dialog.setHost(_vds.getHostName(), _vds.getSshPort()); - setUser(_vds.getSshUsername()); + _dialog.setVds(_vds); _dialog.connect(); _messages.post( InstallerMessages.Severity.INFO, diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GetAddedGlusterServersQuery.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GetAddedGlusterServersQuery.java index 7c8b47b..e797462 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GetAddedGlusterServersQuery.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GetAddedGlusterServersQuery.java @@ -8,6 +8,7 @@ import org.ovirt.engine.core.bll.Backend; import org.ovirt.engine.core.bll.QueriesCommandBase; import org.ovirt.engine.core.bll.utils.ClusterUtils; +import org.ovirt.engine.core.bll.utils.EngineSSHDialog; import org.ovirt.engine.core.common.businessentities.VDS; import org.ovirt.engine.core.common.businessentities.gluster.GlusterServerInfo; import org.ovirt.engine.core.common.businessentities.gluster.PeerStatus; @@ -17,7 +18,6 @@ import org.ovirt.engine.core.common.vdscommands.VDSReturnValue; import org.ovirt.engine.core.common.vdscommands.VdsIdVDSCommandParametersBase; import org.ovirt.engine.core.dao.gluster.GlusterDBUtils; -import org.ovirt.engine.core.utils.ssh.EngineSSHDialog; /** * Query to get Added Gluster Servers with/without server ssh key fingerprint diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GetGlusterServersForImportQuery.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GetGlusterServersForImportQuery.java index 40be00a..036dc7e 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GetGlusterServersForImportQuery.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GetGlusterServersForImportQuery.java @@ -5,11 +5,11 @@ import javax.naming.AuthenticationException; +import org.ovirt.engine.core.bll.utils.GlusterUtil; import org.ovirt.engine.core.common.errors.VdcBllMessages; import org.ovirt.engine.core.common.queries.gluster.GlusterServersQueryParameters; import org.ovirt.engine.core.dal.dbbroker.DbFacade; import org.ovirt.engine.core.dao.VdsStaticDAO; -import org.ovirt.engine.core.utils.gluster.GlusterUtil; /** * Query to fetch list of gluster servers via ssh using the given serverName and password. diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/utils/EngineSSHClient.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/utils/EngineSSHClient.java new file mode 100644 index 0000000..b532013 --- /dev/null +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/utils/EngineSSHClient.java @@ -0,0 +1,116 @@ +package org.ovirt.engine.core.bll.utils; + +import java.io.IOException; +import java.security.GeneralSecurityException; +import java.security.KeyPair; +import java.security.KeyStore; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import org.ovirt.engine.core.common.businessentities.VDS; +import org.ovirt.engine.core.common.config.Config; +import org.ovirt.engine.core.common.config.ConfigValues; +import org.ovirt.engine.core.dal.dbbroker.DbFacade; + +import org.ovirt.engine.core.utils.crypt.EngineEncryptionUtils; +import org.ovirt.engine.core.utils.crypt.OpenSSHUtils; +import org.ovirt.engine.core.utils.ssh.SSHClient; + +/** + * SSH client to be used with engine defaults + */ +public class EngineSSHClient extends SSHClient { + + private static final Log log = LogFactory.getLog(EngineSSHDialog.class); + private VDS _vds; + + /** + * Constructor. + */ + public EngineSSHClient() { + super(); + setHardTimeout( + Config.<Integer>GetValue( + ConfigValues.SSHInactivityHardTimoutSeconds + ) * 1000 + ); + setSoftTimeout( + Config.<Integer>GetValue( + ConfigValues.SSHInactivityTimoutSeconds + ) * 1000 + ); + } + + public void setVds(VDS vds) { + _vds = vds; + if (_vds != null) { + setHost(_vds.getHostName(), _vds.getSshPort()); + setUser(_vds.getSshUsername()); + } + } + + public VDS getVds() { + return _vds; + } + + @Override + public void connect() throws Exception { + super.connect(); + if (_vds != null) { + String actual = getHostFingerprint(); + String expected = _vds.getSshKeyFingerprint(); + + if (expected == null || expected.isEmpty()) { + _vds.setSshKeyFingerprint(getHostFingerprint()); + try { + DbFacade.getInstance().getVdsStaticDao().update(_vds.getStaticData()); + } catch (Exception e) { + throw new SecurityException( + String.format( + "Couldn't store fingerprint to db for host %s: %s", + _vds.getHostName(), + e + ) + ); + } + } else if (!actual.equals(expected)) { + throw new GeneralSecurityException( + String.format( + "Invalid fingerprint %s, expected %s", + actual, + expected + ) + ); + } + } + } + + /** + * Get host fingerprint. + * @return fingerprint. + */ + public String getHostFingerprint() throws IOException { + String fingerprint = OpenSSHUtils.getKeyFingerprintString(getHostKey()); + + if (fingerprint == null) { + throw new IOException("Unable to parse host key"); + } + + return fingerprint; + } + + /** + * Use default engine ssh key. + */ + public void useDefaultKeyPair() { + KeyStore.PrivateKeyEntry entry = EngineEncryptionUtils.getPrivateKeyEntry(); + + setKeyPair( + new KeyPair( + entry.getCertificate().getPublicKey(), + entry.getPrivateKey() + ) + ); + } +} diff --git a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ssh/EngineSSHDialog.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/utils/EngineSSHDialog.java similarity index 67% rename from backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ssh/EngineSSHDialog.java rename to backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/utils/EngineSSHDialog.java index 6fc740a..cef1f73 100644 --- a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ssh/EngineSSHDialog.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/utils/EngineSSHDialog.java @@ -1,4 +1,4 @@ -package org.ovirt.engine.core.utils.ssh; +package org.ovirt.engine.core.bll.utils; import java.io.IOException; import java.net.ConnectException; @@ -8,6 +8,9 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.ovirt.engine.core.utils.crypt.EngineEncryptionUtils; +import org.ovirt.engine.core.utils.ssh.SSHClient; +import org.ovirt.engine.core.utils.ssh.SSHDialog; +import org.ovirt.engine.core.common.businessentities.VDS; /** * SSH dialog to be used with engine defaults @@ -15,9 +18,21 @@ public class EngineSSHDialog extends SSHDialog { private static final Log log = LogFactory.getLog(EngineSSHDialog.class); + VDS _vds; protected SSHClient _getSSHClient() { - return new EngineSSHClient(); + EngineSSHClient client = new EngineSSHClient(); + client.setVds(_vds); + return client; + } + + /** + * Setting internal vds object + */ + public void setVds(VDS vds) throws Exception { + _vds = vds; + setHost(_vds.getHostName(), _vds.getSshPort()); + setUser(_vds.getSshUsername()); } /** diff --git a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/gluster/GlusterUtil.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/utils/GlusterUtil.java similarity index 94% rename from backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/gluster/GlusterUtil.java rename to backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/utils/GlusterUtil.java index 15da4a0..8ff91f1 100644 --- a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/gluster/GlusterUtil.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/utils/GlusterUtil.java @@ -1,4 +1,4 @@ -package org.ovirt.engine.core.utils.gluster; +package org.ovirt.engine.core.bll.utils; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -17,8 +17,6 @@ import org.ovirt.engine.core.utils.log.Log; import org.ovirt.engine.core.utils.log.LogFactory; import org.ovirt.engine.core.utils.ssh.ConstraintByteArrayOutputStream; -import org.ovirt.engine.core.utils.ssh.EngineSSHClient; -import org.ovirt.engine.core.utils.ssh.SSHClient; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; @@ -76,7 +74,7 @@ * The already connected and authenticated SSHClient object * @return Set of peers of the server */ - public Set<String> getPeers(SSHClient client) { + public Set<String> getPeers(EngineSSHClient client) { String serversXml = executePeerStatusCommand(client); return extractServers(serversXml); } @@ -134,7 +132,7 @@ } } - protected void authenticate(SSHClient client, String userId, String password) throws AuthenticationException { + protected void authenticate(EngineSSHClient client, String userId, String password) throws AuthenticationException { client.setUser(userId); client.setPassword(password); try { @@ -147,7 +145,7 @@ } } - protected String executePeerStatusCommand(SSHClient client) { + protected String executePeerStatusCommand(EngineSSHClient client) { ByteArrayOutputStream out = new ConstraintByteArrayOutputStream(500); String command = Config.<String> GetValue(ConfigValues.GlusterPeerStatusCommand); try { diff --git a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/AddVdsCommandTest.java b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/AddVdsCommandTest.java index c13d6a0..c245be8 100644 --- a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/AddVdsCommandTest.java +++ b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/AddVdsCommandTest.java @@ -18,6 +18,8 @@ import org.mockito.Mockito; import org.mockito.runners.MockitoJUnitRunner; import org.ovirt.engine.core.bll.utils.ClusterUtils; +import org.ovirt.engine.core.bll.utils.EngineSSHClient; +import org.ovirt.engine.core.bll.utils.GlusterUtil; import org.ovirt.engine.core.common.action.AddVdsActionParameters; import org.ovirt.engine.core.common.businessentities.VDS; import org.ovirt.engine.core.common.config.ConfigValues; @@ -28,10 +30,7 @@ import org.ovirt.engine.core.dao.VdsGroupDAO; import org.ovirt.engine.core.dao.gluster.GlusterDBUtils; import org.ovirt.engine.core.utils.MockConfigRule; -import org.ovirt.engine.core.utils.gluster.GlusterUtil; import org.ovirt.engine.core.utils.log.Log; -import org.ovirt.engine.core.utils.ssh.EngineSSHClient; -import org.ovirt.engine.core.utils.ssh.SSHClient; @RunWith(MockitoJUnitRunner.class) public class AddVdsCommandTest { @@ -116,7 +115,7 @@ doCallRealMethod().when(commandMock).addCanDoActionMessage(any(VdcBllMessages.class)); when(commandMock.getGlusterUtil()).thenReturn(glusterUtil); - when(glusterUtil.getPeers(any(SSHClient.class))).thenReturn(hasPeers ? Collections.singleton(PEER_1) + when(glusterUtil.getPeers(any(EngineSSHClient.class))).thenReturn(hasPeers ? Collections.singleton(PEER_1) : Collections.EMPTY_SET); when(commandMock.getGlusterDBUtils()).thenReturn(glusterDBUtils); @@ -142,7 +141,7 @@ @Test public void canDoActionSucceedsWhenHasPeersThrowsException() throws Exception { setupGlusterMock(true, new VDS(), true); - when(glusterUtil.getPeers(any(SSHClient.class))).thenThrow(new RuntimeException()); + when(glusterUtil.getPeers(any(EngineSSHClient.class))).thenThrow(new RuntimeException()); assertTrue(commandMock.canDoAction()); } diff --git a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/GetServerSSHKeyFingerprintQueryTest.java b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/GetServerSSHKeyFingerprintQueryTest.java index 7f5c769..cfee131 100644 --- a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/GetServerSSHKeyFingerprintQueryTest.java +++ b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/GetServerSSHKeyFingerprintQueryTest.java @@ -13,8 +13,8 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import org.ovirt.engine.core.bll.utils.EngineSSHDialog; import org.ovirt.engine.core.common.queries.ServerParameters; -import org.ovirt.engine.core.utils.ssh.EngineSSHDialog; public class GetServerSSHKeyFingerprintQueryTest extends AbstractQueryTest<ServerParameters, GetServerSSHKeyFingerprintQuery<ServerParameters>> { diff --git a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/gluster/GetAddedGlusterServersQueryTest.java b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/gluster/GetAddedGlusterServersQueryTest.java index 2b533e1..7bd68fa 100644 --- a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/gluster/GetAddedGlusterServersQueryTest.java +++ b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/gluster/GetAddedGlusterServersQueryTest.java @@ -19,6 +19,7 @@ import org.junit.Test; import org.ovirt.engine.core.bll.AbstractQueryTest; import org.ovirt.engine.core.bll.utils.ClusterUtils; +import org.ovirt.engine.core.bll.utils.EngineSSHDialog; import org.ovirt.engine.core.common.businessentities.VDS; import org.ovirt.engine.core.common.businessentities.VDSStatus; import org.ovirt.engine.core.common.businessentities.gluster.GlusterServerInfo; @@ -31,7 +32,6 @@ import org.ovirt.engine.core.compat.Guid; import org.ovirt.engine.core.dao.VdsDAO; import org.ovirt.engine.core.dao.gluster.GlusterDBUtils; -import org.ovirt.engine.core.utils.ssh.EngineSSHDialog; public class GetAddedGlusterServersQueryTest extends AbstractQueryTest<AddedGlusterServersParameters, GetAddedGlusterServersQuery<AddedGlusterServersParameters>> { private List<VDS> serversList; diff --git a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/gluster/GetGlusterServersForImportQueryTest.java b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/gluster/GetGlusterServersForImportQueryTest.java index 60afe7e..b5f41a4 100644 --- a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/gluster/GetGlusterServersForImportQueryTest.java +++ b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/gluster/GetGlusterServersForImportQueryTest.java @@ -16,12 +16,12 @@ import org.junit.Before; import org.junit.Test; import org.ovirt.engine.core.bll.AbstractQueryTest; +import org.ovirt.engine.core.bll.utils.GlusterUtil; import org.ovirt.engine.core.common.businessentities.VdsStatic; import org.ovirt.engine.core.common.errors.VdcBllMessages; import org.ovirt.engine.core.common.queries.gluster.GlusterServersQueryParameters; import org.ovirt.engine.core.compat.Guid; import org.ovirt.engine.core.dao.VdsStaticDAO; -import org.ovirt.engine.core.utils.gluster.GlusterUtil; public class GetGlusterServersForImportQueryTest extends AbstractQueryTest<GlusterServersQueryParameters, GetGlusterServersForImportQuery<GlusterServersQueryParameters>> { private static final String SERVER_NAME1 = "testserver1"; diff --git a/backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/gluster/GlusterUtilTest.java b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/utils/GlusterUtilTest.java similarity index 96% rename from backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/gluster/GlusterUtilTest.java rename to backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/utils/GlusterUtilTest.java index dabf60e..14f8ce1 100644 --- a/backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/gluster/GlusterUtilTest.java +++ b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/utils/GlusterUtilTest.java @@ -1,4 +1,4 @@ -package org.ovirt.engine.core.utils.gluster; +package org.ovirt.engine.core.bll.utils; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -19,7 +19,6 @@ import org.mockito.Mock; import org.mockito.Spy; import org.mockito.runners.MockitoJUnitRunner; -import org.ovirt.engine.core.utils.ssh.EngineSSHClient; @RunWith(MockitoJUnitRunner.class) public class GlusterUtilTest { diff --git a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/crypt/OpenSSHUtils.java b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/crypt/OpenSSHUtils.java index ee7d587..ff7cc6e 100644 --- a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/crypt/OpenSSHUtils.java +++ b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/crypt/OpenSSHUtils.java @@ -137,6 +137,11 @@ * @return an array of bytes containing the fingerprint of the key */ public static final byte[] getKeyFingerprintBytes(final PublicKey key) { + if (key == null) { + log.error("Public key is null, failed to retreive fingerprint."); + return null; + } + // Get the serialized version of the key: final byte[] keyBytes = getKeyBytes(key); if (keyBytes == null) { diff --git a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ssh/EngineSSHClient.java b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ssh/EngineSSHClient.java deleted file mode 100644 index 23d690f..0000000 --- a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ssh/EngineSSHClient.java +++ /dev/null @@ -1,67 +0,0 @@ -package org.ovirt.engine.core.utils.ssh; - -import java.io.IOException; -import java.security.KeyPair; -import java.security.KeyStore; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import org.ovirt.engine.core.common.config.Config; -import org.ovirt.engine.core.common.config.ConfigValues; - -import org.ovirt.engine.core.utils.crypt.EngineEncryptionUtils; -import org.ovirt.engine.core.utils.crypt.OpenSSHUtils; - -/** - * SSH client to be used with engine defaults - */ -public class EngineSSHClient extends SSHClient { - - private static final Log log = LogFactory.getLog(EngineSSHDialog.class); - - /** - * Constructor. - */ - public EngineSSHClient() { - super(); - setHardTimeout( - Config.<Integer>GetValue( - ConfigValues.SSHInactivityHardTimoutSeconds - ) * 1000 - ); - setSoftTimeout( - Config.<Integer>GetValue( - ConfigValues.SSHInactivityTimoutSeconds - ) * 1000 - ); - } - - /** - * Get host fingerprint. - * @return fingerprint. - */ - public String getHostFingerprint() throws IOException { - String fingerprint = OpenSSHUtils.getKeyFingerprintString(getHostKey()); - - if (fingerprint == null) { - throw new IOException("Unable to parse host key"); - } - - return fingerprint; - } - - /** - * Use default engine ssh key. - */ - public void useDefaultKeyPair() { - KeyStore.PrivateKeyEntry entry = EngineEncryptionUtils.getPrivateKeyEntry(); - - setKeyPair( - new KeyPair( - entry.getCertificate().getPublicKey(), - entry.getPrivateKey() - ) - ); - } -} -- To view, visit http://gerrit.ovirt.org/16687 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ie0ce892c90844bc157e9b2feaba6aeca8acad78d Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Yaniv Bronhaim <ybron...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches