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.RSAPublicKey;
/** Type of key e.g. rsa, dsa */
public enum KeyType {
/** SSH identifier for RSA keys */

View File

@@ -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.
* <p/>
* 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
*/

View File

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

View File

@@ -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);

View File

@@ -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();
}

View File

@@ -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;

View File

@@ -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());

View File

@@ -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;

View File

@@ -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 <a href="http://www.ietf.org/rfc/rfc4252.txt">SSH Authentication Protocol</a>.
*
* @see net.schmizz.sshj.userauth.UserAuth
*/
/** An authentication method of the <a href="http://www.ietf.org/rfc/rfc4252.txt">SSH Authentication Protocol</a>. */
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();
}

View File

@@ -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 {
* <p/>
* 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
*/