http://git-wip-us.apache.org/repos/asf/airavata/blob/9a6eaaae/tools/gsissh/src/main/java/edu/illinois/ncsa/BCGSS/TlsHandlerUtil.java ---------------------------------------------------------------------- diff --git a/tools/gsissh/src/main/java/edu/illinois/ncsa/BCGSS/TlsHandlerUtil.java b/tools/gsissh/src/main/java/edu/illinois/ncsa/BCGSS/TlsHandlerUtil.java index da45965..36eec77 100644 --- a/tools/gsissh/src/main/java/edu/illinois/ncsa/BCGSS/TlsHandlerUtil.java +++ b/tools/gsissh/src/main/java/edu/illinois/ncsa/BCGSS/TlsHandlerUtil.java @@ -1,282 +1,282 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ - -package edu.illinois.ncsa.BCGSS; -import edu.illinois.ncsa.bouncycastle.crypto.tls.*; - -import java.io.*; - -public class TlsHandlerUtil { - private TlsProtocolHandler tlsHandler; - private TlsClient tlsClient; - private CircularByteBuffer netInStream; - private ByteArrayOutputStream netOutStream; - private boolean connectionThreadStarted = false; - private IOException connectionThreadException = null; - - /* - public TlsHandlerUtil(TlsClient client) { - this(client, new TlsProtocolVersion[] {TlsProtocolVersion.TLSv10, - TlsProtocolVersion.SSLv3}); - } - */ - - //public TlsHandlerUtil(TlsClient client, TlsProtocolVersion[] protocols) { - public TlsHandlerUtil(TlsClient client) { - this.tlsClient = client; - - this.netInStream = new CircularByteBuffer( - CircularByteBuffer.INFINITE_SIZE); - - //TODO: set a good initial size of buffer? - this.netOutStream = new ByteArrayOutputStream(); - - this.tlsHandler = new TlsProtocolHandler( - netInStream.getInputStream(), netOutStream); - //this.tlsHandler.setEnabledProtocols(protocols); - } - - /** - * - * @param inNetBuf - * @return - */ - public byte[] nextHandshakeToken(byte[] inNetBuf) throws IOException { - return nextHandshakeToken(inNetBuf, 0, inNetBuf.length); - } - - /** - * - * @param inNetBuf - * @param off - * @param len - * @return - * @throws java.io.IOException - */ - public byte[] nextHandshakeToken(byte[] inNetBuf, int off, int len) - throws IOException { - if (isHandshakeFinished()) { - return null; - } - - if (! isConnectionThreadStarted()) { - (new ConnectionThread()).start(); - } - - - if (tlsHandler.getHandshakeBlocking() > 0) { - tlsHandler.decHandshakeBlocking(inNetBuf.length); - } - - netInStream.getOutputStream().write(inNetBuf, off, len); - - // block until the TlsProtocolHandler's record stream blocks - // or until the handshake is finished. After either, a handshake - // token may have been produced - while (tlsHandler.getHandshakeBlocking() == 0 && - ! isHandshakeFinished()) { - - IOException e = getConnectionThreadException(); - if (e != null) { - throw new IOException("TLS connection thread exception", e); - } - - try { - Thread.sleep(25); - } catch (InterruptedException e1) { - throw new IOException("Handshake interrupted while waiting " + - "for new network data to be processed", e1); - } - } - - byte[] token = drainNetOutStream(); - - if (token.length > 0) { - return token; - } - - if (tlsHandler.getHandshakeBlocking() > 0) { - // no token produced; need more data - return null; - } - - if (isHandshakeFinished()) { - return null; - } else { - throw new IOException("No handshake data available, but the " + - "record stream is not blocking and wasn't interrupted"); - } - } - - /** - * - * @param appData - * @return - * @throws IOException - */ - public byte[] wrap(byte[] appData) throws IOException { - return wrap(appData, 0, appData.length); - } - - /** - * - * @param appData - * @param off - * @param len - * @return - * @throws IOException - */ - public byte[] wrap(byte[] appData, int off, int len) throws IOException { - if (! isHandshakeFinished()) { - return null; - } - - tlsHandler.getOutputStream().write(appData, off, len); - return drainNetOutStream(); - } - - /** - * - * @param netData - * @return - * @throws IOException - */ - public byte[] unwrap(byte[] netData) throws IOException { - return unwrap(netData, 0, netData.length); - } - - /** - * - * @param netData - * @param off - * @param len - * @return - * @throws IOException - */ - public byte[] unwrap(byte[] netData, int off, int len) throws IOException { - if (! isHandshakeFinished()) { - return null; - } - - if (netData.length == 0) { - return null; - } - - netInStream.getOutputStream().write(netData, off, len); - - // Force the record to be processed in order to put an unknown - // amount of data in the application queue. It's assumed that - // the netData parameter is a full SSL record; if it's not, then - // this method will block indefinitely - byte[] tmp = new byte[1]; - tlsHandler.getInputStream().read(tmp, 0, 1); - - int avail = tlsHandler.getApplicationDataQueueSize(); - - if (avail == 0) { - return tmp; - } - - byte[] appBuf = new byte[avail + 1]; - appBuf[0] = tmp[0]; - tlsHandler.getInputStream().read(appBuf, 1, avail); - - return appBuf; - } - - /** - * - * @return - * @throws java.io.IOException - */ - public byte[] close() throws IOException { - tlsHandler.close(); - return drainNetOutStream(); - } - - /** - * - * @return - */ - public boolean isHandshakeFinished() { - return this.tlsHandler.isHandshakeFinished(); - } - - /** - * - * @return - */ - private byte[] drainNetOutStream() { - byte[] rval = netOutStream.toByteArray(); - netOutStream.reset(); - return rval; - } - - /** - * - * @param b - */ - private synchronized void setConnectionThreadStarted(boolean b) { - connectionThreadStarted = b; - } - - /** - * - * @return - */ - private synchronized boolean isConnectionThreadStarted() { - return connectionThreadStarted; - } - - /** - * - * @return - */ - private IOException getConnectionThreadException() { - return connectionThreadException; - } - - /** - * - * @param e - */ - private void setConnectionThreadException(IOException e) { - this.connectionThreadException = e; - } - - /** - * - */ - private class ConnectionThread extends Thread { - /** - * - */ - public void run() { - setConnectionThreadStarted(true); - try { - tlsHandler.connect(tlsClient); - } catch (IOException e) { - setConnectionThreadException(e); - } - //System.out.println("TLS connection thread done"); - } - } -} +///* +// * +// * Licensed to the Apache Software Foundation (ASF) under one +// * or more contributor license agreements. See the NOTICE file +// * distributed with this work for additional information +// * regarding copyright ownership. The ASF licenses this file +// * to you under the Apache License, Version 2.0 (the +// * "License"); you may not use this file except in compliance +// * with the License. You may obtain a copy of the License at +// * +// * http://www.apache.org/licenses/LICENSE-2.0 +// * +// * Unless required by applicable law or agreed to in writing, +// * software distributed under the License is distributed on an +// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// * KIND, either express or implied. See the License for the +// * specific language governing permissions and limitations +// * under the License. +// * +// */ +// +//package edu.illinois.ncsa.BCGSS; +////import edu.illinois.ncsa.bouncycastle.crypto.tls.*; +// +//import java.io.*; +// +//public class TlsHandlerUtil { +// private TlsProtocolHandler tlsHandler; +// private TlsClient tlsClient; +// private CircularByteBuffer netInStream; +// private ByteArrayOutputStream netOutStream; +// private boolean connectionThreadStarted = false; +// private IOException connectionThreadException = null; +// +// /* +// public TlsHandlerUtil(TlsClient client) { +// this(client, new TlsProtocolVersion[] {TlsProtocolVersion.TLSv10, +// TlsProtocolVersion.SSLv3}); +// } +// */ +// +// //public TlsHandlerUtil(TlsClient client, TlsProtocolVersion[] protocols) { +// public TlsHandlerUtil(TlsClient client) { +// this.tlsClient = client; +// +// this.netInStream = new CircularByteBuffer( +// CircularByteBuffer.INFINITE_SIZE); +// +// //TODO: set a good initial size of buffer? +// this.netOutStream = new ByteArrayOutputStream(); +// +// this.tlsHandler = new TlsProtocolHandler( +// netInStream.getInputStream(), netOutStream); +// //this.tlsHandler.setEnabledProtocols(protocols); +// } +// +// /** +// * +// * @param inNetBuf +// * @return +// */ +// public byte[] nextHandshakeToken(byte[] inNetBuf) throws IOException { +// return nextHandshakeToken(inNetBuf, 0, inNetBuf.length); +// } +// +// /** +// * +// * @param inNetBuf +// * @param off +// * @param len +// * @return +// * @throws java.io.IOException +// */ +// public byte[] nextHandshakeToken(byte[] inNetBuf, int off, int len) +// throws IOException { +// if (isHandshakeFinished()) { +// return null; +// } +// +// if (! isConnectionThreadStarted()) { +// (new ConnectionThread()).start(); +// } +// +// +// if (tlsHandler.getHandshakeBlocking() > 0) { +// tlsHandler.decHandshakeBlocking(inNetBuf.length); +// } +// +// netInStream.getOutputStream().write(inNetBuf, off, len); +// +// // block until the TlsProtocolHandler's record stream blocks +// // or until the handshake is finished. After either, a handshake +// // token may have been produced +// while (tlsHandler.getHandshakeBlocking() == 0 && +// ! isHandshakeFinished()) { +// +// IOException e = getConnectionThreadException(); +// if (e != null) { +// throw new IOException("TLS connection thread exception", e); +// } +// +// try { +// Thread.sleep(25); +// } catch (InterruptedException e1) { +// throw new IOException("Handshake interrupted while waiting " + +// "for new network data to be processed", e1); +// } +// } +// +// byte[] token = drainNetOutStream(); +// +// if (token.length > 0) { +// return token; +// } +// +// if (tlsHandler.getHandshakeBlocking() > 0) { +// // no token produced; need more data +// return null; +// } +// +// if (isHandshakeFinished()) { +// return null; +// } else { +// throw new IOException("No handshake data available, but the " + +// "record stream is not blocking and wasn't interrupted"); +// } +// } +// +// /** +// * +// * @param appData +// * @return +// * @throws IOException +// */ +// public byte[] wrap(byte[] appData) throws IOException { +// return wrap(appData, 0, appData.length); +// } +// +// /** +// * +// * @param appData +// * @param off +// * @param len +// * @return +// * @throws IOException +// */ +// public byte[] wrap(byte[] appData, int off, int len) throws IOException { +// if (! isHandshakeFinished()) { +// return null; +// } +// +// tlsHandler.getOutputStream().write(appData, off, len); +// return drainNetOutStream(); +// } +// +// /** +// * +// * @param netData +// * @return +// * @throws IOException +// */ +// public byte[] unwrap(byte[] netData) throws IOException { +// return unwrap(netData, 0, netData.length); +// } +// +// /** +// * +// * @param netData +// * @param off +// * @param len +// * @return +// * @throws IOException +// */ +// public byte[] unwrap(byte[] netData, int off, int len) throws IOException { +// if (! isHandshakeFinished()) { +// return null; +// } +// +// if (netData.length == 0) { +// return null; +// } +// +// netInStream.getOutputStream().write(netData, off, len); +// +// // Force the record to be processed in order to put an unknown +// // amount of data in the application queue. It's assumed that +// // the netData parameter is a full SSL record; if it's not, then +// // this method will block indefinitely +// byte[] tmp = new byte[1]; +// tlsHandler.getInputStream().read(tmp, 0, 1); +// +// int avail = tlsHandler.getApplicationDataQueueSize(); +// +// if (avail == 0) { +// return tmp; +// } +// +// byte[] appBuf = new byte[avail + 1]; +// appBuf[0] = tmp[0]; +// tlsHandler.getInputStream().read(appBuf, 1, avail); +// +// return appBuf; +// } +// +// /** +// * +// * @return +// * @throws java.io.IOException +// */ +// public byte[] close() throws IOException { +// tlsHandler.close(); +// return drainNetOutStream(); +// } +// +// /** +// * +// * @return +// */ +// public boolean isHandshakeFinished() { +// return this.tlsHandler.isHandshakeFinished(); +// } +// +// /** +// * +// * @return +// */ +// private byte[] drainNetOutStream() { +// byte[] rval = netOutStream.toByteArray(); +// netOutStream.reset(); +// return rval; +// } +// +// /** +// * +// * @param b +// */ +// private synchronized void setConnectionThreadStarted(boolean b) { +// connectionThreadStarted = b; +// } +// +// /** +// * +// * @return +// */ +// private synchronized boolean isConnectionThreadStarted() { +// return connectionThreadStarted; +// } +// +// /** +// * +// * @return +// */ +// private IOException getConnectionThreadException() { +// return connectionThreadException; +// } +// +// /** +// * +// * @param e +// */ +// private void setConnectionThreadException(IOException e) { +// this.connectionThreadException = e; +// } +// +// /** +// * +// */ +// private class ConnectionThread extends Thread { +// /** +// * +// */ +// public void run() { +// setConnectionThreadStarted(true); +// try { +// tlsHandler.connect(tlsClient); +// } catch (IOException e) { +// setConnectionThreadException(e); +// } +// //System.out.println("TLS connection thread done"); +// } +// } +//}
http://git-wip-us.apache.org/repos/asf/airavata/blob/9a6eaaae/tools/gsissh/src/main/java/org/apache/airavata/gsi/ssh/GSSContextX509.java ---------------------------------------------------------------------- diff --git a/tools/gsissh/src/main/java/org/apache/airavata/gsi/ssh/GSSContextX509.java b/tools/gsissh/src/main/java/org/apache/airavata/gsi/ssh/GSSContextX509.java index e0fc007..2eb70c6 100644 --- a/tools/gsissh/src/main/java/org/apache/airavata/gsi/ssh/GSSContextX509.java +++ b/tools/gsissh/src/main/java/org/apache/airavata/gsi/ssh/GSSContextX509.java @@ -27,24 +27,24 @@ import java.io.FileInputStream; import java.net.InetAddress; import java.net.UnknownHostException; -import edu.illinois.ncsa.BCGSS.BCGSSContextImpl; import org.globus.common.CoGProperties; import org.globus.gsi.GSIConstants; import org.globus.gsi.gssapi.GSSConstants; -import org.globus.gsi.gssapi.GlobusGSSContextImpl; import org.globus.gsi.gssapi.GlobusGSSCredentialImpl; import org.globus.gsi.gssapi.auth.HostAuthorization; -import org.globus.myproxy.MyProxy; -import org.globus.myproxy.MyProxyException; import org.gridforum.jgss.ExtendedGSSContext; import org.gridforum.jgss.ExtendedGSSCredential; import org.gridforum.jgss.ExtendedGSSManager; -import org.ietf.jgss.*; - -import com.jcraft.jsch.JSchException; +import org.ietf.jgss.GSSContext; +import org.ietf.jgss.GSSCredential; +import org.ietf.jgss.GSSException; +import org.ietf.jgss.GSSName; +import org.ietf.jgss.MessageProp; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.jcraft.jsch.JSchException; + /** * This class is based on GSSContextKrb5; it substitutes the globus * ExtendedGSSManager and uses the SecurityUtils method to get the credential if @@ -102,15 +102,15 @@ public class GSSContextX509 implements com.jcraft.jsch.GSSContext { // context.requestCredDeleg(true); // context.requestAnonymity(false); - context = new BCGSSContextImpl(name, (GlobusGSSCredentialImpl) credential); - context.requestLifetime(GSSCredential.DEFAULT_LIFETIME); - context.requestCredDeleg(true); - context.requestMutualAuth(true); - context.requestReplayDet(true); - context.requestSequenceDet(true); - context.requestConf(false); - context.requestInteg(true); - ((ExtendedGSSContext)context).setOption(GSSConstants.DELEGATION_TYPE, GSIConstants.DELEGATION_TYPE_FULL); +// context = new BCGSSContextImpl(name, (GlobusGSSCredentialImpl) credential); +// context.requestLifetime(GSSCredential.DEFAULT_LIFETIME); +// context.requestCredDeleg(true); +// context.requestMutualAuth(true); +// context.requestReplayDet(true); +// context.requestSequenceDet(true); +// context.requestConf(false); +// context.requestInteg(true); +// ((ExtendedGSSContext)context).setOption(GSSConstants.DELEGATION_TYPE, GSIConstants.DELEGATION_TYPE_FULL); return; } catch (GSSException ex) { http://git-wip-us.apache.org/repos/asf/airavata/blob/9a6eaaae/tools/gsissh/src/main/java/org/apache/airavata/gsi/ssh/impl/GSISSHAbstractCluster.java ---------------------------------------------------------------------- diff --git a/tools/gsissh/src/main/java/org/apache/airavata/gsi/ssh/impl/GSISSHAbstractCluster.java b/tools/gsissh/src/main/java/org/apache/airavata/gsi/ssh/impl/GSISSHAbstractCluster.java index 5e966bc..f6f3247 100644 --- a/tools/gsissh/src/main/java/org/apache/airavata/gsi/ssh/impl/GSISSHAbstractCluster.java +++ b/tools/gsissh/src/main/java/org/apache/airavata/gsi/ssh/impl/GSISSHAbstractCluster.java @@ -20,10 +20,36 @@ */ package org.apache.airavata.gsi.ssh.impl; -import com.jcraft.jsch.*; +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.StringWriter; +import java.net.URL; +import java.security.SecureRandom; +import java.util.HashMap; +import java.util.List; +import java.util.Map; -import org.apache.airavata.gsi.ssh.api.*; -import org.apache.airavata.gsi.ssh.api.authentication.*; +import javax.xml.transform.Source; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerConfigurationException; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.stream.StreamResult; +import javax.xml.transform.stream.StreamSource; + +import org.apache.airavata.gsi.ssh.api.Cluster; +import org.apache.airavata.gsi.ssh.api.CommandExecutor; +import org.apache.airavata.gsi.ssh.api.SSHApiException; +import org.apache.airavata.gsi.ssh.api.ServerInfo; +import org.apache.airavata.gsi.ssh.api.authentication.AuthenticationInfo; +import org.apache.airavata.gsi.ssh.api.authentication.GSIAuthenticationInfo; +import org.apache.airavata.gsi.ssh.api.authentication.SSHKeyAuthentication; +import org.apache.airavata.gsi.ssh.api.authentication.SSHPasswordAuthentication; +import org.apache.airavata.gsi.ssh.api.authentication.SSHPublicKeyAuthentication; +import org.apache.airavata.gsi.ssh.api.authentication.SSHPublicKeyFileAuthentication; import org.apache.airavata.gsi.ssh.api.job.JobDescriptor; import org.apache.airavata.gsi.ssh.api.job.JobManagerConfiguration; import org.apache.airavata.gsi.ssh.api.job.OutputParser; @@ -37,25 +63,15 @@ import org.apache.commons.io.FileUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.xml.transform.*; -import javax.xml.transform.stream.StreamResult; -import javax.xml.transform.stream.StreamSource; - -import java.io.ByteArrayInputStream; -import java.io.File; -import java.io.IOException; -import java.io.StringWriter; -import java.net.URL; -import java.security.SecureRandom; -import java.util.List; -import java.util.Map; +import com.jcraft.jsch.ExtendedSession; +import com.jcraft.jsch.GSISSHIdentityFile; +import com.jcraft.jsch.GSISSHIdentityRepository; +import com.jcraft.jsch.Identity; +import com.jcraft.jsch.JSch; +import com.jcraft.jsch.JSchException; +import com.jcraft.jsch.Session; public class GSISSHAbstractCluster implements Cluster { - static { - JSch.setConfig("gssapi-with-mic.x509", "org.apache.airavata.gsi.ssh.GSSContextX509"); - JSch.setConfig("userauth.gssapi-with-mic", "com.jcraft.jsch.UserAuthGSSAPIWithMICGSSCredentials"); - - } private static final Logger log = LoggerFactory.getLogger(GSISSHAbstractCluster.class); public static final String X509_CERT_DIR = "X509_CERT_DIR"; @@ -70,7 +86,10 @@ public class GSISSHAbstractCluster implements Cluster { private Session session; private ConfigReader configReader; + + private JSch defaultJSch; + private static Identity identityFile = null; public GSISSHAbstractCluster(ServerInfo serverInfo, AuthenticationInfo authenticationInfo, JobManagerConfiguration config) throws SSHApiException { this(serverInfo, authenticationInfo); @@ -88,6 +107,8 @@ public class GSISSHAbstractCluster implements Cluster { this.authenticationInfo = authenticationInfo; if (authenticationInfo instanceof GSIAuthenticationInfo) { + JSch.setConfig("gssapi-with-mic.x509", "org.apache.airavata.gsi.ssh.GSSContextX509"); + JSch.setConfig("userauth.gssapi-with-mic", "com.jcraft.jsch.UserAuthGSSAPIWithMICGSSCredentials"); System.setProperty(X509_CERT_DIR, (String) ((GSIAuthenticationInfo) authenticationInfo).getProperties(). get("X509_CERT_DIR")); } @@ -98,25 +119,22 @@ public class GSISSHAbstractCluster implements Cluster { } catch (IOException e) { throw new SSHApiException("Unable to load system configurations.", e); } - JSch jSch = new ExtendedJSch(); - - log.debug("Connecting to server - " + serverInfo.getHost() + ":" + serverInfo.getPort() + " with user name - " - + serverInfo.getUserName()); - try { - session = jSch.getSession(serverInfo.getUserName(), serverInfo.getHost(), serverInfo.getPort()); - session.setTimeout(Integer.parseInt(configReader.getConfiguration(SSH_SESSION_TIMEOUT))); - } catch (Exception e) { + if(defaultJSch == null){ + defaultJSch = createJSch(authenticationInfo); + } + log.debug("Connecting to server - " + serverInfo.getHost() + ":" + serverInfo.getPort() + " with user name - " + + serverInfo.getUserName()); + + session = createSession(defaultJSch,serverInfo.getUserName(), serverInfo.getHost(), serverInfo.getPort()); + } + catch (Exception e) { throw new SSHApiException("An exception occurred while creating SSH session." + "Connecting server - " + serverInfo.getHost() + ":" + serverInfo.getPort() + " connecting user name - " + serverInfo.getUserName(), e); } - java.util.Properties config = this.configReader.getProperties(); - session.setConfig(config); - - //============================================================= // Handling vanilla SSH pieces //============================================================= @@ -143,10 +161,8 @@ public class GSISSHAbstractCluster implements Cluster { logDebug("The public key file for vanilla SSH " + publicKeyFile); - Identity identityFile; - try { - identityFile = GSISSHIdentityFile.newInstance(privateKeyFile, null, jSch); + identityFile = GSISSHIdentityFile.newInstance(privateKeyFile, null, defaultJSch); } catch (JSchException e) { throw new SSHApiException("An exception occurred while initializing keys using files. " + "(private key and public key)." + @@ -157,7 +173,7 @@ public class GSISSHAbstractCluster implements Cluster { } // Add identity to identity repository - GSISSHIdentityRepository identityRepository = new GSISSHIdentityRepository(jSch); + GSISSHIdentityRepository identityRepository = new GSISSHIdentityRepository(defaultJSch); identityRepository.add(identityFile); // Set repository to session @@ -173,14 +189,11 @@ public class GSISSHAbstractCluster implements Cluster { SSHPublicKeyAuthentication sshPublicKeyAuthentication = (SSHPublicKeyAuthentication) authenticationInfo; - - Identity identityFile; - try { String name = serverInfo.getUserName() + "_" + serverInfo.getHost(); identityFile = GSISSHIdentityFile.newInstance(name, sshPublicKeyAuthentication.getPrivateKey(serverInfo.getUserName(), serverInfo.getHost()), - sshPublicKeyAuthentication.getPublicKey(serverInfo.getUserName(), serverInfo.getHost()), jSch); + sshPublicKeyAuthentication.getPublicKey(serverInfo.getUserName(), serverInfo.getHost()), defaultJSch); } catch (JSchException e) { throw new SSHApiException("An exception occurred while initializing keys using byte arrays. " + "(private key and public key)." + @@ -190,7 +203,7 @@ public class GSISSHAbstractCluster implements Cluster { } // Add identity to identity repository - GSISSHIdentityRepository identityRepository = new GSISSHIdentityRepository(jSch); + GSISSHIdentityRepository identityRepository = new GSISSHIdentityRepository(defaultJSch); identityRepository.add(identityFile); // Set repository to session @@ -212,7 +225,7 @@ public class GSISSHAbstractCluster implements Cluster { } try { - session.connect(); + session.connect(Integer.parseInt(configReader.getConfiguration(SSH_SESSION_TIMEOUT))); } catch (Exception e) { throw new SSHApiException("An exception occurred while connecting to server." + "Connecting server - " + serverInfo.getHost() + ":" + serverInfo.getPort() + @@ -620,6 +633,70 @@ public class GSISSHAbstractCluster implements Cluster { } public void disconnect() throws SSHApiException { -// getSession().disconnect(); + if(getSession().isConnected()){ + getSession().disconnect(); + } } + /** + + * the file system abstraction which will be necessary to + * perform certain file system operations. + * @return the new default JSch implementation. + * @throws JSchException + * known host keys cannot be loaded. + */ + protected JSch createJSch(AuthenticationInfo authenticationInfo) throws JSchException { +// final File fs = new File(System.getProperty("user.home")); + if(authenticationInfo instanceof GSIAuthenticationInfo){ + final JSch jsch = new ExtendedJSch(); +// knownHosts(jsch, fs); + return jsch; + }else{ + final JSch jsch = new JSch(); +// knownHosts(jsch, fs); + return jsch; + } + + } + /** + * Create a new remote session for the requested address. + * + * @param user + * login to authenticate as. + * @param host + * server name to connect to. + * @param port + * port number of the SSH daemon (typically 22). + * @return new session instance, but otherwise unconfigured. + * @throws JSchException + * the session could not be created. + */ + private Session createSession(JSch jsch, String user, String host, int port) throws JSchException { + final Session session = jsch.getSession(user, host, port); + // We retry already in getSession() method. JSch must not retry + // on its own. + session.setConfig("MaxAuthTries", "1"); //$NON-NLS-1$ //$NON-NLS-2$ + session.setTimeout(Integer.parseInt(configReader.getConfiguration(SSH_SESSION_TIMEOUT))); + java.util.Properties config = this.configReader.getProperties(); + session.setConfig(config); + + return session; + } + private static void knownHosts(final JSch sch,final File home) throws JSchException { + if (home == null) + return; + final File known_hosts = new File(new File(home, ".ssh"), "known_hosts"); //$NON-NLS-1$ //$NON-NLS-2$ + try { + final FileInputStream in = new FileInputStream(known_hosts); + try { + sch.setKnownHosts(in); + } finally { + in.close(); + } + } catch (FileNotFoundException none) { + // Oh well. They don't have a known hosts in home. + } catch (IOException err) { + // Oh well. They don't have a known hosts in home. + } + } } http://git-wip-us.apache.org/repos/asf/airavata/blob/9a6eaaae/tools/gsissh/src/main/java/org/apache/airavata/gsi/ssh/util/SSHUtils.java ---------------------------------------------------------------------- diff --git a/tools/gsissh/src/main/java/org/apache/airavata/gsi/ssh/util/SSHUtils.java b/tools/gsissh/src/main/java/org/apache/airavata/gsi/ssh/util/SSHUtils.java index d4af5d4..1741833 100644 --- a/tools/gsissh/src/main/java/org/apache/airavata/gsi/ssh/util/SSHUtils.java +++ b/tools/gsissh/src/main/java/org/apache/airavata/gsi/ssh/util/SSHUtils.java @@ -97,7 +97,7 @@ public class SSHUtils { if (new File(lFile).isDirectory()) { prefix = lFile + File.separator; } - JSch jsch = new ExtendedJSch(); + JSch jsch = new JSch(); log.debug("Connecting to server - " + serverInfo.getHost() + ":" + serverInfo.getPort() + " with user name - " + serverInfo.getUserName()); @@ -442,7 +442,7 @@ public class SSHUtils { * @param localFile This is the local file to copy, this can be a directory too */ public void scpFrom(String remoteFile, String localFile) throws SSHApiException { - JSch jsch = new ExtendedJSch(); + JSch jsch = new JSch(); log.debug("Connecting to server - " + serverInfo.getHost() + ":" + serverInfo.getPort() + " with user name - " + serverInfo.getUserName()); http://git-wip-us.apache.org/repos/asf/airavata/blob/9a6eaaae/tools/gsissh/src/test/java/org/apache/airavata/gsi/ssh/impl/DefaultSSHApiTestWithMyProxyAuth.java ---------------------------------------------------------------------- diff --git a/tools/gsissh/src/test/java/org/apache/airavata/gsi/ssh/impl/DefaultSSHApiTestWithMyProxyAuth.java b/tools/gsissh/src/test/java/org/apache/airavata/gsi/ssh/impl/DefaultSSHApiTestWithMyProxyAuth.java index f53f29b..5a12723 100644 --- a/tools/gsissh/src/test/java/org/apache/airavata/gsi/ssh/impl/DefaultSSHApiTestWithMyProxyAuth.java +++ b/tools/gsissh/src/test/java/org/apache/airavata/gsi/ssh/impl/DefaultSSHApiTestWithMyProxyAuth.java @@ -49,9 +49,9 @@ public class DefaultSSHApiTestWithMyProxyAuth { public static void main(String[]ars){ - String myProxyUserName = "us3"; - String myProxyPassword = "Cme4UScan"; - String certificateLocation = "/Users/smarru/deploy/certificates"; + String myProxyUserName = "ogce"; + String myProxyPassword = "OGCE@xsede14"; + String certificateLocation = "/Users/raminder/.globus/certificates"; GSIAuthenticationInfo authenticationInfo @@ -62,8 +62,13 @@ public class DefaultSSHApiTestWithMyProxyAuth { CommandInfo commandInfo = new RawCommandInfo("/bin/ls"); // Server info - ServerInfo serverInfo = new ServerInfo("us3", "stampede.tacc.utexas.edu", 2222); - + //Stampede +// ServerInfo serverInfo = new ServerInfo(myProxyUserName, "stampede.tacc.utexas.edu", 2222); + //Trestles +// ServerInfo serverInfo = new ServerInfo(myProxyUserName, "trestles.sdsc.xsede.org", 22); + + //Lonestar + ServerInfo serverInfo = new ServerInfo(myProxyUserName, "lonestar.tacc.utexas.edu", 22); // Output CommandOutput commandOutput = new SystemCommandOutput(); http://git-wip-us.apache.org/repos/asf/airavata/blob/9a6eaaae/tools/gsissh/src/test/java/org/apache/airavata/gsi/ssh/impl/VanilaTestWithSSHAuth.java ---------------------------------------------------------------------- diff --git a/tools/gsissh/src/test/java/org/apache/airavata/gsi/ssh/impl/VanilaTestWithSSHAuth.java b/tools/gsissh/src/test/java/org/apache/airavata/gsi/ssh/impl/VanilaTestWithSSHAuth.java index dfbaef0..7437419 100644 --- a/tools/gsissh/src/test/java/org/apache/airavata/gsi/ssh/impl/VanilaTestWithSSHAuth.java +++ b/tools/gsissh/src/test/java/org/apache/airavata/gsi/ssh/impl/VanilaTestWithSSHAuth.java @@ -47,21 +47,45 @@ public class VanilaTestWithSSHAuth { private String workingDirectory; private String privateKeyPath; private String publicKeyPath; + private String path; @BeforeTest public void setUp() throws Exception { System.out.println("Test case name " + this.getClass().getName()); - this.hostName = "bigred2.uits.iu.edu"; //default ssh host -// System.setProperty("ssh.user", "lginnali"); -// System.setProperty("ssh.private.key.path", "/Users/lahirugunathilake/.ssh/id_dsa"); -// System.setProperty("ssh.public.key.path", "/Users/lahirugunathilake/.ssh/id_dsa.pub"); -// System.setProperty("ssh.working.directory", "/tmp"); + //Trestles + this.hostName = "trestles.sdsc.xsede.org"; + this.userName = "ogce"; + this.path="/opt/torque/bin/"; + //Stampede: +// this.hostName = "stampede.tacc.xsede.org"; +// this.userName = "ogce"; +// this.path="/usr/bin"; + //Lonestar: +// this.hostName = "lonestar.tacc.utexas.edu"; +// this.userName = "us3"; +// this.path="/opt/sge6.2/bin/lx24-amd64"; + //Alamo: +// this.hostName = "alamo.uthscsa.edu"; +// this.userName = "raminder"; +// this.path="/opt/torque/bin/"; + //Bigred: +// this.hostName = "bigred2.uits.iu.edu"; +// this.userName = "cgateway"; +// this.path="/opt/torque/torque-5.0.1/bin/"; + + System.setProperty("ssh.host",hostName); + System.setProperty("ssh.username", userName); + System.setProperty("private.ssh.key", "/home/user/.ssh/id_dsa"); + System.setProperty("public.ssh.key", "/home/user/.ssh/id_dsa.pub"); + System.setProperty("ssh.working.directory", "/tmp"); this.hostName = System.getProperty("ssh.host"); this.userName = System.getProperty("ssh.username"); this.password = System.getProperty("ssh.password"); this.privateKeyPath = System.getProperty("private.ssh.key"); this.publicKeyPath = System.getProperty("public.ssh.key"); + + System.setProperty("ssh.keypass", ""); this.passPhrase = System.getProperty("ssh.keypass"); this.workingDirectory = System.getProperty("ssh.working.directory"); @@ -87,13 +111,13 @@ public class VanilaTestWithSSHAuth { } // Server info ServerInfo serverInfo = new ServerInfo(this.userName, this.hostName); - Cluster pbsCluster = new PBSCluster(serverInfo, authenticationInfo, CommonUtils.getPBSJobManager("/opt/torque/torque-4.2.3.1/bin/")); + Cluster pbsCluster = new PBSCluster(serverInfo, authenticationInfo, CommonUtils.getPBSJobManager(path)); String date = new Date().toString(); date = date.replaceAll(" ", "_"); date = date.replaceAll(":", "_"); - String pomFile = System.getProperty("basedir") + File.separator + "pom.xml"; + String pomFile = new File("").getAbsolutePath() + File.separator + "pom.xml"; workingDirectory = workingDirectory + File.separator + date + "_" + UUID.randomUUID(); @@ -124,12 +148,13 @@ public class VanilaTestWithSSHAuth { jobDescriptor.setProcessesPerNode(1); jobDescriptor.setQueueName("normal"); jobDescriptor.setMaxWallTime("5"); - jobDescriptor.setJobSubmitter("aprun -n 1"); + //jobDescriptor.setJobSubmitter("aprun -n 1"); List<String> inputs = new ArrayList<String>(); inputs.add(remoteLocation + File.separator + fileName); jobDescriptor.setInputValues(inputs); //finished construction of job object System.out.println(jobDescriptor.toXML()); + if(hostName.contains("trestles")){ String jobID = pbsCluster.submitBatchJob(jobDescriptor); System.out.println("JobID returned : " + jobID); @@ -156,6 +181,7 @@ public class VanilaTestWithSSHAuth { System.out.println(jobById.getUsedCPUTime()); System.out.println(jobById.getUsedMemory()); System.out.println(jobById.getVariableList()); + } } @Test @@ -170,7 +196,7 @@ public class VanilaTestWithSSHAuth { } // Server info ServerInfo serverInfo = new ServerInfo(this.userName, this.hostName); - Cluster pbsCluster = new PBSCluster(serverInfo, authenticationInfo, CommonUtils.getPBSJobManager("/opt/torque/torque-4.2.3.1/bin/")); + Cluster pbsCluster = new PBSCluster(serverInfo, authenticationInfo, CommonUtils.getPBSJobManager(path)); String date = new Date().toString(); date = date.replaceAll(" ", "_"); @@ -190,6 +216,4 @@ public class VanilaTestWithSSHAuth { Thread.sleep(1000); pbsCluster.scpFrom(workingDirectory + File.separator + "pom.xml", (new File(".")).getAbsolutePath()); } - - }
