예제 #1
0
파일: CLI.java 프로젝트: Surgo/jenkins
 public int execute(
     List<String> args, InputStream stdin, OutputStream stdout, OutputStream stderr) {
   return entryPoint.main(
       args,
       Locale.getDefault(),
       new RemoteInputStream(stdin),
       new RemoteOutputStream(stdout),
       new RemoteOutputStream(stderr));
 }
예제 #2
0
파일: CLI.java 프로젝트: Surgo/jenkins
  public CLI(URL jenkins, ExecutorService exec) throws IOException, InterruptedException {
    String url = jenkins.toExternalForm();
    if (!url.endsWith("/")) url += '/';

    ownsPool = exec == null;
    pool = exec != null ? exec : Executors.newCachedThreadPool();

    int clip = getCliTcpPort(url);
    if (clip >= 0) {
      // connect via CLI port
      String host = new URL(url).getHost();
      LOGGER.fine("Trying to connect directly via TCP/IP to port " + clip + " of " + host);
      Socket s = new Socket(host, clip);
      DataOutputStream dos = new DataOutputStream(s.getOutputStream());
      dos.writeUTF("Protocol:CLI-connect");

      channel =
          new Channel(
              "CLI connection to " + jenkins,
              pool,
              new BufferedInputStream(new SocketInputStream(s)),
              new BufferedOutputStream(new SocketOutputStream(s)));
    } else {
      // connect via HTTP
      LOGGER.fine("Trying to connect to " + url + " via HTTP");
      url += "cli";
      jenkins = new URL(url);

      FullDuplexHttpStream con = new FullDuplexHttpStream(jenkins);
      channel =
          new Channel(
              "Chunked connection to " + jenkins,
              pool,
              con.getInputStream(),
              con.getOutputStream());
      new PingThread(channel, 30 * 1000) {
        protected void onDead() {
          // noop. the point of ping is to keep the connection alive
          // as most HTTP servers have a rather short read time out
        }
      }.start();
    }

    // execute the command
    entryPoint = (CliEntryPoint) channel.waitForRemoteProperty(CliEntryPoint.class.getName());

    if (entryPoint.protocolVersion() != CliEntryPoint.VERSION)
      throw new IOException(Messages.CLI_VersionMismatch());
  }
예제 #3
0
파일: CLI.java 프로젝트: Surgo/jenkins
  /**
   * Authenticate ourselves against the server.
   *
   * @return identity of the server represented as a public key.
   */
  public PublicKey authenticate(Iterable<KeyPair> privateKeys)
      throws IOException, GeneralSecurityException {
    Pipe c2s = Pipe.createLocalToRemote();
    Pipe s2c = Pipe.createRemoteToLocal();
    entryPoint.authenticate("ssh", c2s, s2c);
    Connection c = new Connection(s2c.getIn(), c2s.getOut());

    try {
      byte[] sharedSecret = c.diffieHellman(false).generateSecret();
      PublicKey serverIdentity = c.verifyIdentity(sharedSecret);

      // try all the public keys
      for (KeyPair key : privateKeys) {
        c.proveIdentity(sharedSecret, key);
        if (c.readBoolean()) return serverIdentity; // succeeded
      }
      if (privateKeys.iterator().hasNext())
        throw new GeneralSecurityException("Authentication failed. No private key accepted.");
      else
        throw new GeneralSecurityException("No private key is available for use in authentication");
    } finally {
      c.close();
    }
  }
예제 #4
0
파일: CLI.java 프로젝트: Surgo/jenkins
 /** Returns true if the named command exists. */
 public boolean hasCommand(String name) {
   return entryPoint.hasCommand(name);
 }