Class OpenSSHKeyV1KeyFile
- java.lang.Object
-
- net.schmizz.sshj.userauth.keyprovider.BaseFileKeyProvider
-
- com.hierynomus.sshj.userauth.keyprovider.OpenSSHKeyV1KeyFile
-
- All Implemented Interfaces:
FileKeyProvider
,KeyProvider
public class OpenSSHKeyV1KeyFile extends BaseFileKeyProvider
Reads a key file in the new OpenSSH format. The format is described in the following document: Key Protocol
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
OpenSSHKeyV1KeyFile.Factory
-
Field Summary
Fields Modifier and Type Field Description private static byte[]
AUTH_MAGIC
static java.lang.String
BCRYPT
private static java.lang.String
BEGIN
private static java.lang.String
END
protected org.slf4j.Logger
log
private static java.lang.String
NONE_CIPHER
static java.lang.String
OPENSSH_PRIVATE_KEY
private java.security.PublicKey
pubKey
private static java.util.Map<java.lang.String,Factory.Named<Cipher>>
SUPPORTED_CIPHERS
-
Fields inherited from class net.schmizz.sshj.userauth.keyprovider.BaseFileKeyProvider
kp, pwdf, resource, type
-
-
Constructor Summary
Constructors Constructor Description OpenSSHKeyV1KeyFile()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private boolean
checkHeader(java.io.BufferedReader reader)
private Cipher
createCipher(java.lang.String cipherName)
private java.security.PrivateKey
createECDSAPrivateKey(KeyType kt, Buffer.PlainBuffer buffer, ECDSACurve ecdsaCurve)
private Buffer.PlainBuffer
decryptPrivateKey(byte[] privateKey, int privateKeyLength, java.lang.String cipherName, java.lang.String kdfName, byte[] kdfOptions)
java.security.PublicKey
getPublic()
void
init(java.io.File location, PasswordFinder pwdf)
void
init(java.io.Reader privateKey, java.io.Reader publicKey, PasswordFinder pwdf)
void
init(java.lang.String privateKey, java.lang.String publicKey, PasswordFinder pwdf)
private void
initializeCipher(java.lang.String kdfName, byte[] kdfOptions, Cipher cipher)
private void
initPubKey(java.io.Reader publicKey)
private java.security.KeyPair
readDecodedKeyPair(Buffer.PlainBuffer keyBuffer)
private java.lang.String
readEncodedKey(java.io.BufferedReader reader)
private byte[]
readEncryptedPrivateKey(byte[] privateKeyEncoded, Buffer.PlainBuffer inputBuffer)
protected java.security.KeyPair
readKeyPair()
private java.security.PublicKey
readPublicKey(Buffer.PlainBuffer plainBuffer)
private java.security.spec.RSAPrivateCrtKeySpec
readRsaPrivateKeySpec(Buffer.PlainBuffer buffer)
Read RSA Private CRT Key Spec according to OpenSSH sshkey_private_deserialize in sshkey.cprivate java.security.KeyPair
readUnencrypted(Buffer.PlainBuffer keyBuffer, java.security.PublicKey publicKey)
-
Methods inherited from class net.schmizz.sshj.userauth.keyprovider.BaseFileKeyProvider
getPrivate, getType, init, init, init, init, init
-
-
-
-
Field Detail
-
BEGIN
private static final java.lang.String BEGIN
- See Also:
- Constant Field Values
-
END
private static final java.lang.String END
- See Also:
- Constant Field Values
-
AUTH_MAGIC
private static final byte[] AUTH_MAGIC
-
OPENSSH_PRIVATE_KEY
public static final java.lang.String OPENSSH_PRIVATE_KEY
- See Also:
- Constant Field Values
-
BCRYPT
public static final java.lang.String BCRYPT
- See Also:
- Constant Field Values
-
NONE_CIPHER
private static final java.lang.String NONE_CIPHER
- See Also:
- Constant Field Values
-
SUPPORTED_CIPHERS
private static final java.util.Map<java.lang.String,Factory.Named<Cipher>> SUPPORTED_CIPHERS
-
pubKey
private java.security.PublicKey pubKey
-
log
protected final org.slf4j.Logger log
-
-
Method Detail
-
getPublic
public java.security.PublicKey getPublic() throws java.io.IOException
- Specified by:
getPublic
in interfaceKeyProvider
- Overrides:
getPublic
in classBaseFileKeyProvider
- Returns:
- the public key.
- Throws:
java.io.IOException
- if there is an I/O error retrieving the public key
-
init
public void init(java.io.File location, PasswordFinder pwdf)
- Specified by:
init
in interfaceFileKeyProvider
- Overrides:
init
in classBaseFileKeyProvider
-
init
public void init(java.lang.String privateKey, java.lang.String publicKey, PasswordFinder pwdf)
- Specified by:
init
in interfaceFileKeyProvider
- Overrides:
init
in classBaseFileKeyProvider
-
init
public void init(java.io.Reader privateKey, java.io.Reader publicKey, PasswordFinder pwdf)
- Specified by:
init
in interfaceFileKeyProvider
- Overrides:
init
in classBaseFileKeyProvider
-
readKeyPair
protected java.security.KeyPair readKeyPair() throws java.io.IOException
- Specified by:
readKeyPair
in classBaseFileKeyProvider
- Throws:
java.io.IOException
-
initPubKey
private void initPubKey(java.io.Reader publicKey) throws java.io.IOException
- Throws:
java.io.IOException
-
readDecodedKeyPair
private java.security.KeyPair readDecodedKeyPair(Buffer.PlainBuffer keyBuffer) throws java.io.IOException, java.security.GeneralSecurityException
- Throws:
java.io.IOException
java.security.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, java.lang.String cipherName, java.lang.String kdfName, byte[] kdfOptions) throws java.io.IOException
- Throws:
java.io.IOException
-
initializeCipher
private void initializeCipher(java.lang.String kdfName, byte[] kdfOptions, Cipher cipher) throws Buffer.BufferException
- Throws:
Buffer.BufferException
-
createCipher
private Cipher createCipher(java.lang.String cipherName)
-
readPublicKey
private java.security.PublicKey readPublicKey(Buffer.PlainBuffer plainBuffer) throws Buffer.BufferException, java.security.GeneralSecurityException
- Throws:
Buffer.BufferException
java.security.GeneralSecurityException
-
readEncodedKey
private java.lang.String readEncodedKey(java.io.BufferedReader reader) throws java.io.IOException
- Throws:
java.io.IOException
-
checkHeader
private boolean checkHeader(java.io.BufferedReader reader) throws java.io.IOException
- Throws:
java.io.IOException
-
readUnencrypted
private java.security.KeyPair readUnencrypted(Buffer.PlainBuffer keyBuffer, java.security.PublicKey publicKey) throws java.io.IOException, java.security.GeneralSecurityException
- Throws:
java.io.IOException
java.security.GeneralSecurityException
-
createECDSAPrivateKey
private java.security.PrivateKey createECDSAPrivateKey(KeyType kt, Buffer.PlainBuffer buffer, ECDSACurve ecdsaCurve) throws java.security.GeneralSecurityException, Buffer.BufferException
- Throws:
java.security.GeneralSecurityException
Buffer.BufferException
-
readRsaPrivateKeySpec
private java.security.spec.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
-
-