Class AbstractGeneratorHostKeyProvider
java.lang.Object
org.apache.sshd.common.util.logging.AbstractLoggingBean
org.apache.sshd.common.keyprovider.AbstractKeyPairProvider
org.apache.sshd.server.keyprovider.AbstractGeneratorHostKeyProvider
- All Implemented Interfaces:
AlgorithmNameProvider
,KeyIdentityProvider
,KeyPairProvider
,KeySizeIndicator
- Direct Known Subclasses:
BouncyCastleGeneratorHostKeyProvider
,SimpleGeneratorHostKeyProvider
public abstract class AbstractGeneratorHostKeyProvider
extends AbstractKeyPairProvider
implements AlgorithmNameProvider, KeySizeIndicator
Holds a single
KeyPair
which is generated the 1st time loadKeys(SessionContext)
is called. If
there is a file backing it up and the file exists, the key is loaded from it. Otherwise a new key pair is generated
and saved (provided a path is configured and isOverwriteAllowed()
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate String
static final String
static final boolean
private final AtomicReference<Iterable<KeyPair>>
private int
private AlgorithmParameterSpec
private boolean
private Path
Fields inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean
log
Fields inherited from interface org.apache.sshd.common.keyprovider.KeyIdentityProvider
EMPTY_KEYS_PROVIDER
Fields inherited from interface org.apache.sshd.common.keyprovider.KeyPairProvider
ECDSA_SHA2_NISTP256, ECDSA_SHA2_NISTP384, ECDSA_SHA2_NISTP521, EMPTY_KEYPAIR_PROVIDER, SSH_DSS, SSH_DSS_CERT, SSH_ECDSA_SHA2_NISTP256_CERT, SSH_ECDSA_SHA2_NISTP384_CERT, SSH_ECDSA_SHA2_NISTP521_CERT, SSH_ED25519, SSH_ED25519_CERT, SSH_RSA, SSH_RSA_CERT
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
doReadKeyPairs
(SessionContext session, NamedResource resourceKey, InputStream inputStream) protected abstract void
doWriteKeyPair
(NamedResource resourceKey, KeyPair kp, OutputStream outputStream) protected KeyPair
generateKeyPair
(String algorithm) int
getPath()
boolean
loadFromFile
(SessionContext session, String alg, Path keyPath) loadKeys
(SessionContext session) Load available keys.readKeyPairs
(SessionContext session, Path keyPath, OpenOption... options) resolveKeyPairs
(SessionContext session, Path keyPath) void
setAlgorithm
(String algorithm) void
setKeySize
(int keySize) void
setKeySpec
(AlgorithmParameterSpec keySpec) void
setOverwriteAllowed
(boolean overwriteAllowed) void
protected void
writeKeyPair
(KeyPair kp, Path keyPath, OpenOption... options) Methods inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean
debug, debug, debug, debug, debug, error, error, error, error, error, getSimplifiedLogger, info, info, warn, warn, warn, warn, warn, warn, warn, warn
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.apache.sshd.common.keyprovider.KeyPairProvider
getKeyTypes, loadKey
-
Field Details
-
DEFAULT_ALGORITHM
- See Also:
-
DEFAULT_ALLOWED_TO_OVERWRITE
public static final boolean DEFAULT_ALLOWED_TO_OVERWRITE- See Also:
-
keyPairHolder
-
path
-
algorithm
-
keySize
private int keySize -
keySpec
-
overwriteAllowed
private boolean overwriteAllowed
-
-
Constructor Details
-
AbstractGeneratorHostKeyProvider
protected AbstractGeneratorHostKeyProvider()
-
-
Method Details
-
getPath
-
setPath
-
getAlgorithm
- Specified by:
getAlgorithm
in interfaceAlgorithmNameProvider
-
setAlgorithm
-
getKeySize
public int getKeySize()- Specified by:
getKeySize
in interfaceKeySizeIndicator
- Returns:
- The number of bits used in the key
-
setKeySize
public void setKeySize(int keySize) -
getKeySpec
-
setKeySpec
-
isOverwriteAllowed
public boolean isOverwriteAllowed() -
setOverwriteAllowed
public void setOverwriteAllowed(boolean overwriteAllowed) -
clearLoadedKeys
public void clearLoadedKeys() -
loadKeys
Description copied from interface:KeyIdentityProvider
Load available keys.- Specified by:
loadKeys
in interfaceKeyIdentityProvider
- Parameters:
session
- TheSessionContext
for invoking this load command - may benull
if not invoked within a session context (e.g., offline tool or session unknown).- Returns:
- an
Iterable
instance of available keys - ignored ifnull
-
resolveKeyPairs
protected Iterable<KeyPair> resolveKeyPairs(SessionContext session, Path keyPath) throws IOException, GeneralSecurityException - Throws:
IOException
GeneralSecurityException
-
loadFromFile
protected Iterable<KeyPair> loadFromFile(SessionContext session, String alg, Path keyPath) throws IOException, GeneralSecurityException - Throws:
IOException
GeneralSecurityException
-
readKeyPairs
protected Iterable<KeyPair> readKeyPairs(SessionContext session, Path keyPath, OpenOption... options) throws IOException, GeneralSecurityException - Throws:
IOException
GeneralSecurityException
-
doReadKeyPairs
protected Iterable<KeyPair> doReadKeyPairs(SessionContext session, NamedResource resourceKey, InputStream inputStream) throws IOException, GeneralSecurityException - Throws:
IOException
GeneralSecurityException
-
writeKeyPair
protected void writeKeyPair(KeyPair kp, Path keyPath, OpenOption... options) throws IOException, GeneralSecurityException - Throws:
IOException
GeneralSecurityException
-
doWriteKeyPair
protected abstract void doWriteKeyPair(NamedResource resourceKey, KeyPair kp, OutputStream outputStream) throws IOException, GeneralSecurityException - Throws:
IOException
GeneralSecurityException
-
generateKeyPair
- Throws:
GeneralSecurityException
-