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 singleKeyPair
which is generated the 1st timeloadKeys(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 andisOverwriteAllowed()
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.String
algorithm
static java.lang.String
DEFAULT_ALGORITHM
static boolean
DEFAULT_ALLOWED_TO_OVERWRITE
private java.util.concurrent.atomic.AtomicReference<java.lang.Iterable<java.security.KeyPair>>
keyPairHolder
private int
keySize
private java.security.spec.AlgorithmParameterSpec
keySpec
private boolean
overwriteAllowed
private java.nio.file.Path
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_ED25519, SSH_RSA
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractGeneratorHostKeyProvider()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
clearLoadedKeys()
protected java.lang.Iterable<java.security.KeyPair>
doReadKeyPairs(SessionContext session, NamedResource resourceKey, java.io.InputStream inputStream)
protected abstract void
doWriteKeyPair(NamedResource resourceKey, java.security.KeyPair kp, java.io.OutputStream outputStream)
protected java.security.KeyPair
generateKeyPair(java.lang.String algorithm)
java.lang.String
getAlgorithm()
int
getKeySize()
java.security.spec.AlgorithmParameterSpec
getKeySpec()
java.nio.file.Path
getPath()
boolean
isOverwriteAllowed()
protected java.lang.Iterable<java.security.KeyPair>
loadFromFile(SessionContext session, java.lang.String alg, java.nio.file.Path keyPath)
java.util.List<java.security.KeyPair>
loadKeys(SessionContext session)
Load available keys.protected java.lang.Iterable<java.security.KeyPair>
readKeyPairs(SessionContext session, java.nio.file.Path keyPath, java.nio.file.OpenOption... options)
protected java.lang.Iterable<java.security.KeyPair>
resolveKeyPairs(SessionContext session, java.nio.file.Path keyPath)
void
setAlgorithm(java.lang.String algorithm)
void
setKeySize(int keySize)
void
setKeySpec(java.security.spec.AlgorithmParameterSpec keySpec)
void
setOverwriteAllowed(boolean overwriteAllowed)
void
setPath(java.nio.file.Path path)
protected void
writeKeyPair(java.security.KeyPair kp, java.nio.file.Path keyPath, java.nio.file.OpenOption... options)
-
Methods inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean
getSimplifiedLogger
-
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 Detail
-
DEFAULT_ALGORITHM
public static final java.lang.String DEFAULT_ALGORITHM
- See Also:
- Constant Field Values
-
DEFAULT_ALLOWED_TO_OVERWRITE
public static final boolean DEFAULT_ALLOWED_TO_OVERWRITE
- See Also:
- Constant Field Values
-
keyPairHolder
private final java.util.concurrent.atomic.AtomicReference<java.lang.Iterable<java.security.KeyPair>> keyPairHolder
-
path
private java.nio.file.Path path
-
algorithm
private java.lang.String algorithm
-
keySize
private int keySize
-
keySpec
private java.security.spec.AlgorithmParameterSpec keySpec
-
overwriteAllowed
private boolean overwriteAllowed
-
-
Method Detail
-
getPath
public java.nio.file.Path getPath()
-
setPath
public void setPath(java.nio.file.Path path)
-
getAlgorithm
public java.lang.String getAlgorithm()
- Specified by:
getAlgorithm
in interfaceAlgorithmNameProvider
-
setAlgorithm
public void setAlgorithm(java.lang.String algorithm)
-
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
public java.security.spec.AlgorithmParameterSpec getKeySpec()
-
setKeySpec
public void setKeySpec(java.security.spec.AlgorithmParameterSpec keySpec)
-
isOverwriteAllowed
public boolean isOverwriteAllowed()
-
setOverwriteAllowed
public void setOverwriteAllowed(boolean overwriteAllowed)
-
clearLoadedKeys
public void clearLoadedKeys()
-
loadKeys
public java.util.List<java.security.KeyPair> loadKeys(SessionContext session)
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 java.lang.Iterable<java.security.KeyPair> resolveKeyPairs(SessionContext session, java.nio.file.Path keyPath) throws java.io.IOException, java.security.GeneralSecurityException
- Throws:
java.io.IOException
java.security.GeneralSecurityException
-
loadFromFile
protected java.lang.Iterable<java.security.KeyPair> loadFromFile(SessionContext session, java.lang.String alg, java.nio.file.Path keyPath) throws java.io.IOException, java.security.GeneralSecurityException
- Throws:
java.io.IOException
java.security.GeneralSecurityException
-
readKeyPairs
protected java.lang.Iterable<java.security.KeyPair> readKeyPairs(SessionContext session, java.nio.file.Path keyPath, java.nio.file.OpenOption... options) throws java.io.IOException, java.security.GeneralSecurityException
- Throws:
java.io.IOException
java.security.GeneralSecurityException
-
doReadKeyPairs
protected java.lang.Iterable<java.security.KeyPair> doReadKeyPairs(SessionContext session, NamedResource resourceKey, java.io.InputStream inputStream) throws java.io.IOException, java.security.GeneralSecurityException
- Throws:
java.io.IOException
java.security.GeneralSecurityException
-
writeKeyPair
protected void writeKeyPair(java.security.KeyPair kp, java.nio.file.Path keyPath, java.nio.file.OpenOption... options) throws java.io.IOException, java.security.GeneralSecurityException
- Throws:
java.io.IOException
java.security.GeneralSecurityException
-
doWriteKeyPair
protected abstract void doWriteKeyPair(NamedResource resourceKey, java.security.KeyPair kp, java.io.OutputStream outputStream) throws java.io.IOException, java.security.GeneralSecurityException
- Throws:
java.io.IOException
java.security.GeneralSecurityException
-
generateKeyPair
protected java.security.KeyPair generateKeyPair(java.lang.String algorithm) throws java.security.GeneralSecurityException
- Throws:
java.security.GeneralSecurityException
-
-