Class OpenSSHKeyPairResourceParser
java.lang.Object
org.apache.sshd.common.util.logging.AbstractLoggingBean
org.apache.sshd.common.config.keys.loader.AbstractKeyPairResourceParser
org.apache.sshd.common.config.keys.loader.openssh.OpenSSHKeyPairResourceParser
- All Implemented Interfaces:
KeyPairResourceLoader,KeyPairResourceParser
Basic support for OpenSSH key file(s)
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringprivate static final byte[]static final Stringprivate static final Map<Class<?>, PrivateKeyEntryDecoder<?, ?>> private static final Map<String, PrivateKeyEntryDecoder<?, ?>> static final Stringstatic final OpenSSHKeyPairResourceParserFields inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean
logFields inherited from interface org.apache.sshd.common.config.keys.loader.KeyPairResourceLoader
MAX_CIPHER_NAME_LENGTH, MAX_KEY_COMMENT_LENGTH, MAX_KEY_TYPE_NAME_LENGTH, MAX_PRIVATE_KEY_DATA_SIZE, MAX_PUBLIC_KEY_DATA_SIZEFields inherited from interface org.apache.sshd.common.config.keys.loader.KeyPairResourceParser
EMPTY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionextractKeyPairs(SessionContext session, NamedResource resourceKey, String beginMarker, String endMarker, FilePasswordProvider passwordProvider, InputStream stream, Map<String, String> headers) static PrivateKeyEntryDecoder<?, ?> getPrivateKeyEntryDecoder(Class<?> keyType) static PrivateKeyEntryDecoder<?, ?> getPrivateKeyEntryDecoder(String keyType) static PrivateKeyEntryDecoder<?, ?> static PrivateKeyEntryDecoder<?, ?> protected Map.Entry<PrivateKey, String> readPrivateKey(SessionContext session, NamedResource resourceKey, OpenSSHParserContext context, String keyType, FilePasswordProvider passwordProvider, InputStream stream) readPrivateKeys(SessionContext session, NamedResource resourceKey, OpenSSHParserContext context, Collection<? extends PublicKey> publicKeys, FilePasswordProvider passwordProvider, InputStream stream) protected PublicKeyreadPublicKey(SessionContext session, NamedResource resourceKey, OpenSSHParserContext context, InputStream stream, Map<String, String> headers) static voidregisterPrivateKeyEntryDecoder(PrivateKeyEntryDecoder<?, ?> decoder) protected OpenSSHKdfOptionsresolveKdfOptions(SessionContext session, NamedResource resourceKey, String beginMarker, String endMarker, InputStream stream, Map<String, String> headers) protected <S extends InputStream>
SvalidateStreamMagicMarker(SessionContext session, NamedResource resourceKey, S stream) Methods inherited from class org.apache.sshd.common.config.keys.loader.AbstractKeyPairResourceParser
canExtractKeyPairs, extractKeyPairs, extractKeyPairs, getBeginners, getEnders, getEndingMarkers, loadKeyPairs, separateDataLinesFromHeadersMethods 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.config.keys.loader.KeyPairResourceLoader
loadKeyPairs, loadKeyPairs, loadKeyPairs, loadKeyPairs, loadKeyPairs, loadKeyPairs, loadKeyPairs, loadKeyPairs, loadKeyPairs, loadKeyPairs, loadKeyPairs
-
Field Details
-
BEGIN_MARKER
- See Also:
-
BEGINNERS
-
END_MARKER
- See Also:
-
ENDERS
-
AUTH_MAGIC
- See Also:
-
INSTANCE
-
AUTH_MAGIC_BYTES
private static final byte[] AUTH_MAGIC_BYTES -
BY_KEY_TYPE_DECODERS_MAP
-
BY_KEY_CLASS_DECODERS_MAP
-
-
Constructor Details
-
OpenSSHKeyPairResourceParser
public OpenSSHKeyPairResourceParser()
-
-
Method Details
-
extractKeyPairs
public Collection<KeyPair> extractKeyPairs(SessionContext session, NamedResource resourceKey, String beginMarker, String endMarker, FilePasswordProvider passwordProvider, InputStream stream, Map<String, String> headers) throws IOException, GeneralSecurityException- Specified by:
extractKeyPairsin classAbstractKeyPairResourceParser- Parameters:
session- TheSessionContextfor invoking this load command - may benullif not invoked within a session context (e.g., offline tool or session unknown).resourceKey- A hint as to the origin of the text linesbeginMarker- The line containing the begin markerendMarker- The line containing the end markerpasswordProvider- TheFilePasswordProviderto use in case the data is encrypted - may benullif no encryptedstream- The decoded dataInputStreamheaders- Any headers that may have been available when data was read- Returns:
- The extracted
KeyPairs - may benull/empty if none. - Throws:
IOException- If failed to parse the dataGeneralSecurityException- If failed to generate the keys
-
resolveKdfOptions
protected OpenSSHKdfOptions resolveKdfOptions(SessionContext session, NamedResource resourceKey, String beginMarker, String endMarker, InputStream stream, Map<String, String> headers) throws IOException, GeneralSecurityException- Throws:
IOExceptionGeneralSecurityException
-
readPublicKey
protected PublicKey readPublicKey(SessionContext session, NamedResource resourceKey, OpenSSHParserContext context, InputStream stream, Map<String, String> headers) throws IOException, GeneralSecurityException- Throws:
IOExceptionGeneralSecurityException
-
readPrivateKeys
protected List<KeyPair> readPrivateKeys(SessionContext session, NamedResource resourceKey, OpenSSHParserContext context, Collection<? extends PublicKey> publicKeys, FilePasswordProvider passwordProvider, InputStream stream) throws IOException, GeneralSecurityException - Throws:
IOExceptionGeneralSecurityException
-
readPrivateKey
protected Map.Entry<PrivateKey,String> readPrivateKey(SessionContext session, NamedResource resourceKey, OpenSSHParserContext context, String keyType, FilePasswordProvider passwordProvider, InputStream stream) throws IOException, GeneralSecurityException - Throws:
IOExceptionGeneralSecurityException
-
validateStreamMagicMarker
protected <S extends InputStream> S validateStreamMagicMarker(SessionContext session, NamedResource resourceKey, S stream) throws IOException - Throws:
IOException
-
registerPrivateKeyEntryDecoder
- Parameters:
decoder- The decoder to register- Throws:
IllegalArgumentException- if no decoder or not key type or no supported names for the decoder- See Also:
-
getPrivateKeyEntryDecoder
- Parameters:
keyType- TheOpenSSHkey type string - e.g.,ssh-rsa, ssh-dss- ignored ifnull/empty- Returns:
- The registered
PrivateKeyEntryDecoderor {code null} if not found
-
getPrivateKeyEntryDecoder
- Parameters:
kp- TheKeyPairto examine - ignored ifnull- Returns:
- The matching
PrivateKeyEntryDecoderprovided both the public and private keys have the same decoder -nullif no match found - See Also:
-
getPrivateKeyEntryDecoder
- Parameters:
key- TheKey(public or private) - ignored ifnull- Returns:
- The registered
PrivateKeyEntryDecoderfor this key or {code null} if no match found - See Also:
-
getPrivateKeyEntryDecoder
- Parameters:
keyType- The keyClass- ignored ifnullor not aKeycompatible type- Returns:
- The registered
PrivateKeyEntryDecoderor {code null} if no match found
-