@Override public void notifyUnimplemented(long seqNum) throws SSHException { throw new SSHException(DisconnectReason.PROTOCOL_ERROR, "Unexpected: SSH_MSG_UNIMPLEMENTED"); }
@Override public SSHException chain(Throwable t) { if (t instanceof SSHException) return (SSHException) t; else return new SSHException(t); }
HashedHostMatcher(String hash) throws SSHException { this.hash = hash; final String[] hostParts = hash.split("\\|"); if (hostParts.length != 4) { throw new SSHException("Unrecognized format for hashed hostname"); } salt = hostParts[2]; }
private int getPacketLength() throws IOException { readIntoBuffer(lenBuf, 0, lenBuf.length); final long len = (lenBuf[0] << 24 & 0xff000000L | lenBuf[1] << 16 & 0x00ff0000L | lenBuf[2] << 8 & 0x0000ff00L | lenBuf[3] & 0x000000ffL); if (len > SFTPPacket.MAX_SIZE) { throw new SSHException(String.format("Indicated packet length %d too large", len)); } return (int) len; }
Factory.Named.Util.create(trans.getConfig().getFileKeyProviderFactories(), format.toString()); if (fkp == null) throw new SSHException("No provider available for " + format + " key file"); fkp.init(loc, passwordFinder); return fkp;
/** * Creates a {@link KeyProvider} instance from passed strings. Currently only PKCS8 format private key files are * supported (OpenSSH uses this format). * <p/> * * @param privateKey the private key as a string * @param publicKey the public key as a string if it's not included with the private key * @param passwordFinder the {@link PasswordFinder} that can supply the passphrase for decryption (may be {@code * null} in case keyfile is not encrypted) * * @return the key provider ready for use in authentication * * @throws SSHException if there was no suitable key provider available for the file format; typically because * BouncyCastle is not in the classpath * @throws IOException if the key file format is not known, etc. */ public KeyProvider loadKeys(String privateKey, String publicKey, PasswordFinder passwordFinder) throws IOException { final KeyFormat format = KeyProviderUtil.detectKeyFileFormat(privateKey, publicKey != null); final FileKeyProvider fkp = Factory.Named.Util.create(trans.getConfig().getFileKeyProviderFactories(), format.toString()); if (fkp == null) throw new SSHException("No provider available for " + format + " key file"); fkp.init(privateKey, publicKey, passwordFinder); return fkp; }
@Override public SSHException chain(Throwable t) { if (t instanceof SSHException) return (SSHException) t; else return new SSHException(t); }
@Override public void notifyUnimplemented(long seqNum) throws SSHException { throw new SSHException(DisconnectReason.PROTOCOL_ERROR, "Unexpected: SSH_MSG_UNIMPLEMENTED"); }
@Override public void notifyUnimplemented(long seqNum) throws SSHException { throw new SSHException(DisconnectReason.PROTOCOL_ERROR, "Unexpected: SSH_MSG_UNIMPLEMENTED"); }
@Override public SSHException chain(Throwable t) { if (t instanceof SSHException) return (SSHException) t; else return new SSHException(t); }
public HashedEntry(Marker marker, String hash, KeyType type, PublicKey key) throws SSHException { super(marker, type, key); this.hashedHost = hash; { final String[] hostParts = hashedHost.split("\\|"); if (hostParts.length != 4) throw new SSHException("Unrecognized format for hashed hostname"); salt = hostParts[2]; } }
HashedHostMatcher(String hash) throws SSHException { this.hash = hash; final String[] hostParts = hash.split("\\|"); if (hostParts.length != 4) { throw new SSHException("Unrecognized format for hashed hostname"); } salt = hostParts[2]; }
@Override public void notifyDisconnect(final DisconnectReason reason, final String message) { log.warn(String.format("Disconnected %s", reason)); failure = new SSHException(reason, message); }
private int getPacketLength() throws IOException { readIntoBuffer(lenBuf, 0, lenBuf.length); final long len = (lenBuf[0] << 24 & 0xff000000L | lenBuf[1] << 16 & 0x00ff0000L | lenBuf[2] << 8 & 0x0000ff00L | lenBuf[3] & 0x000000ffL); if (len > SFTPPacket.MAX_SIZE) { throw new SSHException(String.format("Indicated packet length %d too large", len)); } return (int) len; }
private int getPacketLength() throws IOException { readIntoBuffer(lenBuf, 0, lenBuf.length); final long len = (lenBuf[0] << 24 & 0xff000000L | lenBuf[1] << 16 & 0x00ff0000L | lenBuf[2] << 8 & 0x0000ff00L | lenBuf[3] & 0x000000ffL); if (len > SFTPPacket.MAX_SIZE) { throw new SSHException(String.format("Indicated packet length %d too large", len)); } return (int) len; }
public void testCausalChainHasMessageContaining() { assert ssh.causalChainHasMessageContaining( new SSHException("Session.connect: java.io.IOException: End of IO Stream Read")).apply( " End of IO Stream Read"); assert ssh.causalChainHasMessageContaining( new SSHException("Session.connect: java.net.SocketException: Connection reset")).apply("java.net.Socket"); assert !ssh.causalChainHasMessageContaining(new NullPointerException()).apply(" End of IO Stream Read"); }
public void testExceptionMessagesRetry() { assert !ssh.shouldRetry(new SSHException("")); assert !ssh.shouldRetry(new NullPointerException((String) null)); }
public void testExceptionClassesRetry() { assert ssh.shouldRetry(new ConnectionException("Read timed out", new SSHException("Read timed out", new SocketTimeoutException("Read timed out")))); assert ssh.shouldRetry(new SFTPException("Failure!")); assert ssh.shouldRetry(new SocketTimeoutException("connect timed out")); assert ssh.shouldRetry(new TransportException("socket closed")); assert ssh.shouldRetry(new ConnectionException("problem")); assert ssh.shouldRetry(new ConnectException("Connection refused")); assert !ssh.shouldRetry(new IOException("channel is not open", new NullPointerException())); }
/** * Creates a {@link KeyProvider} instance from passed strings. Currently only PKCS8 format private key files are * supported (OpenSSH uses this format). * <p/> * * @param privateKey the private key as a string * @param publicKey the public key as a string if it's not included with the private key * @param passwordFinder the {@link PasswordFinder} that can supply the passphrase for decryption (may be {@code * null} in case keyfile is not encrypted) * * @return the key provider ready for use in authentication * * @throws SSHException if there was no suitable key provider available for the file format; typically because * BouncyCastle is not in the classpath * @throws IOException if the key file format is not known, etc. */ public KeyProvider loadKeys(String privateKey, String publicKey, PasswordFinder passwordFinder) throws IOException { final KeyFormat format = KeyProviderUtil.detectKeyFileFormat(privateKey, publicKey != null); final FileKeyProvider fkp = Factory.Named.Util.create(trans.getConfig().getFileKeyProviderFactories(), format.toString()); if (fkp == null) throw new SSHException("No provider available for " + format + " key file"); fkp.init(privateKey, publicKey, passwordFinder); return fkp; }
/** * Creates a {@link KeyProvider} instance from passed strings. Currently only PKCS8 format private key files are * supported (OpenSSH uses this format). * <p/> * * @param privateKey the private key as a string * @param publicKey the public key as a string if it's not included with the private key * @param passwordFinder the {@link PasswordFinder} that can supply the passphrase for decryption (may be {@code * null} in case keyfile is not encrypted) * * @return the key provider ready for use in authentication * * @throws SSHException if there was no suitable key provider available for the file format; typically because * BouncyCastle is not in the classpath * @throws IOException if the key file format is not known, etc. */ public KeyProvider loadKeys(String privateKey, String publicKey, PasswordFinder passwordFinder) throws IOException { final KeyFormat format = KeyProviderUtil.detectKeyFileFormat(privateKey, publicKey != null); final FileKeyProvider fkp = Factory.Named.Util.create(trans.getConfig().getFileKeyProviderFactories(), format.toString()); if (fkp == null) throw new SSHException("No provider available for " + format + " key file"); fkp.init(privateKey, publicKey, passwordFinder); return fkp; }