Documentation
¶
Overview ¶
Package keygen handles the creation of new SSH key pairs.
Index ¶
- Variables
- type ErrUnsupportedKeyType
- type FilesystemErr
- type KeyPair
- func (s *KeyPair) AuthorizedKey() string
- func (s *KeyPair) CryptoPublicKey() crypto.PublicKey
- func (s *KeyPair) KeyPairExists() bool
- func (s *KeyPair) PrivateKey() crypto.PrivateKey
- func (s *KeyPair) PublicKey() ssh.PublicKey
- func (s *KeyPair) RawAuthorizedKey() []byte
- func (s *KeyPair) RawPrivateKey() []byte
- func (s *KeyPair) RawProtectedPrivateKey() []byte
- func (s *KeyPair) Signer() ssh.Signer
- func (s *KeyPair) WriteKeys() error
- type KeyType
- type Option
- type SSHKeyPair
- type SSHKeysAlreadyExistErr
Constants ¶
This section is empty.
Variables ¶
var ErrMissingSSHKeys = errors.New("missing one or more keys; did something happen to them after they were generated?")
ErrMissingSSHKeys indicates we're missing some keys that we expected to have after generating. This should be an extreme edge case.
Functions ¶
This section is empty.
Types ¶
type ErrUnsupportedKeyType ¶
type ErrUnsupportedKeyType struct {
// contains filtered or unexported fields
}
ErrUnsupportedKeyType indicates an unsupported key type.
func (ErrUnsupportedKeyType) Error ¶
func (e ErrUnsupportedKeyType) Error() string
Error implements the error interface for ErrUnsupportedKeyType.
type FilesystemErr ¶
type FilesystemErr struct {
Err error
}
FilesystemErr is used to signal there was a problem creating keys at the filesystem-level. For example, when we're unable to create a directory to store new SSH keys in.
func (FilesystemErr) Error ¶
func (e FilesystemErr) Error() string
Error returns a human-readable string for the error. It implements the error interface.
func (FilesystemErr) Unwrap ¶
func (e FilesystemErr) Unwrap() error
Unwrap returns the underlying error.
type KeyPair ¶
type KeyPair struct {
// contains filtered or unexported fields
}
KeyPair holds a pair of SSH keys and associated methods.
func New ¶
New generates a KeyPair, which contains a pair of SSH keys.
If the key pair already exists, it will be loaded from disk, otherwise, a new SSH key pair is generated. If no key type is specified, Ed25519 will be used.
func (*KeyPair) AuthorizedKey ¶
AuthorizedKey returns the SSH public key (RFC 4253) in OpenSSH authorized_keys format. The returned string is trimmed of sshd options and comments.
func (*KeyPair) CryptoPublicKey ¶
CryptoPublicKey returns the crypto.PublicKey of the SSH key pair.
func (*KeyPair) KeyPairExists ¶
KeyPairExists checks if the SSH key pair exists on disk.
func (*KeyPair) PrivateKey ¶
func (s *KeyPair) PrivateKey() crypto.PrivateKey
PrivateKey returns the unencrypted crypto.PrivateKey.
func (*KeyPair) RawAuthorizedKey ¶
RawAuthorizedKey returns the underlying SSH public key (RFC 4253) in OpenSSH authorized_keys format.
func (*KeyPair) RawPrivateKey ¶
RawPrivateKey returns the raw unencrypted private key bytes in PEM format.
func (*KeyPair) RawProtectedPrivateKey ¶
RawProtectedPrivateKey returns the raw password protected private key bytes in PEM format.
type Option ¶
type Option func(*KeyPair)
Option is a functional option for KeyPair.
func WithBitSize ¶
WithBitSize sets the key size for the RSA key pair. This option is ignored for other key types.
func WithEllipticCurve ¶
WithEllipticCurve sets the elliptic curve for the ECDSA key pair. Supported curves are P-256, P-384, and P-521. The default curve is P-384. This option is ignored for other key types.
func WithKeyType ¶
WithKeyType sets the key type for the key pair. Available key types are RSA, Ed25519, and ECDSA.
func WithPassphrase ¶
WithPassphrase sets the passphrase for the private key.
type SSHKeyPair ¶
type SSHKeyPair = KeyPair
SSHKeyPair holds a pair of SSH keys and associated methods. Deprecated: Use KeyPair instead.
type SSHKeysAlreadyExistErr ¶
type SSHKeysAlreadyExistErr struct {
Path string
}
SSHKeysAlreadyExistErr indicates that files already exist at the location at which we're attempting to create SSH keys.
func (SSHKeysAlreadyExistErr) Error ¶
func (e SSHKeysAlreadyExistErr) Error() string
Error returns the a human-readable error message for SSHKeysAlreadyExistErr. It satisfies the error interface.