Add provider with reader resource.

This commit is contained in:
David Kocher
2014-05-06 21:22:12 +02:00
parent 60d54fa5de
commit 896b0ea288
4 changed files with 67 additions and 5 deletions

View File

@@ -39,10 +39,10 @@ public class OpenSSHKeyFile
extends PKCS8KeyFile {
public static class Factory
implements net.schmizz.sshj.common.Factory.Named<FileKeyProvider> {
implements net.schmizz.sshj.common.Factory.Named<KeyProvider> {
@Override
public FileKeyProvider create() {
public KeyProvider create() {
return new OpenSSHKeyFile();
}

View File

@@ -17,6 +17,7 @@ package net.schmizz.sshj.userauth.keyprovider;
import java.io.File;
import java.io.IOException;
import java.io.Reader;
import java.security.KeyPair;
import java.security.PrivateKey;
import java.security.PublicKey;
@@ -26,6 +27,7 @@ import net.schmizz.sshj.common.KeyType;
import net.schmizz.sshj.userauth.password.PasswordFinder;
import net.schmizz.sshj.userauth.password.PasswordUtils;
import net.schmizz.sshj.userauth.password.PrivateKeyFileResource;
import net.schmizz.sshj.userauth.password.PrivateKeyReaderResource;
import net.schmizz.sshj.userauth.password.PrivateKeyStringResource;
import net.schmizz.sshj.userauth.password.Resource;
@@ -41,13 +43,13 @@ import org.slf4j.LoggerFactory;
/** Represents a PKCS8-encoded key file. This is the format used by OpenSSH and OpenSSL. */
public class PKCS8KeyFile
implements FileKeyProvider {
implements FileKeyProvider, ReaderKeyProvider {
public static class Factory
implements net.schmizz.sshj.common.Factory.Named<FileKeyProvider> {
implements net.schmizz.sshj.common.Factory.Named<KeyProvider> {
@Override
public FileKeyProvider create() {
public KeyProvider create() {
return new PKCS8KeyFile();
}
@@ -84,6 +86,18 @@ public class PKCS8KeyFile
return type != null ? type : (type = KeyType.fromKey(getPublic()));
}
@Override
public void init(Reader location) {
assert location != null;
resource = new PrivateKeyReaderResource(location);
}
@Override
public void init(Reader location, PasswordFinder pwdf) {
init(location);
this.pwdf = pwdf;
}
@Override
public void init(File location) {
assert location != null;

View File

@@ -0,0 +1,15 @@
package net.schmizz.sshj.userauth.keyprovider;
import java.io.Reader;
import net.schmizz.sshj.userauth.password.PasswordFinder;
/**
* @version $Id:$
*/
public interface ReaderKeyProvider extends KeyProvider {
void init(Reader location);
void init(Reader location, PasswordFinder pwdf);
}

View File

@@ -0,0 +1,33 @@
/*
* Copyright 2010-2012 sshj contributors
*
* Licensed 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.password;
import java.io.IOException;
import java.io.Reader;
public class PrivateKeyReaderResource
extends Resource<Reader> {
public PrivateKeyReaderResource(Reader privateKeyFile) {
super(privateKeyFile);
}
@Override
public Reader getReader()
throws IOException {
return getDetail();
}
}