keys

package
v0.0.20 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2022 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Rendered for js/wasm

Overview

Package keys provides APIs to manage configured keys and load them into an SSH agent.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConfiguredKey

type ConfiguredKey struct {
	// Id is the unique ID for this key.
	ID string `js:"id"`
	// Name is a name allocated to key.
	Name string `js:"name"`
	// Encrypted indicates if the key is encrypted and requires a passphrase
	// to load.
	Encrypted bool `js:"encrypted"`
}

ConfiguredKey is a key configured for use.

type DefaultManager added in v0.0.20

type DefaultManager struct {
	// contains filtered or unexported fields
}

DefaultManager is an implementation of Manager.

func NewManager

func NewManager(agt agent.Agent, syncStorage, sessionStorage chrome.PersistentStore) *DefaultManager

NewManager returns a Manager implementation that can manage keys in the supplied agent, and store configured keys in the supplied storage.

func (*DefaultManager) Add added in v0.0.20

func (m *DefaultManager) Add(name string, pemPrivateKey string, callback func(err error))

Add implements Manager.Add.

func (*DefaultManager) Configured added in v0.0.20

func (m *DefaultManager) Configured(callback func(keys []*ConfiguredKey, err error))

Configured implements Manager.Configured.

func (*DefaultManager) Load added in v0.0.20

func (m *DefaultManager) Load(id ID, passphrase string, callback func(err error))

Load implements Manager.Load.

func (*DefaultManager) LoadFromSession added in v0.0.20

func (m *DefaultManager) LoadFromSession(callback func(err error))

LoadFromSession loads all keys for the current session into the agent.

func (*DefaultManager) Loaded added in v0.0.20

func (m *DefaultManager) Loaded(callback func(keys []*LoadedKey, err error))

Loaded implements Manager.Loaded.

func (*DefaultManager) Remove added in v0.0.20

func (m *DefaultManager) Remove(id ID, callback func(err error))

Remove implements Manager.Remove.

func (*DefaultManager) Unload added in v0.0.20

func (m *DefaultManager) Unload(key *LoadedKey, callback func(err error))

Unload implements Manager.Unload.

type ID

type ID string

ID is a unique identifier for a configured key.

const (
	// InvalidID is a special ID that will not be assigned to any key.
	InvalidID ID = ""
)

type LoadedKey

type LoadedKey struct {
	// Type is the type of key loaded in the agent (e.g., 'ssh-rsa').
	Type string `js:"type"`
	// InternalBlob is the public key material for the loaded key. Must
	// be exported to be handled correctly in conversion to/from js.Value.
	InternalBlob string `js:"blob"`
	// Comment is a comment for the loaded key.
	Comment string `js:"comment"`
}

LoadedKey is a key loaded into the agent.

func (*LoadedKey) Blob

func (k *LoadedKey) Blob() []byte

Blob returns the public key material for the loaded key.

func (*LoadedKey) ID

func (k *LoadedKey) ID() ID

ID returns the unique ID corresponding to the key. If the ID cannot be determined, then InvalidID is returned.

The ID for a key loaded into the agent is stored in the Comment field as a string in a particular format.

func (*LoadedKey) SetBlob added in v0.0.8

func (k *LoadedKey) SetBlob(b []byte)

SetBlob sets the given public key material for the loaded key.

type Manager

type Manager interface {
	// Configured returns the full set of keys that are configured. The
	// callback is invoked with the result.
	Configured(callback func(keys []*ConfiguredKey, err error))

	// Add configures a new key.  name is a human-readable name describing
	// the key, and pemPrivateKey is the PEM-encoded private key.  callback
	// is invoked when complete.
	Add(name string, pemPrivateKey string, callback func(err error))

	// Remove removes the key with the specified ID.  callback is invoked
	// when complete.
	//
	// Note that it might be nice to return an error here, but
	// the underlying Chrome APIs don't make it trivial to determine
	// if the requested key was removed, or ignored because it didn't
	// exist.  This could be improved, but it doesn't seem worth it at
	// the moment.
	Remove(id ID, callback func(err error))

	// Loaded returns the full set of keys loaded into the agent. The
	// callback is invoked with the result.
	Loaded(callback func(keys []*LoadedKey, err error))

	// Load loads a new key into to the agent, using the passphrase to
	// decrypt the private key.  callback is invoked when complete.
	//
	// NOTE: Unencrypted private keys are not currently supported.
	Load(id ID, passphrase string, callback func(err error))

	// Unload unloads a key from the agent. callback is invoked when
	// complete.
	Unload(key *LoadedKey, callback func(err error))
}

Manager provides an API for managing configured keys and loading them into an SSH agent.

func NewClient

func NewClient(msg MessageSender) Manager

NewClient returns a Manager implementation that forwards calls to a Server.

type MessageSender

type MessageSender interface {
	SendMessage(msg js.Value, callback func(rsp js.Value))
	Error() error
}

MessageSender defines methods sufficient to send messages.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server exposes a Manager instance via a messaging API so that a shared instance can be invoked from a different page.

func NewServer

func NewServer(mgr Manager) *Server

NewServer returns a new Server that manages keys using the supplied Manager.

func (*Server) OnMessage added in v0.0.20

func (s *Server) OnMessage(headerObj js.Value, sender js.Value, sendResponse func(js.Value))

OnMessage is the callback invoked when a message is received. It determines the type of request received, invokes the appropriate method on the underlying manager instance, and then sends a response with the result.

This method is guaranteed to invoke sendReponse (aside from unexpected panics). Context for why this important:

The caller is expected to be handling an OnMessage event from the browser,
and it returns 'true' to the browser to indicate that the event will be
handled asynchronously and the port must not yet be closed. Invoking
sendResponse is the signal to the browser to close the port and free
resources.

Jump to

Keyboard shortcuts

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