This commit is contained in:
Shikhar Bhushan
2010-03-07 20:29:57 +01:00
parent 5e9ed80c20
commit 492a187d2f
10 changed files with 65 additions and 124 deletions

View File

@@ -21,6 +21,7 @@ import java.security.interfaces.DSAPublicKey;
import java.security.interfaces.RSAPrivateKey; import java.security.interfaces.RSAPrivateKey;
import java.security.interfaces.RSAPublicKey; import java.security.interfaces.RSAPublicKey;
/** Type of key e.g. rsa, dsa */
public enum KeyType { public enum KeyType {
/** SSH identifier for RSA keys */ /** SSH identifier for RSA keys */

View File

@@ -38,11 +38,7 @@ package net.schmizz.sshj.signature;
import java.security.PrivateKey; import java.security.PrivateKey;
import java.security.PublicKey; import java.security.PublicKey;
/** /** Signature interface for SSH used to sign or verify data. Usually wraps a {@code javax.crypto.Signature} object. */
* Signature interface for SSH used to sign or verify data.
* <p/>
* Usually wraps a javax.crypto.Signature object.
*/
public interface Signature { public interface Signature {
/** /**
@@ -55,21 +51,15 @@ public interface Signature {
void init(PublicKey pubkey, PrivateKey prvkey); void init(PublicKey pubkey, PrivateKey prvkey);
/** /**
* Compute the signature * Convenience method, same as calling {@link #update(byte[], int, int)} with offset as {@code 0} and {@code
* * H.length}.
* @return the computed signature
*/
byte[] sign();
/**
* Convenience method for {@link #update(byte[], int, int)}
* *
* @param H the byte-array to update with * @param H the byte-array to update with
*/ */
void update(byte[] H); 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 H byte-array to update with
* @param off offset within the array * @param off offset within the array
@@ -78,9 +68,16 @@ public interface Signature {
void update(byte[] H, int off, int len); 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 * @return {@code true} on successful verification, {@code false} on failure
*/ */

View File

@@ -35,7 +35,7 @@
*/ */
package net.schmizz.sshj.transport.cipher; package net.schmizz.sshj.transport.cipher;
/** AES128CBC cipher */ /** {@code aes128-cbc} cipher */
public class AES128CBC public class AES128CBC
extends BaseCipher { extends BaseCipher {

View File

@@ -43,35 +43,27 @@ public interface Cipher {
Decrypt Decrypt
} }
/** /** @return the block size for this cipher */
* Retrieves the block size for this cipher
*
* @return
*/
int getBlockSize(); int getBlockSize();
/** /** @return the size of the initialization vector */
* Retrieves the size of the initialization vector
*
* @return
*/
int getIVSize(); int getIVSize();
/** /**
* Initialize the cipher for encryption or decryption with the given private key and initialization vector * Initialize the cipher for encryption or decryption with the given private key and initialization vector
* *
* @param mode * @param mode whether this instance wil encrypt or decrypt
* @param key * @param key the key for the cipher
* @param iv * @param iv initialization vector
*/ */
void init(Mode mode, byte[] key, byte[] iv); void init(Mode mode, byte[] key, byte[] iv);
/** /**
* Performs in-place encryption or decryption on the given data. * Performs in-place encryption or decryption on the given data.
* *
* @param input * @param input the subject
* @param inputOffset * @param inputOffset offset at which to start
* @param inputLen * @param inputLen number of bytes starting at {@code inputOffset}
*/ */
void update(byte[] input, int inputOffset, int inputLen); void update(byte[] input, int inputOffset, int inputLen);

View File

@@ -18,19 +18,19 @@ package net.schmizz.sshj.userauth;
import net.schmizz.sshj.transport.Transport; import net.schmizz.sshj.transport.Transport;
/** The parameters available to authentication method */ /** The parameters available to authentication methods. */
public interface AuthParams { 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(); String getNextServiceName();
/** /**
* Retrieve the transport which will allow sending packets; retrieving information like the session-id, remote * @return the transport which will allow sending packets; retrieving information like the session-id, remote
* host/port etc. which is needed by some method. * host/port etc. which is needed by some method.
*/ */
Transport getTransport(); Transport getTransport();
/** All userauth requests need to include the username */ /** @return all userauth requests need to include the username */
String getUsername(); String getUsername();
} }

View File

@@ -12,26 +12,6 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * 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; package net.schmizz.sshj.userauth.keyprovider;
@@ -44,15 +24,27 @@ import java.security.PublicKey;
/** A KeyProvider is a container for a public-private keypair. */ /** A KeyProvider is a container for a public-private keypair. */
public interface KeyProvider { 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() PrivateKey getPrivate()
throws IOException; 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() PublicKey getPublic()
throws IOException; 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() KeyType getType()
throws IOException; throws IOException;

View File

@@ -12,26 +12,6 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * 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; package net.schmizz.sshj.userauth.keyprovider;
@@ -77,18 +57,21 @@ public class OpenSSHKeyFile
@Override @Override
public void init(File location) { public void init(File location) {
File f = new File(location + ".pub"); final File f = new File(location + ".pub");
if (f.exists()) if (f.exists())
try { try {
BufferedReader br = new BufferedReader(new FileReader(f)); final BufferedReader br = new BufferedReader(new FileReader(f));
String keydata = br.readLine(); try {
final String keydata = br.readLine();
if (keydata != null) { if (keydata != null) {
String[] parts = keydata.split(" "); String[] parts = keydata.split(" ");
assert parts.length >= 2; assert parts.length >= 2;
type = KeyType.fromString(parts[0]); type = KeyType.fromString(parts[0]);
pubKey = new Buffer.PlainBuffer(Base64.decode(parts[1])).readPublicKey(); pubKey = new Buffer.PlainBuffer(Base64.decode(parts[1])).readPublicKey();
} }
} finally {
br.close(); br.close();
}
} catch (IOException e) { } catch (IOException e) {
// let super provide both public & private key // let super provide both public & private key
log.warn("Error reading public key file: {}", e.toString()); log.warn("Error reading public key file: {}", e.toString());

View File

@@ -12,26 +12,6 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * 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; package net.schmizz.sshj.userauth.keyprovider;

View File

@@ -20,32 +20,28 @@ import net.schmizz.sshj.transport.TransportException;
import net.schmizz.sshj.userauth.AuthParams; import net.schmizz.sshj.userauth.AuthParams;
import net.schmizz.sshj.userauth.UserAuthException; import net.schmizz.sshj.userauth.UserAuthException;
/** /** An authentication method of the <a href="http://www.ietf.org/rfc/rfc4252.txt">SSH Authentication Protocol</a>. */
* An authentication method of the <a href="http://www.ietf.org/rfc/rfc4252.txt">SSH Authentication Protocol</a>.
*
* @see net.schmizz.sshj.userauth.UserAuth
*/
public interface AuthMethod public interface AuthMethod
extends SSHPacketHandler { extends SSHPacketHandler {
/** Returns assigned name of this authentication method */ /** @return assigned name of this authentication method */
String getName(); String getName();
/** /**
* Initializes this {@link AuthMethod} with the {@link AuthParams parameters} needed for authentication. This method * This method must be called before requesting authentication with this method.
* must be called before requesting authentication with this method. *
* @param params parameters needed for authentication
*/ */
void init(AuthParams params); void init(AuthParams params);
/** /**
* @throws net.schmizz.sshj.userauth.UserAuthException * @throws UserAuthException if there is an error with the request
* * @throws TransportException if there is a transport-related error
* @throws TransportException
*/ */
void request() void request()
throws UserAuthException, TransportException; throws UserAuthException, TransportException;
/** Returns whether authentication should be reattempted if it failed. */ /** @return whether authentication should be reattempted if it failed. */
boolean shouldRetry(); boolean shouldRetry();
} }

View File

@@ -15,7 +15,7 @@
*/ */
package net.schmizz.sshj.userauth.password; package net.schmizz.sshj.userauth.password;
/** An interface for servicing requests for plaintext passwords. */ /** Services requests for plaintext passwords. */
public interface PasswordFinder { public interface PasswordFinder {
/** /**
@@ -36,7 +36,7 @@ public interface PasswordFinder {
* <p/> * <p/>
* This method is geared at interactive implementations, and stub implementations may simply return {@code false}. * 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 * @return whether to retry requesting password for a particular resource
*/ */