/** * Authenticate ourselves against the server. * * @return * identity of the server represented as a public key. * @deprecated Specific to {@link Mode#REMOTING}. */ @Deprecated 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(); } }
@Override public Void invoke(File f, VirtualChannel channel) throws IOException, InterruptedException { try (InputStream fis = Files.newInputStream(fileToPath(reading(f))); OutputStream out = p.getOut()) { org.apache.commons.io.IOUtils.copy(fis, out); } catch (Exception x) { p.error(x); } return null; } }
/** * Reads this file. */ public InputStream read() throws IOException, InterruptedException { if(channel==null) { return Files.newInputStream(fileToPath(reading(new File(remote)))); } final Pipe p = Pipe.createRemoteToLocal(); actAsync(new Read(p)); return p.getIn(); } private class Read extends SecureFileCallable<Void> {
public Void invoke(File f, VirtualChannel channel) throws IOException { try (OutputStream os = p.getOut(); OutputStream out = new java.util.zip.GZIPOutputStream(os, 8192); RandomAccessFile raf = new RandomAccessFile(reading(f), "r")) { raf.seek(offset); byte[] buf = new byte[8192]; int len; while ((len = raf.read(buf)) >= 0) { out.write(buf, 0, len); } return null; } } });
private Object writeReplace() { Pipe p = Pipe.createLocalToRemote(); // the thread will terminate when there's nothing more to read. new StreamCopyThread("Stream reader: maven process at "+socket,in,p.getOut(),true).start(); return new Connection(p,new RemoteOutputStream(out)); }
if(this.channel==null) { final Pipe pipe = Pipe.createLocalToRemote(); final Pipe pipe = Pipe.createRemoteToLocal(); readFromTar(remote + '/' + description,new File(target.remote),TarCompression.GZIP.extract(pipe.getIn())); } catch (IOException e) {// BuildException or IOException try {
@Override public Void invoke(File f, VirtualChannel channel) throws IOException { try (InputStream in = pipe.getIn()) { readFromTar(remote + '/' + description, f, TarCompression.GZIP.extract(in)); return null; } } }
public void testLocalWrite2() throws Exception { Pipe p = Pipe.createLocalToRemote(); Future<Integer> f = channel.callAsync(new ReadingCallable(p)); Thread.sleep(2000); // wait for remote to connect to local. write(p); int r = f.get(); System.out.println("result=" + r); assertEquals(5,r); }
/** * Creates a {@link Pipe} that allows local system to write and remote system to read. */ public static Pipe createLocalToRemote() { return new Pipe(null, new ProxyOutputStream()); }
/** * Test the "remote-write local-read" pipe. */ public void testRemoteWrite() throws Exception { Pipe p = Pipe.createRemoteToLocal(); Future<Integer> f = channel.callAsync(new WritingCallable(p)); read(p); int r = f.get(); System.out.println("result=" + r); assertEquals(5,r); }
final Pipe p = Pipe.createRemoteToLocal(); actAsync(new SecureFileCallable<Void>() { private static final long serialVersionUID = 1L; return new java.util.zip.GZIPInputStream(p.getIn());
@Override public Integer invoke(File f, VirtualChannel channel) throws IOException { try (OutputStream out = pipe.getOut()) { return writeToTar(f, scanner, TarCompression.GZIP.compress(out)); } } }
/** * Writer end closes even before the remote computation kicks in. */ public void testQuickBurstWrite() throws Exception { final Pipe p = Pipe.createLocalToRemote(); Future<Integer> f = channel.callAsync(new QuickBurstCallable(p)); OutputStream os = p.getOut(); os.write(1); os.close(); // at this point the async executable kicks in. // TODO: introduce a lock to ensure the ordering. assertEquals(1,(int)f.get()); }
if(this.channel==null) { final Pipe pipe = Pipe.createLocalToRemote(); final Pipe pipe = Pipe.createRemoteToLocal(); readFromTar(remote + '/' + description,new File(target.remote),TarCompression.GZIP.extract(pipe.getIn())); } catch (IOException e) {// BuildException or IOException try {
private Object readResolve() { assert in==null; this.in = pipe.getIn(); assert out!=null; assert socket==null; return this; }
/** * Test the "local-write remote-read" pipe. */ public void testLocalWrite() throws Exception { Pipe p = Pipe.createLocalToRemote(); Future<Integer> f = channel.callAsync(new ReadingCallable(p)); write(p); int r = f.get(); System.out.println("result=" + r); assertEquals(5,r); }
@Override public Void invoke(File f, VirtualChannel channel) throws IOException, InterruptedException { try (InputStream fis = Files.newInputStream(reading(f).toPath()); OutputStream out = p.getOut()) { org.apache.commons.io.IOUtils.copy(fis, out); } catch (InvalidPathException e) { p.error(new IOException(e)); } catch (Exception x) { p.error(x); } return null; } });
/** * Creates a {@link Pipe} that allows local system to write and remote system to read. */ public static Pipe createLocalToRemote() { return new Pipe(null, new ProxyOutputStream()); }