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)- Author:
- Apache MINA SSHD Project
-
-
Field Summary
Fields Modifier and Type Field Description static StringAUTH_MAGICstatic StringBEGIN_MARKERstatic List<String>BEGINNERSstatic StringEND_MARKERstatic List<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
-
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 String BEGIN_MARKER
- See Also:
- Constant Field Values
-
END_MARKER
public static final String END_MARKER
- See Also:
- Constant Field Values
-
AUTH_MAGIC
public static final String AUTH_MAGIC
- See Also:
- Constant Field Values
-
INSTANCE
public static final OpenSSHKeyPairResourceParser INSTANCE
-
-
Method Detail
-
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
public static void registerPrivateKeyEntryDecoder(PrivateKeyEntryDecoder<?,?> decoder)
- Parameters:
decoder- The decoder to register- Throws:
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(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(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(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(Class<?> keyType)
- Parameters:
keyType- The keyClass- ignored ifnullor not aKeycompatible type- Returns:
- The registered
PrivateKeyEntryDecoderor {code null} if no match found
-
-