Improvements per JVE.

This commit is contained in:
David Solin
2016-09-13 08:04:15 -05:00
parent e420593fa9
commit 6185ac4db8
3 changed files with 8 additions and 13 deletions

View File

@@ -426,18 +426,7 @@ public class Buffer<T extends Buffer<T>> {
public PublicKey readPublicKey() public PublicKey readPublicKey()
throws BufferException { throws BufferException {
try { try {
final KeyType type = KeyType.fromString(readString()); return KeyType.fromString(readString()).readPubKeyFromBuffer(this);
switch (type) {
case RSA:
case DSA:
return type.readPubKeyFromBuffer(this);
default:
if (SecurityUtils.isBouncyCastleRegistered()) {
return type.readPubKeyFromBuffer(this);
} else {
throw new BufferException("BouncyCastle is required to read a key of type " + type);
}
}
} catch (GeneralSecurityException e) { } catch (GeneralSecurityException e) {
throw new SSHRuntimeException(e); throw new SSHRuntimeException(e);
} }

View File

@@ -116,6 +116,9 @@ public enum KeyType {
@Override @Override
public PublicKey readPubKeyFromBuffer(Buffer<?> buf) public PublicKey readPubKeyFromBuffer(Buffer<?> buf)
throws GeneralSecurityException { throws GeneralSecurityException {
if (!SecurityUtils.isBouncyCastleRegistered()) {
throw new GeneralSecurityException("BouncyCastle is required to read a key of type " + sType);
}
try { try {
// final String algo = buf.readString(); it has been already read // final String algo = buf.readString(); it has been already read
final String curveName = buf.readString(); final String curveName = buf.readString();

View File

@@ -57,7 +57,7 @@ public class OpenSSHKnownHosts
try { try {
// Read in the file, storing each line as an entry // Read in the file, storing each line as an entry
String line; String line;
while ((line = br.readLine()) != null) while ((line = br.readLine()) != null) {
try { try {
HostEntry entry = entryFactory.parseEntry(line); HostEntry entry = entryFactory.parseEntry(line);
if (entry != null) { if (entry != null) {
@@ -65,7 +65,10 @@ public class OpenSSHKnownHosts
} }
} catch (SSHException ignore) { } catch (SSHException ignore) {
log.debug("Bad line ({}): {} ", ignore.toString(), line); log.debug("Bad line ({}): {} ", ignore.toString(), line);
} catch (SSHRuntimeException ignore) {
log.debug("Failed to process line ({}): {} ", ignore.toString(), line);
} }
}
} finally { } finally {
IOUtils.closeQuietly(br); IOUtils.closeQuietly(br);
} }