Cleanup some code

This commit is contained in:
Jeroen van Erp
2019-01-24 15:09:00 +01:00
parent 2f7b181306
commit a5017d55c8
5 changed files with 16 additions and 18 deletions

View File

@@ -69,7 +69,7 @@ public class Macs {
return new Factory("hmac-sha2-512-etm@openssh.com", "HmacSHA512", 64, 64, true); return new Factory("hmac-sha2-512-etm@openssh.com", "HmacSHA512", 64, 64, true);
} }
private static class Factory implements net.schmizz.sshj.common.Factory.Named<MAC> { public static class Factory implements net.schmizz.sshj.common.Factory.Named<MAC> {
private String name; private String name;
private String algorithm; private String algorithm;

View File

@@ -18,7 +18,6 @@ package com.hierynomus.sshj.transport.verification;
import net.schmizz.sshj.common.Base64; import net.schmizz.sshj.common.Base64;
import net.schmizz.sshj.common.IOUtils; import net.schmizz.sshj.common.IOUtils;
import net.schmizz.sshj.common.SSHException; import net.schmizz.sshj.common.SSHException;
import net.schmizz.sshj.transport.mac.HMACSHA1;
import net.schmizz.sshj.transport.mac.MAC; import net.schmizz.sshj.transport.mac.MAC;
import java.io.IOException; import java.io.IOException;
@@ -26,6 +25,8 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import com.hierynomus.sshj.transport.mac.Macs;
public class KnownHostMatchers { public class KnownHostMatchers {
public static HostMatcher createMatcher(String hostEntry) throws SSHException { public static HostMatcher createMatcher(String hostEntry) throws SSHException {
@@ -63,7 +64,7 @@ public class KnownHostMatchers {
} }
private static class HashedHostMatcher implements HostMatcher { private static class HashedHostMatcher implements HostMatcher {
private final MAC sha1 = new HMACSHA1(); private final MAC sha1 = Macs.HMACSHA1().create();
private final String hash; private final String hash;
private final String salt; private final String salt;
private byte[] saltyBytes; private byte[] saltyBytes;

View File

@@ -40,7 +40,6 @@ import java.nio.CharBuffer;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.security.*; import java.security.*;
import java.security.spec.ECPrivateKeySpec; import java.security.spec.ECPrivateKeySpec;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.RSAPrivateKeySpec; import java.security.spec.RSAPrivateKeySpec;
import java.util.Arrays; import java.util.Arrays;
@@ -194,7 +193,7 @@ public class OpenSSHKeyV1KeyFile extends BaseFileKeyProvider {
KeyPair kp; KeyPair kp;
switch (kt) { switch (kt) {
case ED25519: case ED25519:
byte[] pubKey = keyBuffer.readBytes(); // string publickey (again...) keyBuffer.readBytes(); // string publickey (again...)
keyBuffer.readUInt32(); // length of privatekey+publickey keyBuffer.readUInt32(); // length of privatekey+publickey
byte[] privKey = new byte[32]; byte[] privKey = new byte[32];
keyBuffer.readRawBytes(privKey); // string privatekey keyBuffer.readRawBytes(privKey); // string privatekey
@@ -203,7 +202,7 @@ public class OpenSSHKeyV1KeyFile extends BaseFileKeyProvider {
break; break;
case RSA: case RSA:
BigInteger n = keyBuffer.readMPInt(); // Modulus BigInteger n = keyBuffer.readMPInt(); // Modulus
BigInteger e = keyBuffer.readMPInt(); // Public Exponent keyBuffer.readMPInt(); // Public Exponent
BigInteger d = keyBuffer.readMPInt(); // Private Exponent BigInteger d = keyBuffer.readMPInt(); // Private Exponent
keyBuffer.readMPInt(); // iqmp (q^-1 mod p) keyBuffer.readMPInt(); // iqmp (q^-1 mod p)
keyBuffer.readMPInt(); // p (Prime 1) keyBuffer.readMPInt(); // p (Prime 1)
@@ -223,7 +222,7 @@ public class OpenSSHKeyV1KeyFile extends BaseFileKeyProvider {
default: default:
throw new IOException("Cannot decode keytype " + keyType + " in openssh-key-v1 files (yet)."); throw new IOException("Cannot decode keytype " + keyType + " in openssh-key-v1 files (yet).");
} }
String comment = keyBuffer.readString(); // string comment keyBuffer.readString(); // string comment
byte[] padding = new byte[keyBuffer.available()]; byte[] padding = new byte[keyBuffer.available()];
keyBuffer.readRawBytes(padding); // char[] padding keyBuffer.readRawBytes(padding); // char[] padding
for (int i = 0; i < padding.length; i++) { for (int i = 0; i < padding.length; i++) {
@@ -235,7 +234,7 @@ public class OpenSSHKeyV1KeyFile extends BaseFileKeyProvider {
} }
private PrivateKey createECDSAPrivateKey(KeyType kt, PlainBuffer buffer, String name) throws GeneralSecurityException, Buffer.BufferException { private PrivateKey createECDSAPrivateKey(KeyType kt, PlainBuffer buffer, String name) throws GeneralSecurityException, Buffer.BufferException {
PublicKey pk = kt.readPubKeyFromBuffer(buffer); // Public key kt.readPubKeyFromBuffer(buffer); // Public key
BigInteger s = new BigInteger(1, buffer.readBytes()); BigInteger s = new BigInteger(1, buffer.readBytes());
X9ECParameters ecParams = NISTNamedCurves.getByName(name); X9ECParameters ecParams = NISTNamedCurves.getByName(name);
ECNamedCurveSpec ecCurveSpec = new ECNamedCurveSpec(name, ecParams.getCurve(), ecParams.getG(), ecParams.getN()); ECNamedCurveSpec ecCurveSpec = new ECNamedCurveSpec(name, ecParams.getCurve(), ecParams.getG(), ecParams.getN());

View File

@@ -19,23 +19,23 @@ import java.util.Collection;
public class ErrorDeliveryUtil { public class ErrorDeliveryUtil {
public static void alertPromises(Throwable x, Promise... promises) { public static void alertPromises(Throwable x, Promise<?, ?>... promises) {
for (Promise p : promises) for (Promise<?, ?> p : promises)
p.deliverError(x); p.deliverError(x);
} }
public static void alertPromises(Throwable x, Collection<? extends Promise> promises) { public static void alertPromises(Throwable x, Collection<? extends Promise<?, ?>> promises) {
for (Promise p : promises) for (Promise<?, ?> p : promises)
p.deliverError(x); p.deliverError(x);
} }
public static void alertEvents(Throwable x, Event... events) { public static void alertEvents(Throwable x, Event<?>... events) {
for (Event e : events) for (Event<?> e : events)
e.deliverError(x); e.deliverError(x);
} }
public static void alertEvents(Throwable x, Collection<? extends Event> events) { public static void alertEvents(Throwable x, Collection<? extends Event<?>> events) {
for (Event e : events) for (Event<?> e : events)
e.deliverError(x); e.deliverError(x);
} }

View File

@@ -35,7 +35,6 @@ import net.schmizz.sshj.transport.kex.Curve25519SHA256;
import net.schmizz.sshj.transport.kex.DHGexSHA1; import net.schmizz.sshj.transport.kex.DHGexSHA1;
import net.schmizz.sshj.transport.kex.DHGexSHA256; import net.schmizz.sshj.transport.kex.DHGexSHA256;
import net.schmizz.sshj.transport.kex.ECDHNistP; import net.schmizz.sshj.transport.kex.ECDHNistP;
import net.schmizz.sshj.transport.mac.*;
import net.schmizz.sshj.transport.random.BouncyCastleRandom; import net.schmizz.sshj.transport.random.BouncyCastleRandom;
import net.schmizz.sshj.transport.random.JCERandom; import net.schmizz.sshj.transport.random.JCERandom;
import net.schmizz.sshj.transport.random.SingletonRandomFactory; import net.schmizz.sshj.transport.random.SingletonRandomFactory;
@@ -45,7 +44,6 @@ import net.schmizz.sshj.userauth.keyprovider.PKCS8KeyFile;
import net.schmizz.sshj.userauth.keyprovider.PuTTYKeyFile; import net.schmizz.sshj.userauth.keyprovider.PuTTYKeyFile;
import org.slf4j.Logger; import org.slf4j.Logger;
import java.io.IOException;
import java.util.*; import java.util.*;
/** /**