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: https://github.com/openssh/openssh-portable/blob/master/PROTOCOL.key
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final byte[]
static final String
private static final String
private static final String
protected final org.slf4j.Logger
private static final String
static final String
private PublicKey
private 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 boolean
checkHeader
(BufferedReader reader) private Cipher
createCipher
(String cipherName) private PrivateKey
createECDSAPrivateKey
(KeyType kt, Buffer.PlainBuffer buffer, String name) private Buffer.PlainBuffer
decryptPrivateKey
(byte[] privateKey, int privateKeyLength, String cipherName, String kdfName, byte[] kdfOptions) void
private void
initializeCipher
(String kdfName, byte[] kdfOptions, Cipher cipher) private void
initPubKey
(Reader publicKey) private KeyPair
readDecodedKeyPair
(Buffer.PlainBuffer keyBuffer) private String
readEncodedKey
(BufferedReader reader) private byte[]
readEncryptedPrivateKey
(byte[] privateKeyEncoded, Buffer.PlainBuffer inputBuffer) protected KeyPair
private PublicKey
readPublicKey
(Buffer.PlainBuffer plainBuffer) private RSAPrivateCrtKeySpec
Read RSA Private CRT Key Spec according to OpenSSH sshkey_private_deserialize in sshkey.cprivate KeyPair
readUnencrypted
(Buffer.PlainBuffer keyBuffer, PublicKey publicKey) Methods inherited from class net.schmizz.sshj.userauth.keyprovider.BaseFileKeyProvider
getPrivate, getPublic, 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
-
init
- Specified by:
init
in interfaceFileKeyProvider
- Overrides:
init
in classBaseFileKeyProvider
-
readKeyPair
- Specified by:
readKeyPair
in classBaseFileKeyProvider
- Throws:
IOException
-
initPubKey
- Throws:
IOException
-
readDecodedKeyPair
private KeyPair readDecodedKeyPair(Buffer.PlainBuffer keyBuffer) throws IOException, GeneralSecurityException - Throws:
IOException
GeneralSecurityException
-
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:
IOException
GeneralSecurityException
-
createECDSAPrivateKey
private PrivateKey createECDSAPrivateKey(KeyType kt, Buffer.PlainBuffer buffer, String name) 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
-