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 classOpenSSHKeyV1KeyFile.Factory
-
Field Summary
Fields Modifier and Type Field Description private static byte[]AUTH_MAGICstatic java.lang.StringBCRYPTprivate static java.lang.StringBEGINprivate static java.lang.StringENDprotected org.slf4j.Loggerlogprivate static java.lang.StringNONE_CIPHERstatic java.lang.StringOPENSSH_PRIVATE_KEYprivate java.security.PublicKeypubKeyprivate 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 booleancheckHeader(java.io.BufferedReader reader)private CiphercreateCipher(java.lang.String cipherName)private java.security.PrivateKeycreateECDSAPrivateKey(KeyType kt, Buffer.PlainBuffer buffer, ECDSACurve ecdsaCurve)private Buffer.PlainBufferdecryptPrivateKey(byte[] privateKey, int privateKeyLength, java.lang.String cipherName, java.lang.String kdfName, byte[] kdfOptions)java.security.PublicKeygetPublic()voidinit(java.io.File location, PasswordFinder pwdf)voidinit(java.io.Reader privateKey, java.io.Reader publicKey, PasswordFinder pwdf)voidinit(java.lang.String privateKey, java.lang.String publicKey, PasswordFinder pwdf)private voidinitializeCipher(java.lang.String kdfName, byte[] kdfOptions, Cipher cipher)private voidinitPubKey(java.io.Reader publicKey)private java.security.KeyPairreadDecodedKeyPair(Buffer.PlainBuffer keyBuffer)private java.lang.StringreadEncodedKey(java.io.BufferedReader reader)private byte[]readEncryptedPrivateKey(byte[] privateKeyEncoded, Buffer.PlainBuffer inputBuffer)protected java.security.KeyPairreadKeyPair()private java.security.PublicKeyreadPublicKey(Buffer.PlainBuffer plainBuffer)private java.security.spec.RSAPrivateCrtKeySpecreadRsaPrivateKeySpec(Buffer.PlainBuffer buffer)Read RSA Private CRT Key Spec according to OpenSSH sshkey_private_deserialize in sshkey.cprivate java.security.KeyPairreadUnencrypted(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:
getPublicin interfaceKeyProvider- Overrides:
getPublicin 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:
initin interfaceFileKeyProvider- Overrides:
initin classBaseFileKeyProvider
-
init
public void init(java.lang.String privateKey, java.lang.String publicKey, PasswordFinder pwdf)- Specified by:
initin interfaceFileKeyProvider- Overrides:
initin classBaseFileKeyProvider
-
init
public void init(java.io.Reader privateKey, java.io.Reader publicKey, PasswordFinder pwdf)- Specified by:
initin interfaceFileKeyProvider- Overrides:
initin classBaseFileKeyProvider
-
readKeyPair
protected java.security.KeyPair readKeyPair() throws java.io.IOException- Specified by:
readKeyPairin 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.IOExceptionjava.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.BufferExceptionjava.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.IOExceptionjava.security.GeneralSecurityException
-
createECDSAPrivateKey
private java.security.PrivateKey createECDSAPrivateKey(KeyType kt, Buffer.PlainBuffer buffer, ECDSACurve ecdsaCurve) throws java.security.GeneralSecurityException, Buffer.BufferException
- Throws:
java.security.GeneralSecurityExceptionBuffer.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
-
-