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
public class OpenSSHKeyPairResourceParser extends AbstractKeyPairResourceParser
Basic support for OpenSSH key file(s)
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringAUTH_MAGICprivate static byte[]AUTH_MAGIC_BYTESstatic java.lang.StringBEGIN_MARKERstatic java.util.List<java.lang.String>BEGINNERSprivate static java.util.Map<java.lang.Class<?>,PrivateKeyEntryDecoder<?,?>>BY_KEY_CLASS_DECODERS_MAPprivate static java.util.Map<java.lang.String,PrivateKeyEntryDecoder<?,?>>BY_KEY_TYPE_DECODERS_MAPstatic java.lang.StringEND_MARKERstatic java.util.List<java.lang.String>ENDERSstatic OpenSSHKeyPairResourceParserINSTANCE-
Fields inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean
log
-
Fields 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_SIZE
-
Fields inherited from interface org.apache.sshd.common.config.keys.loader.KeyPairResourceParser
EMPTY
-
-
Constructor Summary
Constructors Constructor Description OpenSSHKeyPairResourceParser()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Collection<java.security.KeyPair>extractKeyPairs(SessionContext session, NamedResource resourceKey, java.lang.String beginMarker, java.lang.String endMarker, FilePasswordProvider passwordProvider, java.io.InputStream stream, java.util.Map<java.lang.String,java.lang.String> headers)static PrivateKeyEntryDecoder<?,?>getPrivateKeyEntryDecoder(java.lang.Class<?> keyType)static PrivateKeyEntryDecoder<?,?>getPrivateKeyEntryDecoder(java.lang.String keyType)static PrivateKeyEntryDecoder<?,?>getPrivateKeyEntryDecoder(java.security.Key key)static PrivateKeyEntryDecoder<?,?>getPrivateKeyEntryDecoder(java.security.KeyPair kp)protected java.util.Map.Entry<java.security.PrivateKey,java.lang.String>readPrivateKey(SessionContext session, NamedResource resourceKey, OpenSSHParserContext context, java.lang.String keyType, FilePasswordProvider passwordProvider, java.io.InputStream stream)protected java.util.List<java.security.KeyPair>readPrivateKeys(SessionContext session, NamedResource resourceKey, OpenSSHParserContext context, java.util.Collection<? extends java.security.PublicKey> publicKeys, FilePasswordProvider passwordProvider, java.io.InputStream stream)protected java.security.PublicKeyreadPublicKey(SessionContext session, NamedResource resourceKey, OpenSSHParserContext context, java.io.InputStream stream, java.util.Map<java.lang.String,java.lang.String> headers)static voidregisterPrivateKeyEntryDecoder(PrivateKeyEntryDecoder<?,?> decoder)protected OpenSSHKdfOptionsresolveKdfOptions(SessionContext session, NamedResource resourceKey, java.lang.String beginMarker, java.lang.String endMarker, java.io.InputStream stream, java.util.Map<java.lang.String,java.lang.String> headers)protected <S extends java.io.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, separateDataLinesFromHeaders
-
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.config.keys.loader.KeyPairResourceLoader
loadKeyPairs, loadKeyPairs, loadKeyPairs, loadKeyPairs, loadKeyPairs, loadKeyPairs, loadKeyPairs, loadKeyPairs, loadKeyPairs, loadKeyPairs, loadKeyPairs
-
-
-
-
Field Detail
-
BEGIN_MARKER
public static final java.lang.String BEGIN_MARKER
- See Also:
- Constant Field Values
-
BEGINNERS
public static final java.util.List<java.lang.String> BEGINNERS
-
END_MARKER
public static final java.lang.String END_MARKER
- See Also:
- Constant Field Values
-
ENDERS
public static final java.util.List<java.lang.String> ENDERS
-
AUTH_MAGIC
public static final java.lang.String AUTH_MAGIC
- See Also:
- Constant Field Values
-
INSTANCE
public static final OpenSSHKeyPairResourceParser INSTANCE
-
AUTH_MAGIC_BYTES
private static final byte[] AUTH_MAGIC_BYTES
-
BY_KEY_TYPE_DECODERS_MAP
private static final java.util.Map<java.lang.String,PrivateKeyEntryDecoder<?,?>> BY_KEY_TYPE_DECODERS_MAP
-
BY_KEY_CLASS_DECODERS_MAP
private static final java.util.Map<java.lang.Class<?>,PrivateKeyEntryDecoder<?,?>> BY_KEY_CLASS_DECODERS_MAP
-
-
Method Detail
-
extractKeyPairs
public java.util.Collection<java.security.KeyPair> extractKeyPairs(SessionContext session, NamedResource resourceKey, java.lang.String beginMarker, java.lang.String endMarker, FilePasswordProvider passwordProvider, java.io.InputStream stream, java.util.Map<java.lang.String,java.lang.String> headers) throws java.io.IOException, java.security.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:
java.io.IOException- If failed to parse the datajava.security.GeneralSecurityException- If failed to generate the keys
-
resolveKdfOptions
protected OpenSSHKdfOptions resolveKdfOptions(SessionContext session, NamedResource resourceKey, java.lang.String beginMarker, java.lang.String endMarker, java.io.InputStream stream, java.util.Map<java.lang.String,java.lang.String> headers) throws java.io.IOException, java.security.GeneralSecurityException
- Throws:
java.io.IOExceptionjava.security.GeneralSecurityException
-
readPublicKey
protected java.security.PublicKey readPublicKey(SessionContext session, NamedResource resourceKey, OpenSSHParserContext context, java.io.InputStream stream, java.util.Map<java.lang.String,java.lang.String> headers) throws java.io.IOException, java.security.GeneralSecurityException
- Throws:
java.io.IOExceptionjava.security.GeneralSecurityException
-
readPrivateKeys
protected java.util.List<java.security.KeyPair> readPrivateKeys(SessionContext session, NamedResource resourceKey, OpenSSHParserContext context, java.util.Collection<? extends java.security.PublicKey> publicKeys, FilePasswordProvider passwordProvider, java.io.InputStream stream) throws java.io.IOException, java.security.GeneralSecurityException
- Throws:
java.io.IOExceptionjava.security.GeneralSecurityException
-
readPrivateKey
protected java.util.Map.Entry<java.security.PrivateKey,java.lang.String> readPrivateKey(SessionContext session, NamedResource resourceKey, OpenSSHParserContext context, java.lang.String keyType, FilePasswordProvider passwordProvider, java.io.InputStream stream) throws java.io.IOException, java.security.GeneralSecurityException
- Throws:
java.io.IOExceptionjava.security.GeneralSecurityException
-
validateStreamMagicMarker
protected <S extends java.io.InputStream> S validateStreamMagicMarker(SessionContext session, NamedResource resourceKey, S stream) throws java.io.IOException
- Throws:
java.io.IOException
-
registerPrivateKeyEntryDecoder
public static void registerPrivateKeyEntryDecoder(PrivateKeyEntryDecoder<?,?> decoder)
- Parameters:
decoder- The decoder to register- Throws:
java.lang.IllegalArgumentException- if no decoder or not key type or no supported names for the decoder- See Also:
IdentityResourceLoader.getPublicKeyType(),KeyTypeNamesSupport.getSupportedKeyTypes()
-
getPrivateKeyEntryDecoder
public static PrivateKeyEntryDecoder<?,?> getPrivateKeyEntryDecoder(java.lang.String keyType)
- Parameters:
keyType- TheOpenSSHkey type string - e.g.,ssh-rsa, ssh-dss- ignored ifnull/empty- Returns:
- The registered
PrivateKeyEntryDecoderor {code null} if not found
-
getPrivateKeyEntryDecoder
public static PrivateKeyEntryDecoder<?,?> getPrivateKeyEntryDecoder(java.security.KeyPair kp)
- 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(Key)
-
getPrivateKeyEntryDecoder
public static PrivateKeyEntryDecoder<?,?> getPrivateKeyEntryDecoder(java.security.Key key)
- Parameters:
key- TheKey(public or private) - ignored ifnull- Returns:
- The registered
PrivateKeyEntryDecoderfor this key or {code null} if no match found - See Also:
getPrivateKeyEntryDecoder(Class)
-
getPrivateKeyEntryDecoder
public static PrivateKeyEntryDecoder<?,?> getPrivateKeyEntryDecoder(java.lang.Class<?> keyType)
- Parameters:
keyType- The keyClass- ignored ifnullor not aKeycompatible type- Returns:
- The registered
PrivateKeyEntryDecoderor {code null} if no match found
-
-