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 Stringstatic final Stringstatic final booleanprivate booleanprivate final AtomicReference<Iterable<KeyPair>> private intprivate AlgorithmParameterSpecprivate booleanprivate PathFields inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean
logFields inherited from interface org.apache.sshd.common.keyprovider.KeyIdentityProvider
EMPTY_KEYS_PROVIDERFields 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 TypeMethodDescriptionvoiddoReadKeyPairs(SessionContext session, NamedResource resourceKey, InputStream inputStream) protected abstract voiddoWriteKeyPair(NamedResource resourceKey, KeyPair kp, OutputStream outputStream) protected KeyPairgenerateKeyPair(String algorithm) intgetPath()booleanbooleanloadFromFile(SessionContext session, String alg, Path keyPath) loadKeys(SessionContext session) Load available keys.readKeyPairs(SessionContext session, Path keyPath, OpenOption... options) resolveKeyPairs(SessionContext session, Path keyPath) voidsetAlgorithm(String algorithm) protected voidsetFilePermissions(Path path) Restricts the file permissions such that only the owner can access the file.voidsetKeySize(int keySize) voidsetKeySpec(AlgorithmParameterSpec keySpec) voidsetOverwriteAllowed(boolean overwriteAllowed) voidvoidsetStrictFilePermissions(boolean strict) Sets whether thisAbstractGeneratorHostKeyProvidershall enforce that a newly created host key file has file access permissions that allow only the owner to access it.protected voidwriteKeyPair(KeyPair kp, Path keyPath) 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, warnMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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 -
enforceFilePermissions
private boolean enforceFilePermissions
-
-
Constructor Details
-
AbstractGeneratorHostKeyProvider
protected AbstractGeneratorHostKeyProvider()
-
-
Method Details
-
getPath
-
setPath
-
getAlgorithm
- Specified by:
getAlgorithmin interfaceAlgorithmNameProvider
-
setAlgorithm
-
getKeySize
public int getKeySize()- Specified by:
getKeySizein 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) -
hasStrictFilePermissions
public boolean hasStrictFilePermissions() -
setStrictFilePermissions
public void setStrictFilePermissions(boolean strict) Sets whether thisAbstractGeneratorHostKeyProvidershall enforce that a newly created host key file has file access permissions that allow only the owner to access it. By defaulttrue.- Parameters:
strict- whether to restrict file permissions to owner-only access
-
clearLoadedKeys
public void clearLoadedKeys() -
loadKeys
Description copied from interface:KeyIdentityProviderLoad available keys.- Specified by:
loadKeysin interfaceKeyIdentityProvider- Parameters:
session- TheSessionContextfor invoking this load command - may benullif not invoked within a session context (e.g., offline tool or session unknown).- Returns:
- an
Iterableinstance of available keys - ignored ifnull
-
resolveKeyPairs
protected Iterable<KeyPair> resolveKeyPairs(SessionContext session, Path keyPath) throws IOException, GeneralSecurityException - Throws:
IOExceptionGeneralSecurityException
-
loadFromFile
protected Iterable<KeyPair> loadFromFile(SessionContext session, String alg, Path keyPath) throws IOException, GeneralSecurityException - Throws:
IOExceptionGeneralSecurityException
-
readKeyPairs
protected Iterable<KeyPair> readKeyPairs(SessionContext session, Path keyPath, OpenOption... options) throws IOException, GeneralSecurityException - Throws:
IOExceptionGeneralSecurityException
-
doReadKeyPairs
protected Iterable<KeyPair> doReadKeyPairs(SessionContext session, NamedResource resourceKey, InputStream inputStream) throws IOException, GeneralSecurityException - Throws:
IOExceptionGeneralSecurityException
-
writeKeyPair
- Throws:
IOExceptionGeneralSecurityException
-
setFilePermissions
Restricts the file permissions such that only the owner can access the file.- Parameters:
path-Pathof a newly created (empty) host key file- Throws:
IOException- on errors
-
doWriteKeyPair
protected abstract void doWriteKeyPair(NamedResource resourceKey, KeyPair kp, OutputStream outputStream) throws IOException, GeneralSecurityException - Throws:
IOExceptionGeneralSecurityException
-
generateKeyPair
- Throws:
GeneralSecurityException
-