コード例 #1
0
ファイル: Launcher.java プロジェクト: Rafal-G/jenkins
        public Channel launchChannel(String[] cmd, OutputStream err, FilePath _workDir, Map<String,String> envOverrides) throws IOException, InterruptedException {
            printCommandLine(cmd, _workDir);

            Pipe out = Pipe.createRemoteToLocal();
            final String workDir = _workDir==null ? null : _workDir.getRemote();

            OutputStream os = getChannel().call(new RemoteChannelLaunchCallable(cmd, out, err, workDir, envOverrides));

            return new Channel("remotely launched channel on "+channel,
                Computer.threadPoolForRemoting, out.getIn(), new BufferedOutputStream(os));
        }
コード例 #2
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();
    }
  }