diff --git a/src/main/java/net/schmizz/sshj/common/KeyType.java b/src/main/java/net/schmizz/sshj/common/KeyType.java index 08c1b355..0c3da6f0 100644 --- a/src/main/java/net/schmizz/sshj/common/KeyType.java +++ b/src/main/java/net/schmizz/sshj/common/KeyType.java @@ -21,6 +21,7 @@ import java.security.interfaces.DSAPublicKey; import java.security.interfaces.RSAPrivateKey; import java.security.interfaces.RSAPublicKey; +/** Type of key e.g. rsa, dsa */ public enum KeyType { /** SSH identifier for RSA keys */ diff --git a/src/main/java/net/schmizz/sshj/signature/Signature.java b/src/main/java/net/schmizz/sshj/signature/Signature.java index 84b4f7b6..b77cb7cf 100644 --- a/src/main/java/net/schmizz/sshj/signature/Signature.java +++ b/src/main/java/net/schmizz/sshj/signature/Signature.java @@ -38,11 +38,7 @@ package net.schmizz.sshj.signature; import java.security.PrivateKey; import java.security.PublicKey; -/** - * Signature interface for SSH used to sign or verify data. - *

- * Usually wraps a javax.crypto.Signature object. - */ +/** Signature interface for SSH used to sign or verify data. Usually wraps a {@code javax.crypto.Signature} object. */ public interface Signature { /** @@ -55,21 +51,15 @@ public interface Signature { void init(PublicKey pubkey, PrivateKey prvkey); /** - * Compute the signature - * - * @return the computed signature - */ - byte[] sign(); - - /** - * Convenience method for {@link #update(byte[], int, int)} + * Convenience method, same as calling {@link #update(byte[], int, int)} with offset as {@code 0} and {@code + * H.length}. * * @param H the byte-array to update with */ void update(byte[] H); /** - * Update the computed signature with the given data + * Update the computed signature with the given data. * * @param H byte-array to update with * @param off offset within the array @@ -78,9 +68,16 @@ public interface Signature { void update(byte[] H, int off, int len); /** - * Verify against the given signature + * Compute the signature. * - * @param sig + * @return the computed signature + */ + byte[] sign(); + + /** + * Verify against the given signature. + * + * @param sig the signature to verify against * * @return {@code true} on successful verification, {@code false} on failure */ diff --git a/src/main/java/net/schmizz/sshj/transport/cipher/AES128CBC.java b/src/main/java/net/schmizz/sshj/transport/cipher/AES128CBC.java index 78d78732..4c121511 100644 --- a/src/main/java/net/schmizz/sshj/transport/cipher/AES128CBC.java +++ b/src/main/java/net/schmizz/sshj/transport/cipher/AES128CBC.java @@ -35,7 +35,7 @@ */ package net.schmizz.sshj.transport.cipher; -/** AES128CBC cipher */ +/** {@code aes128-cbc} cipher */ public class AES128CBC extends BaseCipher { diff --git a/src/main/java/net/schmizz/sshj/transport/cipher/Cipher.java b/src/main/java/net/schmizz/sshj/transport/cipher/Cipher.java index 8ebcaf7b..62d2e269 100644 --- a/src/main/java/net/schmizz/sshj/transport/cipher/Cipher.java +++ b/src/main/java/net/schmizz/sshj/transport/cipher/Cipher.java @@ -43,35 +43,27 @@ public interface Cipher { Decrypt } - /** - * Retrieves the block size for this cipher - * - * @return - */ + /** @return the block size for this cipher */ int getBlockSize(); - /** - * Retrieves the size of the initialization vector - * - * @return - */ + /** @return the size of the initialization vector */ int getIVSize(); /** * Initialize the cipher for encryption or decryption with the given private key and initialization vector * - * @param mode - * @param key - * @param iv + * @param mode whether this instance wil encrypt or decrypt + * @param key the key for the cipher + * @param iv initialization vector */ void init(Mode mode, byte[] key, byte[] iv); /** * Performs in-place encryption or decryption on the given data. * - * @param input - * @param inputOffset - * @param inputLen + * @param input the subject + * @param inputOffset offset at which to start + * @param inputLen number of bytes starting at {@code inputOffset} */ void update(byte[] input, int inputOffset, int inputLen); diff --git a/src/main/java/net/schmizz/sshj/userauth/AuthParams.java b/src/main/java/net/schmizz/sshj/userauth/AuthParams.java index 2ffa5d2f..5b8b1e60 100644 --- a/src/main/java/net/schmizz/sshj/userauth/AuthParams.java +++ b/src/main/java/net/schmizz/sshj/userauth/AuthParams.java @@ -18,19 +18,19 @@ package net.schmizz.sshj.userauth; import net.schmizz.sshj.transport.Transport; -/** The parameters available to authentication method */ +/** The parameters available to authentication methods. */ public interface AuthParams { - /** All userauth requests need to include the name of the next service being requested */ + /** @return name of the next service being requested */ String getNextServiceName(); /** - * Retrieve the transport which will allow sending packets; retrieving information like the session-id, remote - * host/port etc. which is needed by some method. + * @return the transport which will allow sending packets; retrieving information like the session-id, remote + * host/port etc. which is needed by some method. */ Transport getTransport(); - /** All userauth requests need to include the username */ + /** @return all userauth requests need to include the username */ String getUsername(); } \ No newline at end of file diff --git a/src/main/java/net/schmizz/sshj/userauth/keyprovider/KeyProvider.java b/src/main/java/net/schmizz/sshj/userauth/keyprovider/KeyProvider.java index 65808a6e..0bd6a628 100644 --- a/src/main/java/net/schmizz/sshj/userauth/keyprovider/KeyProvider.java +++ b/src/main/java/net/schmizz/sshj/userauth/keyprovider/KeyProvider.java @@ -12,26 +12,6 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * - * This file may incorporate work covered by the following copyright and - * permission notice: - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. */ package net.schmizz.sshj.userauth.keyprovider; @@ -44,15 +24,27 @@ import java.security.PublicKey; /** A KeyProvider is a container for a public-private keypair. */ public interface KeyProvider { - /** Returns the private key. */ + /** + * @return the private key. + * + * @throws IOException if there is an I/O error retrieving the private key + */ PrivateKey getPrivate() throws IOException; - /** Returns the public key. */ + /** + * @return the public key. + * + * @throws IOException if there is an I/O error retrieving the public key + */ PublicKey getPublic() throws IOException; - /** Returns the {@link KeyType}. */ + /** + * @return the {@link KeyType}. + * + * @throws IOException if there is an I/O error retrieving the key type + */ KeyType getType() throws IOException; diff --git a/src/main/java/net/schmizz/sshj/userauth/keyprovider/OpenSSHKeyFile.java b/src/main/java/net/schmizz/sshj/userauth/keyprovider/OpenSSHKeyFile.java index 8745d593..74d3c448 100644 --- a/src/main/java/net/schmizz/sshj/userauth/keyprovider/OpenSSHKeyFile.java +++ b/src/main/java/net/schmizz/sshj/userauth/keyprovider/OpenSSHKeyFile.java @@ -12,26 +12,6 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * - * This file may incorporate work covered by the following copyright and - * permission notice: - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. */ package net.schmizz.sshj.userauth.keyprovider; @@ -77,18 +57,21 @@ public class OpenSSHKeyFile @Override public void init(File location) { - File f = new File(location + ".pub"); + final File f = new File(location + ".pub"); if (f.exists()) try { - BufferedReader br = new BufferedReader(new FileReader(f)); - String keydata = br.readLine(); - if (keydata != null) { - String[] parts = keydata.split(" "); - assert parts.length >= 2; - type = KeyType.fromString(parts[0]); - pubKey = new Buffer.PlainBuffer(Base64.decode(parts[1])).readPublicKey(); + final BufferedReader br = new BufferedReader(new FileReader(f)); + try { + final String keydata = br.readLine(); + if (keydata != null) { + String[] parts = keydata.split(" "); + assert parts.length >= 2; + type = KeyType.fromString(parts[0]); + pubKey = new Buffer.PlainBuffer(Base64.decode(parts[1])).readPublicKey(); + } + } finally { + br.close(); } - br.close(); } catch (IOException e) { // let super provide both public & private key log.warn("Error reading public key file: {}", e.toString()); diff --git a/src/main/java/net/schmizz/sshj/userauth/keyprovider/PKCS8KeyFile.java b/src/main/java/net/schmizz/sshj/userauth/keyprovider/PKCS8KeyFile.java index a1088391..5f2bb1d5 100644 --- a/src/main/java/net/schmizz/sshj/userauth/keyprovider/PKCS8KeyFile.java +++ b/src/main/java/net/schmizz/sshj/userauth/keyprovider/PKCS8KeyFile.java @@ -12,26 +12,6 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * - * This file may incorporate work covered by the following copyright and - * permission notice: - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. */ package net.schmizz.sshj.userauth.keyprovider; diff --git a/src/main/java/net/schmizz/sshj/userauth/method/AuthMethod.java b/src/main/java/net/schmizz/sshj/userauth/method/AuthMethod.java index 8c9e91b3..51a76a71 100644 --- a/src/main/java/net/schmizz/sshj/userauth/method/AuthMethod.java +++ b/src/main/java/net/schmizz/sshj/userauth/method/AuthMethod.java @@ -20,32 +20,28 @@ import net.schmizz.sshj.transport.TransportException; import net.schmizz.sshj.userauth.AuthParams; import net.schmizz.sshj.userauth.UserAuthException; -/** - * An authentication method of the SSH Authentication Protocol. - * - * @see net.schmizz.sshj.userauth.UserAuth - */ +/** An authentication method of the SSH Authentication Protocol. */ public interface AuthMethod extends SSHPacketHandler { - /** Returns assigned name of this authentication method */ + /** @return assigned name of this authentication method */ String getName(); /** - * Initializes this {@link AuthMethod} with the {@link AuthParams parameters} needed for authentication. This method - * must be called before requesting authentication with this method. + * This method must be called before requesting authentication with this method. + * + * @param params parameters needed for authentication */ void init(AuthParams params); /** - * @throws net.schmizz.sshj.userauth.UserAuthException - * - * @throws TransportException + * @throws UserAuthException if there is an error with the request + * @throws TransportException if there is a transport-related error */ void request() throws UserAuthException, TransportException; - /** Returns whether authentication should be reattempted if it failed. */ + /** @return whether authentication should be reattempted if it failed. */ boolean shouldRetry(); } diff --git a/src/main/java/net/schmizz/sshj/userauth/password/PasswordFinder.java b/src/main/java/net/schmizz/sshj/userauth/password/PasswordFinder.java index c4db7fab..3825c46a 100644 --- a/src/main/java/net/schmizz/sshj/userauth/password/PasswordFinder.java +++ b/src/main/java/net/schmizz/sshj/userauth/password/PasswordFinder.java @@ -15,7 +15,7 @@ */ package net.schmizz.sshj.userauth.password; -/** An interface for servicing requests for plaintext passwords. */ +/** Services requests for plaintext passwords. */ public interface PasswordFinder { /** @@ -36,7 +36,7 @@ public interface PasswordFinder { *

* This method is geared at interactive implementations, and stub implementations may simply return {@code false}. * - * @param resource + * @param resource the resource for which password is being requested * * @return whether to retry requesting password for a particular resource */