key

package
v0.0.13 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 8, 2023 License: Apache-2.0 Imports: 12 Imported by: 5

Documentation

Overview

Package key contains the common functions to parse and create keys. TODO: It also defines the public key algorithms supported by RA.

Index

Constants

This section is empty.

Variables

View Source
var SSHKeyAlgoStrMap = map[string]PublicKeyAlgo{
	"RSA2048": RSA2048,
	"RSA4096": RSA4096,
	"ECCP256": ECDSAsecp256r1,
	"ECCP384": ECDSAsecp384r1,
	"ECCP521": ECDSAsecp521r1,
	"ED25519": ED25519,
}

SSHKeyAlgoStrMap contains the mapping from strings to supported public key algorithms.

Functions

func CastSSHPublicKeyToAgentKey

func CastSSHPublicKeyToAgentKey(key ssh.PublicKey) *agent.Key

CastSSHPublicKeyToAgentKey casts any types of SSH PublicKey to *agent.Key.

func CastSSHPublicKeyToCertificate

func CastSSHPublicKeyToCertificate(key ssh.PublicKey) (*ssh.Certificate, error)

CastSSHPublicKeyToCertificate casts any types of SSH PublicKey to *ssh.Certificate; otherwise, an error is returned.

func GenerateKeyPair

func GenerateKeyPair(pka PublicKeyAlgo) (crypto.PrivateKey, ssh.PublicKey, error)

GenerateKeyPair returns a new pair of keys for the specified algorithm. Caller should cast the returned private key to one of *rsa.PrivateKey, *ecdsa.PrivateKey or *ed25519.PrivateKey depending on the specified input.

func GetPrivateKeyFromFile

func GetPrivateKeyFromFile(file string) (interface{}, error)

GetPrivateKeyFromFile reads the private key from file and returns *rsa.PrivateKey, *dsa.PrivateKey or *ecdsa.PrivateKeyrsa; otherwise, an error is returned.

func GetPublicKeyFromFile

func GetPublicKeyFromFile(file string) (key ssh.PublicKey, comment string, err error)

GetPublicKeyFromFile returns the first SSH public key from the given file; otherwise, an error is returned.

func GetPublicKeysFromBytes

func GetPublicKeysFromBytes(data []byte) (keys []ssh.PublicKey, comments []string, err error)

GetPublicKeysFromBytes returns a slice of SSH public keys from the given data chunk.

func GetPublicKeysFromFile

func GetPublicKeysFromFile(file string) (keys []ssh.PublicKey, comments []string, err error)

GetPublicKeysFromFile returns a slice of SSH public keys from the given file; otherwise, an error is returned.

Types

type PublicKeyAlgo

type PublicKeyAlgo int

PublicKeyAlgo is used to specify public key algorithm for the key pair in ssh-agent.

const (
	RSA2048 PublicKeyAlgo = iota
	RSA4096
	ECDSAsecp256r1
	ECDSAsecp384r1
	ECDSAsecp521r1
	// ED25519 is not supported in yubico hardware keys currently.
	ED25519
)

List of supported public key algorithms.

func GetSSHKeyAlgo added in v0.0.13

func GetSSHKeyAlgo(keyType string) (PublicKeyAlgo, error)

GetSSHKeyAlgo returns a specific public key algorithm by the given algo string. It returns RSA2048 and an error if no valid algorithms found.

func (PublicKeyAlgo) String added in v0.0.13

func (p PublicKeyAlgo) String() string

String stringifies the PublicKeyAlgo.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL