Class OpenSSHKeyV1KeyFile
java.lang.Object
net.schmizz.sshj.userauth.keyprovider.BaseFileKeyProvider
com.hierynomus.sshj.userauth.keyprovider.OpenSSHKeyV1KeyFile
- All Implemented Interfaces:
FileKeyProvider,KeyProvider
Reads a key file in the new OpenSSH format.
The format is described in the following document: Key Protocol
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final byte[]static final Stringprivate static final Stringprivate static final Stringprotected final org.slf4j.Loggerprivate static final Stringstatic final Stringprivate PublicKeyprivate static final Map<String, Factory.Named<Cipher>> Fields inherited from class net.schmizz.sshj.userauth.keyprovider.BaseFileKeyProvider
kp, pwdf, resource, type -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate booleancheckHeader(BufferedReader reader) private CiphercreateCipher(String cipherName) private PrivateKeycreateECDSAPrivateKey(KeyType kt, Buffer.PlainBuffer buffer, ECDSACurve ecdsaCurve) private Buffer.PlainBufferdecryptPrivateKey(byte[] privateKey, int privateKeyLength, String cipherName, String kdfName, byte[] kdfOptions) voidinit(File location, PasswordFinder pwdf) voidinit(Reader privateKey, Reader publicKey, PasswordFinder pwdf) voidinit(String privateKey, String publicKey, PasswordFinder pwdf) private voidinitializeCipher(String kdfName, byte[] kdfOptions, Cipher cipher) private voidinitPubKey(Reader publicKey) private KeyPairreadDecodedKeyPair(Buffer.PlainBuffer keyBuffer) private StringreadEncodedKey(BufferedReader reader) private byte[]readEncryptedPrivateKey(byte[] privateKeyEncoded, Buffer.PlainBuffer inputBuffer) protected KeyPairprivate PublicKeyreadPublicKey(Buffer.PlainBuffer plainBuffer) private RSAPrivateCrtKeySpecRead RSA Private CRT Key Spec according to OpenSSH sshkey_private_deserialize in sshkey.cprivate KeyPairreadUnencrypted(Buffer.PlainBuffer keyBuffer, PublicKey publicKey) Methods inherited from class net.schmizz.sshj.userauth.keyprovider.BaseFileKeyProvider
getPrivate, getType, init, init, init, init, init
-
Field Details
-
BEGIN
- See Also:
-
END
- See Also:
-
AUTH_MAGIC
private static final byte[] AUTH_MAGIC -
OPENSSH_PRIVATE_KEY
- See Also:
-
BCRYPT
- See Also:
-
NONE_CIPHER
- See Also:
-
SUPPORTED_CIPHERS
-
pubKey
-
log
protected final org.slf4j.Logger log
-
-
Constructor Details
-
OpenSSHKeyV1KeyFile
public OpenSSHKeyV1KeyFile()
-
-
Method Details
-
getPublic
- Specified by:
getPublicin interfaceKeyProvider- Overrides:
getPublicin classBaseFileKeyProvider- Returns:
- the public key.
- Throws:
IOException- if there is an I/O error retrieving the public key
-
init
- Specified by:
initin interfaceFileKeyProvider- Overrides:
initin classBaseFileKeyProvider
-
init
- Specified by:
initin interfaceFileKeyProvider- Overrides:
initin classBaseFileKeyProvider
-
init
- Specified by:
initin interfaceFileKeyProvider- Overrides:
initin classBaseFileKeyProvider
-
readKeyPair
- Specified by:
readKeyPairin classBaseFileKeyProvider- Throws:
IOException
-
initPubKey
- Throws:
IOException
-
readDecodedKeyPair
private KeyPair readDecodedKeyPair(Buffer.PlainBuffer keyBuffer) throws IOException, GeneralSecurityException - Throws:
IOExceptionGeneralSecurityException
-
readEncryptedPrivateKey
private byte[] readEncryptedPrivateKey(byte[] privateKeyEncoded, Buffer.PlainBuffer inputBuffer) throws Buffer.BufferException - Throws:
Buffer.BufferException
-
decryptPrivateKey
private Buffer.PlainBuffer decryptPrivateKey(byte[] privateKey, int privateKeyLength, String cipherName, String kdfName, byte[] kdfOptions) throws IOException - Throws:
IOException
-
initializeCipher
private void initializeCipher(String kdfName, byte[] kdfOptions, Cipher cipher) throws Buffer.BufferException - Throws:
Buffer.BufferException
-
createCipher
-
readPublicKey
private PublicKey readPublicKey(Buffer.PlainBuffer plainBuffer) throws Buffer.BufferException, GeneralSecurityException -
readEncodedKey
- Throws:
IOException
-
checkHeader
- Throws:
IOException
-
readUnencrypted
private KeyPair readUnencrypted(Buffer.PlainBuffer keyBuffer, PublicKey publicKey) throws IOException, GeneralSecurityException - Throws:
IOExceptionGeneralSecurityException
-
createECDSAPrivateKey
private PrivateKey createECDSAPrivateKey(KeyType kt, Buffer.PlainBuffer buffer, ECDSACurve ecdsaCurve) throws GeneralSecurityException, Buffer.BufferException -
readRsaPrivateKeySpec
private RSAPrivateCrtKeySpec readRsaPrivateKeySpec(Buffer.PlainBuffer buffer) throws Buffer.BufferException Read RSA Private CRT Key Spec according to OpenSSH sshkey_private_deserialize in sshkey.c- Parameters:
buffer- Buffer- Returns:
- RSA Private CRT Key Specification
- Throws:
Buffer.BufferException- Thrown on failure to read from buffer
-