Documentation
¶
Index ¶
- Constants
- Variables
- func CleanupOldKnownHosts(fn string)
- func DecryptAes256Gcm(passphrase []byte, cryptoText []byte) []byte
- func DirExists(name string) bool
- func EncryptAes256Gcm(passphrase []byte, plaintext []byte, salt []byte) []byte
- func FileExists(name string) bool
- func FileExistsLen(name string) (bool, int64)
- func Fingerprint(k ssh.PublicKey) string
- func GenAddress() string
- func GenRsaKeyPair(rsa_file string, bits int) (priv *rsa.PrivateKey, sshPriv ssh.Signer, err error)
- func GetAvailPort() int
- func GetDockerIP() string
- func GetExternalIP() string
- func GetExternalIPAsInt() int
- func GetOriginatorPrivateKey() string
- func GetOriginatorPublicKey() string
- func GzipFile(ungzipped, gzipped string) error
- func IsRoutableIPv4(ip string) bool
- func KnownHostsEqual(a, b *KnownHosts) (bool, error)
- func LoadRSAPrivateKey(path string) (privkey ssh.Signer, err error)
- func LoadRSAPublicKey(path string) (pubkey ssh.PublicKey, err error)
- func MakeRandPadding(minBytes int, maxBytes int) []byte
- func NewMyClient(c ssh.Conn, chans <-chan ssh.NewChannel, reqs <-chan *ssh.Request) *myClient
- func PasswordToSshPrivKeyUnlocker(password []byte, iv []byte) []byte
- func ReadGzippedFile(gzipped string) ([]byte, error)
- func RemoveAsciiArmor(data []byte) ([]byte, error)
- func RsaToSshPublicKey(pubkey *rsa.PublicKey) []byte
- func RunningDockerId() ([]byte, error)
- func StartDockerImage(image string)
- func StopAllDockers()
- func StripNanomsgAddressPrefix(nanomsgAddr string) (suffix string, err error)
- func TSPrintf(format string, a ...interface{})
- func TrimRightNewline(slice []byte) []byte
- func Ts() string
- func UnGzipFile(gzipped, ungzipped string) error
- func VPrintf(format string, a ...interface{})
- func WrapInAsciiArmor(data []byte) ([]byte, error)
- func WriteGzippedFile(by []byte, gzipped string) error
- func XorWrapBytes(a []byte, b []byte) []byte
- type HostState
- type KnownHosts
- func (h *KnownHosts) Close()
- func (h *KnownHosts) HostAlreadyKnown(hostname string, remote net.Addr, key ssh.PublicKey, pubBytes []byte, ...) (HostState, error, *ServerPubKey)
- func (h *KnownHosts) SshConnect(username string, keypath string, host string, port int, ...) ([]byte, error)
- func (h *KnownHosts) SshMakeNewAcct(privKeyPath string, host string, port int) (acctid string, err error)
- func (h *KnownHosts) Sync()
- type MailgunConfig
- type ServerPubKey
- type Shovel
- type ShovelPair
Constants ¶
const AddIfNotKnown = true
const IgnoreIfNotKnown = false
const RequiredSaltLen = 64
Variables ¶
var DockerHubTestImage string = "jaten/pelican04"
this is the current docker image used to run sshd inside of and connect to. We don't actually connect to a real sshd anymore, but we did during protocol development. It might be useful to test against the real sshd in the future, so we keep it around.
var OriginatorPrivateKey string = `` /* 3247-byte string literal not displayed */
var OriginatorPublicKey string = `` /* 724-byte string literal not displayed */
var Verbose bool
Verbose can be set to true for debug output. For production builds it should be set to false, the default.
Functions ¶
func CleanupOldKnownHosts ¶
func CleanupOldKnownHosts(fn string)
CleanupOldKnownHosts removes fn + defaultFileFormat().
func DecryptAes256Gcm ¶
DecryptAes256Gcm is the inverse of EncryptAesGcm. It removes the base64url encoding, and then decrypts cryptoText using passphrase under the assumption that AES256-GCM was used to encrypt it.
func EncryptAes256Gcm ¶
EncryptAes256Gcm encrypts plaintext using passphrase using AES256-GCM, then converts it to base64url encoding.
func FileExists ¶
FileExists returns true iff the path name is a file (and not a directory or non-existant).
func FileExistsLen ¶
FileExistsLen check if name is an actually file (directories don't count) and also returns the length of the file.
func Fingerprint ¶
Fingerprint performs a SHA256 BASE64 fingerprint of the PublicKey, similar to OpenSSH. See: https://anongit.mindrot.org/openssh.git/commit/?id=56d1c83cdd1ac
func GenAddress ¶
func GenAddress() string
GenAddress generates a local address by calling GetAvailPort() and GetExternalIP(), then prefixing them with 'tcp://'.
func GenRsaKeyPair ¶
GenRsaKeyPair generates an RSA keypair of length bits. If rsa_file != "", we write the private key to rsa_file and the public key to rsa_file + ".pub". If rsa_file == "" the keys are not written to disk.
func GetAvailPort ¶
func GetAvailPort() int
GetAvailPort asks the OS for an unused port. There's a race here, where the port could be grabbed by someone else before the caller gets to Listen on it, but in practice such races are rare. Uses net.Listen("tcp", ":0") to determine a free port, then releases it back to the OS with Listener.Close().
func GetDockerIP ¶
func GetDockerIP() string
GetDockerIP returns the IP address bound by the container returned by RunningDockerId().
func GetExternalIP ¶
func GetExternalIP() string
GetExternalIP tries to determine the external IP address used on this host.
func GetExternalIPAsInt ¶
func GetExternalIPAsInt() int
GetExternalIPAsInt calls GetExternalIP() and then converts the resulting IPv4 string into an integer.
func GetOriginatorPrivateKey ¶
func GetOriginatorPrivateKey() string
func GetOriginatorPublicKey ¶
func GetOriginatorPublicKey() string
func GzipFile ¶
GzipFile reads the file in path ungzipped, then writes it back out to path gzipped in compressed format.
func IsRoutableIPv4 ¶
IsRoutableIPv4 returns true if the string in ip represents an IPv4 address that is not private. See http://en.wikipedia.org/wiki/Private_network#Private_IPv4_address_spaces for the numeric ranges that are private. 127.0.0.1, 192.168.0.1, and 172.16.0.1 are examples of non-routables IP addresses.
func KnownHostsEqual ¶
func KnownHostsEqual(a, b *KnownHosts) (bool, error)
KnownHostsEqual compares two instances of KnownHosts structures for equality.
func LoadRSAPrivateKey ¶
LoadRSAPrivateKey reads a private key from path on disk.
func LoadRSAPublicKey ¶
LoadRSAPublicKey reads a public key from path on disk. By convention these keys end in '.pub', but that is not verified here.
func MakeRandPadding ¶
MakeRandPadding produces non crypto (fast) random bytes for prepending to messges/compressed messages to avoid leaking info, and to make it harder to recognize if you've actually cracked it.
func NewMyClient ¶
func PasswordToSshPrivKeyUnlocker ¶
PasswordToSshPrivKeyUnlocker follows the OpenSSL formula for converting a human entered password into the key used to decode the AES-128-CBC (or otherwise) encrypted private key.
func ReadGzippedFile ¶
ReadGzippedFile reads from path gzipped, returning the uncompressed bytes.
func RemoveAsciiArmor ¶
RemoveAsciiArmor is the inverse of WrapInAsciiArmor. It removes the armor from data.
func RsaToSshPublicKey ¶
RsaToSshPublicKey convert an RSA Public Key to the SSH authorized_keys format.
func RunningDockerId ¶
RunningDockerId runs 'docker ps -q -n=1 -f status=running' and returns the output and any error.
func StartDockerImage ¶
func StartDockerImage(image string)
StartDockerImage starts a docker container based on image. It runs /sbin/my_init as the process, thereby assuming that /sbin/my_init is available inside the named image.
func StopAllDockers ¶
func StopAllDockers()
StopAllDockers calls 'docker stop' on all containers determined by successive calls to RunningDockerId().
func StripNanomsgAddressPrefix ¶
StripNanomsgAddressPrefix removes the 'tcp://' prefix from nanomsgAddr.
func TrimRightNewline ¶
TrimRightNewline removes the trailing byte of slice if it is a newline '\n' character.
func UnGzipFile ¶
UnGzipFile reads the file gzipped into memory, and the writes it back out to disk in file ungzipped without the compression.
func VPrintf ¶
func VPrintf(format string, a ...interface{})
VPrintf is like fmt.Printf, but only prints if Verbose is true. Uses TSPrint to mark each print with a timestamp.
func WrapInAsciiArmor ¶
WrapInAsciiArmor returns data as an Ascii-armored text block, using the type PELICAN-PROTOCOL-FORMAT. This makes its contents more resilliant to being forwarded through email.
func WriteGzippedFile ¶
WriteGzippedFile writes the bytes in by to the file named by gzipped.
func XorWrapBytes ¶
XorWrapBytes deterministicallyl XORs two byte slices together, wrapping one against the other if need be. The result is the same length as the longer of a and b
Types ¶
type HostState ¶
type HostState int
const Banned HostState = 1
const KnownOK HostState = 2
const KnownRecordMismatch HostState = 3
const Unknown HostState = 0
type KnownHosts ¶
type KnownHosts struct { Hosts map[string]*ServerPubKey // FilepathPrefix doesn't have the .json.snappy suffix on it. FilepathPrefix string // PersistFormat doubles as the file suffix as well as // the format indicator PersistFormat string // contains filtered or unexported fields }
KnownHosts represents in Hosts a hash map of host identifier (ip or name) and the corresponding public key for the server. It corresponds to the ~/.ssh/known_hosts file.
func NewKnownHosts ¶
func NewKnownHosts(filepathPrefix string) *KnownHosts
NewKnownHosts creats a new KnownHosts structure. filepathPrefix does not include the
PersistFormat suffix. If filepathPrefix + defaultFileFormat() exists as a
file on disk, then we read the contents of that file into the new KnownHosts. We note the filepathPrefix for future saves back to that file as well.
func (*KnownHosts) Close ¶
func (h *KnownHosts) Close()
Close cleans up and prepares for shutdown. It calls h.Sync() to write the state to disk.
func (*KnownHosts) HostAlreadyKnown ¶
func (*KnownHosts) SshConnect ¶
func (*KnownHosts) SshMakeNewAcct ¶
func (*KnownHosts) Sync ¶
func (h *KnownHosts) Sync()
Sync writes the contents of the KnownHosts structure to the file h.FilepathPrefix + h.PersistFormat.
type MailgunConfig ¶
type MailgunConfig struct { ApiKey string `json:"apikey"` Domain string `json:"domain"` FromEmail string `json:"from-email"` // e.g. "Jill McMail <jill@example.com>" RecipEmail []string `json:"recip-email"` // e.g. ["Jill McMail <jill@examaple.com", "Joe McMail <joe@example.com>"] }
func ReadMailgunConfig ¶
func ReadMailgunConfig(path string) *MailgunConfig
func (*MailgunConfig) Load ¶
func (c *MailgunConfig) Load(path string) error
func (*MailgunConfig) Save ¶
func (c *MailgunConfig) Save(path string) error
func (*MailgunConfig) SendPPPBackupMailgunMail ¶
func (cfg *MailgunConfig) SendPPPBackupMailgunMail(body string) (statusMsg string, id string, err error)
type ServerPubKey ¶
type ServerPubKey struct { Hostname string // HumanKey is a serialized and readable version of Key, the key for Hosts map in KnownHosts. HumanKey string ServerBanned bool // contains filtered or unexported fields }
ServerPublicKey stores the RSA public keys for a particular known server. This structure is stored in KnownHosts.Hosts.
type Shovel ¶
Shovel shovels data from an io.ReadCloser to an io.WriteCloser in an independent go routine started by Shovel::Start(). You can request that the shovel stop by closing ReqStop, and wait until Done is closed to know that it is finished.
func (*Shovel) Start ¶
func (s *Shovel) Start(w io.WriteCloser, r io.ReadCloser, label string)
Start starts the shovel doing an io.Copy from r to w. The goroutine that is running the copy will close the Ready channel just before starting the io.Copy. The label parameter allows reporting on when a specific shovel was shut down.
type ShovelPair ¶
a ShovelPair manages the forwarding of a bidirectional channel, such as that in forwarding an ssh connection.
func (*ShovelPair) Start ¶
func (s *ShovelPair) Start(a io.ReadWriteCloser, b io.ReadWriteCloser, ab_label string, ba_label string)
Start the pair of shovels. ab_label will label the a<-b shovel. ba_label will label the b<-a shovel.
func (*ShovelPair) Stop ¶
func (s *ShovelPair) Stop()