Skip to content

osal.sshagent #

ssh agent

import freeflowuniverse.crystallib.osal.sshagent

mut agent := sshagent.new()!

privkey:='
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW
QyNTUxOQAAACDXf9Z/2AH8/8a1ppagCplQdhWyQ8wZAieUw3nNcxsDiQAAAIhb3ybRW98m
0QAAAAtzc2gtZWQyNTUxOQAAACDXf9Z/2AH8/8a1ppagCplQdhWyQ8wZAieUw3nNcxsDiQ
AAAEC+fcDBPqdJHlJOQJ2zXhU2FztKAIl3TmWkaGCPnyts49d/1n/YAfz/xrWmlqAKmVB2
FbJDzBkCJ5TDec1zGwOJAAAABWJvb2tz
-----END OPENSSH PRIVATE KEY-----
'

//make sure the name chose is same as original name of the key
mut sshkey:=agent.add('mykey:,privkey)!


sshkey.forget()!

'

hero

there is also a hero command

//will add the key and load (at this stage no support for passphrases)
!!sshagent.key_add name:'myname'
    privkey:'
        -----BEGIN OPENSSH PRIVATE KEY-----
        b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW
        QyNTUxOQAAACDXf9Z/2AH8/8a1ppagCplQdhWyQ8wZAieUw3nNcxsDiQAAAIhb3ybRW98m
        0QAAAAtzc2gtZWQysdsdsddsdsdsdsdsdsd8/8a1ppagCplQdhWyQ8wZAieUw3nNcxsDiQ
        AAAEC+fcDBPqdJHlJOQJ2zXhU2FztKAIl3TmWkaGCPnyts49d/1n/YAfz/xrWmlqAKmVB2
        FbJDzBkCJ5TDec1zGwOJAAAABWJvb2tz
        -----END OPENSSH PRIVATE KEY-----
        '

fn loaded #

fn loaded() bool

fn new #

fn new(args_ SSHAgentNewArgs) !SSHAgent

enum SSHKeyCat #

enum SSHKeyCat {
	ed25519
	rsa
}

struct KeyGetArgs #

@[params]
struct KeyGetArgs {
pub mut:
	pubkey string
	// privkey string	
	// privkey_path string
	name string
}

struct SSHAgent #

@[heap]
struct SSHAgent {
pub mut:
	keys     []SSHKey
	active   bool
	homepath pathlib.Path
}

fn (SSHAgent) add #

fn (mut agent SSHAgent) add(name string, privkey_ string) !SSHKey

load the key, they key is content (private key) . a name is required

fn (SSHAgent) exists #

fn (mut agent SSHAgent) exists(args KeyGetArgs) bool

fn (SSHAgent) forget #

fn (mut agent SSHAgent) forget(name string) !

forget the specified key

fn (SSHAgent) generate #

fn (mut agent SSHAgent) generate(name string, passphrase string) !SSHKey

returns path to sshkey

fn (SSHAgent) get #

fn (mut agent SSHAgent) get(args_ KeyGetArgs) ?SSHKey

fn (SSHAgent) init #

fn (mut agent SSHAgent) init() !

get all keys from sshagent and from the local .ssh dir

fn (SSHAgent) keys_loaded #

fn (mut agent SSHAgent) keys_loaded() ![]SSHKey

fn (SSHAgent) load #

fn (mut agent SSHAgent) load(keypath string) !SSHKey

load key starting from path to private key

fn (SSHAgent) reset #

fn (mut agent SSHAgent) reset() !

unload all ssh keys

fn (SSHAgent) str #

fn (mut agent SSHAgent) str() string

struct SSHAgentNewArgs #

@[params]
struct SSHAgentNewArgs {
pub mut:
	homepath string
}

struct SSHKey #

@[heap]
struct SSHKey {
pub mut:
	name   string
	pubkey string
	loaded bool
	email  string
	agent  &SSHAgent @[skip; str: skip]
	cat    SSHKeyCat
}

fn (SSHKey) keypath #

fn (mut key SSHKey) keypath() !pathlib.Path

fn (SSHKey) keypath_pub #

fn (mut key SSHKey) keypath_pub() !pathlib.Path

fn (SSHKey) keypub #

fn (mut key SSHKey) keypub() !string

fn (SSHKey) forget #

fn (mut key SSHKey) forget() !

load the key, they key is content, other keys will be unloaded

fn (SSHKey) str #

fn (mut key SSHKey) str() string

fn (SSHKey) load #

fn (mut key SSHKey) load() !