Class 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: https://github.com/openssh/openssh-portable/blob/master/PROTOCOL.key
    • Field Detail

      • 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
      • 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
    • Constructor Detail

      • OpenSSHKeyV1KeyFile

        public OpenSSHKeyV1KeyFile()
    • Method Detail

      • getPublic

        public java.security.PublicKey getPublic()
                                          throws java.io.IOException
        Specified by:
        getPublic in interface KeyProvider
        Overrides:
        getPublic in class BaseFileKeyProvider
        Returns:
        the public key.
        Throws:
        java.io.IOException - if there is an I/O error retrieving the public key
      • readKeyPair

        protected java.security.KeyPair readKeyPair()
                                             throws java.io.IOException
        Specified by:
        readKeyPair in class BaseFileKeyProvider
        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
      • 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
      • createCipher

        private Cipher createCipher​(java.lang.String cipherName)
      • 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
      • 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