Examples of SshKey


Examples of com.alu.e3.data.model.SSHKey

  // only the first key registered is ever used.  If there are no credentials
  // or different credentials, an error is logged.
  protected boolean verifyCredentials(Instance instance) {
    boolean hasConsistentCredentials = true;
   
    SSHKey instKey = instance.getSSHKey();
    if (instKey != null) {
      if (this.key == null) {
        this.key = instKey;
        if (!writeKeyFile()) {
          this.key = null;
          return false;
        }
        return true;
     
      if (!instKey.isSameKey(this.key)) {
        hasConsistentCredentials = false;
        logger.warn("Instance " + instance.getName() + " (" + instance.getInternalIP() +
          ") uses a different key than another " + E3Constant.TDR_COLLECTOR + " instance!");
      }
    } else {
View Full Code Here

Examples of com.alu.e3.data.model.SSHKey

              if (!CommonTools.isLocal(localizedGatewayIP))
              {
                /* Get the ssh key. TODO: handle case without sshkey (eg. if user/password provided) */
                // return manager can not be null
                Instance manager = Utilities.getManagerByIP(CommonTools.getLocalHostname(), CommonTools.getLocalAddress(),  topology.getInstancesByType(E3Constant.E3MANAGER), logger);
                SSHKey key = manager.getSSHKey();
                if (key != null) {
                  if(logger.isDebugEnabled()) {
                    logger.debug("using key: " + key.getName());
                  }
                }
               
                /* Connect via ssh. */
                SSHCommand sshCommand = (SSHCommand) cmd;
                sshCommand.connect(key, localizedGatewayIP, 22, instance.getUser(), instance.getPassword());
               
                if (!sshCommand.isConnected())
                {
                  String errorSshMsg = "Error: ssh connection to " + localizedGatewayIP+  " failed (sshkey=";
                  errorSshMsg += (key == null) ? "not defined " : key.getName();
                  errorSshMsg += "user=" + instance.getUser() + ")";
                  throw new InstallerDeployException(errorSshMsg);
                }
               
                if(logger.isDebugEnabled()) {
                  logger.debug("command type: " + cmd.getImplementationType());
                }
               
                /* check if the destination directory already exists. */
                ShellCommandResult dirExistResult = cmd.execShellCommand("ls "+ config.getRemotePath() + "/bin/install.sh");
                if (dirExistResult.getExitStatus() != 0)
                {
                  /* Create the destination directory */
                  ShellCommandResult dirCreateResult = cmd.execShellCommand("mkdir -p -m 755 "+ config.getRemotePath());
                  if (dirCreateResult.getExitStatus() != 0)
                  {
                    throw new InstallerDeployException("Unable to create remote destination directory "+ config.getRemotePath() + ".");
                  }
               
                  /* Remote copy the package. */
                  if(logger.isDebugEnabled()) {
                    logger.debug("package url: " + config.getPackageUrl());
                  }
                  URL urlPackage = new URL(config.getPackageUrl());
                  String strFilename;
                  if (urlPackage.getProtocol().equals("file"))
                  {
                    strFilename = new File(urlPackage.getFile()).getName();
                    cmd.copy(urlPackage.getFile(), config.getRemotePath() + "/" + strFilename);
                   
                  } else {
                    /* TODO: handle HTTP package URL ? */
                    if(logger.isDebugEnabled()) {
                      logger.debug("URL type " + urlPackage.getProtocol() + " is not supported yet.");
                    }
                    continue;
                  }
               
                  /* Unzip TODO: instaler filename and install location in config */
                  ShellCommandResult cmdRes = cmd.execShellCommand("tar xfz " + strFilename, config.getRemotePath());
                  if (cmdRes.getExitStatus() != 0)
                  {
                    /* unzip has failed, display output. TODO: handle failure */
                    throw new InstallerDeployException("Unzip archive" + strFilename + " failed (returned code: "+ cmdRes + ")");
                  }
                } else{
                  // version already installed in the gateway                 
                  if(logger.isErrorEnabled()) {
                    logger.error("WARNING: " + config.getRemotePath() + " already exist on gateway " + localizedGatewayIP);
                  }
                 
                  report.append("WARNING: " + config.getRemotePath() + " already exist on gateway " + localizedGatewayIP + ". " +
                      "Be carefull this existing binary was used. Remove it first to use the new binary content !!! \n");

                }
               
                String fullyQualifiedInstallerCmd = replaceManagerIPPattern(config.getInstallerCmd(), managerIP);
                if(logger.isDebugEnabled()) {
                  logger.debug("Executing shell command '" + fullyQualifiedInstallerCmd + "'");
                }
               
                /* Launch Install. */
                ShellCommandResult cmdResInstallation = cmd.execShellCommand(fullyQualifiedInstallerCmd, config.getRemotePath());
                if (cmdResInstallation.getExitStatus() != 0)
                {
                  /* remote installation has failed, display output. */
                  throw new InstallerDeployException("Installation has failed while executing command [" + fullyQualifiedInstallerCmd + "]\ndetails:"+ cmdResInstallation);
                }
                 
                /* Launch sanity check. */
                ShellCommandResult cmdResSanityCheck = cmd.execShellCommand(config.getSanityCheckCmd(), config.getRemotePath());
                if (cmdResSanityCheck.getExitStatus() != 0)
                {
                  /* remote installation has failed, display output. TODO: handle failure */
                  throw new InstallerDeployException("Sanity check has failed  while executing command ["+ config.getSanityCheckCmd() + "] in the folder [" + config.getRemotePath() + "]\nDetails:"+ cmdResSanityCheck);
                }
              }
              else { // Local
                //if ("E3Gateway".equals(instance.getType())) {
               
                String generateNatureCmd = config.getGenerateNatureCmd();
                if (generateNatureCmd != null && !generateNatureCmd.isEmpty())
                {
               
                  String fullyQualifiedGenerateNatureCmd = replaceManagerIPPattern(generateNatureCmd, managerIP);
                  if(logger.isDebugEnabled()) {
                    logger.debug("Executing shell command '" + fullyQualifiedGenerateNatureCmd + "'");
                  }
                 
                  /* Get the ssh key. TODO: handle case without sshkey (eg. if user/password provided) */
                  SSHKey key = instance.getSSHKey();
                  if (key != null) {
                    if(logger.isDebugEnabled()) {
                      logger.debug("using key: " + key.getName());
                    }
                  }
                  /* Connect via ssh. */
                  SSHCommand sshCommand = (SSHCommand) cmd;
                  sshCommand.connect(key, localizedGatewayIP, 22, instance.getUser(), instance.getPassword());
                 
                  if (!sshCommand.isConnected())
                  {
                    String errorSshMsg = "Error: ssh connection to" + localizedGatewayIP+  " failed (sshkey=";
                    errorSshMsg += (key == null) ? "not defined " : key.getName();
                    errorSshMsg += "user=" + instance.getUser() + ")";
                    throw new InstallerDeployException(errorSshMsg);
                  }
                 
                  // And we need to update the configuration.properties file directly
View Full Code Here

Examples of com.alu.e3.data.model.SSHKey

          NodeList privateKeyNode = keyElement.getElementsByTagName("PrivateKey");
          strPublicKey = keyElement.getElementsByTagName("PublicKey").item(0).getTextContent();
          strPrivateKey = (privateKeyNode == null || privateKeyNode.getLength() == 0) ? null : privateKeyNode.item(0).getTextContent();
        }

        SSHKey key = new SSHKey(strKeyName, strPrivateKey == null ? null : strPrivateKey.getBytes("UTF-8"), strPublicKey.getBytes("UTF-8"));
        topology.addKey(key);
       
        if(logger.isDebugEnabled()) {
          logger.debug(key.toString());
        }
      }
     

      NodeList labNodes = rootElement.getElementsByTagName("Node");
View Full Code Here

Examples of com.alu.e3.data.model.SSHKey

    tdrCollectorInstanceWatcher = new TDRCollectorInstanceWatcher();
    tdrCollectorInstanceWatcher.setConfigName(CONFIG_NAME);
    tdrCollectorInstanceWatcher.setKeyName(KEY_NAME);
    tdrCollectorInstanceWatcher.setWriteLocation(WRITE_LOCATION);
   
    SSHKey key = null;
    if (useKey) {
      key = new SSHKey(KEY_NAME, PRIVATE_KEY, PUBLIC_KEY);
   
   
    topologyClient = new DummyTopologyClient();
    tdrCollectorInstanceWatcher.setTopologyClient(topologyClient)
View Full Code Here

Examples of com.gitblit.transport.ssh.SshKey

  }

  @Test
  public void testKeysAddCommand() throws Exception {
    KeyPair kp = generator.generateKeyPair();
    SshKey key = new SshKey(kp.getPublic());
    testSshCommand("keys add --permission R", key.getRawData());
    List<SshKey> keys = getKeyManager().getKeys(username);
    assertEquals(String.format("There are %d keys!", keys.size()), 3, keys.size());
    assertEquals(AccessPermission.CLONE, keys.get(2).getPermission());

    String result = testSshCommand("keys ls -L");
View Full Code Here

Examples of com.gitblit.transport.ssh.SshKey

@CommandMetaData(name = "git-upload-pack", description = "Sends packs to a client for clone and fetch", hidden = true)
public class Upload extends BaseGitCommand {
  @Override
  protected void runImpl() throws Failure {
    try {
      SshKey key = getContext().getClient().getKey();
      if (key != null && !key.canClone()) {
        throw new Failure(1, "Sorry, your SSH public key is not allowed to clone!");
      }
      UploadPack up = uploadPackFactory.create(getContext().getClient(), repo);
      up.upload(in, out, null);
    } catch (Exception e) {
View Full Code Here

Examples of com.gitblit.transport.ssh.SshKey

@CommandMetaData(name = "git-receive-pack", description = "Receives pushes from a client", hidden = true)
public class Receive extends BaseGitCommand {
  @Override
  protected void runImpl() throws Failure {
    SshKey key = getContext().getClient().getKey();
    if (key != null && !key.canPush()) {
      throw new Failure(1, "Sorry, your SSH public key is not allowed to push changes!");
    }
    try {
      ReceivePack rp = receivePackFactory.create(getContext().getClient(), repo);
      rp.receive(in, out, null);
View Full Code Here

Examples of com.gitblit.transport.ssh.SshKey

  @Before
  public void prepare() {
    rwKeyPair = generator.generateKeyPair();

    MemoryKeyManager keyMgr = getKeyManager();
    keyMgr.addKey(username, new SshKey(rwKeyPair.getPublic()));

    roKeyPair = generator.generateKeyPair();
    SshKey sshKey = new SshKey(roKeyPair.getPublic());
    sshKey.setPermission(AccessPermission.CLONE);
    keyMgr.addKey(username, sshKey);
  }
View Full Code Here

Examples of com.gitblit.transport.ssh.SshKey

  protected SshKey parseKey(String rawData) throws UnloggedFailure {
    if (rawData.contains("PRIVATE")) {
      throw new UnloggedFailure(1"Please provide a PUBLIC key, not a PRIVATE key!");
    }
    SshKey key = new SshKey(rawData);
    return key;
  }
View Full Code Here

Examples of com.gitblit.transport.ssh.SshKey

      List<String> keys = readKeys(addKeys);
      if (keys.isEmpty()) {
        throw new UnloggedFailure("No public keys were read from STDIN!");
      }
      for (String key : keys) {
        SshKey sshKey = parseKey(key);
        try {
          // this method parses the rawdata and produces a public key
          // if it fails it will throw a Buffer.BufferException
          // the null check is a QC verification on top of that
          if (sshKey.getPublicKey() == null) {
            throw new RuntimeException();
          }
        } catch (RuntimeException e) {
          throw new UnloggedFailure("The data read from SDTIN can not be parsed as an SSH public key!");
        }
        if (!StringUtils.isEmpty(permission)) {
          AccessPermission ap = AccessPermission.fromCode(permission);
          if (ap.exceeds(AccessPermission.NONE)) {
            try {
              sshKey.setPermission(ap);
            } catch (IllegalArgumentException e) {
              throw new Failure(1, e.getMessage());
            }
          }
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.